Skip to content

Commit e0d30fd

Browse files
fix(opencode): actionable skip reports with declaring origin
Skip messages now include where the plugin was declared (scope + config source) so a config-sourced and a local-file plugin failing for the same reason no longer read identically. Formatting lives in plugin/report.ts with a regression test pinning the wiring and the copy.
1 parent 635e82a commit e0d30fd

3 files changed

Lines changed: 65 additions & 1 deletion

File tree

‎packages/opencode/src/plugin/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { EffectBridge } from "@/effect/bridge"
2727
import { InstanceState } from "@/effect/instance-state"
2828
import { errorMessage } from "@/util/error"
2929
import { PluginLoader } from "./loader"
30+
import { missingMessage } from "./report"
3031
import { parsePluginSpecifier, readPluginId, readV1Plugin, resolvePluginId } from "./shared"
3132
import { registerAdapter } from "@/control-plane/adapters"
3233
import type { WorkspaceAdapter } from "@/control-plane/types"
@@ -190,7 +191,7 @@ const layer = Layer.effect(
190191
report: {
191192
start(candidate) {},
192193
missing(candidate, _retry, message) {
193-
publishPluginError(`Plugin ${candidate.plan.spec} skipped: ${message}`)
194+
publishPluginError(missingMessage(candidate, message))
194195
},
195196
error(candidate, _retry, stage, error, resolved) {
196197
const spec = candidate.plan.spec
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { ConfigPlugin } from "@/config/plugin"
2+
3+
type MissingCandidate = {
4+
plan: { spec: string }
5+
origin: ConfigPlugin.Origin
6+
}
7+
8+
// Skip reports must say WHERE the plugin was declared so users know which
9+
// config to fix: a config-sourced and a local-file plugin fail for very
10+
// different reasons despite identical specs.
11+
export function missingMessage(candidate: MissingCandidate, message: string): string {
12+
return `Plugin ${candidate.plan.spec} (${candidate.origin.scope}: ${candidate.origin.source}) skipped: ${message}`
13+
}

‎packages/opencode/test/plugin/loader-shared.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,4 +1303,54 @@ export default {
13031303
}
13041304
}),
13051305
)
1306+
1307+
it.live("missing reports carry the declaring origin so users know what to fix", () =>
1308+
withTmp(
1309+
async (dir) => {
1310+
const mod = path.join(dir, "mods", "acme-plugin")
1311+
await fs.mkdir(path.join(mod, "dist"), { recursive: true })
1312+
await Bun.write(
1313+
path.join(mod, "package.json"),
1314+
JSON.stringify(
1315+
{ name: "acme-plugin", version: "1.0.0", exports: { "./tui": "./dist/tui.js" } },
1316+
null,
1317+
2,
1318+
),
1319+
)
1320+
await Bun.write(path.join(mod, "dist", "tui.js"), "export default {}\n")
1321+
return { mod }
1322+
},
1323+
(tmp) =>
1324+
Effect.gen(function* () {
1325+
const { missingMessage } = yield* Effect.promise(() => import("../../src/plugin/report"))
1326+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: undefined })
1327+
const missing: string[] = []
1328+
1329+
try {
1330+
yield* Effect.promise(() =>
1331+
PluginLoader.loadExternal({
1332+
items: [
1333+
{
1334+
1335+
scope: "local" as const,
1336+
source: tmp.path,
1337+
},
1338+
],
1339+
kind: "server",
1340+
report: {
1341+
missing(candidate, _retry, message) {
1342+
missing.push(missingMessage(candidate, message))
1343+
},
1344+
},
1345+
}),
1346+
)
1347+
} finally {
1348+
install.mockRestore()
1349+
}
1350+
1351+
expect(missing.length).toBe(1)
1352+
expect(missing[0]).toStartWith(`Plugin [email protected] (local: ${tmp.path}) skipped:`)
1353+
}),
1354+
),
1355+
)
13061356
})

0 commit comments

Comments
 (0)