test(bash): migrate permission metadata tests to Effect runtime

Replace raw async/Promise-based test helpers with Effect-based
equivalents to align with the upstream BashTool API changes. Introduce
a ManagedRuntime composed of CrossSpawnSpawner, AppFileSystem, Plugin,
Truncate, and Agent layers. Update metadata, ask, and execute call
sites to return Effect values instead of plain promises.
This commit is contained in:
Imanol Maiztegui
2026-04-17 22:54:14 +02:00
parent 2ee8394cf1
commit 8bae4413fd
@@ -1,11 +1,27 @@
// regression test for bash permission metadata.command
import { describe, expect, test } from "bun:test"
import { Effect, Layer, ManagedRuntime } from "effect"
import { BashTool } from "../../src/tool/bash"
import { Instance } from "../../src/project/instance"
import { tmpdir } from "../fixture/fixture"
import { Shell } from "../../src/shell/shell"
import { SessionID, MessageID } from "../../src/session/schema"
import type { Permission } from "../../src/permission"
import { Agent } from "../../src/agent/agent"
import { Truncate } from "../../src/tool/truncate"
import * as CrossSpawnSpawner from "../../src/effect/cross-spawn-spawner"
import { AppFileSystem } from "../../src/filesystem"
import { Plugin } from "../../src/plugin"
const runtime = ManagedRuntime.make(
Layer.mergeAll(
CrossSpawnSpawner.defaultLayer,
AppFileSystem.defaultLayer,
Plugin.defaultLayer,
Truncate.defaultLayer,
Agent.defaultLayer,
),
)
Shell.acceptable.reset()
@@ -16,15 +32,16 @@ const baseCtx = {
agent: "code",
abort: AbortSignal.any([]),
messages: [],
metadata: () => {},
ask: async () => {},
metadata: () => Effect.void,
ask: () => Effect.void,
}
const capture = (requests: Array<Omit<Permission.Request, "id" | "sessionID" | "tool">>) => ({
...baseCtx,
ask: async (req: Omit<Permission.Request, "id" | "sessionID" | "tool">) => {
requests.push(req)
},
ask: (req: Omit<Permission.Request, "id" | "sessionID" | "tool">) =>
Effect.sync(() => {
requests.push(req)
}),
})
describe("bash permission metadata.command", () => {
@@ -33,10 +50,10 @@ describe("bash permission metadata.command", () => {
await Instance.provide({
directory: tmp.path,
fn: async () => {
const bash = await BashTool.init()
const bash = await runtime.runPromise(BashTool.pipe(Effect.flatMap((info) => info.init())))
const requests: Array<Omit<Permission.Request, "id" | "sessionID" | "tool">> = []
const command = "echo hello"
await bash.execute({ command, description: "Echo hello" }, capture(requests))
await Effect.runPromise(bash.execute({ command, description: "Echo hello" }, capture(requests)))
const bashReq = requests.find((r) => r.permission === "bash")
expect(bashReq).toBeDefined()