refactor(core): consolidate references (#31539)

This commit is contained in:
Dax
2026-06-09 12:08:58 -04:00
committed by GitHub
parent 75d469d17d
commit ec87cf82cb
65 changed files with 687 additions and 2730 deletions
-48
View File
@@ -25,8 +25,6 @@ import {
tmpdirScoped,
} from "../fixture/fixture"
import { testEffect } from "../lib/effect"
import { Reference } from "@/reference/reference"
import { RepositoryCache } from "@/reference/repository-cache"
const FIXTURES_DIR = path.join(import.meta.dir, "fixtures")
@@ -45,13 +43,6 @@ const ctx = {
ask: () => Effect.void,
}
const referenceLayer = (flags: Partial<RuntimeFlags.Info> = {}) =>
Reference.layer.pipe(
Layer.provide(Config.defaultLayer),
Layer.provide(RepositoryCache.defaultLayer),
Layer.provide(RuntimeFlags.layer(flags)),
)
const readLayer = (flags: Partial<RuntimeFlags.Info> = {}) =>
Layer.mergeAll(
Agent.defaultLayer,
@@ -59,13 +50,11 @@ const readLayer = (flags: Partial<RuntimeFlags.Info> = {}) =>
CrossSpawnSpawner.defaultLayer,
Instruction.defaultLayer,
LSP.defaultLayer,
referenceLayer(flags),
Search.defaultLayer,
Truncate.defaultLayer,
)
const it = testEffect(Layer.mergeAll(readLayer(), testInstanceStoreLayer))
const references = testEffect(Layer.mergeAll(readLayer({ experimentalReferences: true }), testInstanceStoreLayer))
const init = Effect.fn("ReadToolTest.init")(function* () {
const info = yield* ReadTool
@@ -266,43 +255,6 @@ describe("tool.read external_directory permission", () => {
}),
)
references.live("does not ask for external_directory permission when reading configured references", () =>
Effect.gen(function* () {
const fs = yield* FSUtil.Service
const cache = path.join(Global.Path.repos, "github.com", "opencode-read-reference", "repo")
yield* fs.remove(cache, { recursive: true }).pipe(Effect.ignore)
yield* Effect.addFinalizer(() => fs.remove(cache, { recursive: true }).pipe(Effect.ignore))
const source = yield* tmpdirScoped({ git: true })
const remoteRoot = yield* tmpdirScoped()
const remoteDir = path.join(remoteRoot, "opencode-read-reference")
const remoteRepo = path.join(remoteDir, "repo.git")
yield* put(path.join(source, "notes.md"), "reference notes")
yield* git(source, ["add", "."])
yield* git(source, ["commit", "-m", "add notes"])
yield* fs.makeDirectory(remoteDir, { recursive: true }).pipe(Effect.orDie)
yield* git(remoteRoot, ["clone", "--bare", source, remoteRepo])
const dir = yield* tmpdirScoped({
git: true,
config: {
reference: {
docs: "opencode-read-reference/repo",
},
},
})
const { items, next } = asks()
const result = yield* githubBase(
`file://${remoteRoot}/`,
exec(dir, { filePath: path.join(cache, "notes.md") }, next),
)
const ext = items.find((item) => item.permission === "external_directory")
expect(result.output).toContain("reference notes")
expect(ext).toBeUndefined()
}),
)
})
describe("tool.read env file permissions", () => {