Repository navigation
fix(mcp): local: and okf: refuse a doc tree with a directory they cannot list (#1207) - #1369
Conversation
…not list (intel#1207) Both clients listed the tree with rglob("*"), which skips a directory it cannot list without an error: a source holding a.md and sub/b.md with sub at mode 0o111 returned a.md alone, check_connection() said True, and the preflight accepted it. A root at 0o111 gave no docs and a "no doc files found" warning. The clients now list with digest_entries.listed_entries; a directory that cannot be listed raises MCPConnectionError naming it from get_library_docs, as a missing path does. check_connection() returns False with a warning that names the directory. require_local_doc_source lists the tree of a root that passed its other checks and raises InputError "cannot list <directory>", so eval questions generate exits 2 instead of falling back to default seed topics. A listable tree gives the same files, a directory with no doc files still warns and gives no docs, and an unreadable file is still skipped. docs/adding-doc-source.md says what each case does. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…entries lazily (intel#1207) The questions-generate test patched RagasSeedExtractor on dokimi.questions.ragas_seed, but cmd_questions_generate reads it from the dokimi.questions package, so the real extractor ran when the preflight listing was missing. The test now patches the package attribute and fails on the extractor mock. factory.py imports listed_entries inside _require_listable, so the module's import block is as on main and does not conflict with a change to the InputError import line. The unused root parameter of the test helper _files is dropped. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…llbacks of the doc-source listing (intel#1207) Eight mutants of this PR's lines survived the mutation step: the `not unreadable and` guard of the preflight, and the `exc.filename or ...` and `exc.strerror or ...` fallbacks of the client and preflight messages. An unreadable root now has a preflight test that expects `cannot read <root>: permission denied` and no `cannot list`. The subdirectory tests of the clients and the preflight match the directory the message names, and the preflight message ends with the bare strerror. An `OSError` without a filename, and one without a strerror, is raised from the listing and the exact messages are asserted. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 7 selected item(s). CI at `b714c1f`: 1 failing, 20 passing, 4 skippedNot fully read: job Tests (py3.14): HTTP 404: The specified blob does not exist.
Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1369 +/- ##
==========================================
- Coverage 96.23% 96.22% -0.01%
==========================================
Files 509 509
Lines 67757 67785 +28
Branches 11765 11767 +2
==========================================
+ Hits 65204 65225 +21
- Misses 1571 1574 +3
- Partials 982 986 +4
🚀 New features to boost your workflow:
|
…1207) Settles the review point on the changelog fragment: `require_local_doc_source` keeps `cannot read <root>: permission denied` for a root the user cannot read or search, and `cannot list <directory>` is the message for a directory below the root. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
xaleryb
left a comment
There was a problem hiding this comment.
Approved on b714c1f. local: and okf: doc sources exit 2 with cannot list
before any model call when a subdirectory cannot be listed, reusing listed_entries; a readable tree gives the same files and output as main. All 10 mutants of the changed lines are killed. Windows smoke had not started (the hosted Windows queue was stuck); every other check passed.
Summary
#1207:
local:andokf:listed the doc tree withrglob("*"), which skips a directory it cannot list without an error. Onmain, a source holdinga.mdandsub/b.mdwithsubat mode0o111(as a non-root user):mainLocalMarkdownClient(d)._collect_files()andOKFClient(d)._collect_files()['a.md']get_library_docs("x", "parallel_for")['a.md']check_connection()Truerequire_local_doc_source("local:<d>")and("okf:<d>")eval questions generategoes on with the smaller set (or default seed topics, sinceRagasSeedExtractorswallows a retrieval error)A root directory at
0o111holdinga.mdgave[]and a "no doc files found" warning from both clients, though the source is not empty (the preflight already refused that root with "permission denied", and still does).Of the issue's three options this takes (a): a directory that cannot be listed is an error, raised as
MCPConnectionErrorlike a missing path. The repo settles this bug class the same way at its other sites (scorecard digests, catalog scan, arms, reach, novelty bundle: "a directory that cannot be listed is an error, not a smaller tree" indocs/reach-matrix.md), and (b) or (c) would leave the measured docs smaller than the user's with at most a log line, the defect the issue reports.answers generate,evaluateand alocal:/okf:treatment arm do not run this preflight (the #1086 check, which onlyeval questions generateandbenchmark preflightcall): a missing path is not refused before their run, and a treatment arm recordsretrieval_failedfor each question. That is tracked in #1368.Closes #1207
Changes
mcp/utils.py:list_doc_treelists a directory withdigest_entries.listed_entriesand turns anOSErrorintoMCPConnectionError("<client>: cannot list <directory>: <error>"), naming the directory the error names.mcp/local_markdown.py,mcp/okf_client.py:_collect_filesand_iter_candidate_fileslist through it instead ofrglob("*").get_library_docsraises theMCPConnectionError;check_connectionreturnsFalseand logs a warning that names the directory. The filters, the size limit, the single-file source, the empty-directory warning and the skip of an unreadable file are unchanged.mcp/factory.py:require_local_doc_sourcelists the tree of a directory source that passed its other checks and raisesInputError("doc source <source>: cannot list <directory>: <error>")(exit 2), soeval questions generateandbenchmark preflightrefuse it before any seed extraction. The existing refusals and their messages are unchanged.listed_entriesis imported inside the helper, so the module's import block is as onmain.docs/adding-doc-source.md: whatlocal:andokf:do with a missing path, an unlistable directory, an empty directory and an unreadable file.tests/test_doc_source_unlistable.py: both clients and the preflight, parametrized. Thequestions generatetest patchesRagasSeedExtractoron thedokimi.questionspackage, the name the command reads, so it fails when the extractor is reached.eval questions generateandbenchmark preflightexit 2 withcannot list <directory>for a directory below the root, and with the existingcannot read <root>: permission deniedfor a root the user cannot read or search.Risk
A
local:orokf:source with a directory the user cannot list is refused now (MCPConnectionErrorfrom retrieval, exit 2 fromeval questions generateandbenchmark preflight); it was read as a smaller tree before. A tree that can be listed gives the same files and docs. The order of the files_collect_filesreturns is no longerrglob's:OKFClientsorts them as before, andLocalMarkdownClient's scored list is sorted by(-score, path), so the results are in the same order. No existing test pinned the silent skip.A tree is refused for any directory the user cannot list, even one that holds no docs (a root-owned
lost+foundunder a mount point used as the doc root, for one); the message names that directory.Open PRs on
mcp/factory.py, each checked withgit merge-treeagainst this branch:_context7_settings()right afterrequire_local_doc_source. This branch leaves that function's last lines and the blank lines after it as they are; the two merge cleanly.InputErrorimport line. This branch leaves the import block as onmain(listed_entriesis imported inside_require_listable), somcp/factory.pymerges cleanly with each. The new test importsInputErrorfromdokimi.utils, which both still re-export, anddigest_entries.listed_entrieskeeps its signature there.Testing
On a Linux review host, at
b714c1f3(onmain26e3083):make ci-local: 1 failed, 37 passed, 16 skipped; its pytest step 30819 passed, 27 skipped, 2 failed and 1 error, all threeTimeout (>60.0s) from pytest-timeoutunder host load (test_unclosed_openers.py::test_cli_trace_heredoc_scans_many_openers_on_one_line_of_a_closed_heredoc_in_linear_time,test_eval_tasks_generate_history.py::test_usage_errors[extra4-is not a regular expression],test_import_architecture.py::test_every_module_is_in_a_layer); run alone, those three files pass (383 and 54 passed). The commit on top of77f9455achanges only the changelog fragment. At77f9455athe mutation step had 29 mutants of the changed lines, 29 killed, 0 survived (python scripts/mutate_changed.py --base origin/main). The comment-block and duplicate checks pass.tests/test_doc_source_unlistable.pyonmain's code: 15 failed, 6 passed (the first failure isDID NOT RAISE MCPConnectionErrorfromget_library_docswithsubat0o111; the tests that patchlisted_entriesindokimi.mcp.utilsfail there withAttributeError, the name this PR adds; the unreadable-root preflight test passes, since that message is unchanged); here 21 passed.rglob("*")back inLocalMarkdownClientor inOKFClient(the subdirectory and the root test of that client); theOSErrorconversion dropped (a rawPermissionError, 4 tests);check_connectionreturningTrueon the error (the subdirectory test, for each client); the warning not naming the directory (the subdirectory test); the preflight listing dropped (the two preflight tests, and thequestions generatetest, which fails withreached the extractor or generatorraised from theRagasSeedExtractor(...)call). The eight mutants of the changed lines that survived an earlier run (not unreadable anddropped inmcp/factory.py; theexc.filename or ...andexc.strerror or ...fallbacks inmcp/factory.pyandmcp/utils.py) are killed by the unreadable-root preflight test, the subdirectory tests that matchcannot list <root>/sub:(andPermission denied$for the preflight), and the tests that raise anOSErrorwith no filename or no strerror from the listing.0o111directory skip as root.Open questions
None.
Revert
A plain revert restores the silent skip of a directory that cannot be listed. Nothing is stored.
Checklist
pytestpasses [the full run had 3 pytest-timeout failures under host load; each passes alone]ruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)