test: Extract shared conformance-test scaffolding into a common module #78
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
rosa/vernier#78
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found during the two-axis reviews of PRs #76 and #77.
Location:
crates/infra/tests/Severity: Code health — test-infrastructure duplication
Problem
The repository-conformance test suites duplicate their scaffolding verbatim.
post_repository_conformance.rsestablished the pattern (generic behaviour functions + aboth_adapters!macro that instantiates each behaviour against Postgres via#[sqlx::test]and the in-memoryMemoryAppRepovia#[tokio::test], pluscreate_user_request()/seed_user()helpers). PR #76 (confirmation_repository_conformance.rs) and PR #77 (authorization_code_repository_conformance.rs) each copied the macro and user-seeding helpers wholesale, because integration-test binaries can't share code without a common module. Once both merge there are three verbatim copies.Both standards reviews flagged the duplication and set the extraction threshold at the third occurrence — which #77 crosses.
Suggested fix
Extract the shared scaffolding into
crates/infra/tests/common/mod.rs(the standard Rust pattern for sharing across integration-test binaries): theboth_adapters!macro and the user-seeding helpers, parameterised as the confirmation suite already needs (multiple users). Update the three conformance suites to use it; behaviour functions stay in their own files.This should land after PRs #76 and #77 merge, since it touches the same new files.
Agent Brief
Category: enhancement
Summary: Extract the duplicated conformance-test scaffolding into a module shared by the infra crate's integration-test binaries
Current behavior:
The three repository-conformance suites in the infra crate's integration tests (post, password-reset confirmation, authorization code) each carry their own copy of the same scaffolding, because integration-test binaries cannot share code without a common module:
both_adapters!macro — byte-identical in all three suites — that takes a generic behaviour function overR: AppRepositoryand emits two wrapper tests: one running it againstPostgresAppRepositoryvia#[sqlx::test]with the repo's migrations, one againstMemoryAppRepovia#[tokio::test].create_user_request()helper that builds a validCreateUserRequest(fixed argon2 hash, generated confirmation id/verifier, day-long expiry). The post and authorization-code suites hardcode the user name and email; the confirmation suite's variant takes them as parameters because its behaviours need multiple distinct users.seed_user()helper that creates the user and returns itsUserId(present in the post and authorization-code suites; the confirmation suite inlines the equivalent because it also needs the confirmation id back).Desired behavior:
The shared scaffolding lives once, in a common module using the standard Rust pattern for sharing code across integration-test binaries (a
commonmodule under the crate'stests/directory), and all three conformance suites use it. Behaviour functions stay in their own suite files — only the scaffolding moves.Key interfaces:
both_adapters!— moves unchanged; each suite must be able to invoke it after the extraction.create_user_request(name, email)— standardise on the parameterised form the confirmation suite already needs; suites that don't care about the identity can pass fixed values or use a zero-argument convenience wrapper.seed_user()— must support seeding multiple distinct users, and the confirmation suite's need to know the seeded user's email-confirmation id should be satisfiable (whether by returning richer data or by suites composingcreate_user_requestdirectly is an implementation choice).Acceptance criteria:
both_adapters!macro and the user-seeding helpers remains, in a module shared across the infra integration-test binaries.pg_*/mem_*pairs) is identical before and after the refactor, and all of them pass.cimise task passes with no new warnings (note: each integration-test binary compiles the common module independently, so helpers unused by one binary can trigger dead-code warnings — the extraction must not introduce any).Out of scope: