refactor(core): simplify search root protocol (#31060)

This commit is contained in:
Kit Langton
2026-06-06 03:20:06 +00:00
committed by GitHub
parent 4ac4df448a
commit 09d9cf01f9
8 changed files with 18 additions and 89 deletions
+1 -9
View File
@@ -22,7 +22,6 @@ import { testEffect } from "./lib/effect"
const assertions: PermissionV2.AssertInput[] = []
const searches: LocationSearch.GrepInput[] = []
const roots: FileSystem.RootTarget[] = []
let allow = true
let result = new LocationSearch.GrepResult({ items: [], truncated: false, partial: false })
let searchFailure: Ripgrep.InvalidPatternError | undefined
@@ -37,17 +36,13 @@ const filesystem = Layer.succeed(
resolveRoot: (input = {}) =>
Effect.succeed(
new FileSystem.RootTarget({
absolute: `/project/${input.path ?? "."}`,
real: `/project/${input.path ?? "."}`,
directory: "/project",
root: "/project",
resource: input.reference === undefined ? (input.path ?? ".") : `${input.reference}:${input.path ?? "."}`,
reference: input.reference,
type: "directory",
dev: 1,
}),
),
revalidateRoot: Effect.succeed,
resolveList: () => Effect.die("unused"),
listResolved: () => Effect.die("unused"),
listPage: () => Effect.die("unused"),
@@ -61,10 +56,9 @@ const search = Layer.succeed(
LocationSearch.Service,
LocationSearch.Service.of({
files: () => Effect.die("unused"),
grep: (input, root) =>
grep: (input) =>
Effect.sync(() => {
searches.push(input)
if (root) roots.push(root)
if (searchFailure) throw searchFailure
return result
}),
@@ -107,7 +101,6 @@ const settle = (input: Record<string, unknown>) =>
const reset = () => {
assertions.length = 0
searches.length = 0
roots.length = 0
allow = true
searchFailure = undefined
result = new LocationSearch.GrepResult({ items: [], truncated: false, partial: false })
@@ -172,7 +165,6 @@ describe("GrepTool", () => {
},
])
expect(searches).toEqual([{ pattern: "needle", path: RelativePath.make("src"), include: "*.ts", limit: 2 }])
expect(roots).toMatchObject([{ resource: "src" }])
}),
)