Repository navigation
fix(glob): refuse a directory a user's pattern cannot list instead of running on a smaller set - #1505
Conversation
`trace consistency --arm LABEL=GLOB`, the session paths of `trace prefilter` and `skill novelty ground --header` / `--shared-lib` expanded their pattern with `glob.glob(pattern, recursive=True)`, which skips a directory it cannot list (mode 0o111, non-root) without an error. A trace, session or header under it was missing and the command ran on the smaller set: with `docs/top.md` and `docs/sub/a.md`, `<root>/docs/**/*.md` gave `['top.md']` once `docs/sub` was `chmod 111`. The three sites now expand with `dokimi.pattern_glob.expand`, which gives what `glob.glob(pattern, recursive=True)` gives, sorted (a wildcard skips dot names, `**` matches zero or more directories and follows links, a literal segment is statted and not listed), but raises the `OSError` of a directory the pattern has to list. Each caller turns it into its usage error (`InputError`, exit 2) naming the pattern and the directory. A directory only a literal segment passes through, or one a hidden-skipping `**` does not enter, is not listed and does not raise. The `--arm` fallback to the pattern itself when nothing matches, `~` expansion, the literal-file-first rule and the `[1]` literal path of `--header` are unchanged. The module is added to the foundation layer of the import architecture, with a line in the architecture doc, the run-consistency and grading-tiers docs, the `--arm` and `--header` help, and a changelog fragment. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s). CI at Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Leading ** patterns fail to match root-level files, silently omitting inputs from relative arm, session, and header/library expansion.
1 open issue
What changed in this PR
1 new must-fix finding.
This PR addresses #1384 by introducing shared glob expansion that rejects required directory listings that fail, rather than letting commands process incomplete input sets.
Changes:
- Route trace arms, session paths, and header/shared-library patterns through the shared helper.
- Convert listing failures into usage errors naming the affected directory.
- Add parity and permission-error tests, CLI help, and documentation.
| File | Description |
|---|---|
dokimi/tests/test_pattern_glob.py |
Adds glob parity and directory-permission tests. |
dokimi/tests/test_import_architecture.py |
Registers the helper in the foundation layer. |
dokimi/dokimi/pattern_glob.py |
Adds shared expansion with explicit listing errors. |
dokimi/dokimi/novelty/symbols.py |
Uses the helper for header and library patterns. |
dokimi/dokimi/commands/skill.py |
Documents header-pattern listing failures in help. |
dokimi/dokimi/commands/context.py |
Integrates expansion for trace arms and session paths. |
dokimi/docs/run-consistency.md |
Documents arm-pattern fallback and refusal behavior. |
dokimi/docs/grading-tiers.md |
Documents header-pattern listing errors. |
dokimi/docs/architecture.md |
Describes the shared helper and error handling. |
dokimi/changelog.d/20261201_140000_pattern-glob-unlistable.md |
Records the glob permission-handling fix. |
Review effort: Balanced
… unsearchable directory raises A leading `**/` in a user's pattern matched only the directories below the working directory, so `**/*.jsonl` left out `top.jsonl` that `glob.glob` finds. The directory-only expansion of `**` now also yields the empty prefix. The walk below `**` and the directory-only listing took a link whose target the user cannot search for a non-directory (`os.path.isdir` and `DirEntry.is_dir` caught the PermissionError), so the subtree was skipped without the promised error. They now treat only a path that is not there or a link that loops as no directory, and raise any other OSError. `_expand` is split so the literal case is its own function, and the parity fixture gains a root-level `.md` file and the patterns that reach the changed lines. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
Mutation of changed linesAt b8a9f5e: 65 caught · 15 missed Each row is a small deliberate break (a mutant) of a line this PR changes that every test reaching that line still passes. Add a test that fails on it or, if it cannot change behaviour, put
Not checked:
Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary. |
…ow an unsearchable directory raises Review points on intel#1505: directory-only expansion classified every entry before the hidden-name and wildcard filters, so a link to an unsearchable directory that the pattern skips (`runs/.hidden` under `runs/**`, a non-matching link under `runs/open*/`) raised EACCES. `_names` now takes a filter that runs before the directory check. A literal segment below a wildcard (`runs/*/sub/*.jsonl`) was checked with `os.path.lexists`, which hides EACCES, so a directory that could not be searched dropped its files without a word. It is now an lstat that raises everything but the absent-path errors. The leading `**/` zero-directory match raised in the same review is already handled at the head (60374d2) and the parity fixture holds `top.md` with `**/*.md`. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
napetrov
left a comment
There was a problem hiding this comment.
Change class: CONTRACT (head b8a9f5e)
- Contract: changed. errors dokimi/dokimi/novelty/symbols.py:183; dispatch dokimi/dokimi/pattern_glob.py:91
- Responsibility: candidate. policy dokimi/docs/architecture.md; policy dokimi/tests/test_import_architecture.py
- Dependency: none
- Review depth: check the changed surface: callers, docs, tests pin new behaviour
- Coverage gaps: none
Checked recursive, literal and hidden-name handling in the three CLI consumers. The leading / and permission propagation cases from the previous round are fixed. All 52 focused glob tests passed locally on Linux. A multi- glob now suppresses its own duplicate-path warning; the old callers already counted each file once. The Windows smoke job was still queued at review time.
@napetrov (#1505 (review)): This approval asks for no change. No commit was added this round, and the head stays at b8a9f5e. The change-class summary and the recap of the leading |
|
Review points answered at |

Summary
#1384:
trace consistency --arm LABEL=GLOB, the session paths oftrace prefilterandskill novelty ground --header/--shared-libexpand a path pattern withglob.glob(pattern, recursive=True).globskips a directory it cannot list (mode0o111, non-root user) without an error, so a trace, a session or a header under it is not in the arm, the session list or the symbol input, and the command runs on the smaller set. Withdocs/top.mdanddocs/sub/a.md, the pattern<root>/docs/**/*.mdand thenchmod 111 docs/sub:docs/subunlistable, onmain--arm x=<root>/docs/**/*.md(_trace_arms)['a.md', 'top.md']['top.md']_session_paths)['a.md', 'top.md']['top.md']--header/--shared-lib(symbols._files)['a.md', 'top.md']['top.md']Fix taken: the issue's first option. One helper,
dokimi.pattern_glob.expand, gives whatglob.glob(pattern, recursive=True)gives (sorted, a wildcard skips dot names,**matches zero or more directories and follows links, a literal segment is statted and not listed) but raises theOSErrorof a directory the pattern has to list. Each caller turns it into its existing usage error (InputError, exit 2):Error: --arm '<root>/docs/**/*.jsonl': cannot list the directory <root>/docs/sub: Permission denied. The second option (document it and warn) is not taken: it keeps the smaller input set, and the sibling fixes (#1361 and its PR,digest_entries.listed_entries) refuse.Refuted design: walking only the pattern's literal prefix with
os.walk(onerror=...)would raise for a directoryglobnever lists. A patterndocs/*/a.mdwithdocs/subat mode0o111findsdocs/sub/a.md(the next segment is literal, soglobstats it), and a**skips a hidden directory, so a walk that lists every directory under the prefix refuses inputsglobanswers correctly. The helper instead followsglob's own segment-by-segment plan and lists only what it lists.Closes #1384
Changes
dokimi/dokimi/pattern_glob.py(new, foundation layer intests/test_import_architecture.py):expand(pattern)andhas_magic. A directory that is not there (ENOENT,ENOTDIR, a link loop) lists nothing, as forglob; any otherOSErrorof a listing is raised withfilenamenaming the directory. A link into a directory the user cannot search is no longer taken for a non-directory (os.path.isdirandDirEntry.is_dirswallowed thePermissionError): the walk below**and the directory-only listing raise it. A leading**/also matches the working directory itself (**/*.jsonlfindstop.jsonl, asglobdoes).commands/context.py:_trace_arms(--arm, still falling back to the pattern itself when nothing matches) and_session_paths(~expanded and a literal file kept before any glob, as before) expand through_expand_pattern, which refuses with the directory named. The--armhelp says so.novelty/symbols.py:_filesexpands throughexpandand raisesInputErrornaming the directory; a path that exists is still read as it is (inc[1]/). The--headerhelp says so.architecture.md(shared building blocks),run-consistency.md(--arm) andgrading-tiers.md(--header).tests/test_pattern_glob.py: the helper againstglob.globon a listable tree (26 patterns, relative and absolute, hidden names, a link,**in the middle, a magic early segment,inc[[]1]), the unlistable counterexamples, and one test per site that makesdocs/submode0o111(skipped as root) and asserts the error and the directory in its message.Risk
An
--armglob, a session path glob or a--header/--shared-libglob that has to list a directory it cannot list used to give a smaller set and now exits 2 naming the directory. A listable tree gives the same matches in the same order. A directory a literal segment only passes through, or that a**skips as hidden, is not listed and does not refuse. The branch adds one row toLAYERSintests/test_import_architecture.pyand a line toarchitecture.md: open PRs #1190, #1416 and #1249 change that test file and conflict with it on merge (a one-line rebase for whichever merges second); #1190 and #1416 also change thedokimi.utilsimport line ofcommands/context.py, which this PR leaves alone.globon 3.11 to 3.14 could differ from the port in an edge not in the parity table; the table is the pinned set.The refusal message for
--shared-libnames--library: that is the existing_fileswording (the flag argument islibrary), kept here and tracked in #1504.Testing
On a Linux review host, at
b8a9f5e7(onmain9e41f5e8):make ci-local: 38 passed, 0 failed, 16 skipped (steps that need another runner, micromamba, semgrep, or a job condition false on a PR). 32140 tests passed, 27 skipped;pattern_glob.py100% line and branch coverage undertests/test_pattern_glob.py.main's code (the helper replaced by aglob.globstand-in) give6 failed, 32 passed, the first onFailed: DID NOT RAISE PermissionErrorfordocs/**/*.mdover a mode0o111docs/sub. The CLI at this head exits 2 on all three sites with the message above.ENOENTraised, a link not followed,[not a wildcard, the--armfallback dropped, each caller's catch removed, the label, the sort) fails a test of the new file.top.mdanddocs/top.md,expand('**/*.md')gave onlydocs/top.mdbefore and gives both now, asglob.globdoes; withruns/linkpointing intoprivate/subandprivateat mode0o000,expand('<root>/runs/**/*.jsonl'),runs/**andruns/*/a.jsonlraisePermissionError(they returnedruns/top.jsonlor nothing). The new tests fail on the previous head (5 failed): dropping the empty prefix fails 4 parity tests, and going back toos.path.isdir/is_dirreturning False failstest_a_link_into_a_directory_the_user_cannot_search_raises_not_skips.runs/open/a.jsonl, a linkruns/.hiddenand a linkruns/otherintoprivate/subat mode0o000,runs/**/*.jsonlandruns/open*/*.jsonlraisedPermissionErroron the link the pattern leaves out and now returnruns/open/a.jsonl;runs/o*/*.jsonl, which matches the link, still raises. Withruns/privateat mode0o000,runs/*/sub/*.jsonlgave onlyruns/open/sub/a.jsonland now raisesPermissionError; at mode0o111it returns both files. The two new tests fail against the previous head'spattern_glob.py(2 failed, 49 passed); deleting theos.lstatof the new literal-segment check fails the parity casea/*/d.txt. The root-level**/*.mdmatch raised in that round was already fixed at60374d22and is in the parity table (top.md,**/*.md).ci-localstep), at this head: 80 of 100 mutants run (cap 80), 65 killed, 15 survived, in theexc.strerror or excfallbacks, theFalsereturns for an absent path (a listing of one gives nothing either way) and thedirs/dironlyplumbing ofpattern_glob.py; none is waived.fix/unlistable-root-globs,fix/sandbox-cleanup-unlistable,fix/novelty-out-dir-unlistableonmainbcb1f9f:pytest -n auto32223 passed, 27 skipped,mypyclean,ruff checkclean.Open questions
None.
Revert
A plain revert restores
glob.globat the three sites. Nothing is stored.Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to [the tests and the fragment cite glob.glob of a user's pattern skips a directory it cannot list: trace --arm, session paths, --header and --library #1384; theraiselines do not].github/.licenserc.yaml)