Skip to content

refactor(cli): inject PostInstallPipelineUseCase and GitignoreUseCase - #523

Merged
blafourcade merged 1 commit into
nextfrom
refactor/e6-us07-inject-shared-use-cases
Jul 27, 2026
Merged

blafourcade merged 1 commit into
nextfrom
refactor/e6-us07-inject-shared-use-cases

Conversation

@blafourcade

Copy link
Copy Markdown
Contributor

🎯 What & why

PostInstallPipelineUseCase and GitignoreUseCase were instantiated ad hoc at 6 sites, escaping the dependency graph entirely — no test could substitute either at the command level, unlike every other shared use-case.

🛠️ How it works

deps.ts now builds each once and injects them: GitignoreUseCase → PostInstallPipelineUseCase → the 3 install use-cases, and GitignoreUseCase → CleanUseCase. Both verified stateless (only readonly constructor deps) before being shared as singletons — same check applied in #508.

Dead constructor params removed as a consequence, each checked per file rather than assumed:

  • PostInstallPipelineUseCase drops fs — its only use was the removed new GitignoreUseCase(this.fs)
  • InstallIdeConfigUseCase / InstallRuntimeConfigUseCase drop manifestRepo — their only use was the removed new PostInstallPipelineUseCase(...)
  • InstallIdeToolUseCase keeps manifestRepo (still used once); CleanUseCase keeps fs (used 13×)

I initially got the manifestRepo part wrong — the plan asserted it stayed in use across all three install use-cases because I'd counted this.fs but not this.manifestRepo. Biome's noUnusedPrivateClassMembers caught it at commit time; tsc then enumerated all 8 affected call sites. Recorded in the plan's Decisions rather than quietly fixed.

🧪 How to verify

pnpm --filter cli test — 2088/2088 unmodified, tsc clean. Pure DI wiring, zero behavior change: .gitignore still gains .aidd/cache/ on install, aidd clean still removes it.

grep -rn "new PostInstallPipelineUseCase\|new GitignoreUseCase" src/
# -> only the two construction sites in deps.ts, plus the documented init-use-case exception

⚠️ Heads-up

5 of the 6 sites converted, not 6. init-use-case.ts is deliberately left alone: InitUseCase is not in the dependency graph at all — no deps.ts entry, and it is itself ad-hoc constructed by setup-use-case.ts plus 13 test call sites. Injecting GitignoreUseCase there would force every one of those callers to write new GitignoreUseCase(deps.fs) itself — more ad-hoc instantiation, not less — while still not achieving the ticket's goal, since InitUseCase keeps escaping the graph one level up. Wiring InitUseCase into deps.ts is a distinct concern; recorded in the plan rather than half-done here.

Planned in the (now-archived) standalone aidd-cli repo before the framework migration (#462), cartography item B11.

Both were instantiated ad hoc at 6 sites, escaping the dependency graph
entirely — no test could substitute either at the command level, unlike
every other shared use-case.

deps.ts now builds each once and injects them:
GitignoreUseCase -> PostInstallPipelineUseCase -> the 3 install use-cases,
and GitignoreUseCase -> CleanUseCase. Both verified stateless (only
readonly constructor deps) before being shared as singletons, same check
applied in #508.

Dead constructor params removed as a consequence, each checked per file
rather than assumed: PostInstallPipelineUseCase drops `fs` (its only use
was the removed `new GitignoreUseCase`), and InstallIdeConfigUseCase /
InstallRuntimeConfigUseCase drop `manifestRepo` (their only use was the
removed `new PostInstallPipelineUseCase`). InstallIdeToolUseCase still
uses manifestRepo once, so it keeps it; clean-use-case uses `fs` 13 times,
so it keeps that.

Scope: 5 of the 6 sites. init-use-case.ts is deliberately left alone —
InitUseCase is not in the dependency graph at all (no deps.ts entry; it is
itself ad-hoc constructed by setup-use-case.ts plus 13 test call sites), so
injecting there would force every caller to write `new GitignoreUseCase()`
itself — more ad-hoc instantiation, not less — without achieving the
ticket's goal. Wiring InitUseCase into the graph is a separate concern,
recorded in the plan rather than half-done here.

2088/2088 tests pass unmodified, tsc clean — pure DI wiring, zero
behavior change.
@blafourcade
blafourcade merged commit 7ff9edb into next Jul 27, 2026
14 checks passed
@blafourcade
blafourcade deleted the refactor/e6-us07-inject-shared-use-cases branch July 27, 2026 03:30
blafourcade added a commit that referenced this pull request Jul 31, 2026
…#523)

Both were instantiated ad hoc at 6 sites, escaping the dependency graph
entirely — no test could substitute either at the command level, unlike
every other shared use-case.

deps.ts now builds each once and injects them:
GitignoreUseCase -> PostInstallPipelineUseCase -> the 3 install use-cases,
and GitignoreUseCase -> CleanUseCase. Both verified stateless (only
readonly constructor deps) before being shared as singletons, same check
applied in #508.

Dead constructor params removed as a consequence, each checked per file
rather than assumed: PostInstallPipelineUseCase drops `fs` (its only use
was the removed `new GitignoreUseCase`), and InstallIdeConfigUseCase /
InstallRuntimeConfigUseCase drop `manifestRepo` (their only use was the
removed `new PostInstallPipelineUseCase`). InstallIdeToolUseCase still
uses manifestRepo once, so it keeps it; clean-use-case uses `fs` 13 times,
so it keeps that.

Scope: 5 of the 6 sites. init-use-case.ts is deliberately left alone —
InitUseCase is not in the dependency graph at all (no deps.ts entry; it is
itself ad-hoc constructed by setup-use-case.ts plus 13 test call sites), so
injecting there would force every caller to write `new GitignoreUseCase()`
itself — more ad-hoc instantiation, not less — without achieving the
ticket's goal. Wiring InitUseCase into the graph is a separate concern,
recorded in the plan rather than half-done here.

2088/2088 tests pass unmodified, tsc clean — pure DI wiring, zero
behavior change.
blafourcade added a commit that referenced this pull request Jul 31, 2026