test(cli): keep the cli test suite off the operator's ambient QWEN_HOME (#13332)

The verification gate runs the cli suite with the runner's real HOME and
no QWEN_HOME, so the fail-closed operator-settings read in
execution-sandbox-settings.ts hit the runner's real
~/.qwen/settings.json. That file holds invalid JSON on the shared autofix
runners, and 20 test files (455 tests) that load settings or start a
serve stack failed with a FatalConfigError they have nothing to do with.

test-setup.ts already strips other operator-ambient state
(QWEN_RUNTIME_DIR, QWEN_REVIEW_SANDBOX, ...); pin QWEN_HOME to an empty
per-file temp directory there so the suite never reads the operator's
settings. settings.test.ts builds its resolution assertions on a mocked
os.homedir and so needs the ambient variable deleted at module scope.
This commit is contained in:
qwen-code-autofix committed 2026-10-08 06:17:03 +00:00
1 parent be6fb30d29
commit 5068bd91cf
2 files changed
+21

No files matched your search

+6
View File
@@ -95,6 +95,12 @@ vi.mock('@qwen-code/qwen-code-core', async (importOriginal) => {
};
});
// This file's settings resolution is built on the mocked `os.homedir`, so
// the ambient `QWEN_HOME` must not redirect it: test-setup.ts pins the
// variable to an empty directory to keep the suite off the operator's real
// settings. Tests that exercise `QWEN_HOME` itself set it in-body.
delete process.env['QWEN_HOME'];
// Resolve the (mocked) user-settings path once at module load. Tests mock
// `os.homedir`, so the value is stable across the suite. Production callers
// must keep going through `getUserSettingsPath()` to pick up `QWEN_HOME`
+15
View File
@@ -49,6 +49,21 @@ delete process.env['QWEN_RUNTIME_DIR'];
// one explicitly.
delete process.env['QWEN_SERVE_MAX_WORKSPACES'];
// The operator's home directory is ambient state too, and the operator
// settings read (config/execution-sandbox-settings.ts) fails CLOSED on a
// malformed `~/.qwen/settings.json`: on a machine whose real user settings
// file is corrupt — observed on the shared autofix verification runners —
// every test that loads settings or starts a serve stack fails with a
// FatalConfigError it has nothing to do with. Pinning QWEN_HOME to an empty
// per-file directory keeps the suite off the operator's settings. Tests that
// exercise QWEN_HOME resolution itself set or delete the variable in-body.
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
process.env['QWEN_HOME'] = fs.mkdtempSync(
path.join(os.tmpdir(), 'qwen-cli-test-home-'),
);
import { configure } from '@testing-library/react';
import './src/test-utils/customMatchers.js';