Skip to content

Introduce testable abstraction layer for rstest companion-module detection in src/hir/mod.rs #228

@coderabbitai

Description

@coderabbitai

Summary

Direct unit tests of module_qualifies_as_rstest_companion_module, module_has_inner_harness_descriptor_pairs, and collect_rstest_companion_test_functions in src/hir/mod.rs are architecturally blocked: all three functions require a live rustc_lint::LateContext to operate. There is no stable, lightweight seam that can construct that context in isolation, so the qualification logic cannot currently be exercised by ordinary unit tests.

Problem

Without a testable seam:

  • Edge-case behaviour (empty companions, descriptor-only modules, false-positive sibling modules, deeply nested module groups) can only be validated through full UI-level compilation fixtures, which are slow and opaque.
  • Regressions in the qualification predicate may go undetected until a UI test fails, with no easy way to bisect the failure to a specific code path.

Proposed resolution

Introduce a trait or a thin, data-only projection type that abstracts over the parts of LateContext / hir::Item used by the three functions. This would allow:

  1. Unit tests to construct lightweight fakes representing various module shapes (empty, descriptor-only, fn+const pair, unrelated const, etc.) and assert the correct qualification decision.
  2. The production path to continue using the real LateContext-backed implementation with zero overhead.

Context

Identified during review of PR #221, where the architectural constraint was first documented in src/hir/tests.rs. The companion-module detection work is tracked by issue #225.

Raised by @leynos.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions