summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2026-04-17 14:33:02 -0400
committerDax Raad <[email protected]>2026-04-17 14:33:02 -0400
commitb1f076558cf75c9ae5322f6195e68c3c380e3f9c (patch)
tree8c6986132a99f9cf52fd186bf0e7daa00aee9668
parent992435aaf8371dc784f9f3489e998e5c93451d18 (diff)
downloadopencode-b1f076558cf75c9ae5322f6195e68c3c380e3f9c.tar.gz
opencode-b1f076558cf75c9ae5322f6195e68c3c380e3f9c.zip
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
-rw-r--r--packages/opencode/test/cli/tui/plugin-loader-entrypoint.test.ts15
-rw-r--r--packages/opencode/test/plugin/loader-shared.test.ts24
2 files changed, 20 insertions, 19 deletions
diff --git a/packages/opencode/test/cli/tui/plugin-loader-entrypoint.test.ts b/packages/opencode/test/cli/tui/plugin-loader-entrypoint.test.ts
index 395e8ce42..c6c25fcc1 100644
--- a/packages/opencode/test/cli/tui/plugin-loader-entrypoint.test.ts
+++ b/packages/opencode/test/cli/tui/plugin-loader-entrypoint.test.ts
@@ -1,3 +1,4 @@
+import { Option } from "effect"
import { expect, spyOn, test } from "bun:test"
import fs from "fs/promises"
import path from "path"
@@ -5,7 +6,7 @@ import { pathToFileURL } from "url"
import { tmpdir } from "../../fixture/fixture"
import { createTuiPluginApi } from "../../fixture/tui-plugin"
import { TuiConfig } from "../../../src/cli/cmd/tui/config/tui"
-import { Npm } from "../../../src/npm"
+import { Npm } from "../../../src/npm/effect"
const { TuiPluginRuntime } = await import("../../../src/cli/cmd/tui/plugin/runtime")
@@ -56,7 +57,7 @@ test("loads npm tui plugin from package ./tui export", async () => {
}
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
try {
await TuiPluginRuntime.init({ api: createTuiPluginApi(), config })
@@ -117,7 +118,7 @@ test("does not use npm package exports dot for tui entry", async () => {
}
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
try {
await TuiPluginRuntime.init({ api: createTuiPluginApi(), config })
@@ -179,7 +180,7 @@ test("rejects npm tui export that resolves outside plugin directory", async () =
}
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
try {
await TuiPluginRuntime.init({ api: createTuiPluginApi(), config })
@@ -241,7 +242,7 @@ test("rejects npm tui plugin that exports server and tui together", async () =>
}
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
try {
await TuiPluginRuntime.init({ api: createTuiPluginApi(), config })
@@ -299,7 +300,7 @@ test("does not use npm package main for tui entry", async () => {
}
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
const warn = spyOn(console, "warn").mockImplementation(() => {})
const error = spyOn(console, "error").mockImplementation(() => {})
@@ -468,7 +469,7 @@ test("uses npm package name when tui plugin id is omitted", async () => {
}
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path)
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
try {
await TuiPluginRuntime.init({ api: createTuiPluginApi(), config })
diff --git a/packages/opencode/test/plugin/loader-shared.test.ts b/packages/opencode/test/plugin/loader-shared.test.ts
index 5072c1e74..8e3ad5ea0 100644
--- a/packages/opencode/test/plugin/loader-shared.test.ts
+++ b/packages/opencode/test/plugin/loader-shared.test.ts
@@ -1,5 +1,5 @@
import { afterAll, afterEach, describe, expect, spyOn, test } from "bun:test"
-import { Effect } from "effect"
+import { Effect, Option } from "effect"
import fs from "fs/promises"
import path from "path"
import { pathToFileURL } from "url"
@@ -13,7 +13,7 @@ const { Plugin } = await import("../../src/plugin/index")
const { PluginLoader } = await import("../../src/plugin/loader")
const { readPackageThemes } = await import("../../src/plugin/shared")
const { Instance } = await import("../../src/project/instance")
-const { Npm } = await import("../../src/npm")
+const { Npm } = await import("../../src/npm/effect")
afterAll(() => {
if (disableDefault === undefined) {
@@ -239,8 +239,8 @@ describe("plugin.loader.shared", () => {
})
const add = spyOn(Npm, "add").mockImplementation(async (pkg) => {
- if (pkg === "acme-plugin") return { directory: tmp.extra.acme, entrypoint: tmp.extra.acme }
- return { directory: tmp.extra.scope, entrypoint: tmp.extra.scope }
+ if (pkg === "acme-plugin") return { directory: tmp.extra.acme, entrypoint: Option.none() }
+ return { directory: tmp.extra.scope, entrypoint: Option.none() }
})
try {
@@ -301,7 +301,7 @@ describe("plugin.loader.shared", () => {
},
})
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
try {
await load(tmp.path)
@@ -358,7 +358,7 @@ describe("plugin.loader.shared", () => {
},
})
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
try {
await load(tmp.path)
@@ -410,7 +410,7 @@ describe("plugin.loader.shared", () => {
},
})
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
try {
await load(tmp.path)
@@ -455,7 +455,7 @@ describe("plugin.loader.shared", () => {
},
})
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
try {
await load(tmp.path)
@@ -518,7 +518,7 @@ describe("plugin.loader.shared", () => {
},
})
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
try {
await load(tmp.path)
@@ -548,7 +548,7 @@ describe("plugin.loader.shared", () => {
},
})
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: "", entrypoint: "" })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: "", entrypoint: Option.none() })
try {
await load(tmp.path)
@@ -927,7 +927,7 @@ export default {
},
})
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
const missing: string[] = []
try {
@@ -996,7 +996,7 @@ export default {
},
})
- const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: tmp.extra.mod })
+ const install = spyOn(Npm, "add").mockResolvedValue({ directory: tmp.extra.mod, entrypoint: Option.none() })
try {
const loaded = await PluginLoader.loadExternal({