@cbartens/bkit 6.1.1 → 6.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.
- package/.bkit/README.md +14 -12
- package/.bkit/core/.agents/docs.md +1 -11
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-gateguard.cjs +30 -9
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +25 -27
- package/.bkit/core/.agents/rules.md +22 -9
- package/.bkit/core/.bkit/README.md +13 -11
- package/.bkit/core/.bkit/authoring.md +58 -13
- package/.bkit/core/.bkit/cli.md +42 -32
- package/.bkit/core/.bkit/cloud.md +93 -30
- package/.bkit/core/.bkit/install.md +55 -16
- package/.bkit/core/.bkit/jsonl.md +24 -7
- package/.bkit/core/.bkit/pipeline.md +8 -8
- package/.bkit/core/.bkit/prompts.md +160 -43
- package/.bkit/core/.bkit/providers.md +97 -36
- package/.bkit/core/.bkit/templates.md +162 -34
- package/.bkit/core/.bkit/trackers.md +39 -6
- package/.bkit/core/.bkit/workflows.md +344 -136
- package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +50 -27
- package/.bkit/core/.claude/hooks/bkit-preflight.sh +11 -11
- package/.bkit/core/.codex/hooks/bkit-gateguard.cjs +13 -8
- package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +14 -25
- package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +20 -9
- package/.bkit/core/.cursor/hooks/bkit-preflight.sh +8 -8
- package/.bkit/core/.opencode/plugin/bkit-gateguard.js +14 -4
- package/.bkit/core/.opencode/plugin/bkit-guardrails.js +114 -0
- package/.bkit/core/docs/templates/bkit-audit-accessibility.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-adoption.md +30 -6
- package/.bkit/core/docs/templates/bkit-audit-agents.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-analytics.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-annotations.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-app-performance.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-app-store.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-architecture.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-config.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-cost.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-coverage.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-database.md +3 -3
- package/.bkit/core/docs/templates/bkit-audit-dead-code.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-deferrals.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +3 -3
- package/.bkit/core/docs/templates/bkit-audit-documentation.md +32 -2
- package/.bkit/core/docs/templates/bkit-audit-duplication.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-failures.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-flakes.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-gates.md +5 -3
- package/.bkit/core/docs/templates/bkit-audit-issues.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-llm.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-logs.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-models.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-privacy.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-reliability.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-repo.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-security.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-slop.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-testing.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-usability.md +1 -1
- package/.bkit/core/docs/templates/bkit-plan.md +38 -8
- package/.bkit/core/engine/checks/after/auth.ts +118 -47
- package/.bkit/core/engine/checks/after/github.ts +89 -37
- package/.bkit/core/engine/checks/after/index.ts +15 -3
- package/.bkit/core/engine/checks/after/tools.ts +245 -1
- package/.bkit/core/engine/checks/before/files.ts +59 -1
- package/.bkit/core/engine/checks/before/index.ts +8 -0
- package/.bkit/core/engine/checks/status-holes.ts +20 -26
- package/.bkit/core/engine/checks/tips/catalogue.ts +107 -10
- package/.bkit/core/engine/checks/tips/detect.ts +36 -3
- package/.bkit/core/engine/checks/tips/index.ts +1 -1
- package/.bkit/core/engine/cli.ts +13 -13
- package/.bkit/core/engine/commands/ci/ci.ts +64 -11
- package/.bkit/core/engine/commands/ci/push-gate.ts +101 -43
- package/.bkit/core/engine/commands/install/install.ts +28 -25
- package/.bkit/core/engine/commands/install/uninstall.ts +42 -30
- package/.bkit/core/engine/commands/install/upgrade.ts +14 -2
- package/.bkit/core/engine/commands/land.ts +2 -3
- package/.bkit/core/engine/commands/lib.ts +394 -39
- package/.bkit/core/engine/commands/registry.ts +1 -1
- package/.bkit/core/engine/commands/workflow/branches.ts +351 -78
- package/.bkit/core/engine/commands/workflow/challenge.ts +63 -14
- package/.bkit/core/engine/commands/workflow/context.ts +71 -10
- package/.bkit/core/engine/commands/workflow/counters.ts +298 -23
- package/.bkit/core/engine/commands/workflow/decisions.ts +260 -125
- package/.bkit/core/engine/commands/workflow/disk.ts +2 -1
- package/.bkit/core/engine/commands/workflow/feature-base.ts +66 -0
- package/.bkit/core/engine/commands/workflow/issues.ts +312 -17
- package/.bkit/core/engine/commands/workflow/junit.ts +204 -0
- package/.bkit/core/engine/commands/workflow/ledgers.ts +904 -99
- package/.bkit/core/engine/commands/workflow/locks.ts +186 -29
- package/.bkit/core/engine/commands/workflow/loops.ts +87 -0
- package/.bkit/core/engine/commands/workflow/open-decision.ts +251 -0
- package/.bkit/core/engine/commands/workflow/plan-blocks.ts +8 -0
- package/.bkit/core/engine/commands/workflow/plans.ts +1 -1
- package/.bkit/core/engine/commands/workflow/prs.ts +311 -16
- package/.bkit/core/engine/commands/workflow/repo.ts +1 -1
- package/.bkit/core/engine/commands/workflow/run-facts.ts +6 -0
- package/.bkit/core/engine/commands/workflow/runs.ts +877 -174
- package/.bkit/core/engine/commands/workflow/runtime.ts +12 -4
- package/.bkit/core/engine/commands/workflow/status.ts +324 -11
- package/.bkit/core/engine/commands/workflow/step-table.ts +41 -15
- package/.bkit/core/engine/commands/workflow/steps.ts +604 -29
- package/.bkit/core/engine/commands/workflow/summary-findings.ts +1 -1
- package/.bkit/core/engine/commands/workflow/summary.ts +314 -8
- package/.bkit/core/engine/commands/workflow/tasks.ts +400 -27
- package/.bkit/core/engine/commands/workflow/tests-base.ts +319 -0
- package/.bkit/core/engine/commands/workflow/tests-changed.ts +138 -74
- package/.bkit/core/engine/commands/workflow/tests-jump.ts +93 -0
- package/.bkit/core/engine/commands/workflow/tests.ts +815 -182
- package/.bkit/core/engine/commands/workflow/tracker.ts +1134 -137
- package/.bkit/core/engine/commands/workflow/workflows.ts +100 -72
- package/.bkit/core/engine/commands/workflow/worktrees.ts +421 -57
- package/.bkit/core/engine/install/cloud-env.ts +38 -10
- package/.bkit/core/engine/install/managed-block.ts +105 -0
- package/.bkit/core/engine/install/manifest.ts +7 -1
- package/.bkit/core/engine/install/modules/claude.ts +6 -2
- package/.bkit/core/engine/install/modules/cloud.ts +84 -95
- package/.bkit/core/engine/install/modules/codex.ts +10 -2
- package/.bkit/core/engine/install/modules/core.ts +148 -14
- package/.bkit/core/engine/install/modules/opencode.ts +18 -23
- package/.bkit/core/engine/install/network-allowlist.ts +8 -3
- package/.bkit/core/engine/install/project-docs.ts +650 -0
- package/.bkit/core/engine/install/template-copies.ts +58 -5
- package/.bkit/core/engine/install/write.ts +128 -7
- package/.bkit/core/engine/ledgers/journal.ts +18 -10
- package/.bkit/core/engine/ledgers/migrate.ts +20 -8
- package/.bkit/core/engine/ledgers/status.ts +604 -8
- package/.bkit/core/engine/ledgers/telemetry.ts +115 -13
- package/.bkit/core/engine/render/trackers.ts +3 -1
- package/.bkit/core/engine/shared/package-manager.ts +7 -3
- package/.bkit/core/engine/shared/settings.ts +12 -1
- package/.bkit/core/engine/shared/text.ts +14 -0
- package/.bkit/core/engine/tools/instructions-sources.ts +1 -0
- package/.bkit/core/engine/tools/instructions.ts +116 -20
- package/.bkit/core/hooks/antigravity-hook.js +20 -4
- package/.bkit/core/hooks/gateguard-edit-payload.js +8 -5
- package/.bkit/core/hooks/gateguard-engine.js +249 -23
- package/.bkit/core/hooks/guardrails-deny.js +167 -0
- package/.bkit/core/hooks/guardrails-read.js +3 -3
- package/.bkit/core/hooks/guardrails-shell.js +1122 -167
- package/.bkit/core/hooks/guardrails-tiers.js +247 -176
- package/.bkit/core/hooks/preflight-tracker.sh +219 -0
- package/.bkit/core/prompts/bkit-audit-generate.md +23 -6
- package/.bkit/core/prompts/bkit-build-challenge-1.md +5 -4
- package/.bkit/core/prompts/bkit-build-challenge-2.md +6 -5
- package/.bkit/core/prompts/bkit-build-install-skills.md +2 -2
- package/.bkit/core/prompts/bkit-build-plan-convert.md +21 -7
- package/.bkit/core/prompts/bkit-build-plan-current.md +5 -4
- package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +22 -17
- package/.bkit/core/prompts/bkit-build-plan-tasks.md +16 -12
- package/.bkit/core/prompts/bkit-build-plan-tests.md +14 -10
- package/.bkit/core/prompts/bkit-build-plan-verify.md +21 -8
- package/.bkit/core/prompts/bkit-debug-abort-handover.md +10 -5
- package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +22 -6
- package/.bkit/core/prompts/bkit-debug-failure-remediate.md +19 -3
- package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +22 -6
- package/.bkit/core/prompts/bkit-debug-failure-soak.md +10 -7
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +3 -3
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +4 -4
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +3 -3
- package/.bkit/core/prompts/bkit-design-generate.md +6 -4
- package/.bkit/core/prompts/bkit-design-organise.md +4 -3
- package/.bkit/core/prompts/bkit-design-review-1.md +5 -4
- package/.bkit/core/prompts/bkit-design-review-2.md +6 -5
- package/.bkit/core/prompts/bkit-design-spike.md +4 -3
- package/.bkit/core/prompts/bkit-design-update.md +6 -4
- package/.bkit/core/prompts/bkit-plan-generate.md +35 -14
- package/.bkit/core/prompts/bkit-plan-review-1.md +9 -7
- package/.bkit/core/prompts/bkit-plan-review-2.md +9 -7
- package/.bkit/core/prompts/bkit-plan-scope-check.md +8 -6
- package/.bkit/core/prompts/bkit-plan-update.md +22 -8
- package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +11 -8
- package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +9 -5
- package/.bkit/core/prompts/bkit-ship-update-docs.md +26 -4
- package/.bkit/core/prompts/bkit-utility-compress-markdown.md +3 -3
- package/.bkit/core/prompts/bkit-utility-update-decisions.md +10 -7
- package/.bkit/core/prompts/bkit-utility-update-deferrals.md +8 -5
- package/.bkit/core/prompts/bkit-utility-update-documentation.md +31 -7
- package/.bkit/core/prompts/bkit-utility-update-failures.md +8 -5
- package/.bkit/core/prompts/bkit-utility-update-knowledge.md +10 -7
- package/.bkit/core/prompts/bkit-utility-update-roadmap.md +4 -4
- package/.bkit/core/prompts/bkit-utility-update-tracker.md +4 -4
- package/.bkit/core/workflows/bkit-auto.md +23 -11
- package/.bkit/core/workflows/bkit-build.md +331 -100
- package/.bkit/core/workflows/bkit-debug.md +135 -64
- package/.bkit/core/workflows/bkit-design.md +58 -32
- package/.bkit/core/workflows/bkit-plan.md +73 -45
- package/.bkit/core/workflows/bkit-ship.md +233 -167
- package/.bkit/shared/.agents/plugins/bkit/hooks.json +1 -1
- package/.bkit/shared/.bkit/.env.example +5 -0
- package/.bkit/shared/.claude/bkit-cloud.md +7 -7
- package/.bkit/shared/.claude/settings.json +5 -1
- package/.bkit/shared/.cursor/bkit-cloud.md +1 -1
- package/.bkit/shared/.cursor/hooks.json +1 -1
- package/.bkit/shared/.opencode/opencode.json +11 -2
- package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +27 -0
- package/.bkit/templates/.cursor/Dockerfile +7 -7
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +1 -1
- package/.bkit/templates/.github/dependabot.yml +5 -0
- package/.bkit/templates/.github/renovate.json5 +5 -3
- package/.bkit/templates/.github/workflows/bkit-ci.yml +11 -11
- package/.bkit/templates/.github/workflows/bkit-cloud.yml +525 -161
- package/.bkit/templates/.github/workflows/bkit-renovate.yml +2 -2
- package/.bkit/templates/.husky/pre-push +123 -6
- package/.bkit/templates/context/bkit-serena.md +1 -1
- package/.bkit/templates/docs/architecture.md +98 -0
- package/.bkit/templates/docs/capabilities.md +33 -37
- package/.bkit/templates/docs/components.md +142 -0
- package/.bkit/templates/docs/data-schema.md +87 -0
- package/.bkit/{shared → templates}/docs/deployments.md +128 -142
- package/.bkit/templates/docs/design.md +117 -0
- package/.bkit/templates/docs/noise.md +54 -0
- package/.bkit/templates/docs/observability.md +99 -0
- package/.bkit/templates/docs/security.md +137 -0
- package/.bkit/templates/docs/setup.md +93 -0
- package/.bkit/templates/docs/technology.md +70 -0
- package/.bkit/{shared → templates}/docs/testing.md +200 -87
- package/.bkit/templates/scripts/ci/bkit-machine-lock.sh +511 -103
- package/.bkit/templates/scripts/ci/bkit-test-awake.mjs +228 -35
- package/.bkit/templates/scripts/ci/bkit-test-awake.test.mjs +270 -2
- package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +1 -1
- package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +92 -63
- package/.bkit/templates/scripts/graphify/bkit-graphify.sh +59 -11
- package/.bkit/templates/slop-scan.config.json +2 -0
- package/CHANGELOG.md +64 -0
- package/DETAILS.md +24 -19
- package/README.md +1 -1
- package/dist/checks/after/auth.js +114 -46
- package/dist/checks/after/github.js +77 -35
- package/dist/checks/after/index.js +12 -3
- package/dist/checks/after/tools.js +224 -1
- package/dist/checks/before/files.js +59 -1
- package/dist/checks/before/index.js +7 -1
- package/dist/checks/status-holes.js +20 -21
- package/dist/checks/tips/catalogue.js +99 -10
- package/dist/checks/tips/detect.js +35 -3
- package/dist/checks/tips/index.js +1 -1
- package/dist/cli.js +13 -13
- package/dist/commands/ci/ci.js +56 -12
- package/dist/commands/ci/push-gate.js +79 -44
- package/dist/commands/install/install.js +23 -22
- package/dist/commands/install/uninstall.js +36 -30
- package/dist/commands/install/upgrade.js +10 -2
- package/dist/commands/land.js +2 -3
- package/dist/commands/lib.js +323 -25
- package/dist/commands/workflow/branches.js +312 -72
- package/dist/commands/workflow/challenge.js +66 -13
- package/dist/commands/workflow/context.js +46 -10
- package/dist/commands/workflow/counters.js +231 -23
- package/dist/commands/workflow/decisions.js +221 -106
- package/dist/commands/workflow/disk.js +2 -1
- package/dist/commands/workflow/feature-base.js +60 -0
- package/dist/commands/workflow/issues.js +243 -15
- package/dist/commands/workflow/junit.js +137 -0
- package/dist/commands/workflow/ledgers.js +726 -112
- package/dist/commands/workflow/locks.js +150 -29
- package/dist/commands/workflow/loops.js +67 -0
- package/dist/commands/workflow/open-decision.js +199 -0
- package/dist/commands/workflow/plan-blocks.js +6 -0
- package/dist/commands/workflow/plans.js +1 -1
- package/dist/commands/workflow/prs.js +272 -16
- package/dist/commands/workflow/repo.js +1 -1
- package/dist/commands/workflow/run-facts.js +6 -0
- package/dist/commands/workflow/runs.js +747 -155
- package/dist/commands/workflow/runtime.js +8 -4
- package/dist/commands/workflow/status.js +259 -13
- package/dist/commands/workflow/step-table.js +41 -15
- package/dist/commands/workflow/steps.js +530 -26
- package/dist/commands/workflow/summary-findings.js +1 -1
- package/dist/commands/workflow/summary.js +289 -8
- package/dist/commands/workflow/tasks.js +294 -27
- package/dist/commands/workflow/tests-base.js +266 -0
- package/dist/commands/workflow/tests-changed.js +130 -56
- package/dist/commands/workflow/tests-jump.js +77 -0
- package/dist/commands/workflow/tests.js +608 -131
- package/dist/commands/workflow/tracker.js +920 -112
- package/dist/commands/workflow/workflows.js +80 -59
- package/dist/commands/workflow/worktrees.js +387 -58
- package/dist/install/cloud-env.js +32 -10
- package/dist/install/managed-block.js +101 -0
- package/dist/install/manifest.js +7 -1
- package/dist/install/modules/claude.js +6 -2
- package/dist/install/modules/cloud.js +73 -86
- package/dist/install/modules/codex.js +9 -2
- package/dist/install/modules/core.js +133 -14
- package/dist/install/modules/opencode.js +18 -23
- package/dist/install/network-allowlist.js +8 -3
- package/dist/install/project-docs.js +551 -0
- package/dist/install/template-copies.js +55 -5
- package/dist/install/write.js +117 -5
- package/dist/ledgers/journal.js +10 -8
- package/dist/ledgers/migrate.js +20 -9
- package/dist/ledgers/status.js +461 -8
- package/dist/ledgers/telemetry.js +71 -13
- package/dist/render/trackers.js +3 -1
- package/dist/shared/package-manager.js +7 -2
- package/dist/shared/settings.js +8 -0
- package/dist/shared/text.js +13 -0
- package/dist/tools/instructions-sources.js +1 -0
- package/dist/tools/instructions.js +97 -24
- package/package.json +22 -15
- package/.bkit/core/hooks/preflight-linear.sh +0 -73
- package/.bkit/shared/docs/architecture.md +0 -16
- package/.bkit/shared/docs/data-schema.md +0 -16
- package/.bkit/shared/docs/design.md +0 -38
- package/.bkit/shared/docs/noise.md +0 -20
- package/.bkit/shared/docs/observability.md +0 -22
- package/.bkit/shared/docs/security.md +0 -62
- package/.bkit/shared/docs/setup.md +0 -52
- package/.bkit/shared/docs/technology.md +0 -15
- /package/.bkit/templates/{.lintstagedrc.json → lintstagedrc.example.json} +0 -0
- /package/.bkit/templates/{.prettierignore → prettierignore.example} +0 -0
|
@@ -4,77 +4,145 @@
|
|
|
4
4
|
// changed and hands them to the consumer's `bkit:gate:changed`, which runs the tests that
|
|
5
5
|
// import them, the tests that name their paths and static checks on them. Undeclared →
|
|
6
6
|
// the --fallback whole gate runs, exactly as before the script existed.
|
|
7
|
-
import { spawnSync } from "node:child_process";
|
|
8
7
|
import * as fs from "node:fs";
|
|
9
8
|
import * as os from "node:os";
|
|
10
9
|
import * as path from "node:path";
|
|
11
10
|
import { BKIT_GATE_CHANGED_SCRIPT } from "../../install/manifest.js";
|
|
12
|
-
import {
|
|
11
|
+
import { CommandError, EXIT, git, runGit, wholeNumber } from "../lib.js";
|
|
13
12
|
import { readPackageJson } from "../../shared/package-json.js";
|
|
14
|
-
import { COULD_NOT_RUN_EXIT_CODES, scriptCommand
|
|
13
|
+
import { COULD_NOT_RUN_EXIT_CODES, scriptCommand } from "../../shared/package-manager.js";
|
|
14
|
+
import { runGateUnderLock } from "./junit.js";
|
|
15
15
|
/** Exit code: neither `bkit:gate:changed` nor the --fallback gate is declared. */
|
|
16
16
|
const EXIT_NO_GATE = 3;
|
|
17
17
|
/** Exit code: the gate could not run (exit 126 / 127, or the package runner is missing). */
|
|
18
18
|
const EXIT_COULD_NOT_RUN = 4;
|
|
19
|
+
/** The NUL-separated paths `git <args>` prints in `top`; none when it fails. */
|
|
20
|
+
const gitPaths = (top, args) => (git(top, args) ?? "").split("\0").filter(Boolean);
|
|
19
21
|
/**
|
|
20
22
|
* Files changed since `base`, repo-relative and sorted: uncommitted (staged or not),
|
|
21
|
-
* untracked and not ignored, plus every file a commit after `base` touched.
|
|
22
|
-
*
|
|
23
|
+
* untracked and not ignored, plus every file a commit after `base` touched. Existing
|
|
24
|
+
* files only: a deleted file is a change `deletedFiles` lists, and `importersOf` turns
|
|
25
|
+
* into the files that still mention it.
|
|
23
26
|
*/
|
|
24
27
|
export function changedFiles(top, base) {
|
|
25
|
-
const list = (args) => (git(top, args) ?? "").split("\0").filter(Boolean);
|
|
26
28
|
const all = new Set([
|
|
27
|
-
...
|
|
28
|
-
...
|
|
29
|
-
...
|
|
29
|
+
...gitPaths(top, ["diff", "--name-only", "--no-renames", "-z", "HEAD"]),
|
|
30
|
+
...gitPaths(top, ["ls-files", "--others", "--exclude-standard", "-z"]),
|
|
31
|
+
...gitPaths(top, ["diff", "--name-only", "--no-renames", "-z", `${base}...HEAD`]),
|
|
30
32
|
]);
|
|
31
33
|
return [...all].filter((f) => fs.existsSync(path.join(top, f))).sort();
|
|
32
34
|
}
|
|
33
|
-
/** Whether `dir/package.json` declares `name` as a non-empty script. */
|
|
34
|
-
function declares(dir, name) {
|
|
35
|
-
const read = readPackageJson(dir);
|
|
36
|
-
const scripts = read.ok ? read.pkg.scripts : undefined;
|
|
37
|
-
if (typeof scripts !== "object" || scripts === null)
|
|
38
|
-
return false;
|
|
39
|
-
const body = scripts[name];
|
|
40
|
-
return typeof body === "string" && body.trim() !== "";
|
|
41
|
-
}
|
|
42
35
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
36
|
+
* A commit holding the working tree as it is now: tracked files as edited, untracked files
|
|
37
|
+
* that are not ignored, deleted files gone; its parent is HEAD (none before the first
|
|
38
|
+
* commit). It is built in a copy of the index, so no ref, the index and the working tree
|
|
39
|
+
* stay as they were; no ref points at it, and `git gc` prunes it once unreachable objects
|
|
40
|
+
* expire. Null when git cannot build it.
|
|
45
41
|
*/
|
|
46
|
-
function
|
|
47
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "bkit-
|
|
48
|
-
const file = path.join(dir, "out.log");
|
|
42
|
+
export function snapshotTree(top) {
|
|
43
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "bkit-snapshot-"));
|
|
49
44
|
try {
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
45
|
+
const index = path.join(dir, "index");
|
|
46
|
+
const real = git(top, ["rev-parse", "--path-format=absolute", "--git-path", "index"]);
|
|
47
|
+
// The real index's stat data lets `git add -A` skip unchanged files instead of hashing them.
|
|
48
|
+
if (real !== null && fs.existsSync(real))
|
|
49
|
+
fs.copyFileSync(real, index);
|
|
50
|
+
const env = { GIT_INDEX_FILE: index };
|
|
51
|
+
if (!runGit(top, ["add", "-A"], env).ok)
|
|
52
|
+
return null;
|
|
53
|
+
const tree = runGit(top, ["write-tree"], env);
|
|
54
|
+
if (!tree.ok)
|
|
55
|
+
return null;
|
|
56
|
+
const head = git(top, ["rev-parse", "-q", "--verify", "HEAD^{commit}"]);
|
|
57
|
+
const commit = runGit(top, [
|
|
58
|
+
"-c",
|
|
59
|
+
"user.name=bkit",
|
|
60
|
+
"-c",
|
|
61
|
+
"user.email=bkit@localhost",
|
|
62
|
+
"commit-tree",
|
|
63
|
+
"--no-gpg-sign",
|
|
64
|
+
tree.stdout,
|
|
65
|
+
...(head === null ? [] : ["-p", head]),
|
|
66
|
+
"-m",
|
|
67
|
+
"bkit tested snapshot",
|
|
68
|
+
]);
|
|
69
|
+
return commit.ok ? commit.stdout : null;
|
|
71
70
|
}
|
|
72
71
|
finally {
|
|
73
72
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
74
73
|
}
|
|
75
74
|
}
|
|
75
|
+
/** Whether `sha` names a commit the object store still holds. */
|
|
76
|
+
export const commitExists = (top, sha) => git(top, ["cat-file", "-e", `${sha}^{commit}`]) !== null;
|
|
77
|
+
/**
|
|
78
|
+
* The files that differ between snapshot `from` and the working tree now (`now`, else a
|
|
79
|
+
* fresh `snapshotTree`), sorted: `files` the ones that exist now, `deleted` the ones that do
|
|
80
|
+
* not. Null when `from` is gone from the object store or the tree cannot be snapshotted.
|
|
81
|
+
*/
|
|
82
|
+
export function changedBetween(top, from, now = snapshotTree(top)) {
|
|
83
|
+
if (now === null || !commitExists(top, from))
|
|
84
|
+
return null;
|
|
85
|
+
const listed = runGit(top, ["diff", "--name-only", "--no-renames", "-z", from, now]);
|
|
86
|
+
if (!listed.ok)
|
|
87
|
+
return null;
|
|
88
|
+
const all = listed.stdout.split("\0").filter(Boolean).sort();
|
|
89
|
+
const exists = (f) => fs.existsSync(path.join(top, f));
|
|
90
|
+
return { files: all.filter(exists), deleted: all.filter((f) => !exists(f)) };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Files removed since `base`, repo-relative and sorted: deleted in the working tree or
|
|
94
|
+
* the index, or by a commit after `base`, and missing from the working tree now.
|
|
95
|
+
*/
|
|
96
|
+
export function deletedFiles(top, base) {
|
|
97
|
+
const all = new Set([
|
|
98
|
+
...gitPaths(top, ["diff", "--name-only", "--no-renames", "--diff-filter=D", "-z", "HEAD"]),
|
|
99
|
+
...gitPaths(top, [
|
|
100
|
+
"diff",
|
|
101
|
+
"--name-only",
|
|
102
|
+
"--no-renames",
|
|
103
|
+
"--diff-filter=D",
|
|
104
|
+
"-z",
|
|
105
|
+
`${base}...HEAD`,
|
|
106
|
+
]),
|
|
107
|
+
]);
|
|
108
|
+
return [...all].filter((f) => !fs.existsSync(path.join(top, f))).sort();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* For each deleted file, the files of the `base` tree that mention its name without the
|
|
112
|
+
* extension (`git grep -l -F`) and still exist, sorted; a file nothing mentions maps to
|
|
113
|
+
* `[]`. Null when a search fails (`base` names no tree, or the tree cannot be read):
|
|
114
|
+
* the caller cannot tell which tests the deletion touches.
|
|
115
|
+
*/
|
|
116
|
+
export function importersOf(top, base, deleted) {
|
|
117
|
+
const found = new Map();
|
|
118
|
+
for (const file of deleted) {
|
|
119
|
+
const name = path.basename(file, path.extname(file));
|
|
120
|
+
const res = runGit(top, ["grep", "-l", "-z", "-F", "-e", name, base, "--"]);
|
|
121
|
+
// Exit 1 with nothing on stderr is "no match". Any stderr fails the search: git grep
|
|
122
|
+
// exits 0 when it found a match even though it could not read another blob.
|
|
123
|
+
if (res.stderr !== "")
|
|
124
|
+
return null;
|
|
125
|
+
const prefix = `${base}:`;
|
|
126
|
+
found.set(file, res.stdout
|
|
127
|
+
.split("\0")
|
|
128
|
+
.filter(Boolean)
|
|
129
|
+
.map((hit) => (hit.startsWith(prefix) ? hit.slice(prefix.length) : hit))
|
|
130
|
+
.filter((hit) => !deleted.includes(hit) && fs.existsSync(path.join(top, hit)))
|
|
131
|
+
.sort());
|
|
132
|
+
}
|
|
133
|
+
return found;
|
|
134
|
+
}
|
|
135
|
+
/** Whether `dir/package.json` declares `name` as a non-empty script. */
|
|
136
|
+
export function declares(dir, name) {
|
|
137
|
+
const read = readPackageJson(dir);
|
|
138
|
+
const scripts = read.ok ? read.pkg.scripts : undefined;
|
|
139
|
+
if (typeof scripts !== "object" || scripts === null)
|
|
140
|
+
return false;
|
|
141
|
+
const body = scripts[name];
|
|
142
|
+
return typeof body === "string" && body.trim() !== "";
|
|
143
|
+
}
|
|
76
144
|
export const testsChangedVerb = {
|
|
77
|
-
summary: `Check only the files changed since --base: run \`${BKIT_GATE_CHANGED_SCRIPT}\` with them as arguments, else the --fallback gate; exit 0 PASS or nothing changed, 1 FAIL, 4 could not run, 81 tests lock held.`,
|
|
145
|
+
summary: `Check only the files changed since --base: run \`${BKIT_GATE_CHANGED_SCRIPT}\` with them as arguments, else the --fallback gate; exit 0 PASS or nothing changed, 1 FAIL, 4 could not run, 81 tests lock held (read from the lock status file, never from the exit code alone).`,
|
|
78
146
|
use: "by-hand",
|
|
79
147
|
flags: [
|
|
80
148
|
{
|
|
@@ -148,20 +216,26 @@ export const testsChangedVerb = {
|
|
|
148
216
|
const scope = scriptCommand(gate).join(" ");
|
|
149
217
|
ctx.log(`running ${scope}`);
|
|
150
218
|
const who = `bkit tests changed ${gate}`;
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
219
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "bkit-tests-changed-"));
|
|
220
|
+
const log = path.join(dir, "out.log");
|
|
221
|
+
let run;
|
|
222
|
+
try {
|
|
223
|
+
run = runGateUnderLock(argv, top, log, {
|
|
224
|
+
LOCAL_STACK_LOCK_WAIT_S: String(waitS),
|
|
225
|
+
LOCAL_STACK_LOCK_WHO: who,
|
|
226
|
+
});
|
|
227
|
+
for (const line of fs.readFileSync(log, "utf-8").split(/\r?\n/))
|
|
228
|
+
if (line !== "")
|
|
229
|
+
ctx.log(line);
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
233
|
+
}
|
|
234
|
+
const { exitCode, status: lockStatus, lock: lockExit } = run;
|
|
161
235
|
const couldNotRun = lockExit === "could-not-run" || COULD_NOT_RUN_EXIT_CODES.has(exitCode);
|
|
162
236
|
const lockWait = lockExit === "lock-wait";
|
|
163
237
|
const verdict = couldNotRun || lockWait ? null : exitCode === 0 ? "PASS" : "FAIL";
|
|
164
|
-
const lockHolder = lockWait ?
|
|
238
|
+
const lockHolder = lockWait ? (lockStatus?.holder ?? null) : null;
|
|
165
239
|
ctx.emit({ files, gate, scope, exitCode, verdict, lockHolder });
|
|
166
240
|
if (lockWait)
|
|
167
241
|
return EXIT.AGENT_WAIT;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// commands/workflow/tests-jump.ts — `bkit tests jump <run>`: move one waiting run to the front
|
|
2
|
+
// of the tests line.
|
|
3
|
+
//
|
|
4
|
+
// The verb asks bkit's own copy of the lock script (the template, never the consumer's copy) to
|
|
5
|
+
// write the jump marker: `bkit-machine-lock.sh jump --lock tests <run> [<checkout>]`. The lock's
|
|
6
|
+
// waiting helpers sort a ticket carrying the marker's line first and delete the marker once the
|
|
7
|
+
// run has the lock. The script never touches the lock, the holder file or a slot file, so the
|
|
8
|
+
// current holder keeps the lock. With no match the verb lists the queue (`queue --lock tests`).
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
import * as path from "node:path";
|
|
11
|
+
import { CommandError, EXIT } from "../lib.js";
|
|
12
|
+
import { getTemplatesRoot } from "../../shared/package-roots.js";
|
|
13
|
+
/** Exit code: the lock script could not read the queue or write the jump marker. */
|
|
14
|
+
export const EXIT_JUMP_FAILED = 3;
|
|
15
|
+
/** Run a queue subcommand of the template's lock script on the tests lock. */
|
|
16
|
+
function lockScript(args) {
|
|
17
|
+
const script = path.join(getTemplatesRoot(), "scripts", "ci", "bkit-machine-lock.sh");
|
|
18
|
+
const res = spawnSync("bash", [script, args[0], "--lock", "tests", ...args.slice(1)], {
|
|
19
|
+
encoding: "utf-8",
|
|
20
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
21
|
+
});
|
|
22
|
+
if (res.error) {
|
|
23
|
+
throw new CommandError(EXIT_JUMP_FAILED, `cannot run ${script}: ${res.error.message}`);
|
|
24
|
+
}
|
|
25
|
+
return { status: res.status ?? 1, stdout: res.stdout, stderr: res.stderr.trim() };
|
|
26
|
+
}
|
|
27
|
+
const lines = (text) => text.split("\n").filter((line) => line !== "");
|
|
28
|
+
export const testsJumpVerb = {
|
|
29
|
+
summary: "Move the waiting run named <run> to the front of the tests line; the holder keeps the lock. Every use needs the human's approval, so ask them to approve it; exit 0 moved, 1 no single run matched, 3 the lock script failed.",
|
|
30
|
+
use: "by-hand",
|
|
31
|
+
flags: [
|
|
32
|
+
{
|
|
33
|
+
name: "run",
|
|
34
|
+
type: "string",
|
|
35
|
+
positional: true,
|
|
36
|
+
required: true,
|
|
37
|
+
help: "the waiting run's name, as the waiting note prints it",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "checkout",
|
|
41
|
+
type: "string",
|
|
42
|
+
help: "the waiting run's checkout path, to pick one when several runs share the name",
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
output: {
|
|
46
|
+
run: "the run name moved to the front",
|
|
47
|
+
checkout: "the checkout path of the run moved",
|
|
48
|
+
},
|
|
49
|
+
exitCodes: {
|
|
50
|
+
[EXIT_JUMP_FAILED]: "the lock script could not read the queue or write the jump marker",
|
|
51
|
+
},
|
|
52
|
+
run: (ctx) => {
|
|
53
|
+
const run = String(ctx.flags.run);
|
|
54
|
+
const wanted = typeof ctx.flags.checkout === "string" ? [ctx.flags.checkout] : [];
|
|
55
|
+
const res = lockScript(["jump", run, ...wanted]);
|
|
56
|
+
if (res.status === 1) {
|
|
57
|
+
const waiting = lockScript(["queue"]);
|
|
58
|
+
const queued = waiting.status === 0 ? lines(waiting.stdout) : [];
|
|
59
|
+
throw new CommandError(EXIT.NO, `no run named ${run} waits for tests` +
|
|
60
|
+
(queued.length > 0
|
|
61
|
+
? `\nwaiting now:\n${queued.map((line) => ` ${line}`).join("\n")}`
|
|
62
|
+
: ""));
|
|
63
|
+
}
|
|
64
|
+
if (res.status === 3) {
|
|
65
|
+
throw new CommandError(EXIT.NO, `several runs named ${run} wait for tests:\n${lines(res.stdout)
|
|
66
|
+
.map((line) => ` ${line}`)
|
|
67
|
+
.join("\n")}\npass --checkout <path> to pick one`);
|
|
68
|
+
}
|
|
69
|
+
if (res.status !== 0) {
|
|
70
|
+
throw new CommandError(EXIT_JUMP_FAILED, res.stderr || `the lock script's jump exited ${res.status}`);
|
|
71
|
+
}
|
|
72
|
+
const line = lines(res.stdout)[0] ?? "";
|
|
73
|
+
ctx.log(`${run} moves to the front of the tests line`);
|
|
74
|
+
ctx.emit({ run, checkout: line.slice(`${run} — `.length) });
|
|
75
|
+
return EXIT.OK;
|
|
76
|
+
},
|
|
77
|
+
};
|