fix(plugins): preserve tokenjuice runtime rule data

Preserve tokenjuice runtime rule JSON under dist/rules/tests during bundled plugin runtime dependency staging while continuing to prune unrelated tests directories.
This commit is contained in:
Chris Zhang
2026-04-25 08:16:06 +08:00
committed by GitHub
parent 30aa1f890a
commit de8a00d922
3 changed files with 85 additions and 3 deletions

View File

@@ -951,6 +951,66 @@ describe("stageBundledPluginRuntimeDeps", () => {
);
});
it("honors keepDirectories to opt a subtree out of global basename prune", () => {
// Regression: tokenjuice ships runtime-loaded rule data under
// `dist/rules/tests/*.json`. Without keepDirectories the global `tests`
// basename prune would strip that subtree and the plugin would fail to
// load with `Cannot find module '../rules/tests/bun-test.json'`.
const { pluginDir, repoRoot } = createBundledPluginFixture({
packageJson: {
name: "@openclaw/fixture-plugin",
version: "1.0.0",
dependencies: { "keep-target": "1.0.0" },
openclaw: { bundle: { stageRuntimeDependencies: true } },
},
});
const depDir = path.join(repoRoot, "node_modules", "keep-target");
fs.mkdirSync(path.join(depDir, "dist", "rules", "tests"), { recursive: true });
fs.mkdirSync(path.join(depDir, "src", "tests"), { recursive: true });
fs.writeFileSync(
path.join(depDir, "package.json"),
'{ "name": "keep-target", "version": "1.0.0" }\n',
"utf8",
);
fs.writeFileSync(
path.join(depDir, "dist", "rules", "tests", "bun-test.json"),
'{"rule":"bun"}\n',
"utf8",
);
fs.writeFileSync(
path.join(depDir, "src", "tests", "legit-test.spec.ts"),
"describe('x', () => {});\n",
"utf8",
);
stageBundledPluginRuntimeDeps({
cwd: repoRoot,
stagedRuntimeDepPruneRules: new Map([
["keep-target", { keepDirectories: ["dist/rules/tests"] }],
]),
});
// Opt-in path: preserved intact.
expect(
fs.existsSync(
path.join(
pluginDir,
"node_modules",
"keep-target",
"dist",
"rules",
"tests",
"bun-test.json",
),
),
).toBe(true);
// Unlisted `tests/` directories still get pruned.
expect(fs.existsSync(path.join(pluginDir, "node_modules", "keep-target", "src", "tests"))).toBe(
false,
);
});
it("applies default prune rules for known heavy non-runtime package cargo", () => {
const { pluginDir, repoRoot } = createBundledPluginFixture({
packageJson: {