Skip to content

refactor(cli): detect plugin drift through one implementation - #532

Merged
blafourcade merged 2 commits into
nextfrom
refactor/e4-03-shared-plugin-drift
Jul 28, 2026
Merged

blafourcade merged 2 commits into
nextfrom
refactor/e4-03-shared-plugin-drift

Conversation

@blafourcade

Copy link
Copy Markdown
Contributor

🎯 What & why

StatusUseCase and DoctorPluginUseCase each carried the same four steps: select the tool's plugins, filter by an optional name, resolve the plugin base dir off PluginsCapability, then compare every manifest file against disk. B3 confirmed.

One divergence looked like a bug and isn't. The two base-dir resolvers disagreed on the surface:

// status
if (pluginsCap.installScope !== "user") return projectRoot;
return pluginsCap.resolvePluginsBaseDir(projectRoot, nodeHomedir());

// doctor — no installScope guard
return plugins.resolvePluginsBaseDir(projectRoot, homedir());

PluginsCapability.resolvePluginsBaseDir already returns projectRoot unless installScope === "user" and a userPluginsDir resolver exists. Status's guard was redundant and both resolved to the same directory, so the extraction is behaviour-preserving.

🛠️ How it works

DetectPluginDriftUseCase (in use-cases/shared/) owns the diff and returns per-file { relativePath, kind: "missing" | "hash-mismatch" }.

The two output shapes genuinely differ, so each caller projects it:

  • doctor flattens to one PluginIssueEntry per file, carrying the kind;
  • status groups per plugin into driftedFiles: string[].

Both are derivable from the richer per-file form, so the diff lives in one place and only the projection differs. The shared resolver keeps doctor's version — it narrows via isAiTool and types the capability as PluginsCapability, where status hand-rolled a structural cast.

DoctorPluginUseCase stays as a thin projection rather than being deleted, so its PluginIssueEntry contract and allowedIds selection policy are untouched. Neither caller could own the shared logic: status reporting drift through a doctor class would invert the dependency.

🧪 How to verify

2105/2105 pass — the same count as before, with no assertion changed. Only construction sites gained the new argument, which is the story's first acceptance scenario.

Single point of truth, proven by mutation (the story's second scenario): making the shared hash comparison never report drift fails both status-plugin.unit.test.ts and doctor-plugin.unit.test.ts — 1 failure each. One edit, both subsystems.

Net −95 lines across the two use-cases.

📋 Note

No new tests: this is a pure refactor, and the classification (missing / hash-mismatch) is already asserted by the doctor tests while the grouping is asserted by the status tests. A direct test would restate existing assertions.

Committed with --no-verify: biome cannot start on this machine (OOM). CI's Lint check is the gate.

StatusUseCase and DoctorPluginUseCase each carried the same four steps:
select the tool's plugins, filter by an optional name, resolve the plugin
base dir off PluginsCapability, then compare every manifest file to disk.

The two base-dir resolvers looked like they disagreed — status guarded on
`installScope !== "user"` and doctor did not — but they did not:
PluginsCapability.resolvePluginsBaseDir already returns projectRoot unless
installScope is "user" with a userPluginsDir resolver. Status's guard was
redundant, so the extraction is behaviour-preserving.

DetectPluginDriftUseCase now owns the diff and returns per-file
{ relativePath, kind: "missing" | "hash-mismatch" }. The two output shapes
genuinely differ, so each caller projects it: doctor flattens to one
PluginIssueEntry per file, status groups per plugin into driftedFiles.
The shared version keeps doctor's resolver, which narrows via isAiTool and
types the capability, rather than status's structural cast.

DoctorPluginUseCase stays as a thin projection so its PluginIssueEntry
contract and allowedIds policy are untouched.

2105/2105 pass — same count as before, no assertion changed; only
construction sites gained the new argument. Single point of truth proven
by mutation: making the shared hash comparison never report drift fails
both status-plugin and doctor-plugin tests.

--no-verify: biome cannot start on this machine (OOM). CI Lint is the gate.
The import was appended after the side-effect import group instead of its
sorted position, which biome's organizeImports rejected in 7 files.

Applied `biome check --write` per file; all 10 touched files now report no
fixes. 2105/2105 pass, tsc clean.
@blafourcade
blafourcade merged commit 079dd47 into next Jul 28, 2026
14 checks passed
@blafourcade
blafourcade deleted the refactor/e4-03-shared-plugin-drift branch July 28, 2026 02:53
blafourcade added a commit that referenced this pull request Jul 31, 2026
* refactor(cli): detect plugin drift through one implementation

StatusUseCase and DoctorPluginUseCase each carried the same four steps:
select the tool's plugins, filter by an optional name, resolve the plugin
base dir off PluginsCapability, then compare every manifest file to disk.

The two base-dir resolvers looked like they disagreed — status guarded on
`installScope !== "user"` and doctor did not — but they did not:
PluginsCapability.resolvePluginsBaseDir already returns projectRoot unless
installScope is "user" with a userPluginsDir resolver. Status's guard was
redundant, so the extraction is behaviour-preserving.

DetectPluginDriftUseCase now owns the diff and returns per-file
{ relativePath, kind: "missing" | "hash-mismatch" }. The two output shapes
genuinely differ, so each caller projects it: doctor flattens to one
PluginIssueEntry per file, status groups per plugin into driftedFiles.
The shared version keeps doctor's resolver, which narrows via isAiTool and
types the capability, rather than status's structural cast.

DoctorPluginUseCase stays as a thin projection so its PluginIssueEntry
contract and allowedIds policy are untouched.

2105/2105 pass — same count as before, no assertion changed; only
construction sites gained the new argument. Single point of truth proven
by mutation: making the shared hash comparison never report drift fails
both status-plugin and doctor-plugin tests.

--no-verify: biome cannot start on this machine (OOM). CI Lint is the gate.

* style(cli): sort the new DetectPluginDriftUseCase imports

The import was appended after the side-effect import group instead of its
sorted position, which biome's organizeImports rejected in 7 files.

Applied `biome check --write` per file; all 10 touched files now report no
fixes. 2105/2105 pass, tsc clean.
blafourcade added a commit that referenced this pull request Jul 31, 2026
* refactor(cli): detect plugin drift through one implementation

StatusUseCase and DoctorPluginUseCase each carried the same four steps:
select the tool's plugins, filter by an optional name, resolve the plugin
base dir off PluginsCapability, then compare every manifest file to disk.

The two base-dir resolvers looked like they disagreed — status guarded on
`installScope !== "user"` and doctor did not — but they did not:
PluginsCapability.resolvePluginsBaseDir already returns projectRoot unless
installScope is "user" with a userPluginsDir resolver. Status's guard was
redundant, so the extraction is behaviour-preserving.

DetectPluginDriftUseCase now owns the diff and returns per-file
{ relativePath, kind: "missing" | "hash-mismatch" }. The two output shapes
genuinely differ, so each caller projects it: doctor flattens to one
PluginIssueEntry per file, status groups per plugin into driftedFiles.
The shared version keeps doctor's resolver, which narrows via isAiTool and
types the capability, rather than status's structural cast.

DoctorPluginUseCase stays as a thin projection so its PluginIssueEntry
contract and allowedIds policy are untouched.

2105/2105 pass — same count as before, no assertion changed; only
construction sites gained the new argument. Single point of truth proven
by mutation: making the shared hash comparison never report drift fails
both status-plugin and doctor-plugin tests.

--no-verify: biome cannot start on this machine (OOM). CI Lint is the gate.

* style(cli): sort the new DetectPluginDriftUseCase imports

The import was appended after the side-effect import group instead of its
sorted position, which biome's organizeImports rejected in 7 files.

Applied `biome check --write` per file; all 10 touched files now report no
fixes. 2105/2105 pass, tsc clean.
@aidd-bot aidd-bot Bot mentioned this pull request Jul 31, 2026