Repository navigation
Fix #1990: root docs keep their CR LF line endings through codev init and update - #1991
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On a CR LF
CLAUDE.md/AGENTS.md,codev updateandcodev initwrote the managed block with LF, so the doc ended up with mixed line endings. A CR LF doc is what a Windows checkout withcore.autocrlfgives 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-newwritten 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.tsfailed 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.mdtemplate measured 0 CR LF / 168 LF. Finally it runs the installedcodev initandcodev update --agenttwice on each project. Where a.codev-newappears, it then takes the new version (the doc becomes its.codev-new) and runsupdateonce more.Runs:
main(9fc63f2cc) + probe: run 45715166133. It fails, as it should: these are the defects.d1a763de2) + probe: run 45715172568. Green.Counts are CR LF / LF line breaks, before → after the first
update. In both runs the secondupdatechanged nothing.mainmaincore.autocrlf=true)main).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..codev-newatmain.codev-newat this headmain/ head)So the product was wrong, but not as the issue guessed. An adopter on Windows got no false conflict:
matchesTemplatealready 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-newwhose every line differed from the doc.Root Cause
renderHotContextBlockjoins it with\n, andupsertHotContextBlockspliced 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:copyRootFileswrote 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.tswas green):.codev-newbyte comparisons are this bug. On a Windows checkout the templates are CR LF, andinitwrote the block in LF, so the doc it wrote was mixed while.codev-newis the pure CR LF template.replace(/\n/g, '\r\n')turned a CR LF doc into\r\r\n.slice(end + 2)assumed LF.Fix
The change is in
packages/codev/src/lib/managed-block.tsandpackages/codev/src/lib/scaffold.ts.Rule: a root doc's line ending is read from its text outside the managed block.
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:initruns 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-newis removed once the doc is merged, and so is one holding an older shipped version, via the #1985 hashes.Also unchanged:
initwrites it (codev update: replace an unedited CLAUDE.md / AGENTS.md from an older release (shipped-template hash list, as skills have) #1985). That doc is never mixed..codev-new, behave byte for byte as before.main; the result is idempotent.Test Plan
main'smanaged-block.tsandscaffold.tsand all 62 pass with the fix.bugfix-1990-crlf-root-docs.test.ts, 11 tests:initandupdateagainst 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:.codev-newis the template in CR LF;.codev-newis LF even from a CR LF template;initon a CR LF checkout writes CR LF throughout;.codev-newis settled once merged, and one holding an older shipped version is removed by the codev update: replace an unedited CLAUDE.md / AGENTS.md from an older release (shipped-template hash list, as skills have) #1985 hashes.managed-block.test.ts: the rule itself, including both healing shapes and the LF fallback..codev-newexpectation, no longer depend on the checkout's line endings.packages/codev/skeletoncopy 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.mainand at this head.d1a763de2(the last code commit), suites plus the root-doc files: run 45715161906. Every job is green.root-docs):bugfix-1982-update-root-docs13/13,air-1985-update-older-root-docs22/22 andbugfix-1990-crlf-root-docs11/11.managed-block16/16.Review notes
chore(porch):commit names. The architect accepted the rebuttal: porch writes those on every project, and rewriting them would mean force-pushing itsstatus.yamlhistory.d1a763de2: both reviewers read the PR body before its update for the.codev-newchange landed, and both flagged that stale body, now fixed.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..codev-newtakes its doc's line ending in this PR. That is the architect's call, open to the owner's overrule.