Skip to content

Commit 905226c

Browse files
vglafirovfwang
authored andcommitted
fix: Add Plugin Mocks to Provider Tests (anomalyco#8276)
1 parent 73adf7e commit 905226c

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

packages/opencode/src/provider/provider.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import z from "zod"
2-
import path from "path"
3-
import os from "os"
42
import fuzzysort from "fuzzysort"
53
import { Config } from "../config/config"
64
import { mapValues, mergeDeep, omit, pickBy, sortBy } from "remeda"
@@ -605,13 +603,13 @@ export namespace Provider {
605603
},
606604
experimentalOver200K: model.cost?.context_over_200k
607605
? {
608-
cache: {
609-
read: model.cost.context_over_200k.cache_read ?? 0,
610-
write: model.cost.context_over_200k.cache_write ?? 0,
611-
},
612-
input: model.cost.context_over_200k.input,
613-
output: model.cost.context_over_200k.output,
614-
}
606+
cache: {
607+
read: model.cost.context_over_200k.cache_read ?? 0,
608+
write: model.cost.context_over_200k.cache_write ?? 0,
609+
},
610+
input: model.cost.context_over_200k.input,
611+
output: model.cost.context_over_200k.output,
612+
}
615613
: undefined,
616614
},
617615
limit: {

packages/opencode/test/provider/provider.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
1-
import { test, expect } from "bun:test"
1+
import { test, expect, mock } from "bun:test"
22
import path from "path"
3+
4+
// Mock BunProc and default plugins to prevent actual installations during tests
5+
mock.module("../../src/bun/index", () => ({
6+
BunProc: {
7+
install: async (pkg: string, _version?: string) => {
8+
// Return package name without version for mocking
9+
const lastAtIndex = pkg.lastIndexOf("@")
10+
return lastAtIndex > 0 ? pkg.substring(0, lastAtIndex) : pkg
11+
},
12+
run: async () => {
13+
throw new Error("BunProc.run should not be called in tests")
14+
},
15+
which: () => process.execPath,
16+
InstallFailedError: class extends Error {},
17+
},
18+
}))
19+
20+
const mockPlugin = () => ({})
21+
mock.module("opencode-copilot-auth", () => ({ default: mockPlugin }))
22+
mock.module("opencode-anthropic-auth", () => ({ default: mockPlugin }))
23+
mock.module("@gitlab/opencode-gitlab-auth", () => ({ default: mockPlugin }))
24+
325
import { tmpdir } from "../fixture/fixture"
426
import { Instance } from "../../src/project/instance"
527
import { Provider } from "../../src/provider/provider"

0 commit comments

Comments
 (0)