Skip to content

test(usage): mock the keychain cache write path in buffer tests - #34

Merged
axisrow merged 1 commit into
mainfrom
test/mock-keychain-write-path
Sep 27, 2026
Merged

axisrow merged 1 commit into
mainfrom
test/mock-keychain-write-path

Conversation

@axisrow

@axisrow axisrow commented Sep 27, 2026

Copy link
Copy Markdown
Owner

What

Follow-up to the #22 review thread (PRRT_kwDOUqBlWc6mTGSl, non-blocking note):

  • beforeEach in usage-token-buffer.test.ts now also mocks fs.writeFileSync and fs.mkdirSync (same pattern as usage-token.test.ts), so no test can touch the real ~/.cache/ccstatusline via the keychain-cache write path.
  • New miss-branch test: a security dump-keychain scan that finds nothing records the keychain-fallback-empty marker (writeFileSync(<…keychain-fallback-empty>, '')) and getUsageToken() returns null — the branch perf(usage): cache empty macOS keychain scans for 30s #22 introduced is now covered, and the mocks are proven by it.

Verification

bun test src/utils/__tests__/usage-token-buffer.test.ts — 2 pass; full suite + lint green on the branch.

🤖 Generated with Claude Code

Follow-up to the #22 review (PRRT_kwDOUqBlWc6mTGSl): only the read
side (statSync) was mocked, so a future full-miss test would write a
real marker into the developer's ~/.cache. Mock writeFileSync and
mkdirSync like usage-token.test.ts does, and add the miss-branch test:
a dump-keychain scan finding nothing must record the
keychain-fallback-empty marker and still yield no token.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@axisrow
axisrow merged commit 7da787a into main Sep 27, 2026
4 checks passed
@axisrow
axisrow deleted the test/mock-keychain-write-path branch September 27, 2026 17:10
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.

1 participant