Skip to content

imports_test keeps btclib free of bip32_descriptors imports (closes #2887) - #2909

Merged
fametrano merged 2 commits into
btclib-org:mainfrom
dodoshell:iss-2887-imports-descriptors
Nov 4, 2026
Merged

fametrano merged 2 commits into
btclib-org:mainfrom
dodoshell:iss-2887-imports-descriptors

Conversation

@dodoshell

@dodoshell dodoshell commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

tests/imports_test.py now keeps btclib free of bip32_descriptors imports, as it already did for btclib_wallet. bip32_descriptors depends on btclib too, so an import of it from src/btclib would be a cycle the suite let through.

_is_btclib_or_wallet also matches bip32_descriptors, and test_the_application_slab_has_no_inbound_edge counts it among the slab roots. The scan test plants import bip32_descriptors.bip32 and from bip32_descriptors import descriptors beside the btclib_wallet ones; it reads more than two names now, so it is renamed test_the_application_slab_scan_reads_every_name.

Closes #2887

How it was verified

  • import bip32_descriptors.bip32 appended to src/btclib/alias.py: test_the_application_slab_has_no_inbound_edge fails with {'alias.py': ['bip32_descriptors.bip32']}; the same plant with main's tests/imports_test.py passes. Plant reverted.
  • uv run pytest: 24443 passed, 102 skipped, coverage 100.00%.

Checks

  • uv run pre-commit run --all-files is clean (ruff, mypy strict,
    markdownlint, the copyright notice, uv.lock)
  • uv run pytest passes
  • I have read and understood every line of this change, and can
    answer a review of it without the model

The pre-commit box is unticked because the hook set can't run in full on my Windows machine: the hooks that check Python files pass, and the markdown and line-ending hooks are left to CI.

Summary by CodeRabbit

  • Tests
    • Updated import-boundary checks to cover both external application packages and their submodules, while verifying that imports from either package remain outside btclib.
  • Documentation
    • Updated architecture and assurance documentation to describe the import boundaries and their test coverage.

…tclib-org#2887)

`tests/imports_test.py` checked that btclib imports nothing of
`btclib_wallet`, but not of `bip32_descriptors`, which depends on btclib
as well. `_is_btclib_or_wallet` now matches `bip32_descriptors` names
too, and the slab check counts the package among its roots, so a
planted `import bip32_descriptors.bip32` in `src/btclib` fails
`test_the_application_slab_has_no_inbound_edge`. The scan test plants
imports of both packages and is renamed `reads_every_name`, since it
reads more than two names now.

Signed-off-by: dodoshell <326978213+dodoshell@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The import checks now recognize bip32_descriptors and its submodules alongside btclib_wallet. The planted-import test and inbound-edge check cover both packages. The architecture documents now describe these tested import boundaries.

Changes: Import boundary checks

Layer / File(s) Summary
Expand external package checks
tests/imports_test.py, ARCHITECTURE.md, ASSURANCE_CASE.md
The scanner recognizes imports from both external packages. The planted-import test and inbound-edge check cover both package roots. The architecture documents describe the tested boundaries.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: fametrano

Merge Risk: Minimal · up to 7c600

The change only broadens import-boundary test enforcement and matching documentation; no production behavior or actionable merge risk is introduced.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: updating imports_test to prevent btclib from importing bip32_descriptors. The issue reference is relevant.
Linked Issues check Passed Issue #2887 has two coding requirements. tests/imports_test.py adds _DESCRIPTORS_PACKAGE = "bip32_descriptors", updates _is_btclib_or_slab and _btclib_names_imported_by to recognize the packag…
Out of Scope Changes check Passed The whole-PR diff changes tests/imports_test.py, ARCHITECTURE.md, and ASSURANCE_CASE.md. The test changes enforce issue #2887. The documentation changes record the same one-way import boundary a…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

Issue #2887 has two coding requirements. tests/imports_test.py adds _DESCRIPTORS_PACKAGE = "bip32_descriptors", updates _is_btclib_or_slab and _btclib_names_imported_by to recognize the package and its submodules, and adds the package to slab_roots. The scan test plants import bip32_descriptors.bip32 and asserts that the scanner returns the package names. These changes implement both requirements. The reported planted-import failure and full pytest result provide additional author-reported verification.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff changes tests/imports_test.py, ARCHITECTURE.md, and ASSURANCE_CASE.md. The test changes enforce issue #2887. The documentation changes record the same one-way import boundary and identify the enforcing test. No unrelated source or test behavior appears in the diff.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 1 files. (2 skipped: 2 unsupported.)

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.1)

ast-grep could not parse rule config: /ast-grep-rules/ast-grep-essentials/rules/cpp/security/weak-cipher-openssl-cpp.yml

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c8e335f0-4e5b-4c24-9c2f-64ce0e59fb45
Commits

Reviewing files that changed from the base of the PR and between 7a469d4 and 7c6002b.

Files selected for processing: 3
  • ARCHITECTURE.md
  • ASSURANCE_CASE.md
  • tests/imports_test.py
Files skipped from review as they are similar to previous changes: 1
  • tests/imports_test.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pmazzocchi

Copy link
Copy Markdown
Contributor

Claimed: a /btclib-pr session of @pmazzocchi is reviewing this pull request locally before deciding on its approval.

@pmazzocchi pmazzocchi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this: the test change is right and meets ISS #2887's Done when, and two sentences elsewhere need to follow it before it can land.

A local review ran the test as written against a planted import bip32_descriptors.bip32 in src/btclib/alias.py: your version fails it and main's passes it, and seven other import shapes (an alias, from … import *, a TYPE_CHECKING block, a function-local import, among them) fail it too. CI is green on this head.

The diff now makes test_the_application_slab_has_no_inbound_edge hold the bip32_descriptors direction as well, but ARCHITECTURE.md still lists only the edge to btclib_wallet as held by a test (the Layers paragraph, "the edge to btclib_wallet below, each held by a test", and the bip32-descriptors bullet under What sits outside the package, which says only "It imports btclib."), and ASSURANCE_CASE.md's Layering bullet names only btclib_wallet. A reader of those files concludes nothing holds the descriptors edge. The fix is to name both packages in the three places, for example "the edges to bip32_descriptors and btclib_wallet below" and "It imports btclib, and nothing in btclib imports it: tests/imports_test.py holds that edge to one direction.", refilling each paragraph.

The two new comments in tests/imports_test.py say bip32/ and descriptors/ "have since moved on to" and "moved to" bip32_descriptors. btclib-wallet's main still ships both packages, and btclib-org/.github#1811 is open, so the move is not done; the tree's prose also avoids history. Something true before and after the move would read "bip32_descriptors publishes bip32/ and descriptors/" and "the import package that publishes bip32/ and descriptors/ (btclib-org/.github#1811)". A smaller point: _is_btclib_or_wallet now also answers for bip32_descriptors, so a name such as _is_btclib_or_slab would read better.

@pmazzocchi

Copy link
Copy Markdown
Contributor

Released: the /btclib-pr session hands this back to its author, with the review above.

…beside btclib_wallet (issue btclib-org#2887)

Signed-off-by: dodoshell <326978213+dodoshell@users.noreply.github.com>
@dodoshell

Copy link
Copy Markdown
Contributor Author

Thanks, all three places now name both packages, the two comments say what bip32_descriptors publishes instead of where things moved, and the helper is _is_btclib_or_slab.

@fametrano fametrano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approves 7c6002b, on the maintainer's decision of 2026-11-04.

Codex, as the fresh reviewer, cleared 7c6002b with no findings, and read the added prose on the merge with main. Every point of @pmazzocchi's review is answered in 7c6002b. Every check passed; the review bot does not run on a fork's pull request, so there is no ACK. No thread is open, the diff touches nothing under .github/, and it merges cleanly with main. Not checked: a planted import against the real tree, which the pull request's body and the earlier review report.

@fametrano
fametrano merged commit ac21675 into btclib-org:main Nov 4, 2026
20 checks passed
@fametrano

Copy link
Copy Markdown
Member

Thank you, @dodoshell: this is on main as ac21675, under your name, and #2887 is closed.

tests/imports_test.py now guards btclib against importing bip32_descriptors as well as btclib_wallet. Both packages sit above btclib, and an import going the other way would make btclib depend on its own dependents. The scan test plants an import of each package, so it fails at once if that guard ever stops looking.

Nothing was added on our side. Your second commit answered every point of the earlier review: the predicate's new name, the two test comments, and the three passages in ARCHITECTURE.md and ASSURANCE_CASE.md. One thing the test does not catch, here or on main, is an importlib.import_module(...) call or a relative from . import. If you want a next step, that would make a good issue.

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.

imports_test does not keep btclib free of bip32_descriptors imports

3 participants