Repository navigation
fix(index): never write through a link inside the index directory - #362
Merged
Merged
Conversation
Add unit tests (Unix only) for the three temp records the daemon writes next to daemon.pid before renaming one into place: the claim's daemon.pid.<pid>.tmp, the socket rewrite's daemon.pid.<pid>.bound and the republish's daemon.pid.<pid>.reassert. Each name is planted as a link to a file outside the index directory, or as a dangling link to a path there. After the write the outside file is unchanged, the dangling target does not exist, nothing new appears outside, and daemon.pid is a regular record naming this process. On the current tree all six cases fail: the record is written into the outside file, or the dangling target is created.
- resolve_project_file refuses a path that does not exist yet when its nearest existing ancestor is a link out of the root, or a dangling link; a missing path below real directories still passes. - With .codegraph/ui linked to a directory outside the project that has no trails yet, a save creates nothing out there. - A link at the save's temp file name, to an outside file or a dangling path, is neither written through nor renamed into place: the outside file is unchanged, nothing is created, and the saved trail is a regular file. - A <id>.json in the trails directory that links to an outside file that parses as a trail is not listed and not read. On the current tree every case fails: the missing paths pass the lexical check, the save creates trails/ outside the project, the temp file write goes through the link, and the linked trail is listed with its note.
Add crates/codegraph-cli/tests/index_root_links.rs (Unix only). Each case plants one name under .codegraph/ that the full index or a daemon start writes by name (the edge and reference spill files, daemon.log, the diagnostics directory) as a link to an existing file outside the project, a dangling link, or (Linux) a link to /dev/zero, or a spill as a FIFO. It then runs init --debug, status, sync after an edit, search, a daemon-mode MCP session and uninit --force in child processes under a 20 s deadline and a 2 GiB address-space cap. Every command finishes, stays under 200 MiB and exits 0; afterwards nothing outside the project changed, no new entry appeared there, and no dangling target was created. A combined case links all four names, .gitignore and writer.pid at once. A guard covers a .codegraph that is itself a link out of the project: init --debug and sync --debug are refused and leave that directory as it was. It passes on the current tree. On the current tree the other cases fail, except daemon.log linked to /dev/zero, which passes: the spills are written into the outside file or create the dangling target, a FIFO spill blocks init past the deadline, a spill linked to /dev/zero is read without bound, daemon.log is appended to or created outside, the debug log is created in the outside directory, and init --debug fails when diagnostics is a dangling link or a link to /dev/zero.
The full index's two spill files are created fresh, replacing whatever held their names, and read back through the same handles instead of being reopened by path. A debug log in the index directory goes only into a real diagnostics directory as a new file; otherwise it stays beside the index directory with a warning. A log moved there keeps its open handle on Unix and is reopened as a regular file only on Windows.
…wing a link The temp records renamed over daemon.pid (.tmp, .bound, .reassert) are created fresh, so whatever already holds their predictable names is replaced rather than written through. daemon.log is appended to only as a regular file; anything else there sends the daemon's output to the null sink with a warning.
… to one A missing project path is accepted only when the nearest entry that exists above it resolves inside the project, and an entry that does not resolve, such as a dangling link, is refused, so the trails directory is never created outside the project. Saved trails are listed and read only as regular files themselves, and a trail's temp file is created fresh before the rename.
…ollowing a link Document codegraph-core's managed_file helpers and their callers, and how the index spill files, daemon.log, the default debug log directory, the temporary daemon records and saved trails behave when an entry in the index directory is a link, a FIFO or a directory. Describe the viewer's checks on the trail directory and on the trail files it lists.
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (94.83%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage. @@ Coverage Diff @@
## main #362 +/- ##
========================================
Coverage 96.41% 96.42%
========================================
Files 369 370 +1
Lines 256165 256629 +464
========================================
+ Hits 246989 247445 +456
- Misses 9176 9184 +8
... and 3 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Merged
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.
Summary
.codegraph/) are no longer written through whatever already holds that name. A newcodegraph-coremodule,managed_file, creates such a file fresh (an entry already at the name, such as a link or a FIFO, is replaced rather than followed), appends only to a regular file, and accepts only a real directory where a directory is expected.daemon.logis appended to only when it is a regular file; anything else there sends the daemon's output to the null sink with a warning. The temporary records renamed overdaemon.pid(.tmp,.bound,.reassert) are created fresh..codegraph/diagnostics/only when that is a real directory, as a new file; otherwise it stays beside the index directory with a warning.The stored graph does not change: no extraction-version move.
docs/architecture.md,docs/cli.md,docs/troubleshooting.mdanddocs/ui.mddescribe the behavior.This follows #360 (merged as 97fa800) and uses its regular-file readers.
Tests
Each new test was run on the base first and failed there for the reason it targets; the two guards noted below pass on the base by design.
crates/codegraph-cli/tests/index_root_links.rs(Unix): each case plants one name under.codegraph/that the full index or a daemon start writes by name (the edge and reference spill files,daemon.log, the diagnostics directory) as a link to an existing file outside the project, a dangling link, a link to/dev/zero(Linux), or a spill as a FIFO. It then runsinit --debug,status,syncafter an edit,search, a daemon-mode MCP session anduninit --forcein child processes under a 20 s deadline and a 2 GiB address-space cap. Every command finishes, stays under 200 MiB and exits 0, nothing outside the project changes and no dangling target is created. A combined case plants all four names at once. Guards:daemon.loglinked to/dev/zero, and a.codegraphthat is itself a link out of the project (init --debugandsync --debugare refused and leave that directory as it was).codegraph-daemonunit tests for the three temp record names, each planted as a link to an outside file or as a dangling link.codegraph-uiunit tests forresolve_project_fileandtests/trails.rscases for a linked trails directory, a link at the temp file name, and a linked trail file.codegraph-coreunit tests formanaged_file.Verification
cargo fmt --all --check,cargo clippy --workspace --all-targets --locked -- -D warnings, and the same clippy cross-compiled forx86_64-pc-windows-msvc.tests/trails.rs19), codegraph-rs 3201 passed.scripts/regen-goldens.sh --check: 32 corpora identical.Cargo.lockdependency bump and a one-line docs fix beneath it; the pre-push gate (make pre-ci) ran again on the rebased head.