Files
learningcircuit--local-deep…/tests/test_domain_classifier_no_import_cycle.py
wehub-resource-sync 7a0da7932b
Backwards Compatibility / Verify Encryption Constants (push) Waiting to run
Backwards Compatibility / PyPI Version Compatibility (push) Waiting to run
Backwards Compatibility / Database Migration Tests (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (python) (push) Waiting to run
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Blocked by required conditions
Docker Tests (Consolidated) / detect-changes (push) Waiting to run
Docker Tests (Consolidated) / Build Test Image (push) Waiting to run
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Blocked by required conditions
Docker Tests (Consolidated) / Accessibility Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Unit Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Example Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / Production Image Smoke Test (push) Blocked by required conditions
Docker Tests (Consolidated) / Infrastructure Tests (push) Blocked by required conditions
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Waiting to run
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

63 lines
2.6 KiB
Python

"""Regression: ``domain_classifier.models`` must import without a cycle.
``domain_classifier.models`` defines the ``DomainClassification`` model and
needs SQLAlchemy's ``Base``. It used to import ``Base`` from the
``..database.models`` *package*, whose ``__init__`` eagerly imports every model
— including ``DomainClassification`` back from this module. Importing
``domain_classifier.models`` first (before ``database.models`` was cached)
crashed at import time::
ImportError: cannot import name 'DomainClassification' from partially
initialized module 'local_deep_research.domain_classifier.models'
The fix imports ``Base`` from the dependency-free ``database.base`` leaf
instead. Because ``database`` is a namespace package (no ``__init__.py``),
importing ``database.base`` never triggers ``database.models.__init__`` — so the
eager re-import of ``DomainClassification`` is never reached. (Importing from
``database.models.base`` would NOT work: pulling any submodule of
``database.models`` first runs that package's ``__init__``, re-triggering the
cycle.) These checks import the cycle-critical modules in FRESH interpreters —
pytest's module cache would mask a real cycle within a single process (whatever
imports ``database.models`` first hides it) — and assert they load cleanly.
"""
import subprocess
import sys
import pytest
# Each statement must import on its own in a clean interpreter. The first is the
# one that regressed; the others guard the surrounding cycle members.
CYCLE_CRITICAL = [
"import local_deep_research.domain_classifier.models",
"from local_deep_research.domain_classifier.models import DomainClassification",
"import local_deep_research.database.models",
"import local_deep_research.domain_classifier",
]
@pytest.mark.parametrize("stmt", CYCLE_CRITICAL)
def test_cycle_critical_module_imports_clean(stmt):
result = subprocess.run(
[sys.executable, "-c", stmt],
capture_output=True,
text=True,
timeout=120,
)
assert result.returncode == 0, (
"Import failed (possible reintroduced circular import):\n"
f" statement: {stmt}\n{result.stderr}"
)
def test_domain_classification_shares_the_canonical_base():
"""The model must register on the same Base as the rest of the schema."""
from local_deep_research.database.models import Base
from local_deep_research.database.models.base import Base as LeafBase
from local_deep_research.domain_classifier.models import (
DomainClassification,
)
assert Base is LeafBase
assert DomainClassification.__table__.metadata is Base.metadata