mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-21 10:16:03 +00:00
40 lines
1.7 KiB
TypeScript
40 lines
1.7 KiB
TypeScript
import { describe, expect } from "bun:test"
|
|
import fs from "fs/promises"
|
|
import path from "path"
|
|
import { Effect } from "effect"
|
|
import { Ripgrep } from "@opencode-ai/core/ripgrep"
|
|
import { RelativePath } from "@opencode-ai/core/schema"
|
|
import { tmpdir } from "./fixture/tmpdir"
|
|
import { testEffect } from "./lib/effect"
|
|
|
|
const it = testEffect(Ripgrep.defaultLayer)
|
|
|
|
describe("Ripgrep", () => {
|
|
it.live("allows caller globs to re-include git metadata", () =>
|
|
Effect.acquireUseRelease(
|
|
Effect.promise(() => tmpdir()),
|
|
(tmp) =>
|
|
Effect.gen(function* () {
|
|
yield* Effect.promise(() => fs.mkdir(path.join(tmp.path, ".opencode")))
|
|
yield* Effect.promise(() => fs.writeFile(path.join(tmp.path, ".opencode", "config"), "needle\n"))
|
|
yield* Effect.promise(() => fs.mkdir(path.join(tmp.path, ".git")))
|
|
yield* Effect.promise(() => fs.writeFile(path.join(tmp.path, ".git", "config"), "needle\n"))
|
|
const ripgrep = yield* Ripgrep.Service
|
|
|
|
const files = yield* ripgrep.find({ cwd: tmp.path, pattern: "**/*", limit: 10 })
|
|
expect(files.map((item) => item.path)).toContain(RelativePath.make(".opencode/config"))
|
|
expect(files.map((item) => item.path)).toContain(RelativePath.make(".git/config"))
|
|
|
|
const matches = yield* ripgrep.grep({ cwd: tmp.path, pattern: "needle", include: "config", limit: 10 })
|
|
expect(matches.map((item) => item.entry.path)).toContain(
|
|
RelativePath.make(".opencode/config"),
|
|
)
|
|
expect(matches.map((item) => item.entry.path)).toContain(
|
|
RelativePath.make(".git/config"),
|
|
)
|
|
}),
|
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
|
),
|
|
)
|
|
})
|