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
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
206 lines
7.4 KiB
TypeScript
206 lines
7.4 KiB
TypeScript
// Vitest unit config tests validate unit test project configuration.
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { createPatternFileHelper } from "./helpers/pattern-file.js";
|
|
import { normalizeConfigPath, normalizeConfigPaths } from "./helpers/vitest-config-paths.js";
|
|
import {
|
|
createUnitVitestConfig,
|
|
createUnitVitestConfigWithOptions,
|
|
loadExtraExcludePatternsFromEnv,
|
|
resolveDefaultUnitCoverageIncludePatterns,
|
|
} from "./vitest/vitest.unit.config.ts";
|
|
|
|
const patternFiles = createPatternFileHelper("openclaw-vitest-unit-config-");
|
|
|
|
function requireTestConfig<T extends { test?: unknown }>(config: T): NonNullable<T["test"]> {
|
|
if (!config.test) {
|
|
throw new Error("expected unit vitest test config");
|
|
}
|
|
return config.test as NonNullable<T["test"]>;
|
|
}
|
|
|
|
afterEach(() => {
|
|
patternFiles.cleanup();
|
|
});
|
|
|
|
describe("loadExtraExcludePatternsFromEnv", () => {
|
|
it("returns an empty list when no extra exclude file is configured", () => {
|
|
expect(loadExtraExcludePatternsFromEnv({})).toStrictEqual([]);
|
|
});
|
|
|
|
it("loads extra exclude patterns from a JSON file", () => {
|
|
const filePath = patternFiles.writePatternFile("extra-exclude.json", [
|
|
"src/infra/update-runner.test.ts",
|
|
42,
|
|
"",
|
|
"ui/src/ui/views/chat.test.ts",
|
|
]);
|
|
|
|
expect(
|
|
loadExtraExcludePatternsFromEnv({
|
|
OPENCLAW_VITEST_EXTRA_EXCLUDE_FILE: filePath,
|
|
}),
|
|
).toEqual(["src/infra/update-runner.test.ts", "ui/src/ui/views/chat.test.ts"]);
|
|
});
|
|
|
|
it("throws when the configured file is not a JSON array", () => {
|
|
const filePath = patternFiles.writePatternFile("extra-exclude.json", {
|
|
exclude: ["src/infra/update-runner.test.ts"],
|
|
});
|
|
|
|
expect(() =>
|
|
loadExtraExcludePatternsFromEnv({
|
|
OPENCLAW_VITEST_EXTRA_EXCLUDE_FILE: filePath,
|
|
}),
|
|
).toThrow(/JSON array/u);
|
|
});
|
|
});
|
|
|
|
describe("unit vitest config", () => {
|
|
it("defaults unit tests to the non-isolated runner", () => {
|
|
const unitConfig = createUnitVitestConfig({});
|
|
const testConfig = requireTestConfig(unitConfig);
|
|
expect(testConfig.isolate).toBe(false);
|
|
expect(normalizeConfigPath(testConfig.runner)).toBe("test/non-isolated-runner.ts");
|
|
});
|
|
|
|
it("keeps acp and ui tests out of the generic unit lane", () => {
|
|
const unitConfig = createUnitVitestConfig({});
|
|
const testConfig = requireTestConfig(unitConfig);
|
|
expect(testConfig.exclude).toContain("extensions/**");
|
|
expect(testConfig.exclude).toContain("test/**");
|
|
for (const pattern of [
|
|
"ui/src/ui/app-chat.test.ts",
|
|
"ui/src/ui/chat/**/*.test.ts",
|
|
"ui/src/ui/views/chat.test.ts",
|
|
]) {
|
|
expect(testConfig.include).not.toContain(pattern);
|
|
}
|
|
});
|
|
|
|
it("narrows the active include list to CLI file filters when present", () => {
|
|
const unitConfig = createUnitVitestConfigWithOptions(
|
|
{},
|
|
{
|
|
argv: ["node", "vitest", "run", "src/commitments/store.test.ts"],
|
|
},
|
|
);
|
|
const testConfig = requireTestConfig(unitConfig);
|
|
expect(testConfig.include).toEqual(["src/commitments/store.test.ts"]);
|
|
expect(testConfig.passWithNoTests).toBeUndefined();
|
|
});
|
|
|
|
it("lets root Vitest project runs skip unit files owned by excluded projects", () => {
|
|
const unitConfig = createUnitVitestConfigWithOptions(
|
|
{},
|
|
{
|
|
argv: ["node", "vitest", "run", "src/config/channel-configured.test.ts"],
|
|
},
|
|
);
|
|
const testConfig = requireTestConfig(unitConfig);
|
|
expect(testConfig.include).toEqual(["src/config/channel-configured.test.ts"]);
|
|
expect(testConfig.passWithNoTests).toBe(true);
|
|
});
|
|
|
|
it("lets unrelated root Vitest projects skip when CLI filters match no unit files", () => {
|
|
const unitConfig = createUnitVitestConfigWithOptions(
|
|
{},
|
|
{
|
|
argv: ["node", "vitest", "run", "extensions/browser/index.test.ts"],
|
|
},
|
|
);
|
|
const testConfig = requireTestConfig(unitConfig);
|
|
expect(testConfig.include).toEqual([]);
|
|
expect(testConfig.passWithNoTests).toBe(true);
|
|
});
|
|
|
|
it("adds the OpenClaw runtime setup hooks on top of the base setup", () => {
|
|
const unitConfig = createUnitVitestConfig({});
|
|
const testConfig = requireTestConfig(unitConfig);
|
|
expect(normalizeConfigPaths(testConfig.setupFiles)).toEqual([
|
|
"test/setup.ts",
|
|
"test/setup-openclaw-runtime.ts",
|
|
]);
|
|
});
|
|
|
|
it("appends extra exclude patterns instead of replacing the base unit excludes", () => {
|
|
const unitConfig = createUnitVitestConfigWithOptions(
|
|
{},
|
|
{
|
|
extraExcludePatterns: ["src/security/**"],
|
|
},
|
|
);
|
|
const testConfig = requireTestConfig(unitConfig);
|
|
expect(testConfig.exclude).toContain("src/commands/**");
|
|
expect(testConfig.exclude).toContain("src/config/**");
|
|
expect(testConfig.exclude).toContain("src/security/**");
|
|
});
|
|
|
|
it("skips default coverage source discovery when coverage is disabled", () => {
|
|
const unitConfig = createUnitVitestConfig({});
|
|
const testConfig = requireTestConfig(unitConfig);
|
|
|
|
expect(testConfig.coverage?.include).toBeUndefined();
|
|
});
|
|
|
|
it("scopes default coverage to source files owned by the unit lane", () => {
|
|
const unitConfig = createUnitVitestConfigWithOptions(
|
|
{},
|
|
{
|
|
argv: ["node", "vitest", "run", "--coverage"],
|
|
},
|
|
);
|
|
const testConfig = requireTestConfig(unitConfig);
|
|
const coverageInclude = testConfig.coverage?.include;
|
|
expect(coverageInclude).toContain("src/commitments/runtime.ts");
|
|
expect(coverageInclude).toContain("src/media-generation/runtime-shared.ts");
|
|
expect(coverageInclude).toContain("src/web-search/runtime.ts");
|
|
expect(coverageInclude).not.toContain("packages/markdown-core/src/render.ts");
|
|
expect(coverageInclude).not.toContain("src/security/audit-workspace-skills.ts");
|
|
});
|
|
|
|
it("derives default coverage includes from non-fast unit tests with sibling source files", () => {
|
|
const coverageInclude = resolveDefaultUnitCoverageIncludePatterns();
|
|
expect(coverageInclude).toContain("packages/memory-host-sdk/src/host/embeddings.ts");
|
|
expect(coverageInclude).toContain("src/commitments/store.ts");
|
|
expect(coverageInclude).toContain("src/tools/planner.ts");
|
|
});
|
|
|
|
it("leaves coverage include filters unset for explicit unit include lists", () => {
|
|
const unitConfig = createUnitVitestConfigWithOptions(
|
|
{},
|
|
{
|
|
includePatterns: ["src/commitments/runtime.test.ts"],
|
|
},
|
|
);
|
|
const testConfig = requireTestConfig(unitConfig);
|
|
|
|
expect(testConfig.coverage?.include).toBeUndefined();
|
|
});
|
|
|
|
it("keeps bundled unit include files out of the resolved exclude list", () => {
|
|
const unitConfig = createUnitVitestConfigWithOptions(
|
|
{},
|
|
{
|
|
includePatterns: [
|
|
"src/infra/matrix-plugin-helper.test.ts",
|
|
"src/plugin-sdk/facade-runtime.test.ts",
|
|
"src/plugins/loader.test.ts",
|
|
],
|
|
},
|
|
);
|
|
const testConfig = requireTestConfig(unitConfig);
|
|
|
|
expect(testConfig.include).toEqual([
|
|
"src/infra/matrix-plugin-helper.test.ts",
|
|
"src/plugin-sdk/facade-runtime.test.ts",
|
|
"src/plugins/loader.test.ts",
|
|
]);
|
|
expect(testConfig.exclude).not.toContain("src/infra/**");
|
|
expect(testConfig.exclude).not.toContain("src/plugin-sdk/**");
|
|
expect(testConfig.exclude).not.toContain("src/plugins/**");
|
|
expect(testConfig.exclude).not.toContain("src/infra/matrix-plugin-helper.test.ts");
|
|
expect(testConfig.exclude).not.toContain("src/plugin-sdk/facade-runtime.test.ts");
|
|
expect(testConfig.exclude).not.toContain("src/plugins/loader.test.ts");
|
|
});
|
|
});
|