Repository navigation
fix: a directory a walk cannot list is an error, not a smaller tree, in select_docs, the skill link check and catalog provenance - #1636
Conversation
…st (intel#1383) select_docs expanded each include pattern with Path.glob, which skips a directory it cannot list (mode 0o111, non-root) without an error. With docs/top.md and docs/sub/a.md, include docs/**/*.md and docs/sub unlistable, it returned top.md alone, and min_docs and max_docs were checked against that smaller count. Each include pattern's walk is now checked for a directory it has to list: an unlistable one raises DocSelectionError naming it. A directory the exclude list drops, one no match can lie under, a path the pattern only names, a path that is not there and a link that leaves the root are not listed by the pattern and stay no error. The check is a new helper, apart from _outside_links. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…ntel#1479) _check_links walked the skill with os.walk and no onerror, so a link out of the skill inside a hidden or vendored folder that cannot be listed (mode 0o111, non-root) was never checked. check_skill returned the name, and build_plugin then failed in the copy with a shutil.Error instead of the ValueError the other refusals raise. _check_link_loops returned on the same OSError, leaving it to the copy. Both now raise a ValueError naming the folder, before the copy. A folder load_skill already refuses (any but a dot-named, vendored or __pycache__ one) is left to it, so its error is unchanged. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…ist (intel#1480) Since the scan gives an error row for a directory above the skills that cannot be listed, catalog provenance dropped it at the _skill_file(...) is None branch: the skills under that directory were missing from the table and its summary, with no note. Such a row (unlisted, with an error, its path a directory with no SKILL.md) now raises an InputError naming the directory, before any row is printed, with or without a skills.yaml. A manifest entry with no file, and a skill whose own folder cannot be listed, keep their behaviour. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…rror (intel#1383) The unlistable-directory check resolved the include pattern's base link with no guard, so a link that loops, where resolve raises RuntimeError (Python before 3.13) or OSError, escaped select_docs instead of giving the min_docs error. A link that resolve cannot follow leads nowhere, so the check now treats it as not walked and goes on. Tests cover the resolve failure and a loop below the pattern's base. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
There was a problem hiding this comment.
🟡 Changes recommended
Directory traversal mishandles exclusions and symlinks, causing false errors or silently missed documents, while unreadable loader-excluded subdirectories can pass validation and fail during plugin builds.
4 open issues
What changed in this PR
4 new findings.
This PR makes dokimi report directories it cannot list instead of silently accepting incomplete document sets, skill checks, or provenance tables.
Changes:
- Add listing-error handling to document selection, skill validation, and catalog provenance.
- Add regression tests for permissions, exclusions, and symlink behavior.
- Document the error behavior and add changelog fragments.
| File | Description |
|---|---|
| dokimi/tests/test_skill_links_unlistable.py | Tests skill validation before copying. |
| dokimi/tests/test_select_docs_unlistable.py | Tests listing failures and selection boundaries. |
| dokimi/tests/test_select_docs_link_loops.py | Tests looping-link handling. |
| dokimi/tests/test_provenance_unlistable.py | Tests provenance refusal and preserved behavior. |
| dokimi/README.md | Documents benchmark listing errors. |
| dokimi/dokimi/runner/spec.py | Adds document-tree listing validation. |
| dokimi/dokimi/harnesses/skill_treatment.py | Handles listing failures in link checks. |
| dokimi/dokimi/commands/catalog_provenance.py | Refuses incomplete provenance scans. |
| dokimi/docs/external-content.md | Documents provenance exit behavior. |
| dokimi/docs/coding-harnesses.md | Documents skill-folder refusal. |
| dokimi/changelog.d/20261204_100200_provenance-unlistable.md | Records the provenance fix. |
| dokimi/changelog.d/20261204_100100_skill-links-unlistable.md | Records the skill-check fix. |
| dokimi/changelog.d/20261204_100000_select-docs-unlistable.md | Records the document-selection fix. |
Review effort: Balanced
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s). CI at Review limit reached. This PR has had 6 reviews, so it will only be reviewed again when you ask. Test notes (3)
Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1636 +/- ##
==========================================
+ Coverage 96.47% 96.49% +0.02%
==========================================
Files 561 569 +8
Lines 74345 75325 +980
Branches 12840 12996 +156
==========================================
+ Hits 71722 72686 +964
- Misses 1605 1611 +6
- Partials 1018 1028 +10
🚀 New features to boost your workflow:
|
napetrov
left a comment
There was a problem hiding this comment.
Change class: CONTRACT (head aa75ca1)
- Contract: candidate. errors dokimi/dokimi/commands/catalog_provenance.py:95; errors dokimi/dokimi/harnesses/skill_treatment.py:151
- Responsibility: none
- Dependency: none
- Review depth: check the changed surface: callers, docs, tests pin new behaviour
- Coverage gaps: none
Open issues to resolve on aa75ca18.
- On a non-root Linux run, the base selects the visible document when a separate include targets an excluded directory. The head raises DocSelectionError while listing the excluded directory. Earlier finding
- The base reads a named file through an in-root alias to a searchable directory. The head attempts to list that directory and raises DocSelectionError. Earlier finding
Reviewed the diff, edge cases and prior threads. Focused tests: 23 passed on head. The full local suite was outside coverage.
…s and no more select_docs now walks an include pattern as Path.glob does: a literal part is entered (through a link too) and the last literal name is looked up, not listed, a wildcard part lists and follows a link to a directory, `**` lists and skips links. A directory outside the root or dropped by the exclude list is not listed, at the start of the walk as below it. So `alias/a.md`, `docs/*/a.md`, `../outside/**/*.md` and an include whose base the exclude list drops no longer raise, and a directory reached through a link by `docs/*/*.md` is listed (review threads on spec.py). The skill link check leaves to load_skill only a folder it names: one under a `__pycache__` it leaves out is refused by the link check, as the copy would fail on it (skill_treatment.py thread). catalog provenance treats a folder it cannot even search (mode 000) as holding no SKILL.md instead of raising PermissionError from the probe (catalog_provenance.py thread). Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@napetrov (#1636 (review)): Its two open points are the threads 4806872319 (a directory the exclude list drops, where a literal path starts) and 4806872244 (a named file through an in-root link); both are fixed in 622bcdd, with the repros and tests in those replies. |
provenance: a folder that cannot be listed and holds a directory or a dangling link named SKILL.md passed the exists() check of _holds_skill_file, so _skill_file dropped its row and the skills beside it went unseen; the check is now is_file(), the test _skill_file applies. select_docs: an unlistable directory the exclude list matches itself but not the files below it (docs/[s]ub) was pruned before listing, while its files stay selected on a listable tree; it is pruned only when the exclusion also covers a file below it, and otherwise raises. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…exclude list covers its whole subtree An exclude such as `docs/*/x` matched the synthetic name `docs/sub/x`, so an unlistable `docs/sub` holding `a.md` was pruned and `select_docs` returned `top.md` alone with no error, while the listable tree selected both. The walk now prunes a directory only when an exclude entry names it or a parent (`docs/sub`, `docs/sub/**`) or ends in `*` and matches it (`docs/s*`). catalog provenance: cover the `OSError` branch of the SKILL.md lookup, which Python 3.11 and 3.12 raise for a folder with mode 000, with a test that makes `is_file` raise it. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…e ending in /* covers Review point: `exclude=["docs/sub/*"]` drops every file below `docs/sub`, but `_excludes_subtree` matched the directory name `docs/sub` against the pattern, which fnmatch refuses, so an unlistable `docs/sub` raised DocSelectionError. A pattern that ends in `*` is now matched against the directory plus a `/`, so `docs/sub/*` and `docs/*/*` count as covering the subtree; `docs/sub/a*` still does not. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
Mutation of changed linesAt 1aea8f5: 65 caught · 0 missed · 5 waived Not checked:
Marked harmless with
Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary. |
… of an exclude matches An exclude such as docs/sub?/** has the forms docs/sub?/* and docs/sub?. The second matches docs/sub/ through the ? but no file below it, so _excludes_subtree dropped an unlistable docs/sub while _is_excluded kept docs/sub/a.md selected, and the result lost a document without an error. The matching form must itself end in *. This settles the review thread on spec.py:132. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
napetrov
left a comment
There was a problem hiding this comment.
Change class: CONTRACT (head 1aea8f5)
- Contract: candidate. errors dokimi/dokimi/commands/catalog_provenance.py:106; errors dokimi/dokimi/harnesses/skill_treatment.py:152
- Responsibility: none
- Dependency: none
- Review depth: check the changed surface: callers, docs, tests pin new behaviour
- Coverage gaps: none
1 blocking, 0 minor.
Document selection, skill link checks and catalog provenance now report unlistable directories. Document selection can still refuse a path whose matching files are all excluded.
CI on head 1aea8f5: 0 failing Actions jobs; merge base 101e0b9 is behind base tip 5225c2a.
Compared the change and input edges against the merge base and checked existing threads and GitHub Actions. Runtime checks used focused Linux tests and local fixtures. Focused tests on the head: head 45 passed in 1.86s.
| seen.add((real, parts)) # mutation-ok[delete-statement]: see above | ||
| if real != root_resolved: | ||
| rel = real.relative_to(root_resolved).as_posix() | ||
| if _excludes_subtree(rel, exclude): |
There was a problem hiding this comment.
blocking: A complete selection can fail on excluded Markdown
dokimi/dokimi/runner/spec.py:224 The walk proves that whole subtrees are excluded without considering what the include can select (C2). The previous whole-subtree case is fixed. Earlier thread
How to check: Include README.md and docs/**/*.md, exclude docs/*.md, and make docs/restricted search-only. Base selects README.md. Head raises DocSelectionError, even though the matched documents are excluded.
Expected: Use the remaining include pattern when checking exclusions. Here the exclude glob covers all eligible Markdown below docs.
vchamarthi
left a comment
There was a problem hiding this comment.
@antonwolfy, could you fix the small thing I've marked fix before merge (in the line comments) and fix what napetrov's thread on dokimi/dokimi/runner/spec.py:224 still points out? I'll approve once that's done.
I'll approve once that's done.
Optional, non-blocking (1)
dokimi/dokimi/commands/catalog_provenance.py:105:catalog provenanceprints a table with no error when a folder above the skills cannot be listed but holds a readableSKILL.md(main has it too).
What I checked on 1aea8f5:
- When I changed the code on purpose, the tests still passed for 4 of 12 changes, and no test pins these down yet (non-blocking):
dokimi/dokimi/commands/catalog_provenance.py:93(the handled error is raised again),dokimi/dokimi/harnesses/skill_treatment.py:200(the handled error is raised again),dokimi/dokimi/runner/spec.py:216(the handled error is raised again) and 1 more. - The 87 changed tests pass, and fail on main as expected.
- The full test suite passes with main merged in (37,801 tests), apart from failures main has too.
- It merges cleanly onto main.
| partial clone) reports `history: partial` with `missing_blobs`; fetch them for an exact count. | ||
| When a manifest leaves the head of the matched path unspecified, the behind column reads | ||
| `unknown`. Its JSON fields `at_head`, `behind_commits`, and `behind_months` are null. `--format json` adds the upstreams, one row per skill and a `summary`. | ||
| A directory under `--root` that cannot be listed, above the skills, exits 2 and names the directory (`--root: <dir> cannot be listed (Permission denied), so the skills under it may be missing`) with no table, since the table would describe a smaller tree. |
There was a problem hiding this comment.
Fix before merge (blocking): The new sentence in external-content.md says an unlistable directory above the skills exits 2, but one with a readable SKILL.md is listed with no error.
I tested this suggestion: it fixes the problem, and the tests still pass.
| A directory under `--root` that cannot be listed, above the skills, exits 2 and names the directory (`--root: <dir> cannot be listed (Permission denied), so the skills under it may be missing`) with no table, since the table would describe a smaller tree. | |
| A directory under `--root` that cannot be listed and holds no `SKILL.md`, above the skills, exits 2 and names the directory (`--root: <dir> cannot be listed (Permission denied), so the skills under it may be missing`) with no table, since the table would describe a smaller tree. |
Details
I tried catalog provenance --root on a/SKILL.md, sub/SKILL.md and sub/x/SKILL.md, with sub at mode 0o111. It prints a table with the rows a and sub, no sub/x row, and no error. The sentence says such a directory exits 2 with no table, and I'd expect the sentence to cover only a directory with no SKILL.md file, as the PR description does.

Summary
Same cause as #1168, #1481 and #1510: a glob or an
os.walkwith noonerrorskips a directory it cannot list (mode0o111, non-root), so the result is a smaller tree that is counted or trusted as the whole. Three sites still do it onmain:maindocs/top.md,docs/sub/a.md, includedocs/**/*.md,chmod 111 docs/subselect_docsgives['top.md'](listable:['a.md', 'top.md']);min_docsandmax_docsare checked against the smaller countSKILL.mdand a hidden.h/holding a link to a file outside the skill,chmod 111 skill/.hcheck_skillreturnsdemo;build_pluginthen fails in the copy withshutil.Error [('.../skill/.h', '.../plugin/skills/demo/.h', "[Errno 13] Permission denied ...")], not aValueErrora/SKILL.mdandsub/x/SKILL.md,chmod 111 sub[('demo', True, .../a/SKILL.md), ('sub', False, None)]andcatalog provenancedrops thesubrow at itscontinue: the table and its summary are for a smaller tree, with no wordEach follows how #1481 reported the same condition: a refusal of the command's own error type that names the directory. #1383 takes the issue's first option (walk the directories an include pattern lists with an
onerror, then keepPath.glob's matching), so**, hidden files andexcludematch as before. #1480 takes the first option too (anInputError, ascatalog trigger-set --catalogexits 2), not a note under the table.Closes #1383
Closes #1479
Closes #1480
Changes
runner/spec.py: new_refuse_unlistable, called for each include pattern after its glob. It walks the pattern's parts asPath.globdoes (_next_steps): a literal part is entered, through a link too, and the last literal name is looked up, not listed; a wildcard part lists the directory and enters the directories it matches, links included;**lists, enters the directories below it without following links, and also matches none. It raisesDocSelectionError("cannot list <dir>: <reason>")for a directory that cannot be listed. A directory theexcludelist drops together with the files below it (_excludes_subtree: an entry that names the directory or a parent,docs/subordocs/sub/**, or has a form that ends in*and matches it,docs/s*; not an entry for one file name below it such asdocs/*/x, nordocs/sub?/**, whose formdocs/sub?matchesdocs/sub/through the?but no file below it, which leavesdocs/sub/a.mdselected on a listable tree, so the unlistable directory is an error; notdocs/[s]ub, which matches the directory and no file in it, so the files stay selected on a listable tree and the directory is an error) (at the start of the walk too), one outside the root (a..pattern or a link out), a path that is not there and a link whose target cannot be reached are not listed by the pattern and stay no error. A directory thatresolve()cannot follow (it raisesRuntimeErroron Python before 3.13, orOSError) leads nowhere and is not walked, so the oldmin_docserror comes out._outside_linksand theleaves_rootclosure are not touched.harnesses/skill_treatment.py:_check_linkspasses_refuse_unlistedas theonerrorof itsos.walk, and_check_link_loopscalls it where itsvisitreturned on anOSError(the comment saying the copy reports it is gone). It raises aValueErrornaming the folder, before the copy. A folderload_skillalready refuses (not under a dot-named, vendored or__pycache__folder it leaves out, More rglob/os.walk sites list or digest a directory tree and skip a subdirectory they cannot list #1168) is left to it, socannot load skill at ...is unchanged; the existingtest_check_skill_says_a_skill_it_cannot_list_does_not_loadstays as it was. A folder under such a left-out folder,__pycache__/sub, is refused by the link check, sinceload_skillnever names it and the copy would fail on it.commands/catalog_provenance.py: new_refuse_unlisted, applied to the entries ofread_skill_manifestand, when askills.yamllists some skills, to the scan that finds the rest. An entry that isunlisted, has anerrorand whose path is a directory with noSKILL.mdfile (a directory or a dangling link namedSKILL.mdis no file) raisesInputError("--root: <dir> cannot be listed (...), so the skills under it may be missing")before any row is printed. A directory with no search permission (mode0o000) holds noSKILL.mdwe can read, so it is refused the same way, not with aPermissionErrorfrom the probe. A manifest entry with no file, and a skill whose own folder cannot be listed (its row has aSKILL.md), keep the old behaviour.dokimi/README.md(benchmark spec exit codes),docs/coding-harnesses.md(skill delivery),docs/external-content.md(catalog provenance). No page added.tests/test_select_docs_unlistable.py,tests/test_skill_links_unlistable.py,tests/test_provenance_unlistable.py,tests/test_select_docs_link_loops.py.Risk
benchmark runwith agolden_manifestnow exits 2, naming the directory, where it ran on the smaller document set. A tree whose directories are all listable is unchanged.__pycache__-nested folder that cannot be listed is now refused bycheck_skill/build_plugin(the cell fails before the image build), wherecheck_skillpassed it and the copy failed with ashutil.Error.catalog provenanceexits 2 for a root with such a directory, where it printed a smaller table. A root with no such directory prints the same table._outside_linksand adds_leaves_rootinrunner/spec.py, the neighbour of the new helper. The helper is a separate function after_symlink_note, and the only line added toselect_docsis one call, so the two should merge without conflict.onerrorin_check_linksis redundant in effect with the one in_check_link_loops: with either alonecheck_skillrefuses the repro. Both are kept, as the issue asks, so each pass refuses on its own; a test with the loop check stubbed pins the walk's.Testing
On a Linux review host, at
1aea8f5c(onmain101e0b9a):make ci-local: 37 passed, 1 failed, 16 skipped (docker and network jobs, semgrep, micromamba, the fuzz job, the jobs a PR condition or another job's matrix gates). The pytest run is 35468 passed, 1 failed, 28 skipped. The failure istests/test_import_architecture.py::test_package_uses_the_new_modules(dokimi.runs.resolveimportsdokimi.utils), which fails the same way onmain's code (not touched here; filed separately as dokimi.runs.resolve imports dokimi.utils, which test_package_uses_the_new_modules refuses #1629).Scan commitsand the mutation of changed lines pass.main,tests/test_runner_spec.py::test_min_docs_error_on_a_looping_docs_link_is_a_selection_errorraisedRuntimeErrorfrom the new helper'sresolve(); the helper now guards it (tests/test_select_docs_link_loops.py, 2 cases for theresolvefailure fail without the guard).mainand pass here:test_select_docs_unlistable.py4 failed, 6 passed onmain(first:DID NOT RAISE DocSelectionError),test_skill_links_unlistable.py6 failed, 2 passed (first:DID NOT RAISE ValueError, andshutil.Errorfrombuild_plugin),test_provenance_unlistable.py2 failed, 3 passed (DID NOT RAISE InputError). All pass at the head.select_docs, the walk's outside-the-root return (a..pattern and a link out, one test each), the exclude check at the start of the walk, the exclude check not dropping the root for a.*pattern, a literal part listed instead of entered (a link reached by name, and the last name ofdocs/*/a.md), a wildcard part not following a link, a wildcard entering a directory it does not match or one the last part matches,**also matching no directory,**ending the pattern,**following a link, the link-target-unreachable tolerance, the walk'sonerror, the loop check's call, theload_skillcarve-out and the ancestor check for__pycache__/sub, and the provenance probe'sOSError(mode0o000, both with and without a manifest). Theresolveguard: replacingexcept (RuntimeError, OSError)fails both cases of the helper test.aa75ca18and passing here:alias/a.mdthrough an in-root link to a mode0o111directory,docs/sub/**/*.mdwhose base the exclude list drops,docs/*/*.mdthrough a link to a mode0o111directory (now an error naming it),../outside/**/*.mdwith../outsideat mode0o111,docs/*/a.mdover a mode0o111docs/sub(selectsa.md),__pycache__/subat mode0o111(refused bycheck_skill), andcatalog provenanceover a mode0o000sub(exit 2 where it raisedPermissionError).0o111subholding an empty directorysub/SKILL.mdor a dangling link of that name besidesub/x/SKILL.md(with and without askills.yaml):catalog provenanceexits 2 namingsub;include=["docs/**/*.md"],exclude=["docs/[s]ub"]over a mode0o111docs/sub:select_docsraisescannot list ...docs/sub(on a listable tree it selectsa.md,top.md,x.md). 5 of the 35 tests oftest_provenance_unlistable.pyandtest_select_docs_unlistable.pyfail on those reverts.include=["docs/**/*.md"],exclude=["docs/*/x"]over a mode0o111docs/subholdinga.mdbeside a readabledocs/top.md: at4d8fc2faselect_docsreturnedtop.mdalone, now it raisescannot list ...docs/sub(the listable tree selectsa.md,top.md,x.md); that test fails on the previous head's code.exclude=["docs/s*"]and["docs/sub"]still drop the directory with no error. Mutants: matchingrel_dir + "/x"again fails thedocs/*/xtest; dropping the trailing-*clause fails thedocs/s*test; keeping only thestartswithor only the==of the named-directory clause fails the test of an unlistabledocs/sub/deepbelow an excludeddocs/suband the["docs/sub"]assertion. For thecatalog provenancelines codecov named: Python 3.11 and 3.12 raisePermissionErrorfromPath.is_filefor a name inside a mode0o000folder, where 3.13 returns False, so theexcept OSErrorof_holds_skill_fileran on no 3.13 input. A test now makesis_fileraise it and expects exit 2; narrowing theexcepttoFileNotFoundErrorfails it.include=["docs/**/*.md"],exclude=["docs/sub?/**"]over a mode0o111docs/subholdinga.mdbeside a readabledocs/top.md: the formdocs/sub?matchesdocs/sub/and no file below it, so on a listable treea.mdis selected and the unlistable directory now raisescannot list ...docs/sub(before,top.mdalone). The test fails on a copy with the old trailing-*check on the pattern restored, and onmain's code (which has no check).0o111directory).Open questions
None.
Revert
A plain revert restores the old behaviour (a smaller tree read without a word). Nothing is stored.
Checklist
pytestpasses [one failure,test_package_uses_the_new_modules, which fails the same onmain]ruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)