Skip to content

BUILD: declare jsonschema and the other function-body third-party reaches (split-opendox slice 3) - #8

Merged
brettheap merged 2 commits into
mainfrom
build/declare-function-body-deps
Sep 11, 2026
Merged

brettheap merged 2 commits into
mainfrom
build/declare-function-body-deps

Conversation

@brettheap

@brettheap brettheap commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

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 comment 5627156620): "jsonschema is 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 bodies

Every Import/ImportFrom under src/, grouped by top-level name, classified against pyproject.toml's declared dependencies and sys.stdlib_module_names:

root class import-time deferred total
opendox declared (pinned upstream) 17 13 30
doc_health known lawful-but-unresolvable adapter (§4.1's own 2nd clause; not a PyPI package) 8 5 13
yaml declared (PyYAML>=6.0) 6 2 8
openxdox / route_extension / subcommand_extension local (own) — — 22
jsonschema UNDECLARED 0 1 1
(17 stdlib roots) stdlib — — —

jsonschema is reached exactly once under src/: 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 built pyproject.toml's dependency list (module body + module-level if/try/with only). No other undeclared third-party name is reached under src/.

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 precedent pyproject.toml itself documents) and tests/test_doxchat_model_intake.py:1505 (the test extra, covered transitively once jsonschema is a base dependency). Repo-wide grep -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, main 114d6e3d) 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.py carries 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.18 added 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 own DEPENDENCY_REMEDY string (src/openxdox/snapshot.py:105, unchanged) already names jsonschema>=4.18 as what the code needs, and Draft202012Validator — the name gate_console.py:563 imports — was added in jsonschema 4.18.0. referencing and rfc3339-validator (named alongside jsonschema in that same string) are deliberately not added: neither is imported anywhere under src/, so declaring them would be a new dependency nothing in the tree calls for.
  • tests/test_dependency_direction.py — the allowlist no longer hand-lists jsonschema as a known gap (DEFERRED_ALSO_ALLOWED = frozenset({"jsonschema"}) is gone). DEFERRED_ALLOWED is now _declared_runtime_dependency_import_names(), a small tomllib read of pyproject.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 fail test_every_deferred_cross_package_reach_out_of_src_is_known unless it is actually declared.

The walker is unchanged. _census/_src_census already descends into function bodies today — it marks them at_import_time=False, it does not skip them, which is exactly how jsonschema was 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:

  • "11 undeclared REPO_ROOT / "scripts" reaches ... over 9 opendox_code rows (from #889)" (comments 5613123987, 5618539241) — at openDox-code (leg 1), not this repository: lawful carved arrivals whose code constructs a path assuming openxFactory's own scripts/ directory exists at the destination (it does not, post-carve). A path-construction/runtime-layout defect, not an undeclared import needing a pyproject.toml entry.
  • "23 undeclared scripts/ideation_dashboard reaches over 15 rows (memo: 19/13)" (comment 5621719657, leg 3's own independent verification) — prose/docstring citations of the pre-carve scripts/ideation_dashboard layout (the same bucket the ruling elsewhere calls "the 20 prose paths ... across 16 arrived files, none on declared lines", comment 5618797424) — 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_dashboard reaches surviving under this leg's own tests/, remedied by "RULED Q-L8 (c)" per PR #7 §8 — is also out of scope: none runs under validate, 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 at bfd95063, which is this branch's base. The collision note's "BUILD slice 2" (the opendox @ git+… pin bump and the OPENDOX_BACK_IMPORTS ratchet in this same test file) had not yet opened a PR. This diff touches only the dependency list in pyproject.toml (not the opendox pin line) and only the DEFERRED_ALSO_ALLOWED/DEFERRED_ALLOWED allowlist machinery in the test file (not OPENDOX_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]" (resolves opendox to the pinned 8e9ffa62, jsonschema to 4.26.0, satisfying >=4.18):

$ python -m pytest -q tests/test_leg_shape.py tests/test_dependency_direction.py --noconftest
24 passed in 1.92s

(tests/test_dependency_direction.py alone, -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 raises ModuleNotFoundError: No module named 'doc_health' — pre-existing and untouched by this diff (git diff origin/main -- src/openxdox/gate_console.py is empty); doc_health is § 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-info first (a stray build artifact otherwise reads as an undeclared file):

OK .../xdox: openxdox_code (opensoft/openXdox-code) at opensoft/openxFactory@b075fd91dc8f
(opendox-carve-0), phase B — 92 row(s) arrived, 9 digest(s) verified, 81 declared-edit row(s)
within their lines, 4 unapplied; 6 of 6 declared replica(s) verified (byte-identical, or — where
the row declares lines — differing only on them); 99 file(s) under scripts, src/openxdox, tests
with none undeclared (1 scaffold, 0 replica, 2 created); scaffold admissions checked against
3487e476d782

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 3487e476d782 by 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's FormatChecker() registers no "date-time" checker unless rfc3339-validator is installed (confirmed empirically: 'date-time' in FormatChecker().checkers is False without 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> and contracts/ does not exist anywhere in this tree (find . -iname contracts — no output), so both call sites already raise GateRefused at schema-load, before a document ever reaches FormatChecker, with or without rfc3339-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 populates contracts/schemas/ and makes this path live — add rfc3339-validator to [project] dependencies in that same act, or _validate_contract_document will silently under-enforce date-time fields 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:

  • Declare jsonschema as a runtime dependency so deferred contract validation works in clean installations.

Enhancements:

  • Derive deferred dependency allowlists from the project’s declared dependencies instead of maintaining a separate hand-written exception list.

Build:

  • Add jsonschema>=4.18 to the project’s runtime dependencies.

Tests:

  • Update dependency-direction validation to verify deferred imports against dependencies declared in pyproject.toml.

…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>
Copilot AI lite review requested due to automatic review settings September 11, 2026 00:54
@brettheap
brettheap marked this pull request as ready for review September 11, 2026 00:54
@sourcery-ai

sourcery-ai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This slice adds jsonschema>=4.18 as a runtime dependency for the deferred contract-validation import and makes dependency-direction tests derive permitted deferred third-party roots from pyproject.toml, eliminating the prior hand-written allowlist while leaving the AST walker, source code, and carve manifest unchanged.

Sequence diagram for deferred contract validation dependency

sequenceDiagram
    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
Loading

Flow diagram for dependency-direction enforcement

flowchart 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"]
Loading

File-Level Changes

Change Details Files
Declare the deferred jsonschema runtime dependency and align the dependency-direction check with the manifest of declared dependencies.
  • Add jsonschema>=4.18 to project runtime dependencies, with rationale for the version floor and the single source reach.
  • Replace the hand-maintained deferred-import exception with a tomllib-based derivation from [project] dependencies.
  • Retain the PyYAML-to-yaml import-name mapping and strengthen failure messaging for undeclared deferred imports.
pyproject.toml
tests/test_dependency_direction.py
Preserve the existing AST census and validate the dependency declaration change without modifying source or manifest files.
  • Leave function-body traversal unchanged; the slice fixes declaration rather than coverage.
  • Verify dependency-direction and leg-shape tests pass and confirm arrival-verifier results remain unchanged.
tests/test_dependency_direction.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Sep 11, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/test_dependency_direction.py Resolved
Comment thread tests/test_dependency_direction.py Resolved
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>
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment thread pyproject.toml Resolved
Copilot AI review requested due to automatic review settings September 11, 2026 00:58

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Two moderate findings remain unresolved.

Review details

Suppressed comments (2)

pyproject.toml:108

  • Adding only jsonschema does not make the FormatChecker() used by gate_console.py enforce the contract's date/date-time formats in a clean install. The repository's own validator documents that jsonschema registers those checkers only when rfc3339-validator is 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. Add rfc3339-validator to the runtime dependencies, or make gate_console fail 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 as foo-bar whose installed metadata reports foo_bar would be omitted from DEFERRED_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

@brettheap
brettheap merged commit 208656f into main Sep 11, 2026
4 checks passed
brettheap added a commit that referenced this pull request Sep 11, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants