test(opencode): replace bun writes in fff tests

This commit is contained in:
Shoubhit Dash
2026-03-25 04:59:50 +05:30
parent f977cbe2b8
commit 00ce0a7ab7
3 changed files with 31 additions and 15 deletions

View File

@@ -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")
},
})

View File

@@ -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")
},
})

View File

@@ -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({