Repository navigation
BUILD: declare jsonschema and the other function-body third-party reaches (split-opendox slice 3) - #8
Conversation
…e 3) pyproject.toml's dependency derivation (levelling round 2) walked module bodies and module-level if/try/with only, so the one reach inside a function body -- jsonschema, src/openxdox/gate_console.py:563's _validate_contract_document -- never entered its scope. Recorded as a correction, not fixed, on landing (opensoft/openXfactory#656 comment 5627156620, correction (c)): "owed a one-line dependency PR." Add jsonschema>=4.18 (the floor this leg's own DEPENDENCY_REMEDY string already names, and the release that introduced Draft202012Validator) to [project] dependencies. tests/test_dependency_direction.py's own allowlist for deferred (function-body) reaches no longer hand-lists jsonschema as a known gap -- it now derives DEFERRED_ALLOWED from pyproject.toml's actual declared dependencies via tomllib, so the suite asserts the declaration exists instead of trusting a name in a list that could go stale the next time a name is reached only this way. The walker (_census / _src_census) already descends into function bodies -- it marks them not-at-import-time, it does not skip them -- so no walker change is needed; this is a declaration fix, not a coverage fix. Refs opensoft/openXfactory#656 Lane: openxfactory-4-opendox-extraction Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Reviewer's GuideThis slice adds Sequence diagram for deferred contract validation dependencysequenceDiagram
participant Caller
participant GateConsole as gate_console.py
participant Jsonschema
Caller->>GateConsole: _validate_contract_document()
GateConsole->>Jsonschema: import Draft202012Validator, FormatChecker
Jsonschema-->>GateConsole: validator types
GateConsole-->>Caller: contract validation result
Flow diagram for dependency-direction enforcementflowchart LR
Source["src/ deferred imports"] --> Census[_census]
Census --> Roots["third-party import roots"]
Manifest["pyproject.toml project dependencies"] --> Allowed[_declared_runtime_dependency_import_names]
Roots --> Check[test_every_deferred_cross_package_reach_out_of_src_is_known]
Allowed --> Check
Check --> Result{All deferred roots declared?}
Result -->|yes| Pass["pass"]
Result -->|no| Fail["fail"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_dependency_direction.py" line_range="75-86" />
<code_context>
+ cannot drift apart with one hand-maintained twice. A PEP 508 requirement's
+ distinguishing name is everything before its first version/marker/URL
+ separator; the PyPI distribution name and the import name differ for
+ exactly one entry here, `PyYAML` -> `yaml`, mapped by hand because no
+ general rule covers it.
+ """
+ import re
+ import tomllib
+
+ data = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))
+ names = {
+ re.split(r"[ @\[<>=!~;]", requirement, maxsplit=1)[0].strip().lower()
+ for requirement in data["project"]["dependencies"]
+ }
+ return frozenset("yaml" if name == "pyyaml" else name for name in names)
+
+
</code_context>
<issue_to_address>
**nitpick (bug_risk):** The dependency-to-import mapping only special-cases `PyYAML`; when a declared distribution uses a different import root (for example `scikit-learn` → `sklearn`), the census reports the legitimate deferred import as undeclared even though the dependency is present in `pyproject.toml`.
**Triggers:** When a future runtime dependency has a distribution name that differs from its top-level Python import name and is imported from a function body.
**Suggested fix:** Maintain an explicit distribution-to-import-root mapping for every such dependency, or derive the import roots from installed package metadata.
</issue_to_address>
### Comment 2
<location path="tests/test_dependency_direction.py" line_range="89-100" />
<code_context>
+#: Cross-package roots reachable ONLY inside a function body, where the name
</code_context>
<issue_to_address>
**nitpick:** The comment says `DEFERRED_ALLOWED` contains roots reachable only inside function bodies, but the implementation contains every declared runtime dependency, including `opendox` and `yaml` that are also allowed at import time; the documentation therefore misstates which imports this allowlist permits.
**Suggested fix:** Describe the set as all declared runtime dependency import roots that are permitted for deferred reaches, rather than as roots reachable only inside function bodies.
```suggestion
#: Cross-package roots that are declared runtime dependencies and therefore
#: permitted for deferred reaches — DERIVED from `pyproject.toml` rather than
#: hand-listed, so this set can only ever say "declared", never merely
#: "allowlisted". It includes roots also allowed at import time, such as
#: `opendox` and `yaml`, as well as roots reached only inside function bodies.
#: `jsonschema` is the one example today: reached once,
#: `gate_console.py:563`'s `_validate_contract_document`, exercised only when
#: a caller asks to validate a contract document. It was the BUILD-arc slice 3
#: finding recorded on opensoft/openxFactory#656 comment 5627156620,
#: correction (c) — undeclared because the derivation walk `pyproject.toml`
#: documents covers module bodies and module-level `if`/`try`/`with` only,
#: never a function body, the same gap `DEFERRED_ALLOWED` closes for the
#: CHECK: declaring the name (this same PR) is what makes it appear here, not
#: a second hand-typed copy of it.
```
</issue_to_address>Sourcery assessment
Approved.
Two Sourcery nitpicks on PR #8's DEFERRED_ALLOWED derivation, both taken: 1. The distribution->import-name mapping hand-special-cased only PyYAML; a future dependency with a differing import root (e.g. scikit-learn -> sklearn) would have been silently reported as an undeclared deferred reach. Replaced with importlib.metadata.packages_distributions(), the same RECORD/top-level metadata pip itself relies on, so no hand-maintained table can go stale as dependencies change. 2. The comment claimed DEFERRED_ALLOWED holds names reachable ONLY inside a function body, but the set also contains opendox/yaml (declared AND import-time). Reworded to say what the set actually is: every declared runtime dependency, permitted for a deferred reach; import-time reaches still gate separately through IMPORT_TIME_ALLOWED. Re-verified: tests/test_leg_shape.py + tests/test_dependency_direction.py = 24 passed; arrival verifier phase B still OK, all figures unchanged. Lane: openxfactory-4-opendox-extraction Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
There was a problem hiding this comment.
🟡 Changes recommended
The runtime dependencies omit rfc3339-validator, so malformed RFC 3339 timestamps may not be rejected.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Declares jsonschema as a runtime dependency and validates deferred imports against declared dependencies.
Changes:
- Adds
jsonschema>=4.18. - Derives deferred-import allowances from
pyproject.toml.
File summaries
| File | Description |
|---|---|
tests/test_dependency_direction.py |
Checks deferred imports against declared dependencies. |
pyproject.toml |
Declares the jsonschema runtime dependency. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🔵 Needs a closer look
Two moderate findings remain unresolved.
Review details
Suppressed comments (2)
pyproject.toml:108
- Adding only
jsonschemadoes not make theFormatChecker()used bygate_console.pyenforce the contract'sdate/date-timeformats in a clean install. The repository's own validator documents that jsonschema registers those checkers only whenrfc3339-validatoris importable and exits when they are absent (scripts/validate-ideation-dashboard-contracts.py:174-188); with this dependency list, malformed timestamps can therefore pass the gate. Addrfc3339-validatorto the runtime dependencies, or makegate_consolefail closed when the checkers are unavailable.
"jsonschema>=4.18",
tests/test_dependency_direction.py:93
- The metadata comparison only lowercases distribution names, but PEP 508 names are also equivalent across
-,_, and.. A valid dependency declared asfoo-barwhose installed metadata reportsfoo_barwould be omitted fromDEFERRED_ALLOWED, causing a deferred import to be falsely reported as undeclared; canonicalize both sides before comparing.
if any(dist.lower() in declared_distributions for dist in dist_names)
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
…lice-2 ratchet branch Slice 3's derived deferred-allowlist and this branch's ratchet lowering touch the same two files and do not overlap: its hunks are the allowlists at the top of tests/test_dependency_direction.py and the dependency block's comment, this one's are OPENDOX_BACK_IMPORTS and the `opendox @ git+…` pin line. Merged rather than rebased because this repository's ruleset declines a force push. Lane: openxfactory-4-opendox-extraction Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>



Lane: openxfactory-4-opendox-extraction (formerly openxfactory-opendox)
BUILD arc (§ 3.5/3.6) slice 3, on Brett Heap's ruling of 2026-09-10 (opensoft/openXfactory#656 comment
5626260214): "START NOW, LAND EACH SLICE WHEN GREEN — small slices ... (the undeclared reaches) first." The specific owed item is correction (c) of the § 4.1 landing (#656 comment5627156620): "jsonschemais an UNDECLARED dependency of openXdox-code (gate_console.py:563+ 2 sites;pyproject.toml's derivation walked module bodies only) — allowlisted with reason, NOT fixed (not a direction fix) — owed a one-line dependency PR."Refs opensoft/openXfactory#656
1. Measured — a from-scratch AST census of
src/, module+class+function bodiesEvery
Import/ImportFromundersrc/, grouped by top-level name, classified againstpyproject.toml's declared dependencies andsys.stdlib_module_names:opendoxdoc_healthyamlPyYAML>=6.0)openxdox/route_extension/subcommand_extensionjsonschemajsonschemais reached exactly once undersrc/:src/openxdox/gate_console.py:563, inside_validate_contract_document,from jsonschema import Draft202012Validator, FormatChecker— a function body, hence deferred, hence outside the scope of the derivation walk that builtpyproject.toml's dependency list (module body + module-levelif/try/withonly). No other undeclared third-party name is reached undersrc/.The correction's "+ 2 sites" are real, but neither is
src/:scripts/validate-ideation-dashboard-contracts.py:107(a root-level script, explicitly out of this leg's dependency-derivation scope by the precedentpyproject.tomlitself documents) andtests/test_doxchat_model_intake.py:1505(the test extra, covered transitively oncejsonschemais a base dependency). Repo-widegrep -rn "^\s*from jsonschema import\|^\s*import jsonschema"finds exactly these three lines.2. Manifest disposition for the two touched files
grep -n "pyproject.toml" docs/opendox-carve-manifest.yaml(openxFactory, main114d6e3d) returns zero matches — confirmed by command, not assumed.pyproject.toml's own header says why: "This is a CREATED file and therefore carries NO row ... RULED OQ-C: the manifest declares what LEAVES openxFactory, never what a destination assembles."tests/test_dependency_direction.pycarries the identical self-declaration in its own docstring (created at PR #7, no row). Both are scaffold/created files outside the manifest's fence — free to edit, no declared-edit line range applies, no manifest question for Brett here.3. The fix
Two files,
+70 −9:pyproject.toml—jsonschema>=4.18added to[project] dependencies, with a comment block (mirroring the PyYAML block's shape) citing the correction, the one reach, and the floor's source: this leg's ownDEPENDENCY_REMEDYstring (src/openxdox/snapshot.py:105, unchanged) already namesjsonschema>=4.18as what the code needs, andDraft202012Validator— the namegate_console.py:563imports — was added in jsonschema 4.18.0.referencingandrfc3339-validator(named alongside jsonschema in that same string) are deliberately not added: neither is imported anywhere undersrc/, so declaring them would be a new dependency nothing in the tree calls for.tests/test_dependency_direction.py— the allowlist no longer hand-listsjsonschemaas a known gap (DEFERRED_ALSO_ALLOWED = frozenset({"jsonschema"})is gone).DEFERRED_ALLOWEDis now_declared_runtime_dependency_import_names(), a smalltomllibread ofpyproject.toml's actual[project] dependencies, mapped to import names (PyYAML→yaml, the one case where the two differ). The suite now asserts the declaration exists rather than trusting a name someone typed into a list — the next name reached only from a function body will failtest_every_deferred_cross_package_reach_out_of_src_is_knownunless it is actually declared.The walker is unchanged.
_census/_src_censusalready descends into function bodies today — it marks themat_import_time=False, it does not skip them, which is exactly howjsonschemawas findable as a deferred reach in the first place (round 2's own measurement, and independently re-derived here). This slice is a declaration fix, not a coverage fix.4. Finding (B) — the "11 + 23 undeclared reaches" on #656 — a DIFFERENT class, out of scope here
Searched #656's comments of 2026-09-09/10 for "undeclared reach". Two distinct figures turn up, neither the jsonschema class:
REPO_ROOT / "scripts"reaches ... over 9opendox_coderows (from #889)" (comments5613123987,5618539241) — at openDox-code (leg 1), not this repository: lawful carved arrivals whose code constructs a path assuming openxFactory's ownscripts/directory exists at the destination (it does not, post-carve). A path-construction/runtime-layout defect, not an undeclared import needing apyproject.tomlentry.scripts/ideation_dashboardreaches over 15 rows (memo: 19/13)" (comment5621719657, leg 3's own independent verification) — prose/docstring citations of the pre-carvescripts/ideation_dashboardlayout (the same bucket the ruling elsewhere calls "the 20 prose paths ... across 16 arrived files, none on declared lines", comment5618797424) — a documentation-staleness class, not a Python import statement.Neither is a "function-body third-party reach [missing from] pyproject" in the sense finding (A) is. This PR does not touch either. (A third, separate item — four
ideation_dashboardreaches surviving under this leg's owntests/, remedied by "RULED Q-L8 (c)" per PR #7 §8 — is also out of scope: none runs undervalidate, and its remedy is recorded as not this lane's to write.)5. Sibling search
gh pr list --repo opensoft/openXdox-code --state open→ no open PRs at time of authoring; PR #7 (§ 4.1 inversion) is already merged atbfd95063, which is this branch's base. The collision note's "BUILD slice 2" (theopendox @ git+…pin bump and theOPENDOX_BACK_IMPORTSratchet in this same test file) had not yet opened a PR. This diff touches only the dependency list inpyproject.toml(not theopendoxpin line) and only theDEFERRED_ALSO_ALLOWED/DEFERRED_ALLOWEDallowlist machinery in the test file (notOPENDOX_BACK_IMPORTS), so the two should not overlap; this branch will rebase onto main if slice 2 lands first.6. Validators
Fresh venv,
pip install -e ".[test]"(resolvesopendoxto the pinned8e9ffa62,jsonschemato4.26.0, satisfying>=4.18):(
tests/test_dependency_direction.pyalone,-v: 12 passed — same 12 as PR #7 landed, no new/removed test, only the allowlist's derivation changed.)python -c "import openxdox.gate_console"still raisesModuleNotFoundError: No module named 'doc_health'— pre-existing and untouched by this diff (git diff origin/main -- src/openxdox/gate_console.pyis empty);doc_healthis § 4.1's own separately-tracked, not-yet-reachable adapter surface (12 of 18 modules, per correction (c) clause (i)), not this slice's to fix.Arrival verifier, phase B, from an openxFactory checkout, tree cleaned of
__pycache__/.pytest_cache/*.egg-infofirst (a stray build artifact otherwise reads as an undeclared file):Every figure identical to PR #7's own landed OK line (
92 / 9 / 81 / 4 unapplied / 6 of 6 / 99 file(s) (1 scaffold, 0 replica, 2 created)) — this PR moves no manifest row, no replica, no created-file count; the one scaffold admission (pyproject.toml) differs from--dest-base 3487e476d782by design (that is the fix) and is still accounted for, not undeclared.Nothing in openxFactory is touched by this pull request: no manifest, no pin, no gitlink, no
openspec/changes/.7. Findings recorded, not fixed (review round)
rfc3339-validator(Copilot review, this PR) — jsonschema'sFormatChecker()registers no"date-time"checker unlessrfc3339-validatoris installed (confirmed empirically:'date-time' in FormatChecker().checkersisFalsewithout it, so a malformed timestamp raises zero errors). Not live in this repository today:_validate_contract_document's schema path is<repo root>/contracts/schemas/<name>andcontracts/does not exist anywhere in this tree (find . -iname contracts— no output), so both call sites already raiseGateRefusedat schema-load, before a document ever reachesFormatChecker, with or withoutrfc3339-validator. Not added here: nothing in this tree's import graph reaches it directly (it is jsonschema's own optional internal plugin lookup). Owed to whichever BUILD-arc slice populatescontracts/schemas/and makes this path live — addrfc3339-validatorto[project] dependenciesin that same act, or_validate_contract_documentwill silently under-enforcedate-timefields once there is a schema to check them against.🤖 Generated with Claude Code
Summary by Sourcery
Declare the deferred jsonschema dependency and make dependency-direction checks enforce the project manifest.
Bug Fixes:
Enhancements:
Build:
Tests: