Skip to content

Commit 6da7d5a

Browse files
author
Kevin Arthur
committed
test(lightcraft): pin the real close-dialog truncation and record its evidence
The browser spec now opens the dialog through the menubar command (Ctrl+W is reserved by the browser), matches Save exactly, and asserts whole ZWJ clusters plus the 48-grapheme budget. It passes on Chromium/Linux and the captured dialog shows the CJK run followed by undamaged family emoji. Review follow-ups: the audit README points at §6 for the uncertain records, "four-replacement" describes the removed escapers correctly, and the XML tests use an independent XML 1.0 predicate instead of the implementation's own `isXmlChar` (now module-local again) so a sanitizer regression cannot agree with itself.
1 parent 4de578a commit 6da7d5a

9 files changed

Lines changed: 50 additions & 17 deletions

File tree

‎docs/audits/lightcraft/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Review depth at cutoff A: **22 threads** (body plus every fetched comment),
4949
**954 full bodies**, **5 title-only** records (empty or unreadable body).
5050
Dispositions: **843 out-of-scope**, **90 screened-for-varve**, **18
5151
already-handled**, **28 uncertain**, **2 implemented**. The 28 uncertain
52-
records are listed in `findings.md` §4; they need a Varve reproduction before a
52+
records are listed in `findings.md` §6; they need a Varve reproduction before a
5353
defect can be claimed.
5454

5555

‎docs/audits/lightcraft/continuation.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Last updated: 2026-10-22.
2828
| Batch | Finding | Commit | State |
2929
|---|---|---|---|
3030
| 1 | Exported markup carries XML-illegal characters (`findings.md` §1) | see `git log --grep lightcraft` | implemented + unit-validated |
31-
| 2 | Name truncation splits grapheme clusters (`findings.md` §2) | see `git log --grep lightcraft` | implemented + unit-validated + E2E |
31+
| 2 | Name truncation splits grapheme clusters (`findings.md` §2) | see `git log --grep lightcraft` | implemented; unit and Chromium E2E passed 2026-10-22 |
32+
| 3 | Unreadable settings discarded (`findings.md` §3a) | see `git log --grep lightcraft` | implemented + unit-validated; recovery notice still missing |
3233

3334
`screened-for-varve` queues from `findings.md` §4 stay open: preview/export
3435
divergence, deterministic export bytes, mask-overlay visibility while adjusting,

‎docs/audits/lightcraft/findings.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Two (`2376`, `2489`) are reports with no actionable content.
173173
| Changed-component regression | `pnpm exec vitest run packages/editor/src/components/Inspector/sections/FontDetectSection.test.tsx …` | 48 passed across 6 files |
174174
| Type checking | `pnpm --filter @varve/shared --filter @varve/codegen --filter @varve/editor typecheck` | clean |
175175
| Format/lint/audits | commit checkpoint (Biome staged, emoji, health, contacts, docs, secrets, import boundaries, E2E typecheck) | passed |
176-
| Real workflow, browser | `tests/e2e/dialogs/lightcraft-name-truncation.spec.ts` (Chromium, Linux) | see `continuation.md` |
176+
| Real workflow, browser | `VARVE_HEAVY_TASK_PARALLELISM=0 VARVE_E2E_PORT=1433 npx playwright test tests/e2e/dialogs/lightcraft-name-truncation.spec.ts --project=chromium --workers=1` | passed (1 spec, 2026-10-22). Screenshot: `docs/screenshots/lightcraft-corpus/close-dialog-grapheme-name.png` — the dialog shows 24 CJK characters followed by whole family emoji and the truncation ellipsis. |
177177
| Documentation drift | `pnpm audit:docs` | clean |
178178

179179
The full `@varve/editor` Vitest package and the Rust workspace were **not** run
99.9 KB
Loading

‎packages/codegen/src/xmlIntegrity.test.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,26 @@
1919
*/
2020
import type { Document as SceneDoc } from '@varve/scene';
2121
import { createDocument, makeTextNode } from '@varve/scene';
22-
import { isXmlChar } from '@varve/shared';
2322
import { describe, expect, it } from 'vitest';
2423
import { exportNodeToSvg } from './svg';
2524

26-
/** Every character XML 1.0 cannot represent, whatever the escaping. */
25+
/**
26+
* Independent predicate for the XML 1.0 `Char` production. Deliberately not
27+
* imported from the implementation: a regression in the sanitizer must show up
28+
* as a test failure, not as agreement with itself.
29+
*/
2730
function illegalXmlCharacters(source: string): string[] {
2831
const illegal: string[] = [];
2932
for (const character of source) {
30-
if (!isXmlChar(character.codePointAt(0) as number)) illegal.push(character);
33+
const code = character.codePointAt(0) as number;
34+
const legal =
35+
code === 0x9 ||
36+
code === 0xa ||
37+
code === 0xd ||
38+
(code >= 0x20 && code <= 0xd7ff) ||
39+
(code >= 0xe000 && code <= 0xfffd) ||
40+
(code >= 0x10000 && code <= 0x10ffff);
41+
if (!legal) illegal.push(character);
3142
}
3243
return illegal;
3344
}

‎packages/editor/src/export/aiDisclosure.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Document } from '@varve/scene';
2-
import { isXmlChar } from '@varve/shared';
32
import { describe, expect, it } from 'vitest';
43
import {
54
applyAiDisclosureToSvg,
@@ -195,8 +194,19 @@ describe('applyAiDisclosureToSvg', () => {
195194
* same SVG embed, so the sanitizer must hold for every field.
196195
*/
197196
describe('AI disclosure XML character integrity', () => {
197+
// Independent XML 1.0 `Char` predicate (never the implementation's).
198198
const illegal = (source: string) =>
199-
Array.from(source).filter((character) => !isXmlChar(character.codePointAt(0) as number));
199+
Array.from(source).filter((character) => {
200+
const code = character.codePointAt(0) as number;
201+
return !(
202+
code === 0x9 ||
203+
code === 0xa ||
204+
code === 0xd ||
205+
(code >= 0x20 && code <= 0xd7ff) ||
206+
(code >= 0xe000 && code <= 0xfffd) ||
207+
(code >= 0x10000 && code <= 0x10ffff)
208+
);
209+
});
200210

201211
it('XMP stays well-formed for a description carrying control characters', () => {
202212
const xmp = generateAiDisclosureXmp({

‎packages/shared/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ export {
755755
ZOOM_STEP_FACTOR,
756756
zoomAboutPoint,
757757
} from './viewport';
758-
export { escapeXmlText, isXmlChar, sanitizeXmlText } from './xmlText';
758+
export { escapeXmlText, sanitizeXmlText } from './xmlText';
759759

760760
/** Semantic Strata package marker. */
761761
export const PACKAGE = '@varve/shared' as const;

‎packages/shared/src/xmlText.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/** U+FFFD REPLACEMENT CHARACTER: the visible, parseable stand-in. */
1717
const REPLACEMENT = '\uFFFD';
1818

19-
export function isXmlChar(codePoint: number): boolean {
19+
function isXmlChar(codePoint: number): boolean {
2020
if (codePoint === 0x9 || codePoint === 0xa || codePoint === 0xd) return true;
2121
if (codePoint < 0x20) return false;
2222
if (codePoint <= 0xd7ff) return true;

‎tests/e2e/dialogs/lightcraft-name-truncation.spec.ts‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ import { dismissFirstRunOverlayIfPresent } from '../helpers/nav';
1515

1616
const REVIEW_DIR = 'reports/lightcraft-corpus';
1717
const FAMILY = '\u{1F468}\u200D\u{1F469}\u200D\u{1F467}';
18-
/** 44 CJK characters then family emoji: the 48-grapheme cut lands inside one. */
19-
const DOCUMENT_NAME = `${'\u4e2d'.repeat(44)}${FAMILY.repeat(6)}`;
18+
/**
19+
* 24 CJK characters then 25 family emoji: 49 graphemes, so the 48-grapheme cut
20+
* lands inside the emoji run. The CJK prefix is short enough that the first
21+
* emoji survives wrapping in the screenshot, which is the point of the visual
22+
* check — a cut that only appears off-screen proves nothing.
23+
*/
24+
const DOCUMENT_NAME = `${'\u4e2d'.repeat(24)}${FAMILY.repeat(25)}`;
2025

2126
function loneSurrogates(text: string): string[] {
2227
const found: string[] = [];
@@ -62,9 +67,14 @@ test.describe('document-name truncation in the close dialog', () => {
6267
await page.mouse.up();
6368
await page.keyboard.press('v');
6469

65-
await page.keyboard.press(process.platform === 'darwin' ? 'Meta+w' : 'Control+w');
70+
// Use the menubar command rather than Ctrl+W: the browser reserves that
71+
// accelerator, so a headless run cannot prove the app's own binding.
72+
await page.getByRole('menuitem', { name: 'File' }).click();
73+
await page.getByRole('menuitem', { name: /close document/i }).click();
6674
const dialog = page.locator('dialog[open]').last();
67-
await expect(dialog.getByRole('button', { name: 'Save' })).toBeVisible({ timeout: 15000 });
75+
await expect(dialog.getByRole('button', { name: 'Save', exact: true })).toBeVisible({
76+
timeout: 15000,
77+
});
6878

6979
const text = (await dialog.textContent()) ?? '';
7080
expect(loneSurrogates(text)).toEqual([]);
@@ -73,11 +83,12 @@ test.describe('document-name truncation in the close dialog', () => {
7383
let index = text.indexOf(man);
7484
expect(index).toBeGreaterThanOrEqual(0);
7585
while (index >= 0) {
76-
expect(text.slice(index, index + 3)).toBe(`\u{1F468}\u200D\u{1F469}`);
86+
// man (2 code units) + ZWJ (1) + woman (2): five units, one cluster.
87+
expect(text.slice(index, index + 5)).toBe(`\u{1F468}\u200D\u{1F469}`);
7788
index = text.indexOf(man, index + 1);
7889
}
79-
// The 48-grapheme budget is honoured: 44 CJK + 3 families + ellipsis.
80-
expect(text).toContain(`${'\u4e2d'.repeat(44)}${FAMILY}${FAMILY}${FAMILY}\u2026`);
90+
// The 48-grapheme budget is honoured: 24 CJK + 23 families + ellipsis.
91+
expect(text).toContain(`${'\u4e2d'.repeat(24)}${FAMILY.repeat(23)}\u2026`);
8192

8293
await page.screenshot({ path: `${REVIEW_DIR}/close-dialog-grapheme-name.png`, fullPage: true });
8394
// Leave no unsaved work behind for later specs in the same context.

0 commit comments

Comments
 (0)