Repository navigation
Commit c033e9e
fix(rust-cli): real Lean precondition checks in verification.rs (P0-5) (#215)
ULTRAPLAN **P0-5**. Until now the seven `verify_*` functions in
`impl/rust-cli/src/verification.rs` returned `Ok(())`. Each one now
checks, against the real filesystem, the Lean precondition its operation
is proved under.
| Rust | Lean | Checks, in order |
|---|---|---|
| `verify_mkdir` | `MkdirPrecondition` (`FilesystemModel.lean:119`) |
target absent (lstat) → parent exists → parent is dir → parent writable
|
| `verify_rmdir` | `RmdirPrecondition` (`FilesystemModel.lean:129`) |
exists (lstat) → real dir → no entries → not sandbox root → parent
writable |
| `verify_create_file` | `CreateFilePrecondition`
(`FileOperations.lean:11`) | as mkdir |
| `verify_delete_file` | `DeleteFilePrecondition`
(`FileOperations.lean:20`) | exists (lstat) → not dir → regular file or
symlink → parent writable |
| `verify_copy_file` | `copyFilePrecondition` | src exists → src not dir
→ dst absent → dst parent exists → src regular file → dst parent dir →
src readable → dst parent writable |
| `verify_move` | `movePrecondition` | src exists → dst absent → src ≠
dst → not into itself → dst parent exists → src/dst parents writable |
| `verify_symlink` | `SymlinkPrecondition` | link absent (lstat) →
parent exists → parent dir → parent writable (the target is deliberately
not checked) |
**Status, in the plan's taxonomy:** each mapping is **TESTED**, not
PROVEN. The Rust checks are written by hand to mirror the Lean `Prop`s,
not extracted from them. Correspondence is checked by review plus 41 new
positive and negative unit tests. The module doc says so.
## Commits
1. `fix(rust-cli): implement real Lean precondition checks`
- Path resolution moves to `state::resolve_under_root`, so the verifiers
and `ShellState::resolve_path` use one rule. The body is moved, not
changed.
- Each verifier first repeats the checks the command already makes, in
the same order and with byte-identical messages, then applies the
conditions only Lean has. User-visible errors therefore stay the same.
2. `chore(rust-cli): remove broken .cargo/config.toml and no-op
build.rs`
- The config's only content was rustflags with a literal `$REPOS_DIR`
link path, for a `lean-runtime-checks` feature that nothing defines.
There is no `extern "C"` and no `#[link]` in `src/`.
- `docs/ABI-FFI-BOUNDARY.adoc` is updated to match.
3. `fix(rust-cli): keep rmdir read_dir error text identical to the
command`
## Behaviour changes (all from conditions the stub skipped)
- **Dangling symlink at a mkdir/touch/cp destination:** now *already
exists*. Before, mkdir and touch failed with an OS error, and cp wrote
*through* the link.
- **`rm` on a FIFO, socket or device:** refused (`Path is not a regular
file`). The model has no such node.
- New messages, reached only through the Lean-only conditions: `Parent
is not a directory (ENOTDIR)`, `… is not writable (EACCES)`, `Source is
not readable (EACCES)`, `Cannot remove the sandbox root`.
- `mv` follows Lean in not requiring the destination parent to be a
directory, so the rename itself reports that case.
## Evidence (rebased on main 3440d69)
```
cargo test suites=23 passed=827 failed=0 ignored=15
cargo clippy --all-targets -D warnings clean
cargo fmt --check clean
```
- Before the change, on 4401867: 787 passed / 14 ignored.
- This PR adds 41 tests, all in `verification.rs`.
- One test moved from passed to ignored because #214 (P0-4) made the
oracle test `#[ignore]`.
- **Mutant:** putting the `Ok(())` stub back into `verify_mkdir` fails
all 5 mkdir negative tests, including the unwritable-parent test. That
shows the permission tests really run as uid 1000.
- The permission tests skip themselves when run as root.
## ⚠ Finding: `RmdirPrecondition` is unsatisfiable (PROVEN)
`isEmptyDir p fs` (`FilesystemModel.lean:69-71`) quantifies over
`child.isPrefixOf p`, which ranges over p's **ancestors**, not its
children. So it requires p's parent **not** to exist, while
`parentWritable` requires the parent to exist. This typechecks against
this repo's `FilesystemModel` on Lean v4.34.1:
```lean
theorem rmdir_precondition_vacuous (p : Path) (fs : Filesystem)
(h : RmdirPrecondition p fs) : False
```
The file was checked with `lake env lean`. As a control, adding `example
: (1:Nat) = 2 := by decide` to the same file produces an error, so the
file is really checked.
**Consequence:** every theorem that takes `hpre : RmdirPrecondition p
fs` (in `FilesystemModel`, `FilesystemEquivalence`,
`FilesystemComposition`) holds vacuously, including the mkdir/rmdir
reversibility results.
The Rust here implements the evident *intent* ("the directory has no
entries"), and its docstring records the gap. The Lean fix
(`p.isPrefixOf child`, i.e. no descendant exists) belongs to the V1
proof phase, not this PR. It has been logged for the owner in
`dev-notes/inbox/findings.md`.
## Not in scope
- `ffi/rust/src/verification.rs` is a separate copy and is untouched.
- The `ShellState::root()` fallback to `/` for a non-UTF-8 root already
existed and is unchanged.
- The CLAUDE.md test-count table (736) is stale; this PR does not update
it.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01VxcAoyMQe7CjQwCKL18Mm4
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 3440d69 commit c033e9e
6 files changed
Lines changed: 743 additions & 88 deletions
File tree
- docs
- impl/rust-cli
- .cargo
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
73 | | - | |
| 72 | + | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
| 81 | + | |
83 | 82 | | |
84 | 83 | | |
85 | 84 | | |
| |||
146 | 145 | | |
147 | 146 | | |
148 | 147 | | |
149 | | - | |
| 148 | + | |
150 | 149 | | |
151 | 150 | | |
152 | 151 | | |
| |||
210 | 209 | | |
211 | 210 | | |
212 | 211 | | |
213 | | - | |
| 212 | + | |
214 | 213 | | |
215 | 214 | | |
216 | 215 | | |
| |||
273 | 272 | | |
274 | 273 | | |
275 | 274 | | |
276 | | - | |
| 275 | + | |
277 | 276 | | |
278 | 277 | | |
279 | 278 | | |
| |||
341 | 340 | | |
342 | 341 | | |
343 | 342 | | |
344 | | - | |
| 343 | + | |
345 | 344 | | |
346 | 345 | | |
347 | 346 | | |
| |||
418 | 417 | | |
419 | 418 | | |
420 | 419 | | |
421 | | - | |
| 420 | + | |
422 | 421 | | |
423 | 422 | | |
424 | 423 | | |
| |||
496 | 495 | | |
497 | 496 | | |
498 | 497 | | |
499 | | - | |
| 498 | + | |
500 | 499 | | |
501 | 500 | | |
502 | 501 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
561 | 561 | | |
562 | 562 | | |
563 | 563 | | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
| 564 | + | |
596 | 565 | | |
597 | 566 | | |
598 | 567 | | |
| |||
949 | 918 | | |
950 | 919 | | |
951 | 920 | | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
952 | 962 | | |
953 | 963 | | |
954 | 964 | | |
| |||
0 commit comments