…only target fetch (QuantEcon#254)
Review follow-up on the _toc.yml caption preservation:
- Matching by identical file set lost the caption of exactly the part a
lecture-adding sync touches (measured on the real python/zh-cn pair: append
one lecture to the first part and 基础工具 reverted to English). Parts are
now paired by largest shared membership, each target part used once, ties
to the nearest position. A part with no shared files keeps the source
caption and is named in a warning; a matched part whose caption is already
byte-identical to the source is logged as not localised. No positional
guessing.
- The merge no longer round-trips through yaml.dump (201 of 204 lines
changed on lecture-python's TOC, comments dropped, re-dumped even when
nothing was preserved). Caption values are substituted into the source
text and the result is verified by parse against the intended document;
noArrayIndent re-serialisation is the fallback only.
- The rebase replay's `type: 'toc'` site in index.ts now fetches
targetContent too, so a rebase no longer re-copies English captions.
- Both target-TOC fetches swallow only a 404; any other status fails the
fetch instead of silently dropping the captions on a transient error.
- Code moved to src/toc-captions.ts (new module, new test file) so this PR
and QuantEcon#289 — which inserts at the same point in sync-orchestrator.ts and
adds the same js-yaml import — merge cleanly in either order.
- Tests: byte-identity on a QuantEcon-style fixture with a comment, quoted
caption and trailing whitespace; gain/lose/reorder a lecture; parts moved;
new part; no-overlap part not guessed; split part; target-only parts;
never-localised no-op by reference; no parts; malformed target; quoting;
commented-out caption line; the block-scalar fallback; matcher unit tests.
Orchestrator test asserts bytes. CHANGELOG, FAQ and architecture map
updated. Merged current main.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
When a sync run regenerated
_toc.yml, it mirrored the source directly and silently overwrote any translated part captions in the target.Two-part fix: fetch the existing target TOC in
index.tsso it is available astargetContent, then inprocessTocFilecallmergeTargetCaptionswhich matches source and target parts by file-set membership and carries the target's caption forward for unchanged parts. New parts with no target equivalent keep the source caption.Part of #254 — the interim caption-preservation step; the structured TOC merge in #259 and the shared deterministic localisation check supersede it, so this PR does not close #254.