Repository navigation
feat(testsuite): rebuild the testsuite on directory-owned databases - #33
Merged
Merged
Conversation
…ixtures - every topic's fixtures/tables.py becomes fixtures/definitions.py: definition classes constructed with a dialect only, holding create/drop expressions - each test directory owns one database (session) and drops+creates its tables before every test (function, autouse) - model fixtures use ActiveRecord.configure; the environment wrapper and the _bind_* helpers are gone from the migrated directories - cli builds its models through configure; plugin groups by directory + scenario - tests: remove the orphaned test_expression_utils suite (its module was dropped in e05edb0) BREAKING: fixtures.tables and the prepare/teardown directory contract are replaced by definition classes and the database/database_config/schema fixtures.
The comparable-text concept is 'a bounded string with equality and order': an unbounded text type is not it (Oracle CLOB and Firebird BLOB have no value comparison), and the suite must not fall back to one silently. 255 bytes keeps ten such columns inside MySQL's 65535-byte row limit; tables with ten long-text columns are not a design target, and long-text families belong in their own compact fixtures. The dialect answers whether it renders varchar (require_data_type) and a dialect that does not is skipped with a reason.
A new package carries the suite's pytest behaviour, and `plugin.py` calls it; the old capability layer is left untouched so this lands without breaking anything. What the package does: - `switches`: one evaluator for both channels (a definition's declaration and a case's marker). A switch the dialect never implemented is a dialect gap, not an "unsupported" answer, so it fails the item with a one-line message rather than skipping or dropping a traceback; a probe that raises or answers with a non-boolean is likewise a fault. Only a genuine "no" skips, and both polarities are supported (must-be-on and must-be-off). - `declarations`: a directory declares itself (`DECLARATION = DirectoryDeclaration(parallel=True, purpose=..., passes_means=..., fails_means=..., switches=...)`). A declared directory is pinned to one worker per scenario; an undeclared one is left alone, which is what a directory of pure expression assertions wants. - `hooks`: collection attaches the text a test carries (case > class > file > directory) to the item, so it reaches JUnit XML; call evaluates a case's markers against the dialect its environment opened; report prints what a failure means, since `-v` shows no docstrings. Markers are read with `iter_markers`, never `get_closest_marker`: the latter returns only the nearest declaration and would silently drop a class or module one. Verified locally: both polarities skip with a reason naming the switch and the case; a missing switch fails by name; metadata lands in JUnit XML including for skipped cases; PG window-function and basic/ddl suites still pass.
… is asked Requiring a dialect for every marked item failed three tests that legitimately have none: the unit tests that assert what the convenience decorators produce. A marker on such a test is inert, which is what it always was, and now that is said explicitly instead of failing. Two refinements: - a database-backed item that surfaces no dialect still fails, because there the dialect exists and only its discovery broke; - dialect discovery beyond the suite's own fixture names takes any argument that carries a `.dialect`, so a directory exposing its dialect under its own name is found without a hard-coded list that would rot. Verified: the two previously failing tests (`test_requires_window_functions` and `TestGeoDocumentScenario::test_full_scenario`) pass, and the whole `feature/contracts` directory passes.
A declaration names a capability, so the switch it names has to answer without being given anything. A parameterised predicate such as `supports_spatial_type(type_name)` answers about one argument, not about the dialect; calling it with no argument raised, and the old layer swallowed that into a skip. The evaluator now reads the probe's signature and reports the required parameters by name, so the mistake is named at the declaration instead of silently turning into a skip.
…the capability module The DDL group renders statements rather than creating tables, so it used to borrow a dialect from a probe connection built on the fly: the old `dialect_for(scenario)` opened a throw-away database, and on failure returned an un-adapted dialect, which made every version-gated probe answer "no" and skip silently. It now owns one database per directory like every other group and takes the dialect from that adapted backend, which is the only dialect that can answer a version-gated question. With that, `core/capabilities.py` has no users left, and it is deleted. Its design is the negative example the plan records: a single marker that cannot express a conjunction, `get_closest_marker` silently dropping class and module declarations, switches that could not be declared as "must be off", a probe that raised being read as "unsupported", and a probe database left on the server. The directory also declares itself in the new vocabulary: parallel, with the purpose and the meaning of a pass and a failure stated where a report can read them.
Two names implied things the mechanism does not do: * `switch` suggested a feature a user could toggle. What a declaration states is a fact the dialect must confirm, so the module is `requirements`, the error is `MissingRequirementError`, a `Requirement` carries a dialect `method` and the answer it must give, and the declaration's field is `requires=`; * `DirectoryDeclaration` assumed a directory. A module or a file may declare itself later, so the class is `Declaration` -- named for the act, not the container. Also removed here: `requires_switch` and `absent_switch`. They were invented during the first skeleton and never asked for; the case-level channel is the existing `requires_protocol` marker, and it is now the only one the plugin evaluates. Neither name was used by any test.
A composite primary key is a different declaration set from the single-key tables: on an engine that cannot express one, creating the table fails during setup and would take the single-key CRUD contract down with it. ``basic/crud_composite_pk`` now owns the composite set (``OrderItem``, its single-key ``Order`` counterpart and the column-mapped variant), its database and its fixture group. ``basic/crud`` keeps the single-key ``users`` table only, and the composite fixtures leave the shared ``basic`` conftest so they are configured only where they are used.
… off core ``fixture_types`` is the L1 definition layer's type vocabulary -- the varchar/text/temporal helpers and the drop-if-exists probe -- and is imported by every fixture definition module plus several backends' test helpers. It is not plugin machinery, so it lives at ``testsuite/fixture_types.py`` now and those importers follow it. ``database_name`` moves to ``pytest_plugin/declarations.py``, beside the scope declaration that the migrated directories use. ``core/declarations`` keeps the legacy contract probe that ``plugin.py`` still consults and imports the derivation from its new home.
…xture it provided The directory-owned-database layout left ``testsuite/core`` holding three pieces that nothing needs any more: the ``Environment`` object, the ``prepare``/``teardown``/``ensure_database`` directory contracts the plugin ran around each test, and the ``contract_for_path`` probe that found them. No conftest in any backend declares those hooks, no test asks for the ``environment`` fixture, and every directory builds its own tables in its own ``conftest.py`` -- so the plugin now does exactly two things: pin a directory's database-backed tests per scenario, and evaluate the ``requires_*`` markers. ``pytest_plugin/hooks`` looks for the dialect through the fixtures that still exist (``ddl_dialect`` / ``database``); the fixture lists no longer mention a fixture that was never defined in the migrated directories. ``scripts/gen_bridges.py`` stops importing ``core.bridges``, a module that never existed on this branch (the script could not run at all). The bridge plan is computed from the feature tree it points at, which is the only authority there is. Verified: all ten projects still collect their whole suite (core 11728, mysql 10848, postgres 9231, mariadb 6169, oracle 5904, sqlserver 5708, clickhouse 5353, firebird 5294, snowflake 3519, bigquery 2304), and core runs its ``feature/basic`` set on SQLite with 883 passed.
The fixture design is rewritten around one rule: a table is declared once, by a model's annotations, and the DDL is derived from it. Hand-written Definition classes and the fixture_types vocabulary go away. Records what the redesign has to answer, in the fixture README: * bare means literally no annotation -- the acceptance fixture for the product promise that writing a class is enough to get a table. It is blocked on core's storage-type inference, which does not exist yet. * two rules already written down in core are reused rather than reinvented: suggested_column_types() answers all 18 common types or fails on a missing key, and every type concept is either rendered or substituted. The DDL side needs the same answer-every-key discipline. * length is missing from exactly five content types, and millisecond is the only timestamp precision every backend can honour; microseconds become a declared capability instead of a shared constant. * Mapped models fold into each group's annotated variant instead of being their own groups, and the complex group's bare variant is column-limited by the dialects that answer None for a value family. The directory declaration is now evaluated where the dialect is known: hooks.evaluate reads the directory's requirements alongside the case markers, and a switch no dialect implements still fails rather than skips.
Core cannot yet say what a declaration needs, so the requirement is stated next to the model that creates it: per table, the DDL/DML operations the fixture performs and the dialect switches each one requires on or off. A switch name resolves through a fixed order because the dialect answers capability questions through two channels that do not overlap -- a zero-argument boolean method, and a key of supports_data_types(). Neither channel knowing the name is a MissingRequirementError naming the dialect and the switch: a dialect that never answered is not a dialect that said no. The four operations only execute. Evaluation and skipping belong to the caller, which has already asked the registry; an assertion inside an operation would make a capability question look like a defect. Tests cover both channels, the gap case, the polarity of requires_off, and the per-column form the complex group's bare variant needs.
…ontracts The dialect method that names a stand-in for a concept it cannot render is now substitute_data_types, so the two contract tests read it under that name. The suggestion name is being freed for the per-backend table that maps the framework's modelled Python types to a data type.
COMMON_TYPES becomes an alias of FRAMEWORK_PYTHON_TYPES instead of a second hard-coded list. The required key set is stated once, beside the lookup walk whose order depends on it, so the contract and the framework cannot drift apart. The list now covers the six complex value families as well.
Records the fixture design the framework now supports: a bare model is expected to build its table from the dialect's suggestions, the complex families get their own fixture group, and the timestamp precision rule (millisecond default) is stated where the fixtures live.
The table behind a bare field's declaration has a promise that can be checked without a server: every framework-modelled type is answered with a renderable declaration, nothing answers None, the backend's own value classes are disjoint from that list and render too, and each call returns a fresh dict. The third obligation for an extra entry -- that its key has an adapter -- is left to each backend's own suite, where the adapter registry is reachable.
…e common one
Four contracts on suggested_extra_column_types(): every answer is a ColumnBase
subclass, the extras keys are disjoint from the common twenty-four, every
answer builds and renders, and the returned table is a copy.
The extras table is opt-in -- {} is the whole 'nothing of my own' answer -- so
unlike the common table it has no None state; the reason is written where the
test is.
…work F12's 18-key table and its three None answers are gone: all backends now answer 24 keys, with Firebird's five documented refusals the only None left. Mark stage 0 and stage 2a complete -- suggested_data_types() now gives bare fields a declaration, so 'bare cannot build a table' is no longer the premise. Correct the dict/timedelta skip notes and the Vector/Range/BitString bare boundary.
Stage 1a of the basic fixtures redesign. annotations.py holds the shared
identity declaration; user_models.py and connection_models.py own the fixture
registrations; crud/nopk/readonly/connection conftests now build the tables
through fixtures/operations.py instead of UserDefinition/TestUserDefinition.
The model bodies still live in models.py for now; moving them into the group
files is a later sub-step. The public connection.fixtures names are kept as
re-exports. Core's basic/{crud,nopk,readonly,connection} bridges all pass.
Stage 1b: composite_pk_models.py registers orders/order_items/store_inventory as model-derived fixtures, and the group's conftest builds them through fixtures/operations.py instead of OrderDefinition/OrderItemDefinition. The derivation already emits the composite PRIMARY KEY, so no declaration changes were needed. Core's basic/crud_composite_pk bridge passes.
Stage 1c: user_models.py now exports BASIC_TABLES/BASIC_FIXTURES for the three tables the CLI feature borrows, cli/conftest.py derives them through fixtures/operations.py, and BASIC_DEFINITIONS is gone from models.py. README records stages 0/1/2a as complete. Core's cli bridge passes alongside the five basic groups migrated in the previous commits.
Stage 1 leaves feature/query/conftest.py importing OrderItem/AsyncOrderItem from fixtures.models untouched, but the redesign intends a complete split of the basic fixtures. Record that query must later switch to a public entry point (composite_pk_models) or its own fixtures, and that models.py definitions can only be deleted once no basic group uses them.
Stage 1 (continued): composite_pk_models.py now defines OrderItem, AsyncOrderItem, StoreInventory, Order and their mapped variants instead of importing them from models.py. models.py re-exports them so existing importers (including feature/query) keep working. Delete OrderDefinition and OrderItemDefinition, which had no remaining users. Core's basic/*, cli and typed_column bridges all pass.
Every basic group now derives its tables from model classes through fixtures/operations.py; no conftest builds a table from a hand-written Definition. Model bodies moved out of models.py into their group modules: user_models, field_models, type_rows_models, type_adapter_models, validation_models, composite_pk_models, connection_models. models.py is now a pure re-export aggregate, and the py310/311/312 files are thin version probes that re-export the baseline rather than 39 hand-copied classes. Projection models that insert column subsets get explicit UseConstraint(ColumnNullableConstraint) via SQL_NULLABLE, and fields whose storage the old Definition spelled out (Literal, Union, adapter-to-text) carry explicit UseSqlType. BASIC_DEFINITIONS is gone; the CLI uses BASIC_FIXTURES. Core's full feature/basic tree and feature/cli pass. Fixture model modules are 84-100% covered; operations.py's remainder is defensive/error branches and seed/reload paths used by only some groups.
The model-as-definition refactor replaced hand-written Definitions that carried backend-specific detail with bare annotations. On non-SQLite servers that lost: explicit integer widths (TinyInt/BigInt), Decimal precision, native-array element types, VarChar(64) UUID keys, and - critically - identity markers on DDL sources, so MySQL/MariaDB built no AUTO_INCREMENT primary key. Restore them in the fixtures: width/precision UseSqlType on TypeCase and the validation models, a VarChar(64) UUID id, explicit identity markers on every DDL-source id, and a native-array-or-text dual candidate for array_val that uses the derivation's existing fallback (ARRAY on PostgreSQL, JSON/text carrier elsewhere). Verified green: SQLite basic (1157), PostgreSQL crud, MySQL crud+validation, MariaDB crud.
plugin.py inferred serial intent from the presence of a database fixture and pinned every database-backing directory to one worker, so the documented 'no declaration = unlimited parallel' rule never held -- the declaration was dead code. Make it live: collection_modifyitems in hooks.py now solely decides grouping, and only when a directory declares Declaration(parallel=True). The 11 basic directories that own a database and share tables each declare parallel=True with a directory-specific purpose/passes/fails; ddl is DB-free and stays undeclared (free to parallelise). Add a unit test locking the rule: declared-parallel pins a worker, absent/False declaration does not. Verified: basic suite green; crud+nopk under -n 2 --dist=loadgroup passes with no shared-table collision.
The developer picks the smallest parallel unit by putting DECLARATION in that directory's conftest; deeper directories inherit it. Add real (unmocked) tests for declaration_for: declaration at the test dir, inheritance from a parent, nearest-declaration-wins, and no-declaration-returns-None.
Backends must not import this group until the DDLSource declaration and derivation contract stabilises.
Use Optional[int] plus pk_auto_generated() as the mechanism-neutral declaration; update the fixtures README (P2, F11, variant tables) to keep identity out of the bare/annotated axis.
Skip JSON-path probes where supports_json_path is false; make the complex-table schema non-autouse and skip dialects that cannot declare it; give composite-PK string members and derived-field ids portable declarations; tolerate driver timezone qualification on datetime round-trips.
Declare VARCHAR PK members and integer auto-ids so MySQL/MariaDB build tables; non-autouse schema in types/types_complex; skip unsupported operations; tolerate driver datetime/decimal differences.
…ibutes to column()
… relation under query, events under basic
…e/setop/integration
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Description
Rebuilds the standardized test suite around directory-owned databases, declaration-driven fixtures, and a pytest plugin mechanism, so that each contract topic owns the database objects it needs instead of sharing a global
coreenvironment fixture. This is the testsuite side of the coordinatedfeature/activerecord-ddlwork across therhosocial-activerecordecosystem.What changed:
coredirectory and its environment fixture are removed. Added the pytest plugin mechanism (P1a) and declaration-driven parallel-test grouping.querysplit intocte,setop, andquery_integration;relationmoved underquery;eventsmoved underbasic.basiccontracts matured;ddlandbenchmark/realworldexplicitly marked immature.migrateapply/rollback/dry-run contracts (sync/async), set-operation and DQL/set_cteCLI contracts, and "can execute" EXPLAIN contracts.NeutralTypesFixtureDDL construction, case-insensitive identifier/assertion handling, Python 3.8 compatibility (Annotated,ClassVar), sync/async parity of CLI contracts.Dependencies: core
rhosocial-activerecord>=1.0.0,<2.0.0. Coordinated changes are required inpython-activerecordand each backend repository (their 1-to-1 mirror bridge trees undertests/); see Related Repositories below.Adds # (issue): N/A
Type of change
feat: A new featuredocs: Documentation only changes (if related to the new feature)perf: A code change that improves performance (if part of the feature)test: Adding missing tests or correcting existing tests (for the new feature)chore: Changes to the build process or auxiliary tools/libraries (test-suite tooling)ci: Changes to our CI configuration files and scripts (if related to the new feature)build: Changes that affect the build system or external dependencies (if related to the new feature)revert: Reverts a previous commit(Also includes
fix,refactor, anddocscommits as part of the feature.)Breaking Change
Impact and migration path:
coredirectory and the environment fixture it provided are deleted. Consumers must move to directory-owned databases and their per-directory L2 fixtures.feat(fixtures)!: L1 definition classes and per-directory L2 backend fixtureschanges the fixture API. Backend bridge trees must adopt the new L1 definitions / L2 fixtures.query→cte/setop/query_integration,relation→ underquery,events→ underbasic. Backends that mirror the testsuite tree must update their bridge-file import paths accordingly.Existing backend implementations will be updated in the coordinated PRs on each backend repository.
Related Repositories/Packages
This is one PR in the coordinated
feature/activerecord-ddlseries. All changes are based on each repository's latestrelease/*branch:rhosocial/python-activerecord(core) — DDL / migration APIs the contracts targetrhosocial/python-activerecord-mysqlrhosocial/python-activerecord-postgresrhosocial/python-activerecord-mariadbrhosocial/python-activerecord-sqlserverrhosocial/python-activerecord-oraclerhosocial/python-activerecord-snowflakerhosocial/python-activerecord-clickhouserhosocial/python-activerecord-bigqueryrhosocial/python-activerecord-firebirdEach backend needs matching bridge-tree updates to consume the new layout and fixture model. This PR is being opened first.
Testing
Test Plan:
Local full-suite execution skipped per
AGENTS.md(full tests run in CI only). CI will run the suite against the supported backends. Note: the four developer checkers mentioned inCLAUDE.md(tools/check_*.py) are not present in this branch, so there was nothing to run locally.Checklist
README.md, etc.).changelog.d/<issue_number>.<type>.md). — to be added after the PR number is assigned.Additional Notes
Part of the cross-repository
feature/activerecord-ddlmerge series. No local branch merges are performed; all merges happen on GitHub after CI passes. Changelog fragment, CI verification, and final merge are tracked in the post-PR phases ofrhosocial-feature-fix-merge.