| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import { test, expect } from "bun:test"
- import path from "path"
- import { tmpdir } from "../fixture/fixture"
- import { Instance } from "../../src/project/instance"
- import { Config } from "../../src/config/config"
- import { Agent as AgentSvc } from "../../src/agent/agent"
- import { Color } from "../../src/util/color"
- test("agent color parsed from project config", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(
- path.join(dir, "opencode.json"),
- JSON.stringify({
- $schema: "https://opencode.ai/config.json",
- agent: {
- build: { color: "#FFA500" },
- plan: { color: "primary" },
- },
- }),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const cfg = await Config.get()
- expect(cfg.agent?.["build"]?.color).toBe("#FFA500")
- expect(cfg.agent?.["plan"]?.color).toBe("primary")
- },
- })
- })
- test("Agent.get includes color from config", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(
- path.join(dir, "opencode.json"),
- JSON.stringify({
- $schema: "https://opencode.ai/config.json",
- agent: {
- plan: { color: "#A855F7" },
- build: { color: "accent" },
- },
- }),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const plan = await AgentSvc.get("plan")
- expect(plan?.color).toBe("#A855F7")
- const build = await AgentSvc.get("build")
- expect(build?.color).toBe("accent")
- },
- })
- })
- test("Color.hexToAnsiBold converts valid hex to ANSI", () => {
- const result = Color.hexToAnsiBold("#FFA500")
- expect(result).toBe("\x1b[38;2;255;165;0m\x1b[1m")
- })
- test("Color.hexToAnsiBold returns undefined for invalid hex", () => {
- expect(Color.hexToAnsiBold(undefined)).toBeUndefined()
- expect(Color.hexToAnsiBold("")).toBeUndefined()
- expect(Color.hexToAnsiBold("#FFF")).toBeUndefined()
- expect(Color.hexToAnsiBold("FFA500")).toBeUndefined()
- expect(Color.hexToAnsiBold("#GGGGGG")).toBeUndefined()
- })
|