CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
cli.test.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| eae38d1 | 1 | /** |
| 2 | * Block G3 — `gluecron` CLI smoke tests. | |
| 3 | * | |
| 4 | * Invokes the `dispatch` function directly without spawning a process; | |
| 5 | * captures stdout lines via an injected `out` callback. This keeps the | |
| 6 | * tests hermetic — no actual HTTP requests (except in cases where they | |
| 7 | * are expected to fail gracefully against a non-responsive host). | |
| 8 | */ | |
| 9 | ||
| 10 | import { describe, it, expect } from "bun:test"; | |
| 11 | import { dispatch, HELP, loadConfig } from "../../cli/gluecron"; | |
| 12 | ||
| 13 | function capture() { | |
| 14 | const lines: string[] = []; | |
| 15 | return { | |
| 16 | out: (s: string) => lines.push(s), | |
| 17 | text: () => lines.join("\n"), | |
| 18 | lines, | |
| 19 | }; | |
| 20 | } | |
| 21 | ||
| 22 | describe("cli — help + version", () => { | |
| 23 | it("prints help on no args", async () => { | |
| 24 | const { out, text } = capture(); | |
| 25 | const code = await dispatch([], out); | |
| 26 | expect(code).toBe(0); | |
| 27 | expect(text()).toContain("gluecron CLI"); | |
| 28 | }); | |
| 29 | ||
| 30 | it("prints help with --help", async () => { | |
| 31 | const { out, text } = capture(); | |
| 32 | const code = await dispatch(["--help"], out); | |
| 33 | expect(code).toBe(0); | |
| 34 | expect(text()).toContain("Usage"); | |
| 35 | }); | |
| 36 | ||
| 37 | it("prints version with --version", async () => { | |
| 38 | const { out, text } = capture(); | |
| 39 | const code = await dispatch(["--version"], out); | |
| 40 | expect(code).toBe(0); | |
| 41 | expect(text()).toMatch(/^\d+\.\d+\.\d+$/); | |
| 42 | }); | |
| 43 | ||
| 44 | it("rejects unknown commands", async () => { | |
| 45 | const { out, text } = capture(); | |
| 46 | const code = await dispatch(["bogus"], out); | |
| 47 | expect(code).toBe(1); | |
| 48 | expect(text()).toContain("unknown command"); | |
| 49 | }); | |
| 50 | }); | |
| 51 | ||
| 52 | describe("cli — config", () => { | |
| 53 | it("loadConfig returns default host when no file exists", () => { | |
| 54 | const cfg = loadConfig(); | |
| 55 | expect(cfg.host).toBeDefined(); | |
| 56 | expect(typeof cfg.host).toBe("string"); | |
| 57 | }); | |
| 58 | }); | |
| 59 | ||
| 60 | describe("cli — HELP text", () => { | |
| 61 | it("lists every major command", () => { | |
| 62 | expect(HELP).toContain("login"); | |
| 63 | expect(HELP).toContain("whoami"); | |
| 64 | expect(HELP).toContain("repo ls"); | |
| 65 | expect(HELP).toContain("repo show"); | |
| 66 | expect(HELP).toContain("repo create"); | |
| 67 | expect(HELP).toContain("issues ls"); | |
| 68 | expect(HELP).toContain("gql"); | |
| 69 | }); | |
| 70 | }); | |
| 71 | ||
| 72 | describe("cli — dispatcher", () => { | |
| 73 | it("repo with no subcommand prints usage", async () => { | |
| 74 | const { out, text } = capture(); | |
| 75 | const code = await dispatch(["repo"], out); | |
| 76 | expect(code).toBe(1); | |
| 77 | expect(text()).toContain("usage:"); | |
| 78 | }); | |
| 79 | ||
| 80 | it("issues without args prints usage", async () => { | |
| 81 | const { out, text } = capture(); | |
| 82 | const code = await dispatch(["issues"], out); | |
| 83 | expect(code).toBe(1); | |
| 84 | expect(text()).toContain("usage:"); | |
| 85 | }); | |
| 86 | ||
| 87 | it("gql without query prints usage", async () => { | |
| 88 | const { out, text } = capture(); | |
| 89 | const code = await dispatch(["gql"], out); | |
| 90 | expect(code).toBe(1); | |
| 91 | expect(text()).toContain("usage:"); | |
| 92 | }); | |
| 93 | }); |