Initial release of File Tools 0.1.0

This commit is contained in:
2026-09-01 02:55:06 +02:00
commit 055f533cf1
62 changed files with 9050 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
import { expect, test, type Page, type Response } 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/file/");
await expect(page.getByRole("heading", { name: "File Tools" })).toBeVisible();
expect(external).toEqual([]);
expect(errors).toEqual([]);
});
test("inspects and hashes a local file in an immutable module worker", async ({
page,
}) => {
const external = await localOnly(page);
const responses: Response[] = [];
page.on("response", (response) => responses.push(response));
await page.goto("/deep/nested/file/");
await page
.locator('input[type="file"]')
.first()
.setInputFiles("tests/fixtures/hello.txt");
await expect(page.getByRole("heading", { name: "hello.txt" })).toBeVisible();
await expect(
page.getByText("text/plain (.txt)", { exact: true }),
).toBeVisible();
await page.getByRole("button", { name: "Hash", exact: true }).click();
await expect(page.getByText(/^[0-9a-f]{64}$/u)).toBeVisible();
const worker = responses.find((response) =>
/\/deep\/nested\/file\/assets\/inspect\.worker-[\w-]+\.js$/u.test(
new URL(response.url()).pathname,
),
);
expect(worker, "inspection worker request").toBeTruthy();
expect(worker!.headers()["content-type"]).toContain("text/javascript");
expect(worker!.headers()["cache-control"]).toBe(
"public, max-age=31536000, immutable",
);
expect(new URL(worker!.url()).origin).toBe(ORIGIN);
expect(external).toEqual([]);
});
test("serves the release identity and hardened headers", async ({
request,
}) => {
const index = await request.get("/deep/nested/file/");
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/file/toolbox-app.json");
await expect(manifest.json()).resolves.toMatchObject({
id: "de.add-ideas.file-tools",
version: "0.1.0",
entry: "./",
});
});