Skip to content

🐛 fix(index): leave an index whose content is current untouched - #13

Merged
LGuichet merged 2 commits into
nextfrom
fix/index-skip-unchanged-write
Oct 31, 2026
Merged

LGuichet merged 2 commits into
nextfrom
fix/index-skip-unchanged-write

Conversation

@LGuichet

@LGuichet LGuichet commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

okfctl index build no longer rewrites an index.md whose content is already current. On a Windows checkout (core.autocrlf=true), that rewrite could change only the line endings, and git then reported the file modified with an empty diff.

Index build

Migrate (okf_version marker)

  • A marker target with a control character stays readable: this PR's first CI run had the fuzzer find an older, unrelated bug. migrate --apply takes its target version from a user-editable plan. For a target such as a tab then a newline, yaml.v3 wrote a literal block whose tab-led line no parser reads back, leaving an unparseable bundle-root index.md. Such a target is now written double-quoted, with every control character escaped. Any other target is written exactly as before.

Index rendering (internal/okf/)

  • reserved_lifecycle.go: WriteIndexWithOptions reads the existing index once, skips it when its content is current, and otherwise picks the line endings from it as before.
  • Tests: index_eol_test.go adds TestWriteIndex_UnchangedIndexIsNotRewritten. It covers pure-CRLF, mixed and LF indexes whose content is current (same bytes, same mtime after the build), with a changed root index as the control (it is still rewritten). TestWriteIndex_PreservesExistingLineEndings gives its mixed-ending index a real content change, so it still proves that a changed mixed index is written LF.
  • migrate.go: bumpRootIndexMarker forces double-quoted style on a target with a control character.
  • writepath_fuzz_test.go: FuzzRootIndexMarker seeds the failing input ("\t\n0"), which went red (found a tab character where an indentation space is expected) and then green. The existing migrate tests, unchanged, are the control for ordinary targets.

Evidence

  • Before (next at the parent of this branch): on a CRLF checkout, an index that an editor or agent left with mixed endings (one line rewritten LF) comes back pure LF from index build even though its content is unchanged. Every build also rewrites every index, so every mtime moves.
    After: that index keeps its bytes and mtime, and index check stays rc 0.

TestWriteIndex_UnchangedIndexIsNotRewritten went red before the change: all three unchanged indexes had their mtime moved, and the mixed one lost its bytes. It is green after.

Real corpus: copies of three production CRLF-checkout bundles, built with the installed next binary (v0.4.0-53-g5d27721) and with this branch.

Bundle Index files byte-changed by index build (before → after) index check rc validate rc
nf525-lne 0/8 → 0/8 0 → 0 0 → 0
plateforme-agree 0/11 → 0/11 0 → 0 0 → 0
ifpos-interface-cases 0/1 → 0/1 0 → 0 0 → 0

Those bundles' indexes are each pure LF or pure CRLF today, so no bytes change in either column; that is the control showing the change hides nothing. The mixed-ending case the change targets is the fixture above.

The index tests, the -run Conformance suite and gofmt pass. internal/okf and cmd pass apart from the tests that fail identically on next on this Windows host (plugin and editor exec, true missing from PATH, CRLF git clones). -race runs in CI only (no C compiler on the host).

Merge Danger

Door: two-way

Blast Radius: index writes

  • okfctl index build (and the commands that rebuild indexes, such as node new, node mv and node rm) no longer touch an index whose content is current. Its bytes, line endings and mtime stay as they were.
  • Not changed: an index that is already LF and whose content does change is still written LF. The build decides from the file it replaces, not from git config.

Not in this PR: line endings of concept files and log.md. index build never writes those, and a log append always changes content.

🤖 Generated with Claude Code

LGuichet and others added 2 commits October 30, 2026 19:08
index build rewrote every index.md on every run, and an index with mixed line endings (an editor or agent wrote LF lines into a CRLF file) came out LF even when nothing changed. On a core.autocrlf=true checkout git then reports the file modified with an empty diff, since its size no longer matches the CRLF size git recorded. Compare the render with the on-disk file the way index check does (line endings are not content) and skip the write when they match. A changed index still keeps CRLF when it was pure CRLF, and falls back to LF otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…racter

bumpRootIndexMarker left the scalar style to yaml.v3, which writes a target such as a tab then a newline as a literal block whose tab-led line no parser reads back, so migrate --apply could leave an unparseable bundle-root index.md. FuzzRootIndexMarker caught it in CI on #13. Force double-quoted style when the target holds a control character; every other target is written as before. The input joins the fuzz seeds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LGuichet
LGuichet merged commit ce38a7e into next Oct 31, 2026
8 checks passed
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