Repository navigation
ci(test): shuffle the unit suite with a printed seed, and create the vcn evidence dir 0700 - #386
Conversation
Three spec loops built their tests from pairs() over string keys. LuaJIT randomizes string hashing per process, so those tests ran in a different order in each run, even with busted --seed. Before this change, 30 runs with --shuffle --seed=7 put 14 tests in more than one order. After it, all 30 runs give the same order. Part of #385 _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
mise run test, which the unit-tests job runs, now passes --shuffle and a seed to busted. The seed is BUSTED_SEED when set, else the current time, and the task prints it with the command that repeats the order. A seed that is not a non-negative integer stops the task with exit 2, because busted would silently pick another one. On main, the suite passes with --shuffle for each of the seeds 1 to 100. Part of #385 _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…ivate The out-made-unsafe case expected launch to refuse a new VERIFY_OUT in a dir with a default ACL, because mkdir made it 0770. The new out-made case expects launch to create it as 0700 and keep every evidence file 0600. On main it fails: "refusing evidence dir: .../acl/out is group- or world-writable". Part of #385 _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
launch made the evidence dir with mkdir -p and set 0700 only later. Under a parent with a default ACL, mkdir(2) got mode 0777, so the new dir was group-writable until the chmod: the default parent case allowed that for a moment, and a new VERIFY_OUT was refused. mkdir -p -m 700 now passes 0700 to mkdir(2) for the evidence dir itself. SKILL.md names the new proof case and gives the measured proof time, 58 s in three runs. Part of #385 _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…dir only SC2174 warns that with -p, -m applies only to the deepest dir. That is the intent: the safety check after mkdir covers the parents. Part of #385 _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…, #388, #390 The merge keeps this branch's bulk-close cases on main's ordered bulk_closes list (#386). Main changed selection.lua, utils.lua, and visual_commands.lua, which cannot reach diff state. check.sh passes on the merged tree. Part of #363 _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
… end check_test_order.sh keeps an in_loop flag instead of reading an empty indent as "not in a loop", and a loop ends at an end at its indentation that only a comment follows. The new spec passes, and the check still flags the three loops that #386 fixed in the tree before #386. Part of #393 _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…scanning check_test_order.sh read the source text, and each review round found another shape it misread: a top-level loop, end with a comment, a one-line loop, test-like text in a long string. The order problem is a run-time fact, so check it at run time instead. tests/helpers/test_order.lua is a busted helper that .busted loads for every busted run, mise run test included. When a spec registers a test, it walks the stack, and in each frame of a file under tests/ it looks for a generic for loop whose iterator is next, which pairs() returns. If it finds one, the registration fails with the loop's file and line. On the tree before #386 it flags the three loops that #386 fixed, and on main it flags visual_commands_select_mode_spec.lua. It adds about 1 s to the suite under coverage. The script, its spec and its mise run check step are gone. Part of #393 _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…er#390) ## Why The operator goal is to clear the open follow-up issues in this repository (coder#385 now) with small reviewed PRs. This PR takes the inbound part of coder#385 item 6. Items 7 and 8 are in coder#386. RFC 6455 requires an endpoint to close a connection with 1007 when a text frame or a close reason is not valid UTF-8. The plugin's inbound check, `server/utils.lua` `is_valid_utf8`, took any lead byte from C0 to FF with the right number of continuation bytes. So it let through overlong forms, UTF-16 surrogates, code points above U+10FFFF, and the bytes F5 to FF. The plugin then decoded the request and ran it. The outbound side already has a strict decoder, `claudecode.utils.utf8_sequence_length` (behind `valid_utf8`, since coder#378). This PR makes the inbound check use that decoder. The outbound part of item 6 does not change: a buffer name with invalid bytes still reaches Claude as U+FFFD, as `lua/claudecode/server/README.md` documents. ## What changed - `lua/claudecode/server/utils.lua`: `is_valid_utf8` walks the text with `utils.utf8_sequence_length` and returns `false` at the first ill-formed sequence. `frame.parse_frame` (text frames and close reasons) and `frame.validate_frame` call it as before. - `tests/unit/server/frame_spec.lua`: seven text-frame cases and one close-reason case that must get 1007, and one frame with the first and last code point of each UTF-8 length that must still parse. - `lua/claudecode/server/README.md`: the 1007 invariant names what counts as ill-formed. - `.agents/skills/verify-diff-lifecycle/covered.lock`: re-recorded. Only the `server/utils.lua` file hash changed, with no covered block or call site. A rejected frame closes the connection through the same `on_disconnect` path as any other close, and the model already lets a client disconnect at any step. ## Scope coder#385 item 6, inbound only. No change to what the plugin sends. ## Blast Radius A client that sends ill-formed UTF-8 now gets Close 1007, where the plugin used to run its request. Claude Code cannot send such bytes: it serializes each message with `JSON.stringify`, which escapes a lone surrogate as `\uD800`, and its WebSocket sends a JS string as UTF-8. The real CLI run below shows that its non-ASCII text still goes through. ## Verification | Run | Code | Result | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `busted tests/unit/server/frame_spec.lua` (red) | 29e3185, the tests on main | 8 failures: each ill-formed case gets no 1007 | | Same (green) | this PR | 25 successes. `mise run test`: 908 successes, 0 failures | | Raw WebSocket client, one masked text frame each, real Neovim 0.12.3 (`verify-claudecode-nvim` harness) | main (17f53b3) | `ED A0 80`, `C0 AF`, `F4 90 80 80` and `F5 80 80 80` each get a `getDiagnostics` answer. The plugin ran the call with the ill-formed path | | Same | this PR | each of those four gets `Close frame, code 1007`. A frame with `F0 9F 98 80` (😀) still gets its answer, and the plugin keeps its other client | | Real Claude CLI 2.1.312, `claude -p --model haiku` with the plugin as an MCP server over the CLI's own WebSocket transport, asked to call `getDiagnostics` for `file://…/naïve-日本-😀.txt` | main | the plugin logs `getDiagnostics arguments: {uri=50 bytes}` and finds the open buffer. Claude replies `ünïcode ✓ diagnostic`, the diagnostic set on that buffer. The CLI closes with 1000 | | Same | this PR | the same: `uri=50 bytes`, reply `ünïcode ✓ diagnostic`, close 1000 | | 10 MB through `is_valid_utf8` in LuaJIT 2.1, best of 3 | main / this PR | ASCII 10.6 / 10.6 ms. Mixed text 16.2 / 13.7 ms. CJK 31.8 / 27.2 ms | | `verify-diff-lifecycle/check.sh` | this PR (15afbfd) | `PASS`. `main: pass (89205 distinct states found)`, `live: pass (5269 distinct states found)` | <details> <summary>How the real CLI run works</summary> `claude -p --ide` does not connect to an IDE in print mode. So the script hands the CLI an `--mcp-config` file with an MCP server of type `ws` at the plugin's port. The lock file's token is in the `x-claude-code-ide-authorization` header. The CLI's IDE transport (`ws-ide`) and this one build the same `WebSocket(url, { protocols: ["mcp"], headers })` and the same transport class, so the bytes on the wire come from the same code. The run uses its own `HOME` and `CLAUDE_CONFIG_DIR` under the harness state dir, and `ANTHROPIC_API_KEY` for one haiku request. The 50-byte `uri` is the UTF-8 length of `file:///tmp/vcn.<id>/work/naïve-日本-😀.txt`. </details> Part of coder#385 --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…-ordered tests (coder#400) ## Why The operator goal is to clear the open follow-up issues in this repository (coder#393 now) with small reviewed PRs. This PR takes coder#393 item 7. Item 6 is in coder#395. 1. **New dirs above `VERIFY_OUT` were refused under a default ACL.** Since coder#386, `vcn.sh launch` created the evidence path with `mkdir -p -m 700`, which sets only the last dir's mode. Under a parent with a default ACL, each new dir above it got the ACL's mode (`770`), and the check after `mkdir` refused the run. This hit a `VERIFY_OUT` more than one level below such a dir. It also hit a new default parent dir (`verify-claudecode-nvim`) under such an `XUM_SCRATCH_DIR`. I fixed it instead of documenting it, because the fix is one loop. 2. **Nothing stopped a spec from registering tests in `pairs()` order.** LuaJIT seeds its string hash in each process, so `pairs()` visits string keys in a different order in each run. A spec that registers tests from such a loop runs them in a different order each time, and the seed that `mise run test` prints does not repeat that order. coder#386 fixed three such loops. A fourth one came in with coder#388 (`visual_commands_select_mode_spec.lua`): in 12 runs, its three tests came in three different orders. ## What changed - `vcn.sh`: launch runs `mkdir -m 700` on each missing dir of the evidence path, shallowest first. This replaces the `mkdir -p -m 700` and its `shellcheck disable`. Two other changes come with it: - If another launch makes a missing parent dir first, launch uses that dir, and the check after `mkdir` decides whether it is safe. Before, `mkdir -p` accepted such a dir. - Launch now keeps a list of only the dirs it made itself. On a failure or a refusal, it removes those dirs and never one that another process made. - `proof-launch-refusals.sh`: - `out-made` puts `VERIFY_OUT` two levels below the default-ACL dir and also checks the middle dir's mode. - `parent-made-unsafe` expected the old refusal of a new default parent dir, so I removed it. That dir now goes through the same code as `out-made`'s middle dir. - `race` (new) puts a `mkdir` shim on `PATH`. The shim plays another launch that makes the dir above `VERIFY_OUT` first, group-writable. Launch must refuse that dir in the check after `mkdir` and leave it in place. - `SKILL.md`: the creation mode and the ACL cases. - `tests/helpers/test_order.lua` (new) is a busted helper, and the new `.busted` file loads it for every busted run, `mise run test` included. When a spec registers a test (`describe`, `it` or `pending`), the helper walks the stack. In each frame of a file in this repository's `tests/` dir, it looks for a generic `for` loop whose iterator is `next`, which is what `pairs()` returns. If it finds one, the registration fails with `<file>:<line> registers "<name>" inside a pairs() loop; loop over an array with ipairs`. Because it checks at run time, it does not depend on formatting, comments, one-line loops or strings. - `tests/unit/test_order_helper_spec.lua` (new) tests the helper. It covers a loop in the spec, a loop in a calling frame, a loop in code outside the `tests/` dir, an `ipairs` loop, and a registration after a loop. - `tests/unit/visual_commands_select_mode_spec.lua`: the three cases come from an array now. - `DEVELOPMENT.md`, `AGENTS.md` and `README.md` (System Verification): the rule and the guard. Codex round 1 found two holes in my first version, a text scan (`scripts/check_test_order.sh`). Round 2 found two more. So I replaced the scan with the run-time check, and the script is gone. Round 3 found the remaining two issues: the helper counted any path with a `tests/` part, and launch aborted when it lost the race for a parent dir. Both are fixed. ## Scope coder#393 item 7. No plugin code changes. ## Blast Radius - **People and agents who run `vcn.sh launch` under a dir with a default ACL.** A deeper `VERIFY_OUT`, or a new default parent dir, now works and starts private, where launch refused it before. - **Contributors.** A spec that registers tests inside a `pairs()` loop now errors in `mise run test`, and in any `busted` run from the repo root. The error names the file and line. - **Run time.** The helper adds about 1 s to the suite under coverage. In two pairs of runs it took 15.8 s against 14.6 s, and 16.9 s against 15.7 s. ## Verification | Run | Code | Result | | ------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `VERIFY_OUT=<0700 dir with default ACL g::rwx>/mid/deeper/out vcn.sh launch` | main (c05a629) | exit 1: `…/mid/deeper, above the evidence dir, is writable by others and not sticky`. The dirs it made are removed | | Same | this PR | launch works. After cleanup, `mid`, `mid/deeper` and `out` are `700`, and every evidence file is `0600` | | `XUM_SCRATCH_DIR=<0700 dir with that ACL> vcn.sh launch` (new default parent dir) | main | exit 1: `…/verify-claudecode-nvim is group- or world-writable` | | Same | this PR | launch works, and `verify-claudecode-nvim` is `700` | | `VERIFY_OUT=<dir>/a/<300-character name>` | this PR | `cannot create …`. The proof dir is empty afterwards, so the `a` that launch made is removed again | | `proof-launch-refusals.sh` (red) | 9575ee0, the new `out-made` on main's `vcn.sh` | `FAIL: out-made: launch failed: vcn: refusing evidence dir: …/acl/mid, above the evidence dir, is writable by others and not sticky` | | `race` case alone (red, Codex round 3 finding) | 3392cd6, the case on b5c7ec4's `vcn.sh` | exit 1: `cannot create …/race/mid/out` | | `race` case alone | this PR | exit 1: `…/race/mid, above the evidence dir, is writable by others and not sticky`. `mid` stays, and `mid/out` is gone. With a shim that makes `mid` `0700`, launch starts the run | | `proof-launch-refusals.sh` (green) | this PR (882da0f) | all 18 cases `PASS` in 78 s on a busy host (56 s before the `race` case, which starts no run), with an empty `TMPDIR` afterwards | | The whole suite with the helper | the tree of bf80d11 (main before coder#386) | 3 errors: `native_terminal_toggle_spec.lua:523` and `:969` and `diff_bulk_close_reentrancy_spec.lua:71`, the three loops coder#386 fixed | | `busted tests/unit/visual_commands_select_mode_spec.lua` with the helper | main's spec (c05a629) | error: `visual_commands_select_mode_spec.lua:24 registers "runs the visual handler for a charwise Select-mode selection" inside a pairs() loop; loop over an array with ipairs` | | Same | this PR | 3 successes | | 12 runs of that spec, test order | main / this PR | 3 different orders / 1 order | | `tests/unit/test_order_helper_spec.lua` with each of two helper mutants (never match `next`, never match a `tests/` frame) | this PR | each: 1 success, 2 failures | | Checkout and rocks copied under `<scratch>/tests/claudecode.nvim`, `busted tests/unit/config_spec.lua` (Codex round 3 finding) | d49b31e / this PR | 1 error / 16 successes | | `mise run check`, `mise run test` | this PR (5df456a, with main up to coder#396 merged) | pass. 967 successes, 0 failures | Gates on 5df456a: `stylua --check`, `prettier --check`, `shellcheck`, `shfmt -d` and `treefmt --ci` pass. This PR changes no file under `lua/` or `plugin/`. On 5df456a, `verify-diff-lifecycle/check.sh` reads STALE only for main's own unrecorded `selection.lua`, `tools/open_file.lua` and `visual_commands.lua` changes (coder#396, coder#397). coder#395 re-records them. Part of coder#393 --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Why
The operator goal is to clear the open follow-up issues in this repository (#385 now) with small reviewed PRs. This PR takes #385 items 7 and 8. Item 6 (strict inbound UTF-8) changes the server, so it gets its own PR.
busted --shufflefor each seed from 1 to 100, and every run passed, so the unit job can shuffle now. One problem showed up first: the same seed did not give the same order. Three spec loops registered their tests frompairs()over string keys. LuaJIT randomizes string hashing per process, so those tests ran in a different order in every run, with or without--shuffle.vcn.sh launchcreated$OUTwithmkdir -pand set0700later. Under a parent dir with a default ACL,mkdir(2)got mode0777, so the new dir was770until thechmod. For the default parent dir, launch accepted that and fixed it a moment later. A newVERIFY_OUTin such a dir was refused instead. SKILL.md also said the refusal proof takes about 30 s.What changed
mise.tomltesttask: busted runs with--shuffle --seed=<seed>. The seed isBUSTED_SEEDwhen set, else the current time. The task printsTest order seed: <seed> (rerun this order with BUSTED_SEED=<seed> mise run test). ABUSTED_SEEDthat is not a non-negative integer stops the task with exit 2, because busted would silently pick another seed.tests/unit/native_terminal_toggle_spec.lua(two loops) andtests/unit/diff_bulk_close_reentrancy_spec.lua: the tables are arrays now, so the tests register in a fixed order. The test bodies are unchanged.README.md(System Verification),DEVELOPMENT.mdandAGENTS.md: the random order andBUSTED_SEED.vcn.sh:mkdir -p -m 700 "$out", somkdir(2)gets0700for the evidence dir itself. Its parents are made as before, and the safety check aftermkdirstill covers them. Ashellcheck disable=SC2174says why-mapplies only to the deepest dir.proof-launch-refusals.sh: theout-made-unsafecase, which expected a refusal, is nowout-made. It expects launch to create a newVERIFY_OUTin a dir with a default ACL as0700, with only0600evidence files.out-aclandout-madeshare one helper.SKILL.md: the creation mode, the new case, and the measured proof time (about 60 s).Scope
#385 items 7 and 8. No plugin code changes. The integration-tests job keeps its order.
Blast Radius
mise run test, and the unit-tests CI job, now gets a random test order. A new order-dependent test fails some runs, and the printed seed repeats the failing order.vcn.sh launchunder a dir with a default ACL. A newVERIFY_OUTthere now works and starts private, where it was refused before.Verification
busted --shuffle --seed=Nfor N = 1..100busted --shuffle --seed=7, TAP order compared--shuffleare identical too--shuffle, seeds 1, 2 and 5 fail and 3, 4 and 6 pass, the same way on a second runBUSTED_SEED=abc mise run testBUSTED_SEED must be a non-negative integer, got 'abc'mise run testTest order seed: 1793512541 …, 899 successes, 0 failuresunit-testsjobTest order seed: 1793512832 (rerun this order with BUSTED_SEED=1793512832 mise run test), 899 successes, 0 failuresstrace -e trace=mkdirofvcn.sh launch,VERIFY_OUTin a0700dir with default ACLg::rwxmkdir(".../out", 0777), then launch refuses:.../out is group- or world-writablemkdir(".../out", 0700), launch works, and all 9 evidence files are0600XUM_SCRATCH_DIR) with that ACLmkdir(".../verify-claudecode-nvim/<time>-<id>", 0700)mkdir -pandmkdir -p -m 700in that dir,umask 0770777gives770,0700gives700proof-launch-refusals.sh(red)vcn.shFAIL: out-made: launch failed: vcn: refusing evidence dir: …/acl/out is group- or world-writableproof-launch-refusals.sh(green), three runsPASSin 58 s, 58 s and 58 s, with an emptyTMPDIRafterwards. Main's proof took 47 s, and the newout-madecase starts one more real runGates on 4596f49:
mise run check,mise run test,stylua --check,prettier --check,shellcheck,shfmt -dandtreefmt --cipass.verify-diff-lifecycle/check.shpasses, because no file underlua/orplugin/changed.Part of #385
Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:xhigh