Repository navigation
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
37 lines (35 loc) · 1.87 KB
/
Copy pathvitest.setup.ts
File metadata and controls
37 lines (35 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Global test hermeticity: pin the complete OpenAlice home and every supported
* split-root override to one per-worker temp tree. Module-level path constants,
* migration journals, Workspace stores, and provider-key stores must never
* resolve into the developer's real data.
*
* Runs before each test file's module graph is imported (vitest setupFiles
* semantics). Specs that need a
* specific home (paths.spec, global-provider-keys.spec) still override via
* vi.resetModules() + their own env handling.
*
* Wired into both hermetic unit/component tests and deterministic local
* integration tests. Only the explicit external-readonly and live-paper
* configs intentionally retain access to real local provider configuration.
*/
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
// Unit tests must never inherit either half of a live split-root setup. In
// particular, pinning OPENALICE_HOME while retaining a real AQ_LAUNCHER_ROOT
// lets a migration journal in the temporary home rewrite real Workspaces.
const testHome = process.env['OPENALICE_TEST_HOME']
?? mkdtempSync(join(tmpdir(), 'oa-vitest-'))
mkdirSync(testHome, { recursive: true })
const gitConfigPath = join(testHome, 'gitconfig')
// An empty global config still inherits $XDG_CONFIG_HOME/git/ignore (or
// ~/.config/git/ignore). Explicitly replace that default with an empty file.
const gitExcludesPath = join(testHome, 'git-excludes')
writeFileSync(gitExcludesPath, '')
writeFileSync(gitConfigPath, `[core]\n\texcludesFile = ${JSON.stringify(gitExcludesPath.replaceAll('\\', '/'))}\n`)
process.env['GIT_CONFIG_GLOBAL'] = gitConfigPath
process.env['GIT_CONFIG_NOSYSTEM'] = '1'
process.env['OPENALICE_HOME'] = testHome
process.env['AQ_LAUNCHER_ROOT'] = join(testHome, 'workspaces')
process.env['OPENALICE_GLOBAL_DIR'] = join(testHome, 'global')