mirror of
https://github.com/morluto/rea.git
synced 2026-11-28 15:18:49 +00:00
ci(apple): run the macOS lane when a pull request changes a macOS-gated test
Pull requests ran the macOS lane only for its listed paths, so a change to a test gated to macOS never ran it before main's full sweep. The CI planner runs before dependencies are installed and cannot load the parser, so a dependency-free candidate test now admits every module that could gate a test to macOS: one that names a "darwin" or "linux" literal and has a skipIf/runIf gate or a case list chosen by a conditional on that literal. The planner selects the lane when a changed test at head is a candidate, and the exact discovery parses only candidates, so the two cannot disagree about a gated module. The test over-selects modules that are not gated; a deleted test selects nothing.
This commit is contained in:
1 parent
a2989e6c4b
commit
3280b1a669
6 files changed
+83
-1
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { matchesGlob } from "node:path";
|
||||
import { isLivingProsePath } from "../lib/docs-facts.mjs";
|
||||
import { mayGateTestToDarwin } from "./darwin-gate-candidates.mjs";
|
||||
import {
|
||||
CI_FLAGS as flags,
|
||||
MANUAL_VERIFIERS,
|
||||
@@ -116,6 +117,25 @@ const selectTypedLintFiles = (files, listCheckedOutFiles) => {
|
||||
: null;
|
||||
};
|
||||
|
||||
/**
|
||||
* The first changed test at `head` that may gate a test to macOS. A deleted
|
||||
* test has nothing to run.
|
||||
*/
|
||||
const changedTestMayGateDarwin = (repository, head, files) => {
|
||||
const changedTests = files.filter((file) =>
|
||||
/^(src|tests)\/.*\.test\.ts$/u.test(file),
|
||||
);
|
||||
if (changedTests.length === 0) return undefined;
|
||||
const present = new Set(repository.listFiles(head, []));
|
||||
const sources = repository.readFiles(
|
||||
head,
|
||||
changedTests.filter((file) => present.has(file)),
|
||||
);
|
||||
for (const [file, source] of sources)
|
||||
if (mayGateTestToDarwin(source)) return file;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Plan the CI lanes for one event. `repository` answers the Git questions the
|
||||
* plan asks, so the classification runs without a process per decision.
|
||||
@@ -444,6 +464,15 @@ export function planChanges(request, repository) {
|
||||
// Disable rename detection so both the removed and added paths participate.
|
||||
files = repository.changedFiles(base, head);
|
||||
for (const file of files) classifyFile(file, base, head);
|
||||
// Linux lanes skip a test gated to macOS, so a change to one runs the
|
||||
// macOS lane that does.
|
||||
const gated = selected.apple
|
||||
? undefined
|
||||
: changedTestMayGateDarwin(repository, head, files);
|
||||
if (gated !== undefined) {
|
||||
selected.apple = true;
|
||||
reasons.push(`Changed test may be gated to macOS: ${gated}`);
|
||||
}
|
||||
}
|
||||
// Scheduled fast sweeps always execute the complete portable suite and
|
||||
// refresh test-timings-fast, even when only prose changed since the ancestor.
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// The CI planning job runs before dependencies are installed, so it cannot
|
||||
// load the parser that darwin-gated-tests.mjs uses to decide a gate exactly.
|
||||
// This dependency-free test admits a superset of that decision, and the
|
||||
// exact discovery parses only the modules it admits, so the two cannot
|
||||
// disagree about a gated module. A gate can tell macOS from Linux only by
|
||||
// comparing process.platform with a "darwin" or "linux" literal. It is a
|
||||
// skipIf/runIf call, or a case list chosen by a conditional on that literal.
|
||||
// The test may admit modules that are not gated.
|
||||
|
||||
const PLATFORM_LITERAL = /["'`](?:darwin|linux)["'`]/u;
|
||||
const GATE_SHAPE =
|
||||
/\.(?:skipIf|runIf)\s*\(|["'`](?:darwin|linux)["'`]\s*\)?\s*\?\s*\(?\s*\[/u;
|
||||
|
||||
/** Whether a test module's text could gate a test to macOS. */
|
||||
export const mayGateTestToDarwin = (source) =>
|
||||
PLATFORM_LITERAL.test(source) && GATE_SHAPE.test(source);
|
||||
@@ -7,6 +7,7 @@ import { parse } from "@babel/parser";
|
||||
import { traverseFast } from "@babel/types";
|
||||
|
||||
import { projectForTest } from "../lib/test-projects.mjs";
|
||||
import { mayGateTestToDarwin } from "./darwin-gate-candidates.mjs";
|
||||
|
||||
// Tests gated to macOS never run on the Linux lanes, so the macOS lane runs
|
||||
// every one of them. A gate is a Vitest `skipIf`/`runIf` condition, or a
|
||||
@@ -139,6 +140,7 @@ const calleeMethod = (node) =>
|
||||
* `source` is TypeScript module text; a syntax error is thrown, not ignored.
|
||||
*/
|
||||
export const isDarwinGatedTestSource = (source) => {
|
||||
if (!mayGateTestToDarwin(source)) return false;
|
||||
const tree = parse(source, { sourceType: "module", plugins: ["typescript"] });
|
||||
const constants = moduleConstants(tree.program);
|
||||
let gated = false;
|
||||
@@ -154,7 +156,8 @@ export const isDarwinGatedTestSource = (source) => {
|
||||
}
|
||||
if ((method === "for" || method === "each") && node.arguments[0])
|
||||
traverseFast(node.arguments[0], (child) => {
|
||||
// `...(process.platform === "darwin" ? [cases] : [])`
|
||||
// `...(process.platform === "darwin" ? [cases] : [])`. The candidate
|
||||
// filter admits only a conditional that names the platform literal.
|
||||
if (gated || child.type !== "ConditionalExpression") return;
|
||||
const linux = evaluate(child.test, "linux", constants);
|
||||
const darwin = evaluate(child.test, "darwin", constants);
|
||||
|
||||
@@ -162,6 +162,7 @@ const PATH_SCOPES = {
|
||||
"bridge/process/**",
|
||||
"scripts/verify/apple/**",
|
||||
"scripts/ci/darwin-gated-tests.mjs",
|
||||
"scripts/ci/darwin-gate-candidates.mjs",
|
||||
"tests/boundary/filesystem/ciDarwinGatedTests.test.ts",
|
||||
"tests/acceptance/artifactDmgAttachmentRecoveryCli.test.ts",
|
||||
"tests/boundary/providers/native/nativeDmgArtifactReader.test.ts",
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
readFile,
|
||||
readdir,
|
||||
rename,
|
||||
rm,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { dirname, join, matchesGlob } from "node:path";
|
||||
@@ -436,6 +437,36 @@ it("keeps unknown CI scripts on the fast Linux baseline", async () => {
|
||||
for (const flag of CI_FLAGS) expect(full[flag]).toBe(true);
|
||||
});
|
||||
|
||||
// Linux lanes skip a test gated to macOS; changing one runs the macOS lane.
|
||||
it.for([
|
||||
[`it.skipIf(process.platform !== "darwin")("runs", () => {});\n`, true],
|
||||
[`it.skipIf(process.platform === "linux")("runs", () => {});\n`, true],
|
||||
[`it("runs everywhere", () => {});\n`, false],
|
||||
] as const)(
|
||||
"selects the macOS lane for a changed test that may be gated to it: %j",
|
||||
async ([source, apple]) => {
|
||||
const { directory, base } = await fixture();
|
||||
const test = "tests/boundary/filesystem/gated.test.ts";
|
||||
const head = await change(directory, [test], source);
|
||||
expect(await classify(directory, base, head)).toMatchObject({ apple });
|
||||
},
|
||||
);
|
||||
|
||||
it("does not select the macOS lane for a deleted macOS-gated test", async () => {
|
||||
const { directory } = await fixture();
|
||||
const test = "tests/boundary/filesystem/gated.test.ts";
|
||||
const base = await change(
|
||||
directory,
|
||||
[test],
|
||||
`it.skipIf(process.platform !== "darwin")("runs", () => {});\n`,
|
||||
);
|
||||
await rm(join(directory, test));
|
||||
const head = await commit(directory);
|
||||
expect(await classify(directory, base, head)).toMatchObject({
|
||||
apple: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("does not credit a fixture test as coverage for an unrelated shared script", async () => {
|
||||
const { directory } = await fixture();
|
||||
const module = "scripts/lib/uncovered.mjs";
|
||||
|
||||
@@ -26,6 +26,7 @@ const FIXTURES = {
|
||||
"darwinConstant.test.ts": `const onDarwin = process.platform === "darwin";\nit.skipIf(!onDarwin)("runs", () => {});`,
|
||||
"darwinArm64.test.ts": `it.skipIf(process.platform !== "darwin" || process.arch !== "arm64")("runs", () => {});`,
|
||||
"darwinCases.test.ts": `it.for(["portable", ...(process.platform === "darwin" ? ["plist"] : [])])("%s", () => {});`,
|
||||
"notLinux.test.ts": `it.skipIf(process.platform === "linux")("runs", () => {});`,
|
||||
"ungated.test.ts": `it("runs everywhere", () => {});`,
|
||||
"linuxOnly.test.ts": `it.skipIf(process.platform !== "linux")("runs", () => {});`,
|
||||
"posixHosts.test.ts": `it.skipIf(!["darwin", "linux"].includes(process.platform))("runs", () => {});`,
|
||||
@@ -41,6 +42,7 @@ const GATED = [
|
||||
"darwinConstant.test.ts",
|
||||
"darwinRun.test.ts",
|
||||
"darwinSkip.test.ts",
|
||||
"notLinux.test.ts",
|
||||
].map((name) => `${DIRECTORY}/${name}`);
|
||||
|
||||
const fixtureRepository = async (files: Readonly<Record<string, string>>) => {
|
||||
|
||||
Reference in new issue
Block a user