Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(module-pins): allow test files added after release in source parity

Steven Enamakel8dd55d540095
diff --git a/scripts/__tests__/module-pins.test.mjs b/scripts/__tests__/module-pins.test.mjs
index b454d8c040..af78e3be3a 100644
--- a/scripts/__tests__/module-pins.test.mjs
+++ b/scripts/__tests__/module-pins.test.mjs
@@ -322,7 +322,7 @@ function sourceParityFixture() {
return { root, git, releaseCommit, candidateCommit, parity };
}
-function sourceParitySetFixture() {
+function sourceParitySetFixture({ includeNewTest = false } = {}) {
const root = mkdtempSync(join(tmpdir(), "module-source-parity-set-"));
const git = (args) =>
execFileSync("git", args, { cwd: root, stdio: "ignore" });
@@ -333,7 +333,10 @@ function sourceParitySetFixture() {
git(["config", "tag.gpgsign", "false"]);
mkdirSync(join(root, "src"), { recursive: true });
writeFileSync(join(root, "Cargo.toml"), '[package]\nname = "fixture"\nversion = "1.0.0"\n');
- writeFileSync(join(root, "src/lib.rs"), "pub mod alpha;\npub mod beta;\npub mod gamma;\n");
+ writeFileSync(
+ join(root, "src/lib.rs"),
+ "pub mod alpha;\npub mod beta;\npub mod gamma;\npub mod future;\n",
+ );
const paths = ["src/alpha_tests.rs", "src/beta_tests.rs", "src/gamma_tests.rs"];
const modulePaths = ["src/alpha.rs", "src/beta.rs", "src/gamma.rs"];
@@ -344,6 +347,12 @@ function sourceParitySetFixture() {
);
writeFileSync(join(root, paths[index]), `#[test] fn works_${index}() {}\n`);
}
+ const futurePath = "src/future_tests.rs";
+ const futureModulePath = "src/future.rs";
+ writeFileSync(
+ join(root, futureModulePath),
+ '#[cfg(test)]\n#[path = "future_tests.rs"]\nmod tests;\npub fn future() {}\n',
+ );
git(["add", "."]);
git(["commit", "-qm", "release"]);
git(["tag", "-a", "-m", "release", "v1.0.0"]);
@@ -357,28 +366,41 @@ function sourceParitySetFixture() {
`#[test] fn works_${index}() { assert_eq!(${index}, ${index}); }\n`,
);
}
+ if (includeNewTest) {
+ writeFileSync(join(root, futurePath), "#[test] fn future_test() {}\n");
+ }
git(["add", "."]);
git(["commit", "-qm", "owner test set"]);
const candidateCommit = execFileSync("git", ["rev-parse", "HEAD"], {
cwd: root,
encoding: "utf8",
}).trim();
- const blobAt = (commit, path) =>
- execFileSync("git", ["rev-parse", `${commit}:${path}`], {
- cwd: root,
- encoding: "utf8",
- }).trim();
- const testFiles = paths.map((path) => ({
+ const blobAt = (commit, path) => {
+ try {
+ return execFileSync("git", ["rev-parse", `${commit}:${path}`], {
+ cwd: root,
+ encoding: "utf8",
+ stdio: ["ignore", "pipe", "ignore"],
+ }).trim();
+ } catch {
+ return undefined;
+ }
+ };
+ const testPaths = includeNewTest ? [...paths, futurePath] : paths;
+ const testFiles = testPaths.map((path) => ({
path,
- releaseMode: "100644",
- releaseBlob: blobAt(releaseCommit, path),
+ releaseMode: blobAt(releaseCommit, path) ? "100644" : null,
+ releaseBlob: blobAt(releaseCommit, path) ?? null,
candidateMode: "100644",
candidateBlob: blobAt(candidateCommit, path),
}));
- const bindings = modulePaths.map((modulePath, index) => ({
+ const bindingPaths = includeNewTest
+ ? [...modulePaths, futureModulePath]
+ : modulePaths;
+ const bindings = bindingPaths.map((modulePath, index) => ({
modulePath,
moduleBlob: blobAt(candidateCommit, modulePath),
- testPath: paths[index],
+ testPath: testPaths[index],
}));
const canonicalTree = execFileSync(
"git",
@@ -391,7 +413,7 @@ function sourceParitySetFixture() {
const match = entry.match(
/^([0-7]{6}) (blob|commit) ([0-9a-f]{40})\t([\s\S]+)$/,
);
- if (paths.includes(match[4])) return null;
+ if (testPaths.includes(match[4])) return null;
return `${match[1]} ${match[2]} ${match[3]}\t${match[4]}\n`;
})
.filter(Boolean)
@@ -415,7 +437,7 @@ function sourceParitySetFixture() {
unchangedTreeSha256: createHash("sha256").update(canonicalTree).digest("hex"),
bindings,
};
- return { root, git, releaseCommit, candidateCommit, parity, paths };
+ return { root, git, releaseCommit, candidateCommit, parity, paths: testPaths };
}
const provider = {
id: "tinyx-lang",
@@ -462,6 +484,26 @@ test("source parity proof accepts an explicit set of exact test-only files", ()
}
});
+test("multi-file source parity can attest an explicitly bound test file added after release", () => {
+ const fixture = sourceParitySetFixture({ includeNewTest: true });
+ try {
+ const result = validateTestOnlySourceParity({
+ repoPath: fixture.root,
+ version: "1.0.0",
+ assets: [
+ { hostKey: "linux", archive: "fixture.tar.gz", sha256: "a".repeat(64) },
+ ],
+ actualHead: fixture.candidateCommit,
+ proof: fixture.parity,
+ });
+ assert.equal(result.ok, true, result.message);
+ assert.equal(fixture.parity.testFiles.at(-1).releaseMode, null);
+ assert.equal(fixture.parity.testFiles.at(-1).releaseBlob, null);
+ } finally {
+ rmSync(fixture.root, { recursive: true, force: true });
+ }
+});
+
test("multi-file source parity rejects omitted files, extra changes, and widened descendants", () => {
const assets = [
{ hostKey: "linux", archive: "fixture.tar.gz", sha256: "a".repeat(64) },
diff --git a/scripts/lib/module-pins.mjs b/scripts/lib/module-pins.mjs
index 50122c4ee6..d1efe43635 100644
--- a/scripts/lib/module-pins.mjs
+++ b/scripts/lib/module-pins.mjs
@@ -315,14 +315,19 @@ export function validateTestOnlySourceParity({
throw new Error("test-file paths must be unique safe Rust source paths");
}
filePaths.add(file.path);
- if (file.releaseMode !== "100644" || file.candidateMode !== "100644") {
+ const newTestFile =
+ fileSetProof && file.releaseMode === null && file.releaseBlob === null;
+ if (
+ (!newTestFile && file.releaseMode !== "100644") ||
+ file.candidateMode !== "100644"
+ ) {
throw new Error("attested test file must remain a regular non-executable file");
}
if (
- ![file.releaseBlob, file.candidateBlob].every((sha) =>
- /^[0-9a-f]{40}$/.test(sha),
- ) ||
- file.releaseBlob === file.candidateBlob
+ !/^[0-9a-f]{40}$/.test(file.candidateBlob) ||
+ (!newTestFile &&
+ (!/^[0-9a-f]{40}$/.test(file.releaseBlob) ||
+ file.releaseBlob === file.candidateBlob))
) {
throw new Error("test-file blob pair is malformed or unchanged");
}
@@ -369,14 +374,18 @@ export function validateTestOnlySourceParity({
for (const file of files) {
const releaseFile = releaseEntries.find((item) => item.path === file.path);
const candidateFile = candidateEntries.find((item) => item.path === file.path);
+ const newTestFile =
+ fileSetProof && file.releaseMode === null && file.releaseBlob === null;
if (
- !releaseFile ||
+ (newTestFile
+ ? releaseFile !== undefined
+ : !releaseFile ||
+ releaseFile.mode !== file.releaseMode ||
+ releaseFile.type !== "blob" ||
+ releaseFile.oid !== file.releaseBlob) ||
!candidateFile ||
- releaseFile.mode !== file.releaseMode ||
candidateFile.mode !== file.candidateMode ||
- releaseFile.type !== "blob" ||
candidateFile.type !== "blob" ||
- releaseFile.oid !== file.releaseBlob ||
candidateFile.oid !== file.candidateBlob
) {
throw new Error(