Skip to content

Reorganize and refactor CGP test suite#246

Merged
soareschen merged 2 commits into
mainfrom
ai-test-reorg
Jul 1, 2026
Merged

Reorganize and refactor CGP test suite#246
soareschen merged 2 commits into
mainfrom
ai-test-reorg

Conversation

@soareschen

Copy link
Copy Markdown
Collaborator

AI Overview

This PR restructures the CGP test suite so that tests are grouped by the feature they exercise rather than by the macro that happens to appear in them. The old layout bucketed tests under construct names like cgp_fn_tests, component_tests, and dispatcher_macro_tests, which mixed unrelated concerns — a single construct such as delegate_components! served basic delegation, open dispatch, and namespaces all at once, so its bucket revealed nothing about what was actually being verified. The new layout replaces those buckets with concept targets like basic_delegation, abstract_types, namespaces, and higher_order_providers, each named for the behavior under test. No test coverage was removed in the process; every runtime test, compile-time wiring check, and provider/context definition from the old suite is preserved.

The structural change

Each concept is now its own Cargo integration test target, which gives it an isolated coherence scope — the same property a separate crate has, and one that matters because CGP tests are dominated by type-level wiring that lives at module scope. A target is two things: an entrypoint file tests/<concept>_tests.rs that carries the module doc comment and a single pub mod, and a module directory tests/<concept>/ whose mod.rs lists one file per unit test. Within a target, every unit test lives in its own self-contained file that defines its own components, providers, and context types, because separate files are the only reliable isolation for module-scope constructs.

The suite also moved out of the library crate entirely. On main, some tests lived under src/tests/ (compiled via #[cfg(test)]) and some namespace fixtures lived under src/namespaces/; both are now integration targets under tests/, and src/lib.rs holds only shared support code (currently none). The macro-test crate was reorganized the same way and gained two new failure-case targets, parser_rejections and invalid_expansion, that are seeded and ready to grow. Two auxiliary packages, cgp-test-crate-a and cgp-test-crate-b, were added to exercise cross-crate behavior under Rust's coherence and orphan rules.

How snapshots were consolidated

A key discipline in the new layout is that each macro is snapshotted only in the concept target that owns its feature, and invoked plainly everywhere else. A macro snapshot pins the pretty-printed generated code as a golden assertion, so a redundant snapshot in a non-owning file adds nothing but a golden string that breaks whenever unrelated codegen changes. The reorg therefore stripped the incidental snapshot_*! wrappers that the old by-construct files scattered across the suite, leaving one canonical snapshot (plus its genuinely distinct variants) per macro in its owning target. This removes only golden-string assertions, never compile or runtime coverage, because the plain macro still expands and runs.

Impacts

The changes ripple through the test suite, its supporting crates, and its documentation. The following list captures the concrete effects a reviewer should expect to see in the diff:

  • Test organization is now by concept. Seventeen concept targets replace the old construct buckets, each with an entrypoint, a module directory, and one file per unit test.
  • Tests moved from src/ to tests/. The library-based tests and namespace fixtures became integration targets; src/lib.rs is now effectively empty.
  • Snapshot coverage was deduplicated. Redundant macro snapshots were converted to plain macro invocations, with each macro's canonical expansion living only in its owning target.
  • The macro-test crate was restructured and extended. It follows the same entrypoint-plus-directory shape and adds the parser_rejections and invalid_expansion failure-case targets as a foundation for future corner cases.
  • Cross-crate coverage was added. The new cgp-test-crate-a/cgp-test-crate-b packages verify that a downstream crate can wire a foreign component, define a local provider for a foreign provider trait, and participate in an upstream namespace.
  • Two missing #[cgp_impl] snapshots were restored. The #[cgp_impl] + #[implicit] expansion (in implicit_arguments) and the #[cgp_impl] + #[use_provider] expansion (in higher_order_providers) are pinned again, matching the ownership table and recovering golden coverage that had existed before the reorg.
  • Every test still passes. The full workspace runs green (295 tests), formatting is clean, and the suite compiles — which for CGP's compile-time wiring checks is itself the passing condition.

These changes are structural and organizational: they change where tests live and how their generated code is pinned, not what behavior the suite verifies. A reviewer can therefore focus on whether the concept groupings are sensible and whether the snapshot ownership is placed correctly, confident that the behavioral coverage is unchanged from main.

@soareschen soareschen added the AI label Jul 1, 2026
@soareschen soareschen merged commit 09a9f6e into main Jul 1, 2026
5 checks passed
@soareschen soareschen deleted the ai-test-reorg branch July 1, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant