


























@@ -1,4 +1,6 @@
11import fs from "node:fs";
2+import { join } from "node:path";
3+import { fileURLToPath, pathToFileURL } from "node:url";
24import AjvPkg from "ajv";
35import type { JsonSchemaObject } from "openclaw/plugin-sdk/config-schema";
46import { describe, expect, it, vi } from "vitest";
@@ -399,44 +401,59 @@ describe("diffs viewer URL helpers", () => {
399401400402describe("viewer assets", () => {
401403it("prefers the built plugin asset layout when present", async () => {
404+const repoRoot = join(process.cwd(), "tmp", "diffs-viewer-assets-test-repo");
405+const builtRuntimePath = join(
406+repoRoot,
407+"dist",
408+"extensions",
409+"diffs",
410+"assets",
411+"viewer-runtime.js",
412+);
402413const stat = vi.fn(async (path: string) => {
403-if (path === "/repo/dist/extensions/diffs/assets/viewer-runtime.js") {
414+if (path === builtRuntimePath) {
404415return { mtimeMs: 1 };
405416}
406417const error = Object.assign(new Error(`missing: ${path}`), { code: "ENOENT" });
407418throw error;
408419});
409420410-await expect(
411-resolveViewerRuntimeFileUrl({
412-baseUrl: "file:///repo/dist/extensions/diffs/index.js",
413- stat,
414-}),
415-).resolves.toMatchObject({
416-pathname: "/repo/dist/extensions/diffs/assets/viewer-runtime.js",
421+const runtimeUrl = await resolveViewerRuntimeFileUrl({
422+baseUrl: pathToFileURL(join(repoRoot, "dist", "extensions", "diffs", "index.js")),
423+ stat,
417424});
425+426+expect(fileURLToPath(runtimeUrl)).toBe(builtRuntimePath);
418427expect(stat).toHaveBeenCalledTimes(1);
419428});
420429421430it("falls back to the source asset layout when the built artifact is absent", async () => {
431+const repoRoot = join(process.cwd(), "tmp", "diffs-viewer-assets-test-repo");
432+const sourceCandidatePath = join(
433+repoRoot,
434+"extensions",
435+"diffs",
436+"src",
437+"assets",
438+"viewer-runtime.js",
439+);
440+const sourceRuntimePath = join(repoRoot, "extensions", "diffs", "assets", "viewer-runtime.js");
422441const stat = vi.fn(async (path: string) => {
423-if (path === "/repo/extensions/diffs/assets/viewer-runtime.js") {
442+if (path === sourceRuntimePath) {
424443return { mtimeMs: 1 };
425444}
426445const error = Object.assign(new Error(`missing: ${path}`), { code: "ENOENT" });
427446throw error;
428447});
429448430-await expect(
431-resolveViewerRuntimeFileUrl({
432-baseUrl: "file:///repo/extensions/diffs/src/viewer-assets.js",
433- stat,
434-}),
435-).resolves.toMatchObject({
436-pathname: "/repo/extensions/diffs/assets/viewer-runtime.js",
449+const runtimeUrl = await resolveViewerRuntimeFileUrl({
450+baseUrl: pathToFileURL(join(repoRoot, "extensions", "diffs", "src", "viewer-assets.js")),
451+ stat,
437452});
438-expect(stat).toHaveBeenNthCalledWith(1, "/repo/extensions/diffs/src/assets/viewer-runtime.js");
439-expect(stat).toHaveBeenNthCalledWith(2, "/repo/extensions/diffs/assets/viewer-runtime.js");
453+454+expect(fileURLToPath(runtimeUrl)).toBe(sourceRuntimePath);
455+expect(stat).toHaveBeenNthCalledWith(1, sourceCandidatePath);
456+expect(stat).toHaveBeenNthCalledWith(2, sourceRuntimePath);
440457});
441458442459it("serves a stable loader that points at the current runtime bundle", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。