test: migrate agent color config tests (#27139)
This commit is contained in:
@@ -1,58 +1,50 @@
|
|||||||
import { test, expect } from "bun:test"
|
import { test, expect } from "bun:test"
|
||||||
import { Effect, Layer } from "effect"
|
import { Effect, Layer } from "effect"
|
||||||
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
||||||
import path from "path"
|
|
||||||
import { provideInstance, tmpdirScoped } from "../fixture/fixture"
|
|
||||||
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 { testEffect } from "../lib/effect"
|
import { testEffect } from "../lib/effect"
|
||||||
|
|
||||||
const it = testEffect(Layer.mergeAll(AgentSvc.defaultLayer, CrossSpawnSpawner.defaultLayer))
|
const it = testEffect(Layer.mergeAll(Config.defaultLayer, AgentSvc.defaultLayer, CrossSpawnSpawner.defaultLayer))
|
||||||
|
|
||||||
const writeConfig = (dir: string, agent: Config.Info["agent"]) =>
|
it.instance(
|
||||||
Effect.promise(() =>
|
"agent color parsed from project config",
|
||||||
Bun.write(
|
() =>
|
||||||
path.join(dir, "opencode.json"),
|
Effect.gen(function* () {
|
||||||
JSON.stringify({
|
const cfg = yield* Config.Service.use((svc) => svc.get())
|
||||||
$schema: "https://opencode.ai/config.json",
|
|
||||||
agent,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
it.live("agent color parsed from project config", () =>
|
|
||||||
Effect.gen(function* () {
|
|
||||||
const dir = yield* tmpdirScoped()
|
|
||||||
yield* writeConfig(dir, {
|
|
||||||
build: { color: "#FFA500" },
|
|
||||||
plan: { color: "primary" },
|
|
||||||
})
|
|
||||||
|
|
||||||
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))
|
}),
|
||||||
}),
|
{
|
||||||
|
git: true,
|
||||||
|
config: {
|
||||||
|
agent: {
|
||||||
|
build: { color: "#FFA500" },
|
||||||
|
plan: { color: "primary" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
it.live("Agent.get includes color from config", () =>
|
it.instance(
|
||||||
Effect.gen(function* () {
|
"Agent.get includes color from config",
|
||||||
const dir = yield* tmpdirScoped()
|
() =>
|
||||||
yield* writeConfig(dir, {
|
Effect.gen(function* () {
|
||||||
plan: { color: "#A855F7" },
|
|
||||||
build: { color: "accent" },
|
|
||||||
})
|
|
||||||
|
|
||||||
yield* Effect.gen(function* () {
|
|
||||||
const plan = yield* AgentSvc.Service.use((svc) => svc.get("plan"))
|
const plan = yield* AgentSvc.Service.use((svc) => svc.get("plan"))
|
||||||
expect(plan?.color).toBe("#A855F7")
|
expect(plan?.color).toBe("#A855F7")
|
||||||
const build = yield* AgentSvc.Service.use((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))
|
}),
|
||||||
}),
|
{
|
||||||
|
git: true,
|
||||||
|
config: {
|
||||||
|
agent: {
|
||||||
|
plan: { color: "#A855F7" },
|
||||||
|
build: { color: "accent" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
test("Color.hexToAnsiBold converts valid hex to ANSI", () => {
|
test("Color.hexToAnsiBold converts valid hex to ANSI", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user