test: pin auth behavior before the multi-account refactor - #1417
Draft
l2ysho wants to merge 3 commits into
Draft
Conversation
Stage-0 of #1297. The keyring backend — the default for real users — was never reached through a command: useAuthSetup and run-cli both pin APIFY_DISABLE_KEYRING=1, and the auth commands only ran under test:api. - Shared @napi-rs/keyring fake in test/__setup__/keyring-mock.ts, plus a useKeyringBackend() hook so one file can cover both backends - New test/local/commands/auth.test.ts stubs apify-client, so login, logout and auth token now run in test:local on both backends - credentials.test.ts: writeFileSync spy so the skipIfUnchanged tests can fail, 0o600 assertions, keyring write failures for setToken and setProxyPassword, the stale-credentials throw, resolveToken happy path - e2e auth token now compares stdout to the token, not to length > 0 Every new test was mutation-verified against the branch it covers. Closes #1387 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
From the second staff review: - getBackend() reading a persisted secretsBackend marker is what makes a keyring downgrade survive across processes; it had no test - every login in auth.test.ts used one identity, so the merge in getLoggedClient was never given a differing user. Stage-1 rewrites exactly that merge Also imports process in credentials.test.ts and notes the nesting constraint on useKeyringBackend. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Stage-0 of #1297. Test-only, no
src/changes. Closes #1387.The keyring backend — the default for real users — was never reached through a command, and the auth commands had 0% coverage in
test:local. Both are now covered on both backends. Every new test was mutation-verified.Why
useAuthSetupandrun-cliboth pinAPIFY_DISABLE_KEYRING=1, so no test ever hit the keyring path.src/commands/auth/*ran only undertest:api/test:e2e, which needTEST_USER_TOKEN.getLoggedClientis a secondauth.jsonwriter, separate fromcredentials.ts. Its keyring branch — striptoken, stripproxy.password, dropproxywhen empty — had no test.What
test/__setup__/keyring-mock.ts— shared@napi-rs/keyringfake. ExposeskeyringStore,keyringFailures,keyringSetKeys.useKeyringBackend()inuseAuthSetup.ts— describe-scoped, so one file covers both backends. Throws if the file forgot the mock, rather than writing to the developer's real OS keyring.test/local/commands/auth.test.ts— 11 tests. Stubsapify-client, sologin/logout/auth tokenrun intest:localon both backends.credentials.test.ts— 23 → 42 tests:writeFileSyncspy (F1/F2 could not fail before),0o600, keyring write failures forsetTokenandsetProxyPassword, the stale-credentials throw,resolveTokenviagetApifyClientOptions, the persistedsecretsBackendmarker branch.auth tokencompares stdout to the token, not tolength > 0(F5).All 8 exit criteria in #1387 are met, plus F3 and the account-switch merge that Stage-1 rewrites.
Notes
resolveTokenhas anAPIFY_TOKENbranch. It does not —src/lib/utils.ts:132isexistingToken ?? (ensureMigrated(), getToken()). That variable is read inactor.ts,mcp/install.tsandactor/charge.tsinstead.auth.test.ts:116asserts that fields from the old account survive a re-login. That is current behavior, pinned deliberately, and flagged in a comment.Verification
test:local585 passed / 4 skipped. Lint, format, build, test typecheck clean.test:apinot run locally — no token here; theuseAuthSetup.tschange is one added export.🤖 Generated with Claude Code