|
1 | 1 | // Changed Lanes tests cover changed lanes script behavior. |
2 | 2 | import { execFileSync, spawnSync } from "node:child_process"; |
3 | | -import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs"; |
| 3 | +import { chmodSync, existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs"; |
4 | 4 | import { createRequire } from "node:module"; |
5 | 5 | import path from "node:path"; |
6 | 6 | import { pathToFileURL } from "node:url"; |
@@ -165,6 +165,62 @@ function runChangedFormatLaneWithRepoOxfmt(cwd: string, changedPaths: string[]) |
165 | 165 | }); |
166 | 166 | } |
167 | 167 |
|
| 168 | +// Keep the real gate and managed children; only the external check commands are synthetic. |
| 169 | +function runChangedCheckWithRecordedCommands(failingCommand: string | null) { |
| 170 | + const dir = makeTempRepoRoot(tempDirs, "openclaw-changed-check-order-"); |
| 171 | + const binDir = path.join(dir, "bin"); |
| 172 | + const eventsPath = path.join(dir, "events.jsonl"); |
| 173 | + const childPath = path.join(dir, "command.cjs"); |
| 174 | + mkdirSync(binDir); |
| 175 | + writeFileSync(eventsPath, ""); |
| 176 | + writeFileSync( |
| 177 | + childPath, |
| 178 | + ` |
| 179 | +const fs = require("node:fs"); |
| 180 | +const bin = process.argv[2]; |
| 181 | +const args = process.argv.slice(3); |
| 182 | +const events = ${JSON.stringify(eventsPath)}; |
| 183 | +const active = ${JSON.stringify(path.join(dir, "active"))}; |
| 184 | +const record = (event) => fs.appendFileSync(events, JSON.stringify({event, bin, args}) + "\\n"); |
| 185 | +fs.mkdirSync(active); |
| 186 | +record("start"); |
| 187 | +process.on("exit", () => { record("finish"); fs.rmdirSync(active); }); |
| 188 | +if (bin === "pnpm" && args[0] === ${JSON.stringify(failingCommand)}) { |
| 189 | + console.error("Synthetic check failure: " + args[0]); |
| 190 | + process.exitCode = 23; |
| 191 | +} |
| 192 | +`, |
| 193 | + ); |
| 194 | + const quote = (value: string) => `'${value.replaceAll("'", "'\\''")}'`; |
| 195 | + for (const bin of ["pnpm", "node"]) { |
| 196 | + const launcher = path.join(binDir, bin); |
| 197 | + writeFileSync( |
| 198 | + launcher, |
| 199 | + `#!/bin/sh\nexec ${quote(process.execPath)} ${quote(childPath)} ${bin} "$@"\n`, |
| 200 | + ); |
| 201 | + chmodSync(launcher, 0o755); |
| 202 | + writeFileSync( |
| 203 | + `${launcher}.cmd`, |
| 204 | + `@echo off\r\n"${process.execPath}" "${childPath}" ${bin} %*\r\n`, |
| 205 | + ); |
| 206 | + } |
| 207 | + const paths = ["src/gateway/server-runtime-state.ts"]; |
| 208 | + const result = runRepoScript("scripts/check-changed.mjs", ["--", ...paths], { |
| 209 | + ...createNestedGitEnv(), |
| 210 | + CI: "", |
| 211 | + GITHUB_ACTIONS: "", |
| 212 | + OPENCLAW_CHECK_CHANGED_REMOTE_CHILD: "1", |
| 213 | + OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE: "", |
| 214 | + PATH: `${binDir}${path.delimiter}${process.env.PATH ?? ""}`, |
| 215 | + }); |
| 216 | + const events: { event: string; bin: string; args: string[] }[] = readFileSync(eventsPath, "utf8") |
| 217 | + .trim() |
| 218 | + .split("\n") |
| 219 | + .filter(Boolean) |
| 220 | + .map((line) => JSON.parse(line)); |
| 221 | + return { events, paths, result }; |
| 222 | +} |
| 223 | + |
168 | 224 | function createSyntheticMergeRepo(prefix: string): { dir: string; staleBase: string } { |
169 | 225 | const dir = makeTempRepoRoot(tempDirs, prefix); |
170 | 226 | git(dir, ["init", "-q", "--initial-branch=main"]); |
@@ -367,6 +423,51 @@ describe("scripts/changed-lanes", () => { |
367 | 423 | ]); |
368 | 424 | }); |
369 | 425 |
|
| 426 | + it.each(["tsgo:core:test", "lint:tmp:tsgo-core-boundary", null])( |
| 427 | + "runs types before broad audits while retaining serial gate execution (%s)", |
| 428 | + (failingCommand) => { |
| 429 | + const { events, paths, result } = runChangedCheckWithRecordedCommands(failingCommand); |
| 430 | + expect(result.error, result.stderr).toBeUndefined(); |
| 431 | + expect(result.signal, result.stderr).toBeNull(); |
| 432 | + expect(result.status, result.stderr).toBe(failingCommand === null ? 0 : 23); |
| 433 | + const commands = events.filter((event) => event.event === "start"); |
| 434 | + const planned = createChangedCheckPlan(detectChangedLanes(paths)).commands.map((command) => ({ |
| 435 | + bin: command.bin ?? "pnpm", |
| 436 | + args: command.args, |
| 437 | + })); |
| 438 | + const end = |
| 439 | + failingCommand === null |
| 440 | + ? planned.length |
| 441 | + : planned.findIndex((command) => command.args[0] === failingCommand) + 1; |
| 442 | + expect(commands.map(({ bin, args }) => ({ bin, args }))).toEqual(planned.slice(0, end)); |
| 443 | + expect(events).toEqual( |
| 444 | + commands.flatMap(({ bin, args }) => [ |
| 445 | + { event: "start", bin, args }, |
| 446 | + { event: "finish", bin, args }, |
| 447 | + ]), |
| 448 | + ); |
| 449 | + const broadAudits = commands.filter(({ args }) => |
| 450 | + args.some((arg) => |
| 451 | + [ |
| 452 | + "check:coercion-helpers", |
| 453 | + "check:deprecated-api-usage", |
| 454 | + "scripts/check-deadcode-exports.mts", |
| 455 | + ].includes(arg), |
| 456 | + ), |
| 457 | + ); |
| 458 | + if (failingCommand !== null) { |
| 459 | + expect(result.stderr).toContain(`Synthetic check failure: ${failingCommand}`); |
| 460 | + expect(broadAudits).toEqual([]); |
| 461 | + } else { |
| 462 | + expect(broadAudits).toHaveLength(3); |
| 463 | + const lastTypecheck = commands.findLastIndex(({ args }) => args[0]?.startsWith("tsgo:")); |
| 464 | + for (const audit of broadAudits) { |
| 465 | + expect(commands.indexOf(audit)).toBeGreaterThan(lastTypecheck); |
| 466 | + } |
| 467 | + } |
| 468 | + }, |
| 469 | + ); |
| 470 | + |
370 | 471 | it("prints changed check dry-run commands", () => { |
371 | 472 | const result = runRepoScript("scripts/check-changed.mjs", [ |
372 | 473 | "--dry-run", |
@@ -406,13 +507,13 @@ describe("scripts/changed-lanes", () => { |
406 | 507 | "pnpm lint:extensions:no-guarded-wildcard-reexports", |
407 | 508 | "pnpm lint:extensions:no-plugin-sdk-wildcard-reexports", |
408 | 509 | "pnpm dup:check:coverage", |
409 | | - "pnpm check:coercion-helpers", |
410 | 510 | "pnpm deps:pins:check", |
411 | 511 | `pnpm format:check --no-error-on-unmatched-pattern -- ${lanes.paths.join(" ")}`, |
412 | 512 | "pnpm deps:patches:check", |
413 | 513 | "node scripts/report-test-temp-creations.mjs --base origin/main --head HEAD", |
414 | 514 | "pnpm lint:tmp:tsgo-core-boundary", |
415 | 515 | "pnpm tsgo:test:root", |
| 516 | + "pnpm check:coercion-helpers", |
416 | 517 | "pnpm lint:scripts", |
417 | 518 | ]); |
418 | 519 | }); |
@@ -1472,20 +1573,20 @@ describe("scripts/changed-lanes", () => { |
1472 | 1573 | "guarded extension wildcard re-exports", |
1473 | 1574 | "plugin-sdk wildcard re-exports", |
1474 | 1575 | "duplicate scan target coverage", |
1475 | | - "coercion helper declaration guard", |
1476 | 1576 | "dependency pin guard", |
1477 | 1577 | "format changed files", |
1478 | | - "deprecated API usage", |
1479 | 1578 | "plugin boundaries", |
1480 | 1579 | "wrapper shadowing", |
1481 | 1580 | "package patch guard", |
| 1581 | + "test temp creation report (warning-only)", |
| 1582 | + "core tsgo graph boundary", |
| 1583 | + "typecheck core tests", |
| 1584 | + "coercion helper declaration guard", |
| 1585 | + "deprecated API usage", |
1482 | 1586 | // These live-Docker paths include `src/gateway/*.live.test.ts`, and the |
1483 | 1587 | // full-tree knip scan sees test files, so a deleted last consumer can |
1484 | 1588 | // orphan an export here too. |
1485 | 1589 | "dead export scan (skip with OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1)", |
1486 | | - "test temp creation report (warning-only)", |
1487 | | - "core tsgo graph boundary", |
1488 | | - "typecheck core tests", |
1489 | 1590 | "lint core", |
1490 | 1591 | "lint scripts", |
1491 | 1592 | "live Docker shell syntax", |
|
0 commit comments