Release Text Tools 0.1.0

This commit is contained in:
2026-09-01 02:53:56 +02:00
commit c69bd5af12
57 changed files with 8370 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
import { expect, test, type Page } from "@playwright/test";
const ORIGIN = "http://127.0.0.1:4173";
async function localOnly(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("runs from a nested path without external requests", async ({ page }) => {
const errors: string[] = [];
page.on("pageerror", (error) => errors.push(error.message));
page.on("console", (message) => {
if (message.type() === "error") errors.push(message.text());
});
const external = await localOnly(page);
await page.goto("/deep/nested/text/");
await expect(page.getByRole("heading", { name: "Text Tools" })).toBeVisible();
expect(external).toEqual([]);
expect(errors).toEqual([]);
});
test("applies the visible text pipeline and preserves its last output", async ({
page,
}) => {
const external = await localOnly(page);
await page.goto("/deep/nested/text/");
await page.getByLabel("Text source").fill(" Alpha \r\nAlpha\n");
await page.getByRole("button", { name: "Apply pipeline" }).click();
await expect(page.getByLabel("Transformed output")).toHaveValue("Alpha\n");
await expect(
page.getByRole("cell", { name: "Trim every line" }),
).toBeVisible();
await expect(
page.getByRole("cell", { name: "Deduplicate lines" }),
).toBeVisible();
expect(external).toEqual([]);
});
test("serves the release identity and hardened headers", async ({
request,
}) => {
const index = await request.get("/deep/nested/text/");
expect(index.ok()).toBe(true);
expect(index.headers()["content-security-policy"]).toContain(
"default-src 'self'",
);
expect(await index.text()).not.toMatch(/\b(?:src|href)=["']\//u);
const manifest = await request.get("/deep/nested/text/toolbox-app.json");
await expect(manifest.json()).resolves.toMatchObject({
id: "de.add-ideas.text-tools",
version: "0.1.0",
entry: "./",
});
});
+17
View File
@@ -0,0 +1,17 @@
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { App } from "../../src/App";
describe("Text Tools", () => {
it("renders the local workbench and standard shell", async () => {
vi.stubGlobal(
"fetch",
vi.fn(async () => new Response("Not found", { status: 404 })),
);
render(<App />);
expect(
await screen.findByRole("heading", { name: "Text Tools" }),
).toBeVisible();
expect(await screen.findByText("Browser-local")).toBeVisible();
});
});
+42
View File
@@ -0,0 +1,42 @@
import { describe, expect, it } from "vitest";
import {
applyPipeline,
textInventory,
type TransformStep,
} from "../../src/text/pipeline";
const step = (type: TransformStep["type"], option = ""): TransformStep => ({
id: type,
type,
option,
enabled: true,
});
describe("text pipelines", () => {
it("applies transformations in the declared order", () =>
expect(
applyPipeline(" b \nA\na", [
step("trim-lines"),
step("dedupe-lines"),
step("sort-lines", "en"),
]).output,
).toBe("a\nA\nb"));
it("keeps disabled steps out of the report", () =>
expect(
applyPipeline("A", [{ ...step("case", "lower"), enabled: false }]),
).toEqual({ output: "A", steps: [], warnings: [] }));
it("escapes HTML as data", () =>
expect(
applyPipeline("<img src=x onerror=1>", [step("escape", "html")]).output,
).toBe("&lt;img src=x onerror=1&gt;"));
it("reports lossy transliteration", () =>
expect(applyPipeline("Crème", [step("transliterate")]).warnings[0]).toMatch(
/lossy/u,
));
it("tracks exact line endings", () =>
expect(textInventory("a\r\nb\nc\r")).toMatchObject({
crlf: 1,
bareLf: 1,
bareCr: 1,
finalNewline: true,
}));
});