Public: anyone can read this; the crew can change it.
A failed run's one line is the failure itself, and check.txt says it above the tail (#5812) #17715
Merged 11h 12m ago, live in production
sold/leaf-logs-1 → main 0 commits
17 files
changed +292
−82
- docs/CONTRACT.md
- docs/features/run-logs.md
- docs/features/terminal-workspace-kinds.md
- src/actions/runs.ts
- src/contract/openapi/routes/getOwnerNamePullsNumberCheckTxt.ts
- src/core/runs.ts
- src/http/check_text.ts
- src/logs/findings.ts
- src/logs/level.ts
- src/runs/error_line.ts
- src/tui/screens/workspace_kinds.ts
- src/web/render/log.ts
- test/contribute-check-text.test.ts
- test/feed-failed-run.test.ts
- test/log-findings.test.ts
- test/text-clip-checks.test.ts
- test/tui-workspace-kinds.test.ts
docs/CONTRACT.md +2 −2
| @@ -249,8 +249,8 @@ Two more places the table reaches, so it is never only a page: | ||
| 249 | 249 | ## Agent doors beside the table |
| 250 | 250 | |
| 251 | 251 | - `GET /<owner>/<repo>/pulls/<n>/check.txt` is a pull's latest check as plain |
| 252 | text (line 1 `pending`, `green` or `red`; line 2 `head: <oid>`; on red the | |
| 253 | log tail where the log door allows it). It is in the OpenAPI description and | |
| 252 | text (line 1 `pending`, `green` or `red`; line 2 `head: <oid>`; on red what | |
| 253 | failed, then the log tail, where the log door allows it). It is in the OpenAPI description and | |
| 254 | 254 | in `/llms.txt`; `test/openapi-check-txt.test.ts` keeps the three in step. |
| 255 | 255 | |
| 256 | 256 | ## What is not here yet |
docs/features/run-logs.md +4
| @@ -14,6 +14,10 @@ A run writes its log to a file under the forge's data. Once the run is finished, | ||
| 14 | 14 | |
| 15 | 15 | Every one of these asks first whether the run is in this repository and the viewer may read its log; only then is an evicted log fetched back from the store, so a run id from another repository or a hidden log never reaches the store. A run still in progress is never archived or restored. |
| 16 | 16 | |
| 17 | ## The line that says why | |
| 18 | ||
| 19 | When a run fails, the forge keeps the one line that says why (`findingsOf` in `src/logs/findings.ts`): the failing test its check named, at that test's own `(fail)` line; else the line the run's verdict quotes; else, for a deploy or an agent's run, the last line that states an error. The feed's post says it and links to it. `GET …/check.txt` says up to five failing tests with the end of each one's output, above the last 80 lines. A word in passing (`0 failed`, a passing test named for an error) is never taken for it. | |
| 20 | ||
| 17 | 21 | ## When the store is down |
| 18 | 22 | |
| 19 | 23 | A log that fails to archive stays local and the next sweep tries again. The seven-day prune never removes the log of a finished run the store does not hold, and one sweep runs at a time. |
docs/features/terminal-workspace-kinds.md +1 −1
| @@ -4,7 +4,7 @@ row: Notebooks, JSON Lines and logs in the terminal | ||
| 4 | 4 | --- |
| 5 | 5 | # Notebooks, JSON Lines and logs in the terminal |
| 6 | 6 | |
| 7 | The SSH workspace opens `.ipynb`, `.jsonl`/`.ndjson` and `.log`/`.ansi` files the way the blob page does, from the same parsers (`parseNotebook` in `src/web/render/notebook.ts`, `parseJsonl`, `ansiLines`, `logLevel` in `src/web/render/log.ts`). Drawing lives in `src/tui/screens/workspace_kinds.ts`. | |
| 7 | The SSH workspace opens `.ipynb`, `.jsonl`/`.ndjson` and `.log`/`.ansi` files the way the blob page does, from the same parsers (`parseNotebook` in `src/web/render/notebook.ts`, `parseJsonl`, `ansiLines`, `logLevel` in `src/logs/level.ts`). Drawing lives in `src/tui/screens/workspace_kinds.ts`. | |
| 8 | 8 | |
| 9 | 9 | - **Notebook**: cells in order. Markdown keeps its source lines (headings bold), code is dimmed as `In [n]: …`, outputs are text, errors are red, images say `[image output not shown]`. Nothing is run. |
| 10 | 10 | - **JSON Lines**: a table, one row per object; a bad line is a row that names its line number. |
src/actions/runs.ts +8 −4
| @@ -44,7 +44,8 @@ import { err, ok, type Result } from "../kernel/result.ts"; | ||
| 44 | 44 | import { restoreRunLog } from "../runs/archive.ts"; |
| 45 | 45 | import { readRunLog, readRunLogTail, runLogPath } from "../runs/log.ts"; |
| 46 | 46 | import { shownStates, type ShownState } from "../runs/state.ts"; |
| 47 | import { firstErrorLine } from "../runs/error_line.ts"; | |
| 47 | import { findingsOf } from "../logs/findings.ts"; | |
| 48 | import { clip } from "../text/clip.ts"; | |
| 48 | 49 | import { cancelledBy } from "../runs/cancelled.ts"; |
| 49 | 50 | import { requireReader, requireWriter, type AccessError } from "./access.ts"; |
| 50 | 51 | import { deskForRun } from "../crew/desk_posts.ts"; |
| @@ -95,15 +96,18 @@ export function announceRun(app: App, run: Run, actorId?: string): void { | ||
| 95 | 96 | }); |
| 96 | 97 | } |
| 97 | 98 | |
| 99 | /** The most of that line a run keeps. */ | |
| 100 | export const ERROR_LINE_MAX = 120; | |
| 101 | ||
| 98 | 102 | /** |
| 99 | 103 | * What a failed run's public event may say of it: the number of the pull or |
| 100 | * issue it was for. The first error line of its log is a log line, so it is | |
| 104 | * issue it was for. The line that says why it failed is a log line, so it is | |
| 101 | 105 | * kept with the run (`setRunErrorLine`), once, and never put on the event. |
| 102 | 106 | */ |
| 103 | 107 | function failureOf(app: App, run: Run): Record<string, unknown> { |
| 104 | 108 | if (run.state !== "failed") return {}; |
| 105 | const found = firstErrorLine(readRunLog(app.config.dataDir, run.id).lines); | |
| 106 | if (found !== undefined) setRunErrorLine(app.db, run.id, found.text, found.at); | |
| 109 | const found = findingsOf(run, readRunLog(app.config.dataDir, run.id).lines)[0]; | |
| 110 | if (found !== undefined) setRunErrorLine(app.db, run.id, clip(found.says, ERROR_LINE_MAX), found.line ?? 0); | |
| 107 | 111 | const subject = run.issueId === null ? undefined : getIssueById(app.db, run.issueId); |
| 108 | 112 | return subject === undefined ? {} : { subject: subject.number }; |
| 109 | 113 | } |
src/contract/openapi/routes/getOwnerNamePullsNumberCheckTxt.ts +1 −1
| @@ -6,7 +6,7 @@ export const route: Route = { | ||
| 6 | 6 | summary: |
| 7 | 7 | "A pull's latest check as `text/plain`, for a script", |
| 8 | 8 | detail: |
| 9 | "A pull's latest check as `text/plain`, for a script: line 1 is `pending`, `green` or `red`, line 2 is `head: <oid>`; on red a blank line and the last 80 log lines follow, only where the run-log door would show that reader the log. Anonymous on a public repository. It differs from `/api/v1/repos/{owner}/{name}/pulls/{number}/checks?format=text` (`state:`, `head:`, `required:` lines, no log tail, state words `none`/`ok`/`failed`): this answers the one word to branch on, plus the failing tail", | |
| 9 | "A pull's latest check as `text/plain`, for a script: line 1 is `pending`, `green` or `red`, line 2 is `head: <oid>`; on red a blank line, what failed (each failing test with the end of its output), a blank line and the last 80 log lines follow, only where the run-log door would show that reader the log. Anonymous on a public repository. It differs from `/api/v1/repos/{owner}/{name}/pulls/{number}/checks?format=text` (`state:`, `head:`, `required:` lines, no log tail, state words `none`/`ok`/`failed`): this answers the one word to branch on, plus the failing tail", | |
| 10 | 10 | auth: false, |
| 11 | 11 | role: "anonymous", |
| 12 | 12 | refuses: [404], |
src/core/runs.ts +4 −1
| @@ -1995,7 +1995,10 @@ export function listRunning( | ||
| 1995 | 1995 | })); |
| 1996 | 1996 | } |
| 1997 | 1997 | |
| 1998 | /** Keep a finished run's first error line (see `runs/error_line.ts`) beside it. */ | |
| 1998 | /** | |
| 1999 | * Keep the line that says why a finished run failed (`logs/findings.ts`) beside it; `at` is 0 when | |
| 2000 | * its log does not hold it. | |
| 2001 | */ | |
| 1999 | 2002 | export function setRunErrorLine(db: Database, runId: string, text: string, at: number): void { |
| 2000 | 2003 | db.query("UPDATE run SET error_line = ?2, error_at = ?3 WHERE id = ?1").run(runId, text, at); |
| 2001 | 2004 | } |
src/http/check_text.ts +11 −3
| @@ -1,8 +1,10 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * GET /:owner/:name/pulls/:number/check.txt — a pull's latest check as plain |
| 3 | 3 | * text, for a script or an agent. Line 1 is pending, green or red; line 2 is |
| 4 | * `head: <oid>`; on red, a blank line and the last 80 lines of the log, but | |
| 5 | * only when the log door (`runLog`) would show that reader the log. | |
| 4 | * `head: <oid>`; on red, a blank line, what failed (`logs/findings.ts`: each | |
| 5 | * failing test with the end of its own output), a blank line, and the last 80 | |
| 6 | * lines of the log, but only when the log door (`runLog`) would show that | |
| 7 | * reader the log. | |
| 6 | 8 | * |
| 7 | 9 | * `?wait=S` (S in 1..120) holds the request until the latest check's verdict |
| 8 | 10 | * differs from the one it began with, or S seconds pass, then answers the same |
| @@ -16,6 +18,7 @@ | ||
| 16 | 18 | import { getRepoRun, runLog } from "../actions/runs.ts"; |
| 17 | 19 | import { restoreRunLog } from "../runs/archive.ts"; |
| 18 | 20 | import { readRunLogTail } from "../runs/log.ts"; |
| 21 | import { findingsOf } from "../logs/findings.ts"; | |
| 19 | 22 | import { checkSummary } from "../core/runs.ts"; |
| 20 | 23 | import { loadPull } from "./api.ts"; |
| 21 | 24 | import type { Ctx } from "./context.ts"; |
| @@ -162,7 +165,12 @@ async function tailRead( | ||
| 162 | 165 | const log = await runLog(ctx.app, ctx.auth.user, v.repo, run.id, TAIL_MAX); |
| 163 | 166 | lines = log.ok && !log.value.logHidden ? log.value.lines : []; |
| 164 | 167 | } |
| 165 | return lines.slice(-TAIL_MAX); | |
| 168 | if (lines.length === 0) return []; | |
| 169 | const tail = lines.slice(-TAIL_MAX); | |
| 170 | // What failed first: the tail is often the tally or a teardown, far below it. One the tail | |
| 171 | // already shows with nothing to add is not said twice. | |
| 172 | const why = findingsOf(run, tail).filter((f) => f.detail.length > 0 || !tail.some((l) => l.trim() === f.says)); | |
| 173 | return why.length === 0 ? tail : [...why.flatMap((f) => [f.says, ...f.detail]), "", ...tail]; | |
| 166 | 174 | } |
| 167 | 175 | |
| 168 | 176 | async function read(ctx: Ctx): Promise<(Reading & { pullId: string }) | Response> { |
src/logs/findings.ts added +93
| @@ -0,0 +1,93 @@ | ||
| 1 | /** | |
| 2 | * The lines of a failed run's log that say why it failed, most telling first: one answer for the | |
| 3 | * feed's post, check.txt and whoever reads a log next. A check's failing tests are the ones its own | |
| 4 | * report named; otherwise the line the run's verdict quotes, or the last line that states an error. | |
| 5 | * A word in passing ("0 failed", a passing test named for an error) is never an answer: in seven of | |
| 6 | * eight saved red checks of the forge, the first such word had nothing to do with the failure. | |
| 7 | * | |
| 8 | * Every word is masked here, as a log line is (`redactHeld`), and before any cut: half a secret | |
| 9 | * matches nothing. No caller masks again. | |
| 10 | */ | |
| 11 | ||
| 12 | import type { Run } from "../core/runs.ts"; | |
| 13 | import { isSummaryLine } from "../checks/bun-test.ts"; | |
| 14 | import { FAIL } from "../checks/gate_tests.ts"; | |
| 15 | import { redactHeld } from "../kernel/log.ts"; | |
| 16 | import { clip } from "../text/clip.ts"; | |
| 17 | import { logLevel } from "./level.ts"; | |
| 18 | ||
| 19 | export interface Finding { | |
| 20 | /** What broke, in one line. */ | |
| 21 | readonly says: string; | |
| 22 | /** Its own output, when the check kept it: at most {@link DETAIL_LINES}, ending at the failure. */ | |
| 23 | readonly detail: readonly string[]; | |
| 24 | /** Its 1-based number in `lines`; null when they do not hold it. */ | |
| 25 | readonly line: number | null; | |
| 26 | } | |
| 27 | ||
| 28 | export const FINDINGS_MAX = 5; | |
| 29 | export const DETAIL_LINES = 12; | |
| 30 | const SAYS_MAX = 400; | |
| 31 | ||
| 32 | // eslint-disable-next-line no-control-regex | |
| 33 | const ANSI = /\x1b\[[0-?]*[ -/]*[@-~]/g; | |
| 34 | const HEADER = /^(\S+\.test\.[cm]?[jt]sx?):$/; | |
| 35 | /** How a run's log ends when it failed: its verdict, often another line's words, cut. */ | |
| 36 | const VERDICT = "failed: "; | |
| 37 | /** `error: x`, `fatal: x`, `TypeError: x`, `a.ts(1,2): error TS2322: x`. */ | |
| 38 | const STATED = /^(?:Uncaught )?(?:error|fatal|panic|(?:[A-Za-z]\w*)?(?:Error|Exception))(?:\[[^\]]*\]|\([^)]*\))?: |: error TS\d+: /; | |
| 39 | ||
| 40 | const say = (text: string): string => clip(redactHeld(text), SAYS_MAX); | |
| 41 | ||
| 42 | const statesError = (line: string): boolean => STATED.test(line) || logLevel(line) === "error"; | |
| 43 | ||
| 44 | /** | |
| 45 | * The line each failing test failed at: under its own file's header first, then anywhere (a | |
| 46 | * sharded log may keep only the tally). Null when the lines do not hold it. | |
| 47 | */ | |
| 48 | function failLines(lines: readonly string[]): (name: string, file: string | undefined) => number | null { | |
| 49 | const own = new Map<string, number>(); | |
| 50 | const any = new Map<string, number>(); | |
| 51 | let file = ""; | |
| 52 | lines.forEach((line, i) => { | |
| 53 | const header = HEADER.exec(line); | |
| 54 | if (header !== null) file = header[1]!.replace(/^\.\//, ""); | |
| 55 | else if (isSummaryLine(line)) file = ""; | |
| 56 | const name = FAIL.exec(line)?.[1]; | |
| 57 | if (name === undefined) return; | |
| 58 | if (!any.has(name)) any.set(name, i + 1); | |
| 59 | if (file !== "" && !own.has(`${file}\0${name}`)) own.set(`${file}\0${name}`, i + 1); | |
| 60 | }); | |
| 61 | return (name, of) => own.get(`${of ?? ""}\0${name}`) ?? any.get(name) ?? null; | |
| 62 | } | |
| 63 | ||
| 64 | /** The verdict's line, and the line it quotes when one above it does. */ | |
| 65 | function verdictOf(lines: readonly string[]): { at: number; quotes: number } | undefined { | |
| 66 | const at = lines.findLastIndex((l) => l.startsWith(VERDICT)); | |
| 67 | if (at === -1) return undefined; | |
| 68 | const said = lines[at]!.slice(VERDICT.length).replace(/…$/, "").trim(); | |
| 69 | return { at, quotes: said === "" ? -1 : lines.findLastIndex((l, i) => i < at && l.trim().startsWith(said)) }; | |
| 70 | } | |
| 71 | ||
| 72 | /** Why a failed run failed, at most {@link FINDINGS_MAX}; empty when no line says. */ | |
| 73 | export function findingsOf(run: Pick<Run, "kind" | "state" | "checkDetail">, log: readonly string[]): Finding[] { | |
| 74 | if (run.state !== "failed") return []; | |
| 75 | const lines = log.map((l) => l.replace(ANSI, "")); | |
| 76 | const detail = run.checkDetail; | |
| 77 | const tests: readonly { name: string; file?: string; assertion?: string; excerpt?: readonly string[] }[] = | |
| 78 | detail?.failures !== undefined && detail.failures.length > 0 ? detail.failures : (detail?.names ?? []).map((name) => ({ name })); | |
| 79 | if (tests.length > 0) { | |
| 80 | const lineOf = failLines(lines); | |
| 81 | return tests.slice(0, FINDINGS_MAX).map((t) => ({ | |
| 82 | says: say(t.assertion === undefined ? t.name : `${t.name}: ${t.assertion}`), | |
| 83 | detail: (t.excerpt ?? []).slice(-DETAIL_LINES).map((l) => redactHeld(l)), | |
| 84 | // The log holds the name as it was masked on the way in. | |
| 85 | line: lineOf(t.name, t.file) ?? lineOf(redactHeld(t.name), t.file), | |
| 86 | })); | |
| 87 | } | |
| 88 | const verdict = verdictOf(lines); | |
| 89 | // A check's output is full of errors its tests made on purpose: only its verdict speaks for it. | |
| 90 | const stated = run.kind === "check" ? -1 : lines.findLastIndex((l) => !l.startsWith(VERDICT) && statesError(l.trim())); | |
| 91 | const at = [verdict?.quotes ?? -1, stated, verdict?.at ?? -1].find((i) => i !== -1); | |
| 92 | return at === undefined ? [] : [{ says: say(lines[at]!.trim()), detail: [], line: at + 1 }]; | |
| 93 | } |
src/logs/level.ts added +22
| @@ -0,0 +1,22 @@ | ||
| 1 | /** The level a log line states of itself, read the same wherever a log is drawn or searched. */ | |
| 2 | ||
| 3 | /** A timestamp a log line may open with: `2026-01-02T03:04:05Z`, `[03:04:05.123]`. */ | |
| 4 | const STAMP = /^\s*\[?(?:\d{4}-\d\d-\d\d[T ])?\d\d:\d\d:\d\d(?:[.,]\d+)?(?:Z|[+-]\d\d:?\d\d)?\]?[\s:|-]*/; | |
| 5 | const BARE = /^(ERROR|ERR|FATAL|CRITICAL|CRIT|PANIC|WARN|WARNING|DEBUG|TRACE)(?![A-Za-z0-9_])/; | |
| 6 | const BRACKET = /^[[(<](error|err|fatal|critical|crit|panic|warn|warning|debug|trace)[\])>]/i; | |
| 7 | const LOGFMT = /^(?:\S+=\S+\s+){0,4}level=(error|err|fatal|warn|warning|debug|trace)\b/i; | |
| 8 | ||
| 9 | /** | |
| 10 | * The level a log line states in its first token (after an optional timestamp): | |
| 11 | * `ERROR x`, `[warn] x`, `level=error x`. Prose that merely mentions a word | |
| 12 | * ("no errors found", "0 failed") has none. | |
| 13 | */ | |
| 14 | export function logLevel(line: string): "error" | "warn" | "debug" | undefined { | |
| 15 | const rest = line.replace(STAMP, ""); | |
| 16 | const word = BARE.exec(rest)?.[1] ?? BRACKET.exec(rest)?.[1] ?? LOGFMT.exec(line)?.[1]; | |
| 17 | if (word === undefined) return undefined; | |
| 18 | const w = word.toLowerCase(); | |
| 19 | if (w.startsWith("warn")) return "warn"; | |
| 20 | if (w === "debug" || w === "trace") return "debug"; | |
| 21 | return "error"; | |
| 22 | } |
src/runs/error_line.ts deleted −30
| @@ -1,30 +0,0 @@ | ||
| 1 | /** | |
| 2 | * The line of a run's log that says what broke: the first one carrying an | |
| 3 | * error or fail marker, and its 1-based place in the lines `readRunLog` | |
| 4 | * returns — the same count the run page numbers its rows by (`#L<n>`). | |
| 5 | * Read once, when the run finishes, and kept with the event; the feed never | |
| 6 | * opens a log. | |
| 7 | */ | |
| 8 | ||
| 9 | import { clip } from "../text/clip.ts"; | |
| 10 | ||
| 11 | /** bun's `(fail)`, `error:`, `Error`, `failed`, `failure` — as words, any case. */ | |
| 12 | const MARKER = /\(fail\)|\b(?:error|fail(?:ed|ure|s)?)\b/i; | |
| 13 | ||
| 14 | export const ERROR_LINE_MAX = 120; | |
| 15 | ||
| 16 | export interface ErrorLine { | |
| 17 | /** The line, trimmed and cut to `ERROR_LINE_MAX`. */ | |
| 18 | text: string; | |
| 19 | /** Its 1-based number in the log. */ | |
| 20 | at: number; | |
| 21 | } | |
| 22 | ||
| 23 | export function firstErrorLine(lines: readonly string[]): ErrorLine | undefined { | |
| 24 | for (let i = 0; i < lines.length; i++) { | |
| 25 | const text = lines[i]!.trim(); | |
| 26 | if (text !== "" && MARKER.test(text)) | |
| 27 | return { text: clip(text, ERROR_LINE_MAX), at: i + 1 }; | |
| 28 | } | |
| 29 | return undefined; | |
| 30 | } |
src/tui/screens/workspace_kinds.ts +1 −1
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | |
| 11 | 11 | import { parseNotebook } from "../../web/render/notebook.ts"; |
| 12 | 12 | import { parseJsonl } from "../../web/render/jsonl-parse.ts"; |
| 13 | import { logLevel } from "../../web/render/log.ts"; | |
| 13 | import { logLevel } from "../../logs/level.ts"; | |
| 14 | 14 | import { ansiLines } from "../../web/render/ansi.ts"; |
| 15 | 15 | import type { Table } from "../../text/csv.ts"; |
| 16 | 16 | import type { Span } from "../term/screen.ts"; |
src/web/render/log.ts +1 −21
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | /** A terminal log (.log, .ansi) with its colours, laid out as the code view is. */ |
| 2 | 2 | |
| 3 | import { logLevel } from "../../logs/level.ts"; | |
| 3 | 4 | import { html, raw } from "../html.ts"; |
| 4 | 5 | import { btn, empty } from "../ui.ts"; |
| 5 | 6 | import { ansiLines } from "./ansi.ts"; |
| @@ -77,24 +78,3 @@ export function log(input: RenderInput): Rendered { | ||
| 77 | 78 | : html``}`, |
| 78 | 79 | }; |
| 79 | 80 | } |
| 80 | ||
| 81 | /** A timestamp a log line may open with: `2026-01-02T03:04:05Z`, `[03:04:05.123]`. */ | |
| 82 | const STAMP = /^\s*\[?(?:\d{4}-\d\d-\d\d[T ])?\d\d:\d\d:\d\d(?:[.,]\d+)?(?:Z|[+-]\d\d:?\d\d)?\]?[\s:|-]*/; | |
| 83 | const BARE = /^(ERROR|ERR|FATAL|CRITICAL|CRIT|PANIC|WARN|WARNING|DEBUG|TRACE)(?![A-Za-z0-9_])/; | |
| 84 | const BRACKET = /^[[(<](error|err|fatal|critical|crit|panic|warn|warning|debug|trace)[\])>]/i; | |
| 85 | const LOGFMT = /^(?:\S+=\S+\s+){0,4}level=(error|err|fatal|warn|warning|debug|trace)\b/i; | |
| 86 | ||
| 87 | /** | |
| 88 | * The level a log line states in its first token (after an optional timestamp): | |
| 89 | * `ERROR x`, `[warn] x`, `level=error x`. Prose that merely mentions a word | |
| 90 | * ("no errors found", "0 failed") has none. | |
| 91 | */ | |
| 92 | export function logLevel(line: string): "error" | "warn" | "debug" | undefined { | |
| 93 | const rest = line.replace(STAMP, ""); | |
| 94 | const word = BARE.exec(rest)?.[1] ?? BRACKET.exec(rest)?.[1] ?? LOGFMT.exec(line)?.[1]; | |
| 95 | if (word === undefined) return undefined; | |
| 96 | const w = word.toLowerCase(); | |
| 97 | if (w.startsWith("warn")) return "warn"; | |
| 98 | if (w === "debug" || w === "trace") return "debug"; | |
| 99 | return "error"; | |
| 100 | } |
test/contribute-check-text.test.ts +46
| @@ -14,6 +14,9 @@ import { verifyToken } from "../src/core/tokens.ts"; | ||
| 14 | 14 | import { createUser, type User } from "../src/core/users.ts"; |
| 15 | 15 | import { appendRunLog, flushRunLogs } from "../src/runs/log.ts"; |
| 16 | 16 | import { serve, type Servers } from "../src/http/server.ts"; |
| 17 | import { announceRun } from "../src/actions/runs.ts"; | |
| 18 | import { getRun, getRunErrorLine } from "../src/core/runs.ts"; | |
| 19 | import { holdValues, releaseValues } from "../src/kernel/log.ts"; | |
| 17 | 20 | import { quietLogs } from "./helpers/globals.ts"; |
| 18 | 21 | |
| 19 | 22 | quietLogs(); |
| @@ -107,6 +110,49 @@ test("a red check carries the last 80 lines of its log, only for a reader the lo | ||
| 107 | 110 | expect(await (await get(p.number)).text()).toBe("red\nhead: r1\n"); |
| 108 | 111 | }, SLOW); |
| 109 | 112 | |
| 113 | test("a red check says the failing test and its output above the tail, only for a reader of the log", async () => { | |
| 114 | const p = addPull("f1"); | |
| 115 | const id = run(p.id, "f1", "failed"); | |
| 116 | const excerpt = ["error: expect(received).toBe(expected)", "Expected: 1", "Received: 2", "(fail) adds [1ms]"]; | |
| 117 | app.db | |
| 118 | .query("UPDATE run SET check_detail = ? WHERE id = ?") | |
| 119 | .run(JSON.stringify({ passed: 9, failed: 1, names: ["adds"], failures: [{ file: "test/a.test.ts", name: "adds", assertion: excerpt[0], excerpt }] }), id); | |
| 120 | for (let i = 1; i <= 100; i++) appendRunLog(dataDir, id, `line ${i}`); | |
| 121 | flushRunLogs(); | |
| 122 | const text = await (await get(p.number, `forge_session=${createSession(app.db, owner).token}`)).text(); | |
| 123 | expect(text.startsWith(`red\nhead: f1\n\nadds: ${excerpt[0]}\n${excerpt.join("\n")}\n\nline 21\n`)).toBe(true); | |
| 124 | expect(text.endsWith("line 100\n")).toBe(true); | |
| 125 | expect(await (await get(p.number, bob)).text()).toBe("red\nhead: f1\n"); | |
| 126 | }, SLOW); | |
| 127 | ||
| 128 | test("a secret in a failing test's words is masked before any cut, in check.txt and in the kept line", async () => { | |
| 129 | const heldValue = "s3cr3t-Value-91x"; | |
| 130 | const shape = `forge_${"a1B2".repeat(10)}`; | |
| 131 | holdValues("check-text", [heldValue]); | |
| 132 | try { | |
| 133 | // Each assertion puts the secret across a cut: 400 in check.txt, 120 in the kept line. | |
| 134 | for (const [head, secret, at] of [["m1", heldValue, 8], ["m2", shape, 8], ["m3", heldValue, 390], ["m4", shape, 390], ["m5", heldValue, 110], ["m6", shape, 110]] as const) { | |
| 135 | const p = addPull(head); | |
| 136 | const id = run(p.id, head, "failed"); | |
| 137 | // "adds: " is six characters, and the space ends the run of x. | |
| 138 | const assertion = `${"x".repeat(at - 7)} ${secret} end`; | |
| 139 | const detail = { passed: 1, failed: 1, names: ["adds"], failures: [{ file: "test/a.test.ts", name: "adds", assertion, excerpt: [`got ${secret}`] }] }; | |
| 140 | app.db.query("UPDATE run SET check_detail = ? WHERE id = ?").run(JSON.stringify(detail), id); | |
| 141 | appendRunLog(dataDir, id, "(fail) adds [1ms]"); | |
| 142 | flushRunLogs(); | |
| 143 | announceRun(app, getRun(app.db, id)!); | |
| 144 | const text = await (await get(p.number, `forge_session=${createSession(app.db, owner).token}`)).text(); | |
| 145 | const kept = getRunErrorLine(app.db, id)!; | |
| 146 | expect(text).toContain("got [redacted]"); | |
| 147 | expect(kept.at).toBe(1); | |
| 148 | // Not even the start of it, which is what a cut before the mask leaves. | |
| 149 | for (const said of [text, kept.text]) expect(said).not.toContain(secret.slice(0, 8)); | |
| 150 | } | |
| 151 | } finally { | |
| 152 | releaseValues("check-text"); | |
| 153 | } | |
| 154 | }, SLOW); | |
| 155 | ||
| 110 | 156 | test("an unknown pull is 404", async () => { |
| 111 | 157 | expect((await get(9999)).status).toBe(404); |
| 112 | 158 | }, SLOW); |
test/feed-failed-run.test.ts +2 −11
| @@ -1,4 +1,4 @@ | ||
| 1 | /** A failed run's post names its pull or issue and its first error line, and links to that line (#5812). */ | |
| 1 | /** A failed run's post names its pull or issue and the line that says why, and links to that line (#5812). */ | |
| 2 | 2 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 3 | 3 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 4 | import { tmpdir } from "node:os"; |
| @@ -11,7 +11,6 @@ import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; | ||
| 11 | 11 | import { createSession } from "../src/core/sessions.ts"; |
| 12 | 12 | import { createToken } from "../src/core/tokens.ts"; |
| 13 | 13 | import { createUser } from "../src/core/users.ts"; |
| 14 | import { firstErrorLine } from "../src/runs/error_line.ts"; | |
| 15 | 14 | import { appendRunLog } from "../src/runs/log.ts"; |
| 16 | 15 | import { serve, type Servers } from "../src/http/server.ts"; |
| 17 | 16 | |
| @@ -56,7 +55,7 @@ describe("a failed run's feed post", () => { | ||
| 56 | 55 | }); |
| 57 | 56 | runId = run.id; |
| 58 | 57 | claimRun(app.db, run.id); |
| 59 | for (const line of ["→ read src/a.ts", "I will fix it", "error: Cannot find module './nope' from src/a.ts", "error: later"]) | |
| 58 | for (const line of ["error: one it got past", "0 failed", "error: Cannot find module './nope' from src/a.ts", "I could not fix it"]) | |
| 60 | 59 | appendRunLog(dataDir, run.id, line); |
| 61 | 60 | const done = finishRun(app.db, run.id, { state: "failed", summary: "the run failed" }); |
| 62 | 61 | announceRun(app, done!, u.value.id); |
| @@ -68,14 +67,6 @@ describe("a failed run's feed post", () => { | ||
| 68 | 67 | await rm(dataDir, { recursive: true, force: true }); |
| 69 | 68 | }); |
| 70 | 69 | |
| 71 | test("the first error marker is found, cut to 120 chars, with its line number", () => { | |
| 72 | expect(firstErrorLine(["ok", "fine"])).toBeUndefined(); | |
| 73 | expect(firstErrorLine(["a", `Error: ${"x".repeat(200)}`, "error: two"])).toEqual({ | |
| 74 | text: `Error: ${"x".repeat(112)}…`, | |
| 75 | at: 2, | |
| 76 | }); | |
| 77 | }); | |
| 78 | ||
| 79 | 70 | test("home reads the words and links to the line", async () => { |
| 80 | 71 | expect(ranOn).toBe(1); |
| 81 | 72 | const text = await (await fetch(`${servers.url}/feed`, { headers: { cookie: `${cookie}; forge_mode=studio` } })).text(); |
test/log-findings.test.ts added +86
| @@ -0,0 +1,86 @@ | ||
| 1 | /** The line that says why a run failed is the failure itself, never a word in passing. */ | |
| 2 | import { describe, expect, test } from "bun:test"; | |
| 3 | import { DETAIL_LINES, FINDINGS_MAX, findingsOf } from "../src/logs/findings.ts"; | |
| 4 | import type { CheckDetail } from "../src/core/runs.ts"; | |
| 5 | ||
| 6 | const check = (checkDetail: CheckDetail | null) => ({ kind: "check" as const, state: "failed" as const, checkDetail }); | |
| 7 | const red = (...failures: NonNullable<CheckDetail["failures"]>[number][]): CheckDetail => ({ | |
| 8 | passed: 9, failed: failures.length, names: failures.map((f) => f.name), failures, | |
| 9 | }); | |
| 10 | ||
| 11 | // The shape of a real red check (trevato/forge, 2026-12-02): what its tests print comes first. | |
| 12 | const LOG = [ | |
| 13 | "gate: took 4.2s", | |
| 14 | " 0 fail", | |
| 15 | "test/disk.test.ts:", | |
| 16 | "WARN check failed while the check machine's disk was full", | |
| 17 | "error: one a test makes on purpose", | |
| 18 | "(pass) a failed check says its error [2.00ms]", | |
| 19 | "test/other.test.ts:", | |
| 20 | "(fail) finds it [1.00ms]", | |
| 21 | "test/widgets.test.ts:", | |
| 22 | "error: expect(received).toContain(expected)", | |
| 23 | "(fail) finds it [0.63ms]", | |
| 24 | "1 tests failed:", | |
| 25 | "(fail) finds it [0.63ms]", | |
| 26 | "failed: 1 of 6418 tests — \"finds it\"", | |
| 27 | ]; | |
| 28 | ||
| 29 | describe("a check", () => { | |
| 30 | test("its failing test, at its own file's (fail) line, past every word that only looks like one", () => { | |
| 31 | const assertion = "error: expect(received).toContain(expected)"; | |
| 32 | const [found, ...more] = findingsOf(check(red({ file: "test/widgets.test.ts", name: "finds it", assertion })), LOG); | |
| 33 | expect(found).toEqual({ says: `finds it: ${assertion}`, detail: [], line: 11 }); | |
| 34 | expect(more).toEqual([]); | |
| 35 | }); | |
| 36 | ||
| 37 | test("a log that keeps only the tally points at the tally; one without the test points nowhere", () => { | |
| 38 | const detail = red({ file: "test/a.test.ts", name: "adds" }); | |
| 39 | expect(findingsOf(check(detail), ["0 failed", "(fail) adds [1ms] [shard 3]"])[0]!.line).toBe(2); | |
| 40 | expect(findingsOf(check(detail), ["0 failed"])[0]).toEqual({ says: "adds", detail: [], line: null }); | |
| 41 | }); | |
| 42 | ||
| 43 | test("a report with names alone still names them", () => { | |
| 44 | expect(findingsOf(check({ passed: 1, failed: 1, names: ["adds"] }), ["(fail) adds"])).toEqual([{ says: "adds", detail: [], line: 1 }]); | |
| 45 | }); | |
| 46 | ||
| 47 | test("a test whose own name holds a secret is found at its masked line", () => { | |
| 48 | const name = `signs in with forge_${"a1B2".repeat(10)}`; | |
| 49 | const [found] = findingsOf(check(red({ file: "test/a.test.ts", name })), ["0 failed", "(fail) signs in with [redacted]"]); | |
| 50 | expect(found).toEqual({ says: "signs in with [redacted]", detail: [], line: 2 }); | |
| 51 | }); | |
| 52 | ||
| 53 | test("at most five tests, each with the end of its own output", () => { | |
| 54 | const excerpt = Array.from({ length: 30 }, (_, i) => `out ${i}`); | |
| 55 | const found = findingsOf(check(red(...Array.from({ length: 8 }, (_, i) => ({ file: "test/a.test.ts", name: `t${i}`, excerpt })))), []); | |
| 56 | expect(found).toHaveLength(FINDINGS_MAX); | |
| 57 | expect(found[0]!.detail).toEqual(excerpt.slice(-DETAIL_LINES)); | |
| 58 | }); | |
| 59 | ||
| 60 | test("with no failing test, the line its verdict quotes, whole, not an error its tests printed", () => { | |
| 61 | const rule = `gate: rule "both doors": ${"x".repeat(300)}`; | |
| 62 | const log = ["gate: note: nothing to do", rule, "error: on purpose", `failed: ${rule.slice(0, 199)}…`]; | |
| 63 | expect(findingsOf(check(null), log)).toEqual([{ says: rule, detail: [], line: 2 }]); | |
| 64 | expect(findingsOf(check(null), ["error: on purpose", "failed: check exited with code 1"])[0]!.line).toBe(2); | |
| 65 | }); | |
| 66 | ||
| 67 | test("a log with no verdict says nothing rather than guess", () => { | |
| 68 | expect(findingsOf(check(null), ["0 failed", "(pass) a failure is one line"])).toEqual([]); | |
| 69 | expect(findingsOf({ ...check(null), state: "ok" }, LOG)).toEqual([]); | |
| 70 | }); | |
| 71 | }); | |
| 72 | ||
| 73 | describe("a deploy or an agent's run", () => { | |
| 74 | const ran = (log: string[]) => findingsOf({ kind: "deploy", state: "failed", checkDetail: null }, log); | |
| 75 | ||
| 76 | test("the last line that states an error; prose that mentions one does not", () => { | |
| 77 | expect(ran(["error: retried, fine", "TypeError: x is not a function", "no errors found, 0 failed"])[0]!.line).toBe(2); | |
| 78 | expect(ran(["a.ts(1,2): error TS2322: no", "done"])[0]!.line).toBe(1); | |
| 79 | expect(ran(["\x1b[31merror\x1b[0m: in colour"])[0]!.says).toBe("error: in colour"); | |
| 80 | expect(ran(["the failure was handled", "ok"])).toEqual([]); | |
| 81 | }); | |
| 82 | ||
| 83 | test("the verdict itself when nothing else states one", () => { | |
| 84 | expect(ran(["start", "failed: the app did not answer"])[0]!.line).toBe(2); | |
| 85 | }); | |
| 86 | }); |
test/text-clip-checks.test.ts +9 −6
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import { describe, expect, test } from "bun:test"; |
| 2 | import { ERROR_LINE_MAX, firstErrorLine } from "../src/runs/error_line.ts"; | |
| 2 | import { clip } from "../src/text/clip.ts"; | |
| 3 | import { ERROR_LINE_MAX } from "../src/actions/runs.ts"; | |
| 4 | import { findingsOf } from "../src/logs/findings.ts"; | |
| 3 | 5 | import { oneLine } from "../src/checks/words.ts"; |
| 4 | 6 | import { parseTestsRow } from "../src/checks/tests-row.ts"; |
| 5 | 7 | import { summariseCheckFailure } from "../src/checks/summary.ts"; |
| @@ -13,11 +15,12 @@ describe("the lines a red check is explained by are cut at a code point", () => | ||
| 13 | 15 | const head = "error: " + "x".repeat(ERROR_LINE_MAX - 2 - 7); |
| 14 | 16 | const line = head + "🔥" + "y".repeat(300 - head.length - 2); |
| 15 | 17 | expect(line.length).toBe(300); |
| 16 | const got = firstErrorLine([line])!; | |
| 17 | expect(got.at).toBe(1); | |
| 18 | expect(LONE_SURROGATE.test(got.text)).toBe(false); | |
| 19 | expect(got.text.endsWith("…")).toBe(true); | |
| 20 | expect(Array.from(got.text).length).toBe(ERROR_LINE_MAX); | |
| 18 | const got = findingsOf({ kind: "agent", state: "failed", checkDetail: null }, [line])[0]!; | |
| 19 | expect(got.line).toBe(1); | |
| 20 | const kept = clip(got.says, ERROR_LINE_MAX); | |
| 21 | expect(LONE_SURROGATE.test(kept)).toBe(false); | |
| 22 | expect(kept.endsWith("…")).toBe(true); | |
| 23 | expect(Array.from(kept).length).toBe(ERROR_LINE_MAX); | |
| 21 | 24 | }); |
| 22 | 25 | |
| 23 | 26 | test("a failure's one line keeps an emoji whole at its limit", () => { |
test/tui-workspace-kinds.test.ts +1 −1
| @@ -19,7 +19,7 @@ import { settleApp, settleUntil } from "./helpers/tui.ts"; | ||
| 19 | 19 | import { seedAdmin } from "./helpers/admin.ts"; |
| 20 | 20 | import { make as xcfFile } from "./helpers/xcf.ts"; |
| 21 | 21 | import { theme } from "../src/tui/ui/theme.ts"; |
| 22 | import { logLevel } from "../src/web/render/log.ts"; | |
| 22 | import { logLevel } from "../src/logs/level.ts"; | |
| 23 | 23 | import { jsonlTable, kindView, logLines, LINE_CAP, notebookLines, ROW_CAP } from "../src/tui/screens/workspace_kinds.ts"; |
| 24 | 24 | |
| 25 | 25 | quietLogs(); |
new above
offline