You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cook recipe -f cooklang corrupts recipes on repeated round-trips #414
cook recipe -f cooklang is not idempotent: every pass through the formatter adds one leading space to any step line that wraps immediately after an ingredient, cookware or timer. The growth is unbounded, so repeatedly rewriting a .cook file through the formatter corrupts it a little more each time.
Reproduction
cat > p0.cook <<'RECIPE'---title: Round Trip---Mix @plain flour{200%g} with @whole milk{250%ml} in a #large mixing bowl{} and beat until the batter is completely smooth, then fold in @caster sugar{2%tbsp} and a pinch of @fine sea salt{}.RECIPEforiin 1 2 3;do
cook recipe read p$((i-1)).cook -f cooklang > p$i.cook
done
diff p1.cook p3.cook
8c8< and a pinch of @fine sea salt{}.---> and a pinch of @fine sea salt{}.
One leading space after pass 1, two after pass 2, three after pass 3.
Cause
component_word_separator emits the component using Word::from, whose whitespace field is empty. The space that follows the component is therefore handed to the next word rather than being dropped at the line break, so it lands at the start of the wrapped line. On reparse it is ordinary step text, and the next format pass adds another.
Only lines that wrap directly after a component are affected, which is why it is easy to miss — a line wrapping at a plain word is unaffected.
Impact
Any workflow that rewrites recipes through the formatter (normalising a collection, an editor "format document" action, a pre-commit hook) degrades the source on each run.
Notes
There is a failing test proving this, currently marked #[ignore] with the diagnosis in its doc comment, added while extracting the formatters into a library crate: formatting_is_idempotent. Fixing this changes output for every wrapped step, so it wants its own change and a deliberate snapshot review rather than being folded into unrelated work.
Activity
fix: build recipe reference paths with '/' on every platform
fix(recipe): keep the cooklang formatter idempotent
test(recipe): pin the structure of latex, typst and cooklang output