Skip to content

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

refactor(pins): improve parameter destructuring in pin classification

Steven Enamakel3e1b56b0b01f
diff --git a/scripts/lib/module-pin-status.mjs b/scripts/lib/module-pin-status.mjs
index 76b388f3fe..c4e1733367 100644
--- a/scripts/lib/module-pin-status.mjs
+++ b/scripts/lib/module-pin-status.mjs
@@ -52,7 +52,14 @@ export function classifyStatus({
exemption,
sourceParityContext,
}) {
- const strict = classifyPin({ id, version, submodulePath, actual, exemption, sourceParityContext });
+ const strict = classifyPin({
+ id,
+ version,
+ submodulePath,
+ actual,
+ exemption,
+ sourceParityContext,
+ });
if (strict.kind === "exempt") {
return {
id,
@@ -70,7 +77,7 @@ export function classifyStatus({
? " (the drift moved past its module-pin-exemptions.json entry)"
: strict.kind === "invalid-source-parity"
? ` (${strict.message})`
- : "";
+ : "";
if (strict.kind === "match" || strict.kind === "stale-exemption") {
return { id, kind: "in-sync", actual, message: `in sync${note}` };
}
diff --git a/scripts/lib/module-pins.mjs b/scripts/lib/module-pins.mjs
index 9e87ec85d1..abe05d70d4 100644
--- a/scripts/lib/module-pins.mjs
+++ b/scripts/lib/module-pins.mjs
@@ -98,7 +98,14 @@ export function parseRecords(src) {
* A declared exemption accepts one exact drift only. A stale exemption is not
* harmless: it is a standing licence for the next real drift to pass unnoticed.
*/
-export function classifyPin({ id, version, submodulePath, actual, exemption, sourceParityContext }) {
+export function classifyPin({
+ id,
+ version,
+ submodulePath,
+ actual,
+ exemption,
+ sourceParityContext,
+}) {
const wanted = `v${version}`;
if (actual === wanted) {
if (exemption) {
@@ -191,7 +198,8 @@ export function validateTestOnlySourceParity({
assets,
actualHead,
proof,
- runGit = (args) => execFileSync("git", args, { cwd: repoPath, encoding: "utf8" }).trim(),
+ runGit = (args) =>
+ execFileSync("git", args, { cwd: repoPath, encoding: "utf8" }).trim(),
}) {
try {
if (typeof repoPath !== "string" || repoPath.length === 0) {
@@ -206,7 +214,10 @@ export function validateTestOnlySourceParity({
"unchangedTreeSha256",
"binding",
];
- if (!proof || Object.keys(proof).sort().join(",") !== required.sort().join(",")) {
+ if (
+ !proof ||
+ Object.keys(proof).sort().join(",") !== required.sort().join(",")
+ ) {
throw new Error("proof fields are missing or unknown");
}
if (!/^v\d+\.\d+\.\d+$/.test(proof.tag) || proof.tag !== `v${version}`) {
@@ -216,12 +227,25 @@ export function validateTestOnlySourceParity({
["releaseCommit", proof.releaseCommit],
["candidateCommit", proof.candidateCommit],
]) {
- if (!/^[0-9a-f]{40}$/.test(sha)) throw new Error(`${name} must be a full commit SHA`);
+ if (!/^[0-9a-f]{40}$/.test(sha)) {
+ throw new Error(`${name} must be a full commit SHA`);
+ }
+ }
+ if (actualHead !== proof.candidateCommit) {
+ throw new Error("HEAD is not the exact attested candidate commit");
+ }
+ if (runGit(["rev-parse", "HEAD"]) !== proof.candidateCommit) {
+ throw new Error("checked-out HEAD differs from attested candidate");
+ }
+ if (runGit(["status", "--porcelain", "--untracked-files=all"])) {
+ throw new Error("module worktree is dirty");
+ }
+ if (
+ runGit(["rev-parse", `refs/tags/${proof.tag}^{commit}`]) !==
+ proof.releaseCommit
+ ) {
+ throw new Error("release tag does not resolve to the attested release commit");
}
- if (actualHead !== proof.candidateCommit) throw new Error("HEAD is not the exact attested candidate commit");
- if (runGit(["rev-parse", "HEAD"]) !== proof.candidateCommit) throw new Error("checked-out HEAD differs from attested candidate");
- if (runGit(["status", "--porcelain", "--untracked-files=all"])) throw new Error("module worktree is dirty");
- if (runGit(["rev-parse", `refs/tags/${proof.tag}^{commit}`]) !== proof.releaseCommit) throw new Error("release tag does not resolve to the attested release commit");
runGit(["merge-base", "--is-ancestor", proof.releaseCommit, proof.candidateCommit]);
const assetPayload = JSON.stringify({
@@ -230,49 +254,128 @@ export function validateTestOnlySourceParity({
.map(({ hostKey, archive, sha256 }) => ({ hostKey, archive, sha256 }))
.sort((a, b) => a.hostKey.localeCompare(b.hostKey)),
});
- if (sha256(assetPayload) !== proof.assetsSha256) throw new Error("registry version or artifact asset map changed");
- if (!/^[0-9a-f]{64}$/.test(proof.assetsSha256)) throw new Error("asset-map digest is malformed");
- if (!/^[0-9a-f]{64}$/.test(proof.unchangedTreeSha256)) throw new Error("unchanged-tree digest is malformed");
+ if (sha256(assetPayload) !== proof.assetsSha256) {
+ throw new Error("registry version or artifact asset map changed");
+ }
+ if (!/^[0-9a-f]{64}$/.test(proof.assetsSha256)) {
+ throw new Error("asset-map digest is malformed");
+ }
+ if (!/^[0-9a-f]{64}$/.test(proof.unchangedTreeSha256)) {
+ throw new Error("unchanged-tree digest is malformed");
+ }
const file = proof.testFile;
- if (!file || Object.keys(file).sort().join(",") !== "candidateBlob,candidateMode,path,releaseBlob,releaseMode") {
+ if (
+ !file ||
+ Object.keys(file).sort().join(",") !==
+ "candidateBlob,candidateMode,path,releaseBlob,releaseMode"
+ ) {
throw new Error("test-file proof fields are missing or unknown");
}
- const validRepoPath = (value) => typeof value === "string" && /^[A-Za-z0-9_./-]+$/.test(value) && !posix.isAbsolute(value) && !value.split("/").includes("..");
- if (!proof.binding || !validRepoPath(file.path) || !validRepoPath(proof.binding.modulePath) || !file.path.endsWith(".rs") || file.path !== proof.binding.testPath || posix.dirname(file.path) !== posix.dirname(proof.binding.modulePath)) throw new Error("test path is not a safe sibling of the attested module binding");
- if (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) throw new Error("test-file blob pair is malformed or unchanged");
- const entries = (ref) => runGit(["ls-tree", "-r", "--full-tree", "-z", ref])
- .split("\0")
- .filter(Boolean)
- .map((entry) => {
- const match = entry.match(/^([0-7]{6}) (blob|commit) ([0-9a-f]{40})\t([\s\S]+)$/);
- if (!match) throw new Error(`unsupported tree entry in ${ref}`);
- if (!/^[\x20-\x7e]+$/.test(match[4])) throw new Error(`unsupported non-printable Git path in ${ref}`);
- return { mode: match[1], type: match[2], oid: match[3], path: match[4] };
- });
+ const validRepoPath =
+ (value) =>
+ typeof value === "string" &&
+ /^[A-Za-z0-9_./-]+$/.test(value) &&
+ !posix.isAbsolute(value) &&
+ !value.split("/").includes("..");
+ if (
+ !proof.binding ||
+ !validRepoPath(file.path) ||
+ !validRepoPath(proof.binding.modulePath) ||
+ !file.path.endsWith(".rs") ||
+ file.path !== proof.binding.testPath ||
+ posix.dirname(file.path) !== posix.dirname(proof.binding.modulePath)
+ ) {
+ throw new Error("test path is not a safe sibling of the attested module binding");
+ }
+ if (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
+ ) {
+ throw new Error("test-file blob pair is malformed or unchanged");
+ }
+ const entries = (ref) =>
+ runGit(["ls-tree", "-r", "--full-tree", "-z", ref])
+ .split("\0")
+ .filter(Boolean)
+ .map((entry) => {
+ const match = entry.match(
+ /^([0-7]{6}) (blob|commit) ([0-9a-f]{40})\t([\s\S]+)$/,
+ );
+ if (!match) throw new Error(`unsupported tree entry in ${ref}`);
+ if (!/^[\x20-\x7e]+$/.test(match[4])) {
+ throw new Error(`unsupported non-printable Git path in ${ref}`);
+ }
+ return {
+ mode: match[1],
+ type: match[2],
+ oid: match[3],
+ path: match[4],
+ };
+ });
const releaseEntries = entries(proof.releaseCommit);
const candidateEntries = entries(proof.candidateCommit);
const select = (items) => items.find((item) => item.path === file.path);
const releaseFile = select(releaseEntries);
const candidateFile = select(candidateEntries);
- if (!releaseFile || !candidateFile || releaseFile.mode !== file.releaseMode || candidateFile.mode !== file.candidateMode || releaseFile.type !== "blob" || candidateFile.type !== "blob" || releaseFile.oid !== file.releaseBlob || candidateFile.oid !== file.candidateBlob) {
+ if (
+ !releaseFile ||
+ !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("attested test file path, mode, or blob does not match the Git trees");
}
- const treeHash = (items) => sha256(items.filter((item) => item.path !== file.path)
- .map(({ mode, type, oid, path }) => `${mode} ${type} ${oid}\t${path}\n`)
- .sort().join(""));
+ const treeHash = (items) =>
+ sha256(
+ items
+ .filter((item) => item.path !== file.path)
+ .map(({ mode, type, oid, path }) => `${mode} ${type} ${oid}\t${path}\n`)
+ .sort()
+ .join(""),
+ );
const releaseTreeHash = treeHash(releaseEntries);
const candidateTreeHash = treeHash(candidateEntries);
- if (releaseTreeHash !== proof.unchangedTreeSha256 || candidateTreeHash !== proof.unchangedTreeSha256) throw new Error(`other source, manifest, lock, build input, or gitlink differs from the release tree (${releaseTreeHash}/${candidateTreeHash} expected ${proof.unchangedTreeSha256})`);
+ if (
+ releaseTreeHash !== proof.unchangedTreeSha256 ||
+ candidateTreeHash !== proof.unchangedTreeSha256
+ ) {
+ throw new Error(
+ "other source, manifest, lock, build input, or gitlink differs from the release tree",
+ );
+ }
const binding = proof.binding;
- if (!binding || Object.keys(binding).sort().join(",") !== "moduleBlob,modulePath,testPath" || !/^[0-9a-f]{40}$/.test(binding.moduleBlob)) throw new Error("module binding proof is malformed");
+ if (
+ !binding ||
+ Object.keys(binding).sort().join(",") !== "moduleBlob,modulePath,testPath" ||
+ !/^[0-9a-f]{40}$/.test(binding.moduleBlob)
+ ) {
+ throw new Error("module binding proof is malformed");
+ }
const moduleEntry = candidateEntries.find((item) => item.path === binding.modulePath);
- if (!moduleEntry || moduleEntry.type !== "blob" || moduleEntry.mode !== "100644" || moduleEntry.oid !== binding.moduleBlob) throw new Error("test module declaration source differs from the attested blob");
+ if (
+ !moduleEntry ||
+ moduleEntry.type !== "blob" ||
+ moduleEntry.mode !== "100644" ||
+ moduleEntry.oid !== binding.moduleBlob
+ ) {
+ throw new Error("test module declaration source differs from the attested blob");
+ }
const moduleSource = runGit(["show", `${proof.candidateCommit}:${binding.modulePath}`]);
const declaration = `#[cfg(test)]\n#[path = "${file.path.split("/").at(-1)}"]\nmod tests;`;
- if (!moduleSource.includes(declaration)) throw new Error("the exact cfg(test) sibling module binding is absent");
+ if (!moduleSource.includes(declaration)) {
+ throw new Error("the exact cfg(test) sibling module binding is absent");
+ }
return { ok: true };
} catch (error) {
return { ok: false, message: error.message };