Release Format Lab 0.1.0
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
|
||||
const ORIGIN = "http://127.0.0.1:4201";
|
||||
|
||||
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("explores a real directed format graph at a nested path", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.setViewportSize({ width: 1800, height: 1000 });
|
||||
const external = await watchLocalOnly(page);
|
||||
await page.goto("/deep/nested/format-lab/");
|
||||
await expect(page.getByRole("heading", { name: "Format Lab" })).toBeVisible();
|
||||
await page.getByLabel("Domain").selectOption("image");
|
||||
await expect(
|
||||
page.getByRole("img", {
|
||||
name: /Images conversion graph from PNG to JPEG/u,
|
||||
}),
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page.getByText(/This v0.1 lab exposes catalog contracts for Images/u),
|
||||
).toBeVisible();
|
||||
expect(external).toEqual([]);
|
||||
expect(
|
||||
await page
|
||||
.locator(".toolbox-shell__main")
|
||||
.evaluate((node) => getComputedStyle(node).width),
|
||||
).toBe("1440px");
|
||||
});
|
||||
|
||||
test("measures a typed XML round trip and downloads both outputs", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto("/deep/nested/format-lab/");
|
||||
await page.getByLabel("To format").selectOption("xml");
|
||||
await page.getByRole("button", { name: /^JSON → XML/u }).click();
|
||||
await page.getByRole("button", { name: "Run selected round trip" }).click();
|
||||
const output = page.getByRole("textbox", {
|
||||
name: "Conversion output",
|
||||
exact: true,
|
||||
});
|
||||
await expect(output).toContainText(
|
||||
'<field name="active" type="boolean">true',
|
||||
);
|
||||
await expect(
|
||||
page.getByRole("row", { name: /Nested values.*measured preserved/u }),
|
||||
).toBeVisible();
|
||||
const targetDownload = page.waitForEvent("download");
|
||||
await page.getByRole("button", { name: "Download target" }).click();
|
||||
expect((await targetDownload).suggestedFilename()).toBe("converted.xml");
|
||||
const reportDownload = page.waitForEvent("download");
|
||||
await page.getByRole("button", { name: "Download evidence report" }).click();
|
||||
expect((await reportDownload).suggestedFilename()).toBe(
|
||||
"format-lab-report.json",
|
||||
);
|
||||
});
|
||||
|
||||
test("shows CSV losses and retains evidence after invalid source", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto("/deep/nested/format-lab/");
|
||||
await expect(
|
||||
page.getByRole("row", { name: /Scalar types.*measured changed/u }),
|
||||
).toBeVisible();
|
||||
const output = page.getByRole("textbox", {
|
||||
name: "Conversion output",
|
||||
exact: true,
|
||||
});
|
||||
const previous = await output.inputValue();
|
||||
await page.getByLabel("Source data").fill("[");
|
||||
await page.getByRole("button", { name: "Run selected round trip" }).click();
|
||||
await expect(page.getByRole("alert")).toContainText("retained");
|
||||
await expect(output).toHaveValue(previous);
|
||||
});
|
||||
|
||||
test("integrates help, themes, identity, headers and offline reload", async ({
|
||||
page,
|
||||
request,
|
||||
context,
|
||||
}) => {
|
||||
await page.goto("/deep/nested/format-lab/");
|
||||
await page.getByRole("button", { name: "Help" }).click();
|
||||
await expect(
|
||||
page.getByRole("dialog", { name: "About Format Lab" }),
|
||||
).toContainText("lossless claim");
|
||||
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/format-lab/");
|
||||
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/format-lab/toolbox-app.json",
|
||||
);
|
||||
await expect(manifest.json()).resolves.toMatchObject({
|
||||
id: "de.add-ideas.format-lab",
|
||||
version: "0.1.0",
|
||||
privacy: { processing: "local", telemetry: false },
|
||||
});
|
||||
await context.setOffline(true);
|
||||
await page.reload();
|
||||
await expect(page.getByRole("heading", { name: "Format Lab" })).toBeVisible();
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { Workbench } from "../../src/components/Workbench";
|
||||
|
||||
describe("Format Lab workbench", () => {
|
||||
it("shows catalog expectations beside initial measured changes", () => {
|
||||
render(<Workbench />);
|
||||
expect(
|
||||
screen.getByRole("heading", { name: "Format Lab" }),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getAllByText("measured changed").length).toBeGreaterThan(0);
|
||||
expect(
|
||||
screen.getByRole("row", { name: /Document metadata.*not tested/iu }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("retains evidence after malformed input and disables unsupported execution", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Workbench />);
|
||||
const previous = (
|
||||
screen.getByLabelText("Conversion output") as HTMLTextAreaElement
|
||||
).value;
|
||||
await user.clear(screen.getByLabelText("Source data"));
|
||||
await user.type(screen.getByLabelText("Source data"), "[[");
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: "Run selected round trip" }),
|
||||
);
|
||||
expect(screen.getByRole("alert")).toHaveTextContent(/retained/u);
|
||||
expect(screen.getByLabelText("Conversion output")).toHaveValue(previous);
|
||||
await user.selectOptions(screen.getByLabelText("Domain"), "image");
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Run selected round trip" }),
|
||||
).toBeDisabled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { findRoutes, properties } from "../../src/lab/catalog";
|
||||
|
||||
describe("format catalog", () => {
|
||||
it("prefers the lower-loss route for selected properties", () => {
|
||||
const routes = findRoutes("data", "json", "xml", [
|
||||
"scalar-types",
|
||||
"nested",
|
||||
"nulls",
|
||||
]);
|
||||
expect(routes[0]?.formats).toEqual(["json", "xml"]);
|
||||
expect(routes[0]?.summary).toMatchObject({
|
||||
"scalar-types": "expected-preserved",
|
||||
nested: "expected-preserved",
|
||||
});
|
||||
expect(
|
||||
routes.find((route) => route.formats.includes("csv"))?.score,
|
||||
).toBeGreaterThan(routes[0]!.score);
|
||||
});
|
||||
|
||||
it("enumerates bounded acyclic routes and identity evidence", () => {
|
||||
const routes = findRoutes(
|
||||
"subtitle",
|
||||
"ass",
|
||||
"srt",
|
||||
properties.subtitle.map((item) => item.id),
|
||||
);
|
||||
expect(routes.length).toBeGreaterThan(0);
|
||||
expect(
|
||||
routes.every(
|
||||
(route) =>
|
||||
route.edges.length <= 4 &&
|
||||
new Set(route.formats).size === route.formats.length,
|
||||
),
|
||||
).toBe(true);
|
||||
expect(findRoutes("image", "png", "png", ["pixels"])[0]).toMatchObject({
|
||||
formats: ["png"],
|
||||
score: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it("does not invent paths between incompatible audio and video families", () => {
|
||||
expect(findRoutes("av", "wav", "mp4", ["audio"])).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { findRoutes, properties } from "../../src/lab/catalog";
|
||||
import { parseData, runRoundTrip, serializeData } from "../../src/lab/data";
|
||||
|
||||
const all = properties.data.map((property) => property.id);
|
||||
const sample = JSON.stringify([
|
||||
{
|
||||
id: 1,
|
||||
active: true,
|
||||
nullable: null,
|
||||
nested: { score: 1.25 },
|
||||
text: "Café 🚲",
|
||||
},
|
||||
]);
|
||||
|
||||
describe("structured data lab", () => {
|
||||
it("measures typed XML round trips without claiming metadata", () => {
|
||||
const route = findRoutes("data", "json", "xml", all)[0]!;
|
||||
const result = runRoundTrip(sample, route);
|
||||
expect(result.targetText).toContain(
|
||||
'<field name="active" type="boolean">true',
|
||||
);
|
||||
expect(
|
||||
result.measurements.filter(
|
||||
(measurement) => measurement.status === "measured-changed",
|
||||
),
|
||||
).toEqual([]);
|
||||
expect(result.measurements.at(-1)).toMatchObject({
|
||||
property: "metadata",
|
||||
status: "not-tested",
|
||||
});
|
||||
});
|
||||
|
||||
it("exposes CSV type, null and nested-value changes", () => {
|
||||
const route = findRoutes("data", "json", "csv", all)[0]!;
|
||||
const result = runRoundTrip(sample, route);
|
||||
const changed = result.measurements
|
||||
.filter((measurement) => measurement.status === "measured-changed")
|
||||
.map((measurement) => measurement.property);
|
||||
expect(changed).toEqual(
|
||||
expect.arrayContaining(["scalar-types", "nulls", "nested", "numbers"]),
|
||||
);
|
||||
expect(result.notes.join(" ")).toContain("CSV cells");
|
||||
});
|
||||
|
||||
it("neutralizes spreadsheet formulas and keeps the change measurable", () => {
|
||||
const document = parseData('[{"value":" =2+2"}]', "json");
|
||||
const csv = serializeData(document, "csv");
|
||||
expect(csv).toContain("' =2+2");
|
||||
const route = findRoutes("data", "json", "csv", all)[0]!;
|
||||
expect(
|
||||
runRoundTrip('[{"value":" =2+2"}]', route).measurements.find(
|
||||
(measurement) => measurement.property === "unicode",
|
||||
),
|
||||
).toMatchObject({ status: "measured-changed" });
|
||||
});
|
||||
|
||||
it("imports generic XML honestly and rejects active or dangerous input", () => {
|
||||
const generic = parseData(
|
||||
"<records><row><id>1</id><name>Ada</name></row></records>",
|
||||
"xml",
|
||||
);
|
||||
expect(generic.rows).toEqual([{ id: "1", name: "Ada" }]);
|
||||
expect(generic.notes.join(" ")).toMatch(/string fields/u);
|
||||
expect(() =>
|
||||
parseData('<!DOCTYPE x [<!ENTITY e "x">]><records/>', "xml"),
|
||||
).toThrow(/DOCTYPE/u);
|
||||
expect(() => parseData("__proto__,name\nvalue,Ada", "csv")).toThrow(
|
||||
/Dangerous/u,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects duplicate headings and non-record JSON", () => {
|
||||
expect(() => parseData("id,id\n1,2", "csv")).toThrow(/unique/u);
|
||||
expect(() => parseData("[1,2]", "json")).toThrow(/Record 1/u);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user