Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

62 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { kind, layout, shape, variables } from "./report.mjs";
5
6test("a value's shape is its key paths and types, not its values", () => {
7 assert.deepEqual(shape({ a: 1, b: { c: "x", d: [{ e: true }] }, f: null }), {
8 a: "number",
9 b: "object",
10 "b.c": "string",
11 "b.d": "array",
12 "b.d[]": "object",
13 "b.d[].e": "boolean",
14 f: "null",
15 });
16});
17
18test("variables are kept by kind, and only GitHub's", () => {
19 assert.deepEqual(
20 variables({
21 GITHUB_SHA: "a".repeat(40),
22 GITHUB_RUN_ID: "42",
23 GITHUB_SERVER_URL: "https://g1t.sh",
24 RUNNER_TEMP: "/home/runner/work/_temp",
25 CI: "true",
26 PATH: "/bin",
27 SECRET: "x",
28 }),
29 { GITHUB_SHA: "sha", GITHUB_RUN_ID: "integer", GITHUB_SERVER_URL: "url", RUNNER_TEMP: "path", CI: "boolean" },
30 );
31 assert.equal(kind("refs/heads/main"), "ref");
32 assert.equal(kind(""), "empty");
33});
34
35test("the layout says where the workspace is, as GitHub lays it out", () => {
36 const on = layout({ RUNNER_WORKSPACE: "/home/runner/work/web", GITHUB_WORKSPACE: "/home/runner/work/web/web", RUNNER_TEMP: "/home/runner/work/_temp" });
37 assert.equal(on.workspace_under_runner_workspace, true);
38 assert.equal(on.workspace_is_repo_twice, true);
39 assert.equal(layout({ GITHUB_WORKSPACE: "/home/runner/work/repo" }).workspace_is_repo_twice, false);
40});
41
42test("the diff names what g1t lacks or has differently, and what it adds", async () => {
43 const { compare } = await import("../scripts/conformance-diff.mjs");
44 const github = {
45 variables: { GITHUB_SHA: "sha", ImageOS: "text" },
46 layout: { a: true },
47 contexts: { github: { sha: "string", "event.ref": "string" } },
48 event: { ref: "string" },
49 checks: { format: "a-1-{2}" },
50 };
51 const g1t = {
52 variables: { GITHUB_SHA: "sha", G1T: "boolean" },
53 layout: { a: false },
54 contexts: { github: { sha: "string", "event.ref": "number" } },
55 event: { ref: "string" },
56 checks: { format: "a-1-{2}" },
57 };
58 const found = compare(github, g1t);
59 assert.deepEqual(found.missing, ["variable ImageOS (text)"]);
60 assert.deepEqual(found.different, ["layout a: GitHub true, g1t false", 'github. event.ref: GitHub "string", g1t "number"']);
61 assert.deepEqual(found.extra, ["variable G1T (boolean)"]);
62});