Skip to content

test(claude-settings): isolate install tests from the real home directory - #717

Merged
sirmalloc merged 1 commit into
sirmalloc:mainfrom
axisrow:fix/716-isolate-claude-settings-tests
Oct 26, 2026
Merged

sirmalloc merged 1 commit into
sirmalloc:mainfrom
axisrow:fix/716-isolate-claude-settings-tests

Conversation

@axisrow

@axisrow axisrow commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Why

#716: the install tests in claude-settings.test.ts run against the real home directory. One test resets the ccstatusline config path to the actual ~/.config/ccstatusline/settings.json, another deletes CLAUDE_CONFIG_DIR without restoring it, so later install tests operate on the real ~/.claude/settings.json. Under a mutation-testing run over config.ts/claude-settings.ts this destroyed both of my live configs: default settings were materialised over a hand-tuned statusline config, and statusLine was pointed at a client inside the Stryker sandbox, which is deleted after the run — the status line went empty.

What this does

  • claude-settings.test.ts: beforeEach points os.homedir() at the temp directory (and restores CLAUDE_CONFIG_DIR in afterEach, which the default-path test deletes mid-test). Every home lookup in the file now resolves into the temp directory, so no install test can touch the developer's real configs even when the settings parse is broken.
  • config.ts: the default settings path is resolved on every call instead of once at import time, so the mocked home is honored after the module has loaded. Runtime behavior is unchanged (home never changes in a live process).
  • afterEach no longer leaves the real config path active after vi.restoreAllMocks().

Verification

  • bun test src/utils/__tests__/claude-settings.test.ts src/utils/__tests__/config.test.ts: 138 pass.
  • Full suite: 3112 pass / 0 fail.
  • Rerun of the same tests with mtime guards on both real config files: untouched (REAL-FILES-UNTOUCHED).

Closes #716

🤖 Generated with Claude Code

…tory

The install tests reset the ccstatusline config path to the real ~/.config location and, after one test deletes CLAUDE_CONFIG_DIR without restoring it, write the real ~/.claude/settings.json. Under mutation testing a broken settings parse materialised defaults over a live config and pointed statusLine at a file inside the deleted Stryker sandbox (issue sirmalloc#716).

os.homedir() is mocked into the temp directory for the whole file and the default settings path is resolved on every call instead of once at import, so no test can reach the real home even when the parse is broken. afterEach restores CLAUDE_CONFIG_DIR for tests that delete it.

Verified: claude-settings + config tests 138 pass; full suite 3112 pass; mtime guards on both real config files show them untouched during a rerun.

Closes sirmalloc#716

Co-Authored-By: Claude Code <noreply@anthropic.com>
@sirmalloc
sirmalloc merged commit 59ada51 into sirmalloc:main Oct 26, 2026
3 checks passed
axisrow added a commit to axisrow/ccstatusline that referenced this pull request Oct 27, 2026
…it names, sirmalloc#717 claude-settings test isolation, sirmalloc#705 jj detached HEAD, sirmalloc#703 hooks save warning, sirmalloc#700 dev reload, sirmalloc#698 renderer merge ends at hidden widget, sirmalloc#697 block reset timer under-limit hide, sirmalloc#745 dev-deps bumps

Conflict policy: upstream infra wins, fork features ported on top (fork-only
src/daemon/, src/widgets/editors/*, parity fixtures and fork widgets kept).
Notable joins: sirmalloc#703 returns SkippedWidgetHooks through the fork's
saveSettingsTo wrapper; sirmalloc#697 keeps the fork's zero hide state alongside
upstream's under-limit state; sirmalloc#698 replaces the fork's merge-glue palette
semantics with upstream's merge-ends-at-unmerged-empty-widget rule;
dev-reload (ctrl+r) composes with the fork's first-run preset picker.

Co-Authored-By: Claude Code <noreply@anthropic.com>
pcvelz added a commit to pcvelz/ccstatusline-usage that referenced this pull request Oct 29, 2026
Upstream: Extra Usage Limit widget (sirmalloc#756), live widget preview while picking (sirmalloc#755), Fast Mode widget (sirmalloc#754), transcript block fallback fixes (sirmalloc#752), editor keys on a global install (sirmalloc#751), git cache TTL (sirmalloc#750), npx cached copy skip (sirmalloc#749), Block Usage hide at 100% (sirmalloc#747), Block Reset Timer hide until 100% (sirmalloc#697), fish-style branch abbreviation (sirmalloc#614), jj detached HEAD (sirmalloc#705), hooks save warning (sirmalloc#703), dev reload (sirmalloc#700), merge ends at a hidden widget (sirmalloc#698), Block Forecast and Block Limit Timer widgets (sirmalloc#699), contributor guide (sirmalloc#706), POSIX path case fix (sirmalloc#707), whitespace-distinct conflict filenames (sirmalloc#709), Quick Start reorder (sirmalloc#715), bunx launch guidance (sirmalloc#714), jj diff summary counts (sirmalloc#711), powerline manual separators (sirmalloc#713), keychain credential by account (sirmalloc#532), Keychain probe timeout (sirmalloc#760), usage cache scoped per CLAUDE_CONFIG_DIR (sirmalloc#266), test isolation (sirmalloc#717, sirmalloc#753), dev-dependency bumps (sirmalloc#745)

Conflicts resolved per the standard-resolution table; fork deletions re-applied.

Hand edits outside conflicts:
- src/utils/global-command-resolution.ts: fork-rename (ccstatusline@ -> ccstatusline-usage@ in upstream's new bunx pattern)
- src/utils/__tests__/global-package-manager.test.ts: fork-rename (package dir ccstatusline-usage in upstream's new tests)
- src/utils/usage-fetch.ts: compat fix - cacheUsageData gained a fetchedAtMs arg (upstream sirmalloc#266); adapted the fork-only fetchFreshUsageData call site
- src/utils/__tests__/usage-fetch.test.ts: compat fixes - cache/lock now hashed per CLAUDE_CONFIG_DIR (usageFilePath helper) in four fork tests; upstream fableUsage renamed to fork's weeklyFableUsage; seedUsageCache takes TokenHome
- src/utils/__tests__/usage-prefetch.test.ts: compat fix - mockFetchUsageData renamed to upstream's mockFetchUsage in cleanly-merged tests
- README.md: took upstream's Quick Start move (sirmalloc#715) and dropped the fork's old copy; fork-rename of its ccstatusline@ specifiers; links to fork-deleted docs (docs/USAGE.md, docs/WINDOWS.md) replaced with the fork's inline text
- CONTRIBUTING.md: links to the fork-deleted docs/DEVELOPMENT.md pointed at the README Development section
- docs/test-retirements.md: ledger entries for the 12 upstream test renames (sirmalloc#697, sirmalloc#698, sirmalloc#700, sirmalloc#705, sirmalloc#713, sirmalloc#760)
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.

claude-settings.test.ts: installStatusLine tests run against the real home directory and can destroy a user's configs

2 participants

⌂ Proxy