| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806 |
- import { afterEach, beforeEach, expect, test } from "bun:test"
- import path from "path"
- import fs from "fs/promises"
- import { tmpdir } from "../fixture/fixture"
- import { Instance } from "../../src/project/instance"
- import { Config } from "../../src/config/config"
- import { TuiConfig } from "../../src/config/tui"
- import { Global } from "../../src/global"
- import { Filesystem } from "../../src/util/filesystem"
- const managedConfigDir = process.env.KILO_TEST_MANAGED_CONFIG_DIR!
- const wintest = process.platform === "win32" ? test : test.skip
- beforeEach(async () => {
- await Config.invalidate(true)
- })
- afterEach(async () => {
- delete process.env.KILO_CONFIG
- delete process.env.KILO_TUI_CONFIG
- // kilocode_change start
- await fs.rm(path.join(Global.Path.config, "kilo.json"), { force: true }).catch(() => {})
- await fs.rm(path.join(Global.Path.config, "kilo.jsonc"), { force: true }).catch(() => {})
- // kilocode_change end
- await fs.rm(path.join(Global.Path.config, "tui.json"), { force: true }).catch(() => {})
- await fs.rm(path.join(Global.Path.config, "tui.jsonc"), { force: true }).catch(() => {})
- await fs.rm(managedConfigDir, { force: true, recursive: true }).catch(() => {})
- await Config.invalidate(true)
- })
- test("keeps server and tui plugin merge semantics aligned", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- const local = path.join(dir, ".kilo") // kilocode_change
- await fs.mkdir(local, { recursive: true })
- await Bun.write(
- path.join(Global.Path.config, "kilo.json"), // kilocode_change
- JSON.stringify(
- {
- plugin: [["[email protected]", { source: "global" }], "[email protected]"],
- },
- null,
- 2,
- ),
- )
- await Bun.write(
- path.join(Global.Path.config, "tui.json"),
- JSON.stringify(
- {
- plugin: [["[email protected]", { source: "global" }], "[email protected]"],
- },
- null,
- 2,
- ),
- )
- await Bun.write(
- path.join(local, "kilo.json"), // kilocode_change
- JSON.stringify(
- {
- plugin: [["[email protected]", { source: "local" }], "[email protected]"],
- },
- null,
- 2,
- ),
- )
- await Bun.write(
- path.join(local, "tui.json"),
- JSON.stringify(
- {
- plugin: [["[email protected]", { source: "local" }], "[email protected]"],
- },
- null,
- 2,
- ),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const server = await Config.get()
- const tui = await TuiConfig.get()
- const serverPlugins = (server.plugin ?? []).map((item) => Config.pluginSpecifier(item))
- const tuiPlugins = (tui.plugin ?? []).map((item) => Config.pluginSpecifier(item))
- expect(serverPlugins).toEqual(tuiPlugins)
- expect(serverPlugins).toContain("[email protected]")
- expect(serverPlugins).not.toContain("[email protected]")
- const serverOrigins = server.plugin_origins ?? []
- const tuiOrigins = tui.plugin_origins ?? []
- expect(serverOrigins.map((item) => Config.pluginSpecifier(item.spec))).toEqual(serverPlugins)
- expect(tuiOrigins.map((item) => Config.pluginSpecifier(item.spec))).toEqual(tuiPlugins)
- expect(serverOrigins.map((item) => item.scope)).toEqual(tuiOrigins.map((item) => item.scope))
- },
- })
- })
- test("loads tui config with the same precedence order as server config paths", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(path.join(Global.Path.config, "tui.json"), JSON.stringify({ theme: "global" }, null, 2))
- await Bun.write(path.join(dir, "tui.json"), JSON.stringify({ theme: "project" }, null, 2))
- await fs.mkdir(path.join(dir, ".kilo"), { recursive: true }) // kilocode_change
- await Bun.write(
- path.join(dir, ".kilo", "tui.json"), // kilocode_change
- JSON.stringify({ theme: "local", diff_style: "stacked" }, null, 2),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.theme).toBe("local")
- expect(config.diff_style).toBe("stacked")
- },
- })
- })
- test("migrates tui-specific keys from kilo.json when tui.json does not exist", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(
- path.join(dir, "kilo.json"),
- JSON.stringify(
- {
- theme: "migrated-theme",
- tui: { scroll_speed: 5 },
- keybinds: { app_exit: "ctrl+q" },
- },
- null,
- 2,
- ),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.theme).toBe("migrated-theme")
- expect(config.scroll_speed).toBe(5)
- expect(config.keybinds?.app_exit).toBe("ctrl+q")
- const text = await Filesystem.readText(path.join(tmp.path, "tui.json"))
- expect(JSON.parse(text)).toMatchObject({
- theme: "migrated-theme",
- scroll_speed: 5,
- })
- const server = JSON.parse(await Filesystem.readText(path.join(tmp.path, "kilo.json")))
- expect(server.theme).toBeUndefined()
- expect(server.keybinds).toBeUndefined()
- expect(server.tui).toBeUndefined()
- expect(await Filesystem.exists(path.join(tmp.path, "kilo.json.tui-migration.bak"))).toBe(true)
- expect(await Filesystem.exists(path.join(tmp.path, "tui.json"))).toBe(true)
- },
- })
- })
- test("migrates project legacy tui keys even when global tui.json already exists", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(path.join(Global.Path.config, "tui.json"), JSON.stringify({ theme: "global" }, null, 2))
- await Bun.write(
- path.join(dir, "kilo.json"),
- JSON.stringify(
- {
- theme: "project-migrated",
- tui: { scroll_speed: 2 },
- },
- null,
- 2,
- ),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.theme).toBe("project-migrated")
- expect(config.scroll_speed).toBe(2)
- expect(await Filesystem.exists(path.join(tmp.path, "tui.json"))).toBe(true)
- const server = JSON.parse(await Filesystem.readText(path.join(tmp.path, "kilo.json")))
- expect(server.theme).toBeUndefined()
- expect(server.tui).toBeUndefined()
- },
- })
- })
- test("drops unknown legacy tui keys during migration", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(
- path.join(dir, "kilo.json"),
- JSON.stringify(
- {
- theme: "migrated-theme",
- tui: { scroll_speed: 2, foo: 1 },
- },
- null,
- 2,
- ),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.theme).toBe("migrated-theme")
- expect(config.scroll_speed).toBe(2)
- const text = await Filesystem.readText(path.join(tmp.path, "tui.json"))
- const migrated = JSON.parse(text)
- expect(migrated.scroll_speed).toBe(2)
- expect(migrated.foo).toBeUndefined()
- },
- })
- })
- test("skips migration when kilo.jsonc is syntactically invalid", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(
- path.join(dir, "kilo.jsonc"),
- `{
- "theme": "broken-theme",
- "tui": { "scroll_speed": 2 }
- "username": "still-broken"
- }`,
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.theme).toBeUndefined()
- expect(config.scroll_speed).toBeUndefined()
- expect(await Filesystem.exists(path.join(tmp.path, "tui.json"))).toBe(false)
- expect(await Filesystem.exists(path.join(tmp.path, "kilo.jsonc.tui-migration.bak"))).toBe(false)
- const source = await Filesystem.readText(path.join(tmp.path, "kilo.jsonc"))
- expect(source).toContain('"theme": "broken-theme"')
- expect(source).toContain('"tui": { "scroll_speed": 2 }')
- },
- })
- })
- test("skips migration when tui.json already exists", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(path.join(dir, "kilo.json"), JSON.stringify({ theme: "legacy" }, null, 2))
- await Bun.write(path.join(dir, "tui.json"), JSON.stringify({ diff_style: "stacked" }, null, 2))
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.diff_style).toBe("stacked")
- expect(config.theme).toBeUndefined()
- const server = JSON.parse(await Filesystem.readText(path.join(tmp.path, "kilo.json")))
- expect(server.theme).toBe("legacy")
- expect(await Filesystem.exists(path.join(tmp.path, "kilo.json.tui-migration.bak"))).toBe(false)
- },
- })
- })
- test("continues loading tui config when legacy source cannot be stripped", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(path.join(dir, "kilo.json"), JSON.stringify({ theme: "readonly-theme" }, null, 2))
- },
- })
- const source = path.join(tmp.path, "kilo.json")
- await fs.chmod(source, 0o444)
- try {
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.theme).toBe("readonly-theme")
- expect(await Filesystem.exists(path.join(tmp.path, "tui.json"))).toBe(true)
- const server = JSON.parse(await Filesystem.readText(source))
- expect(server.theme).toBe("readonly-theme")
- },
- })
- } finally {
- await fs.chmod(source, 0o644)
- }
- })
- test("migration backup preserves JSONC comments", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(
- path.join(dir, "kilo.jsonc"),
- `{
- // top-level comment
- "theme": "jsonc-theme",
- "tui": {
- // nested comment
- "scroll_speed": 1.5
- }
- }`,
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- await TuiConfig.get()
- const backup = await Filesystem.readText(path.join(tmp.path, "kilo.jsonc.tui-migration.bak"))
- expect(backup).toContain("// top-level comment")
- expect(backup).toContain("// nested comment")
- expect(backup).toContain('"theme": "jsonc-theme"')
- expect(backup).toContain('"scroll_speed": 1.5')
- },
- })
- })
- // kilocode_change start
- test("migrates legacy tui keys across multiple kilo.json levels", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- const nested = path.join(dir, "apps", "client")
- await fs.mkdir(nested, { recursive: true })
- await Bun.write(path.join(dir, "kilo.json"), JSON.stringify({ theme: "root-theme" }, null, 2))
- await Bun.write(path.join(nested, "kilo.json"), JSON.stringify({ theme: "nested-theme" }, null, 2))
- // kilocode_change end
- },
- })
- await Instance.provide({
- directory: path.join(tmp.path, "apps", "client"),
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.theme).toBe("nested-theme")
- expect(await Filesystem.exists(path.join(tmp.path, "tui.json"))).toBe(true)
- expect(await Filesystem.exists(path.join(tmp.path, "apps", "client", "tui.json"))).toBe(true)
- },
- })
- })
- test("flattens nested tui key inside tui.json", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(
- path.join(dir, "tui.json"),
- JSON.stringify({
- theme: "outer",
- tui: { scroll_speed: 3, diff_style: "stacked" },
- }),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.scroll_speed).toBe(3)
- expect(config.diff_style).toBe("stacked")
- // top-level keys take precedence over nested tui keys
- expect(config.theme).toBe("outer")
- },
- })
- })
- test("top-level keys in tui.json take precedence over nested tui key", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(
- path.join(dir, "tui.json"),
- JSON.stringify({
- diff_style: "auto",
- tui: { diff_style: "stacked", scroll_speed: 2 },
- }),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.diff_style).toBe("auto")
- expect(config.scroll_speed).toBe(2)
- },
- })
- })
- test("project config takes precedence over KILO_TUI_CONFIG (matches KILO_CONFIG)", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(path.join(dir, "tui.json"), JSON.stringify({ theme: "project", diff_style: "auto" }))
- const custom = path.join(dir, "custom-tui.json")
- await Bun.write(custom, JSON.stringify({ theme: "custom", diff_style: "stacked" }))
- process.env.KILO_TUI_CONFIG = custom
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- // project tui.json overrides the custom path, same as server config precedence
- expect(config.theme).toBe("project")
- // project also set diff_style, so that wins
- expect(config.diff_style).toBe("auto")
- },
- })
- })
- test("merges keybind overrides across precedence layers", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(path.join(Global.Path.config, "tui.json"), JSON.stringify({ keybinds: { app_exit: "ctrl+q" } }))
- await Bun.write(path.join(dir, "tui.json"), JSON.stringify({ keybinds: { theme_list: "ctrl+k" } }))
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.keybinds?.app_exit).toBe("ctrl+q")
- expect(config.keybinds?.theme_list).toBe("ctrl+k")
- },
- })
- })
- wintest("defaults Ctrl+Z to input undo on Windows", async () => {
- await using tmp = await tmpdir()
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.keybinds?.terminal_suspend).toBe("none")
- expect(config.keybinds?.input_undo).toBe("ctrl+z,ctrl+-,super+z")
- },
- })
- })
- wintest("keeps explicit input undo overrides on Windows", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(path.join(dir, "tui.json"), JSON.stringify({ keybinds: { input_undo: "ctrl+y" } }))
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.keybinds?.terminal_suspend).toBe("none")
- expect(config.keybinds?.input_undo).toBe("ctrl+y")
- },
- })
- })
- wintest("ignores terminal suspend bindings on Windows", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(path.join(dir, "tui.json"), JSON.stringify({ keybinds: { terminal_suspend: "alt+z" } }))
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.keybinds?.terminal_suspend).toBe("none")
- expect(config.keybinds?.input_undo).toBe("ctrl+z,ctrl+-,super+z")
- },
- })
- })
- test("KILO_TUI_CONFIG provides settings when no project config exists", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- const custom = path.join(dir, "custom-tui.json")
- await Bun.write(custom, JSON.stringify({ theme: "from-env", diff_style: "stacked" }))
- process.env.KILO_TUI_CONFIG = custom
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.theme).toBe("from-env")
- expect(config.diff_style).toBe("stacked")
- },
- })
- })
- test("does not derive tui path from KILO_CONFIG", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- const customDir = path.join(dir, "custom")
- await fs.mkdir(customDir, { recursive: true })
- await Bun.write(path.join(customDir, "kilo.json"), JSON.stringify({ model: "test/model" }))
- await Bun.write(path.join(customDir, "tui.json"), JSON.stringify({ theme: "should-not-load" }))
- process.env.KILO_CONFIG = path.join(customDir, "kilo.json") // kilocode_change
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.theme).toBeUndefined()
- },
- })
- })
- test("applies env and file substitutions in tui.json", async () => {
- const original = process.env.TUI_THEME_TEST
- process.env.TUI_THEME_TEST = "env-theme"
- try {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(path.join(dir, "keybind.txt"), "ctrl+q")
- await Bun.write(
- path.join(dir, "tui.json"),
- JSON.stringify({
- theme: "{env:TUI_THEME_TEST}",
- keybinds: { app_exit: "{file:keybind.txt}" },
- }),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.theme).toBe("env-theme")
- expect(config.keybinds?.app_exit).toBe("ctrl+q")
- },
- })
- } finally {
- if (original === undefined) delete process.env.TUI_THEME_TEST
- else process.env.TUI_THEME_TEST = original
- }
- })
- test("applies file substitutions when first identical token is in a commented line", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(path.join(dir, "theme.txt"), "resolved-theme")
- await Bun.write(
- path.join(dir, "tui.jsonc"),
- `{
- // "theme": "{file:theme.txt}",
- "theme": "{file:theme.txt}"
- }`,
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.theme).toBe("resolved-theme")
- },
- })
- })
- test("loads managed tui config and gives it highest precedence", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(
- path.join(dir, "tui.json"),
- JSON.stringify({ theme: "project-theme", plugin: ["[email protected]"] }, null, 2),
- )
- await fs.mkdir(managedConfigDir, { recursive: true })
- await Bun.write(
- path.join(managedConfigDir, "tui.json"),
- JSON.stringify({ theme: "managed-theme", plugin: ["[email protected]"] }, null, 2),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.theme).toBe("managed-theme")
- expect(config.plugin).toEqual(["[email protected]"])
- expect(config.plugin_origins).toEqual([
- {
- spec: "[email protected]",
- scope: "global",
- source: path.join(managedConfigDir, "tui.json"),
- },
- ])
- },
- })
- })
- // kilocode_change start
- test("loads .kilo/tui.json", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await fs.mkdir(path.join(dir, ".kilo"), { recursive: true })
- await Bun.write(path.join(dir, ".kilo", "tui.json"), JSON.stringify({ diff_style: "stacked" }, null, 2))
- // kilocode_change end
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.diff_style).toBe("stacked")
- },
- })
- })
- test("gracefully falls back when tui.json has invalid JSON", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(path.join(dir, "tui.json"), "{ invalid json }")
- await fs.mkdir(managedConfigDir, { recursive: true })
- await Bun.write(path.join(managedConfigDir, "tui.json"), JSON.stringify({ theme: "managed-fallback" }, null, 2))
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.theme).toBe("managed-fallback")
- expect(config.keybinds).toBeDefined()
- },
- })
- })
- test("supports tuple plugin specs with options in tui.json", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(
- path.join(dir, "tui.json"),
- JSON.stringify({
- plugin: [["[email protected]", { enabled: true, label: "demo" }]],
- }),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.plugin).toEqual([["[email protected]", { enabled: true, label: "demo" }]])
- expect(config.plugin_origins).toEqual([
- {
- spec: ["[email protected]", { enabled: true, label: "demo" }],
- scope: "local",
- source: path.join(tmp.path, "tui.json"),
- },
- ])
- },
- })
- })
- test("deduplicates tuple plugin specs by name with higher precedence winning", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(
- path.join(Global.Path.config, "tui.json"),
- JSON.stringify({
- plugin: [["[email protected]", { source: "global" }]],
- }),
- )
- await Bun.write(
- path.join(dir, "tui.json"),
- JSON.stringify({
- plugin: [
- ["[email protected]", { source: "project" }],
- ["[email protected]", { source: "project" }],
- ],
- }),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.plugin).toEqual([
- ["[email protected]", { source: "project" }],
- ["[email protected]", { source: "project" }],
- ])
- expect(config.plugin_origins).toEqual([
- {
- spec: ["[email protected]", { source: "project" }],
- scope: "local",
- source: path.join(tmp.path, "tui.json"),
- },
- {
- spec: ["[email protected]", { source: "project" }],
- scope: "local",
- source: path.join(tmp.path, "tui.json"),
- },
- ])
- },
- })
- })
- test("tracks global and local plugin metadata in merged tui config", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(
- path.join(Global.Path.config, "tui.json"),
- JSON.stringify({
- plugin: ["[email protected]"],
- }),
- )
- await Bun.write(
- path.join(dir, "tui.json"),
- JSON.stringify({
- plugin: ["[email protected]"],
- }),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.plugin).toEqual(["[email protected]", "[email protected]"])
- expect(config.plugin_origins).toEqual([
- {
- spec: "[email protected]",
- scope: "global",
- source: path.join(Global.Path.config, "tui.json"),
- },
- {
- spec: "[email protected]",
- scope: "local",
- source: path.join(tmp.path, "tui.json"),
- },
- ])
- },
- })
- })
- test("merges plugin_enabled flags across config layers", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(
- path.join(Global.Path.config, "tui.json"),
- JSON.stringify({
- plugin_enabled: {
- "internal:sidebar-context": false,
- "demo.plugin": true,
- },
- }),
- )
- await Bun.write(
- path.join(dir, "tui.json"),
- JSON.stringify({
- plugin_enabled: {
- "demo.plugin": false,
- "local.plugin": true,
- },
- }),
- )
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await TuiConfig.get()
- expect(config.plugin_enabled).toEqual({
- "internal:sidebar-context": false,
- "demo.plugin": false,
- "local.plugin": true,
- })
- },
- })
- })
|