Skip to content

Commit 388943f

Browse files
xesrevinuGit Agent
andcommitted
test(cli): add tests for cli config and init commands
- Added test for config command to show provider settings. - Implemented test validation for init command with --local. New tests enhance coverage for CLI commands ensuring proper Co-Authored-By: Git Agent <noreply@git-agent.dev>
1 parent 7078d9e commit 388943f

1 file changed

Lines changed: 43 additions & 2 deletions

File tree

tests/cli-smoke.test.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,20 @@ import { afterEach, describe, expect, it } from "vitest";
77
const repoRoot = process.cwd();
88
const tempDirs: Array<string> = [];
99

10-
const runCli = (args: ReadonlyArray<string>) =>
10+
const runCli = (
11+
args: ReadonlyArray<string>,
12+
options?: {
13+
readonly cwd?: string;
14+
readonly env?: Record<string, string | undefined>;
15+
},
16+
) =>
1117
spawnSync("bun", ["src/cli.ts", ...args], {
12-
cwd: repoRoot,
18+
cwd: options?.cwd ?? repoRoot,
1319
encoding: "utf8",
20+
env: {
21+
...process.env,
22+
...options?.env,
23+
},
1424
});
1525

1626
const newGitRepo = (): string => {
@@ -85,6 +95,37 @@ describe("cli smoke", () => {
8595
expect(result.stderr).toContain("reading hook file");
8696
});
8797

98+
it("config show resolves provider settings from environment", () => {
99+
const dir = newGitRepo();
100+
const xdgHome = mkdtempSync(join(tmpdir(), "git-agent-cli-xdg-"));
101+
tempDirs.push(xdgHome);
102+
103+
const result = runCli(["config", "show", "--cwd", dir], {
104+
env: {
105+
XDG_CONFIG_HOME: xdgHome,
106+
OPENAI_COMPACT_API_KEY: "",
107+
OPENAI_COMPACT_API_BASE_URL: "",
108+
OPENAI_COMPACT_MODEL: "",
109+
GIT_AGENT_BUILD_API_KEY: "",
110+
GIT_AGENT_BUILD_BASE_URL: "https://build.example/v1",
111+
GIT_AGENT_BUILD_MODEL: "build-model",
112+
},
113+
});
114+
115+
expect(result.status).toBe(0);
116+
expect(result.stdout).toContain("api_key: (not set)");
117+
expect(result.stdout).toContain("model: build-model");
118+
expect(result.stdout).toContain("base_url: https://build.example/v1");
119+
});
120+
121+
it("init --local rejects runs that do not request any action", () => {
122+
const dir = newGitRepo();
123+
const result = runCli(["init", "--cwd", dir, "--local"]);
124+
125+
expect(result.status).toBe(1);
126+
expect(result.stderr).toContain("--local requires at least one action flag");
127+
});
128+
88129
it("init --local reports the local config path when it already exists", () => {
89130
const dir = newGitRepo();
90131
mkdirSync(join(dir, ".git-agent"), { recursive: true });

0 commit comments

Comments
 (0)