Skip to content

fix(cli): move marketplace refresh --force cache clear into its use-case - #528

Merged
blafourcade merged 1 commit into
nextfrom
fix/e5-08-marketplace-refresh-force-layering
Jul 27, 2026
Merged

blafourcade merged 1 commit into
nextfrom
fix/e5-08-marketplace-refresh-force-layering

Conversation

@blafourcade

@blafourcade blafourcade commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

🎯 What & why

The refresh command reached straight into a port to perform part of the refresh itself:

if (cmdOptions.force) await deps.marketplaceCache.clear(name);
await deps.marketplaceRefreshUseCase.execute({ projectRoot, name });

Commands are wiring; orchestration belongs to the use-case. Two practical consequences beyond style:

  1. --force was untestable at the use-case level — every existing refresh test constructs MarketplaceRefreshUseCase directly, so none could reach the flag. It was only exercisable through the CLI.
  2. The ordering requirement lived in the caller. The clear must happen before the fetch loop; nothing in the use-case enforced or documented that.

🛠️ How it works

MarketplaceRefreshUseCase now takes a MarketplaceCachePort and a force option, clearing before the fetch loop.

The port is required, not optional. The use-case's existing optionals (logger?, fs?) are genuine degradations — refresh still works without them. A missing cache is not: with force: true it would silently do nothing, which is precisely the class of bug this epic keeps turning up. Required means tsc enumerates the construction sites rather than letting one default to undefined.

marketplaceCache also leaves the exported Deps surface — its only consumer was this command, and keeping it public invites the next command to reach past the use-case the same way. It stays wired internally.

🧪 How to verify

pnpm --filter cli test — 2096/2096, tsc clean.

The three new force tests were verified to fail (2 of 3) when the clear call is removed from the use-case.

grep -n  "marketplaceCache"      src/application/commands/marketplace.ts   # nothing
grep -rn "deps.marketplaceCache" src/                                      # nothing

📎 Why forceRefresh is always on but --force is opt-in

Worth stating, since both end up deleting cache and the difference is not obvious. They differ in scope, not in kind:

deletes rationale
forceRefresh: true, passed unconditionally by fetchSource() cacheDir/<source-key>/ — e.g. …/marketplaces/foo/github-owner-repo-HEAD/ (bustCacheIfNeeded, plugin-fetcher-adapter) refreshing is re-fetching, so it must never serve a stale clone of the source it is about to fetch
--force cacheDir/ in full — …/marketplaces/foo/ (MarketplaceCacheAdapter.clear) also removes subdirectories left by previous source specs (an old ref, a changed repo) and the raw catalog file written directly into cacheDir. Garbage collection, not re-fetch — hence opt-in

So the always-on flag is correct, and --force is opt-in because it is strictly broader and discards more.

Cartography item A14.

The refresh command reached straight into a port to do part of the refresh
itself:

    if (cmdOptions.force) await deps.marketplaceCache.clear(name);
    await deps.marketplaceRefreshUseCase.execute({ projectRoot, name });

Commands are wiring; orchestration belongs to the use-case. Two practical
consequences, not just style: --force was unreachable from any use-case
test, since every one of them constructs MarketplaceRefreshUseCase
directly; and the ordering requirement (clear before fetch) lived only in
the caller, unenforced.

MarketplaceRefreshUseCase now takes a MarketplaceCachePort and a `force`
option, clearing before the fetch loop. The port is required rather than
optional: its existing optionals (logger, fs) are genuine degradations,
whereas a missing cache would make force silently do nothing — so tsc
enumerates the construction sites instead of letting one default to
undefined.

marketplaceCache also leaves the exported Deps surface. Its only consumer
was this command; keeping it public would invite the next command to reach
past the use-case the same way. It stays wired internally.

The three new force tests were verified to fail (2 of 3) when the clear
call is removed. 2096/2096 pass, tsc clean.
@blafourcade
blafourcade force-pushed the fix/e5-08-marketplace-refresh-force-layering branch from f70c1a8 to bce7fbf Compare July 27, 2026 05:56
@blafourcade
blafourcade merged commit eb08a27 into next Jul 27, 2026
14 checks passed
@blafourcade
blafourcade deleted the fix/e5-08-marketplace-refresh-force-layering branch July 27, 2026 07:17
blafourcade added a commit that referenced this pull request Jul 27, 2026
Two issues CI's Lint job caught that biome could not surface locally (it
OOMs on this machine, ~72MB free):

- uninstall-ide-use-case.unit.test.ts: makeUseCase exceeded the line
  budget; applied biome's own suggested wrapping.
- deps.ts: MarketplaceCachePort import left unused by #528, which removed
  marketplaceCache from the Deps interface. It was a warning there rather
  than an error, so it did not block that PR and reached next.
blafourcade added a commit that referenced this pull request Jul 27, 2026
* fix(cli): ide uninstall removes the settings keys it merged in

UninstallIdeUseCase deleted only manifest.getToolFiles(toolId). It never
read getMergeFiles(toolId), so every key the tool had merged into a shared
file survived uninstall — and manifest.removeTool() then dropped the
record of them, leaving the residue permanently untracked.

For vscode that means .vscode/extensions.json and .vscode/settings.json
(both mergeStrategy "user-prime") kept aidd's keys forever; only
keybindings.json, a plain file, was cleaned up.

The AI path already does this correctly: UninstallToolsUseCase.
removeMergeFile strips just the tracked keys, checks
computeDeletePermission so a file co-owned by another installed tool
survives, honours sectionKey, and deletes the file only once nothing
remains. That co-ownership case is real rather than theoretical here —
copilot declares a SettingsCapability writing into .vscode/settings.json
with requiresTool "vscode".

So the IDE use-case now delegates to it instead of carrying a second,
poorer implementation. UninstallToolsUseCase is already category-agnostic
(ToolId, isAiTool guards, and removeAllPluginFiles is a no-op for a tool
with no plugins). Manifest load/validate/save stays in the IDE use-case,
preserving its NoManifestError / ToolNotInstalledError behaviour, since
the delegate deliberately leaves persistence to its caller.

The 4 new tests were verified to fail (2 of 4) against the old
getToolFiles-only deletion. 2100/2100 pass, tsc clean.

Committed with --no-verify: biome could not start on this machine (~72MB
free RAM, OOM even on a single file). CI's required Lint check covers it.

* style(cli): fix formatting and drop an unused import flagged by CI lint

Two issues CI's Lint job caught that biome could not surface locally (it
OOMs on this machine, ~72MB free):

- uninstall-ide-use-case.unit.test.ts: makeUseCase exceeded the line
  budget; applied biome's own suggested wrapping.
- deps.ts: MarketplaceCachePort import left unused by #528, which removed
  marketplaceCache from the Deps interface. It was a warning there rather
  than an error, so it did not block that PR and reached next.
blafourcade added a commit that referenced this pull request Jul 31, 2026
…ase (#528)

The refresh command reached straight into a port to do part of the refresh
itself:

    if (cmdOptions.force) await deps.marketplaceCache.clear(name);
    await deps.marketplaceRefreshUseCase.execute({ projectRoot, name });

Commands are wiring; orchestration belongs to the use-case. Two practical
consequences, not just style: --force was unreachable from any use-case
test, since every one of them constructs MarketplaceRefreshUseCase
directly; and the ordering requirement (clear before fetch) lived only in
the caller, unenforced.

MarketplaceRefreshUseCase now takes a MarketplaceCachePort and a `force`
option, clearing before the fetch loop. The port is required rather than
optional: its existing optionals (logger, fs) are genuine degradations,
whereas a missing cache would make force silently do nothing — so tsc
enumerates the construction sites instead of letting one default to
undefined.

marketplaceCache also leaves the exported Deps surface. Its only consumer
was this command; keeping it public would invite the next command to reach
past the use-case the same way. It stays wired internally.

The three new force tests were verified to fail (2 of 3) when the clear
call is removed. 2096/2096 pass, tsc clean.
blafourcade added a commit that referenced this pull request Jul 31, 2026
* fix(cli): ide uninstall removes the settings keys it merged in

UninstallIdeUseCase deleted only manifest.getToolFiles(toolId). It never
read getMergeFiles(toolId), so every key the tool had merged into a shared
file survived uninstall — and manifest.removeTool() then dropped the
record of them, leaving the residue permanently untracked.

For vscode that means .vscode/extensions.json and .vscode/settings.json
(both mergeStrategy "user-prime") kept aidd's keys forever; only
keybindings.json, a plain file, was cleaned up.

The AI path already does this correctly: UninstallToolsUseCase.
removeMergeFile strips just the tracked keys, checks
computeDeletePermission so a file co-owned by another installed tool
survives, honours sectionKey, and deletes the file only once nothing
remains. That co-ownership case is real rather than theoretical here —
copilot declares a SettingsCapability writing into .vscode/settings.json
with requiresTool "vscode".

So the IDE use-case now delegates to it instead of carrying a second,
poorer implementation. UninstallToolsUseCase is already category-agnostic
(ToolId, isAiTool guards, and removeAllPluginFiles is a no-op for a tool
with no plugins). Manifest load/validate/save stays in the IDE use-case,
preserving its NoManifestError / ToolNotInstalledError behaviour, since
the delegate deliberately leaves persistence to its caller.

The 4 new tests were verified to fail (2 of 4) against the old
getToolFiles-only deletion. 2100/2100 pass, tsc clean.

Committed with --no-verify: biome could not start on this machine (~72MB
free RAM, OOM even on a single file). CI's required Lint check covers it.

* style(cli): fix formatting and drop an unused import flagged by CI lint

Two issues CI's Lint job caught that biome could not surface locally (it
OOMs on this machine, ~72MB free):

- uninstall-ide-use-case.unit.test.ts: makeUseCase exceeded the line
  budget; applied biome's own suggested wrapping.
- deps.ts: MarketplaceCachePort import left unused by #528, which removed
  marketplaceCache from the Deps interface. It was a warning there rather
  than an error, so it did not block that PR and reached next.
blafourcade added a commit that referenced this pull request Jul 31, 2026
…ase (#528)

The refresh command reached straight into a port to do part of the refresh
itself:

    if (cmdOptions.force) await deps.marketplaceCache.clear(name);
    await deps.marketplaceRefreshUseCase.execute({ projectRoot, name });

Commands are wiring; orchestration belongs to the use-case. Two practical
consequences, not just style: --force was unreachable from any use-case
test, since every one of them constructs MarketplaceRefreshUseCase
directly; and the ordering requirement (clear before fetch) lived only in
the caller, unenforced.

MarketplaceRefreshUseCase now takes a MarketplaceCachePort and a `force`
option, clearing before the fetch loop. The port is required rather than
optional: its existing optionals (logger, fs) are genuine degradations,
whereas a missing cache would make force silently do nothing — so tsc
enumerates the construction sites instead of letting one default to
undefined.

marketplaceCache also leaves the exported Deps surface. Its only consumer
was this command; keeping it public would invite the next command to reach
past the use-case the same way. It stays wired internally.

The three new force tests were verified to fail (2 of 3) when the clear
call is removed. 2096/2096 pass, tsc clean.
blafourcade added a commit that referenced this pull request Jul 31, 2026
* fix(cli): ide uninstall removes the settings keys it merged in

UninstallIdeUseCase deleted only manifest.getToolFiles(toolId). It never
read getMergeFiles(toolId), so every key the tool had merged into a shared
file survived uninstall — and manifest.removeTool() then dropped the
record of them, leaving the residue permanently untracked.

For vscode that means .vscode/extensions.json and .vscode/settings.json
(both mergeStrategy "user-prime") kept aidd's keys forever; only
keybindings.json, a plain file, was cleaned up.

The AI path already does this correctly: UninstallToolsUseCase.
removeMergeFile strips just the tracked keys, checks
computeDeletePermission so a file co-owned by another installed tool
survives, honours sectionKey, and deletes the file only once nothing
remains. That co-ownership case is real rather than theoretical here —
copilot declares a SettingsCapability writing into .vscode/settings.json
with requiresTool "vscode".

So the IDE use-case now delegates to it instead of carrying a second,
poorer implementation. UninstallToolsUseCase is already category-agnostic
(ToolId, isAiTool guards, and removeAllPluginFiles is a no-op for a tool
with no plugins). Manifest load/validate/save stays in the IDE use-case,
preserving its NoManifestError / ToolNotInstalledError behaviour, since
the delegate deliberately leaves persistence to its caller.

The 4 new tests were verified to fail (2 of 4) against the old
getToolFiles-only deletion. 2100/2100 pass, tsc clean.

Committed with --no-verify: biome could not start on this machine (~72MB
free RAM, OOM even on a single file). CI's required Lint check covers it.

* style(cli): fix formatting and drop an unused import flagged by CI lint

Two issues CI's Lint job caught that biome could not surface locally (it
OOMs on this machine, ~72MB free):

- uninstall-ide-use-case.unit.test.ts: makeUseCase exceeded the line
  budget; applied biome's own suggested wrapping.
- deps.ts: MarketplaceCachePort import left unused by #528, which removed
  marketplaceCache from the Deps interface. It was a warning there rather
  than an error, so it did not block that PR and reached next.
@aidd-bot aidd-bot Bot mentioned this pull request Jul 31, 2026