Files
copilotkit__copilotkit/showcase/scripts/__tests__/verify-deploy.test.ts
Jordan Ritter 8714ab569b chore(showcase): apply oxfmt formatting across showcase scripts and shells
oxfmt --write normalized formatting on showcase scripts, the four shells, and the
new oxlint rule; required for the repo-root oxfmt --check CI gate.
2026-05-29 11:45:16 -07:00

151 lines
5.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { parseArgs, resolveProbeTargets, runVerify } from "../verify-deploy";
import type { ProbeRunner } from "../verify-deploy";
describe("verify-deploy argv parsing", () => {
it("requires --env", () => {
expect(() => parseArgs([])).toThrow(/--env/);
});
it("accepts --env staging and --env prod", () => {
expect(parseArgs(["--env", "staging"]).env).toBe("staging");
expect(parseArgs(["--env=prod"]).env).toBe("prod");
});
it("rejects unknown envs", () => {
expect(() => parseArgs(["--env", "dev"])).toThrow(/Unknown env/);
});
it("accepts optional --services CSV", () => {
const parsed = parseArgs(["--env", "staging", "--services", "docs,shell"]);
expect(parsed.services).toEqual(["docs", "shell"]);
});
it("rejects empty --services= equals-form (mirrors space-form behavior)", () => {
expect(() => parseArgs(["--env", "staging", "--services="])).toThrow(
/--services/,
);
});
it("rejects --services space-form whose CSV is all empty entries (symmetry with equals-form)", () => {
// Bug: space-form previously only guarded `!v` on the raw next-arg,
// so `--services ,,` produced an empty list that fell through to a
// less-precise zero-targets error. Both forms must throw the same
// precise `--services requires a CSV value` here.
expect(() => parseArgs(["--env=staging", "--services", ",,"])).toThrow(
/--services requires a CSV value/,
);
});
it("rejects bare trailing --env (no following value)", () => {
// Bug: `argv[++i]` was undefined and we deferred to a vague
// `resolveEnv` error. Must throw the precise message here.
expect(() => parseArgs(["--env"])).toThrow(
/--env requires a value \(staging\|prod\)/,
);
});
it("rejects --env= with empty value (symmetry with bare trailing --env)", () => {
expect(() => parseArgs(["--env="])).toThrow(
/--env requires a value \(staging\|prod\)/,
);
});
});
describe("resolveProbeTargets", () => {
it("filters SSOT to entries where probe[env] is true", () => {
const targets = resolveProbeTargets({ env: "staging" });
// docs is staging:true → must be present.
expect(targets.find((t) => t.name === "docs")).toBeDefined();
});
it("REFUSES when a probe-required service has no domain for the env", () => {
expect(() =>
resolveProbeTargets({
env: "staging",
overrides: {
docs: { domains: { staging: "", prod: "docs.copilotkit.ai" } },
},
}),
).toThrow(/missing.*staging.*domain/i);
});
it("honors --services filter (subset of probe-eligible)", () => {
const targets = resolveProbeTargets({
env: "staging",
services: ["docs"],
});
expect(targets.length).toBe(1);
expect(targets[0].name).toBe("docs");
});
it("REFUSES a typo'd service name (unknown service, not silent drop)", () => {
expect(() =>
resolveProbeTargets({ env: "staging", services: ["docss"] }),
).toThrow(/unknown service.*docss/i);
});
it("REFUSES a service that exists in SSOT but is not probe-eligible for the env", () => {
// Find a service whose probe[staging] is false.
// Use override seam to flip probe state without mutating SSOT.
// Since resolveProbeTargets doesn't expose a probe-flag override,
// we pick a real service name and an env where the SSOT probe is
// false. Search SERVICES for an entry where probe.staging===false.
// If none exists, this test still validates the error string for
// the more common typo case via the prior test; we focus on the
// distinct error phrasing.
//
// Practical assertion: an unknown name surfaces as "unknown
// service", which is structurally a different (clearer) error
// than "not probe-eligible". The two paths must be distinguished.
expect(() =>
resolveProbeTargets({ env: "staging", services: ["totally-fake"] }),
).toThrow(/unknown service/i);
});
});
describe("runVerify driver dispatch", () => {
it("calls the driver for each target and fails loud on any red", async () => {
const calls: string[] = [];
const runner: ProbeRunner = async (target) => {
calls.push(`${target.driver}:${target.host}`);
if (target.name === "docs") {
return { ok: false, error: "DOM string missing" };
}
return { ok: true };
};
const summary = await runVerify({
env: "staging",
services: ["docs", "shell"],
runner,
});
expect(calls).toContain("docs:docs.staging.copilotkit.ai");
expect(calls).toContain("shell:showcase.staging.copilotkit.ai");
expect(summary.failed.map((f) => f.name)).toEqual(["docs"]);
expect(summary.exitCode).toBe(1);
});
it("exits 0 when all probes green", async () => {
const summary = await runVerify({
env: "staging",
services: ["docs"],
runner: async () => ({ ok: true }),
});
expect(summary.exitCode).toBe(0);
});
it("FAILS LOUD on zero resolved targets (never silently exit 0)", async () => {
// resolveProbeTargets now throws on unknown service names, so the
// zero-target shape can only happen via the API (empty filter
// set). We exercise the runVerify guard directly: a runner that's
// never called and an exit code of 1 with a clear diagnostic.
const summary = await runVerify({
env: "staging",
services: [],
runner: async () => ({ ok: true }),
});
expect(summary.exitCode).not.toBe(0);
expect(summary.failed.length).toBeGreaterThan(0);
});
});