test: use Effect test helper for agent colors (#25051)
This commit is contained in:
@@ -1,67 +1,59 @@
|
|||||||
import { test, expect } from "bun:test"
|
import { test, expect } from "bun:test"
|
||||||
import { Effect } from "effect"
|
import { Effect, Layer } from "effect"
|
||||||
|
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { provideInstance, tmpdir } from "../fixture/fixture"
|
import { provideInstance, tmpdirScoped } from "../fixture/fixture"
|
||||||
import { Instance } from "../../src/project/instance"
|
|
||||||
import { Config } from "@/config/config"
|
import { Config } from "@/config/config"
|
||||||
import { Agent as AgentSvc } from "../../src/agent/agent"
|
import { Agent as AgentSvc } from "../../src/agent/agent"
|
||||||
import { Color } from "@/util/color"
|
import { Color } from "@/util/color"
|
||||||
import { AppRuntime } from "../../src/effect/app-runtime"
|
import { AppRuntime } from "../../src/effect/app-runtime"
|
||||||
|
import { testEffect } from "../lib/effect"
|
||||||
|
|
||||||
const load = () => AppRuntime.runPromise(Config.Service.use((svc) => svc.get()))
|
const it = testEffect(Layer.mergeAll(AgentSvc.defaultLayer, CrossSpawnSpawner.defaultLayer))
|
||||||
const agent = <A>(dir: string, fn: (svc: AgentSvc.Interface) => Effect.Effect<A>) =>
|
|
||||||
Effect.runPromise(provideInstance(dir)(AgentSvc.Service.use(fn)).pipe(Effect.provide(AgentSvc.defaultLayer)))
|
|
||||||
|
|
||||||
test("agent color parsed from project config", async () => {
|
const writeConfig = (dir: string, agent: Config.Info["agent"]) =>
|
||||||
await using tmp = await tmpdir({
|
Effect.promise(() =>
|
||||||
init: async (dir) => {
|
Bun.write(
|
||||||
await Bun.write(
|
path.join(dir, "opencode.json"),
|
||||||
path.join(dir, "opencode.json"),
|
JSON.stringify({
|
||||||
JSON.stringify({
|
$schema: "https://opencode.ai/config.json",
|
||||||
$schema: "https://opencode.ai/config.json",
|
agent,
|
||||||
agent: {
|
}),
|
||||||
build: { color: "#FFA500" },
|
),
|
||||||
plan: { color: "primary" },
|
)
|
||||||
},
|
|
||||||
}),
|
it.live("agent color parsed from project config", () =>
|
||||||
)
|
Effect.gen(function* () {
|
||||||
},
|
const dir = yield* tmpdirScoped()
|
||||||
})
|
yield* writeConfig(dir, {
|
||||||
await Instance.provide({
|
build: { color: "#FFA500" },
|
||||||
directory: tmp.path,
|
plan: { color: "primary" },
|
||||||
fn: async () => {
|
})
|
||||||
const cfg = await load()
|
|
||||||
|
yield* Effect.gen(function* () {
|
||||||
|
const cfg = yield* Effect.promise(() => AppRuntime.runPromise(Config.Service.use((svc) => svc.get())))
|
||||||
expect(cfg.agent?.["build"]?.color).toBe("#FFA500")
|
expect(cfg.agent?.["build"]?.color).toBe("#FFA500")
|
||||||
expect(cfg.agent?.["plan"]?.color).toBe("primary")
|
expect(cfg.agent?.["plan"]?.color).toBe("primary")
|
||||||
},
|
}).pipe(provideInstance(dir))
|
||||||
})
|
}),
|
||||||
})
|
)
|
||||||
|
|
||||||
test("Agent.get includes color from config", async () => {
|
it.live("Agent.get includes color from config", () =>
|
||||||
await using tmp = await tmpdir({
|
Effect.gen(function* () {
|
||||||
init: async (dir) => {
|
const dir = yield* tmpdirScoped()
|
||||||
await Bun.write(
|
yield* writeConfig(dir, {
|
||||||
path.join(dir, "opencode.json"),
|
plan: { color: "#A855F7" },
|
||||||
JSON.stringify({
|
build: { color: "accent" },
|
||||||
$schema: "https://opencode.ai/config.json",
|
})
|
||||||
agent: {
|
|
||||||
plan: { color: "#A855F7" },
|
yield* Effect.gen(function* () {
|
||||||
build: { color: "accent" },
|
const plan = yield* AgentSvc.Service.use((svc) => svc.get("plan"))
|
||||||
},
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
await Instance.provide({
|
|
||||||
directory: tmp.path,
|
|
||||||
fn: async () => {
|
|
||||||
const plan = await agent(tmp.path, (svc) => svc.get("plan"))
|
|
||||||
expect(plan?.color).toBe("#A855F7")
|
expect(plan?.color).toBe("#A855F7")
|
||||||
const build = await agent(tmp.path, (svc) => svc.get("build"))
|
const build = yield* AgentSvc.Service.use((svc) => svc.get("build"))
|
||||||
expect(build?.color).toBe("accent")
|
expect(build?.color).toBe("accent")
|
||||||
},
|
}).pipe(provideInstance(dir))
|
||||||
})
|
}),
|
||||||
})
|
)
|
||||||
|
|
||||||
test("Color.hexToAnsiBold converts valid hex to ANSI", () => {
|
test("Color.hexToAnsiBold converts valid hex to ANSI", () => {
|
||||||
const result = Color.hexToAnsiBold("#FFA500")
|
const result = Color.hexToAnsiBold("#FFA500")
|
||||||
|
|||||||
Reference in New Issue
Block a user