Skip to content

Fix #1990: root docs keep their CR LF line endings through codev init and update - #1991

Merged
waleedkadous merged 16 commits into
mainfrom
builder/bugfix-1990
Nov 25, 2026
Merged

waleedkadous merged 16 commits into
mainfrom
builder/bugfix-1990

Conversation

@waleedkadous

@waleedkadous waleedkadous commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On a CR LF CLAUDE.md / AGENTS.md, codev update and codev init wrote the managed block with LF, so the doc ended up with mixed line endings. A CR LF doc is what a Windows checkout with core.autocrlf gives an adopter. The block is now written in the line ending the doc uses outside the block, and a doc this bug has already left mixed is healed by the next update.

A .codev-new written beside a root doc now takes that doc's line ending too, so a plain diff shows only the real changes. The root-doc tests no longer depend on the checkout's line endings.

Fixes #1990

Problem

bugfix-1982-update-root-docs.test.ts failed 4 tests on native Windows. Issue #1990 asked whether only the tests were wrong or the product too. That question was settled on a Windows runner, not by reasoning.

Method: a probe test on throwaway branches, since deleted and never merged. It packs the packages as the install verification does and installs them globally into a temp prefix, as an adopter would. It then replaces the installed skeleton with the files exactly as git stores them, which is what the published package carries: the installed CLAUDE.md template measured 0 CR LF / 168 LF. Finally it runs the installed codev init and codev update --agent twice on each project. Where a .codev-new appears, it then takes the new version (the doc becomes its .codev-new) and runs update once more.

Runs:

Counts are CR LF / LF line breaks, before → after the first update. In both runs the second update changed nothing.

Project Conflicts (main / head) CLAUDE.md at main CLAUDE.md at this head AGENTS.md at main AGENTS.md at this head
LF, unedited none / none 0/168 → 0/168 0/168 → 0/168 0/170 → 0/170 0/170 → 0/170
CR LF, unedited (committed and checked out again with core.autocrlf=true) none / none 168/0 → 154/14 mixed 168/0 → 168/0, untouched 170/0 → 156/14 mixed 170/0 → 170/0, untouched
CR LF, managed block missing (doc from before Spec 987) none / none 152/0 → 152/16 mixed 152/0 → 168/0, block put back in CR LF 154/0 → 154/16 mixed 154/0 → 170/0
CR LF, block inserted by a pre-fix update (the state the row above leaves on main) none / none 152/16 → 152/16, stays mixed 152/16 → 168/0, healed 154/16 → 154/16, stays mixed 154/16 → 170/0, healed
CR LF, CLAUDE.md edited outside the block CLAUDE.md / CLAUDE.md 172/0 → 158/14: the adopter's own doc modified 172/0 → 172/0, kept byte for byte 170/0 → 156/14 mixed 170/0 → 170/0
LF, CLAUDE.md edited outside the block CLAUDE.md / CLAUDE.md 0/172 → 0/172 0/172 → 0/172 0/170 → 0/170 0/170 → 0/170

.codev-new, beside the edited CLAUDE.md, in the same runs. "Identical lines" means template lines that a plain diff finds byte-identical in the edited doc.

Project .codev-new at main .codev-new at this head After the adopter merges (main / head)
CR LF, CLAUDE.md edited outside the block 0/168, i.e. LF beside a CR LF doc: 0 of 168 lines identical (the diff shows every line) 168/0, CR LF: 168 of 168 identical (the diff shows only the edit) removed, "nothing left to merge" / removed
LF, CLAUDE.md edited outside the block 0/168, LF: 168 of 168 identical 0/168, LF: 168 of 168 identical removed / removed

So the product was wrong, but not as the issue guessed. An adopter on Windows got no false conflict: matchesTemplate already normalises CR LF before comparing. What they got was mixed line endings, including in an edited doc that is supposed to be kept as it is, plus a .codev-new whose every line differed from the doc.

Root Cause

  • The block: renderHotContextBlock joins it with \n, and upsertHotContextBlock spliced it into the doc as is, whatever line ending the doc used. When it inserted a block (into a doc from before Spec 987), the blank line before the block and the line break after it were also written in LF.
  • .codev-new: copyRootFiles wrote the template as shipped, whatever line ending the doc beside it used.

The four Windows test failures at main (air-1985-update-older-root-docs.test.ts was green):

  • The two .codev-new byte comparisons are this bug. On a Windows checkout the templates are CR LF, and init wrote the block in LF, so the doc it wrote was mixed while .codev-new is the pure CR LF template.
  • "a CRLF checkout of an unedited doc is up to date" was a test problem. Its replace(/\n/g, '\r\n') turned a CR LF doc into \r\r\n.
  • "a doc whose managed block is missing altogether" was a test problem. Its slice(end + 2) assumed LF.

Fix

The change is in packages/codev/src/lib/managed-block.ts and packages/codev/src/lib/scaffold.ts.

Rule: a root doc's line ending is read from its text outside the managed block.

  • The block is the markers, what lies between them, and the line break on each side. Inserting the block writes those breaks, so a pre-fix update may have written them in LF too.
  • If every line break outside the block is CR LF, the doc is CR LF.
  • Anything else takes LF, the ending of the published templates and of the rendered block: all LF, both kinds, or no line break at all.

Block refresh (upsertHotContextBlock): the block is written in the doc's line ending, together with the break on each side and any breaks an insertion adds. Both shapes this bug left behind therefore count as CR LF and are healed by the next update:

  • a CR LF body whose block was replaced in LF;
  • a CR LF doc into which the block was inserted in LF, with an LF break on each side.

init runs the same refresh, so on a CR LF checkout of the skeleton it writes each doc in CR LF throughout.

.codev-new (copyRootFiles) is written in the line ending of the doc beside it, by the same rule. This was the architect's ruling on review, under the standing preference to fix small adjacent things in the same PR.

Settling a leftover is unchanged: matching normalises line endings. So a CR LF .codev-new is removed once the doc is merged, and so is one holding an older shipped version, via the #1985 hashes.

Also unchanged:

Test Plan

  • Regression tests. Across the four root-doc test files, 14 tests fail on main's managed-block.ts and scaffold.ts and all 62 pass with the fix.
    • New bugfix-1990-crlf-root-docs.test.ts, 11 tests: init and update against a skeleton whose root-doc templates are built in LF (as published) and in CR LF (a Windows checkout), so the tests give the same result on any checkout. Covered:
    • managed-block.test.ts: the rule itself, including both healing shapes and the LF fallback.
  • Ending-independent tests. The two LF-assuming bugfix-1982 tests, and air-1985's .codev-new expectation, no longer depend on the checkout's line endings.
  • Fast local loop: with the gitignored packages/codev/skeleton copy converted to CR LF, main's code gives exactly the 4 Windows failures. The fix is green on both LF and CR LF skeletons: 103/103 across the root-doc, managed-block, scaffold and adopt tests.
  • Porch checks pass: build, and the codev test suite.
  • Windows, built and installed package, CR LF and LF projects: both tables above, at main and at this head.
  • Windows, on-demand workflow on this branch at d1a763de2 (the last code commit), suites plus the root-doc files: run 45715161906. Every job is green.
    • Targeted (root-docs): bugfix-1982-update-root-docs 13/13, air-1985-update-older-root-docs 22/22 and bugfix-1990-crlf-root-docs 11/11.
    • codev unit suite: 458 files passed, 14 skipped, 0 failed. This includes managed-block 16/16.
    • CLI tests, install verification, and probes on x64 and ARM64 all passed.
    • The commits after it add only the builder thread log.
  • GitHub CI on the PR: green.

Review notes

  • CMAP round 1:
    • claude APPROVE. It found that a doc whose block a pre-fix update inserted was left with LF breaks outside the markers and would never heal. Fixed, with tests.
    • codex REQUEST_CHANGES, on PR hygiene only.
  • CMAP round 2:
    • claude APPROVE.
    • codex REQUEST_CHANGES, solely on porch's own chore(porch): commit names. The architect accepted the rebuttal: porch writes those on every project, and rewriting them would mean force-pushing its status.yaml history.
  • CMAP round 3, on d1a763de2: both reviewers read the PR body before its update for the .codev-new change landed, and both flagged that stale body, now fixed.
    • Neither found a code defect.
    • codex repeated the porch-commit point.
    • claude's nit: inDocLineEnding's comment says "as it is when no regular file sits there", but an absent path would throw. That can't happen: the only call site has already checked that the doc exists. Left as is, so the code stays exactly what the Windows runs tested.
  • Architect's review:
    • Reproduced the fix on a CR LF project.
    • Ruled that .codev-new takes its doc's line ending in this PR. That is the architect's call, open to the owner's overrule.

…e ending

codev update (and init) rendered the hot-tier block with LF and spliced it into
CLAUDE.md / AGENTS.md as is, so a CR LF doc (a Windows checkout with core.autocrlf)
ended up with mixed line endings: an unedited doc, a doc missing its block, and an
adopter's edited doc alike. Measured on a Windows runner with the packed, installed
package (run 45709493779).

The line ending is read from the text outside the block: all CR LF there is CR LF,
anything else (all LF, both kinds, no break) takes LF, the published templates'
ending. A doc an earlier update left mixed (LF block in a CR LF body) is healed by
the next refresh.
…init and update

- bugfix-1990-crlf-root-docs: init/update against a published-form (LF) skeleton and a
  CR LF-checkout skeleton, built explicitly so the tests hold on any checkout: an
  unedited CR LF doc is untouched, a missing block comes back in CR LF, an edited doc is
  kept byte for byte, a doc this bug left mixed is healed, init on a CR LF checkout
  writes CR LF throughout and its .codev-new matches the doc.
- managed-block: the line-ending rule (CR LF, healing, LF fallback for mixed or no
  break outside the block).
- bugfix-1982: the CRLF test converted only bare LFs (a CR LF checkout got \r\r\n) and
  now also asserts the doc stays CR LF; the block-missing test sliced end + 2, assuming
  LF; the edit-outside test builds its edit in the doc's own line ending.
…as part of the block

A CR LF doc from before Spec 987 that a pre-fix update gave its block by insertion
also got the blank line before the block and the break after it in LF, outside the
markers, so the outside-the-block rule read it as mixed and never healed it (CMAP
review). Those breaks are written by the block's insertion, so they now belong to the
block: excluded when reading the doc's line ending, and written in it.
…into is healed

Pins the insertion-damaged shape ('# Title\r\n\n<block>\n\r\nbody') in the unit tests
and through update; the mixed-outside fallback case now expects the boundary break to
follow the block's LF.
A .codev-new beside a CR LF doc was the template as shipped (LF), so a plain diff of
the two showed every line changed. It is now written in the doc's line ending, by the
rule the block refresh uses (read outside the managed block), so a diff shows only real
changes. Settling still matches with line endings normalised, so a CR LF .codev-new is
removed once the doc is merged, including by the #1985 shipped-version hashes.
Architect's ruling on PR #1991 (fix the adjacent paper cut in the same PR).
…ill settled

- a CR LF doc's .codev-new is the template in CR LF; an LF doc's .codev-new is LF even
  from a CR LF checkout's template (both fail before the fix);
- a CR LF .codev-new is removed once the doc is merged, and one holding an older
  shipped version is removed by the #1985 hashes (guards);
- air-1985 expects the edited LF doc's .codev-new in LF on any checkout.
@waleedkadous
waleedkadous merged commit b6ef50e into main Nov 25, 2026
8 checks passed
waleedkadous added a commit that referenced this pull request Nov 25, 2026
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.

codev update root-doc tests fail on native Windows (5 tests on main since PR #1984)

1 participant