robisie 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +39 -11
  3. package/dist/agents.d.ts +1 -1
  4. package/dist/agents.js +1 -1
  5. package/dist/ci-failure-result.js +1 -1
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +45 -8
  8. package/dist/codex-env.d.ts +9 -0
  9. package/dist/codex-env.js +60 -0
  10. package/dist/commands.js +140 -16
  11. package/dist/constants.d.ts +1 -1
  12. package/dist/constants.js +1 -1
  13. package/dist/delivery-local.d.ts +124 -0
  14. package/dist/delivery-local.js +286 -0
  15. package/dist/done-evidence.d.ts +25 -1
  16. package/dist/done-evidence.js +59 -1
  17. package/dist/engine/bundle-report.json +1687 -0
  18. package/dist/engine/tick.cjs +324704 -0
  19. package/dist/engine-config.d.ts +3 -1
  20. package/dist/engine-config.js +3 -3
  21. package/dist/factory-run.d.ts +17 -0
  22. package/dist/factory-run.js +262 -0
  23. package/dist/helpers.js +1 -1
  24. package/dist/k3-codex-job.d.ts +49 -0
  25. package/dist/k3-codex-job.js +324 -0
  26. package/dist/k3-helper-cli.d.ts +5 -0
  27. package/dist/k3-helper-cli.js +167 -0
  28. package/dist/local-usage.d.ts +47 -0
  29. package/dist/local-usage.js +230 -0
  30. package/dist/manifest.d.ts +5 -2
  31. package/dist/manifest.js +6 -6
  32. package/dist/planer-client.d.ts +45 -4
  33. package/dist/planer-client.js +120 -14
  34. package/dist/roles.d.ts +1 -1
  35. package/dist/select-fingerprint.d.ts +19 -0
  36. package/dist/select-fingerprint.js +46 -0
  37. package/dist/test-report.d.ts +9 -0
  38. package/dist/test-report.js +139 -0
  39. package/dist/tester-result-reader.d.ts +87 -0
  40. package/dist/tester-result-reader.js +122 -0
  41. package/docs/ENGINE-API.md +9 -1
  42. package/docs/README.en.md +55 -16
  43. package/docs/README.md +53 -16
  44. package/docs/RELEASE-0.1.0.md +27 -5
  45. package/helpers/ceo-client-launcher-mcp.mjs +76 -5
  46. package/package.json +6 -2
  47. package/roles/ceo-client.md +10 -8
@@ -0,0 +1,286 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { mkdtempSync, rmSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ export const EVIDENCE_KINDS = ["review", "test", "deliver"];
6
+ export const DEFAULT_DELIVERY_ADAPTER = "local-ff";
7
+ const SHA_RE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
8
+ const OUTPUT_LIMIT = 4000;
9
+ function runGit(repo, args, input) {
10
+ const result = spawnSync("git", args, {
11
+ cwd: repo, encoding: "utf8", input, timeout: 60_000, maxBuffer: 20 * 1024 * 1024, shell: false,
12
+ env: { ...process.env, LC_ALL: "C", GIT_TERMINAL_PROMPT: "0" },
13
+ });
14
+ return { status: result.status, stdout: result.stdout ?? "", stderr: result.stderr ?? "", error: result.error };
15
+ }
16
+ function gitText(run) {
17
+ return (run.error?.message ?? (run.stderr.trim() || run.stdout.trim())).slice(0, OUTPUT_LIMIT);
18
+ }
19
+ function resolveCommit(repo, spec) {
20
+ const run = runGit(repo, ["rev-parse", "--verify", "--quiet", "--end-of-options", `${spec}^{commit}`]);
21
+ const sha = run.stdout.trim();
22
+ return run.status === 0 && SHA_RE.test(sha) ? sha : undefined;
23
+ }
24
+ function isAncestor(repo, ancestor, descendant) {
25
+ const run = runGit(repo, ["merge-base", "--is-ancestor", ancestor, descendant]);
26
+ if (run.status === 0)
27
+ return true;
28
+ if (run.status === 1)
29
+ return false;
30
+ return run;
31
+ }
32
+ /** Kanoniczny JSON (posortowane klucze) — ten sam dowód daje ten sam wiersz notatki. */
33
+ function canonical(value) {
34
+ if (Array.isArray(value))
35
+ return value.map(canonical);
36
+ if (value && typeof value === "object") {
37
+ return Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])]));
38
+ }
39
+ return value;
40
+ }
41
+ function prepare(repo, input) {
42
+ const target = typeof input?.target === "string" ? input.target : "";
43
+ const branch = runGit(repo, ["check-ref-format", "--branch", target]);
44
+ if (!target || target.startsWith("-") || branch.status !== 0 || branch.stdout.trim() !== target) {
45
+ return { ok: false, reason: "invalid-target", message: `Nieprawidłowa nazwa gałęzi celu: ${JSON.stringify(target)}` };
46
+ }
47
+ const ref = `refs/heads/${target}`;
48
+ const targetSha = resolveCommit(repo, ref);
49
+ if (!targetSha)
50
+ return { ok: false, reason: "invalid-target", message: `Gałąź celu ${target} nie istnieje w repozytorium.` };
51
+ const requested = typeof input?.taskSha === "string" ? input.taskSha.toLowerCase() : "";
52
+ if (!SHA_RE.test(requested)) {
53
+ return { ok: false, reason: "invalid-task", message: `SHA zadania musi być pełnym skrótem commita: ${JSON.stringify(input?.taskSha)}` };
54
+ }
55
+ const taskSha = resolveCommit(repo, requested);
56
+ if (taskSha !== requested)
57
+ return { ok: false, reason: "invalid-task", message: `Commit zadania ${requested} nie istnieje w repozytorium.` };
58
+ const merge = runGit(repo, ["merge-tree", "--write-tree", "--name-only", "--no-messages", targetSha, taskSha]);
59
+ const lines = merge.stdout.split("\n").filter(Boolean);
60
+ const tree = lines[0] ?? "";
61
+ if (merge.status === 1 && SHA_RE.test(tree)) {
62
+ const conflicts = [...new Set(lines.slice(1))];
63
+ return { ok: false, reason: "conflict", message: `Scalenie ${taskSha} do ${target} ma konflikty (${conflicts.length}).`, conflicts };
64
+ }
65
+ if (merge.status !== 0 || !SHA_RE.test(tree)) {
66
+ return { ok: false, reason: "error", message: `git merge-tree --write-tree nie powiodło się (wymagany Git ≥ 2.38): ${gitText(merge)}` };
67
+ }
68
+ const forward = isAncestor(repo, targetSha, taskSha);
69
+ if (typeof forward !== "boolean")
70
+ return { ok: false, reason: "error", message: `Sprawdzenie przodka nie powiodło się: ${gitText(forward)}` };
71
+ let mode = forward ? "fast-forward" : "merge";
72
+ if (!forward) {
73
+ const contained = isAncestor(repo, taskSha, targetSha);
74
+ if (typeof contained !== "boolean")
75
+ return { ok: false, reason: "error", message: `Sprawdzenie przodka nie powiodło się: ${gitText(contained)}` };
76
+ if (contained)
77
+ mode = "up-to-date";
78
+ }
79
+ if (targetSha === taskSha)
80
+ mode = "up-to-date";
81
+ return { ok: true, target, ref, targetSha, taskSha, tree, mode };
82
+ }
83
+ function check(repo, prepared, commands, options = {}) {
84
+ const results = [];
85
+ if (!prepared?.ok || !SHA_RE.test(prepared.taskSha ?? "")) {
86
+ return { ok: false, reason: "error", message: "Nieprawidłowy wynik prepare.", results };
87
+ }
88
+ let tmp;
89
+ try {
90
+ tmp = mkdtempSync(join(tmpdir(), "robisie-check-"));
91
+ }
92
+ catch (error) {
93
+ return { ok: false, reason: "error", message: `Nie udało się utworzyć katalogu tymczasowego: ${error instanceof Error ? error.message : String(error)}`, results };
94
+ }
95
+ const worktree = join(tmp, "wt");
96
+ const add = runGit(repo, ["worktree", "add", "--detach", "--quiet", worktree, prepared.taskSha]);
97
+ if (add.status !== 0 || add.error) {
98
+ // add mógł zostawić częściowy wpis — sprzątamy tak samo jak po komendach.
99
+ const outcome = { ok: false, reason: "error", message: `git worktree add nie powiodło się: ${gitText(add)}`, results };
100
+ return withCleanup(outcome, removeWorktree(repo, tmp, worktree, false), tmp, worktree);
101
+ }
102
+ let outcome;
103
+ let failed = [];
104
+ try {
105
+ outcome = runChecks(worktree, commands, options.timeoutMs ?? 600_000, results);
106
+ }
107
+ finally {
108
+ failed = removeWorktree(repo, tmp, worktree, true);
109
+ }
110
+ return withCleanup(outcome, failed, tmp, worktree);
111
+ }
112
+ /** Każdy krok sprzątania jest sprawdzany; porażka nie jest połykana, tylko wraca do wyniku `check`. */
113
+ function removeWorktree(repo, tmp, worktree, added) {
114
+ const failed = [];
115
+ // Po nieudanym `worktree add` worktree może nie istnieć — wtedy porażka `remove` nie jest awarią; decyduje `prune`.
116
+ const remove = runGit(repo, ["worktree", "remove", "--force", worktree]);
117
+ if (added && (remove.status !== 0 || remove.error))
118
+ failed.push({ step: "worktree-remove", message: gitText(remove) || `status=${remove.status}` });
119
+ try {
120
+ rmSync(tmp, { recursive: true, force: true });
121
+ }
122
+ catch (error) {
123
+ failed.push({ step: "rm-tmp", message: error instanceof Error ? error.message : String(error) });
124
+ }
125
+ const prune = runGit(repo, ["worktree", "prune"]);
126
+ if (prune.status !== 0 || prune.error)
127
+ failed.push({ step: "worktree-prune", message: gitText(prune) || `status=${prune.status}` });
128
+ return failed;
129
+ }
130
+ function withCleanup(outcome, failed, tmp, worktree) {
131
+ if (failed.length === 0)
132
+ return outcome;
133
+ const steps = failed.map(entry => entry.step).join(", ");
134
+ const detail = { failed, worktree, tmp };
135
+ let message = `Sprzątanie worktree ${worktree} nie powiodło się (${steps}); może zostać w repo klienta.`;
136
+ if (!outcome.ok && outcome.reason !== "cleanup-failed") {
137
+ detail.checkFailed = { reason: outcome.reason, message: outcome.message };
138
+ message = `${outcome.message} Dodatkowo: ${message}`;
139
+ }
140
+ return { ok: false, reason: "cleanup-failed", message, results: outcome.results, detail };
141
+ }
142
+ function runChecks(cwd, commands, timeoutMs, results) {
143
+ for (const entry of commands) {
144
+ const command = typeof entry?.command === "string" ? entry.command : "";
145
+ const args = Array.isArray(entry?.args) ? entry.args.map(String) : [];
146
+ if (!command) {
147
+ return { ok: false, reason: "check-failed", message: "Pusta komenda sprawdzenia.", results };
148
+ }
149
+ const run = spawnSync(command, args, { cwd, encoding: "utf8", shell: false, timeout: timeoutMs, maxBuffer: 20 * 1024 * 1024 });
150
+ const output = `${run.stdout ?? ""}${run.stderr ?? ""}${run.error ? run.error.message : ""}`.slice(-OUTPUT_LIMIT);
151
+ const outcome = { command, args, status: run.status, signal: run.signal, output };
152
+ results.push(outcome);
153
+ if (run.error || run.status !== 0) {
154
+ return { ok: false, reason: "check-failed", message: `Sprawdzenie ${[command, ...args].join(" ")} nie przeszło (status=${run.status}, sygnał=${run.signal}).`, results };
155
+ }
156
+ }
157
+ return { ok: true, results };
158
+ }
159
+ function checkedOutIn(repo, ref) {
160
+ const list = runGit(repo, ["worktree", "list", "--porcelain", "-z"]);
161
+ if (list.status !== 0)
162
+ return list;
163
+ let path;
164
+ for (const field of list.stdout.split("\0")) {
165
+ if (field.startsWith("worktree "))
166
+ path = field.slice("worktree ".length);
167
+ else if (field === `branch ${ref}`)
168
+ return path ?? repo;
169
+ }
170
+ return undefined;
171
+ }
172
+ function deliver(repo, prepared) {
173
+ if (!prepared?.ok || typeof prepared.ref !== "string" || !prepared.ref.startsWith("refs/heads/")
174
+ || !SHA_RE.test(prepared.targetSha ?? "") || !SHA_RE.test(prepared.taskSha ?? "")) {
175
+ return { ok: false, reason: "error", message: "Nieprawidłowy wynik prepare." };
176
+ }
177
+ const { ref, targetSha, taskSha } = prepared;
178
+ const current = resolveCommit(repo, ref);
179
+ if (prepared.mode === "up-to-date" && current === targetSha) {
180
+ const contained = isAncestor(repo, taskSha, targetSha);
181
+ if (contained === true)
182
+ return { ok: true, moved: false, ref, from: targetSha, to: targetSha };
183
+ }
184
+ const forward = isAncestor(repo, targetSha, taskSha);
185
+ if (typeof forward !== "boolean")
186
+ return { ok: false, reason: "error", message: `Sprawdzenie przodka nie powiodło się: ${gitText(forward)}` };
187
+ if (!forward || prepared.mode !== "fast-forward") {
188
+ return { ok: false, reason: "not-fast-forward", message: `Odmowa: ${taskSha} nie jest fast-forwardem ${prepared.target} (${targetSha}). Zaktualizuj gałąź zadania o cel i powtórz.` };
189
+ }
190
+ // Alias (symbolic ref) przesunąłby gałąź, na którą wskazuje — ochrona wyewidencjonowania widzi tylko dosłowną nazwę.
191
+ const symbolic = runGit(repo, ["symbolic-ref", "-q", ref]);
192
+ if (symbolic.status === 0 && !symbolic.error) {
193
+ return { ok: false, reason: "target-is-symbolic-ref", message: `Odmowa: ${prepared.target} jest aliasem (symbolic ref) do ${symbolic.stdout.trim()}; dostarcz do gałęzi docelowej wprost.` };
194
+ }
195
+ if (symbolic.status !== 1 || symbolic.error)
196
+ return { ok: false, reason: "error", message: `git symbolic-ref nie powiodło się: ${gitText(symbolic)}` };
197
+ const worktree = checkedOutIn(repo, ref);
198
+ if (typeof worktree === "object")
199
+ return { ok: false, reason: "error", message: `git worktree list nie powiodło się: ${gitText(worktree)}` };
200
+ if (worktree !== undefined) {
201
+ return { ok: false, reason: "target-checked-out", message: `Odmowa: gałąź ${prepared.target} jest wyewidencjonowana w ${worktree}; przesunięcie refa rozjechałoby jej drzewo robocze.` };
202
+ }
203
+ const update = runGit(repo, ["update-ref", "--no-deref", "-m", `robisie: dostawa local-ff ${taskSha}`, ref, taskSha, targetSha]);
204
+ if (update.status !== 0) {
205
+ const now = resolveCommit(repo, ref);
206
+ if (now !== targetSha) {
207
+ return { ok: false, reason: "target-moved", message: `Odmowa: ${prepared.target} przesunął się z ${targetSha} na ${now ?? "(brak)"} po prepare; nic nie zmieniono.` };
208
+ }
209
+ return { ok: false, reason: "error", message: `git update-ref nie powiodło się: ${gitText(update)}` };
210
+ }
211
+ return { ok: true, moved: true, ref, from: targetSha, to: taskSha };
212
+ }
213
+ function attachEvidence(repo, sha, kind, evidence) {
214
+ if (!EVIDENCE_KINDS.includes(kind))
215
+ return { ok: false, reason: "invalid-kind", message: `Nieznany rodzaj dowodu: ${JSON.stringify(kind)}` };
216
+ const commit = typeof sha === "string" && SHA_RE.test(sha) ? resolveCommit(repo, sha) : undefined;
217
+ if (!commit || commit !== sha)
218
+ return { ok: false, reason: "invalid-sha", message: `Commit ${JSON.stringify(sha)} nie istnieje.` };
219
+ let line;
220
+ try {
221
+ line = JSON.stringify(canonical(evidence));
222
+ }
223
+ catch (error) {
224
+ return { ok: false, reason: "error", message: `Dowód nie jest serializowalny do JSON: ${error instanceof Error ? error.message : String(error)}` };
225
+ }
226
+ if (line === undefined)
227
+ return { ok: false, reason: "error", message: "Dowód nie jest serializowalny do JSON." };
228
+ const ref = `refs/notes/robisie/${kind}`;
229
+ const strategy = runGit(repo, ["config", `notes.robisie/${kind}.mergeStrategy`, "cat_sort_uniq"]);
230
+ if (strategy.status !== 0)
231
+ return { ok: false, reason: "error", message: `Ustawienie notes mergeStrategy nie powiodło się: ${gitText(strategy)}` };
232
+ const existing = readEvidenceLines(repo, kind, sha);
233
+ if (!Array.isArray(existing))
234
+ return existing;
235
+ if (existing.includes(line))
236
+ return { ok: true, ref, sha, written: false };
237
+ // Ta sama semantyka co cat_sort_uniq: posortowane, unikalne wiersze.
238
+ const body = [...new Set([...existing, line])].sort().join("\n") + "\n";
239
+ const write = runGit(repo, ["notes", `--ref=${ref}`, "add", "-f", "-F", "-", sha], body);
240
+ if (write.status !== 0)
241
+ return { ok: false, reason: "error", message: `git notes add nie powiodło się: ${gitText(write)}` };
242
+ return { ok: true, ref, sha, written: true };
243
+ }
244
+ function readEvidenceLines(repo, kind, sha) {
245
+ const ref = `refs/notes/robisie/${kind}`;
246
+ // Pusta lista tylko przy POTWIERDZONYM braku (znany kod i komunikat gita); każda inna porażka to błąd odczytu.
247
+ const exists = runGit(repo, ["rev-parse", "--verify", "--quiet", ref]);
248
+ if (exists.status === 1 && !exists.error && !exists.stderr.trim())
249
+ return [];
250
+ if (exists.status !== 0 || exists.error) {
251
+ return { ok: false, reason: "evidence-read-failed", message: `Odczyt ${ref} nie powiódł się: ${gitText(exists) || `status=${exists.status}`}` };
252
+ }
253
+ const show = runGit(repo, ["notes", `--ref=${ref}`, "show", sha]);
254
+ if (show.status === 0 && !show.error)
255
+ return show.stdout.split("\n").filter(Boolean);
256
+ if (show.status === 1 && !show.error && /^error: no note found for object [0-9a-f]+\.?$/.test(show.stderr.trim()))
257
+ return [];
258
+ return { ok: false, reason: "evidence-read-failed", message: `git notes show nie powiodło się: ${gitText(show) || `status=${show.status}`}` };
259
+ }
260
+ /** Odczyt dowodów (wiersze JSON) z refs/notes/robisie/<kind> przy SHA. */
261
+ export function readEvidence(repo, kind, sha) {
262
+ if (!EVIDENCE_KINDS.includes(kind))
263
+ return { ok: false, reason: "invalid-kind", message: `Nieznany rodzaj dowodu: ${JSON.stringify(kind)}` };
264
+ const lines = readEvidenceLines(repo, kind, sha);
265
+ if (!Array.isArray(lines))
266
+ return lines;
267
+ const entries = [];
268
+ for (const line of lines) {
269
+ try {
270
+ entries.push(JSON.parse(line));
271
+ }
272
+ catch {
273
+ return { ok: false, reason: "error", message: `Wiersz notatki nie jest JSON: ${line.slice(0, 200)}` };
274
+ }
275
+ }
276
+ return { ok: true, entries };
277
+ }
278
+ /** Adapter `local-ff` (domyślny): scalenie lokalne wyłącznie przez fast-forward z CAS. */
279
+ export function createLocalFfDelivery(repo) {
280
+ return {
281
+ prepare: input => prepare(repo, input),
282
+ check: (prepared, commands, options) => check(repo, prepared, commands, options),
283
+ deliver: prepared => deliver(repo, prepared),
284
+ attachEvidence: (sha, kind, evidence) => attachEvidence(repo, sha, kind, evidence),
285
+ };
286
+ }
@@ -12,8 +12,32 @@ export declare function doneRetrySnapshot(details: Record<string, unknown>): (st
12
12
  export declare function doneEvidenceFingerprint(details: Record<string, unknown>): string;
13
13
  /** CR supplies the receipt; a role or model name is never provider evidence. */
14
14
  export declare function acceptanceIndependenceValid(details: Details): boolean;
15
+ /** Card-level opt-in for client-run proof; never sufficient alone (see LocalDeliveryOptions). */
16
+ export declare function declaresLocalDelivery(details: Details): boolean;
17
+ /** Our factory board uses only the GitHub contract; local proof is never accepted for it (any policy). */
18
+ export declare const FACTORY_PROJECT_SLUG = "robisie-control-room";
19
+ /**
20
+ * Client-run proof for the exact landed SHA: no GitHub check name, run URL or repository address.
21
+ * Every command must have exited 0; the independent receiver receipt is the review independence proof.
22
+ * The SHA is the full 40-char lowercase hex; every other SHA field is compared to it exactly.
23
+ * The declared receiver provider must equal the protected review_receipt (accept_review) provider,
24
+ * so an editable acceptance cannot claim a different reviewer provider than the one who accepted.
25
+ */
26
+ export declare function localProcessTraces(details: Details): {
27
+ ok: boolean;
28
+ missing: ("local" | "review" | "independence")[];
29
+ };
30
+ /**
31
+ * localDelivery is server-owned (enforced review policy); callers that do not know it omit it.
32
+ * Local proof also needs `delivery_mode: "local"` already persisted before the done write.
33
+ * projectSlug is the card's server-read project slug; FACTORY_PROJECT_SLUG always rejects local proof.
34
+ */
35
+ export interface LocalDeliveryOptions {
36
+ localDelivery?: boolean;
37
+ projectSlug?: string;
38
+ }
15
39
  /** Factory cards with a canonical criterion list need a separate per-criterion acceptance. */
16
- export declare function doneAcceptanceProblems(persistedDetails: Details, effectiveDetails: Details): string[];
40
+ export declare function doneAcceptanceProblems(persistedDetails: Details, effectiveDetails: Details, options?: LocalDeliveryOptions): string[];
17
41
  export declare function declaredCardClassChanged(persistedDetails: Details, effectiveDetails: Details): boolean;
18
42
  /**
19
43
  * Factory-only rollout: an absent/explicitly non-executable class stays on the legacy path. For an
@@ -72,8 +72,52 @@ export function acceptanceIndependenceValid(details) {
72
72
  && ["by", "proposal_by", "packager_by", "worker"].every(k => nonEmptyText(authors[k])
73
73
  && String(authors[k]).trim().toLowerCase() !== String(i.receiver_provider).trim().toLowerCase());
74
74
  }
75
+ function isoTimestamp(value) {
76
+ return typeof value === "string" && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(value)
77
+ && Number.isFinite(Date.parse(value));
78
+ }
79
+ /** Card-level opt-in for client-run proof; never sufficient alone (see LocalDeliveryOptions). */
80
+ export function declaresLocalDelivery(details) {
81
+ return details?.delivery_mode === "local";
82
+ }
83
+ /** Our factory board uses only the GitHub contract; local proof is never accepted for it (any policy). */
84
+ export const FACTORY_PROJECT_SLUG = "robisie-control-room";
85
+ /** Provider names compare case- and whitespace-insensitively, like acceptanceIndependenceValid. */
86
+ function sameProvider(a, b) {
87
+ return nonEmptyText(a) && nonEmptyText(b) && a.trim().toLowerCase() === b.trim().toLowerCase();
88
+ }
89
+ /**
90
+ * Client-run proof for the exact landed SHA: no GitHub check name, run URL or repository address.
91
+ * Every command must have exited 0; the independent receiver receipt is the review independence proof.
92
+ * The SHA is the full 40-char lowercase hex; every other SHA field is compared to it exactly.
93
+ * The declared receiver provider must equal the protected review_receipt (accept_review) provider,
94
+ * so an editable acceptance cannot claim a different reviewer provider than the one who accepted.
95
+ */
96
+ export function localProcessTraces(details) {
97
+ const sha = recordOrEmpty(details?.landed).sha, local = recordOrEmpty(details?.local_receipt);
98
+ const review = recordOrEmpty(details?.review), commands = local.commands;
99
+ const valid = typeof sha === "string" && /^[a-f0-9]{40}$/.test(sha);
100
+ const missing = [];
101
+ if (!valid || local.source !== "local" || local.sha !== sha || !nonEmptyText(local.target_branch)
102
+ || !Array.isArray(commands) || commands.length === 0
103
+ || !commands.every((value) => {
104
+ const run = recordOrEmpty(value);
105
+ return nonEmptyText(run.command) && run.exit_code === 0 && typeof run.output === "string"
106
+ && run.output.length <= 2000 && isoTimestamp(run.at);
107
+ }))
108
+ missing.push("local");
109
+ if (!valid || review.sha !== sha || review.verdict !== "PASS")
110
+ missing.push("review");
111
+ const declared = recordOrEmpty(recordOrEmpty(details?.acceptance).independence);
112
+ const protectedProvider = recordOrEmpty(details?.review_receipt).providerDeclared;
113
+ const authors = recordOrEmpty(declared.authoring_providers);
114
+ if (!valid || !acceptanceIndependenceValid(details) || !sameProvider(declared.receiver_provider, protectedProvider)
115
+ || ["by", "proposal_by", "packager_by", "worker"].some(k => sameProvider(authors[k], protectedProvider)))
116
+ missing.push("independence");
117
+ return { ok: !missing.length, missing };
118
+ }
75
119
  /** Factory cards with a canonical criterion list need a separate per-criterion acceptance. */
76
- export function doneAcceptanceProblems(persistedDetails, effectiveDetails) {
120
+ export function doneAcceptanceProblems(persistedDetails, effectiveDetails, options = {}) {
77
121
  const isExecutable = declaredCardClass(persistedDetails) === "executable" ||
78
122
  declaredCardClass(effectiveDetails) === "executable";
79
123
  const isCohort = persistedDetails?.["origin"] === "reksio/propozycja" ||
@@ -142,6 +186,20 @@ export function doneAcceptanceProblems(persistedDetails, effectiveDetails) {
142
186
  if (result.ref !== `machine-process:${recordOrEmpty(effectiveDetails?.ci_receipt).run_url}`)
143
187
  problems.push(`kryterium ${i + 1}: obcy ref machine-process`);
144
188
  }
189
+ if (result?.basis === "local-process") {
190
+ if (options.projectSlug === FACTORY_PROJECT_SLUG) {
191
+ problems.push(`kryterium ${i + 1}: dowód lokalny niedozwolony dla projektu ${FACTORY_PROJECT_SLUG}`);
192
+ }
193
+ else if (options.localDelivery !== true || !declaresLocalDelivery(persistedDetails) || !declaresLocalDelivery(effectiveDetails)) {
194
+ problems.push(`kryterium ${i + 1}: dowód lokalny bez zadeklarowanej dostawy lokalnej`);
195
+ }
196
+ for (const key of localProcessTraces(effectiveDetails).missing) {
197
+ if (!problems.includes(`brak śladu lokalnego: ${key}`))
198
+ problems.push(`brak śladu lokalnego: ${key}`);
199
+ }
200
+ if (result.ref !== `local-process:${recordOrEmpty(effectiveDetails?.landed).sha}`)
201
+ problems.push(`kryterium ${i + 1}: obcy ref local-process`);
202
+ }
145
203
  const verdict = result?.["verdict"];
146
204
  if (verdict !== "PASS")
147
205
  problems.push(`kryterium ${i + 1}: werdykt ${verdict ?? "brak"}`);