Repository navigation
First slice: Go's path.Clean and path.Join, proved (bar v2) - #2
Merged
Merged
Conversation
Path.clean is Go's loop, read once; Path.join is Go's Join. Spec/Defs.lean states Go's four rules on the elements of a path, as a rewriting relation, and Spec.lean proves that whatever order the rules are applied in, clean gives what they leave; that the result has no empty element or `.`, and `..` only at the start; that cleaning is idempotent; that join is what Go's documentation says; and that a clean relative path with no `..`, or any path cleaned as rooted, joined to a folder stays inside it. Go's own tests of Clean and Join are checked by the kernel. lake comparator --paranoid accepts all 10 statements under the six kernels. The differential tests compare 167,263 inputs with a model of the rules and with Go, Python and Node (0 failures, the differences named and confirmed by the model), and catch 22 of 22 planted bugs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AovXVgJBHGiN44TxQM4dcd
- Spec.step_shortens (every rule drops an element, so the rules end in any order) and Spec.rules_unique (every order ends at the same elements) back what the page said of the order; 12 statements now. - Step.parent and SPEC.md say why rule 3's "non-.. element" is read as a name: read literally, `abc/./../def` could end as `abc/def` or `def`. - Path.clean and SPEC.md no longer call the result the shortest path, which nothing proves. - README lists Go's code as tested, not proved, and says that the CLI replaces argument octets that are not UTF-8 with U+FFFD; the tests now run the CLI on such arguments. - The record gives the extra join case its own label. lake comparator --paranoid accepts all 12 statements. 167,263 inputs, 0 failures; 22 of 22 planted bugs caught. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AovXVgJBHGiN44TxQM4dcd
The bar check asks every approved statement to mention the code under proof, and CI failed item 3 on rules_end, normal_iff, step_shortens and rules_unique, which spoke of the rules alone. They are restated: - clean_rules: the elements the rules leave are those `clean p` names (`Names`: rendered as `clean p`, no rule applies, no slash inside); - rules_end: the rules can always be applied until none applies, and leave the elements of `clean p`; - clean_names: `clean p` names exactly one list of elements, so every order of the rules ends at the same elements (was rules_unique); - clean_shape: those elements are some `..`, none if rooted, then names (was normal_iff). That the rules always end is read off `Spec.Step` on the page, not claimed as a statement. Proofs/Unique.lean proves that a path splits one way, that `Names` fixes its elements, and that the rules only drop elements. lake comparator --paranoid accepts all 10 statements, and bar/check.py passes item 3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AovXVgJBHGiN44TxQM4dcd
orda-aska
approved these changes
Oct 28, 2026
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.
This is the first slice of the plan in #1, which I claimed there. It is built to bar v2, in the same shape as hostname, punycode, bech32 and hpack. A self-review (one reviewer, each finding checked by a second agent) has run on it; the changes it led to are listed at the end.
What it does
Go's
path.Cleanandpath.Join(go1.24.7), in Lean, onString:Path.clean p: the path cleaned by lexical processing alone;Path.join es: the elements joined by slashes and cleaned, with the empty ones left out, and the empty string when nothing is left.Path/Basic.leanwrites Go's loop line by line. Go writes into a buffer and keeps its lengthw; here the buffer is a list kept reversed, so writing and removing at the end take one step. The loop reads the input once, from the front.What is proved
Spec.leanhas 10 statements, each aboutPath.cleanorPath.join.lake comparator --paranoidaccepts them under all six kernels bundled with Lean 4.35.0, using onlypropext,Classical.choiceandQuot.sound, in about 45 seconds. There is nosorryoutside the challenge file.Spec/Defs.leanuses nothing from the code. It states Go's four rules on the elements of a path, as a rewriting relationStep://, the root's slash, or a slash at the end);.;..and the name before it (Go says "the non-..element"; read literally, with an empty element or.allowed,abc/./../defcould end asabc/defordef, and Go's own tests givedef);..at the start of a rooted path.Normalsays no rule applies, andrenderwrites elements back: a slash first when rooted,.for nothing.Names s r essayssis whatrender rwrites fores, that no rule applies toes, and that no element holds a slash.clean_rules: whatever order the rules are applied in, once none applies, the elements left are thoseclean pnames. This is the documentation's "applies the following rules iteratively until no further processing can be done", taken literally.rules_end: the rules can always be applied until none applies, and leave the elements ofclean p.clean_names:clean pnames exactly one list of elements, rooted whenpis. Withclean_rules, every order of the rules ends at the same elements. (Each rule drops one element or two, asStepshows, so every order comes to an end.)clean_shape: the elements ofclean pare some..(none if rooted), then names. So the result has no empty element or., and..only at its start. This is the plan's shape claim.clean_idem: cleaning is idempotent.join_eq:joinis the documentation ofJoin.join_inside: a clean relative pathqwith no.., joined to anyb, gives the elements ofclean band then those ofq. This is the plan's "stays inside any folder it is joined to".join_root_inside: anyu, cleaned as rooted (clean ("/" ++ u)) and joined to abthat is not empty, gives the elements ofclean band then elements with no... This is the usual way to join an untrusted path. It needsb ≠ "":join ["", "/etc"]is/etc, whichgo_join_testsrecords.go_clean_tests,go_join_tests: Go's owncleantests(each path, and each result cleaned again) andjointests, bydecide +kernel.The leading
//. As the plan asked, the spec chooses a rule and records it: two slashes at the start are one slash, as in Go (//abccleans to/abc, one of Go's tests). POSIX lets a system give them a meaning of their own, and Python keeps them.The proofs go through a stack on the elements (Pike's algorithm, in
Proofs/Rules.lean): every rule leaves the stack's result unchanged, the rules lead to it, and it is in normal form.Proofs/Loop.leanshows Go's loop keeps the stack in its buffer, element by element.Differential tests
tests/TEST-RESULTS.md: 167,263 inputs, seed 20261027, 0 failures, with no oracle left out.cleantestsandjointests. Every answer of the tool equals the model's.path.Cleanandpath.Join(go1.24.7): agrees on all 167,263;posixpath.normpath(3.13.17);path.posix.normalizeandpath.posix.join(v22.22.0).normalize, 3,236 injoin);joingives.for nothing (5,099).a . /(88,573) and up to 7 overa b . /;.., names, characters that are not ASCII, NUL, tab, CR and LF;tests/plant_bugs.pyplants 22 bugs and compares with the model alone; all 22 are caught (tests/PLANTED-BUGS.md). Among them:dotdotor past a slash;..kept in a rooted path;dotdotnot moved past a kept..;.kept, or a trailing..dropped;dotdotset to 0;joingiving.for nothing, or keeping leading empty elements;Main.lean, a CR kept and wrong arguments exiting 0.Not proved
These are listed on the page:
path.Cleanandpath.Joinis tested, not proved; only Go's own test tables are proved;//, a recorded choice;join_root_inside;Split,Base,Dir,Ext,IsAbs,Match), and Windows paths;Main.lean, which the tests cover.Re-check
Changes from the self-review
The review found nothing blocking. Its reviewer also compared 802,041 more inputs with Go (every path over
a . /up to 12 characters, and joins of up to five tricky elements) and found no difference.clean_rulesgives the elements ofclean p, andclean_namessays there is one such list.rules_end,normal_iff, and thestep_shortensandrules_uniquefirst added for this, spoke of the rules alone. They are restated aboutclean p:rules_endleaves its elements,clean_namesreplacesrules_unique,clean_shapereplacesnormal_iff, and that the rules end is read offStep.Step.parentand SPEC.md say why rule 3 is read as taking a name.Path.cleanand SPEC.md no longer call the result the shortest path, which nothing proves.Kept as is:
join_insidetakes a cleanq. A form for anyqwith no..also holds and follows fromjoin_eq,clean_rulesandrules_end; it needs care atb = q = "", wherejoingives the empty string.Review asks
Stepa fair reading of Go's four rules? In particular, rule 1 is stated on elements as "drop an empty element", which also covers the slash at the end and the root's slash; the root is kept apart asrooted...element".Step.parenttakes only a name: not empty,.or... Taking an empty element or.there would leta//..clean toa, which Go does not do. Is that the right reading?join_insideandjoin_root_insidethe claims a user needs, and isb ≠ ""stated clearly enough?🤖 Generated with Claude Code
https://claude.ai/code/session_01AovXVgJBHGiN44TxQM4dcd