summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2026-03-07 19:21:22 -0500
committerDax Raad <[email protected]>2026-03-07 19:30:32 -0500
commite6d1aae33afc1270a94b8e26f8a520caa275ddd3 (patch)
tree32ad6a042811f7b1be97bef649f7ef18be7285ea
parent9dc8ac47341032096e10761c570e498cc26d2ec1 (diff)
downloadopencode-e6d1aae33afc1270a94b8e26f8a520caa275ddd3.tar.gz
opencode-e6d1aae33afc1270a94b8e26f8a520caa275ddd3.zip
test: lock in process, ripgrep, and installation helpers
-rw-r--r--packages/opencode/test/file/ripgrep.test.ts34
-rw-r--r--packages/opencode/test/installation/installation.test.ts47
-rw-r--r--packages/opencode/test/util/process.test.ts16
3 files changed, 97 insertions, 0 deletions
diff --git a/packages/opencode/test/file/ripgrep.test.ts b/packages/opencode/test/file/ripgrep.test.ts
index ac46f1131..e0d8e83d1 100644
--- a/packages/opencode/test/file/ripgrep.test.ts
+++ b/packages/opencode/test/file/ripgrep.test.ts
@@ -36,4 +36,38 @@ describe("file.ripgrep", () => {
expect(hasVisible).toBe(true)
expect(hasHidden).toBe(false)
})
+
+ test("search returns match metadata", async () => {
+ await using tmp = await tmpdir({
+ init: async (dir) => {
+ await Bun.write(path.join(dir, "match.ts"), "const value = 'needle'\n")
+ await Bun.write(path.join(dir, "other.ts"), "const value = 'other'\n")
+ },
+ })
+
+ const hits = await Ripgrep.search({
+ cwd: tmp.path,
+ pattern: "needle",
+ })
+
+ expect(hits.length).toBe(1)
+ expect(hits[0]?.path.text).toBe("match.ts")
+ expect(hits[0]?.line_number).toBe(1)
+ expect(hits[0]?.lines.text).toContain("needle")
+ })
+
+ test("search returns empty when nothing matches", async () => {
+ await using tmp = await tmpdir({
+ init: async (dir) => {
+ await Bun.write(path.join(dir, "match.ts"), "const value = 'other'\n")
+ },
+ })
+
+ const hits = await Ripgrep.search({
+ cwd: tmp.path,
+ pattern: "needle",
+ })
+
+ expect(hits).toEqual([])
+ })
})
diff --git a/packages/opencode/test/installation/installation.test.ts b/packages/opencode/test/installation/installation.test.ts
new file mode 100644
index 000000000..a7cfe50d9
--- /dev/null
+++ b/packages/opencode/test/installation/installation.test.ts
@@ -0,0 +1,47 @@
+import { afterEach, describe, expect, test } from "bun:test"
+import { Installation } from "../../src/installation"
+
+const fetch0 = globalThis.fetch
+
+afterEach(() => {
+ globalThis.fetch = fetch0
+})
+
+describe("installation", () => {
+ test("reads release version from GitHub releases", async () => {
+ globalThis.fetch = (async () =>
+ new Response(JSON.stringify({ tag_name: "v1.2.3" }), {
+ status: 200,
+ headers: { "content-type": "application/json" },
+ })) as unknown as typeof fetch
+
+ expect(await Installation.latest("unknown")).toBe("1.2.3")
+ })
+
+ test("reads scoop manifest versions", async () => {
+ globalThis.fetch = (async () =>
+ new Response(JSON.stringify({ version: "2.3.4" }), {
+ status: 200,
+ headers: { "content-type": "application/json" },
+ })) as unknown as typeof fetch
+
+ expect(await Installation.latest("scoop")).toBe("2.3.4")
+ })
+
+ test("reads chocolatey feed versions", async () => {
+ globalThis.fetch = (async () =>
+ new Response(
+ JSON.stringify({
+ d: {
+ results: [{ Version: "3.4.5" }],
+ },
+ }),
+ {
+ status: 200,
+ headers: { "content-type": "application/json" },
+ },
+ )) as unknown as typeof fetch
+
+ expect(await Installation.latest("choco")).toBe("3.4.5")
+ })
+})
diff --git a/packages/opencode/test/util/process.test.ts b/packages/opencode/test/util/process.test.ts
index ce599d6d8..3834c5be4 100644
--- a/packages/opencode/test/util/process.test.ts
+++ b/packages/opencode/test/util/process.test.ts
@@ -56,4 +56,20 @@ describe("util.process", () => {
expect(out.code).not.toBe(0)
expect(Date.now() - started).toBeLessThan(1000)
}, 3000)
+
+ test("uses cwd when spawning commands", async () => {
+ const out = await Process.run(node('process.stdout.write(process.cwd())'), {
+ cwd: "/tmp",
+ })
+ expect(out.stdout.toString()).toBe("/tmp")
+ })
+
+ test("merges environment overrides", async () => {
+ const out = await Process.run(node('process.stdout.write(process.env.OPENCODE_TEST ?? "")'), {
+ env: {
+ OPENCODE_TEST: "set",
+ },
+ })
+ expect(out.stdout.toString()).toBe("set")
+ })
})