diff --git a/packages/opencode/test/file/fff.test.ts b/packages/opencode/test/file/fff.test.ts index c067ef57d0..33e4727b29 100644 --- a/packages/opencode/test/file/fff.test.ts +++ b/packages/opencode/test/file/fff.test.ts @@ -5,6 +5,11 @@ import { tmpdir } from "../fixture/fixture" import { Instance } from "../../src/project/instance" import { Fff } from "../../src/file/fff" +async function write(file: string, body: string) { + await fs.mkdir(path.dirname(file), { recursive: true }) + await fs.writeFile(file, body) +} + describe("file.fff", () => { test("allowed respects hidden filter", async () => { expect(Fff.allowed({ rel: "visible.txt", hidden: true })).toBe(true) @@ -15,7 +20,7 @@ describe("file.fff", () => { 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") + await write(path.join(dir, "match.ts"), "const value = 'other'\n") }, }) @@ -35,8 +40,8 @@ describe("file.fff", () => { await using tmp = await tmpdir({ init: async (dir) => { await fs.mkdir(path.join(dir, "a", "b"), { recursive: true }) - await Bun.write(path.join(dir, "a", "b", "c.ts"), "export const x = 1\n") - await Bun.write(path.join(dir, "a", "d.ts"), "export const y = 1\n") + await write(path.join(dir, "a", "b", "c.ts"), "export const x = 1\n") + await write(path.join(dir, "a", "d.ts"), "export const y = 1\n") }, }) diff --git a/packages/opencode/test/tool/glob.test.ts b/packages/opencode/test/tool/glob.test.ts index e2c95adea0..08ed37bfb6 100644 --- a/packages/opencode/test/tool/glob.test.ts +++ b/packages/opencode/test/tool/glob.test.ts @@ -1,10 +1,16 @@ import { describe, expect, test } from "bun:test" +import fs from "fs/promises" import path from "path" import { GlobTool } from "../../src/tool/glob" import { Instance } from "../../src/project/instance" import { tmpdir } from "../fixture/fixture" import { SessionID, MessageID } from "../../src/session/schema" +async function write(file: string, body: string) { + await fs.mkdir(path.dirname(file), { recursive: true }) + await fs.writeFile(file, body) +} + const ctx = { sessionID: SessionID.make("ses_test"), messageID: MessageID.make(""), @@ -20,9 +26,9 @@ describe("tool.glob", () => { test("finds files by glob pattern", async () => { await using tmp = await tmpdir({ init: async (dir) => { - await Bun.write(path.join(dir, "src", "foo.ts"), "export const foo = 1\n") - await Bun.write(path.join(dir, "src", "bar.ts"), "export const bar = 1\n") - await Bun.write(path.join(dir, "src", "baz.js"), "export const baz = 1\n") + await write(path.join(dir, "src", "foo.ts"), "export const foo = 1\n") + await write(path.join(dir, "src", "bar.ts"), "export const bar = 1\n") + await write(path.join(dir, "src", "baz.js"), "export const baz = 1\n") }, }) @@ -48,7 +54,7 @@ describe("tool.glob", () => { test("returns no files found for unmatched patterns", async () => { await using tmp = await tmpdir({ init: async (dir) => { - await Bun.write(path.join(dir, "src", "foo.ts"), "export const foo = 1\n") + await write(path.join(dir, "src", "foo.ts"), "export const foo = 1\n") }, }) @@ -73,9 +79,9 @@ describe("tool.glob", () => { test("falls back for brace glob patterns", async () => { await using tmp = await tmpdir({ init: async (dir) => { - await Bun.write(path.join(dir, "src", "foo.ts"), "export const foo = 1\n") - await Bun.write(path.join(dir, "src", "bar.js"), "export const bar = 1\n") - await Bun.write(path.join(dir, "src", "baz.py"), "print('baz')\n") + await write(path.join(dir, "src", "foo.ts"), "export const foo = 1\n") + await write(path.join(dir, "src", "bar.js"), "export const bar = 1\n") + await write(path.join(dir, "src", "baz.py"), "print('baz')\n") }, }) diff --git a/packages/opencode/test/tool/grep.test.ts b/packages/opencode/test/tool/grep.test.ts index 6c06eab7b2..289013f77d 100644 --- a/packages/opencode/test/tool/grep.test.ts +++ b/packages/opencode/test/tool/grep.test.ts @@ -1,10 +1,16 @@ import { describe, expect, test } from "bun:test" +import fs from "fs/promises" import path from "path" import { GrepTool } from "../../src/tool/grep" import { Instance } from "../../src/project/instance" import { tmpdir } from "../fixture/fixture" import { SessionID, MessageID } from "../../src/session/schema" +async function write(file: string, body: string) { + await fs.mkdir(path.dirname(file), { recursive: true }) + await fs.writeFile(file, body) +} + const ctx = { sessionID: SessionID.make("ses_test"), messageID: MessageID.make(""), @@ -41,7 +47,7 @@ describe("tool.grep", () => { test("no matches returns correct output", async () => { await using tmp = await tmpdir({ init: async (dir) => { - await Bun.write(path.join(dir, "test.txt"), "hello world") + await write(path.join(dir, "test.txt"), "hello world") }, }) await Instance.provide({ @@ -65,8 +71,7 @@ describe("tool.grep", () => { // This test verifies the regex split handles both \n and \r\n await using tmp = await tmpdir({ init: async (dir) => { - // Create a test file with content - await Bun.write(path.join(dir, "test.txt"), "line1\nline2\nline3") + await write(path.join(dir, "test.txt"), "line1\nline2\nline3") }, }) await Instance.provide({ @@ -88,7 +93,7 @@ describe("tool.grep", () => { test("broadens multi-word query when exact has no match", async () => { await using tmp = await tmpdir({ init: async (dir) => { - await Bun.write(path.join(dir, "test.txt"), "upload completed\n") + await write(path.join(dir, "test.txt"), "upload completed\n") }, }) await Instance.provide({ @@ -111,7 +116,7 @@ describe("tool.grep", () => { test("suggests path when content has no match", async () => { await using tmp = await tmpdir({ init: async (dir) => { - await Bun.write(path.join(dir, "src", "server", "auth.ts"), "export const token = 1\n") + await write(path.join(dir, "src", "server", "auth.ts"), "export const token = 1\n") }, }) await Instance.provide({