Compare commits
3 Commits
cursor/nat
...
f87272a3e4
| Author | SHA1 | Date | |
|---|---|---|---|
| f87272a3e4 | |||
| 71962e853f | |||
| 37e9e29c9a |
@@ -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. |
|
| `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. |
|
| `gas.mode`, `gas.graceSeconds` | `dry` or `live`; seconds to undo an action. |
|
||||||
| `notify` | `telegramChatId`, `boardUrl` for links, `remindHours`. |
|
| `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`
|
### `board.json`
|
||||||
|
|
||||||
|
|||||||
@@ -165,6 +165,9 @@ aside { min-width: 0; }
|
|||||||
.foot li span:first-child { color: var(--ink-soft); }
|
.foot li span:first-child { color: var(--ink-soft); }
|
||||||
.foot .open { font-weight: 700; display: flex; align-items: center; gap: 6px; padding: 4px 0; white-space: nowrap; }
|
.foot .open { font-weight: 700; display: flex; align-items: center; gap: 6px; padding: 4px 0; white-space: nowrap; }
|
||||||
.stamp { margin: -8px 0 0; font-size: 12px; color: var(--ink-soft); }
|
.stamp { margin: -8px 0 0; font-size: 12px; color: var(--ink-soft); }
|
||||||
|
/* Detail extras sit in .more; give them their own gap so .stamp's pull-up doesn't overlap evidence. */
|
||||||
|
.card .more { display: flex; flex-direction: column; gap: 16px; }
|
||||||
|
.card .more > .stamp { margin-top: 0; }
|
||||||
.todo-list { display: flex; flex-direction: column; gap: 12px; }
|
.todo-list { display: flex; flex-direction: column; gap: 12px; }
|
||||||
.todo-item { text-align: left; border: 0; cursor: pointer; background: #FBEBD0; border-radius: 18px; padding: 16px 18px; display: flex; align-items: center; gap: 14px; }
|
.todo-item { text-align: left; border: 0; cursor: pointer; background: #FBEBD0; border-radius: 18px; padding: 16px 18px; display: flex; align-items: center; gap: 14px; }
|
||||||
.todo-item .age { flex: none; font-size: 13px; color: #5C4310; }
|
.todo-item .age { flex: none; font-size: 13px; color: #5C4310; }
|
||||||
@@ -451,7 +454,6 @@ aside { min-width: 0; }
|
|||||||
.actions .buttons.side .act { flex: 1 1 0; min-height: 48px; border-radius: 16px; }
|
.actions .buttons.side .act { flex: 1 1 0; min-height: 48px; border-radius: 16px; }
|
||||||
.release-row { flex-direction: column; }
|
.release-row { flex-direction: column; }
|
||||||
.release-row .act { width: 100%; min-height: 52px; }
|
.release-row .act { width: 100%; min-height: 52px; }
|
||||||
.card .more { display: flex; flex-direction: column; gap: 16px; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-reduced-motion: reduce) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
|||||||
@@ -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: 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: 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-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).
|
||||||
|
|||||||
@@ -50,3 +50,8 @@ Breaks: a rerun changes data again, double counts, or produces a different resul
|
|||||||
## R12 · Corrections check what they overwrite
|
## 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`).
|
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.
|
`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.
|
||||||
|
|||||||
@@ -132,7 +132,11 @@ function gitAccess(mr: MrInfo): { url: string; env: NodeJS.ProcessEnv } {
|
|||||||
|
|
||||||
export async function checkout(mr: MrInfo, dir: string) {
|
export async function checkout(mr: MrInfo, dir: string) {
|
||||||
const access = gitAccess(mr);
|
const access = gitAccess(mr);
|
||||||
const git = (...args: string[]) => run('git', args, { cwd: dir, env: access.env, maxBuffer: 16 * 1024 * 1024 });
|
// Git must never walk up from the checkout: an empty folder inside another repository (a
|
||||||
|
// LABUH_HOME that is itself a git checkout) would otherwise send init, set-url and
|
||||||
|
// `checkout --force` to that outer repository.
|
||||||
|
const env = { ...access.env, GIT_CEILING_DIRECTORIES: path.dirname(path.resolve(dir)) };
|
||||||
|
const git = (...args: string[]) => run('git', args, { cwd: dir, env, maxBuffer: 16 * 1024 * 1024 });
|
||||||
try {
|
try {
|
||||||
const { stdout } = await git('rev-parse', 'HEAD');
|
const { stdout } = await git('rev-parse', 'HEAD');
|
||||||
if (stdout.trim() === mr.sha) {
|
if (stdout.trim() === mr.sha) {
|
||||||
|
|||||||
25
src/hub.ts
25
src/hub.ts
@@ -8,7 +8,7 @@ import type { ReviewOutcome, Reviewer, Session } from './review.ts';
|
|||||||
import type { Checked } from './contract.ts';
|
import type { Checked } from './contract.ts';
|
||||||
import { Store, type Ajuan, type OutboxItem, type QueuedEvent, type Release, type ReleaseChanges } from './store.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 { 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 = {
|
export type HubConfig = {
|
||||||
mode: 'shadow' | 'live';
|
mode: 'shadow' | 'live';
|
||||||
@@ -24,10 +24,14 @@ export type HubConfig = {
|
|||||||
gas?: { mode: 'dry' | 'live'; graceSeconds: number };
|
gas?: { mode: 'dry' | 'live'; graceSeconds: number };
|
||||||
// Notifications to the approver (M3). Without a Telegram chat they only go to the Hub's log.
|
// 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 };
|
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';
|
type DeployBy = 'merge' | 'tag';
|
||||||
|
|
||||||
|
const DEVOPS_RULES = ['R9', 'R13'];
|
||||||
const GAS_DEFAULT = { mode: 'dry' as const, graceSeconds: 15 };
|
const GAS_DEFAULT = { mode: 'dry' as const, graceSeconds: 15 };
|
||||||
const NOTIFY_DEFAULT = { telegramChatId: null, boardUrl: 'http://localhost:4810', remindHours: 4 };
|
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.
|
// 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 {
|
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 ?? '-' };
|
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.`);
|
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`;
|
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 });
|
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));
|
||||||
if (previous) {
|
|
||||||
const noteId = this.store.outbox(a.id).find((o) => o.kind === 'verdict')?.note_id;
|
const noteId = this.store.outbox(a.id).find((o) => o.kind === 'verdict')?.note_id;
|
||||||
const verdictUrl = noteId ? `${a.web_url}#note_${noteId}` : null;
|
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 }));
|
if (previous) {
|
||||||
|
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}`);
|
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)' : ''}`;
|
return `${out.checked.verdict} di ${mr.sha.slice(0, 8)}${out.attempts > 1 ? ' (percobaan ke-2)' : ''}`;
|
||||||
|
|||||||
@@ -10,6 +10,15 @@ const DOT = { bad: '🔴', todo: '🟡', ok: '🟢' };
|
|||||||
|
|
||||||
export type Stamp = { reviewer: string; sha: string; model: string; effort: string | null; rubricVersion: string };
|
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'];
|
type Evidence = Checked['findings'][number]['evidence'];
|
||||||
|
|
||||||
// Links that only exist on the reviewer's machine (the local rubric) are shown as plain text.
|
// 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) => `<sub>${s.reviewer} · commit \`${s.sha.slice(0, 8)}\` · ${s.model}${s.effort ? ` ${s.effort}` : ''} · rubrik ${s.rubricVersion} · saran, bukan keputusan: Gas tetap dari approver.</sub>`;
|
const footer = (s: Stamp) => `<sub>${s.reviewer} · commit \`${s.sha.slice(0, 8)}\` · ${s.model}${s.effort ? ` ${s.effort}` : ''} · rubrik ${s.rubricVersion} · saran, bukan keputusan: Gas tetap dari approver.</sub>`;
|
||||||
|
|
||||||
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}`, ''];
|
const lines = [VERDICT_MARKER, `### ${WORD[c.verdict]} — ${c.reason}`, ''];
|
||||||
if (c.findings.length) {
|
if (c.findings.length) {
|
||||||
for (const f of c.findings) lines.push(`- ${DOT[f.kind]} ${f.text} \n ${links(f.evidence)}`);
|
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}`);
|
for (const o of c.overrides) lines.push(`> Aturan Labuh: ${o}`);
|
||||||
if (c.overrides.length) lines.push('');
|
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));
|
lines.push(`Tanya lewat \`@${s.reviewer.toLowerCase()}\` di thread ini. Push commit baru untuk review ulang.`, '', footer(s));
|
||||||
return lines.join('\n');
|
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 {
|
export function errorComment(kind: 'reviewer_error' | 'over_budget', s: Stamp, detail: string[] = []): string {
|
||||||
const head =
|
const head =
|
||||||
kind === 'reviewer_error'
|
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
|
// 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.
|
// 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 bad = c.findings.filter((f) => f.kind === 'bad').length;
|
||||||
const todo = c.findings.filter((f) => f.kind === 'todo').length;
|
const todo = c.findings.filter((f) => f.kind === 'todo').length;
|
||||||
const counts = [bad && `${bad} harus dibenahi`, todo && `${todo} catatan`].filter(Boolean).join(', ');
|
const counts = [bad && `${bad} harus dibenahi`, todo && `${todo} catatan`].filter(Boolean).join(', ');
|
||||||
const why = p.rubricChanged ? 'Rubrik berubah; review ulang' : 'Review ulang';
|
const why = p.rubricChanged ? 'Rubrik berubah; review ulang' : 'Review ulang';
|
||||||
const link = p.verdictUrl ? `[verdict](${p.verdictUrl})` : 'verdict di atas';
|
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<sub>${p.reviewer} · comment verdict selalu diperbarui di tempat</sub>`;
|
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<sub>${p.reviewer} · comment verdict selalu diperbarui di tempat</sub>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// What the MR thread hears about an approver's decision. The decision itself lives on the board.
|
// What the MR thread hears about an approver's decision. The decision itself lives on the board.
|
||||||
|
|||||||
42
test/checkout.test.ts
Normal file
42
test/checkout.test.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { test } from 'node:test';
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { execFileSync } from 'node:child_process';
|
||||||
|
import { mkdtempSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
||||||
|
import os from 'node:os';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { checkout, type MrInfo } from '../src/gitlab.ts';
|
||||||
|
|
||||||
|
const git = (cwd: string, ...args: string[]) => execFileSync('git', ['-c', 'user.name=t', '-c', 'user.email=t@t', ...args], { cwd, encoding: 'utf8' }).trim();
|
||||||
|
|
||||||
|
test('an empty checkout folder inside another repository never touches that repository', async () => {
|
||||||
|
delete process.env.GITLAB_TOKEN;
|
||||||
|
const root = mkdtempSync(path.join(os.tmpdir(), 'labuh-co-'));
|
||||||
|
// The reviewed project, with the MR head under GitLab's ref name.
|
||||||
|
const src = path.join(root, 'src');
|
||||||
|
mkdirSync(src);
|
||||||
|
git(src, 'init', '-q');
|
||||||
|
writeFileSync(path.join(src, 'app.txt'), 'reviewed\n');
|
||||||
|
git(src, 'add', '.');
|
||||||
|
git(src, 'commit', '-qm', 'mr');
|
||||||
|
const sha = git(src, 'rev-parse', 'HEAD');
|
||||||
|
git(src, 'update-ref', 'refs/merge-requests/7/head', sha);
|
||||||
|
// LABUH_HOME is itself a repository, and the work folder already has an empty repo/.
|
||||||
|
const home = path.join(root, 'home');
|
||||||
|
mkdirSync(home);
|
||||||
|
git(home, 'init', '-q');
|
||||||
|
writeFileSync(path.join(home, 'own.txt'), 'labuh\n');
|
||||||
|
git(home, 'add', '.');
|
||||||
|
git(home, 'commit', '-qm', 'home');
|
||||||
|
const homeHead = git(home, 'rev-parse', 'HEAD');
|
||||||
|
const dir = path.join(home, '.work', 'p-7', 'repo');
|
||||||
|
mkdirSync(dir, { recursive: true });
|
||||||
|
|
||||||
|
await checkout({ iid: 7, sha, sshUrl: src, httpUrl: src } as MrInfo, dir);
|
||||||
|
|
||||||
|
assert.equal(git(dir, 'rev-parse', '--show-toplevel'), realpathSync(dir), 'the checkout is its own repository');
|
||||||
|
assert.equal(git(dir, 'rev-parse', 'HEAD'), sha);
|
||||||
|
assert.equal(readFileSync(path.join(dir, 'app.txt'), 'utf8'), 'reviewed\n');
|
||||||
|
assert.equal(git(home, 'rev-parse', 'HEAD'), homeHead, 'the outer repository keeps its HEAD');
|
||||||
|
assert.equal(git(home, 'remote'), '', 'the outer repository gets no remote');
|
||||||
|
assert.equal(readFileSync(path.join(home, 'own.txt'), 'utf8'), 'labuh\n');
|
||||||
|
});
|
||||||
@@ -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/);
|
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 () => {
|
test('mentions are answered in the thread without changing the verdict; own notes are ignored', async () => {
|
||||||
const w = world();
|
const w = world();
|
||||||
w.gl.mrs.set(6, { sha: 'cccc3333', state: 'opened', labels: ['labuh'] });
|
w.gl.mrs.set(6, { sha: 'cccc3333', state: 'opened', labels: ['labuh'] });
|
||||||
|
|||||||
Reference in New Issue
Block a user