Files
glenloch-media/e2e/photo-archive.spec.ts
bhursey 982f9048e1
CI / build (push) Has been cancelled
fix(media): refuse local disk when a NAS share is configured
A bind-mounted host directory made the app report storage as ready while
media landed on the container host's local filesystem, so the NFS export was
never actually used. mediaStorage() now reads the mount table: a share written
as host:/export is only accepted when the media root is on a network
filesystem, otherwise uploads, edits and filing are blocked with the real
device and the fix. Settings and the Media page show the detected filesystem
and host-mount steps, README section 9 documents the OS-level mount (including
Docker-in-LXC) with docker-compose.nfs.yml as the alternative, and the E2E
suites use path-style shares for local test directories.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-11-21 00:45:36 +00:00

153 lines
4.9 KiB
TypeScript

import { test, expect } from "@playwright/test";
import { access, mkdir, readFile, readdir, rm } from "node:fs/promises";
import path from "node:path";
import sharp from "sharp";
import { signInAs, resetDb, BASE } from "./dev";
/**
* The finish-workflow APIs: save an edit, export a delivery size, archive the
* event to the mounted destination, and remove the live event only after the
* archive is complete. Runs against the isolated `media_e2e` database.
*/
const ARCHIVE_ROOT = process.env.ARCHIVE_DIR ?? "/tmp/glenloch-e2e-archive";
const ARCHIVE_FOLDER = "E2E Archive";
// Live photos sit on the configured share too, under `<share>/<folder>/events`.
const MEDIA_ROOT = path.join(ARCHIVE_ROOT, ARCHIVE_FOLDER);
let photoBytes: Buffer;
test.beforeAll(async ({ browser }) => {
const context = await browser.newContext();
const page = await context.newPage();
await resetDb(page);
await context.close();
photoBytes = await sharp({
create: {
width: 1200,
height: 800,
channels: 3,
background: { r: 80, g: 120, b: 160 },
},
})
.jpeg({ quality: 95 })
.toBuffer();
await mkdir(ARCHIVE_ROOT, { recursive: true });
await rm(path.join(ARCHIVE_ROOT, ARCHIVE_FOLDER), {
recursive: true,
force: true,
});
});
test("exports a delivery size, then archives and removes the event", async ({
page,
}) => {
await page.setViewportSize({ width: 1200, height: 900 });
await signInAs(page, "admin@glenloch.local");
const configured = await page.request.put(`${BASE}/api/dev/storage`, {
data: {
// Path-style share: this suite writes to a local E2E directory. A
// NAS-style share name would (correctly) demand a real network mount.
nfsShare: ARCHIVE_ROOT,
archivePath: ARCHIVE_ROOT,
archiveFolder: ARCHIVE_FOLDER,
},
});
expect(configured.ok()).toBe(true);
const storage = (await configured.json()) as { status?: { ready: boolean } };
expect(storage.status?.ready).toBe(true);
const eventResponse = await page.request.post(`${BASE}/api/events`, {
data: {
title: "E2E archive workflow",
eventType: "photoshoot",
startsAtLocal: "2026-11-20T10:00",
location: "Main campus",
},
});
expect(eventResponse.ok()).toBe(true);
const event = (await eventResponse.json()) as { event: { id: string } };
const folderResponse = await page.request.post(
`${BASE}/api/events/${event.event.id}/folders`,
{ data: { name: "Originals", kind: "originals" } },
);
expect(folderResponse.ok()).toBe(true);
const folder = (await folderResponse.json()) as { folder: { id: string } };
const upload = await page.request.post(
`${BASE}/api/events/${event.event.id}/folders/${folder.folder.id}/photos?name=archive-test.jpg`,
{
headers: { "content-type": "image/jpeg" },
data: photoBytes,
},
);
expect(upload.ok()).toBe(true);
const uploaded = (await upload.json()) as { photo: { id: string } };
const edit = await page.request.post(
`${BASE}/api/events/${event.event.id}/folders/${folder.folder.id}/photos/${uploaded.photo.id}/edit`,
{
data: {
adjustments: {
exposure: 0.4,
contrast: 8,
blackPoint: 0,
brightness: 0,
curves: [
{ x: 0, y: 0 },
{ x: 1, y: 1 },
],
},
},
},
);
expect(edit.ok()).toBe(true);
const exported = await page.request.get(
`${BASE}/api/events/${event.event.id}/folders/${folder.folder.id}/photos/${uploaded.photo.id}/export?size=640`,
);
expect(exported.ok()).toBe(true);
expect(exported.headers()["content-disposition"]).toContain(
"archive-test-640.jpg",
);
const exportMeta = await sharp(await exported.body()).metadata();
expect(exportMeta.width).toBe(640);
expect(exportMeta.height).toBe(427);
const archived = await page.request.post(
`${BASE}/api/events/${event.event.id}/archive`,
);
expect(archived.ok()).toBe(true);
const archive = (await archived.json()) as {
archivePath: string;
files: number;
};
expect(archive.files).toBe(3);
const manifest = JSON.parse(
await readFile(path.join(archive.archivePath, "manifest.json"), "utf8"),
) as {
photos: { original: string; edited: string | null; editJson: string | null }[];
};
expect(manifest.photos).toHaveLength(1);
expect(manifest.photos[0].original).toContain("archive-test.jpg");
expect(manifest.photos[0].edited).toContain("archive-test-edited.jpg");
expect(manifest.photos[0].editJson).toContain('"exposure":0.4');
const entries = await readdir(archive.archivePath, { recursive: true });
expect(entries.some((entry) => entry.endsWith("archive-test.jpg"))).toBe(true);
expect(
entries.some((entry) => entry.endsWith("archive-test-edited.jpg")),
).toBe(true);
const gone = await page.goto(`${BASE}/events/${event.event.id}`);
expect(gone?.status()).toBe(404);
await expect(
access(path.join(MEDIA_ROOT, "events", event.event.id)),
).rejects.toThrow();
});