@cbartens/bkit 5.2.4 → 5.3.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/.bkit/README.md +26 -11
- package/.bkit/core/.agents/context.md +1 -1
- package/.bkit/core/.agents/docs.md +1 -1
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +1 -1
- package/.bkit/core/.agents/rules.md +11 -0
- package/.bkit/core/.bkit/README.md +25 -10
- package/.bkit/core/.bkit/cloud.md +9 -8
- package/.bkit/core/.bkit/comparison.md +68 -345
- package/.bkit/core/.bkit/install.md +12 -6
- package/.bkit/core/.bkit/lite.md +73 -0
- package/.bkit/core/.bkit/pipeline.md +345 -0
- package/.bkit/core/.bkit/prompts.md +88 -73
- package/.bkit/core/.bkit/providers.md +41 -22
- package/.bkit/core/.bkit/templates.md +106 -17
- package/.bkit/core/.bkit/trackers.md +47 -1
- package/.bkit/core/.bkit/workflows.md +44 -43
- package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +1 -1
- package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +7 -4
- package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +8 -5
- package/.bkit/core/docs/templates/bkit-audit-adoption.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +14 -10
- package/.bkit/core/docs/templates/bkit-audit-llm.md +20 -14
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +10 -8
- package/.bkit/core/docs/templates/bkit-audit-security.md +3 -3
- package/.bkit/core/docs/templates/bkit-audit-testing.md +4 -3
- package/.bkit/core/docs/templates/bkit-plan.md +8 -6
- package/.bkit/core/engine/checks/after/auth.ts +9 -9
- package/.bkit/core/engine/checks/after/ci-yml.ts +14 -12
- package/.bkit/core/engine/checks/after/github.ts +29 -120
- package/.bkit/core/engine/checks/after/index.ts +2 -2
- package/.bkit/core/engine/checks/after/managed.ts +8 -28
- package/.bkit/core/engine/checks/after/tools.ts +3 -15
- package/.bkit/core/engine/checks/before/context-fetch.ts +1 -21
- package/.bkit/core/engine/checks/before/index.ts +7 -43
- package/.bkit/core/engine/checks/before/mcp.ts +17 -8
- package/.bkit/core/engine/checks/before/repo.ts +9 -12
- package/.bkit/core/engine/checks/status-holes.ts +4 -5
- package/.bkit/core/engine/checks/tips/catalogue.ts +60 -24
- package/.bkit/core/engine/checks/tips/detect.ts +45 -2
- package/.bkit/core/engine/checks/tips/index.ts +37 -8
- package/.bkit/core/engine/cli.ts +39 -16
- package/.bkit/core/engine/commands/analysis.ts +36 -26
- package/.bkit/core/engine/commands/comply.ts +17 -16
- package/.bkit/core/engine/commands/harvest.ts +12 -12
- package/.bkit/core/engine/commands/install/doctor.ts +57 -28
- package/.bkit/core/engine/commands/install/install.ts +62 -126
- package/.bkit/core/engine/commands/install/uninstall.ts +191 -33
- package/.bkit/core/engine/commands/install/upgrade.ts +49 -43
- package/.bkit/core/engine/commands/lib.ts +35 -10
- package/.bkit/core/engine/commands/tips.ts +8 -5
- package/.bkit/core/engine/commands/workflow/branches.ts +4 -4
- package/.bkit/core/engine/commands/workflow/counters.ts +21 -12
- package/.bkit/core/engine/commands/workflow/fids.ts +46 -0
- package/.bkit/core/engine/commands/workflow/ledgers.ts +3 -1
- package/.bkit/core/engine/commands/workflow/prs.ts +4 -2
- package/.bkit/core/engine/commands/workflow/repo.ts +2 -2
- package/.bkit/core/engine/commands/workflow/roadmap.ts +4 -3
- package/.bkit/core/engine/commands/workflow/runs.ts +8 -7
- package/.bkit/core/engine/commands/workflow/steps.ts +1 -0
- package/.bkit/core/engine/commands/workflow/tests.ts +17 -5
- package/.bkit/core/engine/commands/workflow/workflows.ts +15 -14
- package/.bkit/core/engine/commands/workflow/workstreams.ts +2 -1
- package/.bkit/core/engine/commands/workflow/worktrees.ts +13 -5
- package/.bkit/core/engine/install/cloud-env.ts +10 -31
- package/.bkit/core/engine/install/manifest.ts +14 -7
- package/.bkit/core/engine/install/modules/antigravity.ts +15 -26
- package/.bkit/core/engine/install/modules/claude.ts +20 -28
- package/.bkit/core/engine/install/modules/cloud.ts +5 -2
- package/.bkit/core/engine/install/modules/codex.ts +15 -29
- package/.bkit/core/engine/install/modules/core.ts +91 -70
- package/.bkit/core/engine/install/modules/cursor.ts +6 -20
- package/.bkit/core/engine/install/modules/index.ts +7 -1
- package/.bkit/core/engine/install/modules/opencode.ts +48 -70
- package/.bkit/core/engine/install/network-allowlist.ts +73 -0
- package/.bkit/core/engine/install/placeholders.ts +3 -18
- package/.bkit/core/engine/install/write.ts +59 -12
- package/.bkit/core/engine/ledgers/telemetry.ts +6 -4
- package/.bkit/core/engine/render/hosts.ts +47 -67
- package/.bkit/core/engine/render/models.ts +29 -11
- package/.bkit/core/engine/shared/branches.ts +13 -0
- package/.bkit/core/engine/shared/egress.ts +3 -3
- package/.bkit/core/engine/shared/json.ts +18 -1
- package/.bkit/core/engine/shared/package-json.ts +63 -0
- package/.bkit/core/engine/shared/package-roots.ts +0 -10
- package/.bkit/core/engine/shared/protected-paths.ts +5 -130
- package/.bkit/core/engine/shared/settings.ts +36 -0
- package/.bkit/core/hooks/antigravity-hook.js +1 -0
- package/.bkit/core/hooks/guardrails-shell.js +186 -40
- package/.bkit/core/hooks/guardrails-tiers.js +5 -78
- package/.bkit/core/prompts/bkit-audit-generate.md +60 -7
- package/.bkit/core/prompts/bkit-build-challenge-1.md +1 -1
- package/.bkit/core/prompts/bkit-build-challenge-2.md +1 -1
- package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +1 -1
- package/.bkit/core/prompts/bkit-build-challenge-remediate.md +1 -1
- package/.bkit/core/prompts/bkit-build-challenge-tests.md +1 -1
- package/.bkit/core/prompts/bkit-build-install-skills.md +1 -1
- package/.bkit/core/prompts/bkit-build-plan-current.md +1 -1
- package/.bkit/core/prompts/bkit-build-plan-execute.md +4 -4
- package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +1 -1
- package/.bkit/core/prompts/bkit-build-plan-verify.md +2 -2
- package/.bkit/core/prompts/bkit-debug-abort-handover.md +1 -1
- package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +1 -1
- package/.bkit/core/prompts/bkit-debug-failure-remediate.md +1 -1
- package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +78 -0
- package/.bkit/core/prompts/bkit-debug-failure-soak.md +1 -1
- package/.bkit/core/prompts/bkit-debug-summary.md +3 -3
- package/.bkit/core/prompts/bkit-design-spike.md +1 -1
- package/.bkit/core/prompts/bkit-design-summary.md +2 -2
- package/.bkit/core/prompts/bkit-design-update.md +1 -1
- package/.bkit/core/prompts/bkit-plan-complexity-check.md +1 -1
- package/.bkit/core/prompts/bkit-plan-generate.md +1 -1
- package/.bkit/core/prompts/bkit-plan-scope-check-1.md +1 -1
- package/.bkit/core/prompts/bkit-plan-scope-check-2.md +1 -1
- package/.bkit/core/prompts/bkit-plan-summary.md +1 -1
- package/.bkit/core/prompts/bkit-plan-update.md +1 -1
- package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +1 -1
- package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +1 -1
- package/.bkit/core/prompts/bkit-ship-update-docs.md +1 -1
- package/.bkit/core/prompts/bkit-utility-update-decisions.md +9 -2
- package/.bkit/core/prompts/bkit-utility-update-deferrals.md +9 -2
- package/.bkit/core/prompts/bkit-utility-update-documentation.md +2 -1
- package/.bkit/core/prompts/bkit-utility-update-failures.md +9 -2
- package/.bkit/core/prompts/bkit-utility-update-knowledge.md +9 -2
- package/.bkit/core/prompts/bkit-utility-update-roadmap.md +11 -4
- package/.bkit/core/workflows/bkit-build.md +3 -3
- package/.bkit/core/workflows/bkit-debug.md +69 -33
- package/.bkit/core/workflows/bkit-design.md +2 -2
- package/.bkit/core/workflows/bkit-plan.md +11 -4
- package/.bkit/core/workflows/bkit-ship.md +5 -5
- package/.bkit/shared/.claude/bkit-cloud.md +46 -13
- package/.bkit/shared/.claude/settings.json +18 -0
- package/.bkit/shared/.cursor/mcp.json +2 -1
- package/.bkit/shared/.opencode/opencode.json +19 -1
- package/.bkit/shared/docs/deployments.md +20 -4
- package/.bkit/shared/docs/security.md +8 -6
- package/.bkit/shared/docs/testing.md +9 -5
- package/.bkit/templates/.cursor/Dockerfile +30 -16
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-bug.yml +78 -0
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +91 -0
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +56 -0
- package/.bkit/templates/.github/renovate.json5 +91 -12
- package/.bkit/templates/.github/workflows/bkit-ci.yml +66 -53
- package/.bkit/templates/.github/workflows/bkit-cloud.yml +3 -1
- package/.bkit/templates/.github/workflows/bkit-renovate.yml +8 -1
- package/.bkit/templates/.github/workflows/bkit-trivy.yml +67 -0
- package/.bkit/templates/.husky/pre-push +8 -3
- package/.bkit/templates/.oxlintrc.json +21 -0
- package/.bkit/templates/docs/capabilities.md +1 -1
- package/.bkit/templates/scripts/ci/check-capstone.mjs +176 -0
- package/.bkit/templates/scripts/ci/check-capstone.test.mjs +311 -0
- package/.bkit/templates/scripts/graphify/bkit-graph-eager.py +2 -2
- package/.bkit/templates/scripts/graphify/bkit-graph-imports.py +43 -20
- package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +33 -11
- package/.bkit/templates/scripts/graphify/bkit-graph-repair.py +3 -2
- package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +5 -5
- package/.bkit/templates/scripts/graphify/bkit-graphify.sh +79 -19
- package/CHANGELOG.md +50 -3
- package/README.md +258 -129
- package/dist/checks/after/auth.js +10 -11
- package/dist/checks/after/ci-yml.js +11 -14
- package/dist/checks/after/github.js +32 -125
- package/dist/checks/after/index.js +3 -2
- package/dist/checks/after/managed.js +8 -24
- package/dist/checks/after/tools.js +3 -16
- package/dist/checks/before/context-fetch.js +1 -21
- package/dist/checks/before/index.js +6 -42
- package/dist/checks/before/mcp.js +14 -9
- package/dist/checks/before/repo.js +8 -11
- package/dist/checks/status-holes.js +5 -6
- package/dist/checks/tips/catalogue.js +51 -18
- package/dist/checks/tips/detect.js +41 -2
- package/dist/checks/tips/index.js +25 -5
- package/dist/cli.js +34 -14
- package/dist/commands/analysis.js +21 -5
- package/dist/commands/comply.js +20 -18
- package/dist/commands/harvest.js +12 -13
- package/dist/commands/install/doctor.js +55 -23
- package/dist/commands/install/install.js +62 -118
- package/dist/commands/install/uninstall.js +165 -31
- package/dist/commands/install/upgrade.js +46 -39
- package/dist/commands/lib.js +32 -10
- package/dist/commands/tips.js +6 -3
- package/dist/commands/workflow/branches.js +3 -5
- package/dist/commands/workflow/counters.js +17 -7
- package/dist/commands/workflow/fids.js +39 -0
- package/dist/commands/workflow/ledgers.js +3 -1
- package/dist/commands/workflow/prs.js +3 -3
- package/dist/commands/workflow/repo.js +2 -2
- package/dist/commands/workflow/roadmap.js +4 -4
- package/dist/commands/workflow/runs.js +5 -5
- package/dist/commands/workflow/steps.js +1 -0
- package/dist/commands/workflow/tests.js +16 -3
- package/dist/commands/workflow/workflows.js +15 -15
- package/dist/commands/workflow/workstreams.js +2 -1
- package/dist/commands/workflow/worktrees.js +4 -5
- package/dist/install/cloud-env.js +10 -23
- package/dist/install/manifest.js +14 -7
- package/dist/install/modules/antigravity.js +15 -26
- package/dist/install/modules/claude.js +17 -21
- package/dist/install/modules/cloud.js +6 -2
- package/dist/install/modules/codex.js +15 -29
- package/dist/install/modules/core.js +82 -63
- package/dist/install/modules/cursor.js +6 -9
- package/dist/install/modules/index.js +6 -1
- package/dist/install/modules/opencode.js +41 -72
- package/dist/install/network-allowlist.js +62 -0
- package/dist/install/placeholders.js +3 -16
- package/dist/install/write.js +55 -15
- package/dist/ledgers/telemetry.js +5 -4
- package/dist/render/hosts.js +30 -55
- package/dist/render/models.js +20 -9
- package/dist/shared/branches.js +11 -0
- package/dist/shared/egress.js +0 -2
- package/dist/shared/json.js +14 -0
- package/dist/shared/package-json.js +61 -0
- package/dist/shared/package-roots.js +0 -8
- package/dist/shared/protected-paths.js +5 -122
- package/dist/shared/settings.js +18 -1
- package/package.json +21 -17
- package/.bkit/core/.agents/shortcuts.md +0 -73
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Example. Copy into scripts/ci/ and own it. bkit install does not write this file
|
|
3
|
+
// and does not overwrite a copy.
|
|
4
|
+
/**
|
|
5
|
+
* check-capstone.test.mjs — unit tests for the capstone gate.
|
|
6
|
+
*
|
|
7
|
+
* Pure Node, no runner: `node scripts/ci/check-capstone.test.mjs`.
|
|
8
|
+
* Exit: 0 = all tests passed, 1 = at least one test failed.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { spawnSync } from "node:child_process";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { checkCapstone } from "./check-capstone.mjs";
|
|
15
|
+
|
|
16
|
+
const SCRIPT = path.join(path.dirname(fileURLToPath(import.meta.url)), "check-capstone.mjs");
|
|
17
|
+
|
|
18
|
+
let passed = 0;
|
|
19
|
+
let failed = 0;
|
|
20
|
+
|
|
21
|
+
function test(name, fn) {
|
|
22
|
+
try {
|
|
23
|
+
fn();
|
|
24
|
+
passed++;
|
|
25
|
+
console.log(` ok ${name}`);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
failed++;
|
|
28
|
+
console.log(` FAIL ${name} — ${err.message}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function assert(cond, message) {
|
|
33
|
+
if (!cond) throw new Error(message);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The environment of a capstone that watches a static lane and a counted unit lane. */
|
|
37
|
+
const base = (extra = {}) => ({
|
|
38
|
+
LANES: "static,unit",
|
|
39
|
+
STATIC_RESULT: "success",
|
|
40
|
+
UNIT_RESULT: "success",
|
|
41
|
+
UNIT_RAN: "12",
|
|
42
|
+
UNIT_CACHE_SKIP: "",
|
|
43
|
+
...extra,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/** The planner shape: scope + a run level, with a counted integration lane too. */
|
|
47
|
+
const planned = (extra = {}) => ({
|
|
48
|
+
LANES: "static,unit,integration",
|
|
49
|
+
PLAN: JSON.stringify({ run_level: "full" }),
|
|
50
|
+
SCOPE_RESULT: "success",
|
|
51
|
+
STATIC_RESULT: "success",
|
|
52
|
+
UNIT_RESULT: "success",
|
|
53
|
+
UNIT_RAN: "12",
|
|
54
|
+
UNIT_CACHE_SKIP: "false",
|
|
55
|
+
INTEGRATION_RESULT: "success",
|
|
56
|
+
INTEGRATION_RAN: "4",
|
|
57
|
+
INTEGRATION_CACHE_SKIP: "false",
|
|
58
|
+
...extra,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const skipPlan = (extra = {}) =>
|
|
62
|
+
planned({
|
|
63
|
+
PLAN: JSON.stringify({ run_level: "none" }),
|
|
64
|
+
STATIC_RESULT: "skipped",
|
|
65
|
+
UNIT_RESULT: "skipped",
|
|
66
|
+
UNIT_RAN: "",
|
|
67
|
+
UNIT_CACHE_SKIP: "",
|
|
68
|
+
INTEGRATION_RESULT: "skipped",
|
|
69
|
+
INTEGRATION_RAN: "",
|
|
70
|
+
INTEGRATION_CACHE_SKIP: "",
|
|
71
|
+
...extra,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const reds = (env, needle) => {
|
|
75
|
+
const r = checkCapstone(env);
|
|
76
|
+
assert(r.errors.length > 0, `expected a failure, got ${JSON.stringify(r)}`);
|
|
77
|
+
if (needle) {
|
|
78
|
+
assert(
|
|
79
|
+
r.errors.some((e) => e.includes(needle)),
|
|
80
|
+
`no error mentions ${JSON.stringify(needle)}: ${JSON.stringify(r.errors)}`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return r;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const greens = (env) => {
|
|
87
|
+
const r = checkCapstone(env);
|
|
88
|
+
assert(r.errors.length === 0, `expected a pass, got ${JSON.stringify(r.errors)}`);
|
|
89
|
+
return r;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// ── the clean pass ───────────────────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
test("every lane succeeded and the counted lane ran tests: passes", () => {
|
|
95
|
+
const r = greens(base());
|
|
96
|
+
assert(r.warnings.length === 0, `warnings ${JSON.stringify(r.warnings)}`);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("with a plan: scope, every lane and every count good passes", () => {
|
|
100
|
+
greens(planned());
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// ── case 1: a lane whose result is not success ──────────────────────────────
|
|
104
|
+
|
|
105
|
+
test("a failed lane fails, naming the lane and its result", () => {
|
|
106
|
+
reds(base({ STATIC_RESULT: "failure" }), "bkit-tests-static");
|
|
107
|
+
const r = reds(base({ UNIT_RESULT: "failure" }), "result=failure");
|
|
108
|
+
assert(
|
|
109
|
+
r.errors.some((e) => e.includes("bkit-tests-unit")),
|
|
110
|
+
"lane not named",
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("a skipped or cancelled lane fails when the lane was expected to run", () => {
|
|
115
|
+
reds(base({ STATIC_RESULT: "skipped" }), "result=skipped");
|
|
116
|
+
reds(base({ UNIT_RESULT: "cancelled" }), "result=cancelled");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("with a plan, a failed lane fails naming the run level", () => {
|
|
120
|
+
reds(planned({ INTEGRATION_RESULT: "failure" }), "run_level=full");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("a lane whose result was never wired in fails", () => {
|
|
124
|
+
const env = base();
|
|
125
|
+
delete env.STATIC_RESULT;
|
|
126
|
+
reds(env, "STATIC_RESULT");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("a failed scope job fails even when every lane succeeded", () => {
|
|
130
|
+
reds(planned({ SCOPE_RESULT: "failure" }), "bkit-tests-scope");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// ── case 2: a gated lane ran although the plan said skip ────────────────────
|
|
134
|
+
|
|
135
|
+
test("run_level=none with every lane skipped passes", () => {
|
|
136
|
+
greens(skipPlan());
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("run_level=none but a lane ran (success) fails", () => {
|
|
140
|
+
reds(skipPlan({ UNIT_RESULT: "success", UNIT_RAN: "5" }), "bkit-tests-unit");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("run_level=none but a lane ran (failure) fails", () => {
|
|
144
|
+
reds(skipPlan({ STATIC_RESULT: "failure" }), "bkit-tests-static");
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("run_level=none ignores counts on skipped lanes", () => {
|
|
148
|
+
greens(skipPlan({ UNIT_RAN: "0", INTEGRATION_RAN: "not-a-number" }));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// ── case 3: success with 0 tests, or a count that is not a number ───────────
|
|
152
|
+
|
|
153
|
+
test("a lane that succeeded having run 0 tests fails", () => {
|
|
154
|
+
reds(base({ UNIT_RAN: "0" }), "0 tests");
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test("a zero written with leading zeros is still zero", () => {
|
|
158
|
+
reds(base({ UNIT_RAN: "00" }), "0 tests");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("a non-numeric count fails", () => {
|
|
162
|
+
reds(base({ UNIT_RAN: "abc" }), "non-numeric");
|
|
163
|
+
reds(base({ UNIT_RAN: "-3" }), "non-numeric");
|
|
164
|
+
reds(base({ UNIT_RAN: "1.5" }), "non-numeric");
|
|
165
|
+
reds(base({ UNIT_RAN: " 4" }), "non-numeric");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("an empty count fails by default", () => {
|
|
169
|
+
reds(base({ UNIT_RAN: "" }), "non-numeric");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("a positive count passes", () => {
|
|
173
|
+
greens(base({ UNIT_RAN: "1" }));
|
|
174
|
+
greens(base({ UNIT_RAN: "0042" }));
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("each counted lane is checked on its own", () => {
|
|
178
|
+
reds(planned({ UNIT_RAN: "9", INTEGRATION_RAN: "0" }), "bkit-tests-integration");
|
|
179
|
+
reds(planned({ UNIT_RAN: "0", INTEGRATION_RAN: "9" }), "bkit-tests-unit");
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("a lane with no <LANE>_RAN variable is not count-checked", () => {
|
|
183
|
+
const env = base();
|
|
184
|
+
assert(!("STATIC_RAN" in env), "fixture sets STATIC_RAN");
|
|
185
|
+
greens(env);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("a count on a lane that did not succeed is not double-reported", () => {
|
|
189
|
+
const r = reds(base({ UNIT_RESULT: "failure", UNIT_RAN: "0" }), "result=failure");
|
|
190
|
+
assert(r.errors.length === 1, `errors ${JSON.stringify(r.errors)}`);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// ── case 4: a plan that will not parse ──────────────────────────────────────
|
|
194
|
+
|
|
195
|
+
test("a plan that is not JSON fails", () => {
|
|
196
|
+
reds(planned({ PLAN: "{not json" }), "plan");
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("an empty plan fails (a planner that emitted nothing)", () => {
|
|
200
|
+
reds(planned({ PLAN: "" }), "plan");
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test("a plan that is not an object, or has no run_level, fails", () => {
|
|
204
|
+
reds(planned({ PLAN: "[]" }), "plan");
|
|
205
|
+
reds(planned({ PLAN: "null" }), "plan");
|
|
206
|
+
reds(planned({ PLAN: '"full"' }), "plan");
|
|
207
|
+
reds(planned({ PLAN: "{}" }), "plan");
|
|
208
|
+
reds(planned({ PLAN: '{"run_level":""}' }), "plan");
|
|
209
|
+
reds(planned({ PLAN: '{"run_level":3}' }), "plan");
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test("an unparseable plan never lets a skipped lane pass as 'nothing planned'", () => {
|
|
213
|
+
reds(skipPlan({ PLAN: "{not json" }), "plan");
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// ── the exemptions ──────────────────────────────────────────────────────────
|
|
217
|
+
|
|
218
|
+
test("cache_skip=true asserts no count", () => {
|
|
219
|
+
greens(base({ UNIT_CACHE_SKIP: "true", UNIT_RAN: "" }));
|
|
220
|
+
greens(base({ UNIT_CACHE_SKIP: "true", UNIT_RAN: "0" }));
|
|
221
|
+
greens(planned({ INTEGRATION_CACHE_SKIP: "true", INTEGRATION_RAN: "0" }));
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test("cache_skip=true does not excuse a failed lane", () => {
|
|
225
|
+
reds(base({ UNIT_RESULT: "failure", UNIT_CACHE_SKIP: "true" }), "result=failure");
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("only the exact string 'true' is a cache skip", () => {
|
|
229
|
+
reds(base({ UNIT_CACHE_SKIP: "yes", UNIT_RAN: "0" }), "0 tests");
|
|
230
|
+
reds(base({ UNIT_CACHE_SKIP: "TRUE", UNIT_RAN: "0" }), "0 tests");
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("EMPTY_COUNT=warn turns an unreported count into a warning, not a failure", () => {
|
|
234
|
+
const r = greens(base({ EMPTY_COUNT: "warn", UNIT_RAN: "" }));
|
|
235
|
+
assert(r.warnings.length === 1, `warnings ${JSON.stringify(r.warnings)}`);
|
|
236
|
+
assert(r.warnings[0].includes("bkit-tests-unit"), "lane not named in the warning");
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test("EMPTY_COUNT=warn still fails a zero or non-numeric count", () => {
|
|
240
|
+
reds(base({ EMPTY_COUNT: "warn", UNIT_RAN: "0" }), "0 tests");
|
|
241
|
+
reds(base({ EMPTY_COUNT: "warn", UNIT_RAN: "abc" }), "non-numeric");
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("an EMPTY_COUNT value other than warn is the strict default", () => {
|
|
245
|
+
reds(base({ EMPTY_COUNT: "ignore", UNIT_RAN: "" }), "non-numeric");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// ── the wiring ──────────────────────────────────────────────────────────────
|
|
249
|
+
|
|
250
|
+
test("no LANES fails: a gate that watches nothing proves nothing", () => {
|
|
251
|
+
reds({}, "LANES");
|
|
252
|
+
reds({ LANES: "" }, "LANES");
|
|
253
|
+
reds({ LANES: " , " }, "LANES");
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("a lane name that cannot be an env prefix fails", () => {
|
|
257
|
+
reds({ LANES: "unit;rm", UNIT_RESULT: "success" }, "unit;rm");
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test("a hyphenated lane reads <LANE>_ variables with underscores", () => {
|
|
261
|
+
greens({
|
|
262
|
+
LANES: "e2e-web",
|
|
263
|
+
E2E_WEB_RESULT: "success",
|
|
264
|
+
E2E_WEB_RAN: "3",
|
|
265
|
+
E2E_WEB_CACHE_SKIP: "",
|
|
266
|
+
});
|
|
267
|
+
reds(
|
|
268
|
+
{ LANES: "e2e-web", E2E_WEB_RESULT: "success", E2E_WEB_RAN: "0", E2E_WEB_CACHE_SKIP: "" },
|
|
269
|
+
"bkit-tests-e2e-web",
|
|
270
|
+
);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test("lane names tolerate spaces around the commas", () => {
|
|
274
|
+
greens(base({ LANES: " static , unit " }));
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// ── the command line ────────────────────────────────────────────────────────
|
|
278
|
+
|
|
279
|
+
function run(env) {
|
|
280
|
+
const r = spawnSync(process.execPath, [SCRIPT], { env, encoding: "utf-8" });
|
|
281
|
+
return { status: r.status, out: `${r.stdout}${r.stderr}` };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
test("exits 0 and prints a pass line when the lanes are good", () => {
|
|
285
|
+
const r = run(base());
|
|
286
|
+
assert(r.status === 0, `status ${r.status}: ${r.out}`);
|
|
287
|
+
assert(r.out.includes("bkit-tests-check passed"), `output ${r.out}`);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test("exits 1 and prints ::error:: lines when a lane failed", () => {
|
|
291
|
+
const r = run(base({ UNIT_RESULT: "failure" }));
|
|
292
|
+
assert(r.status === 1, `status ${r.status}`);
|
|
293
|
+
assert(r.out.includes("::error::bkit-tests-unit"), `output ${r.out}`);
|
|
294
|
+
assert(r.out.includes("bkit-tests-check FAILED"), `output ${r.out}`);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
test("exits 1 on a zero count, and prints ::warning:: for an unreported one", () => {
|
|
298
|
+
assert(run(base({ UNIT_RAN: "0" })).status === 1, "zero count passed");
|
|
299
|
+
const r = run(base({ EMPTY_COUNT: "warn", UNIT_RAN: "" }));
|
|
300
|
+
assert(r.status === 0, `status ${r.status}: ${r.out}`);
|
|
301
|
+
assert(r.out.includes("::warning::bkit-tests-unit"), `output ${r.out}`);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
test("exits 1 on a plan that will not parse", () => {
|
|
305
|
+
const r = run(planned({ PLAN: "{not json" }));
|
|
306
|
+
assert(r.status === 1, `status ${r.status}`);
|
|
307
|
+
assert(r.out.includes("::error::"), `output ${r.out}`);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
311
|
+
process.exit(failed ? 1 : 0);
|
|
@@ -133,10 +133,10 @@ def inside_callable(path, line):
|
|
|
133
133
|
|
|
134
134
|
|
|
135
135
|
# --- who imports this, transitively -------------------------------------------
|
|
136
|
-
# graph.json already carries the
|
|
136
|
+
# graph.json already carries the imports graphify cannot resolve — a `.js`
|
|
137
137
|
# specifier never reaching a `.tsx` file, and workspace subpaths through an
|
|
138
138
|
# `exports` map. bkit-graph-repair.py injects them during `pnpm graph`, so they are
|
|
139
|
-
# read here like any other edge; warns if
|
|
139
|
+
# read here like any other edge; warns if graph.json lacks any of them.
|
|
140
140
|
INBOUND = collections.defaultdict(set)
|
|
141
141
|
for link in raw["links"]:
|
|
142
142
|
if link.get("relation") not in DEP_RELATIONS:
|
|
@@ -8,13 +8,13 @@ Importable module, not a CLI — underscored so `import graph_imports` works fro
|
|
|
8
8
|
the sibling `graph-*.py` scripts, which are standalone and cannot be imported
|
|
9
9
|
themselves.
|
|
10
10
|
|
|
11
|
-
ONE WRITER. `bkit-graph-repair.py` is the only
|
|
12
|
-
|
|
11
|
+
ONE WRITER. `bkit-graph-repair.py` is the only script that writes
|
|
12
|
+
`resolved_import_edges()` into graph.json, during `pnpm graph`, so `graphify affected` /
|
|
13
13
|
`explain` / `path` / `query` see the same edges these scripts do. bkit-graph-eager.py
|
|
14
|
-
and bkit-graphify-rollup.py call `warn_if_unrepaired()
|
|
15
|
-
graph.
|
|
14
|
+
and bkit-graphify-rollup.py call `warn_if_unrepaired()`, which compares the same set
|
|
15
|
+
against graph.json, and otherwise just read the graph.
|
|
16
16
|
|
|
17
|
-
Two independent gaps
|
|
17
|
+
Two independent gaps.
|
|
18
18
|
|
|
19
19
|
── GAP 1: a `.js` specifier never resolves to a `.tsx` file ──────────────────
|
|
20
20
|
|
|
@@ -99,34 +99,57 @@ ALL_CONDITIONS = ("react-native", "default", "node", "import", "require")
|
|
|
99
99
|
|
|
100
100
|
|
|
101
101
|
REPAIR_ORIGIN = "graph-repair"
|
|
102
|
+
DEP_RELATIONS = {"imports", "imports_from", "re_exports", "dynamic_import"}
|
|
102
103
|
|
|
103
104
|
|
|
104
105
|
def repair_state(graph):
|
|
105
|
-
"""
|
|
106
|
+
"""Edges injected by bkit-graph-repair.py still in graph.json.
|
|
107
|
+
|
|
108
|
+
Counts the per-link `_origin`, the one repair mark that survives
|
|
109
|
+
`cluster-only` (it drops top-level keys it does not own). Zero does NOT mean
|
|
110
|
+
the repair never ran: when graphify already resolves every import there is
|
|
111
|
+
nothing to inject, and clustering merges an injected edge into graphify's own
|
|
112
|
+
when two files import each other. `missing_import_edges` answers that.
|
|
113
|
+
"""
|
|
114
|
+
return sum(1 for l in graph.get("links", ()) if l.get("_origin") == REPAIR_ORIGIN)
|
|
106
115
|
|
|
107
|
-
Consumers call this instead of re-deriving the edges themselves.
|
|
108
116
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
def missing_import_edges(graph):
|
|
118
|
+
"""Import pairs bkit-graph-repair.py adds that graph.json does not carry.
|
|
119
|
+
|
|
120
|
+
Reads source and compares; writes nothing. A pair counts as present in either
|
|
121
|
+
direction, because clustering keeps one link per file pair. Pairs with an
|
|
122
|
+
endpoint absent from the graph are left out, as the repair leaves them out.
|
|
112
123
|
"""
|
|
113
|
-
|
|
114
|
-
|
|
124
|
+
nodes = {n["id"]: n for n in graph.get("nodes", ())}
|
|
125
|
+
files = {str(n.get("source_file") or "") for n in nodes.values()
|
|
126
|
+
if n.get("source_location") == "L1"}
|
|
127
|
+
files.discard("")
|
|
128
|
+
present = set()
|
|
129
|
+
for l in graph.get("links", ()):
|
|
130
|
+
if l.get("relation") not in DEP_RELATIONS:
|
|
131
|
+
continue
|
|
132
|
+
a = str(nodes.get(l["source"], {}).get("source_file") or "")
|
|
133
|
+
b = str(nodes.get(l["target"], {}).get("source_file") or "")
|
|
134
|
+
present.add((a, b))
|
|
135
|
+
present.add((b, a))
|
|
136
|
+
return {(src, dst) for src, dst in resolved_import_edges()
|
|
137
|
+
if src in files and dst in files and (src, dst) not in present}
|
|
115
138
|
|
|
116
139
|
|
|
117
140
|
def warn_if_unrepaired(graph, who, stream=None):
|
|
118
|
-
"""Print a loud warning when graph.json
|
|
141
|
+
"""Print a loud warning when graph.json lacks imports bkit-graph-repair.py adds.
|
|
119
142
|
|
|
120
|
-
Warns only; never repairs on read.
|
|
143
|
+
Warns only; never repairs on read. Returns the count of injected edges.
|
|
121
144
|
"""
|
|
122
145
|
import sys as _sys
|
|
123
|
-
|
|
124
|
-
if
|
|
125
|
-
print(f"[{who}] WARNING: graph.json
|
|
126
|
-
f"
|
|
127
|
-
f"
|
|
146
|
+
missing = missing_import_edges(graph)
|
|
147
|
+
if missing:
|
|
148
|
+
print(f"[{who}] WARNING: graph.json lacks {len(missing)} imports that "
|
|
149
|
+
f"bkit-graph-repair.py adds, so reachability and blast-radius numbers "
|
|
150
|
+
f"below are UNDERSTATED. Run 'pnpm graph:update'.",
|
|
128
151
|
file=stream or _sys.stderr)
|
|
129
|
-
return
|
|
152
|
+
return repair_state(graph)
|
|
130
153
|
|
|
131
154
|
|
|
132
155
|
def _strip_output_ext(path):
|
|
@@ -2,18 +2,40 @@
|
|
|
2
2
|
# Example. Paste at the end of your .husky/pre-push, below the bkit lines, and own it.
|
|
3
3
|
# bkit install does not write this file and does not overwrite a copy.
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
5
|
+
# Capability register current on dev. BLOCKS a push to dev when docs/capabilities.md is not
|
|
6
|
+
# what the pushed commit builds. Reads PUSH_DEV_SHA (commit pushed to dev), set by the bkit
|
|
7
|
+
# pre-push template while reading git's ref list on stdin; stdin is consumed by now.
|
|
8
|
+
#
|
|
9
|
+
# graphify reads the working tree → check runs in a throwaway checkout of the pushed commit
|
|
10
|
+
# (`check-at`): uncommitted edits, a concurrent session's included, cannot change the answer.
|
|
11
|
+
# Other graphify release → blocked, with the install command. graphify NOT INSTALLED → warn
|
|
12
|
+
# only, saying the check did not run: a cloud session without it must still push; CI's Check
|
|
13
|
+
# Capability Register runs the same check on every push to dev. Revert pushes (IS_REVERT=1)
|
|
14
|
+
# skip it, as they skip the test tiers. Other branches → warn-only staleness note.
|
|
8
15
|
CAP_DOC="docs/capabilities.md"
|
|
9
|
-
if [ -f "$CAP_DOC" ]; then
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
echo "[pre-push]
|
|
15
|
-
echo "[pre-push]
|
|
16
|
-
|
|
16
|
+
if [ -f scripts/graphify/bkit-graphify.sh ] && [ -f "$CAP_DOC" ]; then
|
|
17
|
+
if [ -n "${PUSH_DEV_SHA:-}" ] && [ "${IS_REVERT:-0}" != "1" ]; then
|
|
18
|
+
if ! command -v graphify >/dev/null 2>&1; then
|
|
19
|
+
echo "[pre-push] WARNING: $CAP_DOC was NOT checked — graphify is not installed." >&2
|
|
20
|
+
echo "[pre-push] CI's Check Capability Register checks it on this push; if it reds there, run" >&2
|
|
21
|
+
echo "[pre-push] pnpm graph:refresh, commit, and push again. Install graphify to check before pushing:" >&2
|
|
22
|
+
echo "[pre-push] brew install uv && uv tool install '$(bash scripts/graphify/bkit-graphify.sh spec)'" >&2
|
|
23
|
+
elif ! bash scripts/graphify/bkit-graphify.sh check-at "$PUSH_DEV_SHA" < /dev/null; then
|
|
24
|
+
echo "[pre-push] BLOCKED: $CAP_DOC is not what the pushed commit builds (diff above)." >&2
|
|
25
|
+
echo "[pre-push] Fix: pnpm graph:refresh && git add $CAP_DOC && git commit, then push again." >&2
|
|
26
|
+
exit 1
|
|
27
|
+
fi
|
|
28
|
+
else
|
|
29
|
+
# Warn-only. A fresh register is stamped at the parent of its commit → staleness =
|
|
30
|
+
# source files changed since that stamp.
|
|
31
|
+
CAP_SHA=$(sed -n 's/.*Diagrams from `graph\.json` @ `\([0-9a-f]\{7,\}\)`.*/\1/p' "$CAP_DOC" | head -1)
|
|
32
|
+
if [ -n "$CAP_SHA" ] && git cat-file -e "$CAP_SHA^{commit}" 2>/dev/null; then
|
|
33
|
+
CAP_CHANGED=$(git diff --name-only "$CAP_SHA..HEAD" -- '*.ts' '*.tsx' 2>/dev/null | wc -l | tr -d ' ')
|
|
34
|
+
if [ "${CAP_CHANGED:-0}" -gt 0 ]; then
|
|
35
|
+
echo "[pre-push] NOTE: $CAP_DOC diagrams were built at $CAP_SHA; $CAP_CHANGED source files changed since." >&2
|
|
36
|
+
echo "[pre-push] Refresh when convenient: pnpm graph:refresh" >&2
|
|
37
|
+
echo "[pre-push] Not a gate on this branch. A push to dev is blocked until it is current." >&2
|
|
38
|
+
fi
|
|
17
39
|
fi
|
|
18
40
|
fi
|
|
19
41
|
fi
|
|
@@ -102,8 +102,9 @@ graph["links"].extend(added)
|
|
|
102
102
|
# NO top-level marker: a `graph["import_repair"] = {...}` key does not survive
|
|
103
103
|
# `cluster-only`, which rewrites graph.json and keeps only the keys it writes
|
|
104
104
|
# itself (`built_at_commit` survives because graphify sets it). The per-link
|
|
105
|
-
# `_origin` DOES survive,
|
|
106
|
-
# — see warn_if_unrepaired /
|
|
105
|
+
# `_origin` DOES survive, but a zero count is no proof the step was skipped, so
|
|
106
|
+
# readers compare against source instead — see warn_if_unrepaired /
|
|
107
|
+
# missing_import_edges in bkit-graph-imports.py.
|
|
107
108
|
|
|
108
109
|
tmp = args.graph_json + ".repair.tmp"
|
|
109
110
|
with open(tmp, "w", encoding="utf-8") as fh:
|
|
@@ -58,10 +58,10 @@ SRC = (".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".sql")
|
|
|
58
58
|
|
|
59
59
|
# graphify misses two whole classes of import: a `.js` specifier is never
|
|
60
60
|
# resolved to a `.tsx` file, and workspace subpaths through an `exports` map are
|
|
61
|
-
# not resolved at all.
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
#
|
|
61
|
+
# not resolved at all. bkit-graph-repair.py writes them into graph.json during
|
|
62
|
+
# `pnpm graph`, so this reads them like any other edge and does NOT add them on
|
|
63
|
+
# read. A graph lacking any of them gets a warning, and the numbers below are
|
|
64
|
+
# understated.
|
|
65
65
|
# bkit-graph-imports.py is hyphenated, which `import` cannot spell, so it is loaded
|
|
66
66
|
# by path.
|
|
67
67
|
import importlib.util as _ilu
|
|
@@ -760,7 +760,7 @@ def as_capabilities_doc(out, min_weight, overlay, rows, rules_path, surface, ov_
|
|
|
760
760
|
">",
|
|
761
761
|
"> **Rules:**",
|
|
762
762
|
">",
|
|
763
|
-
"> - Generated — do not edit. `pnpm graph:
|
|
763
|
+
"> - Generated — do not edit. `pnpm graph:refresh` rewrites this file.",
|
|
764
764
|
f"> - Source of truth: `{rules_path}`. Every status derived from live source, never typed.",
|
|
765
765
|
"> - Add a capability = add a rule there: capability · lane · owner module · one literal marker.",
|
|
766
766
|
"> - Markers literal, never regex, because `new Ratelimit(` as a regex is an unclosed group matching nothing.",
|