Skip to content

Commit 145d9ff

Browse files
authored
ci: typecheck graphs that consume changed tests (#134107)
1 parent 904e157 commit 145d9ff

6 files changed

Lines changed: 601 additions & 176 deletions

File tree

‎scripts/check-changed.mts‎

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ import { resolveLocalCheckEnv } from "./lib/local-check-runtime.mts";
3535
import { runManagedCommand } from "./lib/managed-child-process.mts";
3636
import { listGeneratedExtensionAssetSources } from "./lib/static-extension-assets.mts";
3737
import { createSparseTsgoSkipEnv } from "./lib/tsgo-sparse-guard.mts";
38+
import type { createChangedCoreTestCheck } from "./run-tsgo-core-test-shards.mts";
3839

3940
type ChangedCheckCommand = {
41+
coreTestCheck?: "checkBoundary" | "checkTypes";
4042
name: string;
4143
args: string[];
4244
bin?: string;
@@ -683,8 +685,22 @@ export function createChangedCheckPlan(
683685

684686
// Typechecking alone accepts extension imports; the graph guard also covers
685687
// shared test/tooling dependencies that core tests can pull into their graph.
688+
const changedTestPaths = result.paths.filter(
689+
(file) => getChangedPathFacts(file).surface !== "docs",
690+
);
691+
const narrowCoreTests =
692+
!runAll &&
693+
!lanes.core &&
694+
!lanes.ui &&
695+
!lanes.tooling &&
696+
!lanes.liveDockerTooling &&
697+
changedTestPaths.length > 0 &&
698+
changedTestPaths.every((file) => /^(?:src|ui|packages)\/.+\.test\.tsx?$/u.test(file));
686699
if (runAll || lanes.core || lanes.coreTests || lanes.ui || lanes.tooling) {
687700
add("core tsgo graph boundary", ["lint:tmp:tsgo-core-boundary"]);
701+
if (narrowCoreTests) {
702+
commands.at(-1)!.coreTestCheck = "checkBoundary";
703+
}
688704
}
689705

690706
if (runAll || lanes.scripts || result.paths.includes("scripts/check-script-erasability.mjs")) {
@@ -733,6 +749,9 @@ export function createChangedCheckPlan(
733749
}
734750
if (lanes.coreTests) {
735751
addTypecheck("typecheck core tests", ["tsgo:core:test"]);
752+
if (narrowCoreTests) {
753+
commands.at(-1)!.coreTestCheck = "checkTypes";
754+
}
736755
}
737756
if (lanes.ui) {
738757
addTypecheck("typecheck UI", ["tsgo:ui"]);
@@ -1001,9 +1020,15 @@ async function runChangedCheck(result: ChangedLaneResult, options: ChangedCheckR
10011020
return 0;
10021021
}
10031022

1023+
const coreTestCheck = plan.commands.some((command) => command.coreTestCheck)
1024+
? (await import("./run-tsgo-core-test-shards.mts")).createChangedCoreTestCheck(
1025+
result.paths.filter((file) => getChangedPathFacts(file).surface !== "docs"),
1026+
createSparseTsgoSkipEnv(childEnv),
1027+
)
1028+
: undefined;
10041029
const timings: ChangedCheckTiming[] = [];
10051030
for (const command of plan.commands) {
1006-
const status = await runPlanCommand(command, timings);
1031+
const status = await runPlanCommand(command, timings, coreTestCheck);
10071032
if (status !== 0) {
10081033
printSummary(timings, options);
10091034
return status;
@@ -1042,7 +1067,18 @@ async function runPnpm(command: ChangedCheckCommand, timings: ChangedCheckTiming
10421067
return await runCommand(createPnpmManagedCommand(command), timings);
10431068
}
10441069

1045-
async function runPlanCommand(command: ChangedCheckCommand, timings: ChangedCheckTiming[]) {
1070+
async function runPlanCommand(
1071+
command: ChangedCheckCommand,
1072+
timings: ChangedCheckTiming[],
1073+
coreTestCheck?: ReturnType<typeof createChangedCoreTestCheck>,
1074+
) {
1075+
if (command.coreTestCheck && coreTestCheck) {
1076+
return await runCommand(
1077+
createPnpmManagedCommand(command),
1078+
timings,
1079+
coreTestCheck[command.coreTestCheck],
1080+
);
1081+
}
10461082
if (command.bin) {
10471083
return await runCommand({ ...command, bin: command.bin }, timings);
10481084
}
@@ -1117,16 +1153,19 @@ export function cleanupCorepackPnpmShimDir() {
11171153
async function runCommand(
11181154
command: ChangedCheckCommand & { bin: string },
11191155
timings: ChangedCheckTiming[],
1156+
run?: () => Promise<number>,
11201157
) {
11211158
const startedAt = performance.now();
11221159
console.error(`\n[check:changed] ${command.name}`);
11231160
let status = 1;
11241161
try {
1125-
status = await runManagedCommand({
1126-
bin: command.bin,
1127-
args: command.args,
1128-
env: command.env ?? resolveLocalCheckEnv(),
1129-
});
1162+
status = run
1163+
? await run()
1164+
: await runManagedCommand({
1165+
bin: command.bin,
1166+
args: command.args,
1167+
env: command.env ?? resolveLocalCheckEnv(),
1168+
});
11301169
} catch (error) {
11311170
console.error(error);
11321171
}

0 commit comments

Comments
 (0)