mirror of
https://github.com/anomalyco/opencode.git
synced 2026-09-06 12:24:33 +00:00
42 lines
2 KiB
TypeScript
42 lines
2 KiB
TypeScript
import path from "path"
|
|
import { describe, expect, test } from "bun:test"
|
|
import type { ConfigDiscovery } from "@opencode-ai/core/config/discovery"
|
|
import { ConfigWatch } from "@opencode-ai/core/config/watch"
|
|
import { AbsolutePath } from "@opencode-ai/core/schema"
|
|
|
|
const project = path.resolve("watch-plan-project")
|
|
const root = AbsolutePath.make(path.join(project, ".opencode"))
|
|
const sources: ConfigDiscovery.Sources = {
|
|
direct: ["opencode.json", "opencode.jsonc"].map((name) => AbsolutePath.make(path.join(project, name))),
|
|
project: [{ path: root, present: false }],
|
|
claude: [AbsolutePath.make(path.join(project, ".claude"))],
|
|
agents: [AbsolutePath.make(path.join(project, ".agents"))],
|
|
}
|
|
|
|
describe("ConfigWatch.plan", () => {
|
|
test("groups missing candidates and keeps parent watches when roots appear", () => {
|
|
const missing = ConfigWatch.plan(sources)
|
|
expect(Array.from(missing.values())).toEqual([
|
|
{ path: project, type: "entries", names: [".agents", ".claude", ".opencode", "opencode.json", "opencode.jsonc"] },
|
|
])
|
|
const present = ConfigWatch.plan({ ...sources, project: [{ path: root, present: true }] })
|
|
expect(Array.from(present.values())).toEqual([
|
|
{ path: root, type: "directory", ignore: ["node_modules", ".git", "**/{node_modules,.git}/**"] },
|
|
...missing.values(),
|
|
])
|
|
})
|
|
|
|
test("adds exact watches for explicit files only when not already covered", () => {
|
|
expect(ConfigWatch.plan({ ...sources, explicit: sources.direct[0] })).toEqual(ConfigWatch.plan(sources))
|
|
const present = { ...sources, project: [{ path: root, present: true }] }
|
|
expect(ConfigWatch.plan({ ...present, explicit: AbsolutePath.make(path.join(root, "custom.json")) })).toEqual(
|
|
ConfigWatch.plan(present),
|
|
)
|
|
const directory = path.resolve("watch-plan-external")
|
|
expect(
|
|
Array.from(
|
|
ConfigWatch.plan({ ...sources, explicit: AbsolutePath.make(path.join(directory, "custom.json")) }).values(),
|
|
),
|
|
).toContainEqual({ path: directory, type: "entries", names: ["custom.json"] })
|
|
})
|
|
})
|