import{a as m,b as u,c as d,d as r}from"./chunk-S5I3D4YF.mjs";import"./chunk-DLPEQYKV.mjs";import"./chunk-LVPDR3D2.mjs";import"./chunk-RIT5WMHA.mjs";import"./chunk-O53OUY2B.mjs";import"./chunk-JD45QQDD.mjs";import"./chunk-ICS3PEIS.mjs";import"./chunk-SIWBT4LK.mjs";import"./chunk-CAOKJGEV.mjs";import"./chunk-QPV2G662.mjs";import"./chunk-AUIVUOKV.mjs";import{a as i,b as n,e as p,g as t,h as o}from"./chunk-IFUYCFBO.mjs";import"./chunk-3PFH3U2T.mjs";import"./chunk-76CZ6Z7T.mjs";import c from"fs";import g from"path";import*as f from"child_process";o.mock("node:fs");o.mock("node:child_process");o.mock("./index",()=>({resolveConflicts:o.fn()}));o.mock("./utils",()=>({restoreBackups:o.fn()}));o.mock("./normalizer",()=>({DEFAULT_CONFIG:{defaultStrategy:"merge"}}));i("cli helpers",()=>{p(()=>{o.clearAllMocks()}),i("findGitRoot",()=>{n("returns git root from execSync",()=>{o.spyOn(f,"execSync").mockReturnValue(`/git/root
`);let e=m();t(e).toBe("/git/root")}),n("falls back to process.cwd() on error",()=>{o.spyOn(f,"execSync").mockImplementation(()=>{throw new Error("no git")});let e=m();t(e).toBe(process.cwd())})}),i("parseArgs",()=>{n("parses include/exclude/matcher/debug/sidecar",()=>{let s=r(["node","cli","--include","a.json,b.json","--exclude","c.json","--matcher","micromatch","--debug","--sidecar"]);t(s.overrides).toEqual({include:["a.json","b.json"],exclude:["c.json"],matcher:"micromatch",debug:!0,writeConflictSidecar:!0}),t(s.init).toBe(!1)}),n("sets init flag",()=>{let e=r(["node","cli","--init"]);t(e.init).toBe(!0)}),n("sets restore with undefined",()=>{let e=r(["node","cli","--restore"]);t(e.restore).toBe(void 0)}),n("sets restore with custom directory",()=>{let e=r(["node","cli","--restore","custom-backup"]);t(e.restore).toBe("custom-backup")}),n("warns on unknown option",()=>{let e=o.spyOn(console,"warn").mockImplementation(()=>{});r(["node","cli","--unknown"]),t(e).toHaveBeenCalledWith("Unknown option: --unknown")})}),i("initConfig",()=>{let e="/tmp/test-cli",s=g.join(e,"git-json-resolver.config.js");n("writes starter config if none exists",()=>{c.existsSync.mockReturnValue(!1);let a=o.spyOn(c,"writeFileSync").mockImplementation(()=>{}),l=o.spyOn(console,"log").mockImplementation(()=>{});d(e),t(a).toHaveBeenCalled(),t(l).toHaveBeenCalledWith(`Created starter config at ${s}`)}),n("exits if config already exists",()=>{c.existsSync.mockReturnValue(!0);let a=o.spyOn(process,"exit").mockImplementation(()=>{throw new Error("exit")}),l=o.spyOn(console,"error").mockImplementation(()=>{});t(()=>d(e)).toThrow("exit"),t(l).toHaveBeenCalledWith(`Config file already exists: ${s}`),t(a).toHaveBeenCalledWith(1)})}),i("loadConfigFile",()=>{n("returns {} if no config found",async()=>{c.existsSync.mockReturnValue(!1);let e=await u();t(e).toEqual({})}),n.skip("loads config from js file",async()=>{let e={debug:!0};c.existsSync.mockReturnValue(!0),o.doMock("/git/root/git-json-resolver.config.js",()=>({default:e})),o.spyOn(f,"execSync").mockReturnValue(`/git/root
`);let s=await u();t(s).toEqual(e)})})});
