Release Format Lab 0.1.0
This commit is contained in:
@@ -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