Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/reference/ci-test-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ nonempty. Full discovery and independent Git enumeration still agree before
filtering. Duplicate/unknown selections fail. Every selected file runs exactly
once per active host pool or is explicitly deferred. `BOTH_POOL_FILES` deliberately
runs the named daemon files on both hosts so Linux-only cases are exercised too.
It also runs the portable `open --json` subprocess contract in
`tests/local-network-hint.test.ts` on light PRs' Linux shards, while preserving
its macOS hint checks in the macOS pool. A change to CLI commands or shared
output modules therefore checks this contract before integration. This adds no
macOS minutes per PR; the duration table budgets about four Linux seconds when
the file is selected. The deferral report separates files already run on Linux
from files awaiting all execution; both still await macOS qualification.
Each file retains its suite
working directory and Bun preload.

Expand Down
5 changes: 4 additions & 1 deletion scripts/test-shard-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ export const MACOS_POOL_FILES: Readonly<Record<string, string>> = {};
* Files that need both hosts, with the reason: their macOS run (they match
* {@link PLATFORM_SENSITIVE_SOURCE} or are listed in {@link MACOS_POOL_FILES})
* would otherwise be their only one, while tests in them skip off Linux or
* observe Linux-only behavior. They are planned in the macOS pool, which
* observe Linux-only behavior, or include portable CLI contracts needed on light
* PRs. They are planned in the macOS pool, which
* keeps the pools a partition for the exactly-once coverage check, and are
* added to the Linux pool as well (HACK-2142).
*/
Expand All @@ -527,6 +528,8 @@ export const BOTH_POOL_FILES: Readonly<Record<string, string>> = {
"detached start differs on Linux (setsid, /proc liveness)",
"tests/daemon-socket-permissions.test.ts":
"daemon directory trust walks host paths (macOS /var -> /private/var)",
"tests/local-network-hint.test.ts":
"portable open --json subprocess contract must gate light PRs; macOS hint behavior still needs macOS",
};

/** Parse a layout name, refused closed. */
Expand Down
7 changes: 6 additions & 1 deletion scripts/test-shard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { appendFileSync } from "node:fs";
import { resolve } from "node:path";
import { ClosedCliError } from "../src/lib/cli-result.ts";
import {
BOTH_POOL_FILES,
buildVerifiedPlan,
DURATION_TABLE_PATH,
DURATION_TABLE_SCHEMA,
Expand Down Expand Up @@ -81,7 +82,11 @@ export function prioritizeSlowFiles(files: readonly string[]): string[] {
}

export function deferredMacosSummary(files: readonly string[]): string {
return `### macOS files deferred to the integration run\n\n${files.length} selected platform-sensitive files are deferred to the integration run. Linux results do not qualify these files on macOS.\n\n\`\`\`json\n${JSON.stringify(files, null, 2)}\n\`\`\`\n`;
const both = files.filter((file) => Object.hasOwn(BOTH_POOL_FILES, file));
const macosOnly = files.filter(
(file) => !Object.hasOwn(BOTH_POOL_FILES, file)
);
return `### macOS files deferred to the integration run\n\n${macosOnly.length} selected platform-sensitive files are deferred to the integration run. Linux results do not qualify these files on macOS.\n\n\`\`\`json\n${JSON.stringify(macosOnly, null, 2)}\n\`\`\`\n\n### Files also run on Linux\n\n${both.length} selected files run on Linux in this PR; only their macOS coverage is deferred to the integration run.\n\n\`\`\`json\n${JSON.stringify(both, null, 2)}\n\`\`\`\n`;
}

/** Default shard limit, below the job's `timeout-minutes` so the report prints. */
Expand Down
25 changes: 25 additions & 0 deletions tests/ci-test-selection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,31 @@ describe("conservative dependency selection", () => {
});

describe("PR matrix policy", () => {
test.each([
"src/commands/project.ts",
"src/ui/logger.ts",
"src/lib/local-network-hint.ts",
])("light CLI change gates the portable open output contract on Linux: %s", async (path) => {
expect(await Bun.file(resolve(repoRoot, path)).exists()).toBe(true);
const selection = selectTests({ repoRoot, changed: [path] });
expect(selection.mode).toBe("selected");
const file = "tests/local-network-hint.test.ts";
expect(selection.files).toContain(file);
const plan = await planPullRequest({
repoRoot,
changed: [path],
draft: false,
full: false,
selection,
});
expect(plan.test_files).toBe(JSON.stringify(selection.files));
expect(plan.test_shards).toBe("[4,5,6,7,8]");
expect(plan.defer_macos).toBe(true);
const pools = await classifyTestPools({ repoRoot, files: selection.files });
expect(pools.linux).toContain(file);
expect(pools.macos).toContain(file);
expect(pools.both).toContain(file);
}, 30_000);
test("ordinary light PRs defer platform and Docker inputs until opt-in or integration", async () => {
const selection = {
mode: "selected",
Expand Down
15 changes: 12 additions & 3 deletions tests/test-shard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,11 +831,17 @@ describe("test shard runner", () => {

test("deferred file summary names the selected macOS evidence gap", () => {
const macos = "tests/native-authored-project-start.test.ts";
const summary = deferredMacosSummary([macos]);
const both = "tests/local-network-hint.test.ts";
const summary = deferredMacosSummary([macos, both]);
expect(summary).toContain("deferred to the integration run");
expect(summary).toContain(macos);
expect(summary).toContain("1 selected");
expect(summary).not.toContain("packages/db/tests/smoke.test.ts");
const [deferred, onLinux] = summary.split("### Files also run on Linux");
expect(deferred).toContain(macos);
expect(deferred).not.toContain(both);
expect(onLinux).toContain(both);
expect(onLinux).toContain("only their macOS coverage is deferred");
});

test("prints a start and a result line naming each file", async () => {
Expand Down Expand Up @@ -1167,9 +1173,10 @@ describe("hosted test CI fan-in", () => {
owned.push(root);
const linux = "packages/db/tests/smoke.test.ts";
const macos = "tests/native-authored-project-start.test.ts";
const both = "tests/local-network-hint.test.ts";
const env = {
...process.env,
HACK_TEST_SELECTION: JSON.stringify([linux, macos]),
HACK_TEST_SELECTION: JSON.stringify([linux, macos, both]),
HACK_TEST_DRAFT: "true",
HACK_TEST_DEFER_MACOS: "true",
GITHUB_STEP_SUMMARY: join(root, "summary"),
Expand All @@ -1189,7 +1196,7 @@ describe("hosted test CI fan-in", () => {
expect(child.exitCode, child.stderr.toString()).toBe(0);
files.push(...child.stdout.toString().trim().split("\n").filter(Boolean));
}
expect(files).toEqual([linux]);
expect(files.sort()).toEqual([linux, both].sort());
const report = Bun.spawnSync(
[process.execPath, "scripts/test-shard.ts", "report-deferred"],
{ cwd: repoRoot, env, stdout: "pipe", stderr: "pipe" }
Expand All @@ -1199,6 +1206,8 @@ describe("hosted test CI fan-in", () => {
expect(summary).toContain(macos);
expect(summary).not.toContain(linux);
expect(summary).toContain("deferred to the integration run");
expect(summary.split("### Files also run on Linux")[0]).not.toContain(both);
expect(summary.split("### Files also run on Linux")[1]).toContain(both);
const wrong = Bun.spawnSync(
[
process.execPath,
Expand Down
Loading