Files
adolf/test/vitest-unit-fast-config.test.ts
alvis bedb527145
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Vendor OpenClaw source as Adolf fork baseline
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11),
free to diverge. Tree copied sans upstream .git; upstream remote added for
future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19.
Preserves docs/ARCHITECTURE.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
2026-07-05 09:36:54 +00:00

234 lines
11 KiB
TypeScript

// Vitest unit-fast config tests validate fast unit test project setup.
import { beforeAll, describe, expect, it } from "vitest";
import { spawnNodeEvalSync } from "../src/test-utils/node-process.js";
import { createCommandsLightVitestConfig } from "./vitest/vitest.commands-light.config.ts";
import { createPluginSdkLightVitestConfig } from "./vitest/vitest.plugin-sdk-light.config.ts";
import { createUnitFastFakeTimersVitestConfig } from "./vitest/vitest.unit-fast-fake-timers.config.ts";
import {
classifyUnitFastTestFileContent,
collectBroadUnitFastTestCandidates,
collectUnitFastTestCandidates,
collectUnitFastTestFileAnalysis,
forcedUnitFastTestFiles,
getUnitFastTestFiles,
getUnitFastTimerTestFiles,
isUnitFastTestFile,
isUnitFastTimerTestFile,
resolveUnitFastTestIncludePattern,
resolveUnitFastTimerTestIncludePattern,
} from "./vitest/vitest.unit-fast-paths.mjs";
import { createUnitFastVitestConfig } from "./vitest/vitest.unit-fast.config.ts";
function requireTestConfig<T extends { test?: unknown }>(config: T): NonNullable<T["test"]> {
if (!config.test) {
throw new Error("expected unit-fast vitest test config");
}
return config.test as NonNullable<T["test"]>;
}
function countMatching<T>(items: readonly T[], predicate: (item: T) => boolean): number {
let count = 0;
for (const item of items) {
if (predicate(item)) {
count += 1;
}
}
return count;
}
type UnitFastAnalysisEntry = ReturnType<typeof collectUnitFastTestFileAnalysis>[number];
function collectUnroutedForcedFiles(
analysis: readonly UnitFastAnalysisEntry[],
forcedFiles: ReadonlySet<string>,
): Array<{ file: string; forced: boolean; unitFast: boolean }> {
const unrouted: Array<{ file: string; forced: boolean; unitFast: boolean }> = [];
for (const entry of analysis) {
if (!forcedFiles.has(entry.file)) {
continue;
}
if (!entry.forced || !entry.unitFast) {
unrouted.push({ file: entry.file, forced: entry.forced, unitFast: entry.unitFast });
}
}
return unrouted;
}
describe("unit-fast vitest lane", () => {
let configProbeResult: ReturnType<typeof spawnNodeEvalSync>;
let unitFastConfig: ReturnType<typeof createUnitFastVitestConfig>;
let unitFastTestFiles: ReturnType<typeof getUnitFastTestFiles>;
let unitFastTimerTestFiles: ReturnType<typeof getUnitFastTimerTestFiles>;
let unitFastAnalysis: ReturnType<typeof collectUnitFastTestFileAnalysis>;
let broadCandidates: ReturnType<typeof collectBroadUnitFastTestCandidates>;
let broadAnalysis: ReturnType<typeof collectUnitFastTestFileAnalysis>;
let currentCandidates: ReturnType<typeof collectUnitFastTestCandidates>;
beforeAll(() => {
const script = `
import fs from "node:fs";
let readdirSyncCalls = 0;
const originalReaddirSync = fs.readdirSync;
fs.readdirSync = function patchedReaddirSync(...args) {
readdirSyncCalls += 1;
return originalReaddirSync.apply(this, args);
};
await import("./test/vitest/vitest.unit-fast.config.ts?io-probe=" + Date.now());
console.log(readdirSyncCalls);
`;
configProbeResult = spawnNodeEvalSync(script, {
env: { ...process.env, FORCE_COLOR: "0", NO_COLOR: "1" },
evalFlag: "-e",
imports: ["tsx"],
});
unitFastConfig = createUnitFastVitestConfig({});
unitFastTestFiles = getUnitFastTestFiles();
unitFastTimerTestFiles = getUnitFastTimerTestFiles();
unitFastAnalysis = collectUnitFastTestFileAnalysis();
currentCandidates = collectUnitFastTestCandidates();
broadCandidates = collectBroadUnitFastTestCandidates();
broadAnalysis = collectUnitFastTestFileAnalysis(process.cwd(), { scope: "broad" });
});
it("loads the config without recursively walking repo roots", () => {
expect(configProbeResult.status, configProbeResult.stderr).toBe(0);
const numericOutputLines = configProbeResult.stdout
.trim()
.split(/\r?\n/u)
.map((line) => Number(line.trim()))
.filter(Number.isFinite);
expect(numericOutputLines.length, configProbeResult.stdout).toBeGreaterThan(0);
expect(numericOutputLines.at(-1)).toBeLessThan(20);
});
it("runs cache-friendly tests without the reset-heavy runner or runtime setup", () => {
const testConfig = requireTestConfig(unitFastConfig);
expect(testConfig.isolate).toBe(false);
expect(testConfig.runner).toBeUndefined();
expect(testConfig.setupFiles).toStrictEqual([]);
expect(testConfig.include).toContain(
"src/agents/agent-tools.deferred-followup-guidance.test.ts",
);
expect(testConfig.include).toContain("src/acp/control-plane/runtime-cache.test.ts");
expect(testConfig.include).toContain("src/acp/runtime/registry.test.ts");
expect(testConfig.include).toContain("src/commands/status-overview-values.test.ts");
expect(testConfig.include).toContain("src/entry.version-fast-path.test.ts");
expect(testConfig.include).toContain("src/flows/doctor-startup-channel-maintenance.test.ts");
expect(testConfig.include).toContain("src/crestodian/rescue-policy.test.ts");
expect(testConfig.include).toContain("src/crestodian/assistant.configured.test.ts");
expect(testConfig.include).toContain("src/flows/search-setup.test.ts");
expect(testConfig.include).toContain("src/plugins/config-policy.test.ts");
expect(testConfig.include).toContain("src/proxy-capture/proxy-server.test.ts");
expect(testConfig.include).toContain("src/talk/agent-consult-tool.test.ts");
expect(testConfig.include).toContain("src/sessions/session-lifecycle-events.test.ts");
expect(testConfig.include).toContain("src/sessions/transcript-events.test.ts");
expect(testConfig.include).toContain("src/security/audit-channel-source-config-slack.test.ts");
expect(testConfig.include).toContain("src/security/audit-config-symlink.test.ts");
expect(testConfig.include).toContain("src/security/audit-exec-sandbox-host.test.ts");
expect(testConfig.include).toContain("src/security/audit-gateway.test.ts");
expect(testConfig.include).toContain("src/security/audit-gateway-auth-selection.test.ts");
expect(testConfig.include).toContain("src/security/audit-gateway-http-auth.test.ts");
expect(testConfig.include).toContain("src/security/audit-gateway-tools-http.test.ts");
expect(testConfig.include).toContain("src/security/audit-plugin-readonly-scope.test.ts");
expect(testConfig.include).toContain("src/security/audit-loopback-logging.test.ts");
expect(testConfig.include).toContain("src/video-generation/provider-registry.test.ts");
expect(testConfig.include).toContain("src/plugin-sdk/provider-entry.test.ts");
expect(testConfig.include).toContain("src/security/dangerous-config-flags.test.ts");
expect(testConfig.include).toContain("src/security/context-visibility.test.ts");
expect(testConfig.include).toContain("src/security/safe-regex.test.ts");
});
it("does not treat moved config paths as CLI include filters", () => {
const config = createUnitFastVitestConfig(
{},
{
argv: ["node", "vitest", "run", "--config", "test/vitest/vitest.unit-fast.config.ts"],
},
);
const testConfig = requireTestConfig(config);
expect(testConfig.include).toContain("src/plugin-sdk/provider-entry.test.ts");
expect(testConfig.include).toContain("src/commands/status-overview-values.test.ts");
});
it("keeps obvious stateful files out of the unit-fast lane", () => {
expect(isUnitFastTestFile("src/plugin-sdk/temp-path.test.ts")).toBe(false);
expect(isUnitFastTestFile("src/agents/sandbox.resolveSandboxContext.test.ts")).toBe(false);
expect(isUnitFastTestFile("src/crestodian/assistant.test.ts")).toBe(false);
expect(isUnitFastTestFile("src/flows/channel-setup.test.ts")).toBe(false);
expect(isUnitFastTestFile("src/flows/doctor-health-contributions.test.ts")).toBe(false);
expect(isUnitFastTestFile("src/plugins/install.npm-spec.test.ts")).toBe(false);
expect(isUnitFastTestFile("src/secrets/runtime.test.ts")).toBe(false);
expect(resolveUnitFastTestIncludePattern("src/plugin-sdk/temp-path.ts")).toBeNull();
expect(classifyUnitFastTestFileContent("vi.resetModules(); await import('./x.js')")).toEqual([
"module-mocking",
"vitest-mock-api",
"dynamic-import",
]);
});
it("routes unit-fast source files to their unit-fast sibling tests", () => {
expect(resolveUnitFastTestIncludePattern("src/plugin-sdk/provider-entry.ts")).toBe(
"src/plugin-sdk/provider-entry.test.ts",
);
expect(resolveUnitFastTestIncludePattern("src/commands/status-overview-values.ts")).toBe(
"src/commands/status-overview-values.test.ts",
);
});
it("routes audited stateful-looking tests through the fast lane", () => {
const forcedFileSet = new Set(forcedUnitFastTestFiles);
const forcedAnalysisCount = countMatching(unitFastAnalysis, (entry) =>
forcedFileSet.has(entry.file),
);
expect(forcedAnalysisCount).toBe(forcedUnitFastTestFiles.length);
for (const file of forcedUnitFastTestFiles) {
expect(unitFastTestFiles).toContain(file);
expect(isUnitFastTestFile(file)).toBe(true);
}
const unroutedForcedFiles = collectUnroutedForcedFiles(unitFastAnalysis, forcedFileSet);
expect(unroutedForcedFiles).toStrictEqual([]);
});
it("routes fake-timer unit-fast tests through the serial fake-timer lane", () => {
const fakeTimerFiles = unitFastAnalysis
.filter((entry) => entry.unitFast && entry.reasons.includes("fake-timers"))
.map((entry) => entry.file);
expect(unitFastTimerTestFiles.length).toBeGreaterThan(0);
expect(unitFastTimerTestFiles).toEqual(fakeTimerFiles);
for (const file of unitFastTimerTestFiles) {
expect(isUnitFastTimerTestFile(file)).toBe(true);
expect(resolveUnitFastTestIncludePattern(file)).toBeNull();
expect(resolveUnitFastTimerTestIncludePattern(file)).toBe(file);
}
const fastConfig = requireTestConfig(unitFastConfig);
const timerConfig = requireTestConfig(createUnitFastFakeTimersVitestConfig({}));
expect(fastConfig.include).not.toEqual(expect.arrayContaining(unitFastTimerTestFiles));
expect(timerConfig.include).toEqual(unitFastTimerTestFiles);
expect(timerConfig.fileParallelism).toBe(false);
expect(timerConfig.maxWorkers).toBe(1);
});
it("keeps broad audit candidates separate from automatically routed unit-fast tests", () => {
expect(currentCandidates.length).toBeGreaterThanOrEqual(unitFastTestFiles.length);
expect(broadCandidates.length).toBeGreaterThan(currentCandidates.length);
expect(countMatching(broadAnalysis, (entry) => entry.unitFast)).toBeGreaterThan(
unitFastTestFiles.length,
);
});
it("excludes unit-fast files from the older light lanes so full runs do not duplicate them", () => {
const pluginSdkLight = createPluginSdkLightVitestConfig({});
const commandsLight = createCommandsLightVitestConfig({});
expect(unitFastTestFiles).toContain("src/plugin-sdk/provider-entry.test.ts");
expect(requireTestConfig(pluginSdkLight).exclude).toContain(
"plugin-sdk/provider-entry.test.ts",
);
expect(requireTestConfig(commandsLight).exclude).toContain("status-overview-values.test.ts");
});
});