chore: generate
This commit is contained in:
@@ -102,22 +102,22 @@ describe("tool.lsp", () => {
|
||||
"keeps cursor details for position-based operations",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const dir = (yield* TestInstance).directory
|
||||
const file = path.join(dir, "test.ts")
|
||||
yield* put(file)
|
||||
const dir = (yield* TestInstance).directory
|
||||
const file = path.join(dir, "test.ts")
|
||||
yield* put(file)
|
||||
|
||||
const { items, next } = asks()
|
||||
const result = yield* run({ operation: "goToDefinition", filePath: file, line: 3, character: 7 }, next)
|
||||
const req = items.find((item) => item.permission === "lsp")
|
||||
const { items, next } = asks()
|
||||
const result = yield* run({ operation: "goToDefinition", filePath: file, line: 3, character: 7 }, next)
|
||||
const req = items.find((item) => item.permission === "lsp")
|
||||
|
||||
expect(req).toBeDefined()
|
||||
expect(req!.metadata).toEqual({
|
||||
operation: "goToDefinition",
|
||||
filePath: file,
|
||||
line: 3,
|
||||
character: 7,
|
||||
})
|
||||
expect(result.title).toBe("goToDefinition test.ts:3:7")
|
||||
expect(req).toBeDefined()
|
||||
expect(req!.metadata).toEqual({
|
||||
operation: "goToDefinition",
|
||||
filePath: file,
|
||||
line: 3,
|
||||
character: 7,
|
||||
})
|
||||
expect(result.title).toBe("goToDefinition test.ts:3:7")
|
||||
}),
|
||||
{ git: true },
|
||||
)
|
||||
@@ -126,20 +126,20 @@ describe("tool.lsp", () => {
|
||||
"omits cursor details for documentSymbol",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const dir = (yield* TestInstance).directory
|
||||
const file = path.join(dir, "test.ts")
|
||||
yield* put(file)
|
||||
const dir = (yield* TestInstance).directory
|
||||
const file = path.join(dir, "test.ts")
|
||||
yield* put(file)
|
||||
|
||||
const { items, next } = asks()
|
||||
const result = yield* run({ operation: "documentSymbol", filePath: file, line: 3, character: 7 }, next)
|
||||
const req = items.find((item) => item.permission === "lsp")
|
||||
const { items, next } = asks()
|
||||
const result = yield* run({ operation: "documentSymbol", filePath: file, line: 3, character: 7 }, next)
|
||||
const req = items.find((item) => item.permission === "lsp")
|
||||
|
||||
expect(req).toBeDefined()
|
||||
expect(req!.metadata).toEqual({
|
||||
operation: "documentSymbol",
|
||||
filePath: file,
|
||||
})
|
||||
expect(result.title).toBe("documentSymbol test.ts")
|
||||
expect(req).toBeDefined()
|
||||
expect(req!.metadata).toEqual({
|
||||
operation: "documentSymbol",
|
||||
filePath: file,
|
||||
})
|
||||
expect(result.title).toBe("documentSymbol test.ts")
|
||||
}),
|
||||
{ git: true },
|
||||
)
|
||||
@@ -148,20 +148,20 @@ describe("tool.lsp", () => {
|
||||
"omits file and cursor details for workspaceSymbol",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const dir = (yield* TestInstance).directory
|
||||
workspaceSymbolQueries.length = 0
|
||||
const file = path.join(dir, "test.ts")
|
||||
yield* put(file)
|
||||
const dir = (yield* TestInstance).directory
|
||||
workspaceSymbolQueries.length = 0
|
||||
const file = path.join(dir, "test.ts")
|
||||
yield* put(file)
|
||||
|
||||
const { items, next } = asks()
|
||||
const result = yield* run({ operation: "workspaceSymbol", filePath: file, line: 3, character: 7 }, next)
|
||||
const req = items.find((item) => item.permission === "lsp")
|
||||
const { items, next } = asks()
|
||||
const result = yield* run({ operation: "workspaceSymbol", filePath: file, line: 3, character: 7 }, next)
|
||||
const req = items.find((item) => item.permission === "lsp")
|
||||
|
||||
expect(req).toBeDefined()
|
||||
expect(req!.metadata).toEqual({
|
||||
operation: "workspaceSymbol",
|
||||
})
|
||||
expect(result.title).toBe("workspaceSymbol")
|
||||
expect(req).toBeDefined()
|
||||
expect(req!.metadata).toEqual({
|
||||
operation: "workspaceSymbol",
|
||||
})
|
||||
expect(result.title).toBe("workspaceSymbol")
|
||||
}),
|
||||
{ git: true },
|
||||
)
|
||||
@@ -170,15 +170,15 @@ describe("tool.lsp", () => {
|
||||
"passes workspaceSymbol query to LSP",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const dir = (yield* TestInstance).directory
|
||||
workspaceSymbolQueries.length = 0
|
||||
const file = path.join(dir, "test.ts")
|
||||
yield* put(file)
|
||||
const dir = (yield* TestInstance).directory
|
||||
workspaceSymbolQueries.length = 0
|
||||
const file = path.join(dir, "test.ts")
|
||||
yield* put(file)
|
||||
|
||||
yield* run({ operation: "workspaceSymbol", filePath: file, line: 3, character: 7, query: "TestSymbol" })
|
||||
yield* run({ operation: "workspaceSymbol", filePath: file, line: 3, character: 7 })
|
||||
yield* run({ operation: "workspaceSymbol", filePath: file, line: 3, character: 7, query: "TestSymbol" })
|
||||
yield* run({ operation: "workspaceSymbol", filePath: file, line: 3, character: 7 })
|
||||
|
||||
expect(workspaceSymbolQueries).toEqual(["TestSymbol", ""])
|
||||
expect(workspaceSymbolQueries).toEqual(["TestSymbol", ""])
|
||||
}),
|
||||
{ git: true },
|
||||
)
|
||||
|
||||
@@ -15,7 +15,13 @@ import { ReadTool } from "../../src/tool/read"
|
||||
import { Truncate } from "@/tool/truncate"
|
||||
import { Tool } from "@/tool/tool"
|
||||
import { Filesystem } from "@/util/filesystem"
|
||||
import { disposeAllInstances, provideInstance, testInstanceStoreLayer, TestInstance, tmpdirScoped } from "../fixture/fixture"
|
||||
import {
|
||||
disposeAllInstances,
|
||||
provideInstance,
|
||||
testInstanceStoreLayer,
|
||||
TestInstance,
|
||||
tmpdirScoped,
|
||||
} from "../fixture/fixture"
|
||||
import { testEffect } from "../lib/effect"
|
||||
import { Reference } from "@/reference/reference"
|
||||
import { RepositoryCache } from "@/reference/repository-cache"
|
||||
|
||||
@@ -82,153 +82,153 @@ const githubBase = <A, E, R>(url: string, self: Effect.Effect<A, E, R>) =>
|
||||
describe("tool.repo_clone", () => {
|
||||
it.instance("clones a repo into the managed cache and reuses it on subsequent calls", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const source = yield* tmpdirScoped({ git: true })
|
||||
const remoteRoot = yield* tmpdirScoped()
|
||||
const remoteDir = path.join(remoteRoot, "owner")
|
||||
const remoteRepo = path.join(remoteDir, "repo.git")
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const source = yield* tmpdirScoped({ git: true })
|
||||
const remoteRoot = yield* tmpdirScoped()
|
||||
const remoteDir = path.join(remoteRoot, "owner")
|
||||
const remoteRepo = path.join(remoteDir, "repo.git")
|
||||
|
||||
yield* Effect.promise(() => Bun.write(path.join(source, "README.md"), "v1\n"))
|
||||
yield* git(source, ["add", "."])
|
||||
yield* git(source, ["commit", "-m", "add readme"])
|
||||
yield* fs.makeDirectory(remoteDir, { recursive: true }).pipe(Effect.orDie)
|
||||
yield* git(remoteRoot, ["clone", "--bare", source, remoteRepo])
|
||||
yield* Effect.promise(() => Bun.write(path.join(source, "README.md"), "v1\n"))
|
||||
yield* git(source, ["add", "."])
|
||||
yield* git(source, ["commit", "-m", "add readme"])
|
||||
yield* fs.makeDirectory(remoteDir, { recursive: true }).pipe(Effect.orDie)
|
||||
yield* git(remoteRoot, ["clone", "--bare", source, remoteRepo])
|
||||
|
||||
const tool = yield* init()
|
||||
const cloned = yield* githubBase(`file://${remoteRoot}/`, tool.execute({ repository: "owner/repo" }, ctx))
|
||||
const cached = yield* githubBase(
|
||||
`file://${remoteRoot}/`,
|
||||
tool.execute({ repository: "https://github.com/owner/repo.git" }, ctx),
|
||||
)
|
||||
const tool = yield* init()
|
||||
const cloned = yield* githubBase(`file://${remoteRoot}/`, tool.execute({ repository: "owner/repo" }, ctx))
|
||||
const cached = yield* githubBase(
|
||||
`file://${remoteRoot}/`,
|
||||
tool.execute({ repository: "https://github.com/owner/repo.git" }, ctx),
|
||||
)
|
||||
|
||||
expect(cloned.metadata.status).toBe("cloned")
|
||||
expect(cloned.metadata.localPath).toBe(path.join(Global.Path.repos, "github.com", "owner", "repo"))
|
||||
expect(cached.metadata.status).toBe("cached")
|
||||
expect(yield* fs.readFileString(path.join(cloned.metadata.localPath, "README.md"))).toBe("v1\n")
|
||||
expect(cloned.metadata.status).toBe("cloned")
|
||||
expect(cloned.metadata.localPath).toBe(path.join(Global.Path.repos, "github.com", "owner", "repo"))
|
||||
expect(cached.metadata.status).toBe("cached")
|
||||
expect(yield* fs.readFileString(path.join(cloned.metadata.localPath, "README.md"))).toBe("v1\n")
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("refresh updates an existing cached clone", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const source = yield* tmpdirScoped({ git: true })
|
||||
const remoteRoot = yield* tmpdirScoped()
|
||||
const remoteDir = path.join(remoteRoot, "owner")
|
||||
const remoteRepo = path.join(remoteDir, "repo.git")
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const source = yield* tmpdirScoped({ git: true })
|
||||
const remoteRoot = yield* tmpdirScoped()
|
||||
const remoteDir = path.join(remoteRoot, "owner")
|
||||
const remoteRepo = path.join(remoteDir, "repo.git")
|
||||
|
||||
yield* Effect.promise(() => Bun.write(path.join(source, "README.md"), "v1\n"))
|
||||
yield* git(source, ["add", "."])
|
||||
yield* git(source, ["commit", "-m", "add readme"])
|
||||
yield* fs.makeDirectory(remoteDir, { recursive: true }).pipe(Effect.orDie)
|
||||
yield* git(remoteRoot, ["clone", "--bare", source, remoteRepo])
|
||||
yield* Effect.promise(() => Bun.write(path.join(source, "README.md"), "v1\n"))
|
||||
yield* git(source, ["add", "."])
|
||||
yield* git(source, ["commit", "-m", "add readme"])
|
||||
yield* fs.makeDirectory(remoteDir, { recursive: true }).pipe(Effect.orDie)
|
||||
yield* git(remoteRoot, ["clone", "--bare", source, remoteRepo])
|
||||
|
||||
const branch = yield* git(source, ["branch", "--show-current"])
|
||||
yield* git(source, ["remote", "add", "origin", remoteRepo])
|
||||
yield* git(source, ["push", "-u", "origin", `${branch}:${branch}`])
|
||||
const branch = yield* git(source, ["branch", "--show-current"])
|
||||
yield* git(source, ["remote", "add", "origin", remoteRepo])
|
||||
yield* git(source, ["push", "-u", "origin", `${branch}:${branch}`])
|
||||
|
||||
const tool = yield* init()
|
||||
const first = yield* githubBase(`file://${remoteRoot}/`, tool.execute({ repository: "owner/repo" }, ctx))
|
||||
const tool = yield* init()
|
||||
const first = yield* githubBase(`file://${remoteRoot}/`, tool.execute({ repository: "owner/repo" }, ctx))
|
||||
|
||||
yield* Effect.promise(() => Bun.write(path.join(source, "README.md"), "v2\n"))
|
||||
yield* git(source, ["add", "."])
|
||||
yield* git(source, ["commit", "-m", "update readme"])
|
||||
yield* git(source, ["push", "origin", `${branch}:${branch}`])
|
||||
yield* Effect.promise(() => Bun.write(path.join(source, "README.md"), "v2\n"))
|
||||
yield* git(source, ["add", "."])
|
||||
yield* git(source, ["commit", "-m", "update readme"])
|
||||
yield* git(source, ["push", "origin", `${branch}:${branch}`])
|
||||
|
||||
const refreshed = yield* githubBase(
|
||||
`file://${remoteRoot}/`,
|
||||
tool.execute({ repository: "owner/repo", refresh: true }, ctx),
|
||||
)
|
||||
const refreshed = yield* githubBase(
|
||||
`file://${remoteRoot}/`,
|
||||
tool.execute({ repository: "owner/repo", refresh: true }, ctx),
|
||||
)
|
||||
|
||||
expect(first.metadata.status).toBe("cloned")
|
||||
expect(refreshed.metadata.status).toBe("refreshed")
|
||||
expect(yield* fs.readFileString(path.join(first.metadata.localPath, "README.md"))).toBe("v2\n")
|
||||
expect(first.metadata.status).toBe("cloned")
|
||||
expect(refreshed.metadata.status).toBe("refreshed")
|
||||
expect(yield* fs.readFileString(path.join(first.metadata.localPath, "README.md"))).toBe("v2\n")
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("clones a configured branch", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const source = yield* tmpdirScoped({ git: true })
|
||||
const remoteRoot = yield* tmpdirScoped()
|
||||
const remoteDir = path.join(remoteRoot, "owner")
|
||||
const remoteRepo = path.join(remoteDir, "repo.git")
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const source = yield* tmpdirScoped({ git: true })
|
||||
const remoteRoot = yield* tmpdirScoped()
|
||||
const remoteDir = path.join(remoteRoot, "owner")
|
||||
const remoteRepo = path.join(remoteDir, "repo.git")
|
||||
|
||||
yield* Effect.promise(() => Bun.write(path.join(source, "README.md"), "main\n"))
|
||||
yield* git(source, ["add", "."])
|
||||
yield* git(source, ["commit", "-m", "add readme"])
|
||||
yield* git(source, ["checkout", "-b", "docs"])
|
||||
yield* Effect.promise(() => Bun.write(path.join(source, "DOCS.md"), "docs\n"))
|
||||
yield* git(source, ["add", "."])
|
||||
yield* git(source, ["commit", "-m", "add docs"])
|
||||
yield* fs.makeDirectory(remoteDir, { recursive: true }).pipe(Effect.orDie)
|
||||
yield* git(remoteRoot, ["clone", "--bare", source, remoteRepo])
|
||||
yield* Effect.promise(() => Bun.write(path.join(source, "README.md"), "main\n"))
|
||||
yield* git(source, ["add", "."])
|
||||
yield* git(source, ["commit", "-m", "add readme"])
|
||||
yield* git(source, ["checkout", "-b", "docs"])
|
||||
yield* Effect.promise(() => Bun.write(path.join(source, "DOCS.md"), "docs\n"))
|
||||
yield* git(source, ["add", "."])
|
||||
yield* git(source, ["commit", "-m", "add docs"])
|
||||
yield* fs.makeDirectory(remoteDir, { recursive: true }).pipe(Effect.orDie)
|
||||
yield* git(remoteRoot, ["clone", "--bare", source, remoteRepo])
|
||||
|
||||
const tool = yield* init()
|
||||
const result = yield* githubBase(
|
||||
`file://${remoteRoot}/`,
|
||||
tool.execute({ repository: "owner/repo", branch: "docs" }, ctx),
|
||||
)
|
||||
const tool = yield* init()
|
||||
const result = yield* githubBase(
|
||||
`file://${remoteRoot}/`,
|
||||
tool.execute({ repository: "owner/repo", branch: "docs" }, ctx),
|
||||
)
|
||||
|
||||
expect(result.metadata.status).toBe("cloned")
|
||||
expect(result.metadata.branch).toBe("docs")
|
||||
expect(yield* fs.readFileString(path.join(result.metadata.localPath, "DOCS.md"))).toBe("docs\n")
|
||||
expect(result.metadata.status).toBe("cloned")
|
||||
expect(result.metadata.branch).toBe("docs")
|
||||
expect(yield* fs.readFileString(path.join(result.metadata.localPath, "DOCS.md"))).toBe("docs\n")
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("rejects invalid repository inputs", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = (yield* TestInstance).directory
|
||||
const tool = yield* init()
|
||||
const inputs = [
|
||||
{ repository: "not-a-repo", message: "git URL" },
|
||||
{ repository: "git@github.com:../../../etc/passwd", message: "git URL" },
|
||||
{ repository: "-u:foo/bar", message: "git URL" },
|
||||
{ repository: pathToFileURL(path.join(dir, "local.git")).href, message: "Local file" },
|
||||
]
|
||||
const dir = (yield* TestInstance).directory
|
||||
const tool = yield* init()
|
||||
const inputs = [
|
||||
{ repository: "not-a-repo", message: "git URL" },
|
||||
{ repository: "git@github.com:../../../etc/passwd", message: "git URL" },
|
||||
{ repository: "-u:foo/bar", message: "git URL" },
|
||||
{ repository: pathToFileURL(path.join(dir, "local.git")).href, message: "Local file" },
|
||||
]
|
||||
|
||||
yield* Effect.forEach(
|
||||
inputs,
|
||||
(input) =>
|
||||
Effect.gen(function* () {
|
||||
const result = yield* tool.execute({ repository: input.repository }, ctx).pipe(Effect.exit)
|
||||
yield* Effect.forEach(
|
||||
inputs,
|
||||
(input) =>
|
||||
Effect.gen(function* () {
|
||||
const result = yield* tool.execute({ repository: input.repository }, ctx).pipe(Effect.exit)
|
||||
|
||||
expect(Exit.isFailure(result)).toBe(true)
|
||||
if (Exit.isFailure(result)) {
|
||||
const error = Cause.squash(result.cause)
|
||||
expect(error instanceof Error ? error.message : String(error)).toContain(input.message)
|
||||
}
|
||||
}),
|
||||
{ discard: true },
|
||||
)
|
||||
expect(Exit.isFailure(result)).toBe(true)
|
||||
if (Exit.isFailure(result)) {
|
||||
const error = Cause.squash(result.cause)
|
||||
expect(error instanceof Error ? error.message : String(error)).toContain(input.message)
|
||||
}
|
||||
}),
|
||||
{ discard: true },
|
||||
)
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("rejects local file repository URLs", () =>
|
||||
Effect.gen(function* () {
|
||||
const source = yield* tmpdirScoped({ git: true })
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ repository: pathToFileURL(source).href }, ctx).pipe(Effect.exit)
|
||||
const source = yield* tmpdirScoped({ git: true })
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ repository: pathToFileURL(source).href }, ctx).pipe(Effect.exit)
|
||||
|
||||
expect(Exit.isFailure(result)).toBe(true)
|
||||
if (Exit.isFailure(result)) {
|
||||
const error = Cause.squash(result.cause)
|
||||
expect(error instanceof Error ? error.message : String(error)).toContain("Local file")
|
||||
}
|
||||
expect(Exit.isFailure(result)).toBe(true)
|
||||
if (Exit.isFailure(result)) {
|
||||
const error = Cause.squash(result.cause)
|
||||
expect(error instanceof Error ? error.message : String(error)).toContain("Local file")
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("rejects invalid branch inputs", () =>
|
||||
Effect.gen(function* () {
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ repository: "owner/repo", branch: "bad..branch" }, ctx).pipe(Effect.exit)
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ repository: "owner/repo", branch: "bad..branch" }, ctx).pipe(Effect.exit)
|
||||
|
||||
expect(Exit.isFailure(result)).toBe(true)
|
||||
if (Exit.isFailure(result)) {
|
||||
const error = Cause.squash(result.cause)
|
||||
expect(error instanceof Error ? error.message : String(error)).toContain(
|
||||
"Branch must contain only alphanumeric characters",
|
||||
)
|
||||
}
|
||||
expect(Exit.isFailure(result)).toBe(true)
|
||||
if (Exit.isFailure(result)) {
|
||||
const error = Cause.squash(result.cause)
|
||||
expect(error instanceof Error ? error.message : String(error)).toContain(
|
||||
"Branch must contain only alphanumeric characters",
|
||||
)
|
||||
}
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -45,112 +45,112 @@ const init = Effect.fn("RepoOverviewToolTest.init")(function* () {
|
||||
describe("tool.repo_overview", () => {
|
||||
it.instance("summarizes a local repository path", () =>
|
||||
Effect.gen(function* () {
|
||||
const repo = yield* tmpdirScoped({ git: true })
|
||||
const fs = yield* AppFileSystem.Service
|
||||
yield* fs.writeWithDirs(
|
||||
path.join(repo, "package.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
name: "example-repo",
|
||||
main: "dist/index.js",
|
||||
module: "dist/index.mjs",
|
||||
types: "dist/index.d.ts",
|
||||
exports: {
|
||||
".": "./dist/index.js",
|
||||
"./server": "./dist/server.js",
|
||||
},
|
||||
bin: {
|
||||
example: "./bin/example.js",
|
||||
},
|
||||
const repo = yield* tmpdirScoped({ git: true })
|
||||
const fs = yield* AppFileSystem.Service
|
||||
yield* fs.writeWithDirs(
|
||||
path.join(repo, "package.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
name: "example-repo",
|
||||
main: "dist/index.js",
|
||||
module: "dist/index.mjs",
|
||||
types: "dist/index.d.ts",
|
||||
exports: {
|
||||
".": "./dist/index.js",
|
||||
"./server": "./dist/server.js",
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
)
|
||||
yield* fs.writeWithDirs(path.join(repo, "bun.lock"), "")
|
||||
yield* fs.writeWithDirs(path.join(repo, "README.md"), "# Example\n")
|
||||
yield* fs.writeWithDirs(path.join(repo, "src", "index.ts"), "export const value = 1\n")
|
||||
bin: {
|
||||
example: "./bin/example.js",
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
)
|
||||
yield* fs.writeWithDirs(path.join(repo, "bun.lock"), "")
|
||||
yield* fs.writeWithDirs(path.join(repo, "README.md"), "# Example\n")
|
||||
yield* fs.writeWithDirs(path.join(repo, "src", "index.ts"), "export const value = 1\n")
|
||||
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ path: repo }, ctx)
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ path: repo }, ctx)
|
||||
|
||||
expect(result.metadata.path).toBe(repo)
|
||||
expect(result.metadata.ecosystems).toContain("Node.js")
|
||||
expect(result.metadata.package_manager).toBe("bun")
|
||||
expect(result.metadata.dependency_files).toEqual(expect.arrayContaining(["package.json", "bun.lock"]))
|
||||
expect(result.metadata.entrypoints).toEqual(
|
||||
expect.arrayContaining([
|
||||
"main: dist/index.js",
|
||||
"module: dist/index.mjs",
|
||||
"types: dist/index.d.ts",
|
||||
"exports: .",
|
||||
"exports: ./server",
|
||||
"bin: example",
|
||||
"file: src/index.ts",
|
||||
]),
|
||||
)
|
||||
expect(result.output).toContain("Top-level structure:")
|
||||
expect(result.output).toContain("src/")
|
||||
expect(result.output).toContain("README.md")
|
||||
expect(result.metadata.path).toBe(repo)
|
||||
expect(result.metadata.ecosystems).toContain("Node.js")
|
||||
expect(result.metadata.package_manager).toBe("bun")
|
||||
expect(result.metadata.dependency_files).toEqual(expect.arrayContaining(["package.json", "bun.lock"]))
|
||||
expect(result.metadata.entrypoints).toEqual(
|
||||
expect.arrayContaining([
|
||||
"main: dist/index.js",
|
||||
"module: dist/index.mjs",
|
||||
"types: dist/index.d.ts",
|
||||
"exports: .",
|
||||
"exports: ./server",
|
||||
"bin: example",
|
||||
"file: src/index.ts",
|
||||
]),
|
||||
)
|
||||
expect(result.output).toContain("Top-level structure:")
|
||||
expect(result.output).toContain("src/")
|
||||
expect(result.output).toContain("README.md")
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("resolves relative paths from the instance directory", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = (yield* TestInstance).directory
|
||||
const fs = yield* AppFileSystem.Service
|
||||
yield* fs.writeWithDirs(path.join(dir, "nested", "README.md"), "# Nested\n")
|
||||
const dir = (yield* TestInstance).directory
|
||||
const fs = yield* AppFileSystem.Service
|
||||
yield* fs.writeWithDirs(path.join(dir, "nested", "README.md"), "# Nested\n")
|
||||
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ path: "nested" }, ctx)
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ path: "nested" }, ctx)
|
||||
|
||||
expect(result.metadata.path).toBe(path.join(dir, "nested"))
|
||||
expect(result.output).toContain("README.md")
|
||||
expect(result.metadata.path).toBe(path.join(dir, "nested"))
|
||||
expect(result.output).toContain("README.md")
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("resolves a cached repository from repository shorthand", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const cached = path.join(Global.Path.repos, "github.com", "owner", "repo")
|
||||
yield* fs.writeWithDirs(path.join(cached, "package.json"), JSON.stringify({ name: "cached-repo" }, null, 2))
|
||||
yield* fs.writeWithDirs(path.join(cached, "README.md"), "cached\n")
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const cached = path.join(Global.Path.repos, "github.com", "owner", "repo")
|
||||
yield* fs.writeWithDirs(path.join(cached, "package.json"), JSON.stringify({ name: "cached-repo" }, null, 2))
|
||||
yield* fs.writeWithDirs(path.join(cached, "README.md"), "cached\n")
|
||||
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ repository: "owner/repo" }, ctx)
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ repository: "owner/repo" }, ctx)
|
||||
|
||||
expect(result.metadata.path).toBe(cached)
|
||||
expect(result.metadata.repository).toBe("owner/repo")
|
||||
expect(result.output).toContain("Repository: owner/repo")
|
||||
expect(result.output).toContain(`Path: ${cached}`)
|
||||
expect(result.metadata.path).toBe(cached)
|
||||
expect(result.metadata.repository).toBe("owner/repo")
|
||||
expect(result.output).toContain("Repository: owner/repo")
|
||||
expect(result.output).toContain(`Path: ${cached}`)
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("fails clearly when a repository is not cloned", () =>
|
||||
Effect.gen(function* () {
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ repository: "missing/repo" }, ctx).pipe(Effect.exit)
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ repository: "missing/repo" }, ctx).pipe(Effect.exit)
|
||||
|
||||
expect(Exit.isFailure(result)).toBe(true)
|
||||
if (Exit.isFailure(result)) {
|
||||
const error = Cause.squash(result.cause)
|
||||
expect(error instanceof Error ? error.message : String(error)).toContain("Use repo_clone first")
|
||||
}
|
||||
expect(Exit.isFailure(result)).toBe(true)
|
||||
if (Exit.isFailure(result)) {
|
||||
const error = Cause.squash(result.cause)
|
||||
expect(error instanceof Error ? error.message : String(error)).toContain("Use repo_clone first")
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("resolves cached repositories from host/path references", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const cached = path.join(Global.Path.repos, "gitlab.com", "group", "repo")
|
||||
yield* fs.writeWithDirs(path.join(cached, "README.md"), "cached\n")
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const cached = path.join(Global.Path.repos, "gitlab.com", "group", "repo")
|
||||
yield* fs.writeWithDirs(path.join(cached, "README.md"), "cached\n")
|
||||
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ repository: "gitlab.com/group/repo" }, ctx)
|
||||
const tool = yield* init()
|
||||
const result = yield* tool.execute({ repository: "gitlab.com/group/repo" }, ctx)
|
||||
|
||||
expect(result.metadata.path).toBe(cached)
|
||||
expect(result.metadata.repository).toBe("gitlab.com/group/repo")
|
||||
expect(result.output).toContain("Repository: gitlab.com/group/repo")
|
||||
expect(result.metadata.path).toBe(cached)
|
||||
expect(result.metadata.repository).toBe("gitlab.com/group/repo")
|
||||
expect(result.output).toContain("Repository: gitlab.com/group/repo")
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -32,12 +32,12 @@ const it = testEffect(Layer.mergeAll(ToolRegistry.defaultLayer, node))
|
||||
describe("tool.skill", () => {
|
||||
it.instance("execute returns skill content block with files", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = (yield* TestInstance).directory
|
||||
const skill = path.join(dir, ".opencode", "skill", "tool-skill")
|
||||
yield* Effect.promise(() =>
|
||||
Bun.write(
|
||||
path.join(skill, "SKILL.md"),
|
||||
`---
|
||||
const dir = (yield* TestInstance).directory
|
||||
const skill = path.join(dir, ".opencode", "skill", "tool-skill")
|
||||
yield* Effect.promise(() =>
|
||||
Bun.write(
|
||||
path.join(skill, "SKILL.md"),
|
||||
`---
|
||||
name: tool-skill
|
||||
description: Skill for tool tests.
|
||||
---
|
||||
@@ -46,86 +46,86 @@ description: Skill for tool tests.
|
||||
|
||||
Use this skill.
|
||||
`,
|
||||
),
|
||||
)
|
||||
yield* Effect.promise(() => Bun.write(path.join(skill, "scripts", "demo.txt"), "demo"))
|
||||
),
|
||||
)
|
||||
yield* Effect.promise(() => Bun.write(path.join(skill, "scripts", "demo.txt"), "demo"))
|
||||
|
||||
const home = process.env.OPENCODE_TEST_HOME
|
||||
process.env.OPENCODE_TEST_HOME = dir
|
||||
yield* Effect.addFinalizer(() =>
|
||||
const home = process.env.OPENCODE_TEST_HOME
|
||||
process.env.OPENCODE_TEST_HOME = dir
|
||||
yield* Effect.addFinalizer(() =>
|
||||
Effect.sync(() => {
|
||||
process.env.OPENCODE_TEST_HOME = home
|
||||
}),
|
||||
)
|
||||
|
||||
const registry = yield* ToolRegistry.Service
|
||||
const agent = { name: "build", mode: "primary" as const, permission: [], options: {} }
|
||||
const tool = (yield* registry.tools({
|
||||
providerID: "opencode" as any,
|
||||
modelID: "gpt-5" as any,
|
||||
agent,
|
||||
})).find((tool) => tool.id === SkillTool.id)
|
||||
if (!tool) throw new Error("Skill tool not found")
|
||||
|
||||
const requests: Array<Omit<Permission.Request, "id" | "sessionID" | "tool">> = []
|
||||
const ctx: Tool.Context = {
|
||||
...baseCtx,
|
||||
ask: (req) =>
|
||||
Effect.sync(() => {
|
||||
process.env.OPENCODE_TEST_HOME = home
|
||||
requests.push(req)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
const registry = yield* ToolRegistry.Service
|
||||
const agent = { name: "build", mode: "primary" as const, permission: [], options: {} }
|
||||
const tool = (yield* registry.tools({
|
||||
providerID: "opencode" as any,
|
||||
modelID: "gpt-5" as any,
|
||||
agent,
|
||||
})).find((tool) => tool.id === SkillTool.id)
|
||||
if (!tool) throw new Error("Skill tool not found")
|
||||
const result = yield* tool.execute({ name: "tool-skill" }, ctx)
|
||||
const file = path.resolve(skill, "scripts", "demo.txt")
|
||||
|
||||
const requests: Array<Omit<Permission.Request, "id" | "sessionID" | "tool">> = []
|
||||
const ctx: Tool.Context = {
|
||||
...baseCtx,
|
||||
ask: (req) =>
|
||||
Effect.sync(() => {
|
||||
requests.push(req)
|
||||
}),
|
||||
}
|
||||
|
||||
const result = yield* tool.execute({ name: "tool-skill" }, ctx)
|
||||
const file = path.resolve(skill, "scripts", "demo.txt")
|
||||
|
||||
expect(requests.length).toBe(1)
|
||||
expect(requests[0].permission).toBe("skill")
|
||||
expect(requests[0].patterns).toContain("tool-skill")
|
||||
expect(requests[0].always).toContain("tool-skill")
|
||||
expect(result.metadata.dir).toBe(skill)
|
||||
expect(result.output).toContain(`<skill_content name="tool-skill">`)
|
||||
expect(result.output).toContain(`Base directory for this skill: ${pathToFileURL(skill).href}`)
|
||||
expect(result.output).toContain(`<file>${file}</file>`)
|
||||
expect(requests.length).toBe(1)
|
||||
expect(requests[0].permission).toBe("skill")
|
||||
expect(requests[0].patterns).toContain("tool-skill")
|
||||
expect(requests[0].always).toContain("tool-skill")
|
||||
expect(result.metadata.dir).toBe(skill)
|
||||
expect(result.output).toContain(`<skill_content name="tool-skill">`)
|
||||
expect(result.output).toContain(`Base directory for this skill: ${pathToFileURL(skill).href}`)
|
||||
expect(result.output).toContain(`<file>${file}</file>`)
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("execute preserves not found message", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = (yield* TestInstance).directory
|
||||
const home = process.env.OPENCODE_TEST_HOME
|
||||
process.env.OPENCODE_TEST_HOME = dir
|
||||
yield* Effect.addFinalizer(() =>
|
||||
Effect.sync(() => {
|
||||
process.env.OPENCODE_TEST_HOME = home
|
||||
}),
|
||||
const dir = (yield* TestInstance).directory
|
||||
const home = process.env.OPENCODE_TEST_HOME
|
||||
process.env.OPENCODE_TEST_HOME = dir
|
||||
yield* Effect.addFinalizer(() =>
|
||||
Effect.sync(() => {
|
||||
process.env.OPENCODE_TEST_HOME = home
|
||||
}),
|
||||
)
|
||||
|
||||
const registry = yield* ToolRegistry.Service
|
||||
const agent = { name: "build", mode: "primary" as const, permission: [], options: {} }
|
||||
const tool = (yield* registry.tools({
|
||||
providerID: "opencode" as any,
|
||||
modelID: "gpt-5" as any,
|
||||
agent,
|
||||
})).find((tool) => tool.id === SkillTool.id)
|
||||
if (!tool) throw new Error("Skill tool not found")
|
||||
|
||||
const exit = yield* tool
|
||||
.execute(
|
||||
{ name: "missing-skill" },
|
||||
{
|
||||
...baseCtx,
|
||||
ask: () => Effect.void,
|
||||
},
|
||||
)
|
||||
.pipe(Effect.exit)
|
||||
|
||||
const registry = yield* ToolRegistry.Service
|
||||
const agent = { name: "build", mode: "primary" as const, permission: [], options: {} }
|
||||
const tool = (yield* registry.tools({
|
||||
providerID: "opencode" as any,
|
||||
modelID: "gpt-5" as any,
|
||||
agent,
|
||||
})).find((tool) => tool.id === SkillTool.id)
|
||||
if (!tool) throw new Error("Skill tool not found")
|
||||
|
||||
const exit = yield* tool
|
||||
.execute(
|
||||
{ name: "missing-skill" },
|
||||
{
|
||||
...baseCtx,
|
||||
ask: () => Effect.void,
|
||||
},
|
||||
)
|
||||
.pipe(Effect.exit)
|
||||
|
||||
expect(Exit.isFailure(exit)).toBe(true)
|
||||
if (Exit.isFailure(exit)) {
|
||||
const error = Cause.squash(exit.cause)
|
||||
expect(error).toBeInstanceOf(Error)
|
||||
if (error instanceof Error) expect(error.message).toContain('Skill "missing-skill" not found.')
|
||||
}
|
||||
expect(Exit.isFailure(exit)).toBe(true)
|
||||
if (Exit.isFailure(exit)) {
|
||||
const error = Cause.squash(exit.cause)
|
||||
expect(error).toBeInstanceOf(Error)
|
||||
if (error instanceof Error) expect(error.message).toContain('Skill "missing-skill" not found.')
|
||||
}
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user