Skip to content

Sources: route mock aliases through production topological sort#261

Merged
dfed merged 5 commits intomainfrom
claude/mock-alias-topo-sort-refactor-v2
Apr 19, 2026
Merged

Sources: route mock aliases through production topological sort#261
dfed merged 5 commits intomainfrom
claude/mock-alias-topo-sort-refactor-v2

Conversation

@dfed
Copy link
Copy Markdown
Owner

@dfed dfed commented Apr 19, 2026

Summary

  • Unify mock and production alias emission by treating aliases as first-class MockTreeItem.alias nodes in collectMockParameterTree, so they ride the same orderedPropertiesToGenerate topological sort production uses.
  • Replace the surgical preChild / postChildByFulfilling partition in emitReceiverBindings with a single linear walk over [MockTreeItem] items.
  • Property-only consumers (SafeDIOverrides, configuration types, uncovered-dependency collection, disambiguation) pull property nodes via a new propertyNodes helper and skip aliases.
  • Alias items emit one let <alias>: <Type> = <fulfilling> line resolved through flatParameterDisambiguationMap.
  • Alias-only trees no longer emit an empty SafeDIOverrides struct or safeDIOverrides parameter (hasOverridableTree distinguishes from hasTree).

Why

Production's topo sort already orders aliases correctly relative to their fulfilling children and to sibling nested-function captures. Mock was filtering to .property(...) scopes and re-materializing aliases via a preChild/postChild partition that couldn't handle transitive captures from sibling nested funcs. The surgical interleave shipped first; this PR is the deferred architectural unification.

Test plan

  • swift build --traits sourceBuild
  • swift test --traits sourceBuild (all 831 tests pass)
  • ./CLI/lint.sh

🤖 Generated with Claude Code

Unifies mock and production alias emission by treating aliases as
first-class tree nodes (`MockTreeItem.alias`) in `collectMockParameterTree`,
so they ride the same `orderedPropertiesToGenerate` topological sort that
production uses. Replaces the prior surgical interleave (preChild/postChild
partition in `emitReceiverBindings`) with a single linear walk over items.

Property-only consumers (`SafeDIOverrides` generation, configuration type
collection, uncovered-dependency collection, disambiguation) pull property
nodes via the new `propertyNodes` helper and skip aliases. Alias items emit
a single `let <alias>: <Type> = <fulfilling>` line resolved through
`flatParameterDisambiguationMap`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@dfed dfed force-pushed the claude/mock-alias-topo-sort-refactor-v2 branch from f6b7da9 to 2e361c2 Compare April 19, 2026 01:36
@dfed dfed changed the base branch from claude/compile-verify-codegen-tests to main April 19, 2026 01:36
@dfed dfed marked this pull request as ready for review April 19, 2026 01:37
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2e361c24f0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Sources/SafeDICore/Generators/ScopeGenerator.swift
dfed and others added 2 commits April 18, 2026 20:11
Matches the existing createdProperties pattern. Avoids redundant
recomputation during tree validation, where requiredReceivedProperties
is hammered by the recursive cycle walk and scopes reached from
multiple paths paid the cost each visit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2026

Codecov Report

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

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #261   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           41        41           
  Lines         6369      6370    +1     
=========================================
+ Hits          6369      6370    +1     
Files with missing lines Coverage Δ
Sources/SafeDICore/Generators/ScopeGenerator.swift 100.00% <100.00%> (ø)
Sources/SafeDICore/Models/Scope.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 and others added 2 commits April 18, 2026 21:18
…ree walk

The switch over child scope data had three cases: `.root` (never a child —
only the top-level scope is ever rooted), `.alias`, and `.property`. The
`.root` case's `continue` body was unreachable, and the `.property` case
included a defensive `guard let childProperty = childGenerator.property`
whose else branch was also unreachable (the `.property` enum case always
carries a non-nil property). Restructuring as an `if case` chain lets the
loop silently skip the unreachable `.root` without a dedicated line that
coverage tools see as dead.

Also inlines `hasAliasChildren` into `requiresFunctionWrapper` — it was
only ever called when `needsConfigurationStruct` is false, which implies
`propertyChildren.isEmpty`, so checking `!children.isEmpty` is equivalent
and drops the dead else branch of its pattern-match closure. Merges the
`constructionArguments` extraction into the same `if let` block that
collects default parameters, removing an unreachable `?? []` fallback.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@dfed dfed merged commit 6d51205 into main Apr 19, 2026
17 checks passed
@dfed dfed deleted the claude/mock-alias-topo-sort-refactor-v2 branch April 19, 2026 05:00
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