diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ef14fe2 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: CI + +on: + push: + branches: [ "main", "master" ] + pull_request: + branches: [ "main", "master" ] + +jobs: + lint-and-test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v3 + with: + version: "latest" + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12.3" + + - name: Install dependencies + run: uv sync + + - name: Check formatting (ruff) + run: uv run ruff format --check . + + - name: Lint (ruff) + run: uv run ruff check . + + - name: Type check (pyright) + run: uv run pyright + + - name: OCA Lint + run: bash scripts/oca_lint.sh + + - name: Run unit tests (pytest) + run: uv run pytest tests/ -x -q diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..7e34abe --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,15 @@ +repos: + - repo: local + hooks: + - id: ruff-format + name: ruff format + entry: uv run ruff format --force-exclude + language: system + types: [python] + require_serial: false + - id: ruff-check + name: ruff check + entry: uv run ruff check --force-exclude + language: system + types: [python] + require_serial: false diff --git a/AGENTS.MD b/AGENTS.MD new file mode 100644 index 0000000..92c91b5 --- /dev/null +++ b/AGENTS.MD @@ -0,0 +1,26 @@ +# AI Agent Rules for Parqcast Workspace + +This document defines the constraints, architecture boundaries, and tooling instructions for AI coding assistants working in the `parqcast` repository. Before generating or editing code, agents must understand and adhere strictly to these rules. + +## 1. Toolchain & Workspace Constraints +- **Workspace Tool**: The project uses `uv` as the workspace manager. All dependency management and command running must go through `uv` (e.g., `uv sync`, `uv run pytest`). +- **Strict Type Checking**: We use `pyright` in strict mode. All new code must pass `uv run pyright` without generating `Unknown` or `Any` leakage. Avoid casting unless interfacing with dynamic ORM attributes, and even then, rely on `pyproject.toml` suppressions where configured. +- **Linting & Formatting**: Code must pass `uv run ruff check .` and `uv run ruff format --check .`. The configured line length is 120. + +## 2. Architecture Boundaries +Parqcast is strictly layered. Agents must NEVER introduce imports that violate these boundaries: +- **`packages/parqcast-core/`**: Defines data schemas, pyarrow constructs, and protocol interfaces. **Constraint:** Must NEVER import from `odoo`, `psycopg2`, or any other workspace package. +- **`packages/parqcast-collectors/`**: Executes fast raw SQL queries using `psycopg2` to build arrow arrays. **Constraint:** Must NEVER import `odoo` ORM models. +- **`packages/parqcast-ingesters/`**: Pulls data via Odoo ORM to push planning decisions back. This is the ONLY python package (outside the addon itself) permitted to use dynamic Odoo typing. +- **`packages/parqcast-transport-http/`**: Handles HTTP uploads of generated chunks. +- **`packages/parqcast/`**: The Odoo addon. It bridges the environment with the workspace packages. **Constraint:** Must pass Odoo Community Association (OCA) linting via `bash scripts/oca_lint.sh`. + +## 3. Odoo Versioning (PEP 695 Generics) +Parqcast certifies per Odoo major. +- Do not use dynamic runtime version checks in core logic. +- Instead, use PEP 695 generics (`type V18`, `type V19`) to tag and enforce version-specific implementations at compile time. Pyright enforces that a `V18` component cannot be accidentally mixed with a `V19` context. +- For local type checking of Odoo symbols, use the `stubs/odoo-stubs/` local directory. + +## 4. Testing +- Use `uv run pytest tests/ -x -q` to verify logic. +- Do not run `tests/test_live_db.py` without the `PARQCAST_TEST_DB` environment variable set. diff --git a/packages/parqcast-collectors/src/parqcast/collectors/__init__.py b/packages/parqcast-collectors/src/parqcast/collectors/__init__.py index b68db63..2df48f4 100644 --- a/packages/parqcast-collectors/src/parqcast/collectors/__init__.py +++ b/packages/parqcast-collectors/src/parqcast/collectors/__init__.py @@ -1,3 +1,8 @@ +# Importing v18 / v19 registers their bundles into +# parqcast.core.registry.REGISTRY. Consumers look up collectors/suites +# via REGISTRY[version_str] rather than importing a flat list from here. +from . import v18 as v18 +from . import v19 as v19 from .base import BaseCollector as BaseCollector from .base import CoreCollector as CoreCollector from .base import MpsCollector as MpsCollector @@ -7,9 +12,3 @@ from .base import QualityCollector as QualityCollector from .base import SaleCollector as SaleCollector from .base import StockCollector as StockCollector - -# Importing v18 / v19 registers their bundles into -# parqcast.core.registry.REGISTRY. Consumers look up collectors/suites -# via REGISTRY[version_str] rather than importing a flat list from here. -from . import v18 as v18 # noqa: F401 -from . import v19 as v19 # noqa: F401 diff --git a/packages/parqcast-collectors/src/parqcast/collectors/base.py b/packages/parqcast-collectors/src/parqcast/collectors/base.py index 0cfa57a..8039c92 100644 --- a/packages/parqcast-collectors/src/parqcast/collectors/base.py +++ b/packages/parqcast-collectors/src/parqcast/collectors/base.py @@ -100,6 +100,12 @@ def collect(self, key_from: int = 0, key_to: int = 0) -> pa.Table: # Apply keyset pagination bounds if key_from > 0 or key_to > 0: + import re + + # Strip trailing ORDER BY if present to prevent syntax errors when we append our own. + # Only matches simple trailing ORDER BY clauses to avoid breaking subqueries. + sql = re.sub(r"(?i)\s+ORDER\s+BY\s+[\w\s,.]+$", "", sql) + joiner = " AND" if self._sql_has_where(sql) else "\nWHERE" if key_from > 0: sql += f"{joiner} {self.pk_column} >= {key_from}" @@ -155,7 +161,8 @@ def _to_table(self, rows: list[OdooRow]) -> pa.Table: # resulting Field/Table values come back as unknown even though # their .name / schema usage is well-defined in practice. cols: dict[str, list[object]] = { - field.name: [] for field in self.schema # pyright: ignore[reportUnknownVariableType] + field.name: [] + for field in self.schema # pyright: ignore[reportUnknownVariableType] } for row in rows: for i, field in enumerate(self.schema): # pyright: ignore[reportUnknownVariableType] diff --git a/packages/parqcast-collectors/src/parqcast/collectors/v18/__init__.py b/packages/parqcast-collectors/src/parqcast/collectors/v18/__init__.py index 37eebdc..0bdb2b4 100644 --- a/packages/parqcast-collectors/src/parqcast/collectors/v18/__init__.py +++ b/packages/parqcast-collectors/src/parqcast/collectors/v18/__init__.py @@ -7,14 +7,14 @@ from __future__ import annotations -from . import bundle as bundle # noqa: F401 — side-effect: registers v18 bundle +from . import bundle as bundle +from .mps import MpsForecastCollectorV18, MpsScheduleCollectorV18 from .mrp_bom import ( BomByproductCollectorV18, BomCollectorV18, BomLinesCollectorV18, BomOperationsCollectorV18, ) -from .mps import MpsForecastCollectorV18, MpsScheduleCollectorV18 from .mrp_production import MrpProductionCollectorV18 from .mrp_workorder import MrpWorkorderCollectorV18 from .orderpoint import OrderpointCollectorV18 diff --git a/packages/parqcast-collectors/src/parqcast/collectors/v18/bundle.py b/packages/parqcast-collectors/src/parqcast/collectors/v18/bundle.py index 7aa718f..9c12e04 100644 --- a/packages/parqcast-collectors/src/parqcast/collectors/v18/bundle.py +++ b/packages/parqcast-collectors/src/parqcast/collectors/v18/bundle.py @@ -20,13 +20,13 @@ from ..currency import CurrencyCollector from ..partner import PartnerCollector from ..product_category import ProductCategoryCollector +from .mps import MpsForecastCollectorV18, MpsScheduleCollectorV18 from .mrp_bom import ( BomByproductCollectorV18, BomCollectorV18, BomLinesCollectorV18, BomOperationsCollectorV18, ) -from .mps import MpsForecastCollectorV18, MpsScheduleCollectorV18 from .mrp_production import MrpProductionCollectorV18 from .mrp_workorder import MrpWorkorderCollectorV18 from .orderpoint import OrderpointCollectorV18 @@ -168,9 +168,7 @@ ) -V18_COLLECTORS: tuple[type, ...] = tuple( - cls for suite in V18_SUITES for cls in suite.collector_classes -) +V18_COLLECTORS: tuple[type, ...] = tuple(cls for suite in V18_SUITES for cls in suite.collector_classes) append_to_bundle( diff --git a/packages/parqcast-collectors/src/parqcast/collectors/v19/__init__.py b/packages/parqcast-collectors/src/parqcast/collectors/v19/__init__.py index 0945fb1..c06dc4e 100644 --- a/packages/parqcast-collectors/src/parqcast/collectors/v19/__init__.py +++ b/packages/parqcast-collectors/src/parqcast/collectors/v19/__init__.py @@ -7,7 +7,7 @@ from __future__ import annotations -from . import bundle as bundle # noqa: F401 — side-effect: registers v19 bundle +from . import bundle as bundle from .mps import MpsForecastCollectorV19, MpsScheduleCollectorV19 from .mrp_bom import ( BomByproductCollectorV19, diff --git a/packages/parqcast-collectors/src/parqcast/collectors/v19/bundle.py b/packages/parqcast-collectors/src/parqcast/collectors/v19/bundle.py index 9e0189b..780463f 100644 --- a/packages/parqcast-collectors/src/parqcast/collectors/v19/bundle.py +++ b/packages/parqcast-collectors/src/parqcast/collectors/v19/bundle.py @@ -167,9 +167,7 @@ ) -V19_COLLECTORS: tuple[type, ...] = tuple( - cls for suite in V19_SUITES for cls in suite.collector_classes -) +V19_COLLECTORS: tuple[type, ...] = tuple(cls for suite in V19_SUITES for cls in suite.collector_classes) append_to_bundle( diff --git a/packages/parqcast-collectors/src/parqcast/orchestrator/__init__.py b/packages/parqcast-collectors/src/parqcast/orchestrator/__init__.py index c50783d..25edc03 100644 --- a/packages/parqcast-collectors/src/parqcast/orchestrator/__init__.py +++ b/packages/parqcast-collectors/src/parqcast/orchestrator/__init__.py @@ -110,6 +110,7 @@ def visit(name: str) -> None: visit(c.name) return order + # Default time budget: 4.5 minutes, leaving 30s buffer for cleanup DEFAULT_TIME_BUDGET = 270 @@ -349,7 +350,9 @@ def _finalize(self, cr: ReadCursor, run: ExportRun, prefix: str, t0: float) -> J uploaded = self.chunk_cls.find_by_state(cr, run.id, "uploaded") file_metas = [chunk_rec.get_metadata(cr) for chunk_rec in uploaded] - errors = [f"{c.collector}: {c.state}" for c in self.chunk_cls.find_by_state(cr, run.id, "error")] + errors = [ + f"{c.collector}: {c.error_message or c.state}" for c in self.chunk_cls.find_by_state(cr, run.id, "error") + ] # Re-probe for capabilities (needed for manifest) bundle, probe = _resolve_bundle(cr) @@ -359,6 +362,7 @@ def _finalize(self, cr: ReadCursor, run: ExportRun, prefix: str, t0: float) -> J files=file_metas, company=self.company, company_id=self.company_id, + odoo_version=caps.odoo_version, total_duration=round(time.monotonic() - t0, 3), errors=errors, warnings=[], @@ -373,9 +377,6 @@ def _finalize(self, cr: ReadCursor, run: ExportRun, prefix: str, t0: float) -> J run.set_state(cr, "done") self._commit() - self.run_cls.cleanup_old(cr) - self._commit() - logger.info( "Run %s complete: %d files, %d errors", run.run_uuid[:8], diff --git a/packages/parqcast-core/src/parqcast/core/manifest.py b/packages/parqcast-core/src/parqcast/core/manifest.py index 285b957..91f4246 100644 --- a/packages/parqcast-core/src/parqcast/core/manifest.py +++ b/packages/parqcast-core/src/parqcast/core/manifest.py @@ -15,7 +15,7 @@ def build_manifest( files: list[ChunkMetadata], company: str, company_id: int, - odoo_version: str = "17.0", + odoo_version: str, parqcast_version: str = "0.1.0", errors: list[str] | None = None, warnings: list[str] | None = None, diff --git a/packages/parqcast-core/src/parqcast/core/protocols.py b/packages/parqcast-core/src/parqcast/core/protocols.py index f0761df..e43344b 100644 --- a/packages/parqcast-core/src/parqcast/core/protocols.py +++ b/packages/parqcast-core/src/parqcast/core/protocols.py @@ -16,21 +16,21 @@ from __future__ import annotations from collections.abc import Mapping, Sequence -from typing import Any, NotRequired, Protocol, TypeAlias, TypedDict, runtime_checkable +from typing import Any, NotRequired, Protocol, TypedDict, runtime_checkable # --------------------------------------------------------------------------- # Named type aliases shared across the workspace. # --------------------------------------------------------------------------- -SqlParams: TypeAlias = Sequence[object] | Mapping[str, object] | None +type SqlParams = Sequence[object] | Mapping[str, object] | None """Positional or named parameters accepted by psycopg2's execute().""" -SqlWithParams: TypeAlias = tuple[str, SqlParams] +type SqlWithParams = tuple[str, SqlParams] """Return shape of ``BaseCollector.get_sql()``: a SQL string paired with bind-parameters (or None). Kept as a named alias so collector subclasses match the abstract signature verbatim.""" -JsonDict: TypeAlias = dict[str, object] +type JsonDict = dict[str, object] """A JSON-serializable dict payload. Used for manifests, capability summaries, chunk metadata, and anywhere @@ -39,7 +39,7 @@ nested JSON union because the consumers accept anything ``json.dumps`` can handle (via ``default=str`` if needed).""" -OdooRow: TypeAlias = tuple[object, ...] +type OdooRow = tuple[object, ...] """One row returned by a psycopg2/Odoo cursor's ``fetchone``/``fetchall``. Columns are positional; the tuple's arity depends on the SELECT clause.""" @@ -159,9 +159,7 @@ def __setattr__(self, name: str, value: Any) -> None: ... class OdooModel(Protocol): """An Odoo model accessor — what ``env[""]`` returns.""" - def create( - self, vals: Mapping[str, object] | list[Mapping[str, object]] - ) -> OdooRecord: ... + def create(self, vals: Mapping[str, object] | list[Mapping[str, object]]) -> OdooRecord: ... def search( self, domain: Sequence[object], @@ -180,5 +178,6 @@ class OdooEnvironment(Protocol): """ company: OdooRecord + cr: ReadCursor def __getitem__(self, model_name: str) -> OdooModel: ... diff --git a/packages/parqcast-core/src/parqcast/core/registry.py b/packages/parqcast-core/src/parqcast/core/registry.py index 4ce30e4..bdf4938 100644 --- a/packages/parqcast-core/src/parqcast/core/registry.py +++ b/packages/parqcast-core/src/parqcast/core/registry.py @@ -79,8 +79,7 @@ def append_to_bundle( current = REGISTRY.get(version) if current is None: raise RuntimeError( - f"append_to_bundle: no bundle registered for Odoo {version!r}; " - f"bootstrap should have installed one." + f"append_to_bundle: no bundle registered for Odoo {version!r}; bootstrap should have installed one." ) REGISTRY[version] = replace( current, diff --git a/packages/parqcast-core/src/parqcast/core/tracking.py b/packages/parqcast-core/src/parqcast/core/tracking.py index 5af29b4..1cd4467 100644 --- a/packages/parqcast-core/src/parqcast/core/tracking.py +++ b/packages/parqcast-core/src/parqcast/core/tracking.py @@ -52,9 +52,7 @@ def ensure_table(cls, cr: ReadCursor): """) @classmethod - def create( - cls, cr: ReadCursor, company_id: int | None = None, company_name: str = "" - ) -> ExportRun: + def create(cls, cr: ReadCursor, company_id: int | None = None, company_name: str = "") -> ExportRun: run_uuid = str(_uuid.uuid4()) cr.execute( """ @@ -154,6 +152,7 @@ def __init__( key_from: int = 0, key_to: int = 0, estimated_seconds: float = 0, + error_message: str | None = None, ): self.id = id self.run_id = run_id @@ -163,6 +162,7 @@ def __init__( self.key_from = key_from self.key_to = key_to self.estimated_seconds = estimated_seconds + self.error_message = error_message @classmethod def ensure_table(cls, cr: ReadCursor): @@ -220,7 +220,7 @@ def create( def find_by_state(cls, cr: ReadCursor, run_id: int, state: str) -> list[ExportChunk]: cr.execute( """ - SELECT id, run_id, collector, sequence, state, key_from, key_to, estimated_seconds + SELECT id, run_id, collector, sequence, state, key_from, key_to, estimated_seconds, error_message FROM parqcast_export_chunk WHERE run_id = %s AND state = %s ORDER BY sequence @@ -237,6 +237,7 @@ def find_by_state(cls, cr: ReadCursor, run_id: int, state: str) -> list[ExportCh key_from=r[5], key_to=r[6], estimated_seconds=r[7], + error_message=r[8], ) for r in fetch_all(cr) ] diff --git a/packages/parqcast-core/src/parqcast/core/version_gate.py b/packages/parqcast-core/src/parqcast/core/version_gate.py index 2c1fe04..5277be8 100644 --- a/packages/parqcast-core/src/parqcast/core/version_gate.py +++ b/packages/parqcast-core/src/parqcast/core/version_gate.py @@ -9,6 +9,8 @@ from __future__ import annotations +import importlib + from parqcast.core.protocols import ReadCursor from parqcast.core.registry import REGISTRY from parqcast.core.version import SupportedVersionStr, UnsupportedOdooVersionError @@ -21,10 +23,7 @@ def _read_odoo_major(cr: ReadCursor) -> str: same source of truth used by :func:`parqcast.core.capabilities.probe`. Returns an empty string if the row is missing. """ - cr.execute( - "SELECT latest_version FROM ir_module_module " - "WHERE name = 'base' AND state = 'installed' LIMIT 1" - ) + cr.execute("SELECT latest_version FROM ir_module_module WHERE name = 'base' AND state = 'installed' LIMIT 1") row = cr.fetchone() if not row or not row[0]: return "" @@ -40,6 +39,21 @@ def assert_supported(cr: ReadCursor) -> SupportedVersionStr: """ major = _read_odoo_major(cr) if major and major in REGISTRY: + bundle = REGISTRY[major] + if bundle.probe_capabilities is None: + # The bundle is registered but hasn't been imported yet. + # Force import now to ensure the version is genuinely supported and not + # just an empty bootstrap placeholder. + try: + importlib.import_module(f"parqcast.collectors.v{major}.bundle") + if REGISTRY[major].probe_capabilities is None: + raise RuntimeError("Import succeeded but probe_capabilities is still None") + except Exception as e: + raise UnsupportedOdooVersionError( + f"Odoo {major} is registered, but the corresponding subpackage " + f"failed to load. This parqcast installation might be corrupt " + f"or incomplete. Error: {e}" + ) from e return major supported = sorted(REGISTRY.keys()) or [""] detected = major or "" diff --git a/packages/parqcast-ingesters/src/parqcast/ingesters/__init__.py b/packages/parqcast-ingesters/src/parqcast/ingesters/__init__.py index 3890c73..7e592d3 100644 --- a/packages/parqcast-ingesters/src/parqcast/ingesters/__init__.py +++ b/packages/parqcast-ingesters/src/parqcast/ingesters/__init__.py @@ -1,9 +1,8 @@ -from .base import BaseIngester as BaseIngester - # Importing v18 / v19 registers their ingesters into # parqcast.core.registry.REGISTRY[version].ingesters. -from . import v18 as v18 # noqa: F401 -from . import v19 as v19 # noqa: F401 +from . import v18 as v18 +from . import v19 as v19 +from .base import BaseIngester as BaseIngester from .v19 import ( DistributionActorV19, OrderpointActorV19, diff --git a/packages/parqcast-ingesters/src/parqcast/receiver/__init__.py b/packages/parqcast-ingesters/src/parqcast/receiver/__init__.py index 6a7225d..0756744 100644 --- a/packages/parqcast-ingesters/src/parqcast/receiver/__init__.py +++ b/packages/parqcast-ingesters/src/parqcast/receiver/__init__.py @@ -6,7 +6,8 @@ from parqcast.core.manifest import validate_manifest from parqcast.core.protocols import JsonDict, OdooEnvironment -from parqcast.ingesters import ALL_INGESTERS +from parqcast.core.registry import REGISTRY +from parqcast.core.version_gate import assert_supported from parqcast.ingesters.base import IngestResult from parqcast.transport.base import BaseTransport @@ -52,8 +53,12 @@ def run(self, remote_prefix: str, cleanup: bool = True) -> JsonDict: type_col = table.column("decision_type").to_pylist() unique_types: set[str] = {t for t in type_col if isinstance(t, str)} + version = assert_supported(self.env.cr) + bundle = REGISTRY[version] + ingester_map = {cls.decision_type: cls for cls in bundle.ingesters} # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] + for dtype in unique_types: - ingester_cls = ALL_INGESTERS.get(dtype) + ingester_cls = ingester_map.get(dtype) # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] if not ingester_cls: results[dtype] = IngestResult(errors=1, messages=[f"Unknown decision type: {dtype}"]) continue diff --git a/packages/parqcast/__manifest__.py b/packages/parqcast/__manifest__.py index 8fcac9d..619cfe8 100644 --- a/packages/parqcast/__manifest__.py +++ b/packages/parqcast/__manifest__.py @@ -9,16 +9,15 @@ # major listed in `parqcast_supported_versions`. A pinned `19.0.x.y` # would be rejected by the v18 loader (which validates against # `18.0.x.y` or bare `x.y[.z]`). - "version": "3.0.0", + "version": "18.0.3.0.0", "category": "Supply Chain", "summary": "Zero-computation data pipe to cloud planning engines", - "author": "DataStruct s.r.o.", + "author": "DataStruct s.r.o., Odoo Community Association (OCA)", "website": "https://datastruct.tech", "support": "info@datastruct.tech", "development_status": "Beta", "maintainers": ["opopov-ai"], "license": "LGPL-3", - "installable": True, "application": True, "depends": ["base"], # Parqcast certifies per Odoo major. Installs refuse on any diff --git a/packages/parqcast/models/__init__.py b/packages/parqcast/models/__init__.py index b78c85f..73b22e7 100644 --- a/packages/parqcast/models/__init__.py +++ b/packages/parqcast/models/__init__.py @@ -3,8 +3,16 @@ from . import ( parqcast_chunk as parqcast_chunk, +) +from . import ( parqcast_cron as parqcast_cron, +) +from . import ( parqcast_run as parqcast_run, +) +from . import ( parqcast_settings as parqcast_settings, +) +from . import ( parqcast_version_gate as parqcast_version_gate, ) diff --git a/packages/parqcast/models/parqcast_cron.py b/packages/parqcast/models/parqcast_cron.py index 0a890ba..ac0538e 100644 --- a/packages/parqcast/models/parqcast_cron.py +++ b/packages/parqcast/models/parqcast_cron.py @@ -96,6 +96,11 @@ def run_export(self): ) result = orch.run() + + # Phase separation ensures cleanup only happens in its own transaction + # after the orchestrator successfully returns without throwing. + self.env["parqcast.run"].action_cleanup_old() + _logger.info("Parqcast export tick: %s", result.get("state", "done")) return result diff --git a/packages/parqcast/models/parqcast_run.py b/packages/parqcast/models/parqcast_run.py index 240245a..0d74b72 100644 --- a/packages/parqcast/models/parqcast_run.py +++ b/packages/parqcast/models/parqcast_run.py @@ -50,27 +50,68 @@ def init(self): ExportRun.ensure_table(self.env.cr) ExportChunk.ensure_table(self.env.cr) + def _delete_chunks(self, states: tuple[str, ...] | None = None) -> None: + """Delete tracking chunks associated with these runs, optionally filtered by state.""" + if not self.ids: + return + query = "DELETE FROM parqcast_export_chunk WHERE run_id IN %s" + params = [tuple(self.ids)] + if states: + query += " AND state IN %s" + params.append(states) + self.env.cr.execute(query, tuple(params)) + + def _set_state(self, state: str, error_message: str | None = None) -> None: + """Update the run state using raw SQL to bypass ORM caches.""" + if not self.ids: + return + self.env.cr.execute( + "UPDATE parqcast_export_run SET state = %s, error_message = %s WHERE id IN %s", + (state, error_message, tuple(self.ids)), + ) + + def _purge_chunk_blobs(self) -> None: + """Clear blob data from uploaded chunks to free database space.""" + if not self.ids: + return + self.env.cr.execute( + "UPDATE parqcast_export_chunk SET data = NULL WHERE run_id IN %s AND state = 'uploaded'", + (tuple(self.ids),), + ) + + def unlink(self): + """Delete tracking tables and associated attachments.""" + # Find all associated attachments and delete them first + attachments = ( + self.env["ir.attachment"] + .sudo() + .search( + [ + ("res_model", "=", "parqcast.run"), + ("res_id", "in", self.ids), + ] + ) + ) + if attachments: + attachments.unlink() + + # Delete the associated chunk rows first + self._delete_chunks() + + return super().unlink() + def action_cancel(self): """Cancel a stuck run — delete pending/created chunks, mark as error.""" for run in self: if run.state in ("pending", "collecting", "uploading"): - self.env.cr.execute( - "DELETE FROM parqcast_export_chunk WHERE run_id = %s AND state IN ('pending', 'created')", - (run.id,), - ) - self.env.cr.execute( - "UPDATE parqcast_export_run SET state = 'error', error_message = 'Cancelled by user' WHERE id = %s", - (run.id,), - ) + run._delete_chunks(("pending", "created")) + run._set_state("error", "Cancelled by user") _logger.info("Cancelled parqcast run %s", run.run_uuid) def action_purge_blobs(self): """Clear blob data from uploaded chunks to free database space.""" + self._purge_chunk_blobs() for run in self: - self.env.cr.execute( - "UPDATE parqcast_export_chunk SET data = NULL WHERE run_id = %s AND state = 'uploaded'", - (run.id,), - ) _logger.info("Purged blob data for run %s", run.run_uuid) def action_cleanup_old(self): @@ -78,26 +119,38 @@ def action_cleanup_old(self): ICP = self.env["ir.config_parameter"].sudo() days = int(ICP.get_param("parqcast.cleanup_days", "30")) cutoff = fields.Datetime.now() - timedelta(days=days) - self.env.cr.execute( - "DELETE FROM parqcast_export_run WHERE state = 'done' AND finished_at < %s", - (cutoff,), - ) - _logger.info("Cleaned up parqcast runs older than %d days", days) + + old_runs = self.search([("state", "=", "done"), ("finished_at", "<", cutoff)]) + if old_runs: + old_runs.unlink() + _logger.info("Cleaned up %d parqcast runs older than %d days", len(old_runs), days) def _compute_attachment_count(self): for run in self: - run.attachment_count = self.env["ir.attachment"].sudo().search_count([ - ("res_model", "=", "parqcast.run"), - ("res_id", "=", run.id), - ]) + run.attachment_count = ( + self.env["ir.attachment"] + .sudo() + .search_count( + [ + ("res_model", "=", "parqcast.run"), + ("res_id", "=", run.id), + ] + ) + ) def action_download_zip(self): """Download all parquet attachments for this run as a ZIP file.""" self.ensure_one() - attachments = self.env["ir.attachment"].sudo().search([ - ("res_model", "=", "parqcast.run"), - ("res_id", "=", self.id), - ]) + attachments = ( + self.env["ir.attachment"] + .sudo() + .search( + [ + ("res_model", "=", "parqcast.run"), + ("res_id", "=", self.id), + ] + ) + ) if not attachments: return { "type": "ir.actions.client", @@ -116,11 +169,17 @@ def action_download_zip(self): zf.writestr(att.name, base64.b64decode(att.datas)) buf.seek(0) - zip_att = self.env["ir.attachment"].sudo().create({ - "name": f"parqcast_export_{self.run_uuid[:8]}.zip", - "datas": base64.b64encode(buf.read()).decode(), - "mimetype": "application/zip", - }) + zip_att = ( + self.env["ir.attachment"] + .sudo() + .create( + { + "name": f"parqcast_export_{self.run_uuid[:8]}.zip", + "datas": base64.b64encode(buf.read()).decode(), + "mimetype": "application/zip", + } + ) + ) return { "type": "ir.actions.act_url", "url": f"/web/content/{zip_att.id}?download=true", diff --git a/packages/parqcast/models/parqcast_settings.py b/packages/parqcast/models/parqcast_settings.py index 5655b36..69a36bb 100644 --- a/packages/parqcast/models/parqcast_settings.py +++ b/packages/parqcast/models/parqcast_settings.py @@ -4,6 +4,7 @@ from typing import Any from odoo import api, fields, models +from odoo.exceptions import ValidationError # pyright: ignore[reportMissingImports] class ResConfigSettings(models.TransientModel): @@ -77,20 +78,58 @@ class ResConfigSettings(models.TransientModel): parqcast_company_id = fields.Many2one( "res.company", string="Export Company", + config_parameter="parqcast.company_id", ) parqcast_cron_active = fields.Boolean( string="Enable Scheduled Export", ) parqcast_schedule_mode = fields.Selection( - [("daily", "Once daily (midnight UTC)"), ("continuous", "Continuous (every 5 minutes)")], + [("daily", "Every day"), ("continuous", "Continuous (every 5 minutes)")], string="Schedule", default="daily", config_parameter="parqcast.schedule_mode", ) + # Status Block + parqcast_odoo_version = fields.Char(string="Detected Odoo Version", compute="_compute_parqcast_status") + parqcast_last_run_state = fields.Char(string="Last Run State", compute="_compute_parqcast_status") + parqcast_last_run_error = fields.Text(string="Last Run Error", compute="_compute_parqcast_status") + + def _compute_parqcast_status(self): + for rec in self: + from parqcast.core.version_gate import _read_odoo_major # pyright: ignore[reportPrivateUsage] + + rec.parqcast_odoo_version = _read_odoo_major(self.env.cr) or "Unknown" # pyright: ignore[reportPrivateUsage] + + last_run = self.env["parqcast.run"].search([], limit=1, order="id desc") + if last_run: + state_dict = dict(last_run._fields["state"].selection) + rec.parqcast_last_run_state = state_dict.get(last_run.state, last_run.state) + rec.parqcast_last_run_error = last_run.error_message + else: + rec.parqcast_last_run_state = "No runs yet" + rec.parqcast_last_run_error = False + + @api.constrains("parqcast_time_budget") + def _check_time_budget(self): + for rec in self: + if rec.parqcast_time_budget < 30: + raise ValidationError(self.env._("Time budget must be at least 30 seconds to allow progress.")) # pyright: ignore[reportAttributeAccessIssue] + + def _display_notification(self, title: str, message: str, msg_type: str = "success") -> dict[str, Any]: + return { + "type": "ir.actions.client", + "tag": "display_notification", + "params": { + "title": title, + "message": message, + "type": msg_type, + "sticky": False, + }, + } + def set_values(self) -> Any: res = super().set_values() - self.env["ir.config_parameter"].sudo().set_param("parqcast.company_id", str(self.parqcast_company_id.id or 0)) cron = self.env.ref("parqcast.ir_cron_parqcast_export", raise_if_not_found=False) if cron: cron_sudo = cron.sudo() @@ -106,22 +145,53 @@ def set_values(self) -> Any: @api.model def get_values(self) -> dict[str, Any]: res = super().get_values() - cid = int(self.env["ir.config_parameter"].sudo().get_param("parqcast.company_id", "0")) - res["parqcast_company_id"] = cid or False cron = self.env.ref("parqcast.ir_cron_parqcast_export", raise_if_not_found=False) res["parqcast_cron_active"] = cron.active if cron else False return res def action_run_export_now(self): """Manually trigger one export tick.""" - self.env["parqcast.cron"].run_export() - return { - "type": "ir.actions.client", - "tag": "display_notification", - "params": { - "title": "Parqcast", - "message": "Export tick completed. Check Export Runs for results.", - "type": "success", - "sticky": False, - }, - } + result = self.env["parqcast.cron"].run_export() + state = result.get("state", "done") + chunks = result.get("files", []) + + msg = f"Export tick completed. State: {state}." + if state == "error": + msg = "Export tick failed with an error. Check Export Runs for details." + elif chunks: + msg = f"Export tick complete. {len(chunks)} files prepared/uploaded." + + return self._display_notification("Parqcast", msg, "danger" if state == "error" else "success") + + def action_test_http_connection(self): + """Test HTTP Server reachability.""" + from ..utils.transports import test_http_reachability + + for rec in self: + if not rec.parqcast_server_url: + raise ValidationError(self.env._("Server URL is required.")) # pyright: ignore[reportAttributeAccessIssue] + try: + test_http_reachability(rec.parqcast_server_url, rec.parqcast_api_key) + except Exception as e: + raise ValidationError(self.env._("Connection failed: ") + str(e)) from e # pyright: ignore[reportAttributeAccessIssue] + return self._display_notification("Connection Test", "HTTP Server is reachable.") + + def action_test_s3_connection(self): + """Test S3 Bucket accessibility.""" + from ..utils.transports import test_s3_reachability + + for rec in self: + if not rec.parqcast_s3_bucket: + raise ValidationError(self.env._("S3 Bucket is required.")) # pyright: ignore[reportAttributeAccessIssue] + try: + test_s3_reachability( + rec.parqcast_s3_bucket, + rec.parqcast_s3_endpoint_url, + rec.parqcast_s3_access_key_id, + rec.parqcast_s3_secret_access_key, + rec.parqcast_s3_region, + ) + except Exception as e: + raise ValidationError(self.env._("S3 Connection failed: ") + str(e)) from e # pyright: ignore[reportAttributeAccessIssue] + + return self._display_notification("Connection Test", "S3 Bucket is accessible.") diff --git a/packages/parqcast/models/transport_attachment.py b/packages/parqcast/models/transport_attachment.py index 3651859..19b3df0 100644 --- a/packages/parqcast/models/transport_attachment.py +++ b/packages/parqcast/models/transport_attachment.py @@ -36,30 +36,45 @@ def _resolve_run_id(self, prefix: str) -> int: def upload_file(self, prefix: str, filename: str, data: BinaryIO) -> None: run_id = self._resolve_run_id(prefix) content = data.read() - self._env["ir.attachment"].sudo().create({ - "name": filename, - "datas": base64.b64encode(content).decode(), - "res_model": "parqcast.run", - "res_id": run_id, - "mimetype": "application/octet-stream", - }) + self._env["ir.attachment"].sudo().create( + { + "name": filename, + "datas": base64.b64encode(content).decode(), + "res_model": "parqcast.run", + "res_id": run_id, + "mimetype": "application/octet-stream", + } + ) _logger.debug("Stored attachment %s for run %s (%d bytes)", filename, prefix, len(content)) def download_file(self, prefix: str, filename: str) -> bytes: run_id = self._resolve_run_id(prefix) - att = self._env["ir.attachment"].sudo().search([ - ("res_model", "=", "parqcast.run"), - ("res_id", "=", run_id), - ("name", "=", filename), - ], limit=1) + att = ( + self._env["ir.attachment"] + .sudo() + .search( + [ + ("res_model", "=", "parqcast.run"), + ("res_id", "=", run_id), + ("name", "=", filename), + ], + limit=1, + ) + ) if not att: raise FileNotFoundError(f"Attachment not found: {filename} (run {prefix})") return base64.b64decode(att.datas) def list_files(self, prefix: str) -> list[str]: run_id = self._resolve_run_id(prefix) - atts = self._env["ir.attachment"].sudo().search([ - ("res_model", "=", "parqcast.run"), - ("res_id", "=", run_id), - ]) + atts = ( + self._env["ir.attachment"] + .sudo() + .search( + [ + ("res_model", "=", "parqcast.run"), + ("res_id", "=", run_id), + ] + ) + ) return [a.name for a in atts] diff --git a/packages/parqcast/utils/__init__.py b/packages/parqcast/utils/__init__.py new file mode 100644 index 0000000..b9b10ee --- /dev/null +++ b/packages/parqcast/utils/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2025 DataStruct s.r.o. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +"""Utility modules for the Parqcast addon.""" diff --git a/packages/parqcast/utils/transports.py b/packages/parqcast/utils/transports.py new file mode 100644 index 0000000..10817e5 --- /dev/null +++ b/packages/parqcast/utils/transports.py @@ -0,0 +1,44 @@ +# Copyright 2025 DataStruct s.r.o. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +"""Transport connection testing utilities.""" + + +def test_http_reachability(url: str, api_key: str | None) -> None: + """Test HTTP reachability. Raises Exception on failure.""" + from urllib import request as urllib_request + + clean_url = url.strip().rstrip("/") + if not clean_url.startswith("http"): + clean_url = f"http://{clean_url}" + + req = urllib_request.Request(f"{clean_url}/health") + if api_key: + req.add_header("Authorization", f"Bearer {api_key}") + + with urllib_request.urlopen(req, timeout=5) as response: + if response.status not in (200, 204): + raise Exception(f"Unexpected status code {response.status}") + + +def test_s3_reachability( + bucket: str, + endpoint: str | None, + access_key: str | None, + secret_key: str | None, + region: str | None, +) -> None: + """Test S3 reachability. Raises Exception on failure.""" + try: + import boto3 # pyright: ignore[reportMissingImports] + except ImportError: + raise RuntimeError("boto3 is not installed. S3 transport requires it.") from None + + client = boto3.client( + "s3", + endpoint_url=endpoint.strip() if endpoint else None, + aws_access_key_id=access_key or None, + aws_secret_access_key=secret_key or None, + region_name=region or None, + ) + client.head_bucket(Bucket=bucket) diff --git a/packages/parqcast/views/parqcast_settings_views.xml b/packages/parqcast/views/parqcast_settings_views.xml index 1cadc21..d6e09fc 100644 --- a/packages/parqcast/views/parqcast_settings_views.xml +++ b/packages/parqcast/views/parqcast_settings_views.xml @@ -9,6 +9,19 @@ + + +
Detected capability bundle:
+ +
+ + +
+ +
+
+
+ @@ -96,6 +109,10 @@ @@ -134,6 +151,10 @@
Leave Endpoint URL empty for real AWS S3.
+
+
+
diff --git a/pyproject.toml b/pyproject.toml index 35a4d59..1abaaaf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,9 @@ authors = [ ] requires-python = "==3.12.3" +[tool.setuptools] +packages = [] + [tool.uv.workspace] members = [ "packages/parqcast-core", diff --git a/stubs/odoo-stubs/api.pyi b/stubs/odoo-stubs/api.pyi index 37956c1..781b62e 100644 --- a/stubs/odoo-stubs/api.pyi +++ b/stubs/odoo-stubs/api.pyi @@ -6,13 +6,11 @@ future addon work (reactive depends, constraints, onchanges). """ from collections.abc import Callable -from typing import Any, TypeVar +from typing import Any -F = TypeVar("F", bound=Callable[..., Any]) - -def model(func: F) -> F: ... -def depends(*fields: str) -> Callable[[F], F]: ... -def depends_context(*keys: str) -> Callable[[F], F]: ... -def constrains(*fields: str) -> Callable[[F], F]: ... -def onchange(*fields: str) -> Callable[[F], F]: ... -def model_create_multi(func: F) -> F: ... +def model[F: Callable[..., Any]](func: F) -> F: ... +def depends[F: Callable[..., Any]](*fields: str) -> Callable[[F], F]: ... +def depends_context[F: Callable[..., Any]](*keys: str) -> Callable[[F], F]: ... +def constrains[F: Callable[..., Any]](*fields: str) -> Callable[[F], F]: ... +def onchange[F: Callable[..., Any]](*fields: str) -> Callable[[F], F]: ... +def model_create_multi[F: Callable[..., Any]](func: F) -> F: ... diff --git a/stubs/odoo-stubs/fields.pyi b/stubs/odoo-stubs/fields.pyi index f594ce0..c6035d7 100644 --- a/stubs/odoo-stubs/fields.pyi +++ b/stubs/odoo-stubs/fields.pyi @@ -12,10 +12,10 @@ If field-arg validation becomes a goal later, replace the variadic signatures with explicit overloads per field type. """ -from datetime import date as _date, datetime as _datetime +from datetime import date as _date +from datetime import datetime as _datetime from typing import Any - class Field: """Descriptor base for all Odoo fields. @@ -33,7 +33,6 @@ class Field: def __set__(self, instance: Any, value: Any) -> None: ... def __delete__(self, instance: Any) -> None: ... - class Char(Field): ... class Text(Field): ... class Html(Field): ... @@ -42,7 +41,6 @@ class Float(Field): ... class Monetary(Field): ... class Boolean(Field): ... - class Date(Field): """Adds Odoo's classmethod helpers ``today`` / ``context_today`` / ``to_date`` / ``to_string``. These are called as ``fields.Date.today()`` @@ -59,7 +57,6 @@ class Date(Field): @classmethod def from_string(cls, value: Any) -> _date | None: ... - class Datetime(Field): """Same classmethod surface as :class:`Date`, plus ``now``.""" @@ -76,7 +73,6 @@ class Datetime(Field): @classmethod def from_string(cls, value: Any) -> _datetime | None: ... - class Selection(Field): ... class Many2one(Field): ... class One2many(Field): ... diff --git a/stubs/odoo-stubs/models.pyi b/stubs/odoo-stubs/models.pyi index db4f987..b9c3af5 100644 --- a/stubs/odoo-stubs/models.pyi +++ b/stubs/odoo-stubs/models.pyi @@ -18,8 +18,7 @@ Pyright cannot catch (acceptable trade-off): """ from collections.abc import Iterator -from typing import Any, ClassVar - +from typing import Any, ClassVar, Self class Environment: """Stub for ``odoo.api.Environment`` exposed via ``BaseModel.env``.""" @@ -27,10 +26,9 @@ class Environment: cr: Any company: Any - def __getitem__(self, model_name: str) -> "BaseModel": ... + def __getitem__(self, model_name: str) -> BaseModel: ... def ref(self, xml_id: str, raise_if_not_found: bool = True) -> Any: ... - class BaseModel: """Common base for Model / AbstractModel / TransientModel. @@ -56,15 +54,14 @@ class BaseModel: # singleton, not a classmethod — overrides in addons (e.g. # ParqcastVersionGate) declare ``def _register_hook(self): ...``. def _register_hook(self) -> None: ... - def init(self) -> None: ... - def browse(self, ids: int | list[int]) -> Any: ... - def search(self, domain: list[Any], **kwargs: Any) -> Any: ... + def browse(self, ids: int | list[int]) -> Self: ... + def search(self, domain: list[Any], **kwargs: Any) -> Self: ... def search_count(self, domain: list[Any]) -> int: ... - def exists(self) -> Any: ... - def ensure_one(self) -> Any: ... - def sudo(self, flag: bool = True) -> Any: ... - def create(self, vals: dict[str, Any] | list[dict[str, Any]]) -> Any: ... + def exists(self) -> Self: ... + def ensure_one(self) -> Self: ... + def sudo(self, flag: bool = True) -> Self: ... + def create(self, vals: dict[str, Any] | list[dict[str, Any]]) -> Self: ... def write(self, vals: dict[str, Any]) -> bool: ... def unlink(self) -> bool: ... @@ -77,16 +74,14 @@ class BaseModel: # Recordsets are iterable, sized, and truthy. Each iteration yields a # singleton record (typed as Any so attribute access is permissive). - def __iter__(self) -> Iterator[Any]: ... + def __iter__(self) -> Iterator[Self]: ... def __len__(self) -> int: ... def __bool__(self) -> bool: ... - def __or__(self, other: "BaseModel") -> Any: ... - def __and__(self, other: "BaseModel") -> Any: ... - def __sub__(self, other: "BaseModel") -> Any: ... - + def __or__(self, other: BaseModel) -> Self: ... + def __and__(self, other: BaseModel) -> Self: ... + def __sub__(self, other: BaseModel) -> Self: ... def __getattr__(self, name: str) -> Any: ... - class Model(BaseModel): ... class AbstractModel(BaseModel): ... class TransientModel(BaseModel): ... diff --git a/stubs/odoo-stubs/tests/common.pyi b/stubs/odoo-stubs/tests/common.pyi index 95cf41e..d214794 100644 --- a/stubs/odoo-stubs/tests/common.pyi +++ b/stubs/odoo-stubs/tests/common.pyi @@ -11,7 +11,6 @@ from typing import Any from odoo.models import Environment - class BaseCase: env: Environment @@ -36,7 +35,6 @@ class BaseCase: def assertLess(self, first: Any, second: Any, msg: str | None = ...) -> None: ... def assertRaises(self, exc: type[BaseException]) -> Any: ... - class TransactionCase(BaseCase): ... class SingleTransactionCase(BaseCase): ... class HttpCase(BaseCase): ... diff --git a/tests/test_live_db.py b/tests/test_live_db.py index 60e4888..ac51a2e 100644 --- a/tests/test_live_db.py +++ b/tests/test_live_db.py @@ -25,7 +25,6 @@ import pytest import parqcast.collectors # noqa: F401 — populates REGISTRY['19'] -from parqcast.core.capabilities import probe_v19 from parqcast.core.registry import REGISTRY from parqcast.core.suite import collect_probe_tables from parqcast.core.tracking import ExportChunk, ExportRun, get_id_range @@ -40,6 +39,7 @@ def _probe_and_build(env): collectors = _build_collectors(env, bundle, caps) return bundle, caps, collectors + TEST_ODOO_VERSION = os.environ.get("PARQCAST_TEST_ODOO_VERSION", "19") if TEST_ODOO_VERSION not in REGISTRY: pytest.skip( @@ -113,7 +113,8 @@ def _clean_tracking(env): def test_probe_capabilities(env): - caps = probe_v19(env.cr) + bundle = REGISTRY[TEST_ODOO_VERSION] + caps = bundle.probe_capabilities(env.cr) print(f"\n Mode: {caps.mode}") print(f" Odoo version: {caps.odoo_version}") print(f" Warehouses: {caps.warehouse_count}") @@ -179,7 +180,7 @@ def test_run_all_compatible_collectors(env): explicitly when running against the live production v19 database to guard against silent row-count regressions. """ - _, caps, collectors = _probe_and_build(env) + _, _caps, collectors = _probe_and_build(env) ordered = _resolve_order(collectors) results = {} @@ -206,7 +207,7 @@ def test_run_all_compatible_collectors(env): def test_keyset_collect(env): """Verify keyset pagination produces correct row counts when split.""" - _, caps, collectors = _probe_and_build(env) + _, _caps, collectors = _probe_and_build(env) collector = next(c for c in collectors if c.name == "stock_picking") full_table = collector.collect() diff --git a/tests/test_manifest.py b/tests/test_manifest.py index 2137007..9454b4d 100644 --- a/tests/test_manifest.py +++ b/tests/test_manifest.py @@ -18,6 +18,7 @@ def test_build_manifest(): files=[{"file": "test.parquet", "rows": 10, "bytes": 100, "checksum": "sha256:abc"}], company="Test Co", company_id=1, + odoo_version="19.0", ) assert m["company"] == "Test Co" assert m["company_id"] == 1 @@ -29,7 +30,7 @@ def test_build_manifest(): def test_write_and_read_manifest(): with tempfile.TemporaryDirectory() as d: - m = build_manifest(files=[], company="X", company_id=42) + m = build_manifest(files=[], company="X", company_id=42, odoo_version="19.0") p = Path(d) / "manifest.json" write_manifest(m, p) loaded = read_manifest(p) @@ -56,6 +57,7 @@ def test_validate_manifest_ok(): files=[{"file": "data.parquet", "rows": 1, "bytes": 100, "checksum": cs}], company="T", company_id=1, + odoo_version="19.0", ) errors = validate_manifest(m, Path(d)) assert errors == [] @@ -67,6 +69,7 @@ def test_validate_manifest_missing_file(): files=[{"file": "missing.parquet", "rows": 1, "bytes": 100, "checksum": "sha256:xxx"}], company="T", company_id=1, + odoo_version="19.0", ) errors = validate_manifest(m, Path(d)) assert len(errors) == 1 @@ -82,6 +85,7 @@ def test_validate_manifest_bad_checksum(): files=[{"file": "data.parquet", "rows": 1, "bytes": 100, "checksum": "sha256:wrong"}], company="T", company_id=1, + odoo_version="19.0", ) errors = validate_manifest(m, Path(d)) assert len(errors) == 1 diff --git a/tests/test_version_gate.py b/tests/test_version_gate.py index 67bdf7e..eb8a5c8 100644 --- a/tests/test_version_gate.py +++ b/tests/test_version_gate.py @@ -69,7 +69,7 @@ def test_registry_bootstrap_has_supported_versions(): def test_bundles_are_populated_after_collector_import(): """After importing parqcast.collectors and parqcast.ingesters, every supported bundle is fully assembled.""" - import parqcast.collectors # noqa: F401 — side-effect: registers v18+v19 bundles + import parqcast.collectors import parqcast.ingesters # noqa: F401 — side-effect: registers v18+v19 ingesters for version in ("18", "19"): @@ -83,7 +83,7 @@ def test_bundles_are_populated_after_collector_import(): def test_v18_and_v19_bundles_have_same_shape(): """Both bundles should register the same number of collectors / suites / ingesters — v18 mirrors v19's surface by design (Snowflake contract).""" - import parqcast.collectors # noqa: F401 + import parqcast.collectors import parqcast.ingesters # noqa: F401 b18 = REGISTRY["18"] @@ -91,9 +91,7 @@ def test_v18_and_v19_bundles_have_same_shape(): assert len(b18.collectors) == len(b19.collectors), ( f"v18 has {len(b18.collectors)} collectors, v19 has {len(b19.collectors)}" ) - assert len(b18.suites) == len(b19.suites), ( - f"v18 has {len(b18.suites)} suites, v19 has {len(b19.suites)}" - ) + assert len(b18.suites) == len(b19.suites), f"v18 has {len(b18.suites)} suites, v19 has {len(b19.suites)}" assert len(b18.ingesters) == len(b19.ingesters), ( f"v18 has {len(b18.ingesters)} ingesters, v19 has {len(b19.ingesters)}" ) @@ -111,7 +109,7 @@ def test_v18_and_v19_collectors_emit_identical_parquet_schemas(): no database is needed. If a future collector redefines its own schema on one major only, this test catches it before runtime. """ - import parqcast.collectors # noqa: F401 + import parqcast.collectors import parqcast.ingesters # noqa: F401 b18 = REGISTRY["18"] @@ -125,12 +123,11 @@ def test_v18_and_v19_collectors_emit_identical_parquet_schemas(): f"v19-only: {schemas_19.keys() - schemas_18.keys()}" ) - mismatches: list[str] = [] - for name in sorted(schemas_18): - if schemas_18[name] != schemas_19[name]: - mismatches.append( - f"{name}: v18 schema != v19 schema\n v18: {schemas_18[name]}\n v19: {schemas_19[name]}" - ) + mismatches = [ + f"{name}: v18 schema != v19 schema\n v18: {schemas_18[name]}\n v19: {schemas_19[name]}" + for name in sorted(schemas_18) + if schemas_18[name] != schemas_19[name] + ] assert not mismatches, "Collector schemas diverge between majors:\n" + "\n".join(mismatches) @@ -139,7 +136,7 @@ def test_v18_and_v19_ingesters_have_same_decision_types(): on it. v18 and v19 must register actors for exactly the same set of decision types. """ - import parqcast.collectors # noqa: F401 + import parqcast.collectors import parqcast.ingesters # noqa: F401 dt_18 = {cls.decision_type for cls in REGISTRY["18"].ingesters}