Repository navigation
fix(sieve): resolve case-exact file probes and deduplicate contents (fixes #645) - #658
i-am-paradox wants to merge 1 commit into
Conversation
Marc-cn
left a comment
There was a problem hiding this comment.
Thanks, the approach is the one #645 asks for and the core of it reads right: case-exact traversal against os.listdir, the listing cache keyed by directory mtime, dedup by (st_dev, st_ino). 160 tests pass here.
Two things before merge:
- Please drop the unrelated reformatting. In
core/utils.pyabout 60 of the 169 changed lines are untouched code rewritten by a formatter (quotes, joined argument lists, split f-strings), andsieve/builtin_handlers.pyhas the same. The project isn't formatted withruff format, and these hunks hide the real change and conflict with every other PR touching those files. - The TOML change isn't only about case: to stay at 5 entries,
files_to_includedropsdocs/design.md(OSPS-SA-01.01) andswagger.json(OSPS-SA-02.01), so the LLM step stops reading those. @mlieberman85, that's a content call for you; if those files should stay, the uppercase variants could go intodiscover/filesonly.
Note for Mike: this edits discover_files in config/discovery.py, which #630's notes mark for removal after #622.
|
Thanks @Marc-cn! Addressed both points in 0c37b6c:
All 160 tests in |
…ixes darnitdevorg#645) On case-insensitive filesystems (such as macOS APFS and Windows NTFS), os.path.exists() and open() match lowercase file probes against uppercase files in the repository. As reported in darnitdevorg#645, this causes sieve handlers to: 1. Match candidate probes that don't match the repository's actual case. 2. Read duplicate file contents in llm_eval_handler and llm_extract_handler when files_to_include or files specify both case variants. 3. Cite paths in audit evidence that do not exist under exact case in the repo. Changes: - Added resolve_case_exact_path(path, root=None) in darnit.core.utils. - Cached directory entries via _dir_entries(dir_path) keyed by st_mtime_ns. - Added get_file_identity(full_path) returning (st_dev, st_ino) for physical file deduplication. - file_exists_handler: verifies exact case for globs, max_depth walks, and direct path lookups while preserving repository containment. - _resolve_regex_files & _regex_exclude_evidence: ensures exact case matches and deduplicates by physical file identity. - llm_eval_handler & llm_extract_handler: enforces case-exact paths and deduplicates opened files before adding to file_contents. - discover_files: verifies case-exact paths before returning mapped references. - openssf-baseline.toml: added docs/ARCHITECTURE.md and docs/API.md variants to discover and files. - Unit and regression tests covering case-exact path validation, deduplication, and case-mismatched rejection. Fixes darnitdevorg#645 Signed-off-by: Paradox <159635503+i-am-paradox@users.noreply.github.com>
0c37b6c to
c91e235
Compare
|
Both of my points are addressed: the formatting churn is gone and files_to_include matches main. The case-exact walk only filters candidates, the reads still go through the #635 containment, so the two compose. @mlieberman85: the uppercase variants added to the Baseline discover/files lists, and whether a 400-line change for case-insensitive filesystems is wanted given darnit mostly runs in Linux containers. The dedup of contents is the part I'd keep regardless. |
Summary
Fixes #645.
On case-insensitive filesystems (such as macOS APFS and Windows NTFS),
os.path.exists()andopen()match lowercase file probes against uppercase files in the repository. As reported in #645, this causes sieve handlers to:docs/architecture.mdwhen onlydocs/ARCHITECTURE.mdexists).llm_eval_handlerandllm_extract_handlerwhenfiles_to_includeorfilesspecify both case variants (such asREADME.mdandreadme.md).Key Changes
Case-exact Directory Entry Validation:
resolve_case_exact_path(path, root=None)indarnit.core.utilsto traverse each path component and verify it exists verbatim in the actual directory entries (os.listdir), ensuring exact-case matching across all platforms._dir_entries(dir_path)keyed byst_mtime_ns, ensuring zero subprocess overhead while automatically invalidating if remediation or user edits write files to disk.get_file_identity(full_path)returning(st.st_dev, st.st_ino)for physical file deduplication across paths, symlinks, or aliases.Sieve Handler Updates:
file_exists_handler: verifies exact case for globs,max_depthwalks, and direct path lookups._resolve_regex_files&_regex_exclude_evidence: ensures exact case matches and deduplicates candidate files by physical file identity.llm_eval_handler&llm_extract_handler: enforces case-exact paths and deduplicates opened files before adding them tofile_contents.Config & Baseline Alignment:
discover_files: verifies case-exact paths before returning mapped references.openssf-baseline.toml: updatedOSPS-SA-01.01andOSPS-SA-02.01to probedocs/ARCHITECTURE.mdanddocs/API.md(and.rstvariants) while strictly adhering to the 5-file cap forfiles_to_include.Testing:
tests/darnit/core/test_utils.pyforresolve_case_exact_pathandget_file_identity.tests/darnit/sieve/test_builtin_handlers.pyforfile_exists_handler,regex_handler, depth-limited walks, andllm_eval_handlercase rejection & deduplication.tests/darnit/config/test_discovery.pyverifying case-mismatched files are not discovered.tests/darnit(3,660 passed),tests/darnit_baseline(1,093 passed), andruff check(all clean).