config.test.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { describe, expect, test } from "bun:test"
  2. import { Schema } from "effect"
  3. import { Config } from "../src/config.js"
  4. import { AbsolutePath } from "../src/schema.js"
  5. describe("Config.Entry", () => {
  6. test("round-trips every configuration entry type", () => {
  7. const entries = [
  8. new Config.Document({
  9. type: "document",
  10. path: "/project/opencode.json",
  11. info: new Config.Info({
  12. permissions: [
  13. { action: "shell", resource: "*", effect: "ask" },
  14. { action: "shell", resource: "git status", effect: "allow" },
  15. ],
  16. }),
  17. }),
  18. new Config.Document({ type: "document", info: new Config.Info({ shell: "/bin/zsh" }) }),
  19. new Config.Directory({ type: "directory", path: AbsolutePath.make("/project/.opencode") }),
  20. new Config.File({ type: "file", path: AbsolutePath.make("/project/opencode.json") }),
  21. new Config.AgentsDirectory({ type: "agents", path: AbsolutePath.make("/project/.agents") }),
  22. new Config.ClaudeDirectory({ type: "claude", path: AbsolutePath.make("/project/.claude") }),
  23. ]
  24. const encoded = Schema.encodeSync(Schema.Array(Config.Entry))(entries)
  25. const decoded = Schema.decodeUnknownSync(Schema.Array(Config.Entry))(encoded)
  26. expect(decoded).toEqual(entries)
  27. expect(decoded[0]).toBeInstanceOf(Config.Document)
  28. expect(decoded[1]).not.toHaveProperty("path")
  29. expect(decoded.map((entry) => entry.type)).toEqual(["document", "document", "directory", "file", "agents", "claude"])
  30. expect(decoded[0]?.type === "document" ? decoded[0].info.permissions : undefined).toEqual([
  31. { action: "shell", resource: "*", effect: "ask" },
  32. { action: "shell", resource: "git status", effect: "allow" },
  33. ])
  34. })
  35. test("has a stable public identifier", () => {
  36. expect(Config.Entry.ast.annotations?.identifier).toBe("Config.Entry")
  37. })
  38. })