diff --git a/README.md b/README.md index ebedcae..3d0b924 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ In Docker, prefix with `docker compose run --rm hub node src/hub-cli.ts …` (or | `deployBy` | Per project and target branch, `"tag"` when that branch deploys from release tags: `{"group/repo": {"production": "tag"}}`. Default: deploys on merge. | | `gas.mode`, `gas.graceSeconds` | `dry` or `live`; seconds to undo an action. | | `notify` | `telegramChatId`, `boardUrl` for links, `remindHours`. | +| `devops` | `{"users": ["gitlab-user"], "rules": ["R9", "R13"]}`: who owns deploy setup. A `bad` or `todo` finding that cites one of `rules` (default R9, R13) or points at a CI file, Dockerfile, compose file or manifest tags them, once until the deploy findings go away. | ### `board.json` diff --git a/docs/SPEC.md b/docs/SPEC.md index b409bbd..237d55e 100644 --- a/docs/SPEC.md +++ b/docs/SPEC.md @@ -130,3 +130,4 @@ Detailed when it starts. Known shape: `depends_on` stored as data; a NO-GO propa - 2026-11-06: fixed two-row lanes; Beres keeps four boats first-in-first-out; only Dicek and Siap gas resize. - 2026-11-06: v0.1 released as open source (AGPL-3.0); one Docker image, configuration in `LABUH_HOME`. - 2026-11-06: the hosted reviewer runs in its own container without GitLab tokens, since Codex's sandbox cannot run inside Docker (Sen chose this over hosting without Docker). +- 2026-11-09: deploy setup (CI, Dockerfiles, compose, manifests) belongs to devops (rubric R13). Deploy findings tag the `devops` users from hub.json instead of asking the developer to change CI; the reviewer never suggests CI edits to the developer (Sen, after lti-api !1380). diff --git a/rubric/rubric.md b/rubric/rubric.md index 04e9b99..b10ba83 100644 --- a/rubric/rubric.md +++ b/rubric/rubric.md @@ -50,3 +50,8 @@ Breaks: a rerun changes data again, double counts, or produces a different resul ## R12 · Corrections check what they overwrite A data correction writes only rows it has identified by stable business keys (document number, code), and checks that each value it replaces is still the expected old value before writing (compare first, or `WHERE value = old`). `todo` when it overwrites without checking the old value, or when it relies on a hardcoded database id (user, company, warehouse, actor) that is not resolved or checked in the target environment. Breaks: a hardcoded id decides which rows are changed and is not checked against the target environment. + +## R13 · Deploy setup belongs to devops +How the application is built, shipped and run is owned by devops, not by the MR's developer: CI files, Dockerfiles, compose files, deploy scripts and manifests, runners, registries, servers and CI variables. Cite R13 on every `bad` or `todo` finding about them, in addition to the rule that decides its kind (a deploy order that breaks is still `bad` under R9). The text says what is wrong, never how to change the CI or deploy setup: devops is tagged and fixes it, and the developer should not edit deploy setup to pass review. +When the MR itself changes deploy setup, add a `todo` citing R13 that devops must check that change, even when it looks right. +Answers to mentions follow the same rule: deploy and CI questions go to devops; do not suggest CI edits to the developer. diff --git a/src/hub.ts b/src/hub.ts index 369707d..911d64a 100644 --- a/src/hub.ts +++ b/src/hub.ts @@ -8,7 +8,7 @@ import type { ReviewOutcome, Reviewer, Session } from './review.ts'; import type { Checked } from './contract.ts'; import { Store, type Ajuan, type OutboxItem, type QueuedEvent, type Release, type ReleaseChanges } from './store.ts'; import { latestTag, nextTag, releaseNotes, tagProblem } from './release.ts'; -import { verdictComment, errorComment, replyComment, rereviewComment, decisionComment, gasComment, closeComment, ajuanNote, VERDICT_MARKER, type Stamp } from './render.ts'; +import { verdictComment, errorComment, replyComment, rereviewComment, devopsComment, needsDevops, decisionComment, gasComment, closeComment, ajuanNote, VERDICT_MARKER, type Stamp } from './render.ts'; export type HubConfig = { mode: 'shadow' | 'live'; @@ -24,10 +24,14 @@ export type HubConfig = { gas?: { mode: 'dry' | 'live'; graceSeconds: number }; // Notifications to the approver (M3). Without a Telegram chat they only go to the Hub's log. notify?: { telegramChatId: string | null; boardUrl: string; remindHours: number }; + // Deploy setup belongs to devops: these GitLab users are tagged when a bad or todo finding + // cites one of `rules` or points at a deploy file (CI, Dockerfile, compose, manifests). + devops?: { users: string[]; rules?: string[] }; }; type DeployBy = 'merge' | 'tag'; +const DEVOPS_RULES = ['R9', 'R13']; const GAS_DEFAULT = { mode: 'dry' as const, graceSeconds: 15 }; const NOTIFY_DEFAULT = { telegramChatId: null, boardUrl: 'http://localhost:4810', remindHours: 4 }; // Pipelines are checked at most this often; a deploy that has not finished after DEPLOY_LIMIT is reported. @@ -216,6 +220,11 @@ export class Hub { } } + private devopsFor(c: Checked): string[] { + const d = this.config.devops; + return d?.users.length && needsDevops(c, d.rules ?? DEVOPS_RULES) ? d.users : []; + } + private stamp(a: Ajuan, s: Session | null, sha?: string): Stamp { return { reviewer: this.reviewer.name, sha: sha ?? a.reviewed_sha ?? a.head_sha, model: s?.model ?? this.reviewer.model ?? 'default', effort: this.reviewer.effort, rubricVersion: s?.rubricVersion ?? '-' }; } @@ -265,12 +274,20 @@ export class Hub { this.notify(`error:${a.id}:${mr.sha}`, a, `⚪ ${this.label(a)} perlu dicek manual: ${this.reviewer.name} gagal memberi hasil yang valid.`); return `reviewer error setelah ${out.attempts} percobaan`; } + const devops = this.devopsFor(out.checked); + // Devops is told once when deploy findings appear, not again on every push while they stay. + const before = a.verdict_json ? (JSON.parse(a.verdict_json) as Checked) : null; + const tellDevops = devops.length > 0 && !(before && this.devopsFor(before).length); + const hadVerdictNote = this.store.outbox(a.id).some((o) => o.kind === 'verdict'); this.store.update(a.id, { status: out.checked.verdict, reviewed_sha: mr.sha, rubric_version: s.rubricVersion, verdict_json: JSON.stringify(out.checked), tokens }); - await this.publishVerdict(this.store.ajuanById(a.id), verdictComment(out.checked, this.stamp(a, s, mr.sha))); + await this.publishVerdict(this.store.ajuanById(a.id), verdictComment(out.checked, this.stamp(a, s, mr.sha), devops)); + const noteId = this.store.outbox(a.id).find((o) => o.kind === 'verdict')?.note_id; + const verdictUrl = noteId ? `${a.web_url}#note_${noteId}` : null; if (previous) { - const noteId = this.store.outbox(a.id).find((o) => o.kind === 'verdict')?.note_id; - const verdictUrl = noteId ? `${a.web_url}#note_${noteId}` : null; - await this.publishReply(a, rereviewComment(out.checked, { sha: mr.sha, author: a.author, reviewer: this.reviewer.name, verdictUrl, rubricChanged: previous === mr.sha })); + await this.publishReply(a, rereviewComment(out.checked, { sha: mr.sha, author: a.author, reviewer: this.reviewer.name, verdictUrl, rubricChanged: previous === mr.sha, devops: tellDevops ? devops : [] })); + } else if (tellDevops && hadVerdictNote) { + // An edited verdict note notifies nobody, so the mention goes in a note of its own. + await this.publishReply(a, devopsComment(devops, verdictUrl)); } if (out.checked.verdict === 'go') this.notify(`ready:${a.id}:${mr.sha}`, a, `🟢 ${this.label(a)} siap gas: ${out.checked.reason}`); return `${out.checked.verdict} di ${mr.sha.slice(0, 8)}${out.attempts > 1 ? ' (percobaan ke-2)' : ''}`; diff --git a/src/render.ts b/src/render.ts index d65cef4..b905b5f 100644 --- a/src/render.ts +++ b/src/render.ts @@ -10,6 +10,15 @@ const DOT = { bad: '🔴', todo: '🟡', ok: '🟢' }; export type Stamp = { reviewer: string; sha: string; model: string; effort: string | null; rubricVersion: string }; +// Deploy setup belongs to devops (rubric R13): a bad or todo finding about it tags devops. +const DEPLOY_PATH = /(^|\/)(\.gitlab-ci\.ya?ml|\.gitlab\/ci\/|Dockerfile[^/]*$|\.dockerignore$|(docker-)?compose[^/]*\.ya?ml$|k8s\/|helm\/|deploy\/|ci\/)/; +export function needsDevops(c: Checked, rules: string[]): boolean { + const items = [...c.findings.filter((f) => f.kind !== 'ok'), ...c.postDeploy]; + return items.some((f) => f.evidence.some((e) => (e.rule_id != null && rules.includes(e.rule_id)) || (e.path != null && DEPLOY_PATH.test(e.path)))); +} + +const devopsLine = (users: string[]) => `> 🛠️ Untuk devops ${users.map((u) => `@${u}`).join(' ')}: temuan deploy/CI di atas ditangani devops. Developer tidak perlu mengubah CI atau setup deploy di MR ini.`; + type Evidence = Checked['findings'][number]['evidence']; // Links that only exist on the reviewer's machine (the local rubric) are shown as plain text. @@ -17,7 +26,7 @@ const links = (ev: Evidence) => ev.map((e) => (e.url.startsWith('https://') ? `[ const footer = (s: Stamp) => `${s.reviewer} · commit \`${s.sha.slice(0, 8)}\` · ${s.model}${s.effort ? ` ${s.effort}` : ''} · rubrik ${s.rubricVersion} · saran, bukan keputusan: Gas tetap dari approver.`; -export function verdictComment(c: Checked, s: Stamp): string { +export function verdictComment(c: Checked, s: Stamp, devops: string[] = []): string { const lines = [VERDICT_MARKER, `### ${WORD[c.verdict]} — ${c.reason}`, '']; if (c.findings.length) { for (const f of c.findings) lines.push(`- ${DOT[f.kind]} ${f.text} \n ${links(f.evidence)}`); @@ -30,10 +39,16 @@ export function verdictComment(c: Checked, s: Stamp): string { } for (const o of c.overrides) lines.push(`> Aturan Labuh: ${o}`); if (c.overrides.length) lines.push(''); + if (devops.length) lines.push(devopsLine(devops), ''); lines.push(`Tanya lewat \`@${s.reviewer.toLowerCase()}\` di thread ini. Push commit baru untuk review ulang.`, '', footer(s)); return lines.join('\n'); } +// The verdict comment is edited in place and edits notify nobody: devops gets its own note. +export function devopsComment(users: string[], verdictUrl: string | null): string { + return `${devopsLine(users)}${verdictUrl ? ` Detail di [verdict](${verdictUrl}).` : ''}`; +} + export function errorComment(kind: 'reviewer_error' | 'over_budget', s: Stamp, detail: string[] = []): string { const head = kind === 'reviewer_error' @@ -51,13 +66,14 @@ export function replyComment(answer: string, question: { author: string; noteId: // The verdict comment is edited in place and GitLab sends no notification for edits, so a // re-review also leaves a short new note pointing at it. -export function rereviewComment(c: Checked, p: { sha: string; author: string | null; reviewer: string; verdictUrl: string | null; rubricChanged: boolean }): string { +export function rereviewComment(c: Checked, p: { sha: string; author: string | null; reviewer: string; verdictUrl: string | null; rubricChanged: boolean; devops?: string[] }): string { const bad = c.findings.filter((f) => f.kind === 'bad').length; const todo = c.findings.filter((f) => f.kind === 'todo').length; const counts = [bad && `${bad} harus dibenahi`, todo && `${todo} catatan`].filter(Boolean).join(', '); const why = p.rubricChanged ? 'Rubrik berubah; review ulang' : 'Review ulang'; const link = p.verdictUrl ? `[verdict](${p.verdictUrl})` : 'verdict di atas'; - return `${p.author ? `@${p.author} ` : ''}${why} commit \`${p.sha.slice(0, 8)}\`: ${WORD[c.verdict]}${counts ? ` (${counts})` : ''}. Detail di ${link}.\n\n${p.reviewer} · comment verdict selalu diperbarui di tempat`; + const devops = p.devops?.length ? `\n\n${devopsLine(p.devops)}` : ''; + return `${p.author ? `@${p.author} ` : ''}${why} commit \`${p.sha.slice(0, 8)}\`: ${WORD[c.verdict]}${counts ? ` (${counts})` : ''}. Detail di ${link}.${devops}\n\n${p.reviewer} · comment verdict selalu diperbarui di tempat`; } // What the MR thread hears about an approver's decision. The decision itself lives on the board. diff --git a/test/hub.test.ts b/test/hub.test.ts index dee919f..4e1a1f4 100644 --- a/test/hub.test.ts +++ b/test/hub.test.ts @@ -158,6 +158,65 @@ test('labelled MR is reviewed once, a new commit updates the same comment in the assert.match(note, /new_commit: go di bbbb2222/); }); +const deployFinding = (kind: 'bad' | 'todo' | 'ok'): Checked => ({ + verdict: kind === 'bad' ? 'no_go' : 'go', + reason: 'urutan deploy', + findings: [{ kind, text: 'API naik sebelum migrasi', evidence: [{ type: 'file', path: '.gitlab-ci.yml', line: 118, job_id: null, rule_id: null, label: '.gitlab-ci.yml:118', url: 'https://x' }] }], + postDeploy: [], + dropped: [], + overrides: [], +}); +const codeFinding: Checked = { + verdict: 'go', + reason: 'aman', + findings: [{ kind: 'todo', text: 'tambah test', evidence: [{ type: 'rubric', path: null, line: null, job_id: null, rule_id: 'R8', label: 'rubric R8', url: 'file:///r#r8' }] }], + postDeploy: [], + dropped: [], + overrides: [], +}; + +test('deploy findings tag devops once; code findings and ok checks do not', async () => { + const w = world({ devops: { users: ['ops1', 'ops2'] } }); + w.gl.mrs.set(8, { sha: 'a1', state: 'opened', labels: ['labuh'] }); + w.script(ok(deployFinding('bad')), ok(deployFinding('todo')), ok(codeFinding), ok(deployFinding('ok')), ok(deployFinding('todo'))); + const step = async (sha: string) => { + w.gl.mrs.get(8)!.sha = sha; + await w.hub.poll(); + await w.hub.drain(); + const out = w.store.outbox(w.store.ajuan(PROJECT, 8)!.id); + return { verdict: out.find((o) => o.kind === 'verdict')!.body, replies: out.filter((o) => o.kind === 'reply').map((o) => o.body) }; + }; + + let r = await step('a1'); + assert.match(r.verdict, /Untuk devops @ops1 @ops2/, 'a bad finding on a CI file tags devops in the new verdict note'); + r = await step('a2'); + assert.match(r.verdict, /Untuk devops/); + assert.doesNotMatch(r.replies[0], /@ops1/, 'still a deploy finding: devops is not tagged again'); + r = await step('a3'); + assert.doesNotMatch(r.verdict, /Untuk devops/, 'a code-only todo leaves devops out'); + r = await step('a4'); + assert.doesNotMatch(r.verdict, /Untuk devops/, 'an ok check on a CI file is not a deploy finding'); + r = await step('a5'); + assert.match(r.replies.at(-1)!, /Untuk devops @ops1 @ops2/, 'a deploy finding that comes back tags devops in the re-review note'); +}); + +test('a rubric R13 citation tags devops; without devops users nothing is added', async () => { + const r13: Checked = { ...codeFinding, findings: [{ ...codeFinding.findings[0], evidence: [{ ...codeFinding.findings[0].evidence[0], rule_id: 'R13', label: 'rubric R13' }] }] }; + const w = world({ devops: { users: ['ops1'] } }); + w.gl.mrs.set(9, { sha: 'b1', state: 'opened', labels: ['labuh'] }); + w.script(ok(r13)); + await w.hub.poll(); + await w.hub.drain(); + assert.match(w.store.outbox(w.store.ajuan(PROJECT, 9)!.id).find((o) => o.kind === 'verdict')!.body, /Untuk devops @ops1/); + + const plain = world(); + plain.gl.mrs.set(9, { sha: 'b1', state: 'opened', labels: ['labuh'] }); + plain.script(ok(deployFinding('bad'))); + await plain.hub.poll(); + await plain.hub.drain(); + assert.doesNotMatch(plain.store.outbox(plain.store.ajuan(PROJECT, 9)!.id).find((o) => o.kind === 'verdict')!.body, /devops/); +}); + test('mentions are answered in the thread without changing the verdict; own notes are ignored', async () => { const w = world(); w.gl.mrs.set(6, { sha: 'cccc3333', state: 'opened', labels: ['labuh'] });