

























@@ -19,13 +19,13 @@ afterEach(() => {
1919});
20202121describe("refreshBundledPluginRuntimeMirrorRoot", () => {
22-it("refreshes stale mirrors without deleting the active target root", () => {
22+it("refreshes stale mirrors without leaving removed source files behind", () => {
2323const root = makeTempRoot();
2424const sourceRoot = path.join(root, "source");
2525const targetRoot = path.join(root, "target");
2626fs.mkdirSync(sourceRoot, { recursive: true });
2727fs.mkdirSync(targetRoot, { recursive: true });
28-fs.writeFileSync(path.join(sourceRoot, "index.js"), "export const value = 'v1';\n", "utf8");
28+fs.writeFileSync(path.join(sourceRoot, "old.js"), "export const value = 'v1';\n", "utf8");
29293030expect(
3131refreshBundledPluginRuntimeMirrorRoot({
@@ -35,8 +35,8 @@ describe("refreshBundledPluginRuntimeMirrorRoot", () => {
3535}),
3636).toBe(true);
373738-fs.writeFileSync(path.join(sourceRoot, "index.js"), "export const value = 'v2';\n", "utf8");
39-fs.writeFileSync(path.join(targetRoot, "inflight-import.js"), "still readable\n", "utf8");
38+fs.rmSync(path.join(sourceRoot, "old.js"));
39+fs.writeFileSync(path.join(sourceRoot, "new.js"), "export const value = 'v2';\n", "utf8");
40404141expect(
4242refreshBundledPluginRuntimeMirrorRoot({
@@ -46,9 +46,47 @@ describe("refreshBundledPluginRuntimeMirrorRoot", () => {
4646}),
4747).toBe(true);
484849-expect(fs.readFileSync(path.join(targetRoot, "index.js"), "utf8")).toContain("v2");
50-expect(fs.readFileSync(path.join(targetRoot, "inflight-import.js"), "utf8")).toBe(
51-"still readable\n",
52-);
49+expect(fs.readdirSync(targetRoot).toSorted()).toEqual([
50+".openclaw-runtime-mirror.json",
51+"new.js",
52+]);
53+expect(fs.readFileSync(path.join(targetRoot, "new.js"), "utf8")).toContain("v2");
54+expect(
55+refreshBundledPluginRuntimeMirrorRoot({
56+pluginId: "demo",
57+ sourceRoot,
58+ targetRoot,
59+}),
60+).toBe(false);
61+});
62+63+it("replaces stale target entries when the source changes type", () => {
64+const root = makeTempRoot();
65+const sourceRoot = path.join(root, "source");
66+const targetRoot = path.join(root, "target");
67+fs.mkdirSync(path.join(sourceRoot, "entry"), { recursive: true });
68+fs.writeFileSync(path.join(sourceRoot, "entry", "index.js"), "export const value = 1;\n");
69+70+expect(
71+refreshBundledPluginRuntimeMirrorRoot({
72+pluginId: "demo",
73+ sourceRoot,
74+ targetRoot,
75+}),
76+).toBe(true);
77+78+fs.rmSync(path.join(sourceRoot, "entry"), { recursive: true, force: true });
79+fs.writeFileSync(path.join(sourceRoot, "entry"), "export const value = 2;\n");
80+81+expect(
82+refreshBundledPluginRuntimeMirrorRoot({
83+pluginId: "demo",
84+ sourceRoot,
85+ targetRoot,
86+}),
87+).toBe(true);
88+89+expect(fs.lstatSync(path.join(targetRoot, "entry")).isFile()).toBe(true);
90+expect(fs.readFileSync(path.join(targetRoot, "entry"), "utf8")).toContain("2");
5391});
5492});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。