Skip to content

[AI-3712] Fix the api integration tests' compile on main - #2341

Merged
thesyncim merged 1 commit into
mainfrom
fix/ai-3712-api-tests-compile
Nov 24, 2026
Merged

thesyncim merged 1 commit into
mainfrom
fix/ai-3712-api-tests-compile

Conversation

@kanat

@kanat kanat commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Why

The api group of Integration (router) does not compile on main since dc88f2f (run 45350145644):

internal/api/scheduled_unpaid_test.go:1200:2: cannot assign to scheduledPhoneWindow (neither addressable nor a map index expression)

#2277 set the package-level scheduledPhoneWindow and scheduledCallLimit in TelnyxUnpaidSuite.callOn. #2293, merged before it, made them constants and moved the values a test changes onto the router. Each passed CI on its own. Until this lands, every PR whose CI runs the api group fails.

Changes

  • callOn sets s.router.phoneWindow and s.router.callLimit and restores them in its cleanup, as scheduled_phone_test.go:136-138 does. Test-only.

Validation

  • go vet -tags integration ./internal/api: compiles.
  • go test -tags integration ./internal/api -run TestTelnyxUnpaidSuite -count=1: ok (99.7 s), including the three tests that go through callOn.

🤖 Generated with Claude Code

…Suite

#2277 assigned the package-level scheduledPhoneWindow and scheduledCallLimit,
which #2293 made constants and moved onto the router, so the api integration
tests did not compile on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: GO

Round 1, head 41b6352 merged onto current main (6d3cb55, clean).

  • The change restores what #2277 meant. callOn now shortens s.router.phoneWindow and s.router.callLimit (the router fields #2293 added, set from the constants in server.go:618-619) and its cleanup puts the saved values back, the same shape as scheduled_phone_test.go:136-138.
  • No other site assigns the old names: git grep -E 'scheduledPhoneWindow|scheduledCallLimit' -- acceleration finds only the constants, their uses in server.go:618-619 and comments.
  • go vet ./... && go vet -tags integration ./... from acceleration/ compiles the whole module, no output.
  • go test -tags integration ./internal/api -run TestTelnyxUnpaidSuite -count=1 -v on a private DB: ok (105 s), 48 pass, 0 skip. The nine tests that reach callOn (directly or through ringingOn) all ran and passed.
  • No mutation check: test-only change, and the tests above run it.
  • CI: this is a draft, the integration jobs are skipping on the head. CI runs at gh pr ready.

@kanat
kanat marked this pull request as ready for review November 24, 2026 08:14

@thesyncim thesyncim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked: merges cleanly onto current main and go vet -tags integration ./internal/api/ passes on the merge. Merging to unblock every PR's integration (api) while Kanat is out.

@thesyncim
thesyncim merged commit 7dc095e into main Nov 24, 2026
15 checks passed
@thesyncim
thesyncim deleted the fix/ai-3712-api-tests-compile branch November 24, 2026 10:46
Nash0x7E2 pushed a commit that referenced this pull request Nov 24, 2026
…th the refusal, not a 500 (#2354)

**Problem**
#2295 refused a session on a deployment whose Stream app keys Stream
rejects with its own sentence. A fork reached that refusal through
`refusedRequest`, and so did an app-mode create whose own app rejects
its keys. #2295 relied on `refusedRequest` answering any error as a 400
with the error's text. #2248, already on #2295's branch, had changed
that: an error `refusedRequest` does not recognise is now a 500
"something went wrong". These paths never answered correctly on main.
Their tests in `SelfHostedSessionsSuite` and `AppModeSessionsSuite`
could not run until #2341 fixed the package's compile, so `integration
(api)` fails on every PR.

**Fix**
- `refusedRequest` (money.go) answers `ErrNoStreamKeys` and
`ErrStreamKeysRejected` through `unkeptAnswer`, as `not_configured`.
Create, fork, resume, voice and the socket now give this refusal the
same code and status.
- In app mode, `unkeptIn` (session/stream_keys.go) maps Stream's 401 for
an app's own keys to a new `ErrAppStreamKeysRejected`. That error is a
caller mistake, answered as `invalid_request` in our own words. It names
no deployment variable and none of Stream's text. Before, the raw
`StreamError` went through as a 500.
- Create and fork log Stream's answer as create did before
(`logUnkept`). A resume answers correctly but does not log the cause.

**Tests**
- `TestAForkOnKeysStreamRefusesNamesTheKeysWithNothingOfStreams` caught
a fork answered as a 500. It now also asserts `not_configured`. It
failed on main with 500 "something went wrong".
-
`TestAPersistedTextSessionIntoAnAppRefusingItsKeysIsNotTheDeploymentsToFix`
caught an app's refused keys answered as a 500. It failed on main with a
500. It now also asserts `invalid_request` and our sentence, and that
Stream's "api_key not valid" stays out of the body. Without that last
check, putting back the old catch-all `invalidRequest(err.Error())`
would pass.
- `TestInAppModeTheAppIsTheCustomers` (unit) now expects
`ErrAppStreamKeysRejected` without `STREAM_API_KEY`, where it expected
nil.
- Both suites passed 3 times with `-count=3`. Five mutants were each
killed: no unkept case in `refusedRequest`, the app-mode branch
returning nil, the app refusal answered `not_configured`, the old
catch-all, and the app refusal dropped from `callerMistakes`.
kanat added a commit that referenced this pull request Nov 25, 2026
## Why

A Slack app configuration token rotates: `Server.configToken` calls
`Rotate`, and Slack then treats the refresh token it just got as spent.
The new pair was saved with one `Upsert`. When that one save failed (a
dropped connection, a short database outage), the new pair was gone and
the stored one was dead, so the customer had to send a new
`config_refresh_token`. Same pattern as the credential refresh fixed in
#2192, found in its sibling sweep (AI-3504).

## How it works

```
configToken
├─ Rotate (Slack spends the old refresh token)
└─ saveConfigToken
   ├─ Upsert           ok -> done
   ├─ failed, store.Unwritable? -> stop (a retry fails the same way)
   ├─ wait 100 ms, Upsert again
   ├─ wait 200 ms, Upsert again
   └─ still failing -> one error log (customer, connector, attempts; no token), error returned as before
```

- Bound: 3 saves, 300 ms of pauses, each save at most the store's 2 s
(`credentialDetachedTimeout`), so under 6.3 s, inside the provider app
lock the caller already holds.
- The save is an upsert, so one whose answer was lost and landed is safe
to repeat.
- Reused: `store.Unwritable` (the rule behind the resolver's
`retryable`). Not reused: the resolver's `saveAttempts`, `saveAgain` and
`wait` are unexported and tied to its credential store, and the 10DLC
service repeats the same numbers; a shared helper would need a package
of its own, so the three constants stay local with the reason in the
comment.
- API answers are unchanged: a failed save is the same 500 as before.

## Changes

- `connector_provider_apps.go`: `saveConfigToken` with its two
constants; `configToken` logs the last failure.
- Tests: `RouterSuite.failFirstQueries` (fail only the first n queries
that name a value, on the suite's existing query-hook seam); four tests
in `ConnectorProviderAppsSuite`:
`TestARotatedConfigTokenWhoseFirstSaveFailsIsSavedByTheNextAndUsedWithoutAnotherRotation`,
`TestARotatedConfigTokenWhoseEverySaveFailsIsLoggedOnceWithoutItsWordsAndAnsweredAsAnyFailure`,
`TestARotatedConfigTokenThatPostgresRefusesIsNotSavedAgain`,
`TestARotatedConfigTokenWhoseSaveLosesItsConnectionIsSavedByTheNextAndUsedWithoutAnotherRotation`.
- Second commit, unrelated to AI-3550: `TelnyxUnpaidSuite.callOn`
assigned the package-level `scheduledPhoneWindow` and
`scheduledCallLimit`, which #2293 made constants, so the api package's
integration tests did not compile on `main` (`go vet -tags integration
./internal/api` at dc88f2f). It sets them on the router as the other
scheduled tests do. The same change is #2341 (AI-3712); whichever merges
first, the other's copy merges clean.

## Validation

| Defect | Test | Mutant that fails it |
|---|---|---|
| One failed save loses the pair |
`TestARotatedConfigTokenWhoseFirstSaveFailsIsSavedByTheNextAndUsedWithoutAnotherRotation`:
the next call uses the stored pair, no second rotation | no retry;
`seam-always-fails` |
| Retries without end, or without waiting |
`...WhoseEverySaveFailsIsLoggedOnce...`: 3 attempts, at least 300 ms,
500 | unbounded; 2 attempts; no pause; constant pause |
| A row Postgres refuses is saved again |
`...ThatPostgresRefusesIsNotSavedAgain` (customer id past the index
limit, SQLSTATE 54000): `attempts=1` | retry on `Unwritable` |
| A token or its words in the log, no customer or connector in it | the
all-fail test reads the one error line | token, refresh token, stored
refresh in the line; no customer; no connector; warn level; no log |
| The failure swallowed | all-fail test: status 500 | return nil |
| A dropped connection (SQLSTATE 57P01) is not retried |
`...WhoseSaveLosesItsConnectionIsSavedByTheNext...`: the next call uses
the stored pair | retry only on context deadline; never retry a
Postgres-reported error |
| A refused row's log names the sent token |
`...ThatPostgresRefusesIsNotSavedAgain`: the log line holds no sent
token | log `sent` |
| The every-save-fails log line has extra or missing fields |
`...WhoseEverySaveFailsIsLoggedOnce...`: the line has exactly time,
level, msg, customer, connector, attempts, error | sealed pair as an
extra field |
| The first-save test passes without a failed save |
`...WhoseFirstSaveFailsIs...`: the seam fails exactly one save (two
saves ran) | seam off by one |
| The all-fail call waits on every save |
`...WhoseEverySaveFailsIsLogged...`: the call ends under 2 s | 1 s sleep
after every save |

- Tests run against real Postgres and the suite's fake Slack; the
failing save is the suite's per-suite query hook, no DDL and no store
mock.
- Run: `go test -tags integration ./internal/api -run
TestConnectorProviderAppsSuite` passes, and the suites that use
`failQueries` (authorizations, agent teams, channels, data move,
knowledge urls, 10DLC, guests) pass on the tests that call it. The full
integration run is CI's.
- `go vet -tags integration ./internal/api`, `gofmt -l`, `go build
./...` are clean.
- Not checked: Slack's real behavior on a spent refresh token (the fake
takes the strict reading, as its comment says); whether
`credentialDetachedTimeout` is the real worst case on a stalled network.
The 3 x 100/200 ms bound is a choice, not measured, as in the resolver.

## Review rounds

Round 1: main review NO-GO (no test of a dropped connection; two time
and count gaps), security review GO with one log-field test gap. Round
2: all fixed in tests only; delta review GO, 24 mutants, none survived.
Round 3: one comment word.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants