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