| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { kind, layout, shape, variables } from "./report.mjs"; |
| 5 | |
| 6 | test("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 | |
| 18 | test("variables are kept by kind, and only GitHub's", () => { |
| 19 | assert.deepEqual( |
| 20 | variables({ GITHUB_SHA: "a".repeat(40), GITHUB_RUN_ID: "42", GITHUB_SERVER_URL: "https://g1t.sh", RUNNER_TEMP: "/home/runner/work/_temp", CI: "true", PATH: "/bin", SECRET: "x" }), |
| 21 | { GITHUB_SHA: "sha", GITHUB_RUN_ID: "integer", GITHUB_SERVER_URL: "url", RUNNER_TEMP: "path", CI: "boolean" }, |
| 22 | ); |
| 23 | assert.equal(kind("refs/heads/main"), "ref"); |
| 24 | assert.equal(kind(""), "empty"); |
| 25 | }); |
| 26 | |
| 27 | test("the layout says where the workspace is, as GitHub lays it out", () => { |
| 28 | const on = layout({ RUNNER_WORKSPACE: "/home/runner/work/web", GITHUB_WORKSPACE: "/home/runner/work/web/web", RUNNER_TEMP: "/home/runner/work/_temp" }); |
| 29 | assert.equal(on.workspace_under_runner_workspace, true); |
| 30 | assert.equal(on.workspace_is_repo_twice, true); |
| 31 | assert.equal(layout({ GITHUB_WORKSPACE: "/home/runner/work/repo" }).workspace_is_repo_twice, false); |
| 32 | }); |
| 33 | |
| 34 | test("the diff names what g1t lacks or has differently, and what it adds", async () => { |
| 35 | const { compare } = await import("../scripts/conformance-diff.mjs"); |
| 36 | const github = { variables: { GITHUB_SHA: "sha", ImageOS: "text" }, layout: { a: true }, contexts: { github: { sha: "string", "event.ref": "string" } }, event: { ref: "string" }, checks: { format: "a-1-{2}" } }; |
| 37 | const g1t = { variables: { GITHUB_SHA: "sha", G1T: "boolean" }, layout: { a: false }, contexts: { github: { sha: "string", "event.ref": "number" } }, event: { ref: "string" }, checks: { format: "a-1-{2}" } }; |
| 38 | const found = compare(github, g1t); |
| 39 | assert.deepEqual(found.missing, ["variable ImageOS (text)"]); |
| 40 | assert.deepEqual(found.different, ["layout a: GitHub true, g1t false", 'github. event.ref: GitHub "string", g1t "number"']); |
| 41 | assert.deepEqual(found.extra, ["variable G1T (boolean)"]); |
| 42 | }); |