Skip to content

Commit 7ccfc94

Browse files
Merge remote-tracking branch 'origin/main' into pr-119594-prep
2 parents 0f93804 + c3d17e8 commit 7ccfc94

2 files changed

Lines changed: 68 additions & 17 deletions

File tree

‎scripts/lib/cli-startup-root-help-bundle.ts‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,32 @@ import { createHash } from "node:crypto";
33
import { readdirSync, readFileSync } from "node:fs";
44
import path from "node:path";
55

6+
const OUTPUT_ROOT_HELP_EXPORT_RE =
7+
/\bexport\s+(?:(?:async\s+)?function|class|const|let|var)\s+outputRootHelp\b|\bexport\s*\{[^}]*\boutputRootHelp\s*(?=[,}])/u;
8+
69
export function resolveCliStartupRootHelpBundleIdentity(
710
distDir: string,
811
): { bundleName: string; signature: string } | null {
9-
const bundleName = readdirSync(distDir).find(
10-
(entry) =>
11-
entry.startsWith("root-help-") &&
12-
!entry.startsWith("root-help-metadata-") &&
13-
entry.endsWith(".js"),
14-
);
15-
if (!bundleName) {
16-
return null;
12+
for (const bundleName of readdirSync(distDir).toSorted()) {
13+
if (!bundleName.startsWith("root-help-") || !bundleName.endsWith(".js")) {
14+
continue;
15+
}
16+
const bundleContents = readFileSync(path.join(distDir, bundleName), "utf8");
17+
// The build emits multiple root-help chunks; only the renderer owns this cache identity.
18+
// Selecting a helper chunk forces metadata generation onto its expensive source fallback.
19+
if (!OUTPUT_ROOT_HELP_EXPORT_RE.test(bundleContents)) {
20+
continue;
21+
}
22+
const buildInfo = readBuildIdentity(distDir);
23+
return {
24+
bundleName,
25+
signature: createHash("sha1")
26+
.update(bundleContents)
27+
.update(JSON.stringify(buildInfo))
28+
.digest("hex"),
29+
};
1730
}
18-
const bundleContents = readFileSync(path.join(distDir, bundleName), "utf8");
19-
const buildInfo = readBuildIdentity(distDir);
20-
return {
21-
bundleName,
22-
signature: createHash("sha1")
23-
.update(bundleContents)
24-
.update(JSON.stringify(buildInfo))
25-
.digest("hex"),
26-
};
31+
return null;
2732
}
2833

2934
function readBuildIdentity(distDir: string): { version: string | null; commit: string | null } {

‎test/scripts/write-cli-startup-metadata.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,52 @@ describe("write-cli-startup-metadata", () => {
480480
expect(written.subcommandHelpText.tasks).toContain("openclaw tasks");
481481
});
482482

483+
it("selects the root-help bundle that exports the renderer", async () => {
484+
const tempRoot = createTempDir("openclaw-startup-metadata-bundle-selection-");
485+
const distDir = path.join(tempRoot, "dist");
486+
const extensionsDir = path.join(tempRoot, "extensions");
487+
const outputPath = path.join(distDir, "cli-startup-metadata.json");
488+
const renderSourceRootHelpText = vi.fn(() => "Usage: source fallback\n");
489+
490+
writeStartupMetadataSourceSignatureFixture(tempRoot);
491+
writeFixtureFile(tempRoot, "package.json", '{"type":"module"}\n');
492+
writeFixtureFile(
493+
distDir,
494+
"root-help-live-config-fixture.js",
495+
"async function loadRootHelpRenderOptionsForConfigSensitivePlugins() { return null; }\nexport { loadRootHelpRenderOptionsForConfigSensitivePlugins };\n",
496+
);
497+
writeFixtureFile(
498+
distDir,
499+
"root-help-renderer-fixture.js",
500+
"async function outputRootHelp() { process.stdout.write('Usage: bundled renderer\\n'); }\nexport { outputRootHelp };\n",
501+
);
502+
503+
await writeCliStartupMetadata({
504+
distDir,
505+
outputPath,
506+
extensionsDir,
507+
sourceRootDir: tempRoot,
508+
renderSourceRootHelpText,
509+
renderSourceBrowserHelpText: () => "Usage: openclaw browser\n",
510+
renderSourceSecretsHelpText: () => "Usage: openclaw secrets\n",
511+
renderSourceNodesHelpText: () => "Usage: openclaw nodes\n",
512+
renderSourceSubcommandHelpTextRecord: () => ({
513+
doctor: "Usage: openclaw doctor\n",
514+
gateway: "Usage: openclaw gateway\n",
515+
models: "Usage: openclaw models\n",
516+
plugins: "Usage: openclaw plugins\n",
517+
sessions: "Usage: openclaw sessions\n",
518+
tasks: "Usage: openclaw tasks\n",
519+
}),
520+
});
521+
522+
const written = JSON.parse(readFileSync(outputPath, "utf8")) as {
523+
rootHelpText: string;
524+
};
525+
expect(written.rootHelpText).toBe("Usage: bundled renderer\n");
526+
expect(renderSourceRootHelpText).not.toHaveBeenCalled();
527+
});
528+
483529
it("renders independent startup help snapshots concurrently", async () => {
484530
const tempRoot = createTempDir("openclaw-startup-metadata-concurrency-");
485531
const distDir = path.join(tempRoot, "dist");

0 commit comments

Comments
 (0)