Skip to content

test(editor): cover destination repairs and remove unused serializer - #21532

Merged
nwparker merged 14 commits into
stack-reconcilefrom
stack-final
Sep 19, 2026
Merged

nwparker merged 14 commits into
stack-reconcilefrom
stack-final

Conversation

@nwparker

@nwparker nwparker commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​107 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​104
Prod 1 0 $\color{#cf222e}{\Huge{\mathbf{−}}}$​112 $\color{#cf222e}{\Huge{\mathbf{−}}}$​112

ELI5

Adds destination regressions and removes an unused serialization path.

What Changed

Deletes the unregistered 112-line serializer module and adds tests for edited links/images, spaces in destinations, and unchanged raw destinations beside repaired attributes. The production destination fix is now in the preceding layer so that intermediate layer is safe.

Why

Keeps one active serializer implementation and verifies its contract instead of retaining a competing unused shim.

Linked Issue

Related to #9858; this stack is a partial compatibility improvement and does not close the full request.

Visual Proof

Final hidden Electron save/reopen check, paired client: heading unchanged, typed Markdown remains literal in its own paragraph, formatted link preserved. All three Git/folder/paired cases pass with explicit caret-position assertions.

markdown-reopened-paired-remote.png

Incremental diff is regression tests and deletion of an unregistered module; screenshot above verifies cumulative behavior. Cumulative UI evidence is attached to #21530 and #21553.

Testing

Merged head bd17fae: full CI run 35416503668 succeeded, including typecheck, static analysis, both packaging jobs, all unit-test shards, and changed Electron E2E specs. Readiness review found no issues; deleted module has no registered consumers.

Final stack bd17fae:

All launches used ORCA_BACKGROUND_LAUNCH=1. Paired-client coverage runs on macOS; live SSH/network failures and Windows/Linux Electron UI were not exercised. Latest CI reruns are separate from these local results.

Review

Low incremental risk: regression coverage and removal of unused code. Strengthened Electron tests verify insertion position rather than merely finding typed text.

Independent readiness reviews covered #21527 and #21531. Later preview/scanner findings were fixed with regressions. The fence tracker retains mixed-marker closers to match the installed parser; over-indented closers are rejected.

Remaining stack: #21527 → #21530 → #21531. #21565 merged to main. #21529 merged into #21527; #21532 merged into #21531. The two stack merges have not landed on main. #9858 remains open; full GFM support is broader than this stack.

Agent skill upstream boundary

  • Not applicable; no skill-installer source is included.

Checklist

  • User-visible behavior and implementation rationale explained.
  • Automated checks recorded with their scope.
  • Cross-platform, SSH/folder-workspace, and source-data effects considered.
  • Full PR Checks passed on the merged head; all review threads resolved.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The new href === originalHref check is evaluated after escapeLinkAndImageAttributes has already rewritten href, so unedited destinations that need escaping bypass rawHref and get re-normalized — a byte-fidelity regression in the exact path this PR protects. Details inline.

Reviewed changes

  • Honor edited destinations — renderMarkdown for links and images now uses rawHref/rawSrc only while the decoded destination still equals the value captured at parse time (originalHref/originalSrc); an edited destination serializes from the live value.
  • Guard raw substitution in the literal serializer — escapeLinkAndImageAttributes only swaps in rawHref/rawSrc when the destination is unchanged.
  • Delete dead serializer shim — rich-markdown-serializer-fidelity.ts was unreferenced at both base and head (git grep is empty), so removing it changes nothing at runtime.
  • New round-trip test — markdownAfterDestinationEdit drives a real setLink / image src edit and asserts the escaped new destination. I confirmed it fails against the base sources and passes on head.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one minor test-coverage suggestion inline.

Reviewed changes

  • New destination-edit coverage — markdown-round-trip.test.ts gains a markdownAfterDestinationEdit helper and cases asserting an edited link/image destination serializes from the live value, that spaces are percent-encoded, and that an unchanged raw destination survives a nearby attribute repair.
  • Classification test helper — EditorContent.markdown-classification.test.tsx threads a savedContent parameter through renderEditPath so the two fallback-toggle tests match saved content, consistent with the model reading classification from fileContents rather than drafts.
  • Delete dead serializer shim — rich-markdown-serializer-fidelity.ts (112 lines) has no references at base or head.
  • Base merge — the stack merge moved the originalHref/originalSrc destination guards and the keepRaw fix into stack-reconcile; this layer no longer carries them. The prior byte-fidelity thread is addressed there and was retired.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Strengthened raw-destination regression — the retains an unchanged raw destination while repairing nearby attributes case now uses [a](a\\b\)), whose raw bytes differ from the escaped decoded form. Verified locally: with the base keepRaw guard forced off the test fails (a\\b\) -> a\b\)); with the guard restored all 74 round-trip tests pass. This retires the prior inline finding that the old input passed with the bug present.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Explicit caret placement in the save/reopen spec — markdown-literal-save-reopen.spec.ts replaces editor.click() + ControlOrMeta+End with a paragraph-scoped click, a DOM Range/Selection set plus a dispatched selectionchange, and a poll asserting the selection is ['End', 3] before typing.
  • Stricter save/reopen assertions — adds h1 and last-paragraph toHaveText checks before saving and on reopen, replacing the looser toContainText(TYPED).
  • Base merge — bd17faeb72 merged stack-reconcile (2e94ae2); its only changes vs the first parent are base scanner files, none of this layer's files.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit a611d42 into stack-reconcile Sep 19, 2026
34 of 35 checks passed
nwparker added a commit that referenced this pull request Sep 20, 2026
* refactor(editor): show the preview affordance only after rich mode faults

Proactively classifying every Source-view markdown tab scanned content
nobody was looking at in Rich mode. The toggle and banner now read a
stored per-tab fault instead, recorded once Rich mode actually falls
back, so Source-view tabs never scan speculatively.

* docs(editor): state the fault-tracking constraints in present tense

* fix(editor): register the open-preview banner string

verify:localization-extraction failed because the rich-markdown
fallback banner's "Open preview" button called translate() with a
key never added to en.json.

* fix(editor): document isolated store harness cast

* fix(editor): stop the rich markdown editor from mangling dollar-heavy files

Opening a markdown file full of dollar amounts in rich mode reformatted it
on load, and any save then rewrote the whole file:

- marked emits an `escape` inline token for `\$`, `\*`, `\_`, `\[`; Tiptap's
  markdown parser has no case for it, so the escaped character was deleted
  from the document as soon as the file opened. The marked facade now
  rewrites escape tokens to text tokens, in place, so table cells keep them
  too.
- the inline-math tokenizer treated any same-line `$...$` pair as LaTeX, so
  "from $10 to $20" or "entered 2021 at $0" became a KaTeX atom whose text
  was trimmed. It now requires Pandoc-style boundaries: both `$` must touch
  the formula and the closing `$` must not be followed by a digit.
- the source-preserving reconcile mis-applied any edit at the end of a file
  whose source ends with a newline: getMarkdown never emits one, so the
  end-of-document hunk landed one character late, failed the round-trip
  proof, and fell back to canonical output for the entire file, rewriting
  every `\$`, `&` and table in it. It now patches the newline-stripped
  bodies and re-attaches the source's trailing newline run.

* fix(editor): round-trip escapes as atoms and narrow the end-of-file reconcile

Review findings on the first commit, all reproduced with the real serializer:

- Rewriting marked's `escape` token to text kept the character on load but
  the serializer never re-escapes, so `\# x` came back as `# x` and became a
  heading on the next open; `\$x\$` became inline math. Replace the facade
  rewrite with an inline atom node that owns the escape token and renders
  `\` + character, so escapes round-trip byte for byte in every container.
- The body-strip reconcile ran for every trailing-newline shape. A source
  ending in a blank line parses to a trailing empty paragraph, so canonical
  ends in `\n\n` too; stripping and re-attaching there duplicated the
  paragraph, failed the branch-6 proof, and canonicalized the whole file.
  Only strip when the source ends in exactly one newline that canonical
  lacks; every other shape patches correctly whole, as on main.
- Canonical fallbacks now keep the source's single trailing newline.
- The inline-math regex allowed neither a soft line break inside a formula
  nor a trailing LaTeX line break; both are valid and upstream accepted
  them. Drop the newline and backslash exclusions and the dead `.trim()`.

* fix(editor): carry escapes as a mark so emphasis and links stay continuous

Second-round review of the atom approach: Tiptap's serializer closes every
active mark before a non-text inline node and reopens it after, so an
escape atom inside bold split the run (`**cost \$5 total**` came back as
`**cost **\$**5 total**`, which no longer parses as bold), a link containing
an escape became two links, and find/replace was disabled on any match
touching an escape because atoms are read-only.

The escape is now a non-inclusive mark on ordinary text. A mark's markdown
is one prefix for the whole run, so `getMarkdown` is wrapped to rewrite
marked text as `\X` per character before the manager serializes; inside a
code mark the character is emitted bare, and `& < >` are left to the
serializer's entity encoding. The mark is registered after `Markdown`
because that extension's onBeforeCreate installs the getMarkdown being
wrapped.

Also restores tiptap-marked-facade.ts to the base branch: the previous
commit meant to remove the escape-token rewrite there but restored the
file from the branch's own HEAD, leaving a dead override in the diff.

* fix(editor): retry the whole-text patch and refuse escaped dollars as math closers

Second-round review findings that survived the mark rewrite:

- A source whose last line is whitespace only (`Last.\n  \n`) has a trailing
  run of one newline, so the body strip ran, landed the end hunk after the
  spaces, failed the branch-6 proof, and canonicalized the whole file where
  the base branch had patched it correctly. The body strip is now the first
  attempt and the whole-text patch the second, so no file does worse than
  before; the extra round trip only runs when the first attempt fails.
- `costs $5 to \$x here` parsed as inline math with latex `5 to \`, because
  the tokenizer accepted an escaped `\$` as the closing delimiter. Escaped
  characters are now consumed inside the formula and cannot close it.
- The escaped-dollar test passed on the base branch for the wrong reason
  (the `\$` was deleted before the math tokenizer ran); it now also asserts
  the bytes round-trip, and a new test pins escapes as ordinary searchable
  text.

* fix(editor): keep table pipes, link destinations and display math faithful to source

Pre-existing serializer defects the review catalogued, now fixed in one
place: a serializer-fidelity extension that wraps getMarkdown and rewrites
the document JSON into its source form before Tiptap serializes it. The
escaped-character mark's per-character expansion moves there too.

- `\|` inside a table cell: marked unescapes it per cell before inline
  lexing, so the cell held a bare `|` that split the row on the next load
  and truncated it. Text inside tableCell/tableHeader now escapes `|`,
  code spans included, since the cell split happens before code lexing.
- `\)` inside a link or image destination came back bare and ended the
  destination early. Parentheses in destinations are escaped again.
  (Angle-bracket destinations are not an option: Orca's raw-HTML pass would
  placeholder them before parsing.) Image alt text escapes `[ ] \`, and
  link/image titles escape `"`.
- `$$` anywhere in a paragraph split it, because marked ends a paragraph
  wherever a block tokenizer's `start` points and upstream used
  `indexOf('$$')`. Display math now only starts at a line start.

# Conflicts:
#	src/renderer/src/components/editor/rich-markdown-extensions.ts

* fix(editor): accept indented display math with inner dollars, escape pipes in cell attributes

Review comments on the previous commit:

- Display math whose body holds a `$` (`$$\n\$5\n$$`) fell back to prose
  because the body pattern refused every dollar; it now runs to the
  closing `$$`.
- Display math indented by spaces or a tab no longer opened, because the
  line-start check wanted `$$` right after the newline. The start pattern
  tolerates the indent, and points marked at the newline rather than the
  first `$` so the indent does not stay behind in the paragraph.
- `|` inside a link or image attribute in a table cell was still written
  bare, so the row split on the next load. The cell context now reaches
  destinations, titles and alt text as well as text.

# Conflicts:
#	src/renderer/src/components/editor/rich-markdown-extensions.ts

* style(editor): format merged markdown extensions

* fix(editor): remove duplicate block math tokenizer

* fix(editor): restore inline math import

* fix(editor): avoid duplicate escape extension and preserve EOF shape

* fix(editor): keep existing source-preserving serializer active

* fix(editor): preserve baseline link and escape serializer behavior

* chore(editor): satisfy merged markdown lint rules

* fix(editor): retain escaped punctuation metadata during serialization

* fix(editor): keep escaped mark fallback neutral

* fix(editor): route marked escape tokens through rich markdown mark

* chore(editor): satisfy escape mark lint

* fix(editor): preserve escaped markdown entities through fast serialization

* fix(editor): normalize escaped dollar amounts

* chore(editor): satisfy serializer lint

* fix(editor): preserve nested markdown destinations and escaped entities

* chore(editor): satisfy destination serializer lint

* fix(editor): force source serialization for escaped entity marks

* fix(editor): retain balanced markdown destinations

* fix(editor): preserve escaped mark serialization in plain blocks

* fix(editor): normalize plain escaped money text

* fix(editor): keep table and display math dollar escapes

* chore(editor): remove unused escape helper

* fix(editor): retain raw link and image destinations

* chore(editor): satisfy raw destination lint

* fix(editor): admit comments inside image alt text

* fix(editor): keep plain money escapes out of math recovery

* fix(editor): preserve currency escapes in tables and formatted text

* chore(editor): remove diagnostics and satisfy serializer lint

* fix(editor): scope currency escape recovery to escaped source

* fix(editor): scope escape encoding to text nodes

* test(editor): keep stored preview fault aligned with saved content

* test(editor): cover destination repairs and remove unused serializer (#21532)

* fix(editor): honor edited markdown destinations

* refactor(editor): remove unused markdown serializer shim

* test(editor): cover saved preview and destination repairs

* test(editor): detect raw destination escape regressions

* test(editor): verify save position across hidden Electron clients

* perf(editor): scan fence lines without substring allocations

* fix(editor): match fence suffix whitespace rules

* fix(editor): match fence suffix whitespace rules

* fix(editor): match parser fence whitespace

* fix(editor): keep reconciliation cache contract

* fix(editor): preserve rich-mode validation option

* test(editor): cover source-mode validation skip

* fix(editor): keep rich mode classifier within lint limit

* test(editor): select rich copy ranges through Playwright

* fix(editor): wrap long rich markdown code lines

* test(e2e): retry rich selection before clipboard assertions

---------

Co-authored-by: Frederic Barthelemy <[email protected]>
Co-authored-by: averydev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant