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

+10 -4
View File
@@ -28,6 +28,10 @@ const STYLES_CSS = readFileSync(new URL('../src/web/public/styles.css', import.m
// every other test in this file stubs _showCenterStatus itself and has no need of it.
const PANELS_UI_JS = readFileSync(new URL('../src/web/public/panels-ui.js', import.meta.url), 'utf-8');
// The warning formats counts with the runtime's own locale (a German user reads 131.072), so the
// expectations ask the same runtime instead of hard-coding the en-US grouping.
const num = (n: number) => n.toLocaleString();
function resp(body: unknown, ok = true) {
return { ok, json: async () => body };
}
@@ -1770,8 +1774,8 @@ describe('Custom Model Endpoint Profiles: _confirmContextWarning (in-app modal,
const message = win.document.getElementById('customModelContextWarningMessage')!.textContent!;
expect(message).toContain('qwen3.8-27b-ud-q4_k_xl');
expect(message).toContain('4 parallel');
expect(message).toContain('131,072');
expect(message).toContain('32,768'); // per slot
expect(message).toContain(num(131072));
expect(message).toContain(num(32768)); // per slot
expect(message).toContain('--parallel 1');
expect(message).toContain('Context size has been exceeded');
// this is not the "first message fails outright" case, so it must not claim that
@@ -1784,7 +1788,9 @@ describe('Custom Model Endpoint Profiles: _confirmContextWarning (in-app modal,
const { win, app } = bootApp({});
void app._confirmContextWarning('qwen3', 65536, 40000, 4);
const message = win.document.getElementById('customModelContextWarningMessage')!.textContent!;
expect(message).toContain('65,536 tokens of context are split across 4 parallel server slots, about 16,384 each');
expect(message).toContain(
`${num(65536)} tokens of context are split across 4 parallel server slots, about ${num(16384)} each`
);
app._resolveContextWarningConfirm(false);
});
@@ -1792,7 +1798,7 @@ describe('Custom Model Endpoint Profiles: _confirmContextWarning (in-app modal,
const { win, app } = bootApp({});
void app._confirmContextWarning('qwen3', 16384, 40000, 4);
const message = win.document.getElementById('customModelContextWarningMessage')!.textContent!;
expect(message).toContain('16,384');
expect(message).toContain(num(16384));
expect(message).toMatch(/first message will fail/i);
expect(message).toContain('4 parallel slots');
expect(message).toContain('--parallel 1');
+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 });
});