Release Diff Tools 0.2.0
Verify / verify (push) Canceled after 0s

This commit is contained in:
2026-09-02 04:43:16 +02:00
parent a1380cfba2
commit 46fc10f745
37 changed files with 2722 additions and 455 deletions
+51 -6
View File
@@ -25,7 +25,9 @@ function auditPage(page: Page) {
async function openApp(page: Page) {
await page.goto(APP_PATH);
await expect(
page.getByRole("heading", { name: "Diff Tools", exact: true }),
page
.locator(".hero")
.getByRole("heading", { name: "Diff Tools", exact: true }),
).toBeVisible();
await expect(page.getByText(/substantive change row/u)).toBeVisible();
}
@@ -60,19 +62,19 @@ test("exports exact-decimal JSON Patch without losing the prior result", async (
}) => {
const audit = auditPage(page);
await openApp(page);
await page.getByRole("tab", { name: /JSON Semantic/u }).click();
await page.getByRole("button", { name: /JSON Semantic/u }).click();
await page.getByTestId("left-editor").fill('{"amount":1,"keep":true}');
await page
.getByTestId("right-editor")
.fill('{"amount":9007199254740993123456789,"keep":true}');
await page.getByRole("button", { name: "Compare now" }).click();
await expect(page.getByText(/1 substantive change row/u)).toBeVisible();
await page.getByRole("tab", { name: "Patches" }).click();
await page.getByRole("button", { name: "Patches" }).click();
await expect(page.getByTestId("json-patch")).toContainText(
"9007199254740993123456789",
);
await page.getByRole("tab", { name: /XML Namespace-aware/u }).click();
await page.getByRole("button", { name: /XML Namespace-aware/u }).click();
await expect(page.getByText(/substantive change row/u)).toBeVisible();
const previousVerdict = page.getByText("Different", { exact: true }).first();
await expect(previousVerdict).toBeVisible();
@@ -87,7 +89,7 @@ test("exports exact-decimal JSON Patch without losing the prior result", async (
test("opens local keyed CSV and reports duplicate keys", async ({ page }) => {
const audit = auditPage(page);
await openApp(page);
await page.getByRole("tab", { name: /CSV \/ TSV Keyed rows/u }).click();
await page.getByRole("button", { name: /CSV \/ TSV Keyed rows/u }).click();
await page.getByTestId("left-file-input").setInputFiles({
name: "duplicates.csv",
mimeType: "text/csv",
@@ -118,8 +120,51 @@ test("serves the release identity and hardened headers", async ({
const manifest = await request.get(`${APP_PATH}toolbox-app.json`);
await expect(manifest.json()).resolves.toMatchObject({
id: "de.add-ideas.diff-tools",
version: "0.1.0",
version: "0.2.0",
entry: "./",
privacy: { processing: "local", fileUploads: true, telemetry: false },
});
});
test("runs the bounded three-way merge workspace", async ({ page }) => {
await page.goto("/deep/nested/diff/");
await page.getByRole("button", { name: "Three-way merge" }).click();
await page.getByLabel("Base").fill("one\ntwo\nthree\n");
await page.getByLabel("Ours").fill("ONE\ntwo\nthree\n");
await page.getByLabel("Theirs").fill("one\ntwo\nTHREE\n");
await page.getByRole("button", { name: "Merge locally" }).click();
await expect(page.getByTestId("merge-output")).toHaveValue(
"ONE\ntwo\nTHREE\n",
);
await expect(
page.getByRole("heading", { name: "0 conflict(s)" }),
).toBeVisible();
});
test("imports and compares portable directory manifests", async ({ page }) => {
await page.goto("/deep/nested/diff/");
await page.getByRole("button", { name: "Directories" }).click();
const manifest = (digest: string) => ({
schema: "de.add-ideas.diff-tools.directory-manifest.v1",
schemaVersion: 1,
generatedLocally: true,
hashAlgorithm: "SHA-256",
entries: [{ path: "file.txt", bytes: 4, sha256: digest }],
totals: { files: 1, bytes: 4 },
});
const inputs = page.locator('input[accept*="application/json"]');
await inputs.nth(0).setInputFiles({
name: "left.json",
mimeType: "application/json",
buffer: Buffer.from(JSON.stringify(manifest("a".repeat(64)))),
});
await inputs.nth(1).setInputFiles({
name: "right.json",
mimeType: "application/json",
buffer: Buffer.from(JSON.stringify(manifest("b".repeat(64)))),
});
await page.getByRole("button", { name: "Build & compare manifests" }).click();
await expect(
page.getByRole("row", { name: /file\.txt modified/iu }),
).toBeVisible();
});
+18
View File
@@ -0,0 +1,18 @@
import { expect, test } from "@playwright/test";
test("keeps the primary workspace inside a narrow viewport", async ({
page,
}) => {
await page.goto("/deep/nested/diff/");
await expect(page.locator("main").first()).toBeVisible();
await expect(
page.locator("main .loading, main .workbench-loading"),
).toHaveCount(0);
const widths = await page.evaluate(() => ({
content: document.documentElement.scrollWidth,
viewport: document.documentElement.clientWidth,
}));
expect(widths.viewport).toBeLessThanOrEqual(430);
expect(widths.content).toBeLessThanOrEqual(widths.viewport + 1);
});
+6 -4
View File
@@ -10,7 +10,7 @@ describe("Diff Tools workbench", () => {
expect(screen.getByText("Browser-local")).toBeVisible();
expect(await screen.findByText(/substantive change row/u)).toBeVisible();
expect(screen.getAllByText("CRLF").length).toBeGreaterThan(0);
await user.click(screen.getByRole("tab", { name: "Side by side" }));
await user.click(screen.getByRole("button", { name: "Side by side" }));
expect(
screen.getByRole("table", { name: "Side-by-side differences" }),
).toBeVisible();
@@ -19,7 +19,7 @@ describe("Diff Tools workbench", () => {
it("keeps exact large numbers in the RFC 6902 artifact", async () => {
const user = userEvent.setup();
render(<Workbench />);
await user.click(screen.getByRole("tab", { name: /JSON Semantic/u }));
await user.click(screen.getByRole("button", { name: /JSON Semantic/u }));
fireEvent.change(screen.getByTestId("left-editor"), {
target: { value: '{"n":1}' },
});
@@ -30,7 +30,7 @@ describe("Diff Tools workbench", () => {
await waitFor(() =>
expect(screen.getByText(/1 substantive change row/u)).toBeVisible(),
);
await user.click(screen.getByRole("tab", { name: "Patches" }));
await user.click(screen.getByRole("button", { name: "Patches" }));
expect(
(screen.getByTestId("json-patch") as HTMLTextAreaElement).value,
).toContain("9007199254740993123456789");
@@ -39,7 +39,9 @@ describe("Diff Tools workbench", () => {
it("keeps the last successful XML result visible beside an error", async () => {
const user = userEvent.setup();
render(<Workbench />);
await user.click(screen.getByRole("tab", { name: /XML Namespace-aware/u }));
await user.click(
screen.getByRole("button", { name: /XML Namespace-aware/u }),
);
expect(await screen.findByText(/substantive change row/u)).toBeVisible();
const verdict = screen.getByText("Different", { exact: true });
fireEvent.change(screen.getByTestId("left-editor"), {
+140
View File
@@ -0,0 +1,140 @@
import { describe, expect, it } from "vitest";
import {
compareDirectoryManifests,
createDirectoryManifest,
parseDirectoryManifest,
serializeDirectoryManifest,
} from "../../src/core/directory-manifest";
import { mergeThreeWay } from "../../src/core/merge";
function file(path: string, value: string): File {
const item = new File([value], path.split("/").at(-1)!, {
lastModified: Date.UTC(2026, 0, 1),
});
Object.defineProperty(item, "webkitRelativePath", {
value: `chosen-root/${path}`,
});
return item;
}
describe("directory manifests", () => {
it("hashes bounded files deterministically and strips the selected root", async () => {
const first = await createDirectoryManifest([
file("z.txt", "last"),
file("nested/a.txt", "first"),
]);
const second = await createDirectoryManifest([
file("nested/a.txt", "first"),
file("z.txt", "last"),
]);
expect(first.entries.map((entry) => entry.path)).toEqual([
"nested/a.txt",
"z.txt",
]);
expect(first.entries).toEqual(second.entries);
expect(parseDirectoryManifest(serializeDirectoryManifest(first))).toEqual(
first,
);
});
it("compares content digests rather than timestamps", async () => {
const left = await createDirectoryManifest([
file("same.txt", "same"),
file("changed.txt", "before"),
file("removed.txt", "gone"),
]);
const right = await createDirectoryManifest([
file("same.txt", "same"),
file("changed.txt", "after"),
file("added.txt", "new"),
]);
expect(
compareDirectoryManifests(left, right).map(({ path, status }) => ({
path,
status,
})),
).toEqual([
{ path: "added.txt", status: "added" },
{ path: "changed.txt", status: "modified" },
{ path: "removed.txt", status: "removed" },
{ path: "same.txt", status: "same" },
]);
});
it("rejects traversal and inconsistent imported totals", async () => {
await expect(
createDirectoryManifest([file("../escape.txt", "bad")]),
).rejects.toThrow(/unsafe/iu);
const manifest = await createDirectoryManifest([file("safe.txt", "ok")]);
const serialized = JSON.stringify({
...manifest,
totals: { files: 1, bytes: 999 },
});
expect(() => parseDirectoryManifest(serialized)).toThrow(/totals/iu);
});
it("rejects case-normalized collisions and invalid timestamps on import", async () => {
const manifest = await createDirectoryManifest([file("safe.txt", "ok")]);
const duplicate = {
...manifest,
entries: [
manifest.entries[0],
{ ...manifest.entries[0], path: "SAFE.txt" },
],
totals: { files: 2, bytes: manifest.totals.bytes * 2 },
};
expect(() => parseDirectoryManifest(JSON.stringify(duplicate))).toThrow(
/collision/iu,
);
expect(() =>
parseDirectoryManifest(
JSON.stringify({
...manifest,
entries: [{ ...manifest.entries[0], lastModified: "not-a-date" }],
}),
),
).toThrow(/fields/iu);
});
});
describe("bounded three-way merge", () => {
it("combines non-overlapping line changes without conflict", () => {
const result = mergeThreeWay({
base: "one\ntwo\nthree\n",
ours: "ONE\ntwo\nthree\n",
theirs: "one\ntwo\nTHREE\n",
});
expect(result.clean).toBe(true);
expect(result.text).toBe("ONE\ntwo\nTHREE\n");
});
it("emits explicit ours/base/theirs markers for overlapping changes", () => {
const result = mergeThreeWay({
base: "same\nvalue\n",
ours: "same\nours\n",
theirs: "same\ntheirs\n",
oursName: "working.txt",
theirsName: "incoming.txt",
});
expect(result.clean).toBe(false);
expect(result.conflicts).toHaveLength(1);
expect(result.text).toContain("<<<<<<< working.txt");
expect(result.text).toContain("||||||| base");
expect(result.text).toContain(">>>>>>> incoming.txt");
expect(JSON.parse(result.report)).toMatchObject({
schema: "de.add-ideas.diff-tools.merge-report.v1",
clean: false,
});
});
it("keeps conflict markers on their own lines when inputs lack final newlines", () => {
const result = mergeThreeWay({
base: "base",
ours: "ours",
theirs: "theirs",
});
expect(result.text).toBe(
"<<<<<<< ours\nours\n||||||| base\nbase\n=======\ntheirs\n>>>>>>> theirs\n",
);
});
});