dorfteich/apps/web/e2e/import-vault.spec.ts
Claude Fable 5 2d51a55119
All checks were successful
CD / Build and push images (push) Successful in 2m40s
CD / Deploy to Test (push) Successful in 10s
CD / Smoke tests against Test (push) Successful in 1m9s
CI / Lint, typecheck, test (push) Successful in 4m23s
CI / Build container images (push) Has been skipped
CD / Promote to Int (push) Successful in 12s
CI / Auth e2e pack (push) Successful in 6m15s
CI / Import/export fidelity gate (push) Successful in 47s
Release / Build release images and notes (push) Successful in 1m7s
Release / Release-candidate operations QA (push) Successful in 41s
Prod deploy / Deploy the released images to Prod (push) Successful in 16s
QA: wire the M13 packs into CI, document the vault import (#119)
CI runs the two new packs after the graph pack (chained, each preceded
by the login rate-limit reset): create-missing-page.spec.ts (#115) and
import-vault.spec.ts (#117/#118).

Docs: the pond-admin guide gains a full 'Import an Obsidian vault'
chapter — the three dialog choices, and what happens to folders, links
(including the duplicate-name rule: the alphabetically first vault path
wins), tags, images, and embeds, plus the limits and the all-or-nothing
semantics. The user guide explains following a link to a page that does
not exist yet. features.md gets both bullets. German mirrors updated
throughout (English stays authoritative).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-14 18:28:45 +02:00

136 lines
5.1 KiB
TypeScript

import { readdirSync, readFileSync, statSync } from 'node:fs';
import { dirname, join, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, test, type BrowserContext } from '@playwright/test';
import { zipSync } from 'fflate';
import { contextForUser } from './helpers';
/**
* Obsidian vault import pack (issues #117/#118): a pond admin imports the
* checked-in fixture vault through the settings dialog and the result shows
* up in the app — folder tree, rewritten wikilinks, tag labels, embedded
* image. A plain editor sees no such section. The ZIP is built from the
* fixture directory here, so the vault stays reviewable as plain files.
*/
const BASE_URL = process.env.E2E_BASE_URL ?? 'http://localhost:5173';
const FIXTURE_DIR = join(
dirname(fileURLToPath(import.meta.url)),
'../../../fixtures/import/obsidian-vault',
);
function fixtureZip(): Buffer {
const entries: Record<string, Uint8Array> = {};
const walk = (dir: string): void => {
for (const name of readdirSync(dir)) {
const path = join(dir, name);
if (statSync(path).isDirectory()) walk(path);
else entries[relative(FIXTURE_DIR, path)] = new Uint8Array(readFileSync(path));
}
};
walk(FIXTURE_DIR);
return Buffer.from(zipSync(entries));
}
async function json<T>(context: BrowserContext, url: string, data: unknown): Promise<T> {
const response = await context.request.post(url, { data });
if (!response.ok()) throw new Error(`post ${url}${response.status()}`);
return response.json() as Promise<T>;
}
test('a pond admin imports an Obsidian vault through the settings dialog', async ({ browser }) => {
const context = await contextForUser(browser, BASE_URL, 'fixture-user');
const ts = Date.now();
const pond = await json<{ id: string; slug: string }>(context, '/api/v1/ponds', {
name: `Vault Pond ${ts}`,
});
await json<{ id: string; slug: string; title: string }>(
context,
`/api/v1/ponds/${pond.id}/pages`,
{ title: `Vault Mount ${ts}` },
);
const label = await json<{ id: string; name: string }>(
context,
`/api/v1/ponds/${pond.id}/labels`,
{ name: `import-${ts}` },
);
const page = await context.newPage();
await page.goto(`/p/${pond.slug}/settings`);
// The admin-only section opens the dialog.
await page.locator('.vault-import__open').click();
const dialog = page.locator('.vault-import-dialog');
await expect(dialog).toBeVisible();
await dialog.locator('input[type="file"]').setInputFiles({
name: 'vault.zip',
mimeType: 'application/zip',
buffer: fixtureZip(),
});
// Mount under the prepared page and tag everything with the extra label.
await dialog
.locator('li', { hasText: `Vault Mount ${ts}` })
.locator('input')
.check();
await dialog
.locator('li', { hasText: `import-${ts}` })
.locator('input')
.check();
await dialog.locator('.vault-import-dialog__start').click();
// The job runs; the dialog offers the way into the imported pages.
const doneLink = dialog.getByRole('link');
await expect(doneLink).toBeVisible({ timeout: 30_000 });
await doneLink.click();
// The sidebar shows the vault's folder structure under the mount page.
const mountItem = page
.locator('.sidebar__page-item')
.filter({ has: page.locator(`.sidebar__page:text-is("Vault Mount ${ts}")`) })
.first();
await expect(
mountItem.locator('.sidebar__tree-children .sidebar__page', { hasText: 'Projekte' }),
).toBeVisible();
await expect(page.locator('.sidebar__page:text-is("Startseite")')).toBeVisible();
// A rewritten Obsidian link navigates to the right imported page, and the
// display text still reads like the original note name.
await page.goto(`/p/${pond.slug}/startseite`);
await page.locator('.editor-content a.wikilink', { hasText: 'Projekt A' }).click();
await expect(page).toHaveURL(new RegExp(`/p/${pond.slug}/projekt-a$`));
// The note's image came in as a pond file, and its tags became labels
// (nested #status/aktiv included) next to the dialog's extra label.
await expect(page.locator('.editor-content img').first()).toBeVisible();
const labels = await context.request.get(`/api/v1/ponds/${pond.id}/labels`);
const tree = JSON.stringify(await labels.json());
expect(tree).toContain('status');
expect(tree).toContain('aktiv');
expect(tree).toContain(label.name);
await context.close();
});
test('a plain editor gets no vault-import section', async ({ browser }) => {
const owner = await contextForUser(browser, BASE_URL, 'fixture-user');
const editor = await contextForUser(browser, BASE_URL, 'fixture-editor');
const ts = Date.now();
const pond = await json<{ id: string; slug: string }>(owner, '/api/v1/ponds', {
name: `Vault Gate ${ts}`,
});
await json(owner, `/api/v1/ponds/${pond.id}/members`, {
usernameOrEmail: 'fixture-editor',
role: 'editor',
});
const page = await editor.newPage();
await page.goto(`/p/${pond.slug}/settings`);
await expect(page.locator('.pond-settings-page')).toBeVisible();
await expect(page.locator('.vault-import__open')).toHaveCount(0);
await owner.close();
await editor.close();
});