@bendyline/squisq 1.5.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -10
- package/dist/{Doc-BBVGq1_9.d.ts → Doc-ylqWKDc_.d.ts} +248 -37
- package/dist/{ImageEditDoc-FuyGtt6o.d.ts → ImageEditDoc-D828IXJ1.d.ts} +1 -1
- package/dist/annotationCoercion-Dr_DY9Hx.d.ts +86 -0
- package/dist/{chunk-T5UK6YOB.js → chunk-2PWOO4ZE.js} +60 -17
- package/dist/chunk-2PWOO4ZE.js.map +1 -0
- package/dist/{chunk-VWUFZ6ZG.js → chunk-3E5F2XMR.js} +2 -29
- package/dist/chunk-3E5F2XMR.js.map +1 -0
- package/dist/chunk-4X3JQXNM.js +35 -0
- package/dist/chunk-4X3JQXNM.js.map +1 -0
- package/dist/{chunk-P3K7NLHF.js → chunk-5DKBFXPY.js} +31 -121
- package/dist/chunk-5DKBFXPY.js.map +1 -0
- package/dist/{chunk-DLXZMS5K.js → chunk-5J4HKRJF.js} +51 -3
- package/dist/chunk-5J4HKRJF.js.map +1 -0
- package/dist/chunk-5UYI3RJB.js +2503 -0
- package/dist/chunk-5UYI3RJB.js.map +1 -0
- package/dist/{chunk-BEQODJWV.js → chunk-66QO7XFB.js} +11 -291
- package/dist/chunk-66QO7XFB.js.map +1 -0
- package/dist/{chunk-HWVFJAAH.js → chunk-AMIR72JP.js} +28 -10
- package/dist/chunk-AMIR72JP.js.map +1 -0
- package/dist/chunk-CY2R2VPR.js +884 -0
- package/dist/chunk-CY2R2VPR.js.map +1 -0
- package/dist/chunk-FVJUUTEM.js +74 -0
- package/dist/chunk-FVJUUTEM.js.map +1 -0
- package/dist/{chunk-Q3ROPT5H.js → chunk-GZY66SDN.js} +1 -1
- package/dist/{chunk-Q3ROPT5H.js.map → chunk-GZY66SDN.js.map} +1 -1
- package/dist/chunk-JOQYPRDZ.js +127 -0
- package/dist/chunk-JOQYPRDZ.js.map +1 -0
- package/dist/{chunk-A4O7GIWE.js → chunk-MMPBOUK7.js} +10 -73
- package/dist/chunk-MMPBOUK7.js.map +1 -0
- package/dist/{chunk-LDQ2HJIX.js → chunk-PXLVXTLW.js} +252 -54
- package/dist/chunk-PXLVXTLW.js.map +1 -0
- package/dist/{chunk-TQWLI6S2.js → chunk-Q7LROV2H.js} +4 -2
- package/dist/{chunk-TQWLI6S2.js.map → chunk-Q7LROV2H.js.map} +1 -1
- package/dist/{chunk-GPLTCSXO.js → chunk-R2GC6RLD.js} +7 -7
- package/dist/chunk-R2GC6RLD.js.map +1 -0
- package/dist/chunk-R2YZTCLO.js +292 -0
- package/dist/chunk-R2YZTCLO.js.map +1 -0
- package/dist/chunk-S7A5D7ZJ.js +174 -0
- package/dist/chunk-S7A5D7ZJ.js.map +1 -0
- package/dist/chunk-TFJVXUHH.js +2358 -0
- package/dist/chunk-TFJVXUHH.js.map +1 -0
- package/dist/{chunk-LTN6I7QW.js → chunk-TUWMK62B.js} +55 -4
- package/dist/chunk-TUWMK62B.js.map +1 -0
- package/dist/{chunk-IMSCRLLV.js → chunk-VR7UPJ7C.js} +35 -25
- package/dist/chunk-VR7UPJ7C.js.map +1 -0
- package/dist/{chunk-KKNUBQ6Y.js → chunk-W4O2TX5I.js} +157 -92
- package/dist/chunk-W4O2TX5I.js.map +1 -0
- package/dist/{chunk-5TYS5V3G.js → chunk-X6DUONGT.js} +4204 -3560
- package/dist/chunk-X6DUONGT.js.map +1 -0
- package/dist/doc/index.d.ts +2334 -5
- package/dist/doc/index.js +127 -33
- package/dist/generate/index.d.ts +7 -2
- package/dist/generate/index.js +1 -1
- package/dist/imageEdit/index.d.ts +9 -6
- package/dist/imageEdit/index.js +3 -3
- package/dist/index.d.ts +12 -10
- package/dist/index.js +246 -80
- package/dist/jsonForm/index.d.ts +7 -3
- package/dist/jsonForm/index.js +9 -4
- package/dist/markdown/index.d.ts +6 -70
- package/dist/markdown/index.js +13 -9
- package/dist/narration/index.d.ts +618 -0
- package/dist/narration/index.js +82 -0
- package/dist/recommend/index.d.ts +15 -1
- package/dist/recommend/index.js +2 -2
- package/dist/schemas/index.d.ts +28 -6
- package/dist/schemas/index.js +15 -13
- package/dist/spatial/index.d.ts +0 -1
- package/dist/spatial/index.js +1 -1
- package/dist/storage/index.js +1 -1
- package/dist/{themeLibrary-CehcJhzz.d.ts → themeLibrary-RjVgLpUi.d.ts} +10 -11
- package/dist/timing/index.js +5 -3
- package/dist/transform/index.d.ts +35 -24
- package/dist/transform/index.js +9 -10
- package/dist/{types-DlAZ7MW4.d.ts → types-BwMPl2CB.d.ts} +1 -1
- package/dist/{types-D98li1gV.d.ts → types-C4kiRn_k.d.ts} +3 -1
- package/dist/versions/index.d.ts +2 -1
- package/dist/versions/index.js +2 -2
- package/package.json +6 -6
- package/src/__tests__/applyNarrationTiming.test.ts +190 -0
- package/src/__tests__/applyRenderStyle.test.ts +3 -3
- package/src/__tests__/asciiDiagramBattle.test.ts +246 -0
- package/src/__tests__/asciiDiagramDetect.test.ts +162 -0
- package/src/__tests__/asciiDiagramMapping.test.ts +38 -0
- package/src/__tests__/asciiDiagramParse.test.ts +233 -0
- package/src/__tests__/asciiDiagramPipeline.test.ts +273 -0
- package/src/__tests__/asciiDiagramRender.test.ts +162 -0
- package/src/__tests__/asciiDiagramRepair.test.ts +84 -0
- package/src/__tests__/asciiTimelineDetect.test.ts +157 -0
- package/src/__tests__/asciiTimelineParse.test.ts +205 -0
- package/src/__tests__/asciiTimelinePipeline.test.ts +349 -0
- package/src/__tests__/asciiTimelineRender.test.ts +376 -0
- package/src/__tests__/attrTokens.test.ts +5 -0
- package/src/__tests__/contentContainer.test.ts +43 -0
- package/src/__tests__/customTemplatesFrontmatter.test.ts +0 -15
- package/src/__tests__/customThemesFrontmatter.test.ts +1 -0
- package/src/__tests__/dataTable.test.ts +25 -15
- package/src/__tests__/diagramBlock.test.ts +3 -3
- package/src/__tests__/diagramText.test.ts +26 -0
- package/src/__tests__/docToMarkdownMedia.test.ts +83 -0
- package/src/__tests__/drawingBlock.test.ts +3 -3
- package/src/__tests__/fixtures/asciiDiagramBattle.ts +512 -0
- package/src/__tests__/fixtures/asciiDiagrams.ts +287 -0
- package/src/__tests__/fixtures/asciiTimelines.ts +35 -0
- package/src/__tests__/fixtures/treeviewFixtures.ts +243 -0
- package/src/__tests__/getLayers.test.ts +32 -18
- package/src/__tests__/getLayersFallback.test.ts +8 -8
- package/src/__tests__/imageEditVersions.test.ts +2 -0
- package/src/__tests__/jsonForm.pointer.test.ts +47 -1
- package/src/__tests__/layoutBlock.test.ts +3 -3
- package/src/__tests__/majorApiTypes.test.ts +18 -0
- package/src/__tests__/markdown.test.ts +54 -4
- package/src/__tests__/markdownSanitize.test.ts +7 -5
- package/src/__tests__/matchFontFamily.test.ts +114 -0
- package/src/__tests__/materializeBlockLayers.test.ts +135 -0
- package/src/__tests__/materializeTestUtils.ts +17 -0
- package/src/__tests__/narrationAlign.test.ts +150 -0
- package/src/__tests__/narrationFeatures.test.ts +71 -0
- package/src/__tests__/narrationNuclei.test.ts +45 -0
- package/src/__tests__/narrationPacing.test.ts +189 -0
- package/src/__tests__/narrationScript.test.ts +149 -0
- package/src/__tests__/narrationSessionRepro.test.ts +62 -0
- package/src/__tests__/narrationSidecar.test.ts +88 -0
- package/src/__tests__/narrationSyllables.test.ts +65 -0
- package/src/__tests__/narrationTestSignals.ts +167 -0
- package/src/__tests__/narrationVad.test.ts +66 -0
- package/src/__tests__/resolveDocTheme.test.ts +16 -2
- package/src/__tests__/rootExports.test.ts +18 -0
- package/src/__tests__/scopedContentContainer.test.ts +20 -0
- package/src/__tests__/shapeGeometry.test.ts +12 -0
- package/src/__tests__/templateAnnotationParse.test.ts +10 -0
- package/src/__tests__/templateInputs.test.ts +69 -0
- package/src/__tests__/templateMetadata.test.ts +2 -1
- package/src/__tests__/templates.test.ts +143 -17
- package/src/__tests__/themeCompile.test.ts +49 -22
- package/src/__tests__/transformProvenance.test.ts +160 -0
- package/src/__tests__/transformV2.test.ts +40 -14
- package/src/__tests__/treeviewBattle.test.ts +76 -0
- package/src/__tests__/treeviewDetect.test.ts +168 -0
- package/src/__tests__/treeviewParse.test.ts +118 -0
- package/src/__tests__/treeviewPipeline.test.ts +183 -0
- package/src/__tests__/treeviewRender.test.ts +91 -0
- package/src/__tests__/versions.test.ts +44 -0
- package/src/doc/applyNarrationTiming.ts +244 -0
- package/src/doc/asciiDiagram/chars.ts +210 -0
- package/src/doc/asciiDiagram/detect.ts +175 -0
- package/src/doc/asciiDiagram/index.ts +38 -0
- package/src/doc/asciiDiagram/mapping.ts +225 -0
- package/src/doc/asciiDiagram/parse.ts +1095 -0
- package/src/doc/asciiDiagram/render.ts +963 -0
- package/src/doc/asciiDiagram/repair.ts +400 -0
- package/src/doc/asciiDiagram/types.ts +65 -0
- package/src/doc/asciiTimeline/detect.ts +138 -0
- package/src/doc/asciiTimeline/index.ts +26 -0
- package/src/doc/asciiTimeline/mapping.ts +43 -0
- package/src/doc/asciiTimeline/parse.ts +870 -0
- package/src/doc/asciiTimeline/render.ts +427 -0
- package/src/doc/asciiTimeline/types.ts +73 -0
- package/src/doc/asciiTimeline/wrappedFlow.ts +427 -0
- package/src/doc/audioMapping.ts +60 -46
- package/src/doc/customTemplatesFrontmatter.ts +0 -41
- package/src/doc/docToMarkdown.ts +70 -2
- package/src/doc/index.ts +76 -4
- package/src/doc/markdownToDoc.ts +138 -2
- package/src/doc/materializeBlockLayers.ts +304 -0
- package/src/doc/mediaAnnotations.ts +20 -0
- package/src/doc/resolveDocTheme.ts +8 -7
- package/src/doc/templateInputs.ts +185 -2
- package/src/doc/templates/__tests__/customTemplateRegistry.test.ts +22 -8
- package/src/doc/templates/__tests__/listBlock.test.ts +64 -0
- package/src/doc/templates/diagramBlock.ts +237 -38
- package/src/doc/templates/fallbackBlock.ts +1 -1
- package/src/doc/templates/index.ts +134 -279
- package/src/doc/templates/inputDescriptors.ts +20 -1
- package/src/doc/templates/listBlock.ts +88 -30
- package/src/doc/templates/metadata.ts +10 -0
- package/src/doc/templates/persistentLayers.ts +12 -126
- package/src/doc/templates/registry.ts +88 -0
- package/src/doc/templates/templateNames.ts +22 -0
- package/src/doc/templates/timelineBlock.ts +613 -0
- package/src/doc/templates/treeBlock.ts +131 -0
- package/src/doc/treeview/chars.ts +72 -0
- package/src/doc/treeview/detect.ts +145 -0
- package/src/doc/treeview/index.ts +30 -0
- package/src/doc/treeview/mapping.ts +95 -0
- package/src/doc/treeview/parse.ts +201 -0
- package/src/doc/treeview/render.ts +41 -0
- package/src/doc/treeview/types.ts +43 -0
- package/src/doc/utils/applyRenderStyle.ts +2 -9
- package/src/doc/utils/diagramText.ts +78 -0
- package/src/doc/utils/shapeGeometry.ts +67 -5
- package/src/doc/validate.ts +1 -1
- package/src/generate/templateMapper.ts +7 -0
- package/src/imageEdit/export.ts +6 -5
- package/src/imageEdit/versionPaths.ts +13 -26
- package/src/imageEdit/versions.ts +21 -100
- package/src/index.ts +1 -0
- package/src/internal/immutable.ts +58 -0
- package/src/jsonForm/index.ts +9 -1
- package/src/jsonForm/pointer.ts +68 -23
- package/src/markdown/attrTokens.ts +7 -5
- package/src/markdown/index.ts +1 -0
- package/src/markdown/stringify.ts +4 -9
- package/src/markdown/utils.ts +36 -14
- package/src/narration/align.ts +514 -0
- package/src/narration/features.ts +231 -0
- package/src/narration/index.ts +86 -0
- package/src/narration/nuclei.ts +118 -0
- package/src/narration/pacing.ts +211 -0
- package/src/narration/script.ts +239 -0
- package/src/narration/session.ts +100 -0
- package/src/narration/sidecar.ts +187 -0
- package/src/narration/syllables.ts +85 -0
- package/src/narration/trace.ts +50 -0
- package/src/narration/types.ts +299 -0
- package/src/narration/vad.ts +131 -0
- package/src/recommend/numberHighlight.ts +25 -0
- package/src/recommend/templates.ts +108 -12
- package/src/schemas/BlockTemplates.ts +156 -7
- package/src/schemas/Doc.ts +72 -9
- package/src/schemas/Media.ts +12 -2
- package/src/schemas/Theme.ts +45 -25
- package/src/schemas/Viewport.ts +2 -2
- package/src/schemas/fontStacks.ts +79 -0
- package/src/schemas/themeCompile.ts +15 -0
- package/src/schemas/themeConstants.ts +2 -0
- package/src/schemas/themeLibrary.ts +25 -19
- package/src/schemas/themeValidator.ts +1 -1
- package/src/schemas/themes/gezellig.json +1 -1
- package/src/spatial/Geohash.ts +0 -3
- package/src/storage/ContentContainer.ts +17 -9
- package/src/storage/ScopedContentContainer.ts +45 -15
- package/src/transform/applyTransform.ts +5 -5
- package/src/transform/index.ts +3 -1
- package/src/transform/registry.ts +169 -49
- package/src/transform/templateSelector.ts +21 -2
- package/src/transform/timingAllocator.ts +152 -21
- package/src/transform/types.ts +14 -1
- package/src/versions/gitignore.ts +34 -0
- package/src/versions/index.ts +2 -0
- package/src/versions/operations.ts +18 -104
- package/src/versions/paths.ts +13 -28
- package/src/versions/snapshotStore.ts +202 -0
- package/src/versions/types.ts +3 -1
- package/dist/chunk-5TYS5V3G.js.map +0 -1
- package/dist/chunk-A4O7GIWE.js.map +0 -1
- package/dist/chunk-BEQODJWV.js.map +0 -1
- package/dist/chunk-DLXZMS5K.js.map +0 -1
- package/dist/chunk-GPLTCSXO.js.map +0 -1
- package/dist/chunk-HWVFJAAH.js.map +0 -1
- package/dist/chunk-IMSCRLLV.js.map +0 -1
- package/dist/chunk-JELIRVDP.js +0 -24
- package/dist/chunk-JELIRVDP.js.map +0 -1
- package/dist/chunk-KKNUBQ6Y.js.map +0 -1
- package/dist/chunk-LDQ2HJIX.js.map +0 -1
- package/dist/chunk-LTN6I7QW.js.map +0 -1
- package/dist/chunk-P3K7NLHF.js.map +0 -1
- package/dist/chunk-T5UK6YOB.js.map +0 -1
- package/dist/chunk-UY7KGQ5R.js +0 -192
- package/dist/chunk-UY7KGQ5R.js.map +0 -1
- package/dist/chunk-VLJJHDAC.js +0 -218
- package/dist/chunk-VLJJHDAC.js.map +0 -1
- package/dist/chunk-VWUFZ6ZG.js.map +0 -1
- package/dist/story/index.d.ts +0 -1801
- package/dist/story/index.js +0 -279
- package/src/doc/getLayers.ts +0 -195
- /package/dist/{story → narration}/index.js.map +0 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { parseMarkdown } from '../markdown/parse';
|
|
3
|
+
import { markdownToDoc, flattenRenderableBlocks } from '../doc/markdownToDoc';
|
|
4
|
+
import { applyNarrationTiming } from '../doc/applyNarrationTiming';
|
|
5
|
+
import { resolveAudioMapping } from '../doc/audioMapping';
|
|
6
|
+
import { buildNarrationScript } from '../narration/script';
|
|
7
|
+
import type { NarrationTimingJsonV3 } from '../narration/sidecar';
|
|
8
|
+
import { MemoryContentContainer } from '../storage/ContentContainer';
|
|
9
|
+
import type { Doc } from '../schemas/Doc';
|
|
10
|
+
|
|
11
|
+
const MD = `{[audio src=audio/take.webm anchor=document]}
|
|
12
|
+
|
|
13
|
+
# Intro
|
|
14
|
+
|
|
15
|
+
Alpha beta gamma delta epsilon words for the intro block.
|
|
16
|
+
|
|
17
|
+
# Middle
|
|
18
|
+
|
|
19
|
+
Zeta eta theta iota kappa words for the middle block.
|
|
20
|
+
|
|
21
|
+
# Ending
|
|
22
|
+
|
|
23
|
+
Lambda mu nu xi omicron words for the ending block.
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
function makeDoc(markdown = MD): Doc {
|
|
27
|
+
return markdownToDoc(parseMarkdown(markdown));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A v3 sidecar whose block ranges use the doc's real block ids. */
|
|
31
|
+
function makeSidecar(doc: Doc, overrides?: Partial<NarrationTimingJsonV3>): NarrationTimingJsonV3 {
|
|
32
|
+
const script = buildNarrationScript(doc);
|
|
33
|
+
const bounds = [0, 10, 22, 30];
|
|
34
|
+
return {
|
|
35
|
+
version: 3,
|
|
36
|
+
sourceText: script.sourceText,
|
|
37
|
+
duration: 30,
|
|
38
|
+
bookmarks: [],
|
|
39
|
+
blocks: script.blocks.map((range, i) => ({
|
|
40
|
+
blockId: range.blockId,
|
|
41
|
+
...(range.heading !== undefined ? { heading: range.heading } : {}),
|
|
42
|
+
blockIndex: i,
|
|
43
|
+
charStart: range.charStart,
|
|
44
|
+
charEnd: range.charEnd,
|
|
45
|
+
startSec: bounds[i],
|
|
46
|
+
endSec: bounds[i + 1],
|
|
47
|
+
})),
|
|
48
|
+
...overrides,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function containerWith(sidecar: NarrationTimingJsonV3, path = 'audio/take.webm') {
|
|
53
|
+
const container = new MemoryContentContainer();
|
|
54
|
+
await container.writeFile(path, new Uint8Array([1, 2, 3]), 'audio/webm');
|
|
55
|
+
await container.writeFile(
|
|
56
|
+
`${path}.timing.json`,
|
|
57
|
+
new TextEncoder().encode(JSON.stringify(sidecar)),
|
|
58
|
+
'application/json',
|
|
59
|
+
);
|
|
60
|
+
return container;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
describe('applyNarrationTiming', () => {
|
|
64
|
+
it('re-times blocks from v3 sidecar ranges and owns doc.duration', async () => {
|
|
65
|
+
const doc = makeDoc();
|
|
66
|
+
const container = await containerWith(makeSidecar(doc));
|
|
67
|
+
const result = await applyNarrationTiming(doc, container);
|
|
68
|
+
|
|
69
|
+
expect(result.applied).toBe(true);
|
|
70
|
+
expect(result.clipSrc).toBe('audio/take.webm');
|
|
71
|
+
const flat = flattenRenderableBlocks(result.doc.blocks);
|
|
72
|
+
expect(flat[0].startTime).toBe(0);
|
|
73
|
+
expect(flat[0].duration).toBe(10);
|
|
74
|
+
expect(flat[1].startTime).toBe(10);
|
|
75
|
+
expect(flat[1].duration).toBe(12);
|
|
76
|
+
expect(flat[2].startTime).toBe(22);
|
|
77
|
+
expect(flat[2].duration).toBe(8);
|
|
78
|
+
expect(result.doc.duration).toBe(30);
|
|
79
|
+
// Input doc untouched.
|
|
80
|
+
expect(doc.blocks[0].startTime).not.toBe(10);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('returns the doc unchanged when no narration clip or sidecar exists', async () => {
|
|
84
|
+
const doc = makeDoc('# Just\n\nSome text.\n');
|
|
85
|
+
const container = new MemoryContentContainer();
|
|
86
|
+
const result = await applyNarrationTiming(doc, container);
|
|
87
|
+
expect(result.applied).toBe(false);
|
|
88
|
+
expect(result.doc).toBe(doc);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('honors author pins and records an info diagnostic on real conflict', async () => {
|
|
92
|
+
const pinned = makeDoc(MD.replace('# Middle', '# Middle {duration=3}'));
|
|
93
|
+
const container = await containerWith(makeSidecar(pinned));
|
|
94
|
+
const result = await applyNarrationTiming(pinned, container);
|
|
95
|
+
|
|
96
|
+
expect(result.applied).toBe(true);
|
|
97
|
+
const flat = flattenRenderableBlocks(result.doc.blocks);
|
|
98
|
+
// Pin wins (narration said 12s, pin says 3s).
|
|
99
|
+
expect(flat[1].duration).toBe(3);
|
|
100
|
+
const conflict = result.doc.diagnostics?.find((d) => d.code === 'narration-pin-conflict');
|
|
101
|
+
expect(conflict).toBeTruthy();
|
|
102
|
+
expect(conflict!.severity).toBe('info');
|
|
103
|
+
expect(conflict!.blockId).toBe(flat[1].id);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('matches a renamed heading through text similarity', async () => {
|
|
107
|
+
const original = makeDoc();
|
|
108
|
+
const sidecar = makeSidecar(original);
|
|
109
|
+
// Author renames the middle heading after recording: id + heading drift,
|
|
110
|
+
// but the body text still matches.
|
|
111
|
+
const edited = makeDoc(MD.replace('# Middle', '# Renamed Midsection'));
|
|
112
|
+
const container = await containerWith(sidecar);
|
|
113
|
+
const result = await applyNarrationTiming(edited, container);
|
|
114
|
+
|
|
115
|
+
expect(result.applied).toBe(true);
|
|
116
|
+
const flat = flattenRenderableBlocks(result.doc.blocks);
|
|
117
|
+
expect(flat[1].startTime).toBe(10);
|
|
118
|
+
expect(flat[1].duration).toBe(12);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('falls back to proportional timing for v1 sidecars narrating this doc', async () => {
|
|
122
|
+
const doc = makeDoc();
|
|
123
|
+
const script = buildNarrationScript(doc);
|
|
124
|
+
const container = await containerWith({
|
|
125
|
+
version: 3,
|
|
126
|
+
sourceText: script.sourceText,
|
|
127
|
+
duration: 30,
|
|
128
|
+
bookmarks: [],
|
|
129
|
+
blocks: [],
|
|
130
|
+
});
|
|
131
|
+
const result = await applyNarrationTiming(doc, container);
|
|
132
|
+
|
|
133
|
+
expect(result.applied).toBe(true);
|
|
134
|
+
const flat = flattenRenderableBlocks(result.doc.blocks);
|
|
135
|
+
expect(flat[0].startTime).toBe(0);
|
|
136
|
+
expect(flat[1].startTime).toBeGreaterThan(0);
|
|
137
|
+
expect(flat[2].startTime).toBeGreaterThan(flat[1].startTime);
|
|
138
|
+
const last = flat[flat.length - 1];
|
|
139
|
+
expect(last.startTime + last.duration).toBeCloseTo(30, 5);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('does not apply a v1 sidecar from an unrelated take', async () => {
|
|
143
|
+
const doc = makeDoc();
|
|
144
|
+
const container = await containerWith({
|
|
145
|
+
version: 3,
|
|
146
|
+
sourceText: 'completely different narration about sailboats and harbors and tides',
|
|
147
|
+
duration: 30,
|
|
148
|
+
bookmarks: [],
|
|
149
|
+
blocks: [],
|
|
150
|
+
});
|
|
151
|
+
const result = await applyNarrationTiming(doc, container);
|
|
152
|
+
expect(result.applied).toBe(false);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('resolveAudioMapping with a narration take', () => {
|
|
157
|
+
it('applies narration timing and never double-maps the take into segments', async () => {
|
|
158
|
+
const doc = makeDoc();
|
|
159
|
+
const container = await containerWith(makeSidecar(doc));
|
|
160
|
+
const resolved = await resolveAudioMapping(doc, container);
|
|
161
|
+
|
|
162
|
+
const flat = flattenRenderableBlocks(resolved.blocks);
|
|
163
|
+
expect(flat[1].startTime).toBe(10);
|
|
164
|
+
expect(resolved.duration).toBe(30);
|
|
165
|
+
// The take plays through the media schedule (documentMedia), so it must
|
|
166
|
+
// NOT also appear as an audio segment — that would play it twice.
|
|
167
|
+
expect(resolved.audio.segments.some((s) => s.src === 'audio/take.webm')).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('keeps classic per-block segment mapping for docs without narration', async () => {
|
|
171
|
+
const doc = makeDoc('# Intro\n\nAlpha beta gamma delta epsilon words for the intro block.\n');
|
|
172
|
+
const container = new MemoryContentContainer();
|
|
173
|
+
await container.writeFile('audio/clip.mp3', new Uint8Array([9]), 'audio/mpeg');
|
|
174
|
+
await container.writeFile(
|
|
175
|
+
'audio/clip.mp3.timing.json',
|
|
176
|
+
new TextEncoder().encode(
|
|
177
|
+
JSON.stringify({
|
|
178
|
+
sourceText: 'Alpha beta gamma delta epsilon words for the intro block.',
|
|
179
|
+
duration: 7,
|
|
180
|
+
bookmarks: [],
|
|
181
|
+
}),
|
|
182
|
+
),
|
|
183
|
+
'application/json',
|
|
184
|
+
);
|
|
185
|
+
const resolved = await resolveAudioMapping(doc, container);
|
|
186
|
+
expect(resolved.audio.segments.length).toBe(1);
|
|
187
|
+
expect(resolved.audio.segments[0].src).toBe('audio/clip.mp3');
|
|
188
|
+
expect(resolved.duration).toBe(7);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
@@ -73,13 +73,13 @@ describe('applyRenderStyleToLayers', () => {
|
|
|
73
73
|
expect(c[0].animation?.type).toBe('slowZoom');
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
it(
|
|
76
|
+
it('does not let a default entrance animation override ambientMotion=false', () => {
|
|
77
77
|
const out = applyRenderStyleToLayers(
|
|
78
78
|
[fullBleedImage()],
|
|
79
79
|
BLOCK,
|
|
80
|
-
themeWith({ defaultImageAnimation: 'slowZoom' }),
|
|
80
|
+
themeWith({ ambientMotion: false, defaultImageAnimation: 'slowZoom' }),
|
|
81
81
|
);
|
|
82
|
-
expect(out[0].animation
|
|
82
|
+
expect(out[0].animation).toBeUndefined();
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
it('never overrides an authored animation, including type none', () => {
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
detectAsciiDiagram,
|
|
4
|
+
parseAsciiDiagram,
|
|
5
|
+
renderAsciiDiagram,
|
|
6
|
+
type AsciiDiagram,
|
|
7
|
+
} from '../doc/asciiDiagram/index.js';
|
|
8
|
+
import { BATTLE_DIAGRAMS, type BattleDiagram } from './fixtures/asciiDiagramBattle.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Battle test: a broad corpus of AI-style ASCII diagrams (linear flows,
|
|
12
|
+
* fan-out/in, DAGs, cycles, many-to-many, containers, labeled edges,
|
|
13
|
+
* styles) driven through the codec end-to-end. Each fixture asserts:
|
|
14
|
+
*
|
|
15
|
+
* 1. Detection — the art is recognized as a diagram.
|
|
16
|
+
* 2. Parse accuracy — it parses to EXACTLY the intended nodes / edges /
|
|
17
|
+
* containment (the "we read what the AI drew" guarantee).
|
|
18
|
+
* 3. Semantic fixpoint — render→parse preserves that semantic (editing
|
|
19
|
+
* the canvas never silently drops a node or edge).
|
|
20
|
+
* 4. Byte idempotence — render→parse→render is byte-stable across cycles
|
|
21
|
+
* (no jitter, no drift).
|
|
22
|
+
*
|
|
23
|
+
* Followed by a focused many-to-many section and honest graceful-
|
|
24
|
+
* degradation / known-limitation coverage.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
interface Semantic {
|
|
28
|
+
nodes: string[];
|
|
29
|
+
edges: string[];
|
|
30
|
+
}
|
|
31
|
+
function semantic(d: AsciiDiagram): Semantic {
|
|
32
|
+
return {
|
|
33
|
+
nodes: d.nodes.map((n) => `${n.id}${n.containerId ? `<${n.containerId}` : ''}`).sort(),
|
|
34
|
+
edges: d.edges.map((e) => `${e.source}|${e.target}|${e.directed}|${e.label ?? ''}`).sort(),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function expectedEdgeStrings(fx: BattleDiagram): string[] {
|
|
38
|
+
return fx.edges
|
|
39
|
+
.map(
|
|
40
|
+
([s, t, label, directed]) => `${s}|${t}|${directed === false ? false : true}|${label ?? ''}`,
|
|
41
|
+
)
|
|
42
|
+
.sort();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('battle test — every fixture round-trips', () => {
|
|
46
|
+
for (const fx of BATTLE_DIAGRAMS) {
|
|
47
|
+
describe(`${fx.category}: ${fx.name}`, () => {
|
|
48
|
+
const d = parseAsciiDiagram(fx.art);
|
|
49
|
+
|
|
50
|
+
it('detects as a diagram', () => {
|
|
51
|
+
expect(detectAsciiDiagram(fx.art).isDiagram).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('parses the intended nodes', () => {
|
|
55
|
+
expect(d.nodes.map((n) => n.id).sort()).toEqual([...fx.nodes].sort());
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('parses the intended edges (source, target, direction, label)', () => {
|
|
59
|
+
const got = d.edges
|
|
60
|
+
.map((e) => `${e.source}|${e.target}|${e.directed}|${e.label ?? ''}`)
|
|
61
|
+
.sort();
|
|
62
|
+
expect(got).toEqual(expectedEdgeStrings(fx));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('parses the intended containment', () => {
|
|
66
|
+
const got: Record<string, string> = {};
|
|
67
|
+
for (const n of d.nodes) if (n.containerId) got[n.id] = n.containerId;
|
|
68
|
+
expect(got).toEqual(fx.containers ?? {});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('render→parse preserves the semantic (fixpoint)', () => {
|
|
72
|
+
const reparsed = parseAsciiDiagram(renderAsciiDiagram(d));
|
|
73
|
+
expect(semantic(reparsed)).toEqual(semantic(d));
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('render→parse→render is byte-stable across three cycles', () => {
|
|
77
|
+
const t1 = renderAsciiDiagram(d);
|
|
78
|
+
const t2 = renderAsciiDiagram(parseAsciiDiagram(t1));
|
|
79
|
+
const t3 = renderAsciiDiagram(parseAsciiDiagram(t2));
|
|
80
|
+
expect(t2).toBe(t1);
|
|
81
|
+
expect(t3).toBe(t1);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('battle test — coverage sanity', () => {
|
|
88
|
+
it('covers every intended category', () => {
|
|
89
|
+
const categories = new Set(BATTLE_DIAGRAMS.map((f) => f.category));
|
|
90
|
+
for (const c of [
|
|
91
|
+
'linear',
|
|
92
|
+
'fan-out',
|
|
93
|
+
'fan-in',
|
|
94
|
+
'dag',
|
|
95
|
+
'cycle',
|
|
96
|
+
'many-to-many',
|
|
97
|
+
'edges',
|
|
98
|
+
'labels',
|
|
99
|
+
'container',
|
|
100
|
+
'style',
|
|
101
|
+
]) {
|
|
102
|
+
expect(categories.has(c)).toBe(true);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('fixture names are unique', () => {
|
|
107
|
+
const names = BATTLE_DIAGRAMS.map((f) => f.name);
|
|
108
|
+
expect(new Set(names).size).toBe(names.length);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('battle test — many-to-many relationships', () => {
|
|
113
|
+
it('recovers every edge of a full 3-node mesh (6 directed edges)', () => {
|
|
114
|
+
const fx = BATTLE_DIAGRAMS.find((f) => f.name === 'fullMesh3')!;
|
|
115
|
+
const d = parseAsciiDiagram(fx.art);
|
|
116
|
+
expect(d.edges).toHaveLength(6);
|
|
117
|
+
const pairs = new Set(d.edges.map((e) => `${e.source}->${e.target}`));
|
|
118
|
+
for (const a of ['alpha', 'beta', 'gamma']) {
|
|
119
|
+
for (const b of ['alpha', 'beta', 'gamma']) {
|
|
120
|
+
if (a !== b) expect(pairs.has(`${a}->${b}`)).toBe(true);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('recovers a fan-out hub connecting to all of its targets', () => {
|
|
126
|
+
const fx = BATTLE_DIAGRAMS.find((f) => f.name === 'loadBalancerFanout')!;
|
|
127
|
+
const d = parseAsciiDiagram(fx.art);
|
|
128
|
+
const targets = d.edges
|
|
129
|
+
.filter((e) => e.source === 'load-balancer')
|
|
130
|
+
.map((e) => e.target)
|
|
131
|
+
.sort();
|
|
132
|
+
expect(targets).toEqual(['web1', 'web2', 'web3', 'web4']);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('recovers a fan-in hub reached by all of its sources', () => {
|
|
136
|
+
const fx = BATTLE_DIAGRAMS.find((f) => f.name === 'collectorFanin')!;
|
|
137
|
+
const d = parseAsciiDiagram(fx.art);
|
|
138
|
+
const sources = d.edges
|
|
139
|
+
.filter((e) => e.target === 'collector')
|
|
140
|
+
.map((e) => e.source)
|
|
141
|
+
.sort();
|
|
142
|
+
expect(sources).toEqual(['s1', 's2', 's3']);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('recovers a diamond (two disjoint paths reconverging)', () => {
|
|
146
|
+
const fx = BATTLE_DIAGRAMS.find((f) => f.name === 'diamond')!;
|
|
147
|
+
const d = parseAsciiDiagram(fx.art);
|
|
148
|
+
const edges = new Set(d.edges.map((e) => `${e.source}->${e.target}`));
|
|
149
|
+
expect(edges).toEqual(new Set(['a->b', 'a->c', 'b->d', 'c->d']));
|
|
150
|
+
// Byte-stable, so an edit never collapses one of the two paths.
|
|
151
|
+
expect(renderAsciiDiagram(parseAsciiDiagram(renderAsciiDiagram(d)))).toBe(
|
|
152
|
+
renderAsciiDiagram(d),
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('preserves a bidirectional pair as two directed edges', () => {
|
|
157
|
+
const fx = BATTLE_DIAGRAMS.find((f) => f.name === 'bidirReplication')!;
|
|
158
|
+
const d = parseAsciiDiagram(fx.art);
|
|
159
|
+
expect(d.edges).toHaveLength(2);
|
|
160
|
+
expect(new Set(d.edges.map((e) => `${e.source}->${e.target}`))).toEqual(
|
|
161
|
+
new Set(['primary->replica', 'replica->primary']),
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('battle test — graceful degradation of the hard cases', () => {
|
|
167
|
+
// Dense bipartite crossing meshes are inherently ambiguous in ASCII (two
|
|
168
|
+
// lines that cross in a tight channel cannot be told from a merge). The
|
|
169
|
+
// parser must not crash or hallucinate — it returns *some* subset without
|
|
170
|
+
// throwing, and detection/rendering stay well-defined.
|
|
171
|
+
it('does not crash on a dense bipartite crossing mesh', () => {
|
|
172
|
+
const art = [
|
|
173
|
+
'┌────────┐ ┌────────┐',
|
|
174
|
+
'│ A │ │ B │',
|
|
175
|
+
'└─┬────┬─┘ └─┬────┬─┘',
|
|
176
|
+
' │ └──────┐ ┌───┘ │',
|
|
177
|
+
' │ │ │ │',
|
|
178
|
+
' ▼ ▼ ▼ ▼',
|
|
179
|
+
'┌────────┐ ┌────────┐',
|
|
180
|
+
'│ X │ │ Y │',
|
|
181
|
+
'└────────┘ └────────┘',
|
|
182
|
+
].join('\n');
|
|
183
|
+
const d = parseAsciiDiagram(art);
|
|
184
|
+
expect(d.nodes.map((n) => n.id).sort()).toEqual(['a', 'b', 'x', 'y']);
|
|
185
|
+
// Render never throws and stays byte-idempotent even if edges are lossy.
|
|
186
|
+
const r1 = renderAsciiDiagram(d);
|
|
187
|
+
expect(renderAsciiDiagram(parseAsciiDiagram(r1))).toBe(r1);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// Boxes whose top and bottom borders are different widths (a very common
|
|
191
|
+
// AI misalignment) don't trace as boxes — the fence stays plain code
|
|
192
|
+
// (safe failure) rather than producing a garbled diagram.
|
|
193
|
+
it('rejects a misaligned container as a non-diagram (stays code)', () => {
|
|
194
|
+
const art = [
|
|
195
|
+
'┌───────────────── Cluster ─────────────────┐',
|
|
196
|
+
'│ ┌─────────┐ ┌─────────┐ │',
|
|
197
|
+
'│ │ Pod A │ │ Pod B │ │',
|
|
198
|
+
'│ └─────────┘ └─────────┘ │',
|
|
199
|
+
'└────────────────────────────────────────────┘',
|
|
200
|
+
].join('\n');
|
|
201
|
+
const detection = detectAsciiDiagram(art);
|
|
202
|
+
// The outer misaligned box is dropped; whatever remains is not a
|
|
203
|
+
// confident diagram, so it degrades to a plain code block.
|
|
204
|
+
expect(detection.reasons.length).toBeGreaterThan(0);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('never throws on garbage, empty, or non-diagram fences', () => {
|
|
208
|
+
for (const junk of ['', ' ', 'hello world', '┌──\n│ x', '|||\n---\n|||', 'a | b | c']) {
|
|
209
|
+
expect(() => parseAsciiDiagram(junk)).not.toThrow();
|
|
210
|
+
expect(() => renderAsciiDiagram(parseAsciiDiagram(junk))).not.toThrow();
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe('battle test — known limitation: labels on tight splits / cross-box feedback', () => {
|
|
216
|
+
// The PARSER reads per-branch labels on a shared bus correctly; the
|
|
217
|
+
// RENDERER can only host one label per tight two-way split, so a
|
|
218
|
+
// re-render may normalize one away. Documented so the behavior is a
|
|
219
|
+
// conscious contract, not a silent surprise. (Parse accuracy holds; only
|
|
220
|
+
// re-render label placement is lossy.)
|
|
221
|
+
it('parses both labels of a two-way split, even if re-render keeps one', () => {
|
|
222
|
+
const art = [
|
|
223
|
+
' ┌───────────┐',
|
|
224
|
+
' │ Check? │',
|
|
225
|
+
' └──┬─────┬──┘',
|
|
226
|
+
' yes │ │ no',
|
|
227
|
+
' ▼ ▼',
|
|
228
|
+
' ┌────────┐ ┌────────┐',
|
|
229
|
+
' │ Accept │ │ Reject │',
|
|
230
|
+
' └────────┘ └────────┘',
|
|
231
|
+
].join('\n');
|
|
232
|
+
const d = parseAsciiDiagram(art);
|
|
233
|
+
const labels = d.edges
|
|
234
|
+
.map((e) => e.label)
|
|
235
|
+
.filter(Boolean)
|
|
236
|
+
.sort();
|
|
237
|
+
expect(labels).toEqual(['no', 'yes']);
|
|
238
|
+
// The edges themselves are always preserved; only label placement is
|
|
239
|
+
// best-effort on the tight-split re-render.
|
|
240
|
+
const reparsed = parseAsciiDiagram(renderAsciiDiagram(d));
|
|
241
|
+
expect(reparsed.edges.map((e) => `${e.source}->${e.target}`).sort()).toEqual([
|
|
242
|
+
'check->accept',
|
|
243
|
+
'check->reject',
|
|
244
|
+
]);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
detectAsciiDiagram,
|
|
4
|
+
isAsciiDiagramFence,
|
|
5
|
+
isEligibleAsciiFenceLang,
|
|
6
|
+
isExplicitDiagramLang,
|
|
7
|
+
} from '../doc/asciiDiagram/index.js';
|
|
8
|
+
import type { MarkdownCodeBlock } from '../markdown/types.js';
|
|
9
|
+
import { NEGATIVE_FIXTURES, POSITIVE_FIXTURES } from './fixtures/asciiDiagrams.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The negative corpus is the CONTRACT for detection tuning: every entry
|
|
13
|
+
* must stay rejected. False positives hide real code behind a diagram
|
|
14
|
+
* canvas; false negatives merely leave a code block alone.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const EXPECTED_REJECT_REASONS: Record<string, RegExp> = {
|
|
18
|
+
NEG_MARKDOWN_TABLE: /markdown-table|too-few-corner-candidates/,
|
|
19
|
+
NEG_PSQL_TABLE: /table-lattice/,
|
|
20
|
+
NEG_MYSQL_TABLE: /table-lattice/,
|
|
21
|
+
NEG_SHELL_PIPES: /too-few-corner-candidates|too-few-lines|too-few-boxes/,
|
|
22
|
+
NEG_TS_UNION: /too-few-corner-candidates|too-few-boxes/,
|
|
23
|
+
NEG_SQL_DDL: /too-few-corner-candidates|too-few-boxes/,
|
|
24
|
+
NEG_FILE_TREE: /too-few-corner-candidates|too-few-boxes/,
|
|
25
|
+
NEG_YAML: /too-few-corner-candidates|too-few-boxes/,
|
|
26
|
+
NEG_LOG_COLUMNS: /too-few-corner-candidates|too-few-boxes/,
|
|
27
|
+
NEG_PROSE_HEAVY: /loose-ratio/,
|
|
28
|
+
SINGLE_BOX: /too-few-boxes|too-few-corner-candidates/,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
describe('detectAsciiDiagram — negative corpus (must all reject)', () => {
|
|
32
|
+
for (const [name, fixture] of Object.entries(NEGATIVE_FIXTURES)) {
|
|
33
|
+
it(`rejects ${name}`, () => {
|
|
34
|
+
const detection = detectAsciiDiagram(fixture);
|
|
35
|
+
expect(detection.isDiagram).toBe(false);
|
|
36
|
+
const expected = EXPECTED_REJECT_REASONS[name];
|
|
37
|
+
expect(detection.reasons.join(' ')).toMatch(expected);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
it('rejects oversized fences without parsing', () => {
|
|
42
|
+
const huge = Array.from({ length: 500 }, () => '┌──┐').join('\n');
|
|
43
|
+
const detection = detectAsciiDiagram(huge);
|
|
44
|
+
expect(detection.isDiagram).toBe(false);
|
|
45
|
+
expect(detection.reasons.join(' ')).toMatch(/too-many-lines/);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('rejects tiny fragments', () => {
|
|
49
|
+
expect(detectAsciiDiagram('┌┐\n└┘').isDiagram).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('detectAsciiDiagram — positive fixtures (must all accept)', () => {
|
|
54
|
+
for (const [name, fixture] of Object.entries(POSITIVE_FIXTURES)) {
|
|
55
|
+
it(`accepts ${name}`, () => {
|
|
56
|
+
const detection = detectAsciiDiagram(fixture);
|
|
57
|
+
expect(detection.isDiagram).toBe(true);
|
|
58
|
+
expect(detection.diagram).toBeDefined();
|
|
59
|
+
expect(detection.diagram?.nodes.length).toBeGreaterThanOrEqual(2);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('garbled-label guard (over-broken art falls back to code)', () => {
|
|
65
|
+
// Hand-drawn boxes whose labels overflow their borders AND collide with a
|
|
66
|
+
// neighbour desync the columns row-to-row, so box-drawing chars leak into
|
|
67
|
+
// the extracted labels. That's an unrecoverable parse — detection must
|
|
68
|
+
// decline so the fence renders as a faithful code block, not a garbled
|
|
69
|
+
// canvas. (This is the shape of real "half-broken" architecture art.)
|
|
70
|
+
const COLLIDING = [
|
|
71
|
+
'┌────────┐ ┌────────┐',
|
|
72
|
+
'│ @scope/kernel │ │ @scope/client │',
|
|
73
|
+
'│ x │ │ y │',
|
|
74
|
+
'└────────┘ └────────┘',
|
|
75
|
+
'┌────────┐ ┌────────┐',
|
|
76
|
+
'│ @scope/materls │ │ @scope/schema │',
|
|
77
|
+
'│ z │ │ w │',
|
|
78
|
+
'└────────┘ └────────┘',
|
|
79
|
+
].join('\n');
|
|
80
|
+
|
|
81
|
+
it('rejects a diagram whose labels are structurally garbled', () => {
|
|
82
|
+
const d = detectAsciiDiagram(COLLIDING);
|
|
83
|
+
expect(d.isDiagram).toBe(false);
|
|
84
|
+
expect(d.reasons.join(' ')).toMatch(/garbled-labels/);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('rejects garbled art even when explicitly `diagram`-tagged', () => {
|
|
88
|
+
expect(detectAsciiDiagram(COLLIDING, { explicit: true }).isDiagram).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('does not flag a clean diagram (no box chars in labels)', () => {
|
|
92
|
+
// Sanity: clean labels never trip the guard.
|
|
93
|
+
expect(detectAsciiDiagram(POSITIVE_FIXTURES.TWO_BOX_VERTICAL).isDiagram).toBe(true);
|
|
94
|
+
expect(detectAsciiDiagram(POSITIVE_FIXTURES.NESTED_CONTAINER).isDiagram).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('explicit `diagram` tag (lenient detection)', () => {
|
|
99
|
+
const ONE_BOX = ['┌────────┐', '│ Solo │', '└────────┘'].join('\n');
|
|
100
|
+
|
|
101
|
+
it('isExplicitDiagramLang matches only the `diagram` tag', () => {
|
|
102
|
+
for (const lang of ['diagram', ' Diagram ', 'DIAGRAM'])
|
|
103
|
+
expect(isExplicitDiagramLang(lang)).toBe(true);
|
|
104
|
+
for (const lang of [undefined, null, '', 'text', 'ascii', 'tree', 'js'])
|
|
105
|
+
expect(isExplicitDiagramLang(lang)).toBe(false);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('a single-box diagram is rejected untagged but accepted when explicit', () => {
|
|
109
|
+
expect(detectAsciiDiagram(ONE_BOX).isDiagram).toBe(false);
|
|
110
|
+
const explicit = detectAsciiDiagram(ONE_BOX, { explicit: true });
|
|
111
|
+
expect(explicit.isDiagram).toBe(true);
|
|
112
|
+
expect(explicit.diagram?.nodes).toHaveLength(1);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('still rejects a markdown table even when explicitly tagged', () => {
|
|
116
|
+
expect(
|
|
117
|
+
detectAsciiDiagram(NEGATIVE_FIXTURES.NEG_MARKDOWN_TABLE, { explicit: true }).isDiagram,
|
|
118
|
+
).toBe(false);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('`diagram` is an eligible fence lang and isAsciiDiagramFence accepts a tagged single box', () => {
|
|
122
|
+
expect(isEligibleAsciiFenceLang('diagram')).toBe(true);
|
|
123
|
+
const fence: MarkdownCodeBlock = { type: 'code', lang: 'diagram', value: ONE_BOX };
|
|
124
|
+
expect(isAsciiDiagramFence(fence)).toBe(true);
|
|
125
|
+
// The same content in a bare fence is not auto-detected.
|
|
126
|
+
expect(isAsciiDiagramFence({ type: 'code', value: ONE_BOX })).toBe(false);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('fence language gate', () => {
|
|
131
|
+
it('allows no language, empty, and the inert allowlist', () => {
|
|
132
|
+
expect(isEligibleAsciiFenceLang(undefined)).toBe(true);
|
|
133
|
+
expect(isEligibleAsciiFenceLang(null)).toBe(true);
|
|
134
|
+
expect(isEligibleAsciiFenceLang('')).toBe(true);
|
|
135
|
+
expect(isEligibleAsciiFenceLang('text')).toBe(true);
|
|
136
|
+
expect(isEligibleAsciiFenceLang('TXT')).toBe(true);
|
|
137
|
+
expect(isEligibleAsciiFenceLang('plaintext')).toBe(true);
|
|
138
|
+
expect(isEligibleAsciiFenceLang('plain')).toBe(true);
|
|
139
|
+
expect(isEligibleAsciiFenceLang('ascii')).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('rejects real programming languages', () => {
|
|
143
|
+
for (const lang of ['js', 'ts', 'python', 'sql', 'mermaid', 'json', 'yaml', 'bash']) {
|
|
144
|
+
expect(isEligibleAsciiFenceLang(lang)).toBe(false);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('isAsciiDiagramFence combines the lang gate with content detection', () => {
|
|
149
|
+
const art = POSITIVE_FIXTURES.TWO_BOX_VERTICAL;
|
|
150
|
+
const fence = (lang?: string): MarkdownCodeBlock => ({
|
|
151
|
+
type: 'code',
|
|
152
|
+
...(lang !== undefined ? { lang } : {}),
|
|
153
|
+
value: art,
|
|
154
|
+
});
|
|
155
|
+
expect(isAsciiDiagramFence(fence())).toBe(true);
|
|
156
|
+
expect(isAsciiDiagramFence(fence('text'))).toBe(true);
|
|
157
|
+
expect(isAsciiDiagramFence(fence('js'))).toBe(false);
|
|
158
|
+
expect(isAsciiDiagramFence({ type: 'code', value: NEGATIVE_FIXTURES.NEG_PSQL_TABLE })).toBe(
|
|
159
|
+
false,
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { asciiDiagramToTemplateData, parseAsciiDiagram } from '../doc/asciiDiagram/index';
|
|
3
|
+
|
|
4
|
+
const LOAD_BALANCER_FAN_OUT = ` ┌───────────────┐
|
|
5
|
+
│ Load Balancer │
|
|
6
|
+
└──┬──┬──┬──┬───┘
|
|
7
|
+
┌──────┘ │ │ └──────┐
|
|
8
|
+
▼ ▼ ▼ ▼
|
|
9
|
+
┌──────┐┌──────┐┌──────┐┌──────┐
|
|
10
|
+
│ Web1 ││ Web2 ││ Web3 ││ Web4 │
|
|
11
|
+
└──────┘└──────┘└──────┘└──────┘`;
|
|
12
|
+
|
|
13
|
+
describe('ASCII diagram canvas mapping', () => {
|
|
14
|
+
it('maps fan-out arrows to distributed bottom ports and top-center targets', () => {
|
|
15
|
+
const diagram = parseAsciiDiagram(LOAD_BALANCER_FAN_OUT);
|
|
16
|
+
const { edges } = asciiDiagramToTemplateData(diagram);
|
|
17
|
+
|
|
18
|
+
expect(edges.map((edge) => edge.target)).toEqual(['web1', 'web2', 'web3', 'web4']);
|
|
19
|
+
expect(edges.map((edge) => edge.routing)).toEqual([
|
|
20
|
+
'orthogonal',
|
|
21
|
+
'orthogonal',
|
|
22
|
+
'orthogonal',
|
|
23
|
+
'orthogonal',
|
|
24
|
+
]);
|
|
25
|
+
expect(edges.map((edge) => edge.sourceAnchor)).toEqual([
|
|
26
|
+
{ side: 'bottom', offset: 0.2 },
|
|
27
|
+
{ side: 'bottom', offset: 0.4 },
|
|
28
|
+
{ side: 'bottom', offset: 0.6 },
|
|
29
|
+
{ side: 'bottom', offset: 0.8 },
|
|
30
|
+
]);
|
|
31
|
+
expect(edges.map((edge) => edge.targetAnchor)).toEqual([
|
|
32
|
+
{ side: 'top', offset: 0.5 },
|
|
33
|
+
{ side: 'top', offset: 0.5 },
|
|
34
|
+
{ side: 'top', offset: 0.5 },
|
|
35
|
+
{ side: 'top', offset: 0.5 },
|
|
36
|
+
]);
|
|
37
|
+
});
|
|
38
|
+
});
|