Skip to content

Commit d2ff92e

Browse files
committed
fix(release): bound candidate metadata enumeration
1 parent a59cfeb commit d2ff92e

2 files changed

Lines changed: 78 additions & 14 deletions

File tree

‎scripts/release-plan-producer-core.mts‎

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,26 +219,38 @@ function withCandidateSnapshot<T>(
219219
): T {
220220
const snapshotRoot = mkdtempSync(join(tmpdir(), "openclaw-release-candidate-"));
221221
try {
222-
const tree = execFileSync(
223-
"git",
224-
["ls-tree", "-r", "-z", candidateSha, "--", "package.json", "extensions", "packages"],
225-
{ cwd: repoRoot },
226-
).toString("utf8");
222+
// Enumerate package directories, then metadata only. Recursive runtime listings
223+
// grow with unrelated source files and can overflow the child-process buffer.
224+
const metadataPaths = ["package.json"];
225+
for (const directory of git(repoRoot, [
226+
"ls-tree",
227+
"-d",
228+
"-z",
229+
"--name-only",
230+
candidateSha,
231+
"--",
232+
"extensions/",
233+
"packages/",
234+
])
235+
.split("\0")
236+
.filter(Boolean)) {
237+
metadataPaths.push(`${directory}/package.json`);
238+
if (directory.startsWith("extensions/")) {
239+
metadataPaths.push(`${directory}/README.md`);
240+
}
241+
}
242+
const tree = execFileSync("git", ["ls-tree", "-z", candidateSha, "--", ...metadataPaths], {
243+
cwd: repoRoot,
244+
}).toString("utf8");
227245
const inventoryPaths: string[] = [];
228246
for (const entry of tree.split("\0").filter(Boolean)) {
229247
const [metadata, path] = entry.split("\t");
230-
if (
231-
!path ||
232-
(path !== "package.json" &&
233-
!/^extensions\/[^/]+\/(?:package\.json|README\.md)$/u.test(path) &&
234-
!/^packages\/[^/]+\/package\.json$/u.test(path))
235-
) {
236-
continue;
237-
}
238248
if (metadata?.startsWith("120000 ")) {
239249
throw new Error("candidate package inventory must not contain symbolic links");
240250
}
241-
inventoryPaths.push(path);
251+
if (metadata?.startsWith("100") && path) {
252+
inventoryPaths.push(path);
253+
}
242254
}
243255
if (!inventoryPaths.includes("package.json")) {
244256
throw new Error("candidate package.json is missing");

‎test/scripts/release-plan-producer.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,58 @@ describe("release plan producer", () => {
587587
]);
588588
});
589589

590+
it("ignores large runtime trees when collecting candidate metadata", () => {
591+
const fixture = createFixtureRepo();
592+
const params = sourceParams(fixture);
593+
const expected = produceReleasePlan(params).inventory;
594+
const git = (args: string[], input?: string) =>
595+
execFileSync(
596+
"git",
597+
["-c", "user.name=OpenClaw Test", "-c", "[email protected]", ...args],
598+
{ cwd: fixture.root, encoding: "utf8", input },
599+
).trim();
600+
const blob = git(["hash-object", "-w", "--stdin"], "");
601+
// Git objects reproduce the >1 MiB listing without creating thousands of files.
602+
const runtimeTree = git(
603+
["mktree"],
604+
Array.from(
605+
{ length: 6000 },
606+
(_, index) => `100644 blob ${blob}\truntime-${index}-${"x".repeat(180)}.ts\n`,
607+
).join(""),
608+
);
609+
const pluginsTree = git(["mktree"], `040000 tree ${runtimeTree}\tnoise\n`);
610+
const rootTree = git(
611+
["mktree"],
612+
`${git(["ls-tree", fixture.candidateSha])}\n040000 tree ${pluginsTree}\textensions\n`,
613+
);
614+
const candidateSha = git([
615+
"commit-tree",
616+
rootTree,
617+
"-p",
618+
fixture.candidateSha,
619+
"-m",
620+
"runtime",
621+
]);
622+
expect(produceReleasePlan({ ...params, candidateSha }).inventory).toEqual(expected);
623+
});
624+
625+
it.each([
626+
"package.json",
627+
"packages/ai/package.json",
628+
"extensions/linked/package.json",
629+
"extensions/linked/README.md",
630+
])("rejects candidate metadata symlinks at %s", (path) => {
631+
const fixture = createFixtureRepo();
632+
const target = join(fixture.root, path);
633+
mkdirSync(dirname(target), { recursive: true });
634+
rmSync(target, { force: true });
635+
symlinkSync("must-not-be-read", target);
636+
const candidateSha = commit(fixture.root, "linked metadata");
637+
expect(() => produceReleasePlan({ ...sourceParams(fixture), candidateSha })).toThrow(
638+
"candidate package inventory must not contain symbolic links",
639+
);
640+
});
641+
590642
it("requires the final tag only for postpublish confidence", () => {
591643
const fixture = createFixtureRepo();
592644
expect(produceReleasePlan(sourceParams(fixture))).toMatchObject({

0 commit comments

Comments
 (0)