|
1 | 1 | // Diffs tests cover config plugin behavior. |
2 | 2 | import fs from "node:fs"; |
3 | | -import os from "node:os"; |
4 | | -import { join } from "node:path"; |
5 | | -import { fileURLToPath, pathToFileURL } from "node:url"; |
6 | 3 | import { |
7 | 4 | validateJsonSchemaValue, |
8 | 5 | type JsonSchemaObject, |
9 | 6 | } from "openclaw/plugin-sdk/json-schema-runtime"; |
10 | | -import { beforeAll, describe, expect, it, vi } from "vitest"; |
| 7 | +import { beforeAll, describe, expect, it } from "vitest"; |
11 | 8 | import { |
12 | | - DEFAULT_DIFFS_PLUGIN_SECURITY, |
13 | | - DEFAULT_DIFFS_TOOL_DEFAULTS, |
14 | 9 | diffsPluginConfigSchema, |
15 | 10 | resolveDiffImageRenderOptions, |
16 | 11 | resolveDiffsPluginDefaults, |
17 | 12 | resolveDiffsPluginSecurity, |
18 | 13 | resolveDiffsPluginViewerBaseUrl, |
19 | 14 | } from "./config.js"; |
20 | | -import { resolveDiffsLanguagePackAvailability } from "./plugin.js"; |
21 | 15 | import { ensureCuratedViewerRuntimeForTests } from "./test-helpers.js"; |
22 | 16 | import { buildViewerUrl, normalizeViewerBaseUrl } from "./url.js"; |
23 | 17 | import { |
24 | 18 | getServedLanguagePackViewerAsset, |
25 | 19 | getServedViewerAsset, |
26 | | - resolveViewerRuntimeFileUrl, |
27 | | - LANGUAGE_PACK_VIEWER_LOADER_PATH, |
28 | | - VIEWER_LOADER_PATH, |
| 20 | + LANGUAGE_PACK_VIEWER_ASSET_PREFIX, |
| 21 | + VIEWER_ASSET_PREFIX, |
29 | 22 | VIEWER_RUNTIME_PATH, |
30 | 23 | } from "./viewer-assets.js"; |
31 | 24 | import { parseViewerPayloadJson } from "./viewer-payload.js"; |
32 | 25 |
|
| 26 | +const DEFAULT_DIFFS_TOOL_DEFAULTS = resolveDiffsPluginDefaults(undefined); |
| 27 | +const DEFAULT_DIFFS_PLUGIN_SECURITY = resolveDiffsPluginSecurity(undefined); |
| 28 | +const VIEWER_LOADER_PATH = `${VIEWER_ASSET_PREFIX}viewer.js`; |
| 29 | +const LANGUAGE_PACK_VIEWER_LOADER_PATH = `${LANGUAGE_PACK_VIEWER_ASSET_PREFIX}viewer.js`; |
| 30 | + |
33 | 31 | const FULL_DEFAULTS = { |
34 | 32 | fontFamily: "JetBrains Mono", |
35 | 33 | fontSize: 17, |
@@ -477,62 +475,6 @@ describe("diffs viewer URL helpers", () => { |
477 | 475 | }); |
478 | 476 |
|
479 | 477 | describe("viewer assets", () => { |
480 | | - it("prefers the built plugin asset layout when present", async () => { |
481 | | - const repoRoot = join(process.cwd(), "tmp", "diffs-viewer-assets-test-repo"); |
482 | | - const builtRuntimePath = join( |
483 | | - repoRoot, |
484 | | - "dist", |
485 | | - "extensions", |
486 | | - "diffs", |
487 | | - "assets", |
488 | | - "viewer-runtime.js", |
489 | | - ); |
490 | | - const stat = vi.fn(async (path: string) => { |
491 | | - if (path === builtRuntimePath) { |
492 | | - return { mtimeMs: 1 }; |
493 | | - } |
494 | | - const error = Object.assign(new Error(`missing: ${path}`), { code: "ENOENT" }); |
495 | | - throw error; |
496 | | - }); |
497 | | - |
498 | | - const runtimeUrl = await resolveViewerRuntimeFileUrl({ |
499 | | - baseUrl: pathToFileURL(join(repoRoot, "dist", "extensions", "diffs", "index.js")), |
500 | | - stat, |
501 | | - }); |
502 | | - |
503 | | - expect(fileURLToPath(runtimeUrl)).toBe(builtRuntimePath); |
504 | | - expect(stat).toHaveBeenCalledTimes(1); |
505 | | - }); |
506 | | - |
507 | | - it("falls back to the source asset layout when the built artifact is absent", async () => { |
508 | | - const repoRoot = join(process.cwd(), "tmp", "diffs-viewer-assets-test-repo"); |
509 | | - const sourceCandidatePath = join( |
510 | | - repoRoot, |
511 | | - "extensions", |
512 | | - "diffs", |
513 | | - "src", |
514 | | - "assets", |
515 | | - "viewer-runtime.js", |
516 | | - ); |
517 | | - const sourceRuntimePath = join(repoRoot, "extensions", "diffs", "assets", "viewer-runtime.js"); |
518 | | - const stat = vi.fn(async (path: string) => { |
519 | | - if (path === sourceRuntimePath) { |
520 | | - return { mtimeMs: 1 }; |
521 | | - } |
522 | | - const error = Object.assign(new Error(`missing: ${path}`), { code: "ENOENT" }); |
523 | | - throw error; |
524 | | - }); |
525 | | - |
526 | | - const runtimeUrl = await resolveViewerRuntimeFileUrl({ |
527 | | - baseUrl: pathToFileURL(join(repoRoot, "extensions", "diffs", "src", "viewer-assets.js")), |
528 | | - stat, |
529 | | - }); |
530 | | - |
531 | | - expect(fileURLToPath(runtimeUrl)).toBe(sourceRuntimePath); |
532 | | - expect(stat).toHaveBeenNthCalledWith(1, sourceCandidatePath); |
533 | | - expect(stat).toHaveBeenNthCalledWith(2, sourceRuntimePath); |
534 | | - }); |
535 | | - |
536 | 478 | it("serves a stable loader that points at the current runtime bundle", async () => { |
537 | 479 | const loader = await getServedViewerAsset(VIEWER_LOADER_PATH); |
538 | 480 |
|
@@ -565,39 +507,6 @@ describe("viewer assets", () => { |
565 | 507 | }); |
566 | 508 | }); |
567 | 509 |
|
568 | | -describe("resolveDiffsLanguagePackAvailability", () => { |
569 | | - it.each(["assets", "dist/assets"])( |
570 | | - "requires both the sibling language-pack manifest and generated runtime asset in %s", |
571 | | - (assetDir) => { |
572 | | - const root = fs.mkdtempSync(join(os.tmpdir(), "openclaw-diffs-language-pack-")); |
573 | | - try { |
574 | | - const diffsRoot = join(root, "diffs"); |
575 | | - const languagePackRoot = join(root, "diffs-language-pack"); |
576 | | - fs.mkdirSync(diffsRoot, { recursive: true }); |
577 | | - fs.mkdirSync(languagePackRoot, { recursive: true }); |
578 | | - fs.writeFileSync( |
579 | | - join(languagePackRoot, "openclaw.plugin.json"), |
580 | | - '{"id":"diffs-language-pack"}\n', |
581 | | - ); |
582 | | - const api = { |
583 | | - rootDir: diffsRoot, |
584 | | - config: { plugins: {} }, |
585 | | - runtime: { config: { current: () => ({ plugins: {} }) } }, |
586 | | - } as Parameters<typeof resolveDiffsLanguagePackAvailability>[0]; |
587 | | - |
588 | | - expect(resolveDiffsLanguagePackAvailability(api)).toBe(false); |
589 | | - |
590 | | - fs.mkdirSync(join(languagePackRoot, assetDir), { recursive: true }); |
591 | | - fs.writeFileSync(join(languagePackRoot, assetDir, "viewer-runtime.js"), "export {};\n"); |
592 | | - |
593 | | - expect(resolveDiffsLanguagePackAvailability(api)).toBe(true); |
594 | | - } finally { |
595 | | - fs.rmSync(root, { force: true, recursive: true }); |
596 | | - } |
597 | | - }, |
598 | | - ); |
599 | | -}); |
600 | | - |
601 | 510 | describe("parseViewerPayloadJson", () => { |
602 | 511 | function buildValidPayload(): Record<string, unknown> { |
603 | 512 | return { |
|
0 commit comments