Skip to content

test(backend): derive test-isolation stub membership instead of hand-listing it - #11946

Merged
Git-on-my-level merged 1 commit into
mainfrom
agent/m4-air/derived-test-isolation-membership
Aug 20, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
agent/m4-air/derived-test-isolation-membership

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

The drift

33 backend test files stub utils.conversations.* using hand-maintained lists of module names. That package holds 25 submodules; each file names only the few it happens to need.

#11888 added utils/conversations/meeting_receipt.py and imported it from routers/conversations.py. Two of those suites failed in CI at collection:

ModuleNotFoundError: No module named 'utils.conversations.meeting_receipt'

That reads as a product bug rather than a stale fixture, and the module's author hits it in CI rather than the fixture's owner hitting it locally.

FC-hand-listed-test-isolation-membership already describes this exactly, and prescribes the cure: derive membership from the source signal, union it with the explicit list so omission is not an opt-out, and prove the derivation with an adopter deliberately absent from that list. Its canonical_prevention_artifact named only the Swift runner — the backend carried the same class with no guard. This adds one, and updates the class record to name it.

The guard

package_submodule_stubs(package, *, extra=(), include_package=True) enumerates a package's real submodules from disk — never importing them, so no package side effect runs — and unions extra.

It resolves the directory relative to the backend root rather than through importlib.util.find_spec, because inside a stub_modules block the package is already a stub whose __spec__ is None, so spec lookup would report the fake.

Three properties matter, and each has a test:

  • Private modules are included. A router can from pkg._private import X; skipping _-prefixed names would reproduce the same omission bug.
  • Enumeration recurses. A stubbed sub-package carries an empty __path__, which would otherwise block from pkg.child.leaf import X from resolving against the real tree.
  • A package is detected by containing modules, not by __init__.py. utils/conversations/ is a namespace package with no __init__.py; requiring that file would miss the very package in the incident.

Verification

Added a module to utils/conversations/, imported it from the router with a dotted import, and ran the two suites:

result
before (hand-listed fixtures) 10 errors — ModuleNotFoundError
after (derived) 10 passed

Repeated for a _-prefixed module and a nested sub-package leaf: both covered.

The import form matters and is worth knowing for anyone testing this: from pkg import new resolves through the stubbed parent's __getattr__ and does not reproduce the failure. Only a dotted from pkg.new import X does.

43 tests pass across the three touched suites.

Scope

Two suites adopt the helper — the two that actually broke. The remaining ~31 hand-listed suites are untouched; migrating them is a mechanical sweep with real regression risk and belongs in its own change. No production code is modified.

Failure-Class: FC-hand-listed-test-isolation-membership

Review in cubic

…listing it

33 backend test files stub `utils.conversations.*` with hand-maintained lists of
module names, for a package holding 25 submodules; each file names only the few
it happens to need. #11888 added `utils/conversations/meeting_receipt.py` and
imported it from `routers/conversations.py`, and two of those suites failed in CI
at *collection* with ModuleNotFoundError - which reads as a product bug rather
than a stale fixture, and which the module's author hits in CI rather than the
fixture's owner hitting it locally.

FC-hand-listed-test-isolation-membership already describes this exactly, and
prescribes the cure: derive membership from the source signal, union it with the
explicit list so omission is not an opt-out, and prove the derivation with an
adopter deliberately absent from that list. Its canonical_prevention_artifact
named only the Swift runner; the backend carried the same class with no guard.

Add `package_submodule_stubs`, which enumerates a package's real submodules from
disk - never importing them, so no package side effect runs - and unions `extra`.
It resolves the directory relative to the backend root rather than through
`importlib.util.find_spec`, because inside a `stub_modules` block the package is
already a stub whose `__spec__` is None, so spec lookup would report the fake.

Three properties matter and are covered by tests. Private `_`-prefixed modules
are included: a router can `from pkg._private import X`, which is the same
omission bug. Enumeration recurses, because a stubbed sub-package carries an
empty `__path__` and would otherwise block `from pkg.child.leaf import X` from
resolving. And `utils.conversations` has no `__init__.py`, so a package is
detected by containing modules rather than by that file.

Adopt it in the two suites that actually broke. Verified by adding a module to
the package and importing it dotted from the router: 10 errors before, 10 passed
after. The import form matters - `from pkg import new` resolves through the
stubbed parent's __getattr__ and does not reproduce the failure.

The remaining ~31 hand-listed suites are untouched and remain follow-up work.

Failure-Class: FC-hand-listed-test-isolation-membership

Co-Authored-By: Claude Opus 5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 81fd3e2 into main Aug 20, 2026
41 checks passed
@Git-on-my-level
Git-on-my-level deleted the agent/m4-air/derived-test-isolation-membership branch August 20, 2026 20:03
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.

1 participant