Skip to content

Commit ed00ae2

Browse files
authored
Use instance test helper in glob tests (#25445)
1 parent eebb26a commit ed00ae2

1 file changed

Lines changed: 38 additions & 40 deletions

File tree

packages/opencode/test/tool/glob.test.ts

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Ripgrep } from "../../src/file/ripgrep"
88
import { AppFileSystem } from "@opencode-ai/core/filesystem"
99
import { Truncate } from "@/tool/truncate"
1010
import { Agent } from "../../src/agent/agent"
11-
import { provideTmpdirInstance } from "../fixture/fixture"
11+
import { TestInstance } from "../fixture/fixture"
1212
import { testEffect } from "../lib/effect"
1313

1414
const it = testEffect(
@@ -33,49 +33,47 @@ const ctx = {
3333
}
3434

3535
describe("tool.glob", () => {
36-
it.live("matches files from a directory path", () =>
37-
provideTmpdirInstance((dir) =>
38-
Effect.gen(function* () {
39-
yield* Effect.promise(() => Bun.write(path.join(dir, "a.ts"), "export const a = 1\n"))
40-
yield* Effect.promise(() => Bun.write(path.join(dir, "b.txt"), "hello\n"))
41-
const info = yield* GlobTool
42-
const glob = yield* info.init()
43-
const result = yield* glob.execute(
36+
it.instance("matches files from a directory path", () =>
37+
Effect.gen(function* () {
38+
const test = yield* TestInstance
39+
yield* Effect.promise(() => Bun.write(path.join(test.directory, "a.ts"), "export const a = 1\n"))
40+
yield* Effect.promise(() => Bun.write(path.join(test.directory, "b.txt"), "hello\n"))
41+
const info = yield* GlobTool
42+
const glob = yield* info.init()
43+
const result = yield* glob.execute(
44+
{
45+
pattern: "*.ts",
46+
path: test.directory,
47+
},
48+
ctx,
49+
)
50+
expect(result.metadata.count).toBe(1)
51+
expect(result.output).toContain(path.join(test.directory, "a.ts"))
52+
expect(result.output).not.toContain(path.join(test.directory, "b.txt"))
53+
}),
54+
)
55+
56+
it.instance("rejects exact file paths", () =>
57+
Effect.gen(function* () {
58+
const test = yield* TestInstance
59+
const file = path.join(test.directory, "a.ts")
60+
yield* Effect.promise(() => Bun.write(file, "export const a = 1\n"))
61+
const info = yield* GlobTool
62+
const glob = yield* info.init()
63+
const exit = yield* glob
64+
.execute(
4465
{
4566
pattern: "*.ts",
46-
path: dir,
67+
path: file,
4768
},
4869
ctx,
4970
)
50-
expect(result.metadata.count).toBe(1)
51-
expect(result.output).toContain(path.join(dir, "a.ts"))
52-
expect(result.output).not.toContain(path.join(dir, "b.txt"))
53-
}),
54-
),
55-
)
56-
57-
it.live("rejects exact file paths", () =>
58-
provideTmpdirInstance((dir) =>
59-
Effect.gen(function* () {
60-
const file = path.join(dir, "a.ts")
61-
yield* Effect.promise(() => Bun.write(file, "export const a = 1\n"))
62-
const info = yield* GlobTool
63-
const glob = yield* info.init()
64-
const exit = yield* glob
65-
.execute(
66-
{
67-
pattern: "*.ts",
68-
path: file,
69-
},
70-
ctx,
71-
)
72-
.pipe(Effect.exit)
73-
expect(Exit.isFailure(exit)).toBe(true)
74-
if (Exit.isFailure(exit)) {
75-
const err = Cause.squash(exit.cause)
76-
expect(err instanceof Error ? err.message : String(err)).toContain("glob path must be a directory")
77-
}
78-
}),
79-
),
71+
.pipe(Effect.exit)
72+
expect(Exit.isFailure(exit)).toBe(true)
73+
if (Exit.isFailure(exit)) {
74+
const err = Cause.squash(exit.cause)
75+
expect(err instanceof Error ? err.message : String(err)).toContain("glob path must be a directory")
76+
}
77+
}),
8078
)
8179
})

0 commit comments

Comments
 (0)