Skip to content

Move onlyIfAvailable received dependencies into SafeDIParameters (simple)#241

Merged
dfed merged 1 commit into
mainfrom
dfed/only-if-available-simple-v2
Apr 10, 2026
Merged

Move onlyIfAvailable received dependencies into SafeDIParameters (simple)#241
dfed merged 1 commit into
mainfrom
dfed/only-if-available-simple-v2

Conversation

@dfed
Copy link
Copy Markdown
Owner

@dfed dfed commented Apr 10, 2026

Summary

  • @Received(onlyIfAvailable: true) dependencies from child/grandchild scopes no longer leak to the root mock() signature as top-level optional parameters
  • They become plain optional values (Type? = nil) on SafeDIParameters
  • When nil, the dependency is absent; when provided (e.g., .mock()), the value is used directly
  • Fixed a duplicate-promotion bug when both a required @Received and an onlyIfAvailable @Received existed for the same label+type
  • Documents onlyIfAvailable mock behavior in the manual

Alternative: See #242 for a tree-threading version that uses SafeDIMockConfiguration? instead of plain optional values, enabling subtree override through config structs.

Test plan

  • All 742 tests pass
  • SwiftFormat lint passes
  • Code coverage verified
  • Verified against apple repo integration

🤖 Generated with Claude Code

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.98%. Comparing base (6714dea) to head (77f5884).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #241      +/-   ##
==========================================
+ Coverage   99.91%   99.98%   +0.06%     
==========================================
  Files          41       41              
  Lines        5772     5796      +24     
==========================================
+ Hits         5767     5795      +28     
+ Misses          5        1       -4     
Files with missing lines Coverage Δ
...afeDICore/Generators/DependencyTreeGenerator.swift 99.86% <100.00%> (+0.54%) ⬆️
Sources/SafeDICore/Generators/ScopeGenerator.swift 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…arameters

@received(onlyIfAvailable: true) dependencies are now plain optional properties
on SafeDIParameters (defaulting to nil) instead of top-level mock() parameters.
This keeps the mock() signature focused on required dependencies while placing
optional availability-gated values alongside the rest of the SafeDI configuration.

- ScopeGenerator: split onlyIfAvailable entries out of flatReceivedParameters
  into onlyIfAvailableSafeDIParameterEntries; generate them as SafeDIParameters
  stored properties with = nil defaults; bind them as locals before tree bindings
- DependencyTreeGenerator: add promotedLabelAndTypes dedup set in
  createMockRootScopeGenerator to prevent duplicate promotions
- Include onlyIfAvailable labels in flat parameter disambiguation to avoid
  shadowing conflicts between flat params and SafeDIParameters locals
- Documentation: add Manual section on onlyIfAvailable properties in mocks
- Update all affected test expectations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dfed dfed force-pushed the dfed/only-if-available-simple-v2 branch from f5d1b66 to 77f5884 Compare April 10, 2026 19:14
@dfed dfed marked this pull request as ready for review April 10, 2026 19:48
@dfed dfed merged commit 38b4814 into main Apr 10, 2026
17 checks passed
@dfed dfed deleted the dfed/only-if-available-simple-v2 branch April 10, 2026 19:48
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