opencode/packages/core/test/config/watch.test.ts
Aiden Cline 49e9786bb7
fix(core): bound skill discovery and watches (#55597)
Co-authored-by: Dante <duanjl.china@gmail.com>
Co-authored-by: Kugesh Rajasekaran <47845948+kugesh-Rajasekaran@users.noreply.github.com>
2026-10-17 22:33:39 -05:00

53 lines
2.4 KiB
TypeScript

import path from "path"
import { describe, expect, test } from "bun:test"
import type { ConfigDiscovery } from "@opencode/core/config/discovery"
import { ConfigWatch } from "@opencode/core/config/watch"
import { AbsolutePath } from "@opencode/core/schema"
import { FSUtil } from "@opencode/util/fs-util"
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 system = AbsolutePath.make(path.join(project, "system-opencode"))
const present = ConfigWatch.plan({
...sources,
system: { path: system, present: true },
project: [{ path: root, present: true }],
})
expect(Array.from(present.values())).toEqual([
{ path: system, type: "directory", ignore: FSUtil.ignoreGlobs },
{ path: root, type: "directory", ignore: FSUtil.ignoreGlobs },
{
path: project,
type: "entries",
names: [".agents", ".claude", ".opencode", "opencode.json", "opencode.jsonc", "system-opencode"],
},
])
})
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"] })
})
})