Release Minimize Tools 0.1.0

This commit is contained in:
2026-09-01 13:22:35 +02:00
commit 7bd20872a2
59 changed files with 9534 additions and 0 deletions
+122
View File
@@ -0,0 +1,122 @@
import { expect, test, type Page } from "@playwright/test";
const ORIGIN = "http://127.0.0.1:4200";
async function watchLocalOnly(page: Page) {
const external: string[] = [];
await page.route("**/*", async (route) => {
const url = new URL(route.request().url());
if (url.origin !== ORIGIN) {
external.push(url.href);
await route.abort();
} else await route.continue();
});
return external;
}
test("minimizes a JSON failure at a nested path without network access", async ({
page,
}) => {
await page.setViewportSize({ width: 1800, height: 1000 });
const external = await watchLocalOnly(page);
await page.goto("/deep/nested/minimize/");
await expect(
page.getByRole("heading", { name: "Minimize Tools" }),
).toBeVisible();
await page.getByRole("button", { name: "Minimize reproducer" }).click();
await expect(page.getByLabel("Minimized result")).toHaveValue(
'{"request":{"id":0}}',
);
await expect(page.getByText(/.*bytes · \d+ tests/u)).toBeVisible();
expect(external).toEqual([]);
expect(
await page
.locator(".toolbox-shell__main")
.evaluate((node) => getComputedStyle(node).width),
).toBe("1440px");
});
test("runs regular expressions in a worker and keeps the complete result", async ({
page,
}) => {
await page.goto("/deep/nested/minimize/");
await page.getByLabel("Structure").selectOption("text");
await page.getByLabel("Failure predicate").selectOption("regex-matches");
await page.getByLabel("Failing input").fill("noise TARGET more noise");
await page.getByLabel("Regular expression").fill("TARGET");
await page.getByLabel(/Slow threshold/u).fill("100");
await page.getByRole("button", { name: "Minimize reproducer" }).click();
await expect(page.getByLabel("Minimized result")).toHaveValue("TARGET");
await page.getByLabel("Regular expression").fill("[");
await page.getByRole("button", { name: "Minimize reproducer" }).click();
await expect(page.getByRole("alert")).toContainText("retained");
await expect(page.getByLabel("Minimized result")).toHaveValue("TARGET");
});
test("reduces XML against the restricted browser XSLT predicate", async ({
page,
}) => {
await page.goto("/deep/nested/minimize/");
await page.getByRole("button", { name: "XSLT failure" }).click();
await page.getByRole("button", { name: "Minimize reproducer" }).click();
await expect(page.getByLabel("Minimized result")).toContainText("BOOM");
await expect(page.getByLabel("Minimized result")).not.toContainText(
"metadata",
);
});
test("downloads the minimized case and exact predicate report", async ({
page,
}) => {
await page.goto("/deep/nested/minimize/");
await page.getByRole("button", { name: "Minimize reproducer" }).click();
await expect(page.getByLabel("Minimized result")).not.toHaveValue("");
const caseDownload = page.waitForEvent("download");
await page.getByRole("button", { name: "Download case" }).click();
expect((await caseDownload).suggestedFilename()).toBe("minimized.json");
const reportDownload = page.waitForEvent("download");
await page.getByRole("button", { name: "Download report" }).click();
expect((await reportDownload).suggestedFilename()).toBe(
"minimization-report.json",
);
});
test("integrates help, themes, identity, headers and offline reload", async ({
page,
request,
context,
}) => {
await page.goto("/deep/nested/minimize/");
await page.getByRole("button", { name: "Help" }).click();
await expect(
page.getByRole("dialog", { name: "About Minimize Tools" }),
).toContainText("predicate");
await page.keyboard.press("Escape");
await page.getByRole("button", { name: "Personalize" }).click();
await page.getByRole("button", { name: "Dark" }).click();
await expect(page.locator(".toolbox-shell").first()).toHaveAttribute(
"data-toolbox-theme",
"dark",
);
expect(
await page.evaluate(async () =>
Boolean(await navigator.serviceWorker.ready),
),
).toBe(true);
const index = await request.get("/deep/nested/minimize/");
expect(index.headers()["content-security-policy"]).toContain(
"connect-src 'self'",
);
expect(await index.text()).not.toMatch(/\b(?:src|href)=["']\//u);
const manifest = await request.get("/deep/nested/minimize/toolbox-app.json");
await expect(manifest.json()).resolves.toMatchObject({
id: "de.add-ideas.minimize-tools",
version: "0.1.0",
privacy: { processing: "local", telemetry: false },
});
await context.setOffline(true);
await page.reload();
await expect(
page.getByRole("heading", { name: "Minimize Tools" }),
).toBeVisible();
});
+49
View File
@@ -0,0 +1,49 @@
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it } from "vitest";
import { Workbench } from "../../src/components/Workbench";
describe("Minimize workbench", () => {
it("minimizes the focused JSON Schema example", async () => {
const user = userEvent.setup();
render(<Workbench />);
await user.click(
screen.getByRole("button", { name: "Minimize reproducer" }),
);
await waitFor(() =>
expect(
(screen.getByLabelText("Minimized result") as HTMLTextAreaElement)
.value,
).toContain('"id":0'),
);
expect(screen.getByText(/bytes · \d+ tests/u)).toBeInTheDocument();
});
it("keeps the last complete result after a predicate error", async () => {
const user = userEvent.setup();
render(<Workbench />);
await user.click(
screen.getByRole("button", { name: "Minimize reproducer" }),
);
await waitFor(() =>
expect(screen.getByLabelText("Minimized result")).not.toHaveValue(""),
);
const previous = (
screen.getByLabelText("Minimized result") as HTMLTextAreaElement
).value;
await user.selectOptions(
screen.getByLabelText("Failure predicate"),
"contains",
);
const marker = screen.getByLabelText("Marker");
await user.clear(marker);
await user.type(marker, "NOT PRESENT");
await user.click(
screen.getByRole("button", { name: "Minimize reproducer" }),
);
await waitFor(() =>
expect(screen.getByRole("alert")).toHaveTextContent(/retained/u),
);
expect(screen.getByLabelText("Minimized result")).toHaveValue(previous);
});
});
+128
View File
@@ -0,0 +1,128 @@
import { describe, expect, it } from "vitest";
import { minimizeInput } from "../../src/minimize/engine";
import {
createPredicate,
type RegexEvaluator,
} from "../../src/minimize/predicates";
const unusedRegex: RegexEvaluator = async () => ({
matched: false,
elapsedMs: 0,
timedOut: false,
});
describe("minimization engine", () => {
it("removes XML structure while preserving a literal marker", async () => {
const input = `<case><noise a="1">discard</noise><payload><message>BOOM</message><also>discard</also></payload></case>`;
const predicate = createPredicate(
{ kind: "contains", needle: "BOOM" },
unusedRegex,
);
const result = await minimizeInput(
input,
{ structure: "xml", maxTests: 300, maxSeconds: 5 },
predicate,
new AbortController().signal,
);
expect(result.minimized).toContain("BOOM");
expect(result.minimized.length).toBeLessThan(input.length);
expect(
new DOMParser()
.parseFromString(result.minimized, "application/xml")
.querySelector("parsererror"),
).toBeNull();
expect(result.steps.length).toBeGreaterThan(0);
});
it("keeps the original JSON Schema failure signature", async () => {
const input = JSON.stringify({
request: { id: 0, label: "noise" },
unrelated: [1, 2, 3],
});
const predicate = createPredicate(
{
kind: "json-schema-fails",
preserveFailureSignature: true,
schema: JSON.stringify({
type: "object",
required: ["request"],
properties: {
request: {
type: "object",
required: ["id"],
properties: { id: { type: "integer", minimum: 1 } },
},
},
}),
},
unusedRegex,
);
const result = await minimizeInput(
input,
{ structure: "json", maxTests: 500, maxSeconds: 5 },
predicate,
new AbortController().signal,
);
expect(JSON.parse(result.minimized)).toEqual({ request: { id: 0 } });
});
it("minimizes malformed syntax and reports budget exhaustion", async () => {
const predicate = createPredicate({ kind: "invalid-json" }, unusedRegex);
const result = await minimizeInput(
'{"large": [1,2,}',
{ structure: "json", maxTests: 1, maxSeconds: 5 },
predicate,
new AbortController().signal,
);
expect(result.exhausted).toBe(true);
expect(result.tests).toBe(1);
});
it("rejects a baseline that does not reproduce and honours cancellation", async () => {
await expect(
minimizeInput(
"safe",
{ structure: "text", maxTests: 20, maxSeconds: 2 },
createPredicate({ kind: "contains", needle: "BOOM" }, unusedRegex),
new AbortController().signal,
),
).rejects.toThrow(/does not satisfy/u);
const controller = new AbortController();
controller.abort();
await expect(
minimizeInput(
"BOOM",
{ structure: "text", maxTests: 20, maxSeconds: 2 },
createPredicate({ kind: "contains", needle: "BOOM" }, unusedRegex),
controller.signal,
),
).rejects.toMatchObject({ name: "AbortError" });
});
it("uses isolated regex outcomes and fails closed on unsafe schemas/XSLT", async () => {
const slow = createPredicate(
{ kind: "regex-slow", pattern: "a+", flags: "u", thresholdMs: 20 },
async () => ({ matched: false, elapsedMs: 20, timedOut: false }),
);
expect(await slow("aaaa", new AbortController().signal)).toBe(true);
expect(() =>
createPredicate(
{
kind: "json-schema-fails",
schema: '{"$ref":"https://invalid/schema.json"}',
},
unusedRegex,
),
).toThrow(/unsupported.*\$ref/iu);
expect(() =>
createPredicate(
{
kind: "xslt-throws",
stylesheet:
'<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:include href="https://invalid/x.xsl"/></xsl:stylesheet>',
},
unusedRegex,
),
).toThrow(/include/u);
});
});