-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathvitest.config.ts
More file actions
255 lines (250 loc) · 11.1 KB
/
Copy pathvitest.config.ts
File metadata and controls
255 lines (250 loc) · 11.1 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
import { availableParallelism } from "node:os";
import path from "node:path";
import { defineConfig, defineProject } from "vitest/config";
import pluginVitestProjectOptions from "./nemoclaw/vitest.project";
import { shouldRunLiveE2E } from "./test/e2e/fixtures/live-project-gate.ts";
import { CliCoverageSequencer } from "./test/helpers/cli-coverage-sequencer";
import { resolveIntegrationProjectScheduling } from "./test/helpers/integration-project-scheduling";
import { sourceLoaderNodeOptions } from "./test/helpers/source-loader-options";
import { testTimeout } from "./test/helpers/timeouts";
import { resolveVitestCoverageThresholds } from "./test/helpers/vitest-coverage-thresholds";
import { resolveVitestFeedback } from "./test/helpers/vitest-feedback";
import { vitestStateIsolation } from "./test/helpers/vitest-state-isolation";
import { vitestWatchTriggerPatterns } from "./test/helpers/vitest-watch-triggers";
const { isCi, silent } = resolveVitestFeedback();
const LIVE_E2E_PROJECT_TIMEOUT_MS = 30 * 60 * 1000;
const runLiveE2E = shouldRunLiveE2E();
const canonicalOpenShellPolicyBoundary = path.resolve(
"nemoclaw/src/shared/openshell-policy-boundary.cts",
);
const canonicalSandboxName = path.resolve("nemoclaw/src/shared/sandbox-name.cts");
// Map the generated shared .cjs specifiers back to their .cts source so
// source-mode test projects exercise the single source of truth rather than a
// possibly-stale build artifact.
const canonicalSourceAliases = [
{
find: /^.*openshell-policy-boundary\.cjs$/,
replacement: canonicalOpenShellPolicyBoundary,
},
{
find: /^.*sandbox-name\.cjs$/,
replacement: canonicalSandboxName,
},
];
const e2ePhaseCollectionAlias =
process.env.NEMOCLAW_E2E_PHASE_COLLECTION === "1"
? [
{
find: "../../../dist/lib/onboard/docker-driver-gateway-launch",
replacement: path.resolve("src/lib/onboard/docker-driver-gateway-launch.ts"),
},
{
find: "../../../dist/lib/onboard/docker-driver-gateway-local-tls",
replacement: path.resolve("src/lib/onboard/docker-driver-gateway-local-tls.ts"),
},
]
: [];
const typedSourceTransform = {
oxc: {
include: /\.(?:[cm]?ts|[jt]sx)$/,
},
};
const sourceNodeOptions = sourceLoaderNodeOptions(process.env.NODE_OPTIONS);
const controlledNonLiveEnv = {
NEMOCLAW_DISABLE_GATEWAY_DRIFT_PREFLIGHT: "1",
};
// Pin the file-creation umask of every non-live test worker to exactly 0o022 —
// the conventional CI baseline — so Hermes/OpenClaw guard fixtures are created
// with deterministic modes regardless of the developer's ambient umask (e.g. a
// permissive 0002 on Ubuntu 24.04 would otherwise make them group-writable and
// the guard would reject them). The live/credential-bearing E2E projects are
// intentionally excluded below and keep their own stricter umask handling. See
// test/helpers/normalize-fixture-umask.ts (#6448).
const fixtureUmaskSetup = "test/helpers/normalize-fixture-umask.ts";
const pluginVitestProject = defineProject(pluginVitestProjectOptions);
const integrationProjectScheduling = resolveIntegrationProjectScheduling({
isCi,
npmLifecycleEvent: process.env.npm_lifecycle_event,
argv: process.argv.slice(2),
availableParallelism: availableParallelism(),
});
export default defineConfig({
test: {
globalSetup: "test/helpers/vitest-temp-root.ts",
tags: [
{
name: "e2e/credential-free",
description: "Runs without external credentials in the shared E2E job",
},
],
// Let Vitest select its environment-aware local reporter and add GitHub
// annotations in Actions. CI suppresses passed-test logs while replaying
// the console output attached to failures.
silent,
hideSkippedTests: isCi,
watchTriggerPatterns: vitestWatchTriggerPatterns,
sequence: { sequencer: CliCoverageSequencer },
projects: [
{
...typedSourceTransform,
test: {
...vitestStateIsolation,
name: "cli",
alias: canonicalSourceAliases,
env: controlledNonLiveEnv,
testTimeout: testTimeout(),
setupFiles: [fixtureUmaskSetup, "test/helpers/onboard-script-mocks.cjs"],
include: ["src/**/*.test.ts"],
exclude: ["**/node_modules/**", "**/.claude/**"],
},
},
{
...typedSourceTransform,
test: {
...vitestStateIsolation,
name: "integration",
alias: canonicalSourceAliases,
// Source-backed process fixtures can exceed the unit-test budget
// when several coverage shards transpile and spawn them concurrently.
testTimeout: testTimeout(15_000),
setupFiles: [fixtureUmaskSetup, "test/helpers/onboard-script-mocks.cjs"],
// Integration fixtures often spawn short Node programs. Coverage
// stays serial because concurrent source-loader forks exhaust the
// 7 GiB CI runner. The canonical local full suite instead runs this
// project as a bounded four-worker phase after the other projects.
...integrationProjectScheduling,
env: {
...controlledNonLiveEnv,
NODE_OPTIONS: sourceNodeOptions,
// Integration fixtures exercise onboarding against controlled fake
// Docker state. Keep a base-image Dockerfile change in the PR from
// redirecting those fixtures into the real local-build guard.
NEMOCLAW_SANDBOX_BASE_IMAGE_REF:
"ghcr.io/nvidia/nemoclaw/sandbox-base@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
},
include: ["test/**/*.test.{js,ts}"],
exclude: [
"**/node_modules/**",
"**/.claude/**",
"test/e2e/**",
"test/e2e/live/**",
"test/e2e/support/**",
"test/package-contract/**",
"test/install-express-prompt.test.ts",
"test/install-express-wsl-ollama.test.ts",
"test/install-station-vllm-continuation.test.ts",
"test/install-build-dependency-preflight.test.ts",
"test/install-clone-ref.test.ts",
"test/install-preflight.test.ts",
"test/install-preflight-docker-bootstrap.test.ts",
"test/install-station-controller-binding.test.ts",
"test/install-station-pair-preparation.test.ts",
"test/install-station-resume-cleanup.test.ts",
"test/install-station-dgx-os.test.ts",
"test/install-station-docker-repository.test.ts",
"test/install-station-host-preparation.test.ts",
"test/install-station-package-state.test.ts",
"test/install-station-package-transaction.test.ts",
"test/install-openshell-version-pin.test.ts",
"test/install-openshell-version-check.test.ts",
],
},
},
{
...typedSourceTransform,
test: {
...vitestStateIsolation,
name: "installer-integration",
alias: canonicalSourceAliases,
env: controlledNonLiveEnv,
setupFiles: [fixtureUmaskSetup],
include: [
"test/install-express-prompt.test.ts",
"test/install-express-wsl-ollama.test.ts",
"test/install-station-vllm-continuation.test.ts",
"test/install-build-dependency-preflight.test.ts",
"test/install-clone-ref.test.ts",
"test/install-preflight.test.ts",
"test/install-preflight-docker-bootstrap.test.ts",
"test/install-station-controller-binding.test.ts",
"test/install-station-pair-preparation.test.ts",
"test/install-station-resume-cleanup.test.ts",
"test/install-station-dgx-os.test.ts",
"test/install-station-docker-repository.test.ts",
"test/install-station-host-preparation.test.ts",
"test/install-station-package-state.test.ts",
"test/install-station-package-transaction.test.ts",
"test/install-openshell-version-pin.test.ts",
"test/install-openshell-version-check.test.ts",
],
// Slow tests that spawn real bash install.sh processes. Explicit
// project selection keeps them out of the fast source-test command.
},
},
{
...typedSourceTransform,
test: {
...vitestStateIsolation,
name: "package-contract",
alias: canonicalSourceAliases,
env: controlledNonLiveEnv,
setupFiles: [fixtureUmaskSetup],
include: ["test/package-contract/**/*.test.ts"],
},
},
pluginVitestProject,
{
...typedSourceTransform,
test: {
...vitestStateIsolation,
// Fast tests for the E2E fixture/support layer. Vitest remains the
// only harness; this project does not define a separate runner.
name: "e2e-support",
alias: canonicalSourceAliases,
env: controlledNonLiveEnv,
testTimeout: testTimeout(),
setupFiles: [fixtureUmaskSetup, "test/helpers/onboard-script-mocks.cjs"],
include: ["test/e2e/support/**/*.test.ts"],
},
},
{
...typedSourceTransform,
test: {
name: "e2e-live",
alias: [...canonicalSourceAliases, ...e2ePhaseCollectionAlias],
// Register the typed-source require hook in the worker so live suites
// can import source modules that resolve siblings via a runtime
// `require("../module")` (e.g. inference/ollama-runtime-context.ts).
// Use setupFiles rather than NODE_OPTIONS so the hook stays in-process
// and never leaks `--require` into the real CLI subprocesses under
// test. Mirrors the `cli` project.
//
// Intentionally excludes the fixture-umask setup: live E2E has no
// guard-fixture suites and handles real credentials, so it must keep
// the caller's umask (and sets its own strict `umask 077` inline).
setupFiles: ["test/helpers/onboard-script-mocks.cjs"],
testTimeout: testTimeout(LIVE_E2E_PROJECT_TIMEOUT_MS),
// Live targets mutate host, Docker, gateway, and sandbox state. A
// whole-test retry reuses that state and can hide the first failure
// behind stale locks or exhausted storage. Transient operations must
// retry inside the target after proving their cleanup boundary.
fileParallelism: false,
retry: 0,
include: runLiveE2E ? ["test/e2e/live/**/*.test.ts"] : [],
// Live E2E tests are opt-in because they install, onboard, and
// mutate real NemoClaw/OpenShell state. Run explicitly with:
// NEMOCLAW_RUN_LIVE_E2E=1 npx vitest run --project e2e-live
},
},
],
coverage: {
provider: "v8",
include: ["src/**/*.ts", "bin/**/*.js", "nemoclaw/src/**/*.ts", "nemoclaw/src/**/*.cts"],
exclude: ["**/*.test.ts", "dist/**"],
reporter: ["text-summary", "json-summary"],
thresholds: resolveVitestCoverageThresholds(process.argv.slice(2)),
},
},
});