Qualify complete CI plans when setup invalidates the graph

This commit is contained in:
Codex committed 2026-11-15 12:26:43 -06:00
1 parent a0a7e3a247
commit fb69258afc
3 files changed
+73 -3

No files matched your search

@@ -51,7 +51,7 @@ jobs:
import { readFileSync } from 'node:fs';
import { execFileSync } from 'node:child_process';
import { planTasks } from './.github/scripts/ci-plan.mjs';
import { createTestSelection } from './scripts/ci/select-tests.mjs';
import { createTestSelection, completeTestSelectionFallback } from './scripts/ci/select-tests.mjs';
const config = JSON.parse(readFileSync('turbo.json', 'utf8'));
const lanes = JSON.parse(readFileSync('.github/ci-task-matrix.json', 'utf8'));
const head = execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
@@ -60,7 +60,24 @@ jobs:
['server/src/middleware/auth.ts', '@paperclipai/server', 'server/src/__tests__/agent-auth-middleware.test.ts'],
['server/src/storage/config.test.ts', '@paperclipai/server', 'server/src/storage/config.test.ts'],
]) {
const selected = await createTestSelection(planTasks({ config, lanes, paths: [file, "doc/DEVELOPING.md", "doc/plans/2026-10-30-ci-proof.md"] }), head);
const plan = planTasks({ config, lanes, paths: [file, "doc/DEVELOPING.md", "doc/plans/2026-10-30-ci-proof.md"] });
let selected;
try {
selected = await createTestSelection(plan, head);
} catch (error) {
// Product setup may legitimately invalidate its reviewed, hash-pinned graph.
// Qualify the same complete-plan fallback that the production CLI publishes.
assert.equal(project, '@paperclipai/server', 'The UI case must still prove real narrowing');
assert.match(error.message, /^Opaque setup (?:dependency|builtin|package|module): /);
const fallback = completeTestSelectionFallback(plan, error);
assert.deepEqual(fallback.plan, { ...plan, testSelectionFallback: error.message });
assert.deepEqual(fallback.plan.jobs, plan.jobs, 'Every original lane, shard and budget must remain');
assert.equal(fallback.plan.testSelection, undefined);
assert.equal(fallback.manifest, undefined);
assert.equal(fallback.graphs, undefined);
console.log(file, 'COMPLETE_PLAN_FALLBACK', JSON.stringify(fallback.plan, null, 2));
continue;
}
const graph = selected.graphs.find(graph => graph.project === project);
assert.ok(graph.related.includes(related));
assert.ok(graph.alwaysRun.length > 0, 'Filesystem contracts must remain covered');
+6 -1
View File
@@ -80,6 +80,11 @@ export async function createTestSelection(plan, head) {
return { ...refineTestPlan({ plan, head, owners, graphs, durations: selectionDurations() }), graphs };
}
// An unavailable graph cannot remove any lane or shard from the coarse task plan.
export function completeTestSelectionFallback(plan, error) {
return { plan: { ...plan, testSelectionFallback: error.message } };
}
async function main() {
const plan = JSON.parse(process.env.CI_PLAN || "null");
const output = (key, value) => {
@@ -111,7 +116,7 @@ async function main() {
output("selected", "true");
} catch (error) {
console.warn(`Using the complete task plan: ${error.message}`);
result = { plan: { ...plan, testSelectionFallback: error.message } };
result = completeTestSelectionFallback(plan, error);
output("selected", "false");
}
writeFileSync(`${directory}/plan.json`, JSON.stringify(result.plan));
@@ -232,3 +232,51 @@ test("mixed audited documentation stays graph eligible and large complete source
assert.ok(selectionEligibility({ ...plan, changed: ["doc/DEVELOPING.md"] }));
assert.ok(selectionEligibility({ ...plan, changed: [...plan.changed, "docs/api/issues.md"] }));
});
test("the CLI retains every coarse lane and shard when real Vitest setup is opaque", (t) => {
const directory = realpathSync(mkdtempSync(path.join(tmpdir(), "ci-opaque-setup-")));
t.after(() => rmSync(directory, { recursive: true, force: true }));
const write = (file, source) => {
mkdirSync(path.dirname(path.join(directory, file)), { recursive: true });
writeFileSync(path.join(directory, file), source);
};
symlinkSync(path.join(root, "node_modules"), path.join(directory, "node_modules"), "dir");
write(".gitignore", "node_modules/\n");
write("vitest.config.mjs", 'export default {test:{projects:["ui"]}}');
write("ui/vitest.config.mjs", 'export default {test:{name:"fixture",include:["src/**/*.test.ts"],setupFiles:["./setup.ts"]}}');
write("ui/setup.ts", 'import {readFileSync} from "node:fs"; readFileSync(process.env.INPUT);');
write("ui/src/input.ts", "export const value = 1;");
write("ui/src/input.test.ts", 'import {value} from "./input"; throw new Error("selection must not execute tests " + value);');
// Supply only the fixture's coarse inventory; the real graph worker still has to inspect its setup.
write("scripts/run-vitest-stable.mjs", 'console.log(JSON.stringify({workspaceProjects:["fixture"]}));');
const git = (...args) => execFileSync("git", args, { cwd: directory, encoding: "utf8" }).trim();
const commit = () => git("-c", "user.name=CI", "-c", "user.email=ci@example.invalid", "commit", "-qam", "fixture");
git("init", "-q"); git("add", "."); commit();
const base = git("rev-parse", "HEAD");
git("checkout", "-qb", "pr"); write("ui/src/input.ts", "export const value = 2;"); commit();
const prHead = git("rev-parse", "HEAD");
git("checkout", "--detach", base);
git("-c", "user.name=CI", "-c", "user.email=ci@example.invalid", "merge", "--no-ff", "pr", "-m", "merge");
const merge = git("rev-parse", "HEAD");
const plan = { version: 1, mode: "enabled", forceReason: null, ...mergeDiff(merge, prHead, directory),
jobs: {
general_tests: { run: true, selected: 2, total: 2, matrix: { include: [0, 1].map(shard_index => ({
group: "general-workspaces-a", task: "ci:workspaces-a", shard_index, shard_count: 2,
})) } },
verify_serialized_server: { run: false, matrix: { include: [{ task: "ci:serialized" }] } },
untouched_native_lane: { run: true, matrix: { include: [{ task: "ci:native", shard_index: 0 }] } },
} };
const result = spawnSync(process.execPath, [path.join(root, "scripts/ci/select-tests.mjs")], {
cwd: directory, encoding: "utf8", env: { ...process.env, CI_PLAN: JSON.stringify(plan), BASE_SHA: base,
GITHUB_SHA: merge, GITHUB_OUTPUT: "", GITHUB_STEP_SUMMARY: "" },
});
assert.equal(result.status, 0, result.stderr);
const fallback = JSON.parse(readFileSync(path.join(directory, ".ci-test-selection/plan.json"), "utf8"));
assert.match(fallback.testSelectionFallback, /^Opaque setup builtin: node:fs$/);
assert.deepEqual(fallback, { ...plan, testSelectionFallback: fallback.testSelectionFallback });
assert.deepEqual(fallback.jobs, plan.jobs);
assert.equal(fallback.testSelection, undefined);
assert.throws(() => readFileSync(path.join(directory, ".ci-test-selection/manifest.json")), { code: "ENOENT" });
assert.throws(() => readFileSync(path.join(directory, ".ci-test-selection/audit.json")), { code: "ENOENT" });
});