diff --git a/scripts/check-changed.mjs b/scripts/check-changed.mjs index ecbf6470149..69c302c6d9f 100644 --- a/scripts/check-changed.mjs +++ b/scripts/check-changed.mjs @@ -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) { diff --git a/scripts/lib/tsgo-sparse-guard.mjs b/scripts/lib/tsgo-sparse-guard.mjs index cc29ca0c45a..93e63c06bc6 100644 --- a/scripts/lib/tsgo-sparse-guard.mjs +++ b/scripts/lib/tsgo-sparse-guard.mjs @@ -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, diff --git a/scripts/run-tsgo.mjs b/scripts/run-tsgo.mjs index 62c117478b3..2f8c7fe741f 100644 --- a/scripts/run-tsgo.mjs +++ b/scripts/run-tsgo.mjs @@ -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", diff --git a/test/scripts/changed-lanes.test.ts b/test/scripts/changed-lanes.test.ts index 618ab07a932..cf57c06840f 100644 --- a/test/scripts/changed-lanes.test.ts +++ b/test/scripts/changed-lanes.test.ts @@ -82,6 +82,7 @@ describe("scripts/changed-lanes", () => { it("routes core production changes to core prod and core test lanes", () => { const result = detectChangedLanes(["src/shared/string-normalization.ts"]); + const plan = createChangedCheckPlan(result, { env: { PATH: "/usr/bin" } }); expect(result.lanes).toMatchObject({ core: true, @@ -90,12 +91,12 @@ describe("scripts/changed-lanes", () => { extensionTests: false, all: false, }); - expect(createChangedCheckPlan(result).commands.map((command) => command.args[0])).toContain( - "tsgo:core", - ); - expect(createChangedCheckPlan(result).commands.map((command) => command.args[0])).toContain( - "tsgo:core:test", - ); + expect(plan.commands.map((command) => command.args[0])).toContain("tsgo:core"); + expect(plan.commands.map((command) => command.args[0])).toContain("tsgo:core:test"); + expect(plan.commands.find((command) => command.args[0] === "tsgo:core")?.env).toMatchObject({ + PATH: "/usr/bin", + OPENCLAW_TSGO_SPARSE_SKIP: "1", + }); }); it("routes core test-only changes to core test lanes only", () => { diff --git a/test/scripts/run-tsgo.test.ts b/test/scripts/run-tsgo.test.ts index 9c1b023ce52..1d457d23806 100644 --- a/test/scripts/run-tsgo.test.ts +++ b/test/scripts/run-tsgo.test.ts @@ -1,17 +1,21 @@ import fs from "node:fs"; import path from "node:path"; import { describe, expect, it } from "vitest"; -import { getSparseTsgoGuardError } from "../../scripts/lib/tsgo-sparse-guard.mjs"; +import { + createSparseTsgoSkipEnv, + getSparseTsgoGuardError, + shouldSkipSparseTsgoGuardError, +} from "../../scripts/lib/tsgo-sparse-guard.mjs"; import { createScriptTestHarness } from "./test-helpers.js"; const { createTempDir } = createScriptTestHarness(); describe("run-tsgo sparse guard", () => { - it("ignores non-core-test projects", () => { + it("ignores non-core projects", () => { const cwd = createTempDir("openclaw-run-tsgo-"); expect( - getSparseTsgoGuardError(["-p", "tsconfig.core.json"], { + getSparseTsgoGuardError(["-p", "tsconfig.extensions.json"], { cwd, isSparseCheckoutEnabled: () => true, }), @@ -65,6 +69,24 @@ describe("run-tsgo sparse guard", () => { ).toBeNull(); }); + it("returns a helpful message for sparse core worktrees missing transitive project files", () => { + const cwd = createTempDir("openclaw-run-tsgo-"); + const uiToolDisplay = path.join(cwd, "ui/src/ui/tool-display.ts"); + fs.mkdirSync(path.dirname(uiToolDisplay), { recursive: true }); + fs.writeFileSync(uiToolDisplay, "", "utf8"); + + expect( + getSparseTsgoGuardError(["-p", "tsconfig.core.json"], { + cwd, + isSparseCheckoutEnabled: () => true, + }), + ).toMatchInlineSnapshot(` + "tsconfig.core.json cannot be typechecked from this sparse checkout because tracked project inputs are missing: + - apps/shared/OpenClawKit/Sources/OpenClawKit/Resources/tool-display.json + Expand this worktree's sparse checkout to include those paths, or rerun in a full worktree." + `); + }); + it("returns a helpful message for sparse core-test worktrees missing ui and packages files", () => { const cwd = createTempDir("openclaw-run-tsgo-"); @@ -74,13 +96,23 @@ describe("run-tsgo sparse guard", () => { isSparseCheckoutEnabled: () => true, }), ).toMatchInlineSnapshot(` - "tsconfig.core.test.json requires a full worktree, but this checkout is sparse and missing files that the core test graph imports: + "tsconfig.core.test.json cannot be typechecked from this sparse checkout because tracked project inputs are missing: - packages/plugin-package-contract/src/index.ts - ui/src/i18n/lib/registry.ts - ui/src/i18n/lib/types.ts - ui/src/ui/app-settings.ts - ui/src/ui/gateway.ts - 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." `); }); + + it("recognizes the check:changed sparse-skip env", () => { + expect(shouldSkipSparseTsgoGuardError({ OPENCLAW_TSGO_SPARSE_SKIP: "1" })).toBe(true); + expect(shouldSkipSparseTsgoGuardError({ OPENCLAW_TSGO_SPARSE_SKIP: "true" })).toBe(true); + expect(shouldSkipSparseTsgoGuardError({ OPENCLAW_TSGO_SPARSE_SKIP: "0" })).toBe(false); + expect(createSparseTsgoSkipEnv({ PATH: "/usr/bin" })).toMatchObject({ + PATH: "/usr/bin", + OPENCLAW_TSGO_SPARSE_SKIP: "1", + }); + }); });