Something went wrong. Try again.
Something went wrong. Try again.
3.9 kB · 71 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172import { afterEach, describe, expect, it } from "vitest";import { join } from "node:path";import { runCli } from "../../runner/cli";import { makeTempRepo, type TempRepo } from "../helpers/tempRepo";
/** * Every flag of every subcommand given at once, through the real parser and the real actions, in paths that do not exist. * Each action must refuse in its own words, quickly, before it starts a browser or touches anything: an option that was * parsed wrongly would show up as a different message, a different exit code, or a browser starting. */let repo: TempRepo;afterEach(() => repo?.cleanup());
describe("a call with all its options, against files that are not there", () => { const where = () => { repo = makeTempRepo({ git: false }); const p = (n: string) => join(repo.dir, n); return { p, cfg: p("nope.json") }; };
it("run: says which script it cannot read", async () => { const { p, cfg } = where(); const r = await runCli(["run", p("s.aite"), "--config", cfg, "--profile", "p", "--serve", p("pages"), "--headless", "--no-sandbox", "--display", ":1", "--connect-timeout", "9000", "--no-lock"]); expect(r.exitCode).toBe(2); expect(r.stderr).toContain(`cannot read ${p("s.aite")}`); });
it("report and verdict: say which run.json is missing", async () => { const { p, cfg } = where(); const rep = await runCli(["report", p("results")]); expect(rep).toMatchObject({ exitCode: 2 }); expect(rep.stderr).toContain("cannot make a report"); const v = await runCli(["verdict", p("results"), `--config=${cfg}`, "--project", "p", "--by", "qian", "--port", "5000", "--headless", "--no-sandbox", "--display", ":2"]); expect(v.exitCode).toBe(2); expect(v.stderr).toContain("cannot read run.json"); });
it("profile open, record: say the config file cannot be read", async () => { const { p, cfg } = where(); const open = await runCli(["profile", "open", "alice", "--config", cfg, "--headless", "--no-sandbox", "--display", ":3", "--connect-timeout", "1234"]); expect(open.exitCode).toBe(2); expect(open.stderr).toContain("invalid aite config"); expect(open.stderr).toContain("nope.json"); const rec = await runCli(["record", "https://a.test/", "--out", p("d.aite"), "--profile", "p", "--config", cfg, "--display", ":2", "--headless", "--no-sandbox"]); expect(rec.exitCode).toBe(2); expect(rec.stderr).toContain("invalid aite config"); });
it("schedule: every script that cannot be read is named, and the exit code is 3 (could not run)", async () => { const { p, cfg } = where(); const r = await runCli(["schedule", p("a.aite"), p("b.aite"), "--state", p("state"), "--budget", "90s", "--project", "tests", "--no-gitlab", `--config=${cfg}`, "--profile", "p", "--display", ":1", "--connect-timeout", "5000", "--headless", "--no-sandbox", "--post-cap", "4"]); expect(r.exitCode).toBe(3); const text = `${r.stdout}\n${r.stderr}`; expect(text).toContain(`${p("a.aite")}: could not run`); expect(text).toContain(`${p("b.aite")}: could not run`); });
it("author: says which journey it cannot read, and never calls the model", async () => { const { p, cfg } = where(); const r = await runCli(["author", p("j.md"), "--out", p("scripts/x.aite"), "--model-command", "false", "--attempts", "3", "--profile", "p", "--config", cfg, "--display", ":3", "--headless", "--no-sandbox"]); expect(r.exitCode).toBe(2); expect(r.stderr).toContain("cannot read the journey"); });
it("diagnose: a closed port is the connection, not the page", async () => { const { cfg } = where(); const r = await runCli(["diagnose", "http://127.0.0.1:9/", "--config", cfg, "--reference-dns", "127.0.0.1"]); expect(r.exitCode).toBe(1); expect(r.stdout).toMatch(/likely layer: the connection \(TCP\)/); }, 60_000);});