Skip to content

Commit b1f0765

Browse files
committed
test: align plugin loader npm mocks
- switch plugin loader tests to the effect npm module - return Option.none() for mocked npm entrypoints - keep test fixtures aligned with the current Npm.add contract
1 parent 992435a commit b1f0765

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

packages/opencode/test/cli/tui/plugin-loader-entrypoint.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { Option } from "effect"
12
import { expect, spyOn, test } from "bun:test"
23
import fs from "fs/promises"
34
import path from "path"
45
import { pathToFileURL } from "url"
56
import { tmpdir } from "../../fixture/fixture"
67
import { createTuiPluginApi } from "../../fixture/tui-plugin"
78
import { TuiConfig } from "../../../src/cli/cmd/tui/config/tui"
8-
import { Npm } from "../../../src/npm"
9+
import { Npm } from "../../../src/npm/effect"
910

1011
const { TuiPluginRuntime } = await import("../../../src/cli/cmd/tui/plugin/runtime")
1112

@@ -56,7 +57,7 @@ test("loads npm tui plugin from package ./tui export", async () => {
5657
}
5758
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
5859
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
59-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
60+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
6061

6162
try {
6263
await TuiPluginRuntime.init({ api: createTuiPluginApi(), config })
@@ -117,7 +118,7 @@ test("does not use npm package exports dot for tui entry", async () => {
117118
}
118119
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
119120
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
120-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
121+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
121122

122123
try {
123124
await TuiPluginRuntime.init({ api: createTuiPluginApi(), config })
@@ -179,7 +180,7 @@ test("rejects npm tui export that resolves outside plugin directory", async () =
179180
}
180181
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
181182
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
182-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
183+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
183184

184185
try {
185186
await TuiPluginRuntime.init({ api: createTuiPluginApi(), config })
@@ -241,7 +242,7 @@ test("rejects npm tui plugin that exports server and tui together", async () =>
241242
}
242243
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
243244
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
244-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
245+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
245246

246247
try {
247248
await TuiPluginRuntime.init({ api: createTuiPluginApi(), config })
@@ -299,7 +300,7 @@ test("does not use npm package main for tui entry", async () => {
299300
}
300301
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
301302
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
302-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
303+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
303304
const warn = spyOn(console, "warn").mockImplementation(() => {})
304305
const error = spyOn(console, "error").mockImplementation(() => {})
305306

@@ -468,7 +469,7 @@ test("uses npm package name when tui plugin id is omitted", async () => {
468469
}
469470
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
470471
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
471-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
472+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
472473

473474
try {
474475
await TuiPluginRuntime.init({ api: createTuiPluginApi(), config })

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { afterAll, afterEach, describe, expect, spyOn, test } from "bun:test"
2-
import { Effect } from "effect"
2+
import { Effect, Option } from "effect"
33
import fs from "fs/promises"
44
import path from "path"
55
import { pathToFileURL } from "url"
@@ -13,7 +13,7 @@ const { Plugin } = await import("../../src/plugin/index")
1313
const { PluginLoader } = await import("../../src/plugin/loader")
1414
const { readPackageThemes } = await import("../../src/plugin/shared")
1515
const { Instance } = await import("../../src/project/instance")
16-
const { Npm } = await import("../../src/npm")
16+
const { Npm } = await import("../../src/npm/effect")
1717

1818
afterAll(() => {
1919
if (disableDefault === undefined) {
@@ -239,8 +239,8 @@ describe("plugin.loader.shared", () => {
239239
})
240240

241241
const add = spyOn(Npm, "add").mockImplementation(async (pkg) => {
242-
if (pkg === "acme-plugin") return { directory: tmp.extra.acme, entrypoint: tmp.extra.acme }
243-
return { directory: tmp.extra.scope, entrypoint: tmp.extra.scope }
242+
if (pkg === "acme-plugin") return { directory: tmp.extra.acme, entrypoint: Option.none() }
243+
return { directory: tmp.extra.scope, entrypoint: Option.none() }
244244
})
245245

246246
try {
@@ -301,7 +301,7 @@ describe("plugin.loader.shared", () => {
301301
},
302302
})
303303

304-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
304+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
305305

306306
try {
307307
await load(tmp.path)
@@ -358,7 +358,7 @@ describe("plugin.loader.shared", () => {
358358
},
359359
})
360360

361-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
361+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
362362

363363
try {
364364
await load(tmp.path)
@@ -410,7 +410,7 @@ describe("plugin.loader.shared", () => {
410410
},
411411
})
412412

413-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
413+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
414414

415415
try {
416416
await load(tmp.path)
@@ -455,7 +455,7 @@ describe("plugin.loader.shared", () => {
455455
},
456456
})
457457

458-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
458+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
459459

460460
try {
461461
await load(tmp.path)
@@ -518,7 +518,7 @@ describe("plugin.loader.shared", () => {
518518
},
519519
})
520520

521-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
521+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
522522

523523
try {
524524
await load(tmp.path)
@@ -548,7 +548,7 @@ describe("plugin.loader.shared", () => {
548548
},
549549
})
550550

551-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: "", entrypoint: "" })
551+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: "", entrypoint: Option.none() })
552552

553553
try {
554554
await load(tmp.path)
@@ -927,7 +927,7 @@ export default {
927927
},
928928
})
929929

930-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
930+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
931931
const missing: string[] = []
932932

933933
try {
@@ -996,7 +996,7 @@ export default {
996996
},
997997
})
998998

999-
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
999+
const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
10001000

10011001
try {
10021002
const loaded = await PluginLoader.loadExternal({

0 commit comments

Comments
 (0)