Skip to content
59 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Merge Actions runs: summaries, attempts and re-runs, graceful cancel, log downloads, badges (actions 0009)1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import type { JobLogText } from "@g1t/contracts";
5
6import { archiveFiles, blocks, fileName, highlight, searchLog } from "./log-lines.ts";
7
8const LOG = ["Job: test", "##[group]Run cargo test", "cargo test --locked", "##[endgroup]", "test greet ... FAILED", "##[error]Process completed with exit code 101."].join("\n");
9
10test("a log reads as lines and folded groups, numbered past the group markers", () => {
11 const parsed = blocks(LOG);
12 assert.equal(parsed.length, 4);
13 assert.deepEqual(parsed[1], { kind: "group", title: "Run cargo test", lines: [{ line: { kind: "text", text: "cargo test --locked" }, number: 2 }] });
14 assert.deepEqual(parsed[3], { kind: "line", line: { kind: "error", text: "Process completed with exit code 101." }, number: 4 });
15});
16
17test("search finds lines in any case, inside folded groups too", () => {
18 assert.deepEqual(
19 searchLog(LOG, "CARGO TEST").map((found) => found.number),
20 [2],
21 );
22 assert.deepEqual(
23 searchLog(LOG, "test").map((found) => found.number),
24 [1, 2, 3],
25 );
26 assert.deepEqual(searchLog(LOG, " "), []);
27 // The group's title is not a line of its own.
28 assert.deepEqual(searchLog(LOG, "Run cargo"), []);
29});
30
31test("matches are marked where they fall", () => {
32 assert.deepEqual(highlight("Test a test", "test"), [
33 { text: "Test", match: true },
34 { text: " a ", match: false },
35 { text: "test", match: true },
36 ]);
37 assert.deepEqual(highlight("plain", ""), [{ text: "plain", match: false }]);
38});
39
40test("a run's archive has each job whole and a file per step, named as the API names them", () => {
41 const job = (name: string, chunks: [number, string][], omitted = false): JobLogText => ({
42 jobId: "job_1",
43 name,
44 steps: [{ number: 1, name: "Run cargo test", status: "completed", conclusion: "success", startedAt: null, finishedAt: null }],
45 chunks: chunks.map(([step, text], index) => ({ seq: index + 1, step, text })),
46 done: true,
47 omitted,
48 });
49 const files = archiveFiles([job("test", [[0, "set up\n"], [1, "running\n"], [1, "ok\n"]]), job("deploy/x", [], true)]);
50 assert.deepEqual(
51 files.map((file) => file.path),
52 ["1_test.txt", "test/0_Set up job.txt", "test/1_Run cargo test.txt", "2_deploy_x.txt"],
53 );
54 assert.equal(files[0]!.text, "set up\nrunning\nok\n");
55 assert.equal(files[2]!.text, "running\nok\n");
56 assert.match(files[3]!.text, /left out/);
57 assert.equal(fileName("build / a:b"), "build _ a_b");
58 assert.equal(fileName(".."), "job");
59});

This file's history is long; its oldest lines are credited to the oldest commit read.