ci: observe affected-owner test plans against full results
This commit is contained in:
@@ -178,6 +178,23 @@ it("keeps unknown CI scripts on complete qualification", async () => {
|
||||
for (const flag of CI_FLAGS) expect(plan[flag]).toBe(true);
|
||||
});
|
||||
|
||||
it("emits an observational owner proposal without changing ordinary or full portable execution", async () => {
|
||||
const { directory, base } = await fixture();
|
||||
const head = await change(directory, ["src/evm/Example.ts"]);
|
||||
expect(await classify(directory, base, head)).toMatchObject({
|
||||
code: true,
|
||||
testSelection: { mode: "candidate", owners: ["evm"] },
|
||||
});
|
||||
expect(
|
||||
await classify(directory, base, head, "pull_request", true),
|
||||
).toMatchObject({
|
||||
code: true,
|
||||
testSelection: { mode: "full", owners: [] },
|
||||
});
|
||||
const output = await readFile(join(directory, "scope-output"), "utf8");
|
||||
expect(output).toContain('test_selection={"version":1,"mode":"full"');
|
||||
});
|
||||
|
||||
it("does not charge a documentation PR for unrelated implementation updates on main", async () => {
|
||||
const { directory, base } = await fixture();
|
||||
await git(directory, ["switch", "-c", "docs/change"]);
|
||||
|
||||
@@ -8,6 +8,8 @@ import { expect, it } from "vitest";
|
||||
import { parse } from "yaml";
|
||||
import { z } from "zod";
|
||||
|
||||
import { planTestSelection } from "../../../scripts/ci/test-selection.mjs";
|
||||
|
||||
import { parseTestDurations } from "../../ciTestSequencer.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { workflowGit } from "../../support/workflowGit.js";
|
||||
@@ -61,6 +63,16 @@ it("collects failed-shard diagnostics before enforcing the shard result", async
|
||||
"--reporter=./scripts/ci/test-timing-reporter.mjs",
|
||||
);
|
||||
expect(steps[upload]?.with?.path).toContain("test-timings.json");
|
||||
expect(steps[upload]?.with).toMatchObject({ "include-hidden-files": true });
|
||||
expect(steps[upload]?.with?.path).toContain(
|
||||
".cache/ci-test-selection/report.json",
|
||||
);
|
||||
const summary = steps.find((step) =>
|
||||
step.run?.includes("scripts/ci/test-report.mjs"),
|
||||
);
|
||||
expect(summary?.env?.CI_TEST_SELECTION).toBe(
|
||||
"${{ needs.changes.outputs.test_selection }}",
|
||||
);
|
||||
const command = steps[gate]?.run;
|
||||
if (command === undefined) throw new Error("Missing shard result gate");
|
||||
for (const result of ["failure", "cancelled", "skipped", ""]) {
|
||||
@@ -304,6 +316,13 @@ it("recovers complete module costs from real blob reports without executing test
|
||||
),
|
||||
})
|
||||
.parse(JSON.parse(await readFile(join(root, "test-timings.json"), "utf8")));
|
||||
expect(
|
||||
JSON.parse(await readFile(join(root, "test-timings.json"), "utf8")),
|
||||
).toMatchObject({
|
||||
reason: "passed",
|
||||
unhandledErrors: 0,
|
||||
files: [{ state: "passed" }],
|
||||
});
|
||||
expect(report.files).toHaveLength(1);
|
||||
const file = report.files[0]!;
|
||||
const json = z
|
||||
@@ -349,7 +368,13 @@ it("recovers complete module costs from real blob reports without executing test
|
||||
const failed = JSON.parse(
|
||||
await readFile(join(root, "test-timings.json"), "utf8"),
|
||||
) as unknown;
|
||||
expect(failed).toMatchObject({ version: 1, success: false });
|
||||
expect(failed).toMatchObject({
|
||||
version: 1,
|
||||
success: false,
|
||||
reason: "failed",
|
||||
unhandledErrors: 0,
|
||||
files: [{ state: "failed" }],
|
||||
});
|
||||
// Even a caller accidentally marking the merge successful cannot publish this report.
|
||||
await execute(process.execPath, [fileURLToPath(script)], {
|
||||
cwd: root,
|
||||
@@ -359,3 +384,76 @@ it("recovers complete module costs from real blob reports without executing test
|
||||
readFile(join(root, ".cache/ci-test-history/test-results.json")),
|
||||
).rejects.toMatchObject({ code: "ENOENT" });
|
||||
});
|
||||
|
||||
it("records failed omissions from full reports without treating partial or unhandled outcomes as parity", async () => {
|
||||
const root = await createTestTempDirectory("rea-ci-selection-report-");
|
||||
await workflowGit(root, ["init"]);
|
||||
const paths = [
|
||||
"src/sqlite/provider.test.ts",
|
||||
"src/evm/provider.test.ts",
|
||||
"tests/boundary/mcp/workflow.test.ts",
|
||||
];
|
||||
for (const path of paths) {
|
||||
await mkdir(join(root, path, ".."), { recursive: true });
|
||||
await writeFile(join(root, path), "// fixture\n");
|
||||
}
|
||||
await workflowGit(root, ["add", "src", "tests"]);
|
||||
const timing = {
|
||||
version: 1,
|
||||
success: false,
|
||||
reason: "failed",
|
||||
unhandledErrors: 0,
|
||||
files: paths.map((name, index) => ({
|
||||
name,
|
||||
durationMs: 10,
|
||||
state: index === 1 ? "failed" : "passed",
|
||||
})),
|
||||
};
|
||||
const run = async (report: unknown) => {
|
||||
await writeFile(join(root, "test-timings.json"), JSON.stringify(report));
|
||||
await execute(process.execPath, [fileURLToPath(script)], {
|
||||
cwd: root,
|
||||
env: {
|
||||
...process.env,
|
||||
SHARD_RESULT: "failure",
|
||||
MERGE_RESULT: "failure",
|
||||
CI_VERIFY_TEST_INVENTORY: "true",
|
||||
CI_TEST_SELECTION: JSON.stringify(
|
||||
planTestSelection(["src/sqlite/Provider.ts"], "pull_request", "fast"),
|
||||
),
|
||||
GITHUB_SHA: "merge-sha",
|
||||
CI_PR_HEAD_SHA: "pr-head-sha",
|
||||
},
|
||||
});
|
||||
return JSON.parse(
|
||||
await readFile(
|
||||
join(root, ".cache/ci-test-selection/report.json"),
|
||||
"utf8",
|
||||
),
|
||||
) as unknown;
|
||||
};
|
||||
expect(await run(timing)).toMatchObject({
|
||||
observational: true,
|
||||
complete: true,
|
||||
selected: [paths[0], paths[2]],
|
||||
omitted: [paths[1]],
|
||||
missedFailures: [paths[1]],
|
||||
executionSha: "merge-sha",
|
||||
prHeadSha: "pr-head-sha",
|
||||
});
|
||||
for (const report of [
|
||||
{ ...timing, files: timing.files.slice(0, 1) },
|
||||
{ ...timing, unhandledErrors: 1 },
|
||||
{ ...timing, reason: "interrupted" },
|
||||
])
|
||||
expect(await run(report)).toMatchObject({ complete: false });
|
||||
await expect(run({ ...timing, files: "invalid" })).rejects.toMatchObject({
|
||||
code: 1,
|
||||
});
|
||||
await expect(
|
||||
readFile(join(root, ".cache/ci-test-selection/report.json")),
|
||||
).rejects.toMatchObject({ code: "ENOENT" });
|
||||
await expect(
|
||||
readFile(join(root, ".cache/ci-test-history/test-results.json")),
|
||||
).rejects.toMatchObject({ code: "ENOENT" });
|
||||
});
|
||||
|
||||
@@ -0,0 +1,240 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
compareTestSelection,
|
||||
planTestSelection,
|
||||
} from "../../scripts/ci/test-selection.mjs";
|
||||
|
||||
const sqliteSource = "src/sqlite/SqliteDatabaseProvider.test.ts";
|
||||
const sqliteBoundary = "tests/boundary/sqlite/sqliteDatabaseProvider.test.ts";
|
||||
const adbSource = "src/adb/AdbProvider.test.ts";
|
||||
const adbBoundary =
|
||||
"tests/boundary/providers/adb/adbBugreportPublication.test.ts";
|
||||
const cliBoundary = "tests/boundary/cli/apktoolCli.test.ts";
|
||||
const mcpBoundary = "tests/boundary/mcp/apktoolMcp.test.ts";
|
||||
const processBoundary =
|
||||
"tests/boundary/process/processCaptureLifecycle.test.ts";
|
||||
const acceptance = "tests/acceptance/tools/localToolContracts.test.ts";
|
||||
const composition = "tests/composition/directAnalysisCleanup.test.ts";
|
||||
const evaluation = "tests/evaluation/testDiscovery.test.ts";
|
||||
|
||||
const passed = (name: string) => ({ name, durationMs: 10, state: "passed" });
|
||||
|
||||
it("unions affected leaf owners, keeps changed tests and retains unowned integration tests", () => {
|
||||
const plan = planTestSelection(
|
||||
["src/sqlite/SqliteDatabaseProvider.ts", adbBoundary],
|
||||
"pull_request",
|
||||
"fast",
|
||||
);
|
||||
const inventory = [
|
||||
sqliteSource,
|
||||
sqliteBoundary,
|
||||
adbSource,
|
||||
adbBoundary,
|
||||
cliBoundary,
|
||||
mcpBoundary,
|
||||
processBoundary,
|
||||
acceptance,
|
||||
composition,
|
||||
evaluation,
|
||||
];
|
||||
const report = compareTestSelection(plan, inventory, inventory.map(passed));
|
||||
|
||||
expect(plan).toMatchObject({
|
||||
mode: "candidate",
|
||||
owners: ["adb", "sqlite"],
|
||||
});
|
||||
expect(report.selected).toEqual(
|
||||
expect.arrayContaining([
|
||||
sqliteSource,
|
||||
sqliteBoundary,
|
||||
adbSource,
|
||||
adbBoundary,
|
||||
cliBoundary,
|
||||
mcpBoundary,
|
||||
processBoundary,
|
||||
acceptance,
|
||||
composition,
|
||||
evaluation,
|
||||
]),
|
||||
);
|
||||
expect(report.omitted).toEqual([]);
|
||||
});
|
||||
|
||||
it("omits only unrelated owned tests while retaining dynamic boundary suites", () => {
|
||||
const plan = planTestSelection(
|
||||
["src/sqlite/SqliteDatabaseProvider.ts"],
|
||||
"pull_request",
|
||||
"fast",
|
||||
);
|
||||
const inventory = [
|
||||
sqliteSource,
|
||||
sqliteBoundary,
|
||||
adbSource,
|
||||
adbBoundary,
|
||||
cliBoundary,
|
||||
mcpBoundary,
|
||||
processBoundary,
|
||||
acceptance,
|
||||
composition,
|
||||
evaluation,
|
||||
];
|
||||
const report = compareTestSelection(plan, inventory, inventory.map(passed));
|
||||
|
||||
expect(report.selected).toEqual(
|
||||
expect.arrayContaining([
|
||||
sqliteSource,
|
||||
sqliteBoundary,
|
||||
cliBoundary,
|
||||
mcpBoundary,
|
||||
processBoundary,
|
||||
acceptance,
|
||||
composition,
|
||||
evaluation,
|
||||
]),
|
||||
);
|
||||
expect(report.omitted).toEqual([adbSource, adbBoundary]);
|
||||
expect(report.complete).toBe(true);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["unowned shared source", "src/application/Workflow.ts"],
|
||||
["fixture input", "tests/conformance/c/fixture.c"],
|
||||
["configuration", "vitest.config.ts"],
|
||||
["documentation", "README.md"],
|
||||
["CLI implementation", "src/cli/apktoolCommands.ts"],
|
||||
["MCP implementation", "src/server/registerSqliteTools.ts"],
|
||||
["process ownership", "src/process/ProcessOwnership.ts"],
|
||||
["acceptance test", acceptance],
|
||||
["composition test", composition],
|
||||
])("uses full fallback for %s changes", (_description, path) => {
|
||||
expect(planTestSelection([path], "pull_request", "fast")).toMatchObject({
|
||||
mode: "full",
|
||||
owners: [],
|
||||
changedTests: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("uses full fallback outside ordinary fast pull requests or without diff paths", () => {
|
||||
expect(
|
||||
planTestSelection(["src/sqlite/SqliteDatabaseProvider.ts"], "push", "fast")
|
||||
.mode,
|
||||
).toBe("full");
|
||||
expect(
|
||||
planTestSelection(
|
||||
["src/sqlite/SqliteDatabaseProvider.ts"],
|
||||
"pull_request",
|
||||
"full",
|
||||
).mode,
|
||||
).toBe("full");
|
||||
expect(planTestSelection([], "pull_request", "fast").mode).toBe("full");
|
||||
});
|
||||
|
||||
it("keeps new changed tests and falls back when a changed test was removed", () => {
|
||||
const addedTest = "src/sqlite/NewDatabaseRule.test.ts";
|
||||
const candidate = planTestSelection([addedTest], "pull_request", "fast");
|
||||
expect(candidate.changedTests).toEqual([addedTest]);
|
||||
const inventory = [addedTest, adbSource];
|
||||
expect(
|
||||
compareTestSelection(candidate, inventory, inventory.map(passed)).selected,
|
||||
).toContain(addedTest);
|
||||
|
||||
const removedTest = "src/sqlite/RemovedDatabaseRule.test.ts";
|
||||
const report = compareTestSelection(
|
||||
planTestSelection([removedTest], "pull_request", "fast"),
|
||||
[sqliteSource, adbSource],
|
||||
[passed(sqliteSource), passed(adbSource)],
|
||||
);
|
||||
expect(report.plan.mode).toBe("full");
|
||||
expect(report.selected).toEqual([adbSource, sqliteSource]);
|
||||
expect(report.omitted).toEqual([]);
|
||||
});
|
||||
|
||||
it("marks incomplete inventories and nonterminal outcomes as incomplete", () => {
|
||||
const plan = planTestSelection(
|
||||
["src/sqlite/SqliteDatabaseProvider.ts"],
|
||||
"pull_request",
|
||||
"fast",
|
||||
);
|
||||
const inventory = [sqliteSource, adbSource];
|
||||
const completeResults = inventory.map(passed);
|
||||
|
||||
expect(
|
||||
compareTestSelection(plan, inventory, [passed(sqliteSource)]).complete,
|
||||
).toBe(false);
|
||||
expect(
|
||||
compareTestSelection(plan, inventory, [
|
||||
...completeResults,
|
||||
passed("tests/evaluation/unexpected.test.ts"),
|
||||
]),
|
||||
).toMatchObject({
|
||||
complete: false,
|
||||
unexpected: ["tests/evaluation/unexpected.test.ts"],
|
||||
});
|
||||
expect(
|
||||
compareTestSelection(plan, inventory, [
|
||||
...completeResults,
|
||||
passed(adbSource),
|
||||
]),
|
||||
).toMatchObject({ complete: false, duplicateFiles: 1 });
|
||||
for (const state of ["pending", "skipped"])
|
||||
expect(
|
||||
compareTestSelection(plan, inventory, [
|
||||
passed(sqliteSource),
|
||||
{ name: adbSource, durationMs: 0, state },
|
||||
]),
|
||||
).toMatchObject({ complete: false, unobserved: [adbSource] });
|
||||
});
|
||||
|
||||
it("reports a failure from an omitted test, including collection or module failures", () => {
|
||||
const plan = planTestSelection(
|
||||
["src/sqlite/SqliteDatabaseProvider.ts"],
|
||||
"pull_request",
|
||||
"fast",
|
||||
);
|
||||
const report = compareTestSelection(
|
||||
plan,
|
||||
[sqliteSource, adbSource],
|
||||
[passed(sqliteSource), { name: adbSource, durationMs: 1, state: "failed" }],
|
||||
);
|
||||
|
||||
expect(report.omitted).toContain(adbSource);
|
||||
expect(report.missedFailures).toEqual([adbSource]);
|
||||
});
|
||||
|
||||
it("rejects plans that name unowned owners or malformed changed tests", () => {
|
||||
const plan = planTestSelection(
|
||||
["src/sqlite/SqliteDatabaseProvider.ts"],
|
||||
"pull_request",
|
||||
"fast",
|
||||
);
|
||||
expect(() =>
|
||||
compareTestSelection(
|
||||
{ ...plan, owners: ["unknown"] },
|
||||
[sqliteSource],
|
||||
[passed(sqliteSource)],
|
||||
),
|
||||
).toThrow("Invalid observational test selection plan");
|
||||
expect(() =>
|
||||
compareTestSelection(
|
||||
{ ...plan, changedTests: ["src/sqlite/not-a-test.ts"] },
|
||||
[sqliteSource],
|
||||
[passed(sqliteSource)],
|
||||
),
|
||||
).toThrow("Invalid observational test selection plan");
|
||||
});
|
||||
|
||||
it("uses full fallback when a changed owner has no executable tests", () => {
|
||||
const report = compareTestSelection(
|
||||
planTestSelection(
|
||||
["src/sqlite/SqliteDatabaseProvider.ts"],
|
||||
"pull_request",
|
||||
"fast",
|
||||
),
|
||||
[adbSource],
|
||||
[passed(adbSource)],
|
||||
);
|
||||
|
||||
expect(report.plan.mode).toBe("full");
|
||||
expect(report.omitted).toEqual([]);
|
||||
});
|
||||
Reference in New Issue
Block a user