From 06a3305e5d24b102828dfefbdff9a3f4502dea35 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sun, 15 Nov 2026 19:47:53 +0100 Subject: [PATCH] Pin the replay's edge cases as fixed tests, delete its merge step that no drop reaches, file item 191 --- docs/decisions.md | 4 +++- src/markdown/portable/inline-reduction.test.ts | 13 +++++++++++++ src/markdown/portable/inline-reduction.ts | 14 +------------- todo.md | 7 ++++++- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/docs/decisions.md b/docs/decisions.md index 3bd0f98..6655a9f 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -1199,7 +1199,9 @@ outermost mark, the outermost mark of the leaf across the hard break, and whethe between. Three things keep it so, each found by the property test against the one-leaf-per-pass reference: a round judges all its leaves before it changes any, since a leaf goes by a neighbour that goes in the same pass; a round also judges the edge whitespace of a leaf holding text; and the -replay merges as `trimPass` does, since merged leaves reach an edge as one. The replay runs after a +replay reads the pass's line merged, as `trimPass` merges before it judges. No round merges again: +a leaf that goes has a hard break or a line edge beside it, so it brings no two leaves together. +The replay runs after a pass, never before the first: a pass also takes marks off whitespace by the line as it stands, and the first pass must see the line as it came. Measured in passes (§Cost fixes are measured, never timed): both of item 190's lines took 7, 101 and 1 001 passes at diff --git a/src/markdown/portable/inline-reduction.test.ts b/src/markdown/portable/inline-reduction.test.ts index 1de1da9..245b3c0 100644 --- a/src/markdown/portable/inline-reduction.test.ts +++ b/src/markdown/portable/inline-reduction.test.ts @@ -137,6 +137,19 @@ for (const [name, line] of blankLines) { }) } +const em: AdfMark = { type: 'em' } +const replayedLines: readonly [string, AdfNode[], AdfNode[]][] = [ + ['the lead whitespace a dropped blank leaves at the line start', [marked(' ', em), marked(' x')], [{ text: 'x', type: 'text' }]], + ['the trail whitespace dropped blanks leave before a hard break', [marked('x ', link), marked(' ', em, link), marked(' ', link), marked(' ', em, link), { type: 'hardBreak' }, marked('y', link)], [marked('x', link), { type: 'hardBreak' }, marked('y', link)]], + ['the lead whitespace dropped blanks leave after a hard break', [marked('y', link), { type: 'hardBreak' }, marked(' ', em, link), marked(' ', link), marked(' ', em, link), marked(' x', link)], [marked('y', link), { type: 'hardBreak' }, marked('x', link)]], + ['a blank beside a leaf holding no text', [marked(' ', em), { attrs: { id: 'a' }, type: 'mention' }], [{ attrs: { id: 'a' }, type: 'mention' }]], +] +for (const [name, line, trimmed] of replayedLines) { + test(`trims ${name} in 2 passes`, () => { + assert.deepEqual(trimmedWith(line, spannedPass), { line: trimmed, passes: 2 }) + }) +} + function alternatingBlanks(blanks: number, first: AdfNode, second: AdfNode): AdfNode[] { return Array.from({ length: blanks }, (_, index) => (index % 2 === 0 ? first : second)) } diff --git a/src/markdown/portable/inline-reduction.ts b/src/markdown/portable/inline-reduction.ts index 4c80ffb..b1c33ae 100644 --- a/src/markdown/portable/inline-reduction.ts +++ b/src/markdown/portable/inline-reduction.ts @@ -216,8 +216,7 @@ function withoutEdgeWhitespace(leaves: readonly AdfNode[], grouping: RunGrouping // Every leaf of a round is judged before any changes, as `trimPass` judges against one snapshot. const outcomes = [...judged].flatMap((position) => { const node = linked[position] - const leaf = node === undefined || node.dropped ? undefined : withoutLineEdges(node, linked, grouping) - return node === undefined || node.dropped || leaf === node.leaf ? [] : [{ leaf, node }] + return node === undefined || node.dropped ? [] : [{ leaf: withoutLineEdges(node, linked, grouping), node }] }) judged = new Set() for (const { leaf, node } of outcomes) { @@ -228,17 +227,6 @@ function withoutEdgeWhitespace(leaves: readonly AdfNode[], grouping: RunGrouping unlink(node, linked) judged.add(node.previous).add(node.next) } - // `trimPass` merges before it judges, so leaves a drop brings together reach an edge as one. - for (const position of judged) { - const node = linked[position] - if (node === undefined || node.dropped) continue - for (let next = linked[node.next]; next !== undefined && next.breakBefore === undefined; next = linked[node.next]) { - const [merged, unmerged] = mergeAdjacentText([node.leaf, next.leaf], joinsWhenEditorNormal) - if (merged === undefined || unmerged !== undefined) break - node.leaf = merged - unlink(next, linked) - } - } } const kept: AdfNode[] = [] let position = 0 diff --git a/todo.md b/todo.md index 9fd0bee..14291e6 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 0.1` -`Next ID = 191` +`Next ID = 192` ## Items @@ -19,6 +19,7 @@ | 107 | 0.4.0 | | decision | **Spell the block carry's JSON so its length stays linear in the node's JSON.** | 3 | 1 | 3 | 5 | 5 | | 0.0 | | 170 | 0.4.0 | | owner | **Bundle the packed tarball with webpack, esbuild, Rollup and Bun in the gate, failing on any bundler warning, and run each bundle's round-trip in Node.** | 3 | 1 | 1 | 3 | 5 | | 0.0 | | 42 | 0.5.0 | | defect | **Trim a text leaf's trailing blanks in linear time.** | 1 | 1 | 2 | 2 | 2 | 9 by 3 | 21.2 | +| 191 | 0.5.0 | | defect | **Make the edge trim and the reference of its property test agree on a line whose strong link run ends in blanks before two hard breaks.** | 2 | 1 | 2 | 3 | 2 | code health by 3 | 21.2 | | 31 | 0.5.0 | | | **Make the branch-coverage figure repeat across runs of an unchanged tree.** | 2 | 1 | 1 | 2 | 3 | code health by 3 | 15.9 | | 57 | 0.5.0 | | | **Make each `ci.sh` leg build what it reads, so one leg run alone tests the current tree.** | 2 | 1 | 1 | 2 | 3 | code health by 3 | 15.9 | | 38 | 0.5.0 | | defect | **Spell a lone surrogate in a text node so it survives a UTF-8 encode.** | 1 | 1 | 2 | 2 | 2 | 1 by 2 | 14.2 | @@ -109,6 +110,10 @@ Forge's runtime, which no leg tests. quadratic in a run of blanks inside one leaf: a paragraph of `a`, 80 000 spaces, `b` takes 6.5 s in `adfToPortableMarkdown`. Scan backward, as the expand title's trim does. +### 191. Make the edge trim and the reference of its property test agree on a line whose strong link run ends in blanks before two hard breaks. + +Found while shipping item 190, on `origin/main`'s trim as well as on that chunk's: fast-check seed 578490788, path `94554:1:8:16:15:15:16:16:16:16`, in `trims a spanned line as the reference counts trim it, in no more passes` (`src/markdown/portable/inline-reduction.test.ts`), about one random line in 100 000, so the gate's 3 000 runs on a fixed seed pass. The line, with `held` a link to `v` and `strong`: `'x '` holding `held` and `backgroundColor`, `' '` holding `held`, `' '` unmarked, a hard break, `' '` holding `held`, `' '` unmarked, a hard break. `trimmedEdges` returns the one leaf `'x'`; the reference, `trimPass` on `runsSharedWithNext`'s counts, also keeps a linked `' '`. Decide which is right by `docs/decisions.md` → "After 32 passes…" and the trim's entries, then fix the other and pin the line as a fixed test. + ### 31. Make the branch-coverage figure repeat across runs of an unchanged tree. Three Node test legs over one unchanged tree reported `emit/inline-line.ts` at 95.83%, 96.23% and