@@ -148,6 +148,49 @@ func (ac *APIConnection) ListEndpoints(patterns ...string) (endpoints Endpoints,
148148 return endpoints , nil
149149}
150150
151+ // GetTestEndpoint returns the best endpoint for testing connectivity/authentication.
152+ // Ranking: (1) non-incremental with auth, (2) incremental with auth, (3) non-incremental, (4) first endpoint
153+ func (ac * APIConnection ) GetTestEndpoint () string {
154+ endpoints , err := ac .ListEndpoints ()
155+ if err != nil || len (endpoints ) == 0 {
156+ return ""
157+ }
158+
159+ hasSpecAuth := ac .Spec .Authentication .Type () != AuthTypeNone
160+
161+ var nonIncrementalWithAuth , incrementalWithAuth , nonIncremental string
162+
163+ for _ , ep := range endpoints {
164+ // Determine if incremental (has sync values or update key)
165+ isIncremental := len (ep .Sync ) > 0 || ep .Response .Records .UpdateKey != ""
166+
167+ // Determine if has auth (spec-level or endpoint-level)
168+ hasAuth := hasSpecAuth || ep .Authentication != nil
169+
170+ if ! isIncremental && hasAuth && nonIncrementalWithAuth == "" {
171+ nonIncrementalWithAuth = ep .Name
172+ } else if isIncremental && hasAuth && incrementalWithAuth == "" {
173+ incrementalWithAuth = ep .Name
174+ } else if ! isIncremental && nonIncremental == "" {
175+ nonIncremental = ep .Name
176+ }
177+ }
178+
179+ // Return by priority
180+ if nonIncrementalWithAuth != "" {
181+ return nonIncrementalWithAuth
182+ }
183+ if incrementalWithAuth != "" {
184+ return incrementalWithAuth
185+ }
186+ if nonIncremental != "" {
187+ return nonIncremental
188+ }
189+
190+ // Fallback: first endpoint (already sorted alphabetically)
191+ return endpoints [0 ].Name
192+ }
193+
151194// compile all spec endpoints
152195func (ac * APIConnection ) CompileEndpoints () (compiledEndpoints Endpoints , err error ) {
153196 // render dynamic endpoint if needed
0 commit comments