mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-17 12:31:38 +00:00
* fix(diffs): share SSR preloads and repair language-pack hydration Render viewer and file documents from a single @pierre/diffs SSR preload per file (mode=both previously ran the full diff+highlight pipeline twice; 651ms -> 303ms on an 8-file patch), apply the file-mode font bump as a document-level override, and keep hydration payloads variant-faithful. Fix the language-pack runtime downgrading pack-only languages to plain text at hydration by defining a per-target build flag and forwarding it to payload normalization. Also: case-insensitive language hints, identical before/after short-circuit with details.changed, patch input failures classified as tool input errors, canonical config values now win over deprecated aliases, hash-pinned viewer runtime served immutable, truthful browser-vs-render errors, timing-safe artifact token compare, unref idle browser timer. * docs(changelog): link diffs rendering entry to PR * test(diffs): narrow manifest validation results before value access * test(tooling): allowlist diffs viewer-client define suppression
71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
// Diffs tests cover shared SSR preload behavior.
|
|
import { disposeHighlighter } from "@pierre/diffs";
|
|
import * as diffsSsr from "@pierre/diffs/ssr";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { DEFAULT_DIFFS_TOOL_DEFAULTS, resolveDiffImageRenderOptions } from "./config.js";
|
|
import { renderDiffDocument } from "./render.js";
|
|
|
|
vi.mock("@pierre/diffs/ssr", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("@pierre/diffs/ssr")>();
|
|
return {
|
|
...actual,
|
|
preloadFileDiff: vi.fn(actual.preloadFileDiff),
|
|
preloadMultiFileDiff: vi.fn(actual.preloadMultiFileDiff),
|
|
};
|
|
});
|
|
|
|
describe("renderDiffDocument SSR preloads", () => {
|
|
afterEach(async () => {
|
|
vi.clearAllMocks();
|
|
await disposeHighlighter();
|
|
});
|
|
|
|
it("preloads a before/after diff once for viewer and image output", async () => {
|
|
await renderDiffDocument(
|
|
{
|
|
kind: "before_after",
|
|
before: "const value = 1;\n",
|
|
after: "const value = 2;\n",
|
|
path: "src/example.ts",
|
|
},
|
|
{
|
|
presentation: DEFAULT_DIFFS_TOOL_DEFAULTS,
|
|
image: resolveDiffImageRenderOptions({ defaults: DEFAULT_DIFFS_TOOL_DEFAULTS }),
|
|
expandUnchanged: false,
|
|
},
|
|
"both",
|
|
);
|
|
|
|
expect(diffsSsr.preloadMultiFileDiff).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("preloads each patch file once for viewer and image output", async () => {
|
|
const patch = [
|
|
"diff --git a/a.ts b/a.ts",
|
|
"--- a/a.ts",
|
|
"+++ b/a.ts",
|
|
"@@ -1 +1 @@",
|
|
"-const a = 1;",
|
|
"+const a = 2;",
|
|
"diff --git a/b.ts b/b.ts",
|
|
"--- a/b.ts",
|
|
"+++ b/b.ts",
|
|
"@@ -1 +1 @@",
|
|
"-const b = 1;",
|
|
"+const b = 2;",
|
|
].join("\n");
|
|
|
|
await renderDiffDocument(
|
|
{ kind: "patch", patch },
|
|
{
|
|
presentation: DEFAULT_DIFFS_TOOL_DEFAULTS,
|
|
image: resolveDiffImageRenderOptions({ defaults: DEFAULT_DIFFS_TOOL_DEFAULTS }),
|
|
expandUnchanged: false,
|
|
},
|
|
"both",
|
|
);
|
|
|
|
expect(diffsSsr.preloadFileDiff).toHaveBeenCalledTimes(2);
|
|
});
|
|
});
|