mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-19 18:11:35 +00:00
* chore(types): add declaration files for scripts/lib and scripts/e2e modules
* chore(types): add declaration files for top-level script modules (a-m)
* chore(types): add declaration files for top-level script modules (n-z)
* test: use a non-secret-shaped gateway token fixture
* test: type ci workflow guard helpers for the root test lane
* chore(tooling): typecheck root test/** with a dedicated tsgo lane
- test/tsconfig/tsconfig.test.root.json: root-test program (strict unused checks,
fixtures excluded; two Docker E2E clients that import built dist/** stay out,
same rationale as the scripts/e2e exclusion in tsconfig.scripts.json)
- tsgo:test:root wired into tsgo:test, check:test-types, scripts/check.mjs, and
the ci.yml test-types shard, mirroring the tsgo:scripts lane (#104348)
- changed-lane routing: test/**/*.ts (excluding fixtures) and the lane tsconfig
now trigger 'typecheck test root' in check:changed; previously test/ paths ran
lint only, so harness type errors surfaced first in CI (#104287 envDir case)
- burn down all 1071 latent type errors in the program: precise param/local
types across test/scripts, test/vitest, test/e2e, and transitive scripts/e2e
program members; 205 sibling .d.mts declaration files for imported .mjs
modules (committed separately); zero any, zero ts-expect-error
- resolve the pre-existing testing star-export ambiguity in
scripts/e2e/parallels/common.ts with an explicit re-export
Closes #104388
* chore(types): correct declaration fidelity per structured review
- re-derive 51 .d.mts files from implementation data flow instead of
initializers: fix a wrong never return (runTestProjectsDelegation returns
the child), add encoding-sensitive exec/spawn overloads (plain-gh), restore
the full release profile union, make parsed paths string | null, add missing
parseArgs fields via help/non-help unions, add a missing sibling declaration
(budget-number-args), drop 15 unused lint directives
- precise install-record/tuple typing removes the type-aware oxlint
regressions the first declarations caused in scripts/e2e implementations
- route .mts declaration edits under test/ to the testRoot lane and reference
the test-root project from tsconfig.projects.json so tsgo:all covers it
(closes both review findings against the lane wiring)
* chore(scripts): keep telegram runner dist typing structural for the boundary guard
* chore(types): declare runtime pack and gateway readiness exports added on main
* test: pin the importTargetPlan form of the plugin-contract plan import
The guard expectation still referenced the raw await import( form that
7ae5996bb3 (#103975) replaced with the importTargetPlan fallback helper;
the assertion fails on current main.
279 lines
8.2 KiB
TypeScript
279 lines
8.2 KiB
TypeScript
// Vitest scoped config helper builds test configs for scoped file patterns.
|
|
import path from "node:path";
|
|
import { defineConfig } from "vitest/config";
|
|
import { loadPatternListFromEnv, narrowIncludePatternsForCli } from "./vitest.pattern-file.ts";
|
|
import {
|
|
nonIsolatedRunnerPath,
|
|
repoRoot,
|
|
resolveRepoRootPath,
|
|
sharedVitestConfig,
|
|
} from "./vitest.shared.config.ts";
|
|
import { getUnitFastTestFilesForIncludePatterns } from "./vitest.unit-fast-paths.mjs";
|
|
|
|
function normalizePathPattern(value: string): string {
|
|
return value.replaceAll("\\", "/");
|
|
}
|
|
|
|
function relativizeScopedPattern(value: string, dir: string): string {
|
|
const normalizedValue = normalizePathPattern(value);
|
|
const normalizedDir = normalizePathPattern(dir).replace(/\/+$/u, "");
|
|
if (!normalizedDir) {
|
|
return normalizedValue;
|
|
}
|
|
if (normalizedValue === normalizedDir) {
|
|
return ".";
|
|
}
|
|
const prefix = `${normalizedDir}/`;
|
|
return normalizedValue.startsWith(prefix)
|
|
? normalizedValue.slice(prefix.length)
|
|
: normalizedValue;
|
|
}
|
|
|
|
function relativizeScopedPatterns(values: string[], dir?: string): string[] {
|
|
if (!dir) {
|
|
return values.map(normalizePathPattern);
|
|
}
|
|
return values.map((value) => relativizeScopedPattern(value, dir));
|
|
}
|
|
|
|
function globRoot(pattern: string): string | null {
|
|
const globStart = pattern.search(/[*{[]/u);
|
|
if (globStart < 0) {
|
|
return null;
|
|
}
|
|
const slashBeforeGlob = pattern.lastIndexOf("/", globStart);
|
|
if (slashBeforeGlob < 0) {
|
|
return "";
|
|
}
|
|
return pattern.slice(0, slashBeforeGlob);
|
|
}
|
|
|
|
function directoryPatternCoversInclude(excludePattern: string, includePattern: string): boolean {
|
|
if (!excludePattern.endsWith("/**")) {
|
|
return false;
|
|
}
|
|
const excludeRoot = excludePattern.slice(0, -"/**".length);
|
|
const includeRoot = globRoot(includePattern);
|
|
const candidate = includeRoot ?? includePattern;
|
|
return candidate === excludeRoot || candidate.startsWith(`${excludeRoot}/`);
|
|
}
|
|
|
|
function includePatternIsFullyExcluded(includePattern: string, excludePattern: string): boolean {
|
|
const include = normalizePathPattern(includePattern);
|
|
const exclude = normalizePathPattern(excludePattern);
|
|
return (
|
|
include === exclude ||
|
|
path.matchesGlob(include, exclude) ||
|
|
directoryPatternCoversInclude(exclude, include)
|
|
);
|
|
}
|
|
|
|
export function shouldPassWithNoTestsForCliIncludes(
|
|
cliIncludePatterns: string[] | null,
|
|
excludePatterns: string[],
|
|
): boolean {
|
|
if (cliIncludePatterns === null) {
|
|
return false;
|
|
}
|
|
return cliIncludePatterns.every((includePattern) =>
|
|
excludePatterns.some((excludePattern) =>
|
|
includePatternIsFullyExcluded(includePattern, excludePattern),
|
|
),
|
|
);
|
|
}
|
|
|
|
export function resolveVitestIsolation(
|
|
_env: Record<string, string | undefined> = process.env,
|
|
): boolean {
|
|
return false;
|
|
}
|
|
|
|
const SCOPED_PROJECT_GROUP_ORDER_BY_NAME = new Map(
|
|
[
|
|
"acp",
|
|
"agents",
|
|
"agents-core",
|
|
"agents-embedded-agent",
|
|
"agents-support",
|
|
"agents-tools",
|
|
"auto-reply",
|
|
"auto-reply-core",
|
|
"auto-reply-reply",
|
|
"auto-reply-top-level",
|
|
"boundary",
|
|
"bundled",
|
|
"channels",
|
|
"cli",
|
|
"commands",
|
|
"commands-light",
|
|
"cron",
|
|
"daemon",
|
|
"extension-active-memory",
|
|
"extension-acpx",
|
|
"extension-channels",
|
|
"extension-codex",
|
|
"extension-diffs",
|
|
"extension-discord",
|
|
"extension-feishu",
|
|
"extension-imessage",
|
|
"extension-irc",
|
|
"extension-line",
|
|
"extension-mattermost",
|
|
"extension-matrix",
|
|
"extension-media",
|
|
"extension-memory",
|
|
"extension-messaging",
|
|
"extension-msteams",
|
|
"extension-provider-openai",
|
|
"extension-providers",
|
|
"extension-signal",
|
|
"extension-slack",
|
|
"extension-telegram",
|
|
"extension-voice-call",
|
|
"extension-whatsapp",
|
|
"extension-zalo",
|
|
"extensions",
|
|
"gateway",
|
|
"hooks",
|
|
"infra",
|
|
"logging",
|
|
"media",
|
|
"media-understanding",
|
|
"plugin-sdk",
|
|
"plugin-sdk-light",
|
|
"plugins",
|
|
"process",
|
|
"runtime-config",
|
|
"secrets",
|
|
"shared-core",
|
|
"tasks",
|
|
"tooling-docker",
|
|
"tooling-isolated",
|
|
"tooling",
|
|
"tui",
|
|
"ui",
|
|
"ui-e2e",
|
|
"unit-fast",
|
|
"unit-security",
|
|
"unit-src",
|
|
"unit-support",
|
|
"utils",
|
|
"wizard",
|
|
].map((name, index) => [name, index + 10]),
|
|
);
|
|
|
|
function hashFallbackScopedProjectGroupOrder(key: string): number {
|
|
let hash = 0;
|
|
for (const char of key) {
|
|
hash = (hash * 33 + char.charCodeAt(0)) % 10_000;
|
|
}
|
|
return hash + 1_000;
|
|
}
|
|
|
|
function resolveScopedProjectGroupOrder(
|
|
name?: string,
|
|
dir?: string,
|
|
include?: string[],
|
|
): number | undefined {
|
|
const normalizedName = name?.trim();
|
|
if (normalizedName) {
|
|
return (
|
|
SCOPED_PROJECT_GROUP_ORDER_BY_NAME.get(normalizedName) ??
|
|
hashFallbackScopedProjectGroupOrder(normalizedName)
|
|
);
|
|
}
|
|
const normalizedInclude = include?.map(normalizePathPattern).join("|") ?? "";
|
|
const key = [dir?.trim(), normalizedInclude].filter(Boolean).join("|");
|
|
if (!key) {
|
|
return undefined;
|
|
}
|
|
return hashFallbackScopedProjectGroupOrder(key);
|
|
}
|
|
|
|
export function createScopedVitestConfig(
|
|
include: string[],
|
|
options?: {
|
|
deps?: Record<string, unknown>;
|
|
dir?: string;
|
|
env?: Record<string, string | undefined>;
|
|
environment?: string;
|
|
exclude?: string[];
|
|
argv?: string[];
|
|
includeOpenClawRuntimeSetup?: boolean;
|
|
isolate?: boolean;
|
|
name?: string;
|
|
fileParallelism?: boolean;
|
|
pool?: "forks" | "threads";
|
|
passWithNoTests?: boolean;
|
|
excludeUnitFastTests?: boolean;
|
|
setupFiles?: string[];
|
|
useNonIsolatedRunner?: boolean;
|
|
},
|
|
) {
|
|
const base = sharedVitestConfig as Record<string, unknown>;
|
|
const baseTest = sharedVitestConfig.test ?? {};
|
|
const baseSequence = (baseTest as { sequence?: { groupOrder?: number } }).sequence;
|
|
const scopedDir = options?.dir;
|
|
const resolvedScopedDir = scopedDir ? path.join(repoRoot, scopedDir) : undefined;
|
|
const env = options?.env;
|
|
const includeFromEnv = loadPatternListFromEnv("OPENCLAW_VITEST_INCLUDE_FILE", env);
|
|
const cliInclude = narrowIncludePatternsForCli(include, options?.argv, {
|
|
scopedDir,
|
|
});
|
|
const effectiveInclude = includeFromEnv ?? cliInclude ?? include;
|
|
const scopedInclude = relativizeScopedPatterns(effectiveInclude, scopedDir);
|
|
const unitFastExcludePatterns =
|
|
options?.excludeUnitFastTests === false
|
|
? []
|
|
: getUnitFastTestFilesForIncludePatterns(effectiveInclude, { dir: scopedDir });
|
|
const exclude = relativizeScopedPatterns(
|
|
[...(baseTest.exclude ?? []), ...unitFastExcludePatterns, ...(options?.exclude ?? [])],
|
|
scopedDir,
|
|
);
|
|
const scopedCliInclude = cliInclude ? relativizeScopedPatterns(cliInclude, scopedDir) : null;
|
|
const isolate = options?.isolate ?? resolveVitestIsolation(options?.env);
|
|
const setupFiles = [
|
|
...new Set([
|
|
...(baseTest.setupFiles ?? []),
|
|
...(options?.setupFiles ?? []),
|
|
...(options?.includeOpenClawRuntimeSetup === false ? [] : ["test/setup-openclaw-runtime.ts"]),
|
|
]),
|
|
].map(resolveRepoRootPath);
|
|
const useNonIsolatedRunner = options?.useNonIsolatedRunner ?? !isolate;
|
|
const runner = useNonIsolatedRunner ? nonIsolatedRunnerPath : undefined;
|
|
const scopedGroupOrder = resolveScopedProjectGroupOrder(options?.name, scopedDir, include);
|
|
|
|
return defineConfig({
|
|
...base,
|
|
test: {
|
|
...baseTest,
|
|
...(options?.deps ? { deps: options.deps } : {}),
|
|
...(options?.name ? { name: options.name } : {}),
|
|
...(options?.environment ? { environment: options.environment } : {}),
|
|
isolate,
|
|
...(runner ? { runner } : { runner: undefined }),
|
|
setupFiles,
|
|
...(resolvedScopedDir ? { dir: resolvedScopedDir } : {}),
|
|
include: scopedInclude,
|
|
exclude,
|
|
...(options?.pool ? { pool: options.pool } : {}),
|
|
...(options?.fileParallelism === undefined
|
|
? {}
|
|
: { fileParallelism: options.fileParallelism }),
|
|
...(scopedGroupOrder === undefined
|
|
? {}
|
|
: {
|
|
sequence: {
|
|
...baseSequence,
|
|
groupOrder: scopedGroupOrder,
|
|
},
|
|
}),
|
|
...(options?.passWithNoTests !== undefined
|
|
? { passWithNoTests: options.passWithNoTests }
|
|
: shouldPassWithNoTestsForCliIncludes(scopedCliInclude, exclude)
|
|
? { passWithNoTests: true }
|
|
: {}),
|
|
},
|
|
});
|
|
}
|