Skip to content

test: pin auth behavior before the multi-account refactor - #1417

Draft
l2ysho wants to merge 3 commits into
masterfrom
claude/github-issue-1387-d39d52
Draft

test: pin auth behavior before the multi-account refactor#1417
l2ysho wants to merge 3 commits into
masterfrom
claude/github-issue-1387-d39d52

Conversation

@l2ysho

@l2ysho l2ysho commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

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

  • useAuthSetup and run-cli both pin APIFY_DISABLE_KEYRING=1, so no test ever hit the keyring path.
  • src/commands/auth/* ran only under test:api / test:e2e, which need TEST_USER_TOKEN.
  • getLoggedClient is a second auth.json writer, separate from credentials.ts. Its keyring branch — strip token, strip proxy.password, drop proxy when empty — had no test.
  • 6 tests in Stage-0: Verify tests and coverage #1387 were mutation-verified as unable to fail.

What

  • test/__setup__/keyring-mock.ts — shared @napi-rs/keyring fake. Exposes keyringStore, keyringFailures, keyringSetKeys.
  • useKeyringBackend() in useAuthSetup.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. Stubs apify-client, so login / logout / auth token run in test:local on both backends.
  • credentials.test.ts — 23 → 42 tests: writeFileSync spy (F1/F2 could not fail before), 0o600, keyring write failures for setToken and setProxyPassword, the stale-credentials throw, resolveToken via getApifyClientOptions, the persisted secretsBackend marker branch.
  • e2e auth token compares stdout to the token, not to length > 0 (F5).
  • CONTRIBUTING documents the new hook.

All 8 exit criteria in #1387 are met, plus F3 and the account-switch merge that Stage-1 rewrites.

Notes

  • The issue says resolveToken has an APIFY_TOKEN branch. It does not — src/lib/utils.ts:132 is existingToken ?? (ensureMigrated(), getToken()). That variable is read in actor.ts, mcp/install.ts and actor/charge.ts instead.
  • Install size unchanged — no dependency added, and the shared mock is a test file.
  • auth.test.ts:116 asserts that fields from the old account survive a re-login. That is current behavior, pinned deliberately, and flagged in a comment.

Verification

test:local 585 passed / 4 skipped. Lint, format, build, test typecheck clean. test:api not run locally — no token here; the useAuthSetup.ts change is one added export.

🤖 Generated with Claude Code

l2ysho and others added 3 commits September 10, 2026 13:44
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>
@github-actions github-actions Bot added this to the 149th sprint - Tooling team milestone Sep 10, 2026
@github-actions github-actions Bot added t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics. labels Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stage-0: Verify tests and coverage

2 participants