Skip to content

Validate forwarded-property constraint in mock scope mapping#224

Merged
dfed merged 1 commit intomainfrom
dfed/mock-forwarded-property-validation
Apr 7, 2026
Merged

Validate forwarded-property constraint in mock scope mapping#224
dfed merged 1 commit intomainfrom
dfed/mock-forwarded-property-validation

Conversation

@dfed
Copy link
Copy Markdown
Owner

@dfed dfed commented Apr 7, 2026

Summary

  • Non-root types with generateMock: true that constant-instantiate a child with @Forwarded properties now produce a clear error instead of silently generating uncompilable mock code
  • Extracted validateNoForwardedProperties(for:instantiable:parent:) as a shared helper used by both prod scope population and mock generation — no duplicated validation logic

What changed

  • Extracted the forwarded-property guard from the prod createTypeDescriptionToScopeMapping loop into validateNoForwardedProperties(for:instantiable:parent:)
  • Mock generation calls the same helper per-type inside the generateMockCode loop, after module filtering
  • New test: mock_throwsError_whenNonRootInstantiatedPropertyHasForwardedArgument
  • Added CLAUDE.md guidance to share logic between prod and mock paths

Test plan

  • New test fails before fix, passes after
  • All 769 tests pass
  • SwiftFormat lint clean

🤖 Generated with Claude Code

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4a4249e) to head (839fd27).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #224   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           40        40           
  Lines         6128      6143   +15     
=========================================
+ Hits          6128      6143   +15     
Files with missing lines Coverage Δ
...afeDICore/Generators/DependencyTreeGenerator.swift 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dfed dfed force-pushed the dfed/mock-forwarded-property-validation branch 2 times, most recently from 3a40278 to c33e19b Compare April 7, 2026 04:38
Mock generation skipped the instantiableHasForwardedProperty check
for non-root types with generateMock: true. A constant @Instantiated
child with @forwarded properties would silently produce uncompilable
mock code instead of a clear error.

Extracted validateNoForwardedProperties(for:instantiable:parent:) as
a shared helper called by both the production scope population loop
and the mock generation loop. The mock path runs validation per-type
after module filtering, so only types this module generates mocks for
are checked.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dfed dfed force-pushed the dfed/mock-forwarded-property-validation branch from c33e19b to 839fd27 Compare April 7, 2026 04:43
@dfed dfed marked this pull request as ready for review April 7, 2026 04:45
@dfed dfed self-assigned this Apr 7, 2026
@dfed dfed merged commit 4c11413 into main Apr 7, 2026
19 checks passed
@dfed dfed deleted the dfed/mock-forwarded-property-validation branch April 7, 2026 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant