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

@@ -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", () => {

View File

@@ -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",
});
});
});