fix(test): make changed typechecks sparse-safe

This commit is contained in:
Vincent Koc
2026-04-25 02:02:33 -07:00
parent ed0210a187
commit a33f7b7d05
5 changed files with 120 additions and 25 deletions

View File

@@ -8,6 +8,7 @@ import {
import { booleanFlag, parseFlagArgs, stringFlag } from "./lib/arg-utils.mjs";
import { printTimingSummary } from "./lib/check-timing-summary.mjs";
import { runManagedCommand } from "./lib/managed-child-process.mjs";
import { createSparseTsgoSkipEnv } from "./lib/tsgo-sparse-guard.mjs";
import { isCiLikeEnv } from "./lib/vitest-local-scheduling.mjs";
import { resolveChangedTestTargetPlan } from "./test-projects.test-support.mjs";
@@ -44,11 +45,12 @@ export function createChangedCheckVitestEnv(baseEnv = process.env) {
export function createChangedCheckPlan(result, options = {}) {
const commands = [];
const add = (name, args) => {
const add = (name, args, env) => {
if (!commands.some((command) => command.name === name && sameArgs(command.args, args))) {
commands.push({ name, args });
commands.push({ name, args, ...(env ? { env } : {}) });
}
};
const addTypecheck = (name, args) => add(name, args, createSparseTsgoSkipEnv(options.env));
add("conflict markers", ["check:no-conflict-markers"]);
@@ -89,7 +91,7 @@ export function createChangedCheckPlan(result, options = {}) {
}
if (runAll) {
add("typecheck all", ["tsgo:all"]);
addTypecheck("typecheck all", ["tsgo:all"]);
add("lint", ["lint"]);
add("runtime import cycles", ["check:import-cycles"]);
return {
@@ -103,16 +105,16 @@ export function createChangedCheckPlan(result, options = {}) {
}
if (lanes.core) {
add("typecheck core", ["tsgo:core"]);
addTypecheck("typecheck core", ["tsgo:core"]);
}
if (lanes.coreTests) {
add("typecheck core tests", ["tsgo:core:test"]);
addTypecheck("typecheck core tests", ["tsgo:core:test"]);
}
if (lanes.extensions) {
add("typecheck extensions", ["tsgo:extensions"]);
addTypecheck("typecheck extensions", ["tsgo:extensions"]);
}
if (lanes.extensionTests) {
add("typecheck extension tests", ["tsgo:extensions:test"]);
addTypecheck("typecheck extension tests", ["tsgo:extensions:test"]);
}
if (lanes.core || lanes.coreTests) {

View File

@@ -9,6 +9,28 @@ const CORE_TEST_CONFIGS = new Set([
"tsconfig.core.test.non-agents.json",
]);
const CORE_PROD_CONFIGS = new Set(["tsconfig.core.json"]);
const TSGO_SPARSE_SKIP_ENV_KEY = "OPENCLAW_TSGO_SPARSE_SKIP";
const CORE_PROD_REQUIRED_PATHS = [
{
path: "apps/shared/OpenClawKit/Sources/OpenClawKit/Resources/tool-display.json",
whenPresent: "ui/src/ui/tool-display.ts",
},
{
path: "scripts/lib/bundled-runtime-sidecar-paths.json",
whenPresent: "src/plugins/runtime-sidecar-paths.ts",
},
{
path: "scripts/lib/official-external-channel-catalog.json",
whenPresent: "src/channels/plugins/catalog.ts",
},
{
path: "scripts/lib/plugin-sdk-entrypoints.json",
whenPresent: "src/plugin-sdk/entrypoints.ts",
},
];
const CORE_TEST_REQUIRED_PATHS = [
"packages/plugin-package-contract/src/index.ts",
"ui/src/i18n/lib/registry.ts",
@@ -17,14 +39,27 @@ const CORE_TEST_REQUIRED_PATHS = [
"ui/src/ui/gateway.ts",
];
export function shouldSkipSparseTsgoGuardError(env = process.env) {
const value = env[TSGO_SPARSE_SKIP_ENV_KEY]?.trim().toLowerCase();
return value === "1" || value === "true";
}
export function createSparseTsgoSkipEnv(baseEnv = process.env) {
return {
...baseEnv,
[TSGO_SPARSE_SKIP_ENV_KEY]: baseEnv[TSGO_SPARSE_SKIP_ENV_KEY]?.trim() || "1",
};
}
export function getSparseTsgoGuardError(
args,
{ cwd = process.cwd(), fileExists = fs.existsSync, isSparseCheckoutEnabled } = {},
) {
const projectPath = readProjectFlag(args);
const projectName = projectPath ? path.basename(projectPath) : null;
if (
!projectPath ||
!CORE_TEST_CONFIGS.has(path.basename(projectPath)) ||
!projectName ||
(!CORE_PROD_CONFIGS.has(projectName) && !CORE_TEST_CONFIGS.has(projectName)) ||
isMetadataOnlyCommand(args)
) {
return null;
@@ -36,7 +71,7 @@ export function getSparseTsgoGuardError(
return null;
}
const missingPaths = CORE_TEST_REQUIRED_PATHS.filter(
const missingPaths = getRequiredPathsForProject(projectName, cwd, fileExists).filter(
(relativePath) => !fileExists(path.join(cwd, relativePath)),
);
if (missingPaths.length === 0) {
@@ -44,12 +79,29 @@ export function getSparseTsgoGuardError(
}
return [
`${path.basename(projectPath)} requires a full worktree, but this checkout is sparse and missing files that the core test graph imports:`,
`${projectName} cannot be typechecked from this sparse checkout because tracked project inputs are missing:`,
...missingPaths.map((relativePath) => `- ${relativePath}`),
'Run "gwt sparse full" in this worktree, then rerun the tsgo command.',
"Expand this worktree's sparse checkout to include those paths, or rerun in a full worktree.",
].join("\n");
}
function getRequiredPathsForProject(projectName, cwd, fileExists) {
const requiredPaths = [];
if (CORE_PROD_CONFIGS.has(projectName)) {
requiredPaths.push(...conditionalRequiredPaths(CORE_PROD_REQUIRED_PATHS, cwd, fileExists));
}
if (CORE_TEST_CONFIGS.has(projectName)) {
requiredPaths.push(...CORE_TEST_REQUIRED_PATHS);
}
return [...new Set(requiredPaths)].toSorted((left, right) => left.localeCompare(right));
}
function conditionalRequiredPaths(entries, cwd, fileExists) {
return entries
.filter((entry) => fileExists(path.join(cwd, entry.whenPresent)))
.map((entry) => entry.path);
}
function getGitBooleanConfig(name, { cwd }) {
const result = spawnSync("git", ["config", "--get", "--bool", name], {
cwd,

View File

@@ -7,7 +7,10 @@ import {
applyLocalTsgoPolicy,
shouldAcquireLocalHeavyCheckLockForTsgo,
} from "./lib/local-heavy-check-runtime.mjs";
import { getSparseTsgoGuardError } from "./lib/tsgo-sparse-guard.mjs";
import {
getSparseTsgoGuardError,
shouldSkipSparseTsgoGuardError,
} from "./lib/tsgo-sparse-guard.mjs";
const { args: finalArgs, env } = applyLocalTsgoPolicy(process.argv.slice(2), process.env);
@@ -29,7 +32,12 @@ const releaseLock =
try {
if (sparseGuardError) {
console.error(sparseGuardError);
process.exitCode = 1;
if (shouldSkipSparseTsgoGuardError(env)) {
console.error("[tsgo] skipping sparse-missing project because OPENCLAW_TSGO_SPARSE_SKIP=1");
process.exitCode = 0;
} else {
process.exitCode = 1;
}
} else {
const result = spawnSync(tsgoPath, finalArgs, {
stdio: "inherit",