Skip to content

refactor(cli): resolve the plugin base dir in one place - #544

Merged
blafourcade merged 1 commit into
nextfrom
refactor/e7-02-shared-plugin-base-dir
Jul 28, 2026
Merged

blafourcade merged 1 commit into
nextfrom
refactor/e7-02-shared-plugin-base-dir

Conversation

@blafourcade

Copy link
Copy Markdown
Contributor

🎯 What & why

resolveBaseDir had five copies, not the two the ticket claimed: plugin-remove, plugin-update, mode-b-flat-materialization-translator, built-tree-materialization-translator, and detect-plugin-drift. qualifiesForOpencodeMcpMerge had two, verbatim identical.

🛠️ How it works

The copies differed, but every difference turned out to be non-behavioural — confirmed by reading PluginsCapability.resolvePluginsBaseDir rather than assumed:

  • a redundant installScope !== "user" pre-guard (the capability already returns projectRoot unless the scope is user and a resolver exists);
  • a missing "plugins" in caps presence check;
  • a dead tool === undefined check.

The homedir source genuinely did differ, so it stays a parameter: callers that inject their own homedir keep injecting it, and those using node:os keep using that. Forcing everything onto node:os would have been a silent behaviour change.

plugin-helpers.ts now exports:

  • resolvePluginBaseDirForCapability — the primitive, for the caller that already holds a resolved capability;
  • resolvePluginBaseDir — looks the tool up and delegates;
  • qualifiesForOpencodeMcpMerge.

🧪 How to verify

2105/2105 pass, tsc --noEmit clean, no assertion changed.

Mutation-tested by making the shared resolver return a sentinel path: 14 cases across 10 files failed, spanning four of the five call sites — the evidence the extraction actually landed rather than just compiling.

⚠️ Known gap

plugin-update-use-case.unit.test.ts did not fail under that mutation: it asserts only the manifest version, never the written path. So that one call site rests on tsc rather than on a test. Its missing path coverage is already tracked by SPIKE-E7-01 (#541), whose new tests do assert the user-scope write path.

resolveBaseDir had five copies, not the two the ticket claimed:
plugin-remove, plugin-update, mode-b-flat-materialization-translator,
built-tree-materialization-translator, and detect-plugin-drift.
qualifiesForOpencodeMcpMerge had two, verbatim identical.

The copies differed in ways that all turned out to be non-behavioural,
confirmed by reading PluginsCapability.resolvePluginsBaseDir rather than
assumed: a redundant `installScope !== "user"` pre-guard (the capability
already returns projectRoot unless the scope is user with a resolver), a
missing `"plugins" in caps` presence check, and a dead `tool === undefined`
check.

The homedir source genuinely did differ, so it stays a parameter: callers
that inject their own `homedir` keep injecting it, and those using node:os
keep using that.

plugin-helpers.ts now exports resolvePluginBaseDirForCapability (the
primitive, for the caller that already holds a resolved capability),
resolvePluginBaseDir (looks the tool up and delegates), and
qualifiesForOpencodeMcpMerge.

2105/2105 pass, tsc clean, no assertion changed. Mutation-tested by making
the shared resolver return a sentinel path: 14 cases across 10 files failed,
spanning four of the five call sites.

plugin-update-use-case.unit.test.ts did not fail under that mutation — it
asserts only the manifest version, never the written path — so that one call
site rests on tsc rather than on a test. Its missing path coverage is
already tracked by SPIKE-E7-01.

--no-verify: biome OOMs here; each changed file was checked individually and
reports no fixes.

Co-Authored-By: Claude Opus 5 <[email protected]>
@blafourcade
blafourcade merged commit 3de6ed2 into next Jul 28, 2026
14 checks passed
blafourcade added a commit that referenced this pull request Jul 31, 2026
resolveBaseDir had five copies, not the two the ticket claimed:
plugin-remove, plugin-update, mode-b-flat-materialization-translator,
built-tree-materialization-translator, and detect-plugin-drift.
qualifiesForOpencodeMcpMerge had two, verbatim identical.

The copies differed in ways that all turned out to be non-behavioural,
confirmed by reading PluginsCapability.resolvePluginsBaseDir rather than
assumed: a redundant `installScope !== "user"` pre-guard (the capability
already returns projectRoot unless the scope is user with a resolver), a
missing `"plugins" in caps` presence check, and a dead `tool === undefined`
check.

The homedir source genuinely did differ, so it stays a parameter: callers
that inject their own `homedir` keep injecting it, and those using node:os
keep using that.

plugin-helpers.ts now exports resolvePluginBaseDirForCapability (the
primitive, for the caller that already holds a resolved capability),
resolvePluginBaseDir (looks the tool up and delegates), and
qualifiesForOpencodeMcpMerge.

2105/2105 pass, tsc clean, no assertion changed. Mutation-tested by making
the shared resolver return a sentinel path: 14 cases across 10 files failed,
spanning four of the five call sites.

plugin-update-use-case.unit.test.ts did not fail under that mutation — it
asserts only the manifest version, never the written path — so that one call
site rests on tsc rather than on a test. Its missing path coverage is
already tracked by SPIKE-E7-01.

--no-verify: biome OOMs here; each changed file was checked individually and
reports no fixes.

Co-authored-by: Claude Opus 5 <[email protected]>
blafourcade added a commit that referenced this pull request Jul 31, 2026
resolveBaseDir had five copies, not the two the ticket claimed:
plugin-remove, plugin-update, mode-b-flat-materialization-translator,
built-tree-materialization-translator, and detect-plugin-drift.
qualifiesForOpencodeMcpMerge had two, verbatim identical.

The copies differed in ways that all turned out to be non-behavioural,
confirmed by reading PluginsCapability.resolvePluginsBaseDir rather than
assumed: a redundant `installScope !== "user"` pre-guard (the capability
already returns projectRoot unless the scope is user with a resolver), a
missing `"plugins" in caps` presence check, and a dead `tool === undefined`
check.

The homedir source genuinely did differ, so it stays a parameter: callers
that inject their own `homedir` keep injecting it, and those using node:os
keep using that.

plugin-helpers.ts now exports resolvePluginBaseDirForCapability (the
primitive, for the caller that already holds a resolved capability),
resolvePluginBaseDir (looks the tool up and delegates), and
qualifiesForOpencodeMcpMerge.

2105/2105 pass, tsc clean, no assertion changed. Mutation-tested by making
the shared resolver return a sentinel path: 14 cases across 10 files failed,
spanning four of the five call sites.

plugin-update-use-case.unit.test.ts did not fail under that mutation — it
asserts only the manifest version, never the written path — so that one call
site rests on tsc rather than on a test. Its missing path coverage is
already tracked by SPIKE-E7-01.

--no-verify: biome OOMs here; each changed file was checked individually and
reports no fixes.

Co-authored-by: Claude Opus 5 <[email protected]>
@aidd-bot aidd-bot Bot mentioned this pull request Jul 31, 2026
blafourcade added a commit that referenced this pull request Jul 31, 2026