/** * MEDIA SEAL FINDINGS (coordinator, 27 Nov 2026), phone against the personal object, end to end, on an invented life: * * cd apps/business && pnpm -s exec tsx scripts/__tests__/e2e-media-seal.ts * * Starts the Worker under `wrangler dev` with the personal object onboarded (`dev-worker.ts`), then runs the phone * core's walk (`crates/cotton-ffi/src/phone/personal_object_e2e.rs`, * `what_the_object_holds_of_a_persons_picture_and_a_chat_picture`): with its data key held, it puts up one invented * picture as a person's picture, a WhatsApp profile picture and a chat picture through the drain's own upload, and * reads each back raw; then puts the same three up plain as an app from before did, and reads all six back opened. * AVATAR SEAL (27 Nov 2026), asserted here: the object holds both kinds of face and the chat picture sealed (f1, served * as application/vnd.cotton.f1, never the picture's bytes), the three from before plain, and a reader opens all six. * Cargo goes through `pnpm box:cargo` where `COTTON_E2E_BOX` is set (the rented box). Synthetic data only. */ import { spawnSync, type ChildProcess } from "node:child_process"; import { mkdtempSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import { join, resolve } from "node:path"; import { APP, check, startDevWorker, stop } from "./dev-worker.ts"; import { WS } from "./fixture.ts"; const CRATES = resolve(APP, "../../crates"); const tmp = mkdtempSync(join(tmpdir(), "e2e-media-seal-")); let wrangler: ChildProcess | null = null; const cleanup = (): void => { stop(wrangler); wrangler = null; rmSync(tmp, { recursive: true, force: true }); }; process.on("SIGINT", () => { cleanup(); process.exit(130); }); const PICTURE = process.env.COTTON_E2E_PICTURE ?? ""; try { check(PICTURE.length > 0, "COTTON_E2E_PICTURE names an invented picture"); const { base, credential } = await startDevWorker(tmp, WS, (child) => { wrangler = child; }); const env = { ...process.env, COTTON_E2E_BASE: base, COTTON_E2E_CREDENTIAL: credential, COTTON_E2E_DATABASE: WS, COTTON_E2E_PICTURE: PICTURE }; const test = ["test", "-q", "-p", "cotton-ffi", "--lib", "phone::personal_object::e2e::what_the_object_holds", "--", "--ignored", "--nocapture"]; const walk = process.env.COTTON_E2E_BOX ? spawnSync("pnpm", ["-s", "box:cargo", ...test], { cwd: resolve(CRATES, ".."), encoding: "utf8", env: { ...env, BOX_CARGO_ENV: "COTTON_E2E_BASE COTTON_E2E_CREDENTIAL COTTON_E2E_DATABASE COTTON_E2E_PICTURE" } }) : spawnSync("cargo", test, { cwd: CRATES, encoding: "utf8", env }); const said = /E2E-MEDIA-SEAL (\{.*\})/.exec(walk.stdout); check(walk.status === 0 && said, `the phone's walk ran${said ? "" : `\n${walk.error ? String(walk.error) : `${walk.stdout?.slice(-4000) ?? ""}${walk.stderr?.slice(-4000) ?? ""}`}`}`); type Held = { what: string; key: string; landed: string; held_is_the_picture: boolean; held_is_sealed: boolean; opened_is_the_picture: boolean }; const { sha256, held } = JSON.parse(said![1]!) as { sha256: string; held: Held[] }; check(held.length === 6, `six files were put up (${held.length})`); for (const one of held) { const answer = await fetch(`${base}/v1/media/${one.key}`, { headers: { authorization: `Bearer ${credential}` } }); const served = (answer.headers.get("content-type") ?? "").split(";")[0]!.trim(); console.log(`MEDIA ${JSON.stringify({ ...one, served_as: served, status: answer.status })}`); check(one.landed === "landed" && answer.status === 200, `${one.what} landed and is served (${one.landed}, ${answer.status})`); if (one.what.endsWith("_from_before")) { check(one.held_is_the_picture && !one.held_is_sealed, `${one.what}: held plain, as an app from before put it`); } else { check(one.held_is_sealed && !one.held_is_the_picture && served === "application/vnd.cotton.f1", `${one.what}: the object holds it sealed (f1), never the picture (sealed ${one.held_is_sealed}, served as ${served})`); } check(one.opened_is_the_picture, `${one.what}: a reader opens it to the picture`); } console.log(`e2e media seal: ok, both kinds of face and the chat picture held f1, the three from before still open (the picture's sha256 ${sha256})`); } catch (error) { console.error((error as Error).message); process.exitCode = 1; } finally { cleanup(); }