Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

nightly-watch: first watch opens only a still-red incident; fixture newlines

garrytan8ffee9b2d1cb
diff --git a/docs/ci-red-runbook.md b/docs/ci-red-runbook.md
index 6a68117a8a..2130d307ad 100644
--- a/docs/ci-red-runbook.md
+++ b/docs/ci-red-runbook.md
@@ -31,6 +31,8 @@ response: a repair PR whose body says `Fixes #<issue>`.
issue's JSON block. A dropped or superseded watch therefore loses nothing; a
run that completes after a newer one was evaluated is ignored; a successful
re-run is a newer attempt; a run cancelled by a newer push changes nothing.
+ The first watch for a workflow with no master-red issue yet opens only an
+ incident that is still red.
- **Missing or malformed JSON block:** the state is rebuilt from the actions API
by folding from the last green run before the newest red one. The body says
so. If the API cannot be read, the watch fails and writes nothing.
diff --git a/scripts/lib/master-red.ts b/scripts/lib/master-red.ts
index 20ffdf4e6c..6d81925e5b 100644
--- a/scripts/lib/master-red.ts
+++ b/scripts/lib/master-red.ts
@@ -331,12 +331,13 @@ async function pushRuns(client: GitHubClient, run: RunInfo): Promise<RunInfo[]>
}
/** Pending runs above the high-water mark, or a rebuilt base state plus its pending runs. */
-export function pendingRuns(state: MasterRedState | undefined, runs: RunInfo[], blank: MasterRedState, rebuildReason: string): { state: MasterRedState; pending: RunInfo[] } {
+/** `bootstrap` (no master-red issue exists yet): a past incident that already ended green is not recorded; only a still-red one opens. */
+export function pendingRuns(state: MasterRedState | undefined, runs: RunInfo[], blank: MasterRedState, rebuildReason: string, bootstrap = false): { state: MasterRedState; pending: RunInfo[] } {
const sorted = [...runs].sort((a, b) => order(a, b));
if (state) return { state, pending: sorted.filter(r => !state.evaluated || order(r, state.evaluated) > 0) };
const counted = sorted.filter(r => verdictOf(r.conclusion) !== 'ignored');
const lastRed = counted.map(r => verdictOf(r.conclusion)).lastIndexOf('red');
- if (lastRed < 0) {
+ if (lastRed < 0 || (bootstrap && verdictOf(counted.at(-1)!.conclusion) === 'green')) {
const newest = counted.at(-1);
return { state: { ...blank, evaluated: newest ? refOf(newest) : null, last_green: newest ? refOf(newest) : null, rebuilt: rebuildReason }, pending: [] };
}
@@ -357,7 +358,7 @@ export async function planMasterRed(client: GitHubClient, repo: string, run: Run
const stored = issue ? validState(readJsonBlock(issue.body, MR_MARKER), blank.workflow_file) : undefined;
const reason = !issue ? 'no master-red issue for this workflow yet' : 'the JSON block of the newest master-red issue was missing or malformed';
const runs = await pushRuns(client, run);
- const { state: base, pending } = pendingRuns(stored, runs, blank, reason);
+ const { state: base, pending } = pendingRuns(stored, runs, blank, reason, !issue);
let state = base;
const evaluated: number[] = [];
const closed: MasterRedState[] = [];
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111876367226.json b/test/fixtures/nightly-watch/master-red/annotations-111876367226.json
index d447524142..53af11a36e 100644
--- a/test/fixtures/nightly-watch/master-red/annotations-111876367226.json
+++ b/test/fixtures/nightly-watch/master-red/annotations-111876367226.json
@@ -23,4 +23,4 @@
"title": "error: expect(received).toEqual(expected)",
"message": " {\n- \"future\": true,\n+ \"future\": false,\n \"state\": \"queued\",\n }\n\n- Expected - 1\n+ Received + 1\n\n at <anonymous> (/home/runner/work/gbrain/gbrain/test/persistence-history-fixture.test.ts:55:28)"
}
-]
\ No newline at end of file
+]
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111882475890.json b/test/fixtures/nightly-watch/master-red/annotations-111882475890.json
index 82f8f9fdde..2b5cf27a83 100644
--- a/test/fixtures/nightly-watch/master-red/annotations-111882475890.json
+++ b/test/fixtures/nightly-watch/master-red/annotations-111882475890.json
@@ -5,4 +5,4 @@
"title": "",
"message": "Process completed with exit code 1."
}
-]
\ No newline at end of file
+]
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111902484298.json b/test/fixtures/nightly-watch/master-red/annotations-111902484298.json
index 3cae8b06d1..9ac4751a25 100644
--- a/test/fixtures/nightly-watch/master-red/annotations-111902484298.json
+++ b/test/fixtures/nightly-watch/master-red/annotations-111902484298.json
@@ -65,4 +65,4 @@
"title": "PostgresError: expected 8 dimensions, not 1536",
"message": "\n at ErrorResponse (/home/runner/work/gbrain/gbrain/vendor/postgres/src/connection.js:833:30)\n at handle (/home/runner/work/gbrain/gbrain/vendor/postgres/src/connection.js:503:7)\n at data (/home/runner/work/gbrain/gbrain/vendor/postgres/src/connection.js:330:9)\n at emit (node:events:100:22)\n at addChunk (internal:streams/readable:267:47)\n at readableAddChunkPushByteMode (internal:streams/readable:245:18)\n at data (node:net:633:72)"
}
-]
\ No newline at end of file
+]
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111902768521.json b/test/fixtures/nightly-watch/master-red/annotations-111902768521.json
index f5766cbb28..10a6b3f8cb 100644
--- a/test/fixtures/nightly-watch/master-red/annotations-111902768521.json
+++ b/test/fixtures/nightly-watch/master-red/annotations-111902768521.json
@@ -23,4 +23,4 @@
"title": "error: ENOENT: no such file or directory, open '/tmp/gbrain-managed-lint-R0xjr9/brain/people/jane-doe.md'",
"message": "\n at runLintCore (/home/runner/work/gbrain/gbrain/src/commands/lint.ts:757:21)\n at async lintCollecting (/home/runner/work/gbrain/gbrain/test/managed-lint.test.ts:199:24)\n at async <anonymous> (/home/runner/work/gbrain/gbrain/test/managed-lint.test.ts:284:41)\n at async <anonymous> (/home/runner/work/gbrain/gbrain/test/managed-lint.test.ts:61:15)\n at async withEnv (/home/runner/work/gbrain/gbrain/test/helpers/with-env.ts:68:18)\n at async fixture (/home/runner/work/gbrain/gbrain/test/managed-lint.test.ts:56:13)\n at async <anonymous> (/home/runner/work/gbrain/gb"
}
-]
\ No newline at end of file
+]
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111909257450.json b/test/fixtures/nightly-watch/master-red/annotations-111909257450.json
index 82f8f9fdde..2b5cf27a83 100644
--- a/test/fixtures/nightly-watch/master-red/annotations-111909257450.json
+++ b/test/fixtures/nightly-watch/master-red/annotations-111909257450.json
@@ -5,4 +5,4 @@
"title": "",
"message": "Process completed with exit code 1."
}
-]
\ No newline at end of file
+]
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111909670183.json b/test/fixtures/nightly-watch/master-red/annotations-111909670183.json
index 82f8f9fdde..2b5cf27a83 100644
--- a/test/fixtures/nightly-watch/master-red/annotations-111909670183.json
+++ b/test/fixtures/nightly-watch/master-red/annotations-111909670183.json
@@ -5,4 +5,4 @@
"title": "",
"message": "Process completed with exit code 1."
}
-]
\ No newline at end of file
+]
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111914484195.json b/test/fixtures/nightly-watch/master-red/annotations-111914484195.json
index 6a5d9871bb..c56b19a5cc 100644
--- a/test/fixtures/nightly-watch/master-red/annotations-111914484195.json
+++ b/test/fixtures/nightly-watch/master-red/annotations-111914484195.json
@@ -23,4 +23,4 @@
"title": "PageProjectionConflictError: The page projection changed during preparation. Read its current snapshot before retrying.",
"message": "\n at <anonymous> (/home/runner/work/gbrain/gbrain/src/core/page-state/projections.ts:146:13)"
}
-]
\ No newline at end of file
+]
diff --git a/test/fixtures/nightly-watch/master-red/annotations-111921205893.json b/test/fixtures/nightly-watch/master-red/annotations-111921205893.json
index 82f8f9fdde..2b5cf27a83 100644
--- a/test/fixtures/nightly-watch/master-red/annotations-111921205893.json
+++ b/test/fixtures/nightly-watch/master-red/annotations-111921205893.json
@@ -5,4 +5,4 @@
"title": "",
"message": "Process completed with exit code 1."
}
-]
\ No newline at end of file
+]
diff --git a/test/fixtures/nightly-watch/master-red/ci-manifest-37351182593.json b/test/fixtures/nightly-watch/master-red/ci-manifest-37351182593.json
index 858a2ed906..678cae616e 100644
--- a/test/fixtures/nightly-watch/master-red/ci-manifest-37351182593.json
+++ b/test/fixtures/nightly-watch/master-red/ci-manifest-37351182593.json
@@ -171,4 +171,4 @@
"arm": "postgres-direct"
}
]
-}
\ No newline at end of file
+}
diff --git a/test/fixtures/nightly-watch/master-red/ci-manifest-37354832141.json b/test/fixtures/nightly-watch/master-red/ci-manifest-37354832141.json
index 1b5622e666..3e17173e3f 100644
--- a/test/fixtures/nightly-watch/master-red/ci-manifest-37354832141.json
+++ b/test/fixtures/nightly-watch/master-red/ci-manifest-37354832141.json
@@ -90,4 +90,4 @@
}
],
"failures": []
-}
\ No newline at end of file
+}
diff --git a/test/fixtures/nightly-watch/master-red/commit-pulls.json b/test/fixtures/nightly-watch/master-red/commit-pulls.json
index 24b6139998..dd3f6feea0 100644
--- a/test/fixtures/nightly-watch/master-red/commit-pulls.json
+++ b/test/fixtures/nightly-watch/master-red/commit-pulls.json
@@ -35,4 +35,4 @@
}
}
]
-}
\ No newline at end of file
+}
diff --git a/test/fixtures/nightly-watch/master-red/compare-cab092f5cd...df34c67af6.json b/test/fixtures/nightly-watch/master-red/compare-cab092f5cd...df34c67af6.json
index f9ef3f5c09..a6e3adfb07 100644
--- a/test/fixtures/nightly-watch/master-red/compare-cab092f5cd...df34c67af6.json
+++ b/test/fixtures/nightly-watch/master-red/compare-cab092f5cd...df34c67af6.json
@@ -15,4 +15,4 @@
"sha": "df34c67af680052dbfb612a994e2d56aaee61cb8"
}
]
-}
\ No newline at end of file
+}
diff --git a/test/fixtures/nightly-watch/master-red/jobs-37343551740.json b/test/fixtures/nightly-watch/master-red/jobs-37343551740.json
index d496b199f3..9830d06b5c 100644
--- a/test/fixtures/nightly-watch/master-red/jobs-37343551740.json
+++ b/test/fixtures/nightly-watch/master-red/jobs-37343551740.json
@@ -482,4 +482,4 @@
]
}
]
-}
\ No newline at end of file
+}
diff --git a/test/fixtures/nightly-watch/master-red/jobs-37351182593.json b/test/fixtures/nightly-watch/master-red/jobs-37351182593.json
index 030a41a3d9..a5c4e44466 100644
--- a/test/fixtures/nightly-watch/master-red/jobs-37351182593.json
+++ b/test/fixtures/nightly-watch/master-red/jobs-37351182593.json
@@ -140,4 +140,4 @@
]
}
]
-}
\ No newline at end of file
+}
diff --git a/test/fixtures/nightly-watch/master-red/jobs-37351183194.json b/test/fixtures/nightly-watch/master-red/jobs-37351183194.json
index 2924105c3f..0436513047 100644
--- a/test/fixtures/nightly-watch/master-red/jobs-37351183194.json
+++ b/test/fixtures/nightly-watch/master-red/jobs-37351183194.json
@@ -482,4 +482,4 @@
]
}
]
-}
\ No newline at end of file
+}
diff --git a/test/fixtures/nightly-watch/master-red/jobs-37354832141.json b/test/fixtures/nightly-watch/master-red/jobs-37354832141.json
index 861a856c57..5b373e5f94 100644
--- a/test/fixtures/nightly-watch/master-red/jobs-37354832141.json
+++ b/test/fixtures/nightly-watch/master-red/jobs-37354832141.json
@@ -128,4 +128,4 @@
"steps": []
}
]
-}
\ No newline at end of file
+}
diff --git a/test/fixtures/nightly-watch/master-red/jobs-37354832822.json b/test/fixtures/nightly-watch/master-red/jobs-37354832822.json
index a1312fb0d6..f309b212f3 100644
--- a/test/fixtures/nightly-watch/master-red/jobs-37354832822.json
+++ b/test/fixtures/nightly-watch/master-red/jobs-37354832822.json
@@ -482,4 +482,4 @@
]
}
]
-}
\ No newline at end of file
+}
diff --git a/test/fixtures/nightly-watch/master-red/jobs-37358088371.json b/test/fixtures/nightly-watch/master-red/jobs-37358088371.json
index c186fb5d22..9efdd18339 100644
--- a/test/fixtures/nightly-watch/master-red/jobs-37358088371.json
+++ b/test/fixtures/nightly-watch/master-red/jobs-37358088371.json
@@ -470,4 +470,4 @@
"steps": []
}
]
-}
\ No newline at end of file
+}
diff --git a/test/fixtures/nightly-watch/master-red/runs-e2e-push.json b/test/fixtures/nightly-watch/master-red/runs-e2e-push.json
index 9fa46ef80a..54e7bd6559 100644
--- a/test/fixtures/nightly-watch/master-red/runs-e2e-push.json
+++ b/test/fixtures/nightly-watch/master-red/runs-e2e-push.json
@@ -170,4 +170,4 @@
}
}
]
-}
\ No newline at end of file
+}
diff --git a/test/fixtures/nightly-watch/master-red/runs-test-push.json b/test/fixtures/nightly-watch/master-red/runs-test-push.json
index 8ed19581be..a9b00fd2d6 100644
--- a/test/fixtures/nightly-watch/master-red/runs-test-push.json
+++ b/test/fixtures/nightly-watch/master-red/runs-test-push.json
@@ -170,4 +170,4 @@
}
}
]
-}
\ No newline at end of file
+}
diff --git a/test/scripts/nightly-issue.test.ts b/test/scripts/nightly-issue.test.ts
index a6cd790ad1..cc844147cc 100644
--- a/test/scripts/nightly-issue.test.ts
+++ b/test/scripts/nightly-issue.test.ts
@@ -434,7 +434,13 @@ describe('master-red: push-to-master runs', () => {
});
test('red then green with the red run\'s watch dropped still records the incident, its suspect range and flake follow-ups', async () => {
- const w = testWorld(T.g8315, T.r8320, T.g8352);
+ const w = testWorld(T.g8315);
+ await go(w, T.g8315);
+ expect(w.issues).toHaveLength(0);
+ const g = { run_id: T.g8315.id, run_number: 8315, run_attempt: 1, sha: T.g8315.head_sha };
+ const prior = { schema: 'master-red/v1', workflow: 'Test', workflow_file: 'test.yml', evaluated: g, status: 'green', first_red: null, latest_red: null, last_green: g, suspect: null, open_jobs: [], open_files: [], failed_jobs: [], tests: [], evidence: null, blocked: [] };
+ w.issues.push({ number: 90, title: 'Master red: Test', state: 'closed', labels: [{ name: 'master-red' }], body: jsonBlock(MR_MARKER, prior), created: 0, comments: [] });
+ w.addRun(T.r8320, `jobs-${T.r8320.id}.json`).addRun(T.g8352, `jobs-${T.g8352.id}.json`);
const r = await go(w, T.g8352);
expect(r.masterRed!.action).toBe('record-closed');
const issue = masterIssue(w)!;
@@ -444,9 +450,19 @@ describe('master-red: push-to-master runs', () => {
expect(w.labeled('flake').map(f => f.title)).toEqual(['Flake: test/persistence-history-fixture.test.ts']);
});
- test('an out-of-order red (completing after a newer run was evaluated) is ignored', async () => {
+ test('the first watch ever (no master-red issue yet) opens only a still-red incident, never one that already ended green', async () => {
const w = testWorld(T.g8315, T.r8320, T.g8352);
+ const r = await go(w, T.g8352);
+ expect(r.masterRed!.action).toBe('none');
+ expect(w.issues).toHaveLength(0);
+ });
+
+ test('an out-of-order red (completing after a newer run was evaluated) is ignored', async () => {
+ const w = testWorld(T.g8315, T.r8320);
+ await go(w, T.r8320);
+ w.addRun(T.g8352, `jobs-${T.g8352.id}.json`);
await go(w, T.g8352);
+ expect(mrState(masterIssue(w)!).evaluated!.run_number).toBe(8352);
const before = JSON.stringify(w.issues);
w.addRun(T.r8343, `jobs-${T.r8343.id}.json`);
const r = await go(w, T.r8343);