Skip to content

[TEST] keychain test isolation — sweep stray items in isolated-home teardown - #23

Open
gradyzhuo wants to merge 3 commits into
mainfrom
feat/keychain-test-isolation
Open

[TEST] keychain test isolation — sweep stray items in isolated-home teardown#23
gradyzhuo wants to merge 3 commits into
mainfrom
feat/keychain-test-isolation

Conversation

@gradyzhuo

Copy link
Copy Markdown
Member

Test-only fix (no production changes). Implements docs/superpowers/specs/2026-07-07-keychain-test-isolation-design.md.

Problem

The macOS login Keychain is globalORRERY_HOME doesn't isolate it. Tests that run a claude keychain write against the real Claude Code-credentials service leave stray Claude Code-orrery-<uuid> items in the developer's real keychain. ~2894 had accumulated; a full swift test added ~7/run. Primary source: AccountMigrationTestsAccountMigration.runIfNeededmigrateOrigin(.claude) reads the real default service and copies it to a new per-account service.

Fix (test harness only)

  • Add sweepClaudeKeychain(home:) (TestHelpers.swift): after a test, delete each isolated claude account's per-account keychain service (the deterministic serviceName(forOrreryAccount:) + any explicit keychainItem), by service name.
  • Call it from the teardown of both isolated-home helpers: withIsolatedHome and AccountMigrationTests.makeTempHome.
  • No production code touched (an earlier production-KeychainAccess-seam draft was rejected as churn for a test-only concern).

Result

  • Backlog cleaned locally (~2894 → 7 legit accounts).
  • Per-run growth ~7 → ~1. Full suite green (382).

Known follow-up

A residual ~1/run remains from a source not identifiable by static analysis. Pinning it needs runtime instrumentation (temporary stack-trace in ClaudeKeychain write funcs, reverted after) — deferred to a focused follow-up.

🤖 Generated with Claude Code

gradyzhuo added 3 commits July 7, 2026 21:39
The macOS login Keychain is global — ORRERY_HOME does not isolate it — so tests
that run claude keychain writes (notably AccountMigrationTests via
AccountMigration.runIfNeeded -> migrateOrigin(claude), which reads the real
Claude Code-credentials service) leave stray Claude Code-orrery-* items in the
developer's real keychain (~2900 had accumulated; the suite added ~7/run).

Add sweepClaudeKeychain(home:) and call it from withIsolatedHome and
AccountMigrationTests.makeTempHome teardown — deletes each isolated claude
account's per-account service (by name) after the test. Test-only; no production
change. Reduces per-run growth from ~7 to a residual ~1 from an as-yet-unpinned
source (needs runtime instrumentation; tracked as follow-up).
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