Files
doona/apps/lite/scripts/draft-base.test.ts
T
Zakk fbe1779c79 feat(lite): add doona lite, a simple config editor
apps/lite is a separate Vite app (Astryx, React 19, StyleX) on the same
honk API, for people who want to switch nodes and edit groups,
subscriptions, nodes, routing and DNS without the observability pages.
Every change goes into a draft and one review dialog shows it in plain
words before it is written; dae syntax stays in the text editor. It has
light and dark themes and a demo mode backed by an in-browser mock.
Browser, motion and performance checks in apps/lite/scripts run under
Playwright, CI runs `pnpm -C apps/lite check`, and the UI rules are in
apps/lite/UI-RULES.md. It is linted with the repository config.
2026-10-27 01:37:20 +00:00

31 lines
1.8 KiB
TypeScript

import {expect, it} from 'vitest';
import {capabilities} from '../../../mock/fixtures/capabilities';
import {createMockApi} from '../src/demo/createMockApi';
import {applyContent, readMain} from '../src/api';
import {sectionText, validateContent, writeSection} from '../src/config';
import {draftBase} from '../src/state';
it.each([
['dns', (text: string) => text.replace('tls://1.1.1.1:853', 'tls://1.0.0.1:853')],
['routing', (text: string) => text.replace('{', '{\n domain(example.org) -> direct')]
] as const)('keeps the %s draft on the source of its first edit across a re-read', async (section, change) => {
const api = await createMockApi({isolated: true});
const connection = {api, capabilities, address: 'test'};
const first = await readMain(api);
const pinned = draftBase(undefined, first, true)!;
const local = change(sectionText(first.content, section));
expect(local).not.toBe(sectionText(first.content, section));
const external = first.content.replace('udp://223.5.5.5:53', 'udp://9.9.9.9:53');
expect(external).not.toBe(first.content);
await api.pollOperation(await api.replaceConfigSource(first.id, external, `"${first.content_sha256}"`));
// The invalidation re-read lands while the draft is open.
const base = draftBase(pinned, await readMain(api), true)!;
expect(base.content_sha256).toBe(first.content_sha256);
const content = writeSection(base.content, section, local);
// Export serialises the same base, so it cannot carry the other client's change as if it were the draft's.
expect(content).not.toContain('udp://9.9.9.9:53');
await expect(validateContent(connection, base, content)).rejects.toMatchObject({key: 'conflict'});
await expect(applyContent(connection, base, content)).rejects.toMatchObject({key: 'conflict'});
expect((await readMain(api)).content).toBe(external);
});