@attalabs/vinaya 0.39.0 → 0.41.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.
- package/README.md +9 -9
- package/aeg-root/contracts/developer-reviewer.md +2 -2
- package/aeg-root/contracts/planner-developer.md +5 -5
- package/aeg-root/enforcement.md +22 -22
- package/aeg-root/process.md +4 -4
- package/aeg-root/roles/archivist.md +1 -1
- package/aeg-root/roles/developer/reference.md +7 -1
- package/aeg-root/roles/developer.md +1 -1
- package/aeg-root/roles/planner/reference.md +18 -5
- package/aeg-root/roles/principal.md +1 -1
- package/aeg-root/roles/reviewer.md +3 -3
- package/aeg-root/roles/security.md +4 -4
- package/aeg-root/roles/tranche-archivist.md +2 -2
- package/aeg-root/skills/aeg/SKILL.md +1 -1
- package/aeg-root/state-machine.md +10 -15
- package/aeg-root/templates/brief-template.md +5 -2
- package/aeg-root/templates/decision-record-template.md +38 -0
- package/aeg-root/templates/issue-rationale-template.md +1 -1
- package/aeg-root/tranche-model.md +1 -1
- package/dist/checks/bin/check-body-bare-digits.js +1974 -354
- package/dist/checks/bin/check-branch-topology.js +1296 -243
- package/dist/checks/bin/check-brief-shape.js +2038 -460
- package/dist/checks/bin/check-changeset-coverage.js +2411 -564
- package/dist/checks/bin/check-ci-shard-coverage.js +12391 -15
- package/dist/checks/bin/check-closes-n.js +1296 -243
- package/dist/checks/bin/check-coherence.js +1914 -1155
- package/dist/checks/bin/check-dead-branch-push.js +1242 -230
- package/dist/checks/bin/check-dispatch-readiness.js +2222 -460
- package/dist/checks/bin/check-doc-claims.js +2233 -260
- package/dist/checks/bin/check-doc-coverage-push.js +2436 -550
- package/dist/checks/bin/check-doc-coverage.js +2434 -552
- package/dist/checks/bin/check-doctrine-no-procedures.js +1776 -353
- package/dist/checks/bin/check-doctrine-portability.js +2408 -561
- package/dist/checks/bin/check-evidence-fresh.js +2370 -508
- package/dist/checks/bin/check-exec-bits.js +2407 -560
- package/dist/checks/bin/check-first-push-dispatch.js +1984 -380
- package/dist/checks/bin/check-issue-assignment.js +712 -170
- package/dist/checks/bin/check-issue-milestone-attach.js +1233 -230
- package/dist/checks/bin/check-issue-objectives-numbering.js +1769 -346
- package/dist/checks/bin/check-issue-parts-coverage.js +1233 -230
- package/dist/checks/bin/check-issue-surface-globs.js +1926 -378
- package/dist/checks/bin/check-issue-title-grammar.js +1233 -230
- package/dist/checks/bin/check-issue-tranche-label.js +702 -170
- package/dist/checks/bin/check-main-branch-refusal.js +1245 -232
- package/dist/checks/bin/check-no-disk-state.js +1233 -230
- package/dist/checks/bin/check-pr-premise-reassert.js +1769 -346
- package/dist/checks/bin/check-pr-report-density.js +1233 -230
- package/dist/checks/bin/check-principal-test-plan-wait.js +2489 -259
- package/dist/checks/bin/check-quoted-command.js +2391 -544
- package/dist/checks/bin/check-reader-resolvable-prose.js +2437 -564
- package/dist/checks/bin/check-registry-gates.js +1380 -296
- package/dist/checks/bin/check-retired-vocabulary.js +2416 -550
- package/dist/checks/bin/check-review-gate.js +2073 -371
- package/dist/checks/bin/check-single-plan-pr.js +1297 -235
- package/dist/checks/bin/check-surface-scope.js +1531 -252
- package/dist/checks/bin/check-test-plan.js +2487 -258
- package/dist/checks/bin/check-token-collection-wired.js +1233 -230
- package/dist/checks/bin/check-workspace-escape.js +2408 -561
- package/dist/checks/bin/verify-coherence.js +597 -97
- package/dist/checks/bin/verify-dispatch.js +632 -152
- package/dist/checks/bin/verify-docs.js +642 -132
- package/dist/index.js +25948 -16630
- package/dist/lib/pre-push-cache-test-run.js +1813 -297
- package/dist/lib/pre-push-changed-files.js +65 -19
- package/dist/lib/pre-push-mode.js +466 -0
- package/dist/lib/pre-push-progress-dir.js +4205 -0
- package/dist/lib/pre-push-record-tests.js +446 -0
- package/dist/lib/pre-push-select-tests.js +2353 -632
- package/dist/lib/push-progress-observer.js +4213 -0
- package/package.json +22 -5
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +17 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +73 -30
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +3 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/coherence-checks.ts +2 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +88 -5
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +34 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +26 -4
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +7 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +7 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +29 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dispatch-gate.ts +35 -18
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/index.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/published-prose.ts +70 -45
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +6 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/entry-point.ts +27 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +3 -5
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +96 -9
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-assignment.ts +24 -54
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +809 -106
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/live-record.ts +179 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +8 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +1 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/narration.ts +2 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema-digest.ts +225 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +7 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/main-branch-refusal.ts +23 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-report-density.ts +6 -4
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/principals-config.ts +44 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/prose-rules.ts +532 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/protected-paths.ts +31 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +157 -80
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +8 -12
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/retired-vocabulary.ts +53 -93
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +46 -17
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +85 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +32 -13
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ruling-ordinal.ts +46 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-branch-identity.ts +2 -4
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-gate.ts +63 -8
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/verdict-extraction.ts +24 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/waiver-label.ts +0 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/1q96_modules_@clerk_nextjs_dist_esm_app-router_client_keyless-creator-reader_0lom2js.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__08e39jo._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0sxadt2._.js +13 -0
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1a3j3n1._.js +57 -0
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1ug9syi._.js → [root-of-the-server]__1d4eth3._.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1snpgaw._.js +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_08onyya._.js +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/node_modules_@clerk_nextjs_dist_esm_app-router_server-actions_1x7vfhn.js +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{33rszkngkuoko.js → 0x7u6si-ai179.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{06_55xbp7rcbi.js → 2fu7mfsj4oima.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{2brkwv169ygep.js → 34b4ruddunn3q.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__04adkz-._.js +0 -57
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__19jyp3m._.js +0 -13
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → 2ZARxTwpuRew8-SvYsRdU}/_buildManifest.js +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → 2ZARxTwpuRew8-SvYsRdU}/_clientMiddlewareManifest.js +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → 2ZARxTwpuRew8-SvYsRdU}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/lib/pre-push-record-tests.ts
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
6
|
+
|
|
7
|
+
// src/lib/pre-push-failed-tests.ts
|
|
8
|
+
import { execFileSync } from "node:child_process";
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
10
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
12
|
+
var FAILED_TESTS_RECORD = "vinaya/pre-push-failed-tests.json";
|
|
13
|
+
var LAST_PUSH_RESULT = "vinaya/pre-push-last-result.json";
|
|
14
|
+
var SELECTION_NOTE = "vinaya/pre-push-selection.json";
|
|
15
|
+
var TEST_SELECTION_COMPLETE = "vinaya-test-selection-complete ";
|
|
16
|
+
function completedTestSelection(log, cwd, expected) {
|
|
17
|
+
const completed = new Set;
|
|
18
|
+
let batch = [];
|
|
19
|
+
let markers = 0;
|
|
20
|
+
const absolute = (path) => isAbsolute(path) ? path : join(cwd, path);
|
|
21
|
+
for (const line of log.split(`
|
|
22
|
+
`)) {
|
|
23
|
+
if (!line.startsWith(TEST_SELECTION_COMPLETE)) {
|
|
24
|
+
batch.push(line);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const result = JSON.parse(line.slice(TEST_SELECTION_COMPLETE.length));
|
|
29
|
+
if (![0, 1].includes(result.exitCode) || !Array.isArray(result.files) || !result.files.every((file) => typeof file === "string"))
|
|
30
|
+
return false;
|
|
31
|
+
const text = batch.join(`
|
|
32
|
+
`);
|
|
33
|
+
const summary = [...text.matchAll(/^Ran \d+ tests? across (\d+) files?\.(?:.*)$/gm)].at(-1);
|
|
34
|
+
const headers = new Set([...text.matchAll(/^(\S.*\.test\.[a-zA-Z]+):$/gm)].map((match) => absolute(match[1])));
|
|
35
|
+
const files = new Set(result.files.map(absolute));
|
|
36
|
+
if (!summary || Number(summary[1]) !== files.size || headers.size !== files.size || [...files].some((file) => !headers.has(file)))
|
|
37
|
+
return false;
|
|
38
|
+
for (const file of files)
|
|
39
|
+
completed.add(file);
|
|
40
|
+
markers++;
|
|
41
|
+
batch = [];
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (markers === 0 || batch.join(`
|
|
47
|
+
`).trim() !== "")
|
|
48
|
+
return false;
|
|
49
|
+
return expected === undefined || new Set(expected.map(absolute)).size === completed.size && expected.every((file) => completed.has(absolute(file)));
|
|
50
|
+
}
|
|
51
|
+
function parseFailedTestFiles(log, cwd, exitedNonZero, selected) {
|
|
52
|
+
if (exitedNonZero && !completedTestSelection(log, cwd, selected))
|
|
53
|
+
return "all";
|
|
54
|
+
const failed = new Set;
|
|
55
|
+
let current = null;
|
|
56
|
+
for (const raw of log.split(`
|
|
57
|
+
`)) {
|
|
58
|
+
const line = raw.trimEnd();
|
|
59
|
+
if (/^\d+ tests? failed:/.test(line)) {
|
|
60
|
+
current = null;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const header = /^(\S.*\.test\.[a-zA-Z]+):$/.exec(line);
|
|
64
|
+
if (header?.[1]) {
|
|
65
|
+
current = isAbsolute(header[1]) ? header[1] : join(cwd, header[1]);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (current && (/^\(fail\) /.test(line) || line.startsWith("# Unhandled error")))
|
|
69
|
+
failed.add(current);
|
|
70
|
+
}
|
|
71
|
+
if (failed.size === 0)
|
|
72
|
+
return exitedNonZero ? "all" : [];
|
|
73
|
+
return [...failed].sort();
|
|
74
|
+
}
|
|
75
|
+
function chooseTests(inputs) {
|
|
76
|
+
const { record, head, branch, fullSelection } = inputs;
|
|
77
|
+
const full = {
|
|
78
|
+
version: 1,
|
|
79
|
+
mode: "full",
|
|
80
|
+
head,
|
|
81
|
+
fullCount: fullSelection.length,
|
|
82
|
+
selected: fullSelection
|
|
83
|
+
};
|
|
84
|
+
if (!record || record.failed === "all" || record.selectionCompleted !== true)
|
|
85
|
+
return full;
|
|
86
|
+
if (record.branch !== branch || !inputs.recordIsAncestor)
|
|
87
|
+
return full;
|
|
88
|
+
if (!record.failed.every(inputs.exists))
|
|
89
|
+
return full;
|
|
90
|
+
const rerunFailed = [...record.failed];
|
|
91
|
+
const affectedSince = inputs.affectedSince.filter(inputs.exists).sort();
|
|
92
|
+
const selected = [...new Set([...rerunFailed, ...affectedSince])].sort();
|
|
93
|
+
if (selected.length === 0)
|
|
94
|
+
return full;
|
|
95
|
+
return {
|
|
96
|
+
version: 1,
|
|
97
|
+
mode: "rerun",
|
|
98
|
+
head,
|
|
99
|
+
rerunOf: record.head,
|
|
100
|
+
recordedHead: record.head,
|
|
101
|
+
rerunFailed,
|
|
102
|
+
affectedSince,
|
|
103
|
+
fullCount: fullSelection.length,
|
|
104
|
+
selected
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function recordFromRun(outcome, failed, head, branch, now) {
|
|
108
|
+
if (outcome === "passed")
|
|
109
|
+
return null;
|
|
110
|
+
return { version: 1, head, branch, failed, recordedAt: now.toISOString(), selectionCompleted: failed !== "all" };
|
|
111
|
+
}
|
|
112
|
+
function parseRecord(text) {
|
|
113
|
+
if (!text)
|
|
114
|
+
return null;
|
|
115
|
+
try {
|
|
116
|
+
const value = JSON.parse(text);
|
|
117
|
+
if (value.version !== 1 || typeof value.head !== "string" || typeof value.branch !== "string")
|
|
118
|
+
return null;
|
|
119
|
+
if (value.failed !== "all" && !Array.isArray(value.failed))
|
|
120
|
+
return null;
|
|
121
|
+
return value;
|
|
122
|
+
} catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
var PASSING_RECORD_VERSION = 2;
|
|
127
|
+
var SELECTION_POLICY = {
|
|
128
|
+
name: "pre-push-since-green",
|
|
129
|
+
version: 1,
|
|
130
|
+
depth: "one",
|
|
131
|
+
testTimeoutMs: 30000,
|
|
132
|
+
rootConfigFile: "vinaya.config.json"
|
|
133
|
+
};
|
|
134
|
+
var VERIFICATION_LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "yarn.lock", "pnpm-lock.yaml"];
|
|
135
|
+
var VERIFICATION_INPUT_FILES = ["vinaya.config.json", "package.json", "bunfig.toml", ...VERIFICATION_LOCKFILES];
|
|
136
|
+
var VERIFICATION_ENV_KEYS = ["BUN_ENV", "CI", "NODE_ENV", "NODE_OPTIONS", "TZ"];
|
|
137
|
+
function parsePassingRecord(text) {
|
|
138
|
+
if (!text)
|
|
139
|
+
return null;
|
|
140
|
+
try {
|
|
141
|
+
const value = JSON.parse(text);
|
|
142
|
+
if (value.version !== PASSING_RECORD_VERSION || value.kind !== "passed")
|
|
143
|
+
return null;
|
|
144
|
+
if (typeof value.head !== "string" || typeof value.branch !== "string" || typeof value.context !== "string")
|
|
145
|
+
return null;
|
|
146
|
+
if (!Array.isArray(value.selection) || !value.selection.every((file) => typeof file === "string"))
|
|
147
|
+
return null;
|
|
148
|
+
return value;
|
|
149
|
+
} catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function parseSelectionNote(text, head) {
|
|
154
|
+
if (!text)
|
|
155
|
+
return null;
|
|
156
|
+
try {
|
|
157
|
+
const value = JSON.parse(text);
|
|
158
|
+
if (value.head !== head || !Array.isArray(value.selected))
|
|
159
|
+
return null;
|
|
160
|
+
if (!value.selected.every((file) => typeof file === "string"))
|
|
161
|
+
return null;
|
|
162
|
+
return { mode: "full", ...value };
|
|
163
|
+
} catch {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function passingRecordFromRun(inputs) {
|
|
168
|
+
const { selection, head, branch } = inputs;
|
|
169
|
+
if (inputs.outcome !== "passed" || !selection || selection.head !== head)
|
|
170
|
+
return null;
|
|
171
|
+
if (selection.selected.length === 0 || !head || !branch || branch === "HEAD")
|
|
172
|
+
return null;
|
|
173
|
+
if (!selection.context || inputs.context !== selection.context || inputs.inputsClean !== true)
|
|
174
|
+
return null;
|
|
175
|
+
if (!completedTestSelection(inputs.log, inputs.repoRoot, selection.selected))
|
|
176
|
+
return null;
|
|
177
|
+
return {
|
|
178
|
+
version: PASSING_RECORD_VERSION,
|
|
179
|
+
kind: "passed",
|
|
180
|
+
head,
|
|
181
|
+
branch,
|
|
182
|
+
selection: [...selection.selected],
|
|
183
|
+
selectionCompleted: true,
|
|
184
|
+
context: selection.context,
|
|
185
|
+
recordedAt: inputs.now.toISOString()
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function decideSelection(deps) {
|
|
189
|
+
const context = deps.context !== null && deps.inputsClean === true ? deps.context : null;
|
|
190
|
+
const withContext = (note) => context === null ? note : { ...note, context };
|
|
191
|
+
const sinceGreen = deps.failed === null ? sinceGreenNote(deps, context) : null;
|
|
192
|
+
if (sinceGreen)
|
|
193
|
+
return { note: withContext(sinceGreen), full: null };
|
|
194
|
+
const full = deps.full();
|
|
195
|
+
const record = deps.failed;
|
|
196
|
+
const recordIsAncestor = record ? deps.isAncestor(record.head) : false;
|
|
197
|
+
let usable = record;
|
|
198
|
+
let affectedSince = [];
|
|
199
|
+
if (record && record.failed !== "all" && recordIsAncestor && record.branch === deps.branch) {
|
|
200
|
+
const changed = deps.changedBetween(record.head);
|
|
201
|
+
if (changed === null)
|
|
202
|
+
usable = null;
|
|
203
|
+
else
|
|
204
|
+
affectedSince = deps.affectedSince(changed);
|
|
205
|
+
}
|
|
206
|
+
const note = chooseTests({
|
|
207
|
+
record: usable,
|
|
208
|
+
head: deps.head,
|
|
209
|
+
branch: deps.branch,
|
|
210
|
+
recordIsAncestor,
|
|
211
|
+
fullSelection: full.selected,
|
|
212
|
+
affectedSince,
|
|
213
|
+
exists: deps.exists
|
|
214
|
+
});
|
|
215
|
+
return { note: withContext(note), full };
|
|
216
|
+
}
|
|
217
|
+
function sinceGreenNote(deps, context) {
|
|
218
|
+
const passing = deps.passing;
|
|
219
|
+
if (!passing || passing.selectionCompleted !== true || passing.selection.length === 0)
|
|
220
|
+
return null;
|
|
221
|
+
if (passing.branch !== deps.branch || context === null || passing.context !== context)
|
|
222
|
+
return null;
|
|
223
|
+
if (!deps.isAncestor(passing.head))
|
|
224
|
+
return null;
|
|
225
|
+
const changed = deps.changedBetween(passing.head);
|
|
226
|
+
if (changed === null || changed.includes(join(deps.repoRoot, SELECTION_POLICY.rootConfigFile)))
|
|
227
|
+
return null;
|
|
228
|
+
const read = deps.sinceGreen(passing.head);
|
|
229
|
+
if (read.readFailed)
|
|
230
|
+
return null;
|
|
231
|
+
const selected = [...new Set(read.selected)].filter(deps.exists).sort();
|
|
232
|
+
const affectedSince = selected.filter((file) => !deps.isAlwaysRun(file) || changed.includes(file));
|
|
233
|
+
if (changed.length > 0 && affectedSince.length === 0)
|
|
234
|
+
return null;
|
|
235
|
+
return {
|
|
236
|
+
version: 1,
|
|
237
|
+
mode: "since-green",
|
|
238
|
+
head: deps.head,
|
|
239
|
+
recordedHead: passing.head,
|
|
240
|
+
affectedSince,
|
|
241
|
+
fullCount: null,
|
|
242
|
+
selected
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function cleanGitEnv() {
|
|
246
|
+
const env = { ...process.env };
|
|
247
|
+
for (const key of Object.keys(env))
|
|
248
|
+
if (key.startsWith("GIT_"))
|
|
249
|
+
delete env[key];
|
|
250
|
+
return env;
|
|
251
|
+
}
|
|
252
|
+
function git(repoRoot, args) {
|
|
253
|
+
try {
|
|
254
|
+
return execFileSync("git", args, {
|
|
255
|
+
cwd: repoRoot,
|
|
256
|
+
encoding: "utf8",
|
|
257
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
258
|
+
env: cleanGitEnv()
|
|
259
|
+
}).trim();
|
|
260
|
+
} catch {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function gitPath(repoRoot, name) {
|
|
265
|
+
const out = git(repoRoot, ["rev-parse", "--git-path", name]);
|
|
266
|
+
if (!out)
|
|
267
|
+
return null;
|
|
268
|
+
return isAbsolute(out) ? out : join(repoRoot, out);
|
|
269
|
+
}
|
|
270
|
+
function currentHead(repoRoot) {
|
|
271
|
+
return git(repoRoot, ["rev-parse", "HEAD"]) ?? "";
|
|
272
|
+
}
|
|
273
|
+
function currentBranch(repoRoot) {
|
|
274
|
+
return git(repoRoot, ["rev-parse", "--abbrev-ref", "HEAD"]) ?? "";
|
|
275
|
+
}
|
|
276
|
+
function isAncestor(repoRoot, ancestor, head) {
|
|
277
|
+
try {
|
|
278
|
+
execFileSync("git", ["merge-base", "--is-ancestor", ancestor, head], {
|
|
279
|
+
cwd: repoRoot,
|
|
280
|
+
stdio: "ignore",
|
|
281
|
+
env: cleanGitEnv()
|
|
282
|
+
});
|
|
283
|
+
return true;
|
|
284
|
+
} catch {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function changedBetween(repoRoot, from, to) {
|
|
289
|
+
const read = git(repoRoot, ["diff", "--name-only", "--diff-filter=ACMRD", from, to]);
|
|
290
|
+
if (read === null)
|
|
291
|
+
return null;
|
|
292
|
+
return read.split(`
|
|
293
|
+
`).map((s) => s.trim()).filter(Boolean).map((f) => join(repoRoot, f));
|
|
294
|
+
}
|
|
295
|
+
function readJsonUnderGit(repoRoot, name) {
|
|
296
|
+
const path = gitPath(repoRoot, name);
|
|
297
|
+
if (!path || !existsSync(path))
|
|
298
|
+
return null;
|
|
299
|
+
try {
|
|
300
|
+
return readFileSync(path, "utf8");
|
|
301
|
+
} catch {
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function writeJsonUnderGit(repoRoot, name, value) {
|
|
306
|
+
const path = gitPath(repoRoot, name);
|
|
307
|
+
if (!path)
|
|
308
|
+
return;
|
|
309
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
310
|
+
writeFileSync(path, `${JSON.stringify(value, null, 2)}
|
|
311
|
+
`);
|
|
312
|
+
}
|
|
313
|
+
function removeUnderGit(repoRoot, name) {
|
|
314
|
+
const path = gitPath(repoRoot, name);
|
|
315
|
+
if (path)
|
|
316
|
+
rmSync(path, { force: true });
|
|
317
|
+
}
|
|
318
|
+
function readFailedTestsRecord(repoRoot) {
|
|
319
|
+
return parseRecord(readJsonUnderGit(repoRoot, FAILED_TESTS_RECORD));
|
|
320
|
+
}
|
|
321
|
+
function readPassingRecord(repoRoot) {
|
|
322
|
+
return parsePassingRecord(readJsonUnderGit(repoRoot, FAILED_TESTS_RECORD));
|
|
323
|
+
}
|
|
324
|
+
function clearRecordOfKind(repoRoot, kind) {
|
|
325
|
+
const text = readJsonUnderGit(repoRoot, FAILED_TESTS_RECORD);
|
|
326
|
+
const other = kind === "failed" ? parsePassingRecord(text) : parseRecord(text);
|
|
327
|
+
if (text !== null && other !== null)
|
|
328
|
+
return;
|
|
329
|
+
removeUnderGit(repoRoot, FAILED_TESTS_RECORD);
|
|
330
|
+
}
|
|
331
|
+
function computeVerificationContext(repoRoot, env = process.env) {
|
|
332
|
+
try {
|
|
333
|
+
const sha = (data) => createHash("sha256").update(data).digest("hex");
|
|
334
|
+
const read = (name) => {
|
|
335
|
+
const path = join(repoRoot, name);
|
|
336
|
+
return existsSync(path) ? readFileSync(path) : null;
|
|
337
|
+
};
|
|
338
|
+
const json = (name) => {
|
|
339
|
+
const bytes = read(name);
|
|
340
|
+
return bytes === null ? null : JSON.parse(bytes.toString("utf8"));
|
|
341
|
+
};
|
|
342
|
+
const config = json("vinaya.config.json");
|
|
343
|
+
const pkg = json("package.json");
|
|
344
|
+
const scripts = pkg?.scripts;
|
|
345
|
+
const bunfig = read("bunfig.toml");
|
|
346
|
+
const parts = {
|
|
347
|
+
policy: sha(JSON.stringify(SELECTION_POLICY)),
|
|
348
|
+
inputs: sha(JSON.stringify({ prePush: config?.prePush ?? null, workspaces: pkg?.workspaces ?? null })),
|
|
349
|
+
lockfile: sha(VERIFICATION_LOCKFILES.map((name) => {
|
|
350
|
+
const bytes = read(name);
|
|
351
|
+
return `${name}:${bytes === null ? "absent" : sha(bytes)}`;
|
|
352
|
+
}).join(`
|
|
353
|
+
`)),
|
|
354
|
+
runner: sha(JSON.stringify({
|
|
355
|
+
bunfig: bunfig === null ? null : sha(bunfig),
|
|
356
|
+
testScript: scripts?.test ?? null,
|
|
357
|
+
bun: process.versions.bun ?? null
|
|
358
|
+
})),
|
|
359
|
+
environment: sha(VERIFICATION_ENV_KEYS.map((key) => `${key}=${env[key] ?? "\x00unset"}`).join(`
|
|
360
|
+
`))
|
|
361
|
+
};
|
|
362
|
+
return { digest: sha(JSON.stringify(parts)), parts };
|
|
363
|
+
} catch {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
function verificationInputsDirty(repoRoot) {
|
|
368
|
+
const out = git(repoRoot, ["status", "--porcelain", "--", ...VERIFICATION_INPUT_FILES]);
|
|
369
|
+
return out === null ? null : out !== "";
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/lib/pre-push-record-tests.ts
|
|
373
|
+
function main() {
|
|
374
|
+
if (process.argv[2] === "run") {
|
|
375
|
+
const files = process.argv.slice(3);
|
|
376
|
+
const result = spawnSync("bun", ["test", "--timeout=30000", "--", ...files], { stdio: "inherit" });
|
|
377
|
+
if (result.signal === null && (result.status === 0 || result.status === 1))
|
|
378
|
+
process.stdout.write(TEST_SELECTION_COMPLETE + JSON.stringify({ files, exitCode: result.status }) + `
|
|
379
|
+
`);
|
|
380
|
+
process.exitCode = result.status ?? 1;
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const repoRoot = process.cwd();
|
|
384
|
+
const outcome = process.argv[2] === "passed" ? "passed" : "failed";
|
|
385
|
+
const logPath = process.argv[3];
|
|
386
|
+
const elapsed = Number(process.argv[4]);
|
|
387
|
+
const envMode = process.env.VINAYA_PUSH_MODE;
|
|
388
|
+
const mode = envMode === "storage" || envMode === "ready" ? envMode : "default";
|
|
389
|
+
try {
|
|
390
|
+
let log = "";
|
|
391
|
+
if (logPath) {
|
|
392
|
+
try {
|
|
393
|
+
log = readFileSync2(logPath, "utf8");
|
|
394
|
+
} catch {
|
|
395
|
+
log = "";
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
const head = currentHead(repoRoot);
|
|
399
|
+
const branch = currentBranch(repoRoot);
|
|
400
|
+
const selection = mode === "storage" ? null : parseSelectionNote(readJsonUnderGit(repoRoot, SELECTION_NOTE), head);
|
|
401
|
+
const selectionCompleted = selection?.selected.length === 0 || mode === "storage" || completedTestSelection(log, repoRoot, selection?.selected);
|
|
402
|
+
const settledOutcome = outcome === "passed" && !selectionCompleted ? "failed" : outcome;
|
|
403
|
+
const failed = settledOutcome === "failed" ? parseFailedTestFiles(log, repoRoot, true, selection?.selected) : [];
|
|
404
|
+
const record = outcome === "failed" ? recordFromRun("failed", failed, head, branch, new Date) : null;
|
|
405
|
+
const passing = outcome === "passed" ? passingRecordFromRun({
|
|
406
|
+
outcome,
|
|
407
|
+
selection,
|
|
408
|
+
log,
|
|
409
|
+
repoRoot,
|
|
410
|
+
head,
|
|
411
|
+
branch,
|
|
412
|
+
context: computeVerificationContext(repoRoot)?.digest ?? null,
|
|
413
|
+
inputsClean: verificationInputsDirty(repoRoot) === false,
|
|
414
|
+
now: new Date
|
|
415
|
+
}) : null;
|
|
416
|
+
if (record)
|
|
417
|
+
writeJsonUnderGit(repoRoot, FAILED_TESTS_RECORD, record);
|
|
418
|
+
else if (passing)
|
|
419
|
+
writeJsonUnderGit(repoRoot, FAILED_TESTS_RECORD, passing);
|
|
420
|
+
else if (mode === "storage" || selection?.selected.length === 0)
|
|
421
|
+
clearRecordOfKind(repoRoot, "failed");
|
|
422
|
+
else
|
|
423
|
+
clearRecordOfKind(repoRoot, "passed");
|
|
424
|
+
const result = {
|
|
425
|
+
version: 1,
|
|
426
|
+
head,
|
|
427
|
+
branch,
|
|
428
|
+
mode,
|
|
429
|
+
outcome: settledOutcome,
|
|
430
|
+
selectionCompleted,
|
|
431
|
+
selection,
|
|
432
|
+
failed,
|
|
433
|
+
elapsedSeconds: Number.isFinite(elapsed) ? elapsed : null,
|
|
434
|
+
recordedAt: new Date().toISOString()
|
|
435
|
+
};
|
|
436
|
+
writeJsonUnderGit(repoRoot, LAST_PUSH_RESULT, result);
|
|
437
|
+
if (record && record.failed !== "all") {
|
|
438
|
+
process.stderr.write(`vinaya pre-push: recorded ${record.failed.length} failing file(s) — the next push re-runs only those plus what the fix affects.
|
|
439
|
+
`);
|
|
440
|
+
}
|
|
441
|
+
} catch (err) {
|
|
442
|
+
process.stderr.write(`vinaya pre-push: could not record this run (${err instanceof Error ? err.message : String(err)}).
|
|
443
|
+
`);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
main();
|