|
5 | 5 | // stdin JSON: { reviews, prAuthor, headSha, botLogins?, humanReviewers?, diffPaths?, protectedGlobs?, |
6 | 6 | // tier?, headRef?, baseRef?, repo? } |
7 | 7 | // Spec-Aenderungen (REQ-SPECGATE-*) umgehen die T0/T1-Abkuerzung nicht und verlangen Basis-CODEOWNERS-Deckung. |
| 8 | +// Mit baseRef kommen protectedGlobs und botLogins aus der Basis (Rueckfall: Arbeitsbaum, dann stdin; |
| 9 | +// REQ-CFGBASE-2..4), und Config-Aenderungen (.devloop/**, tier-map) verhalten sich wie Spec-Aenderungen |
| 10 | +// (REQ-CFGBASE-5/6), ausser bei Erstaufnahme. |
8 | 11 | // reviews come from `gh api repos/{owner}/{repo}/pulls/{n}/reviews`. |
9 | 12 | import { evaluateApproval } from "../core/review.js"; |
10 | 13 | import { touchesProtectedSet } from "../core/protected-set.js"; |
11 | 14 | import { isSpecChange, readBaseCodeowners, specGlobs, specPaths, uncoveredByCodeowners, SPEC_GLOBS_PATH, } from "../core/spec-change.js"; |
| 15 | +import { BOT_LOGINS_PATH, PROTECTED_GLOBS_PATH, configPaths, isInitialAdoption, readConfigList, } from "../core/config-change.js"; |
12 | 16 | import { readStdin } from "./_stdin.js"; |
13 | 17 | function fail(reason) { |
14 | 18 | process.stdout.write(JSON.stringify({ ok: false, reason }) + "\n"); |
15 | 19 | process.exit(1); |
16 | 20 | } |
17 | 21 | const req = JSON.parse(await readStdin()); |
18 | 22 | const reviews = req.reviews ?? []; |
| 23 | +const repo = req.repo ?? "."; |
| 24 | +// 0. Config-Listen aus der Basis (REQ-CFGBASE-2/3/4). Unlesbar = config-invalid (kein Rueckfall), |
| 25 | +// nirgends vorhanden = config-missing. Ohne baseRef gilt nur der stdin-Wert wie bisher. |
| 26 | +let protectedGlobs = req.protectedGlobs; |
| 27 | +let botLogins = req.botLogins; |
| 28 | +if (req.baseRef) { |
| 29 | + try { |
| 30 | + const pg = readConfigList(repo, req.baseRef, PROTECTED_GLOBS_PATH); |
| 31 | + const bl = readConfigList(repo, req.baseRef, BOT_LOGINS_PATH); |
| 32 | + protectedGlobs = pg?.list ?? req.protectedGlobs; |
| 33 | + botLogins = bl?.list ?? req.botLogins; |
| 34 | + } |
| 35 | + catch (e) { |
| 36 | + fail(`config-invalid: ${e.message}`); |
| 37 | + } |
| 38 | + const missing = [ |
| 39 | + ...(protectedGlobs === undefined ? [PROTECTED_GLOBS_PATH] : []), |
| 40 | + ...(botLogins === undefined ? [BOT_LOGINS_PATH] : []), |
| 41 | + ]; |
| 42 | + if (missing.length > 0) { |
| 43 | + fail(`config-missing: weder in der Basis ${req.baseRef}, im Arbeitsbaum noch auf stdin: ${missing.join(", ")}`); |
| 44 | + } |
| 45 | +} |
| 46 | +const approvalCtx = { ...req, botLogins }; |
19 | 47 | // 1. Gate-tamper fails ALWAYS, independent of approval state (reward-hacking alarm). |
20 | | -if (req.diffPaths && |
21 | | - req.protectedGlobs && |
22 | | - touchesProtectedSet(req.diffPaths, req.protectedGlobs)) { |
| 48 | +if (req.diffPaths && protectedGlobs && touchesProtectedSet(req.diffPaths, protectedGlobs)) { |
23 | 49 | fail("protected-set-touched: the diff edits a guardian/gate config (reward-hacking alarm)"); |
24 | 50 | } |
25 | 51 | // 1b. Spec-Aenderung (REQ-SPECGATE-1..7). Config gilt immer (REQ-5): ungueltig = fail-closed. |
26 | | -const repo = req.repo ?? "."; |
27 | 52 | let globs; |
28 | 53 | try { |
29 | 54 | globs = specGlobs(repo, req.baseRef); |
@@ -56,16 +81,46 @@ if (specChange) { |
56 | 81 | `${owners === null ? " (keine CODEOWNERS gefunden)" : ""}: ${uncovered.join(", ")}`); |
57 | 82 | } |
58 | 83 | } |
| 84 | +// 1c. Config-Aenderung (REQ-CFGBASE-5/6): kein Abkuerzen, Basis-CODEOWNERS muessen die Pfade decken. |
| 85 | +// Erstaufnahme (Basis ohne jeden Config-Pfad) ist ausgenommen: es gibt nichts zu schuetzen. |
| 86 | +let configChange = false; |
| 87 | +if (req.baseRef) { |
| 88 | + const cfgPaths = configPaths(diffPaths); |
| 89 | + if (cfgPaths.length > 0) { |
| 90 | + let adoption; |
| 91 | + try { |
| 92 | + adoption = isInitialAdoption(repo, req.baseRef); |
| 93 | + } |
| 94 | + catch (e) { |
| 95 | + fail(`config-invalid: ${e.message}`); |
| 96 | + } |
| 97 | + if (!adoption) { |
| 98 | + configChange = true; |
| 99 | + let owners; |
| 100 | + try { |
| 101 | + owners = readBaseCodeowners(repo, req.baseRef); |
| 102 | + } |
| 103 | + catch (e) { |
| 104 | + fail(`config-unguarded: ${e.message} (Config-Pfade: ${cfgPaths.join(", ")})`); |
| 105 | + } |
| 106 | + const uncovered = uncoveredByCodeowners(cfgPaths, owners); |
| 107 | + if (uncovered.length > 0) { |
| 108 | + fail(`config-unguarded: Config-Pfade ohne CODEOWNERS-Deckung in der Basis ${req.baseRef}` + |
| 109 | + `${owners === null ? " (keine CODEOWNERS gefunden)" : ""}: ${uncovered.join(", ")}`); |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | +} |
59 | 114 | // 2. Tier gate (§9): T0/T1 auto-merge — no approval required. (Gate-tamper above still applied.) |
60 | 115 | // Unknown/absent tier defaults to conservative "T3" (approval required). The authoritative |
61 | 116 | // T2/T3 merge block is branch protection's required CODEOWNER review on the high-tier paths; |
62 | 117 | // this check additionally validates a present approval (human, on HEAD) and the protected set. |
63 | 118 | const tier = req.tier ?? "T3"; |
64 | | -if (!specChange && (tier === "T0" || tier === "T1")) { |
| 119 | +if (!specChange && !configChange && (tier === "T0" || tier === "T1")) { |
65 | 120 | process.stdout.write(JSON.stringify({ ok: true, tier, note: "tier T0/T1: no approval required (§9)" }) + "\n"); |
66 | 121 | process.exit(0); |
67 | 122 | } |
68 | | -const status = evaluateApproval(reviews, req); |
| 123 | +const status = evaluateApproval(reviews, approvalCtx); |
69 | 124 | if (status === "ok") { |
70 | 125 | process.stdout.write(JSON.stringify({ ok: true }) + "\n"); |
71 | 126 | process.exit(0); |
|
0 commit comments