test: keep two tests independent of the host's locale and git ignore file

Four tests failed on a machine with a de_DE locale and a global git ignore
file, with no product change involved:

- custom-model-run-menu-ui (3): the warning formats counts with the runtime
  locale (131.072 under de_DE) and the tests hard-coded 131,072. The
  expectations now ask the same runtime through toLocaleString().
- git-worktrees (1): git also reads $XDG_CONFIG_HOME/git/ignore, which
  GIT_CONFIG_GLOBAL does not cover. A global ignore of
  .claude/settings.local.json kept the exclude line from being appended. The
  test now points XDG_CONFIG_HOME and GIT_CONFIG_GLOBAL away for the code
  under test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RandalixandClaude Opus 5.5 committed 2026-11-06 12:25:23 +01:00
1 parent fc25bf5f83
commit 5cdd34bddf
2 files changed
+18 -5

No files matched your search

+8 -1
View File
@@ -17,7 +17,7 @@ import {
} from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import {
agentSkillExcludeLine,
createCaseWorktree,
@@ -50,6 +50,7 @@ const ENV = {
GIT_COMMITTER_EMAIL: 't@example.com',
GIT_CONFIG_GLOBAL: '/dev/null',
GIT_CONFIG_NOSYSTEM: '1',
XDG_CONFIG_HOME: '/nonexistent-xdg',
};
const git = (cwd: string, ...args: string[]) =>
execFileSync('git', args, { cwd, env: ENV, encoding: 'utf-8', stdio: ['ignore', 'pipe', 'pipe'] });
@@ -205,6 +206,11 @@ describe('git worktrees on a real repository', () => {
beforeEach(async () => {
dir = realpathSync(mkdtempSync(join(tmpdir(), 'git-worktrees-')));
// The code under test runs git with the real process env. git reads the global ignore file
// from $XDG_CONFIG_HOME/git/ignore, which GIT_CONFIG_GLOBAL does not cover: a user who
// ignores `.claude/settings.local.json` globally would see that line silently not appended.
vi.stubEnv('XDG_CONFIG_HOME', join(dir, 'xdg'));
vi.stubEnv('GIT_CONFIG_GLOBAL', '/dev/null');
repoDir = join(dir, 'repo');
mkdirSync(repoDir);
git(repoDir, 'init', '-q', '-b', 'main');
@@ -216,6 +222,7 @@ describe('git worktrees on a real repository', () => {
repo = resolved.repo;
});
afterEach(() => {
vi.unstubAllEnvs();
rmSync(dir, { recursive: true, force: true });
});