import { describe, expect, test } from "bun:test" import { Schema } from "effect" import { Config } from "../src/config.js" import { AbsolutePath } from "../src/schema.js" describe("Config.Entry", () => { test("round-trips every configuration entry type", () => { const entries = [ new Config.Document({ type: "document", path: "/project/opencode.json", info: new Config.Info({ permissions: [ { action: "shell", resource: "*", effect: "ask" }, { action: "shell", resource: "git status", effect: "allow" }, ], }), }), new Config.Document({ type: "document", info: new Config.Info({ shell: "/bin/zsh" }) }), new Config.Directory({ type: "directory", path: AbsolutePath.make("/project/.opencode") }), new Config.File({ type: "file", path: AbsolutePath.make("/project/opencode.json") }), new Config.AgentsDirectory({ type: "agents", path: AbsolutePath.make("/project/.agents") }), new Config.ClaudeDirectory({ type: "claude", path: AbsolutePath.make("/project/.claude") }), ] const encoded = Schema.encodeSync(Schema.Array(Config.Entry))(entries) const decoded = Schema.decodeUnknownSync(Schema.Array(Config.Entry))(encoded) expect(decoded).toEqual(entries) expect(decoded[0]).toBeInstanceOf(Config.Document) expect(decoded[1]).not.toHaveProperty("path") expect(decoded.map((entry) => entry.type)).toEqual(["document", "document", "directory", "file", "agents", "claude"]) expect(decoded[0]?.type === "document" ? decoded[0].info.permissions : undefined).toEqual([ { action: "shell", resource: "*", effect: "ask" }, { action: "shell", resource: "git status", effect: "allow" }, ]) }) test("has a stable public identifier", () => { expect(Config.Entry.ast.annotations?.identifier).toBe("Config.Entry") }) })