@cbartens/bkit 5.5.0 → 6.0.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 +30 -20
- package/.bkit/core/.agents/docs.md +1 -0
- package/.bkit/core/.agents/rules.md +51 -26
- package/.bkit/core/.bkit/README.md +29 -19
- package/.bkit/core/.bkit/authoring.md +117 -0
- package/.bkit/core/.bkit/cloud.md +11 -11
- package/.bkit/core/.bkit/comparison.md +5 -5
- package/.bkit/core/.bkit/install.md +20 -20
- package/.bkit/core/.bkit/jsonl.md +202 -122
- package/.bkit/core/.bkit/lite.md +1 -1
- package/.bkit/core/.bkit/pipeline.md +49 -52
- package/.bkit/core/.bkit/prompts.md +106 -167
- package/.bkit/core/.bkit/providers.md +29 -32
- package/.bkit/core/.bkit/templates.md +44 -18
- package/.bkit/core/.bkit/trackers.md +60 -28
- package/.bkit/core/.bkit/workflows.md +399 -359
- package/.bkit/core/AGENTS.md +16 -22
- package/.bkit/core/docs/templates/bkit-audit-accessibility.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-adoption.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-agents.md +19 -43
- package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-analytics.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-annotations.md +11 -35
- package/.bkit/core/docs/templates/bkit-audit-app-performance.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-app-store.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-architecture.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-config.md +18 -42
- package/.bkit/core/docs/templates/bkit-audit-cost.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-coverage.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-database.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-dead-code.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-deferrals.md +15 -38
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-documentation.md +11 -35
- package/.bkit/core/docs/templates/bkit-audit-duplication.md +18 -42
- package/.bkit/core/docs/templates/bkit-audit-failures.md +13 -37
- package/.bkit/core/docs/templates/bkit-audit-flakes.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-gates.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-issues.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-llm.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-logs.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-models.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-privacy.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-reliability.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-repo.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-security.md +13 -37
- package/.bkit/core/docs/templates/bkit-audit-slop.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-testing.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-usability.md +16 -40
- package/.bkit/core/docs/templates/bkit-plan.md +97 -226
- package/.bkit/core/engine/checks/after/ci-yml.ts +39 -30
- package/.bkit/core/engine/checks/after/github.ts +101 -72
- package/.bkit/core/engine/checks/after/index.ts +10 -12
- package/.bkit/core/engine/checks/after/suppression.ts +8 -5
- package/.bkit/core/engine/checks/after/tools.ts +47 -92
- package/.bkit/core/engine/checks/before/env.ts +2 -2
- package/.bkit/core/engine/checks/before/files.ts +5 -4
- package/.bkit/core/engine/checks/before/index.ts +18 -1
- package/.bkit/core/engine/checks/before/repo.ts +168 -2
- package/.bkit/core/engine/checks/tips/catalogue.ts +16 -5
- package/.bkit/core/engine/checks/tips/detect.ts +34 -0
- package/.bkit/core/engine/checks/tips/index.ts +10 -7
- package/.bkit/core/engine/cli.ts +20 -53
- package/.bkit/core/engine/commands/analysis.ts +171 -140
- package/.bkit/core/engine/commands/ci/ci.ts +6 -6
- package/.bkit/core/engine/commands/comply.ts +77 -103
- package/.bkit/core/engine/commands/install/doctor.ts +2 -2
- package/.bkit/core/engine/commands/install/install.ts +57 -18
- package/.bkit/core/engine/commands/install/uninstall.ts +65 -28
- package/.bkit/core/engine/commands/land.ts +18 -12
- package/.bkit/core/engine/commands/lib.ts +79 -17
- package/.bkit/core/engine/commands/registry.ts +4 -0
- package/.bkit/core/engine/commands/setup/setup.ts +7 -7
- package/.bkit/core/engine/commands/stats.ts +204 -0
- package/.bkit/core/engine/commands/tips.ts +10 -5
- package/.bkit/core/engine/commands/workflow/branches.ts +741 -62
- package/.bkit/core/engine/commands/workflow/challenge.ts +673 -0
- package/.bkit/core/engine/commands/workflow/context.ts +853 -29
- package/.bkit/core/engine/commands/workflow/counters.ts +267 -84
- package/.bkit/core/engine/commands/workflow/decisions.ts +541 -0
- package/.bkit/core/engine/commands/workflow/disk.ts +2 -2
- package/.bkit/core/engine/commands/workflow/fids.ts +793 -33
- package/.bkit/core/engine/commands/workflow/issues.ts +427 -105
- package/.bkit/core/engine/commands/workflow/ledgers.ts +884 -27
- package/.bkit/core/engine/commands/workflow/locks.ts +26 -2
- package/.bkit/core/engine/commands/workflow/plan-blocks.ts +582 -0
- package/.bkit/core/engine/commands/workflow/plan-versions.ts +21 -0
- package/.bkit/core/engine/commands/workflow/prs.ts +166 -30
- package/.bkit/core/engine/commands/workflow/repo.ts +59 -7
- package/.bkit/core/engine/commands/workflow/roadmap.ts +16 -7
- package/.bkit/core/engine/commands/workflow/run-facts.ts +501 -0
- package/.bkit/core/engine/commands/workflow/runs.ts +179 -49
- package/.bkit/core/engine/commands/workflow/runtime.ts +22 -1
- package/.bkit/core/engine/commands/workflow/status.ts +142 -29
- package/.bkit/core/engine/commands/workflow/step-table.ts +339 -0
- package/.bkit/core/engine/commands/workflow/steps.ts +213 -88
- package/.bkit/core/engine/commands/workflow/summary.ts +398 -0
- package/.bkit/core/engine/commands/workflow/tests.ts +1013 -148
- package/.bkit/core/engine/commands/workflow/tracker.ts +1195 -0
- package/.bkit/core/engine/commands/workflow/workflows.ts +984 -207
- package/.bkit/core/engine/commands/workflow/workstreams.ts +11 -5
- package/.bkit/core/engine/commands/workflow/worktrees.ts +276 -22
- package/.bkit/core/engine/install/manifest.ts +11 -9
- package/.bkit/core/engine/install/modules/cloud.ts +21 -13
- package/.bkit/core/engine/install/modules/core.ts +325 -7
- package/.bkit/core/engine/install/modules/opencode.ts +2 -2
- package/.bkit/core/engine/install/version-file.ts +6 -2
- package/.bkit/core/engine/ledgers/migrate.ts +92 -0
- package/.bkit/core/engine/ledgers/status.ts +92 -15
- package/.bkit/core/engine/ledgers/telemetry.ts +1261 -254
- package/.bkit/core/engine/render/hosts.ts +4 -0
- package/.bkit/core/engine/render/models.ts +12 -0
- package/.bkit/core/engine/shared/branches.ts +4 -1
- package/.bkit/core/engine/shared/egress.ts +7 -0
- package/.bkit/core/engine/shared/json.ts +25 -7
- package/.bkit/core/engine/shared/settings.ts +202 -33
- package/.bkit/core/engine/shared/text.ts +361 -0
- package/.bkit/core/engine/tools/grammar-density.ts +215 -0
- package/.bkit/core/engine/tools/instructions-sources.ts +834 -0
- package/.bkit/core/engine/tools/instructions.ts +1751 -0
- package/.bkit/core/hooks/gateguard-engine.js +24 -23
- package/.bkit/core/hooks/guardrails-shell.js +2 -3
- package/.bkit/core/hooks/guardrails-tiers.js +7 -1
- package/.bkit/core/hooks/readguard-engine.js +2 -2
- package/.bkit/core/prompts/bkit-audit-generate.md +62 -25
- package/.bkit/core/prompts/bkit-build-challenge-1.md +40 -17
- package/.bkit/core/prompts/bkit-build-challenge-2.md +44 -17
- package/.bkit/core/prompts/bkit-build-install-skills.md +26 -13
- package/.bkit/core/prompts/bkit-build-plan-convert.md +74 -0
- package/.bkit/core/prompts/bkit-build-plan-current.md +26 -13
- package/.bkit/core/prompts/bkit-build-plan-execute.md +74 -26
- package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +64 -23
- package/.bkit/core/prompts/bkit-build-plan-verify.md +57 -33
- package/.bkit/core/prompts/bkit-debug-abort-handover.md +30 -14
- package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +34 -14
- package/.bkit/core/prompts/bkit-debug-failure-remediate.md +34 -17
- package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +26 -13
- package/.bkit/core/prompts/bkit-debug-failure-soak.md +31 -16
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +21 -11
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +20 -11
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +20 -11
- package/.bkit/core/prompts/bkit-design-generate.md +33 -13
- package/.bkit/core/prompts/bkit-design-organise.md +25 -12
- package/.bkit/core/prompts/bkit-design-review-1.md +31 -15
- package/.bkit/core/prompts/bkit-design-review-2.md +28 -13
- package/.bkit/core/prompts/bkit-design-spike.md +30 -13
- package/.bkit/core/prompts/bkit-design-update.md +33 -19
- package/.bkit/core/prompts/bkit-plan-generate.md +75 -19
- package/.bkit/core/prompts/bkit-plan-review-1.md +50 -27
- package/.bkit/core/prompts/bkit-plan-review-2.md +59 -28
- package/.bkit/core/prompts/bkit-plan-scope-check.md +109 -0
- package/.bkit/core/prompts/bkit-plan-update.md +61 -24
- package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +27 -15
- package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +31 -16
- package/.bkit/core/prompts/bkit-ship-update-docs.md +30 -15
- package/.bkit/core/prompts/bkit-utility-compress-markdown.md +24 -14
- package/.bkit/core/prompts/bkit-utility-update-decisions.md +32 -14
- package/.bkit/core/prompts/bkit-utility-update-deferrals.md +29 -14
- package/.bkit/core/prompts/bkit-utility-update-documentation.md +28 -13
- package/.bkit/core/prompts/bkit-utility-update-failures.md +31 -14
- package/.bkit/core/prompts/bkit-utility-update-knowledge.md +33 -14
- package/.bkit/core/prompts/bkit-utility-update-roadmap.md +38 -17
- package/.bkit/core/prompts/bkit-utility-update-tracker.md +43 -20
- package/.bkit/core/workflows/bkit-auto.md +54 -46
- package/.bkit/core/workflows/bkit-build.md +577 -458
- package/.bkit/core/workflows/bkit-debug.md +348 -333
- package/.bkit/core/workflows/bkit-design.md +201 -237
- package/.bkit/core/workflows/bkit-plan.md +210 -321
- package/.bkit/core/workflows/bkit-ship.md +328 -278
- package/.bkit/shared/.bkit/.env.example +2 -2
- package/.bkit/shared/.claude/settings.json +11 -0
- package/.bkit/shared/.cursor/mcp.json +1 -1
- package/.bkit/shared/.cursor/rules/bkit-rules.mdc +1 -1
- package/.bkit/shared/.gitattributes +1 -1
- package/.bkit/shared/.mcp.json +1 -1
- package/.bkit/shared/.opencode/opencode.json +11 -0
- package/.bkit/shared/CLAUDE.md +2 -2
- package/.bkit/shared/GEMINI.md +2 -2
- package/.bkit/shared/docs/architecture.md +1 -1
- package/.bkit/shared/docs/data-schema.md +1 -1
- package/.bkit/shared/docs/deployments.md +16 -28
- package/.bkit/shared/docs/design.md +1 -1
- package/.bkit/shared/docs/noise.md +1 -1
- package/.bkit/shared/docs/observability.md +2 -2
- package/.bkit/shared/docs/security.md +1 -1
- package/.bkit/shared/docs/setup.md +1 -1
- package/.bkit/shared/docs/technology.md +1 -1
- package/.bkit/shared/docs/testing.md +27 -10
- package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +1 -1
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +26 -5
- package/.bkit/templates/.github/workflows/bkit-ci.yml +22 -84
- package/.bkit/templates/.github/workflows/bkit-cloud.yml +21 -19
- package/.bkit/templates/.husky/pre-push +52 -13
- package/.bkit/templates/.prettierignore +7 -0
- package/.bkit/templates/scripts/ci/bkit-local-stack-lock.sh +194 -0
- package/.bkit/templates/scripts/ci/check-capstone.mjs +2 -4
- package/.bkit/templates/scripts/ci/check-capstone.test.mjs +4 -23
- package/.bkit/templates/scripts/ci/lanes/resolve-push-base.mjs +104 -23
- package/.bkit/templates/scripts/ci/lanes/resolve-push-base.test.mjs +103 -6
- package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +1 -1
- package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +3 -1
- package/.bkit/templates/scripts/prettier/bkit-insert-ignore.mjs +49 -29
- package/CHANGELOG.md +142 -0
- package/README.md +58 -34
- package/dist/checks/after/ci-yml.js +39 -29
- package/dist/checks/after/github.js +99 -72
- package/dist/checks/after/index.js +11 -13
- package/dist/checks/after/suppression.js +8 -5
- package/dist/checks/after/tools.js +40 -83
- package/dist/checks/before/env.js +2 -2
- package/dist/checks/before/files.js +5 -3
- package/dist/checks/before/index.js +15 -2
- package/dist/checks/before/repo.js +163 -2
- package/dist/checks/tips/catalogue.js +14 -5
- package/dist/checks/tips/detect.js +32 -0
- package/dist/checks/tips/index.js +7 -5
- package/dist/cli.js +19 -47
- package/dist/commands/analysis.js +109 -100
- package/dist/commands/ci/ci.js +6 -6
- package/dist/commands/comply.js +54 -91
- package/dist/commands/install/doctor.js +2 -2
- package/dist/commands/install/install.js +50 -19
- package/dist/commands/install/uninstall.js +59 -28
- package/dist/commands/land.js +16 -12
- package/dist/commands/lib.js +51 -16
- package/dist/commands/registry.js +4 -0
- package/dist/commands/setup/setup.js +7 -7
- package/dist/commands/stats.js +136 -0
- package/dist/commands/tips.js +7 -3
- package/dist/commands/workflow/branches.js +656 -56
- package/dist/commands/workflow/challenge.js +556 -0
- package/dist/commands/workflow/context.js +709 -30
- package/dist/commands/workflow/counters.js +208 -75
- package/dist/commands/workflow/decisions.js +441 -0
- package/dist/commands/workflow/disk.js +2 -2
- package/dist/commands/workflow/fids.js +689 -33
- package/dist/commands/workflow/issues.js +362 -99
- package/dist/commands/workflow/ledgers.js +762 -27
- package/dist/commands/workflow/locks.js +24 -2
- package/dist/commands/workflow/plan-blocks.js +437 -0
- package/dist/commands/workflow/plan-versions.js +22 -0
- package/dist/commands/workflow/prs.js +142 -32
- package/dist/commands/workflow/repo.js +52 -7
- package/dist/commands/workflow/roadmap.js +9 -7
- package/dist/commands/workflow/run-facts.js +426 -0
- package/dist/commands/workflow/runs.js +144 -43
- package/dist/commands/workflow/runtime.js +12 -1
- package/dist/commands/workflow/status.js +130 -29
- package/dist/commands/workflow/step-table.js +276 -0
- package/dist/commands/workflow/steps.js +171 -80
- package/dist/commands/workflow/summary.js +275 -0
- package/dist/commands/workflow/tests.js +834 -136
- package/dist/commands/workflow/tracker.js +983 -0
- package/dist/commands/workflow/workflows.js +834 -195
- package/dist/commands/workflow/workstreams.js +11 -5
- package/dist/commands/workflow/worktrees.js +221 -22
- package/dist/install/manifest.js +11 -9
- package/dist/install/modules/cloud.js +22 -13
- package/dist/install/modules/core.js +326 -7
- package/dist/install/modules/opencode.js +2 -2
- package/dist/install/version-file.js +6 -2
- package/dist/ledgers/migrate.js +81 -0
- package/dist/ledgers/status.js +61 -8
- package/dist/ledgers/telemetry.js +905 -124
- package/dist/render/hosts.js +4 -0
- package/dist/render/models.js +12 -0
- package/dist/shared/branches.js +3 -1
- package/dist/shared/egress.js +7 -0
- package/dist/shared/json.js +20 -7
- package/dist/shared/settings.js +147 -26
- package/dist/shared/text.js +333 -0
- package/dist/tools/grammar-density.js +183 -0
- package/dist/tools/instructions-sources.js +721 -0
- package/dist/tools/instructions.js +1579 -0
- package/package.json +114 -23
- package/.bkit/core/engine/commands/harvest.ts +0 -459
- package/.bkit/core/engine/tools/wording.ts +0 -748
- package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +0 -69
- package/.bkit/core/prompts/bkit-build-challenge-remediate.md +0 -71
- package/.bkit/core/prompts/bkit-build-challenge-tests.md +0 -74
- package/.bkit/core/prompts/bkit-build-summary.md +0 -94
- package/.bkit/core/prompts/bkit-debug-summary.md +0 -96
- package/.bkit/core/prompts/bkit-design-summary.md +0 -107
- package/.bkit/core/prompts/bkit-plan-complexity-check.md +0 -67
- package/.bkit/core/prompts/bkit-plan-complexity-split.md +0 -88
- package/.bkit/core/prompts/bkit-plan-review-3.md +0 -93
- package/.bkit/core/prompts/bkit-plan-scope-check-1.md +0 -85
- package/.bkit/core/prompts/bkit-plan-scope-check-2.md +0 -85
- package/.bkit/core/prompts/bkit-plan-summary.md +0 -107
- package/.bkit/core/prompts/bkit-ship-summary.md +0 -78
- package/.bkit/templates/scripts/ci/lanes/check-tree-cache.mjs +0 -138
- package/.bkit/templates/scripts/ci/lanes/check-tree-cache.test.mjs +0 -181
- package/dist/commands/harvest.js +0 -353
- package/dist/tools/wording.js +0 -680
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Example. Copy into scripts/ci/ and own it.
|
|
3
|
+
# bkit install does not write this file and does not overwrite a copy.
|
|
4
|
+
#
|
|
5
|
+
# bkit-local-stack-lock.sh — one run at a time on a local stack every checkout shares.
|
|
6
|
+
#
|
|
7
|
+
# . scripts/ci/bkit-local-stack-lock.sh
|
|
8
|
+
# take_local_stack_lock "<who>" || exit 1 # waits while another run holds it
|
|
9
|
+
# try_local_stack_lock "<who>" # returns 1 at once while another run holds it
|
|
10
|
+
# release_local_stack_lock # optional: the lock frees itself when the caller exits
|
|
11
|
+
#
|
|
12
|
+
# bash scripts/ci/bkit-local-stack-lock.sh run "<who>" -- <command> [args…] # package.json
|
|
13
|
+
#
|
|
14
|
+
# WHY. Agents work in several worktrees of one repo at once, and every worktree talks to the
|
|
15
|
+
# SAME local services: a Docker database, an emulator, anything whose container names and ports
|
|
16
|
+
# come from the repo's config. Nothing stops two worktrees using them at once, so a database
|
|
17
|
+
# reset from one wipes the data under a test run in another, and a dev server that stops "its"
|
|
18
|
+
# stack on exit stops it under someone else's run. Both show up as test failures nobody caused.
|
|
19
|
+
# A run that starts, resets or stops the stack, or tests against it, takes this lock first; a
|
|
20
|
+
# second run waits and says who it is waiting for.
|
|
21
|
+
#
|
|
22
|
+
# Wiring:
|
|
23
|
+
# - package.json: wrap each script that starts, resets or stops the stack, e.g.
|
|
24
|
+
# "db:reset": "bash scripts/ci/bkit-local-stack-lock.sh run db:reset -- <your reset command>"
|
|
25
|
+
# - local runners that test against the stack: source this file and call take_local_stack_lock
|
|
26
|
+
# before the first command that touches the stack.
|
|
27
|
+
# - fix hints and docs name those scripts, never the raw command, which skips the lock.
|
|
28
|
+
#
|
|
29
|
+
# The lock is named after the stack: BKIT_LOCAL_STACK when set, otherwise the folder name of the
|
|
30
|
+
# repo's main checkout, so every worktree of one repo finds the same lock. A throwaway stack with
|
|
31
|
+
# names and ports of its own sets BKIT_LOCAL_STACK to its own name and never waits on the shared
|
|
32
|
+
# one. The lock file sits outside the checkout: ~/.cache/bkit/local-stack-lock/<name>.lock
|
|
33
|
+
# ($XDG_CACHE_HOME when set). A small perl process holds it (flock) and exits within a second of
|
|
34
|
+
# the caller exiting, however the caller ends (its parent changes), so a killed run cannot leave
|
|
35
|
+
# a stale lock behind. perl by its full path, so a PATH shim cannot stand in for it.
|
|
36
|
+
#
|
|
37
|
+
# A runner started by a runner that holds the lock (LOCAL_STACK_LOCK_OWNER, exported on success)
|
|
38
|
+
# does not wait on its own parent. Safe under a caller's `set -e`. CI (CI=true or CI=1): no-op,
|
|
39
|
+
# as a CI runner has one job and its own Docker. LOCAL_STACK_LOCK_WAIT_S (default 3600) caps
|
|
40
|
+
# the wait. Needs bash and /usr/bin/perl (macOS and Linux ship both).
|
|
41
|
+
|
|
42
|
+
_LOCAL_STACK_LOCK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
43
|
+
_LOCAL_STACK_LOCK_ROOT="$(git -C "$_LOCAL_STACK_LOCK_DIR" rev-parse --show-toplevel 2>/dev/null || echo "$_LOCAL_STACK_LOCK_DIR")"
|
|
44
|
+
LOCAL_STACK_LOCK_PID=""
|
|
45
|
+
|
|
46
|
+
# The stack's name: BKIT_LOCAL_STACK, else the main checkout's folder name, the same from every
|
|
47
|
+
# worktree. Characters outside A-Z a-z 0-9 . _ - become _.
|
|
48
|
+
local_stack_lock_name() {
|
|
49
|
+
_lsl_name="${BKIT_LOCAL_STACK:-}"
|
|
50
|
+
if [ -z "$_lsl_name" ]; then
|
|
51
|
+
_lsl_common="$(git -C "$_LOCAL_STACK_LOCK_DIR" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)" || return 1
|
|
52
|
+
[ -n "$_lsl_common" ] || return 1
|
|
53
|
+
case "$(basename "$_lsl_common")" in
|
|
54
|
+
.git) _lsl_name="$(basename "$(dirname "$_lsl_common")")" ;;
|
|
55
|
+
*) _lsl_name="$(basename "$_lsl_common" .git)" ;;
|
|
56
|
+
esac
|
|
57
|
+
fi
|
|
58
|
+
printf '%s\n' "$_lsl_name" | LC_ALL=C tr -c 'A-Za-z0-9._\n-' '_'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
# The lock file for the stack this checkout uses.
|
|
62
|
+
local_stack_lock_file() {
|
|
63
|
+
_lsl_stack="$(local_stack_lock_name)" || return 1
|
|
64
|
+
echo "${XDG_CACHE_HOME:-$HOME/.cache}/bkit/local-stack-lock/${_lsl_stack}.lock"
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# "<who> — <checkout> (pid N, since HH:MM:SS)" for the run holding the lock, or nothing.
|
|
68
|
+
local_stack_lock_holder() {
|
|
69
|
+
_lsl_held="$(local_stack_lock_file)" || return 0
|
|
70
|
+
cat "${_lsl_held}.holder" 2>/dev/null
|
|
71
|
+
return 0
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_local_stack_lock() {
|
|
75
|
+
_lsl_mode="$1"
|
|
76
|
+
_lsl_who="$2"
|
|
77
|
+
if [ "${CI:-}" = "true" ] || [ "${CI:-}" = "1" ]; then return 0; fi
|
|
78
|
+
if [ -n "${LOCAL_STACK_LOCK_OWNER:-}" ] && kill -0 "$LOCAL_STACK_LOCK_OWNER" 2>/dev/null; then return 0; fi
|
|
79
|
+
if [ -n "$LOCAL_STACK_LOCK_PID" ] && kill -0 "$LOCAL_STACK_LOCK_PID" 2>/dev/null; then return 0; fi
|
|
80
|
+
|
|
81
|
+
if ! _lsl_file="$(local_stack_lock_file)"; then
|
|
82
|
+
echo "[local-stack-lock] ❌ cannot name the local stack: run inside a git checkout, or set BKIT_LOCAL_STACK" >&2
|
|
83
|
+
return 1
|
|
84
|
+
fi
|
|
85
|
+
_lsl_label="$(basename "$_lsl_file" .lock)"
|
|
86
|
+
if [ ! -x /usr/bin/perl ]; then
|
|
87
|
+
echo "[local-stack-lock] ❌ could not take the lock for the local stack $_lsl_label: /usr/bin/perl not found" >&2
|
|
88
|
+
return 1
|
|
89
|
+
fi
|
|
90
|
+
mkdir -p "$(dirname "$_lsl_file")" || return 1
|
|
91
|
+
_lsl_fifo="$(mktemp -u "${TMPDIR:-/tmp}/local-stack-lock.XXXXXX")"
|
|
92
|
+
mkfifo "$_lsl_fifo" || return 1
|
|
93
|
+
|
|
94
|
+
# The holder answers on the fifo once: ok, busy <holder>, timeout <holder> or error <why>.
|
|
95
|
+
/usr/bin/perl -e '
|
|
96
|
+
use strict;
|
|
97
|
+
use Fcntl qw(:flock);
|
|
98
|
+
use POSIX qw(strftime);
|
|
99
|
+
my ($file, $owner, $who, $checkout, $fifo, $wait_s, $mode, $label) = @ARGV;
|
|
100
|
+
# The caller is the parent of this process. When it exits, this process goes to init (or a
|
|
101
|
+
# subreaper) at once, while `kill 0` would still find it until whoever started it reaps it.
|
|
102
|
+
my $parent = getppid();
|
|
103
|
+
my $caller_alive = sub { getppid() == $parent };
|
|
104
|
+
open(my $out, ">", $fifo) or exit 1;
|
|
105
|
+
$out->autoflush(1);
|
|
106
|
+
my $holder = sub { open(my $h, "<", "$file.holder") or return "another run"; my $l = <$h>; chomp $l; $l };
|
|
107
|
+
my $lock;
|
|
108
|
+
open($lock, ">>", $file) or do { print $out "error cannot open $file: $!\n"; exit 1 };
|
|
109
|
+
my $start = time;
|
|
110
|
+
my $next_note = 0;
|
|
111
|
+
until (flock($lock, LOCK_EX | LOCK_NB)) {
|
|
112
|
+
exit 0 unless $caller_alive->();
|
|
113
|
+
if ($mode eq "try") { print $out "busy " . $holder->() . "\n"; exit 0 }
|
|
114
|
+
if (time - $start >= $wait_s) { print $out "timeout " . $holder->() . "\n"; exit 0 }
|
|
115
|
+
if (time >= $next_note) {
|
|
116
|
+
my $m = int((time - $start) / 60);
|
|
117
|
+
my $so_far = $m ? " (still, $m min so far)" : "";
|
|
118
|
+
print STDERR "[local-stack-lock] ⏳ $who is waiting for the local stack $label$so_far: in use by " . $holder->() . "\n";
|
|
119
|
+
$next_note = time + 60;
|
|
120
|
+
}
|
|
121
|
+
sleep 1;
|
|
122
|
+
}
|
|
123
|
+
$SIG{TERM} = $SIG{INT} = $SIG{HUP} = sub { unlink "$file.holder"; exit 0 };
|
|
124
|
+
if (open(my $h, ">", "$file.holder")) {
|
|
125
|
+
print $h "$who — $checkout (pid $owner, since " . strftime("%H:%M:%S", localtime) . ")\n";
|
|
126
|
+
close $h;
|
|
127
|
+
}
|
|
128
|
+
print $out "ok\n";
|
|
129
|
+
close $out;
|
|
130
|
+
sleep 1 while $caller_alive->();
|
|
131
|
+
unlink "$file.holder";
|
|
132
|
+
' "$_lsl_file" "$$" "$_lsl_who" "$_LOCAL_STACK_LOCK_ROOT" "$_lsl_fifo" "${LOCAL_STACK_LOCK_WAIT_S:-3600}" "$_lsl_mode" "$_lsl_label" </dev/null >/dev/null &
|
|
133
|
+
_lsl_pid=$!
|
|
134
|
+
# The fifo is opened read-write, so the read never blocks on a holder that died before it
|
|
135
|
+
# answered (a failed fork under load, a killed perl): the loop stops once it is gone.
|
|
136
|
+
_lsl_reply="$(
|
|
137
|
+
exec 3<>"$_lsl_fifo"
|
|
138
|
+
while :; do
|
|
139
|
+
if IFS= read -r -t 1 _lsl_line <&3; then
|
|
140
|
+
printf '%s' "$_lsl_line"
|
|
141
|
+
break
|
|
142
|
+
fi
|
|
143
|
+
kill -0 "$_lsl_pid" 2>/dev/null || break
|
|
144
|
+
done
|
|
145
|
+
)" || true
|
|
146
|
+
rm -f "$_lsl_fifo"
|
|
147
|
+
|
|
148
|
+
case "$_lsl_reply" in
|
|
149
|
+
ok)
|
|
150
|
+
LOCAL_STACK_LOCK_PID="$_lsl_pid"
|
|
151
|
+
export LOCAL_STACK_LOCK_OWNER="$$"
|
|
152
|
+
return 0
|
|
153
|
+
;;
|
|
154
|
+
busy\ *)
|
|
155
|
+
echo "[local-stack-lock] the local stack $_lsl_label is in use by ${_lsl_reply#busy }" >&2
|
|
156
|
+
;;
|
|
157
|
+
timeout\ *)
|
|
158
|
+
echo "[local-stack-lock] ❌ $_lsl_who gave up after ${LOCAL_STACK_LOCK_WAIT_S:-3600}s waiting for the local stack $_lsl_label, in use by ${_lsl_reply#timeout }" >&2
|
|
159
|
+
echo "[local-stack-lock] Let that run finish, or stop it. LOCAL_STACK_LOCK_WAIT_S sets how long to wait." >&2
|
|
160
|
+
;;
|
|
161
|
+
"")
|
|
162
|
+
echo "[local-stack-lock] ❌ could not take the lock for the local stack $_lsl_label: the perl process holding it stopped before it answered" >&2
|
|
163
|
+
;;
|
|
164
|
+
*)
|
|
165
|
+
echo "[local-stack-lock] ❌ could not take the lock for the local stack $_lsl_label: ${_lsl_reply#error }" >&2
|
|
166
|
+
;;
|
|
167
|
+
esac
|
|
168
|
+
wait "$_lsl_pid" 2>/dev/null || true
|
|
169
|
+
return 1
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
take_local_stack_lock() { _local_stack_lock wait "$1"; }
|
|
173
|
+
try_local_stack_lock() { _local_stack_lock try "$1"; }
|
|
174
|
+
|
|
175
|
+
release_local_stack_lock() {
|
|
176
|
+
[ -n "$LOCAL_STACK_LOCK_PID" ] || return 0
|
|
177
|
+
kill "$LOCAL_STACK_LOCK_PID" 2>/dev/null || true
|
|
178
|
+
wait "$LOCAL_STACK_LOCK_PID" 2>/dev/null || true
|
|
179
|
+
LOCAL_STACK_LOCK_PID=""
|
|
180
|
+
unset LOCAL_STACK_LOCK_OWNER
|
|
181
|
+
return 0
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
|
185
|
+
if [ "${1:-}" != "run" ] || [ -z "${2:-}" ]; then
|
|
186
|
+
echo "usage: bash scripts/ci/bkit-local-stack-lock.sh run \"<who>\" -- <command> [args…]" >&2
|
|
187
|
+
exit 2
|
|
188
|
+
fi
|
|
189
|
+
_lsl_run_who="$2"
|
|
190
|
+
shift 2
|
|
191
|
+
[ "${1:-}" = "--" ] && shift
|
|
192
|
+
take_local_stack_lock "$_lsl_run_who" || exit 1
|
|
193
|
+
"$@"
|
|
194
|
+
fi
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
* - the plan does not parse (not JSON, not an object, or no `run_level`),
|
|
13
13
|
* - the planner job (`SCOPE_RESULT`) did not succeed,
|
|
14
14
|
* - no lane is named, or a lane's result was never wired in.
|
|
15
|
-
* It asserts nothing
|
|
16
|
-
* SHA, and nothing about a skipped lane when `run_level` is `none`.
|
|
15
|
+
* It asserts nothing about a skipped lane when `run_level` is `none`.
|
|
17
16
|
*
|
|
18
17
|
* Environment:
|
|
19
18
|
* LANES comma-separated lane names, e.g. `static,unit`. The job named
|
|
@@ -23,7 +22,6 @@
|
|
|
23
22
|
* <LANE>_RAN `needs.<job>.outputs.tests_ran`. Setting the variable (even empty)
|
|
24
23
|
* makes the lane counted: it must report a number above 0. A lane
|
|
25
24
|
* with no such variable is not count-checked.
|
|
26
|
-
* <LANE>_CACHE_SKIP `needs.<job>.outputs.cache_skip`; `true` skips the count check.
|
|
27
25
|
* PLAN optional planner JSON (`needs.bkit-tests-scope.outputs.plan`). Unset
|
|
28
26
|
* means every listed lane is expected to run. Set, it must parse and
|
|
29
27
|
* carry a `run_level`; `none` expects every lane to be skipped.
|
|
@@ -128,7 +126,7 @@ export function checkCapstone(env) {
|
|
|
128
126
|
|
|
129
127
|
const ranKey = `${prefix}_RAN`;
|
|
130
128
|
const counted = Object.hasOwn(env, ranKey);
|
|
131
|
-
if (!counted
|
|
129
|
+
if (!counted) {
|
|
132
130
|
parts.push(`${lane}=${result}`);
|
|
133
131
|
continue;
|
|
134
132
|
}
|
|
@@ -39,7 +39,6 @@ const base = (extra = {}) => ({
|
|
|
39
39
|
STATIC_RESULT: "success",
|
|
40
40
|
UNIT_RESULT: "success",
|
|
41
41
|
UNIT_RAN: "12",
|
|
42
|
-
UNIT_CACHE_SKIP: "",
|
|
43
42
|
...extra,
|
|
44
43
|
});
|
|
45
44
|
|
|
@@ -51,10 +50,8 @@ const planned = (extra = {}) => ({
|
|
|
51
50
|
STATIC_RESULT: "success",
|
|
52
51
|
UNIT_RESULT: "success",
|
|
53
52
|
UNIT_RAN: "12",
|
|
54
|
-
UNIT_CACHE_SKIP: "false",
|
|
55
53
|
INTEGRATION_RESULT: "success",
|
|
56
54
|
INTEGRATION_RAN: "4",
|
|
57
|
-
INTEGRATION_CACHE_SKIP: "false",
|
|
58
55
|
...extra,
|
|
59
56
|
});
|
|
60
57
|
|
|
@@ -64,10 +61,8 @@ const skipPlan = (extra = {}) =>
|
|
|
64
61
|
STATIC_RESULT: "skipped",
|
|
65
62
|
UNIT_RESULT: "skipped",
|
|
66
63
|
UNIT_RAN: "",
|
|
67
|
-
UNIT_CACHE_SKIP: "",
|
|
68
64
|
INTEGRATION_RESULT: "skipped",
|
|
69
65
|
INTEGRATION_RAN: "",
|
|
70
|
-
INTEGRATION_CACHE_SKIP: "",
|
|
71
66
|
...extra,
|
|
72
67
|
});
|
|
73
68
|
|
|
@@ -215,19 +210,9 @@ test("an unparseable plan never lets a skipped lane pass as 'nothing planned'",
|
|
|
215
210
|
|
|
216
211
|
// ── the exemptions ──────────────────────────────────────────────────────────
|
|
217
212
|
|
|
218
|
-
test("
|
|
219
|
-
|
|
220
|
-
|
|
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");
|
|
213
|
+
test("a <LANE>_CACHE_SKIP variable excuses no count", () => {
|
|
214
|
+
reds(base({ UNIT_CACHE_SKIP: "true", UNIT_RAN: "0" }), "0 tests");
|
|
215
|
+
reds(planned({ INTEGRATION_CACHE_SKIP: "true", INTEGRATION_RAN: "0" }), "0 tests");
|
|
231
216
|
});
|
|
232
217
|
|
|
233
218
|
test("EMPTY_COUNT=warn turns an unreported count into a warning, not a failure", () => {
|
|
@@ -262,12 +247,8 @@ test("a hyphenated lane reads <LANE>_ variables with underscores", () => {
|
|
|
262
247
|
LANES: "e2e-web",
|
|
263
248
|
E2E_WEB_RESULT: "success",
|
|
264
249
|
E2E_WEB_RAN: "3",
|
|
265
|
-
E2E_WEB_CACHE_SKIP: "",
|
|
266
250
|
});
|
|
267
|
-
reds(
|
|
268
|
-
{ LANES: "e2e-web", E2E_WEB_RESULT: "success", E2E_WEB_RAN: "0", E2E_WEB_CACHE_SKIP: "" },
|
|
269
|
-
"bkit-tests-e2e-web",
|
|
270
|
-
);
|
|
251
|
+
reds({ LANES: "e2e-web", E2E_WEB_RESULT: "success", E2E_WEB_RAN: "0" }, "bkit-tests-e2e-web");
|
|
271
252
|
});
|
|
272
253
|
|
|
273
254
|
test("lane names tolerate spaces around the commas", () => {
|
|
@@ -12,10 +12,19 @@
|
|
|
12
12
|
* is not an ancestor of HEAD (a force-push rewrote the branch), the base falls back to
|
|
13
13
|
* `event.before`.
|
|
14
14
|
*
|
|
15
|
+
* Local mode gives the pre-push hook the same base, so a local slop scan compares against the
|
|
16
|
+
* commit CI's does: the repo comes from `git remote get-url origin`, `origin/<branch>` stands
|
|
17
|
+
* in for `event.before`, and ancestry is tested against the pushed commit (`--head`), which is
|
|
18
|
+
* not always the checked-out one. gh uses its own login.
|
|
19
|
+
*
|
|
15
20
|
* Usage: node scripts/ci/lanes/resolve-push-base.mjs
|
|
16
21
|
* (env: GH_TOKEN, REPO, BRANCH, BEFORE_SHA, WORKFLOW_FILE; optional SOURCE_FILE)
|
|
17
|
-
*
|
|
18
|
-
*
|
|
22
|
+
* node scripts/ci/lanes/resolve-push-base.mjs --local --branch=dev --head=<pushed sha>
|
|
23
|
+
* (env: optional WORKFLOW_FILE, SOURCE_FILE)
|
|
24
|
+
* Output: the base SHA on stdout; the chosen source (`last-green-run`, `event-before`, ...;
|
|
25
|
+
* `origin/<branch>` in place of `event-before` in local mode) on stderr, and in
|
|
26
|
+
* SOURCE_FILE when that env var names a file. A source ending `(run lookup failed)` or
|
|
27
|
+
* `(resolver failed)` means the run list could not be read. Exit 0 always — every
|
|
19
28
|
* failure (gh, git, unparseable output) falls back to `event.before`, itself a valid base.
|
|
20
29
|
*/
|
|
21
30
|
|
|
@@ -26,15 +35,42 @@ import { pathToFileURL } from "node:url";
|
|
|
26
35
|
/** The workflow whose runs establish the base. Set WORKFLOW_FILE if your CI file has another name. */
|
|
27
36
|
export const WORKFLOW_FILE = process.env.WORKFLOW_FILE || "bkit-ci.yml";
|
|
28
37
|
|
|
29
|
-
/**
|
|
30
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Pure decision. `isAncestor(sha)` answers whether `sha` is an ancestor of the pushed commit.
|
|
40
|
+
* `fallback` names the before-sha in the source (`event-before`, or `origin/<branch>` locally);
|
|
41
|
+
* `lookupFailed` marks a run list that could not be read.
|
|
42
|
+
*/
|
|
43
|
+
export function choosePushBase({
|
|
44
|
+
lastGreenSha,
|
|
45
|
+
beforeSha,
|
|
46
|
+
isAncestor,
|
|
47
|
+
fallback = "event-before",
|
|
48
|
+
lookupFailed = false,
|
|
49
|
+
}) {
|
|
31
50
|
if (lastGreenSha && isAncestor(lastGreenSha)) {
|
|
32
51
|
return { base: lastGreenSha, source: "last-green-run" };
|
|
33
52
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
53
|
+
let source = fallback;
|
|
54
|
+
if (lookupFailed) source = `${fallback} (run lookup failed)`;
|
|
55
|
+
else if (lastGreenSha) source = `${fallback} (last green run is not an ancestor)`;
|
|
56
|
+
return { base: beforeSha ?? "", source };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** `owner/repo` from a GitHub remote URL (https, ssh, scp-style), or "" when it has no such path. */
|
|
60
|
+
export function repoFromRemoteUrl(url) {
|
|
61
|
+
const match = /[/:]([^/:\s]+)\/([^/\s]+?)(?:\.git)?\/?$/.exec(String(url ?? "").trim());
|
|
62
|
+
return match ? `${match[1]}/${match[2]}` : "";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** `--local`, `--branch=`, `--head=` from argv; anything else is ignored. */
|
|
66
|
+
export function parseArgs(argv) {
|
|
67
|
+
const args = { local: false, branch: "", head: "" };
|
|
68
|
+
for (const arg of argv) {
|
|
69
|
+
if (arg === "--local") args.local = true;
|
|
70
|
+
else if (arg.startsWith("--branch=")) args.branch = arg.slice("--branch=".length);
|
|
71
|
+
else if (arg.startsWith("--head=")) args.head = arg.slice("--head=".length);
|
|
72
|
+
}
|
|
73
|
+
return args;
|
|
38
74
|
}
|
|
39
75
|
|
|
40
76
|
/** How far back the run lookup reaches. A green run older than this falls back to event.before. */
|
|
@@ -53,7 +89,8 @@ export function newestRunSha(runs) {
|
|
|
53
89
|
return newest ? newest.head_sha : "";
|
|
54
90
|
}
|
|
55
91
|
|
|
56
|
-
|
|
92
|
+
/** `{ sha, failed }`: the newest green push run's head, and whether the run list was unreadable. */
|
|
93
|
+
function lastGreenPushSha(repo, branch, fallbackName, now = new Date()) {
|
|
57
94
|
const since = new Date(now.getTime() - LOOKBACK_DAYS * 86_400_000).toISOString().slice(0, 10);
|
|
58
95
|
const path =
|
|
59
96
|
`repos/${repo}/actions/workflows/${WORKFLOW_FILE}/runs` +
|
|
@@ -69,17 +106,17 @@ function lastGreenPushSha(repo, branch, now = new Date()) {
|
|
|
69
106
|
if (error || status !== 0) {
|
|
70
107
|
const reason = error ? error.message : String(stderr).split("\n")[0];
|
|
71
108
|
console.error(
|
|
72
|
-
`[resolve-push-base] could not list ${WORKFLOW_FILE} runs (${reason}) — using
|
|
109
|
+
`[resolve-push-base] could not list ${WORKFLOW_FILE} runs (${reason}) — using ${fallbackName}`,
|
|
73
110
|
);
|
|
74
|
-
return "";
|
|
111
|
+
return { sha: "", failed: true };
|
|
75
112
|
}
|
|
76
113
|
// Unparseable output throws; main() catches it and falls back to event.before.
|
|
77
|
-
return newestRunSha(JSON.parse(stdout || "[]"));
|
|
114
|
+
return { sha: newestRunSha(JSON.parse(stdout || "[]")), failed: false };
|
|
78
115
|
}
|
|
79
116
|
|
|
80
|
-
/** True only when `sha` is an ancestor of
|
|
81
|
-
function
|
|
82
|
-
const { status, error } = spawnSync("git", ["merge-base", "--is-ancestor", sha,
|
|
117
|
+
/** True only when `sha` is an ancestor of `head`; any git failure is "not an ancestor" (logged). */
|
|
118
|
+
function isAncestorOf(sha, head, fallbackName) {
|
|
119
|
+
const { status, error } = spawnSync("git", ["merge-base", "--is-ancestor", sha, head], {
|
|
83
120
|
stdio: "ignore",
|
|
84
121
|
});
|
|
85
122
|
// 0 = ancestor. 1 = not an ancestor. 128 = the SHA is not in this clone (a force-push dropped
|
|
@@ -88,22 +125,64 @@ function isAncestorOfHead(sha) {
|
|
|
88
125
|
if (!error && (status === 1 || status === 128)) return false;
|
|
89
126
|
const reason = error ? error.message : `git exited ${status}`;
|
|
90
127
|
console.error(
|
|
91
|
-
`[resolve-push-base] cannot test ancestry of ${sha} (${reason}) — using
|
|
128
|
+
`[resolve-push-base] cannot test ancestry of ${sha} (${reason}) — using ${fallbackName}`,
|
|
92
129
|
);
|
|
93
130
|
return false;
|
|
94
131
|
}
|
|
95
132
|
|
|
96
|
-
|
|
133
|
+
/** stdout of a git command, or "" when it fails. */
|
|
134
|
+
function gitOut(args) {
|
|
135
|
+
const { status, stdout, error } = spawnSync("git", args, {
|
|
136
|
+
encoding: "utf8",
|
|
137
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
138
|
+
});
|
|
139
|
+
return !error && status === 0 ? stdout.trim() : "";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The resolver's inputs. CI: env vars, ancestry against HEAD. Local (`--local`): repo from
|
|
144
|
+
* origin's URL, before-sha from `origin/<branch>`, ancestry against `--head`.
|
|
145
|
+
*/
|
|
146
|
+
export function resolveInputs(env, argv) {
|
|
147
|
+
const args = parseArgs(argv);
|
|
148
|
+
if (!args.local) {
|
|
149
|
+
return {
|
|
150
|
+
repo: env.REPO,
|
|
151
|
+
branch: env.BRANCH,
|
|
152
|
+
beforeSha: env.BEFORE_SHA,
|
|
153
|
+
head: "HEAD",
|
|
154
|
+
fallback: "event-before",
|
|
155
|
+
fallbackName: "event.before",
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const branch = args.branch || "dev";
|
|
159
|
+
return {
|
|
160
|
+
repo: repoFromRemoteUrl(gitOut(["remote", "get-url", "origin"])),
|
|
161
|
+
branch,
|
|
162
|
+
beforeSha: gitOut(["rev-parse", "--verify", "--quiet", `origin/${branch}^{commit}`]),
|
|
163
|
+
head: args.head || "HEAD",
|
|
164
|
+
fallback: `origin/${branch}`,
|
|
165
|
+
fallbackName: `origin/${branch}`,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function main(env, argv = []) {
|
|
170
|
+
const input = resolveInputs(env, argv);
|
|
97
171
|
let result;
|
|
98
172
|
try {
|
|
173
|
+
const lastGreen = lastGreenPushSha(input.repo, input.branch, input.fallbackName);
|
|
99
174
|
result = choosePushBase({
|
|
100
|
-
lastGreenSha:
|
|
101
|
-
beforeSha:
|
|
102
|
-
isAncestor:
|
|
175
|
+
lastGreenSha: lastGreen.sha,
|
|
176
|
+
beforeSha: input.beforeSha,
|
|
177
|
+
isAncestor: (sha) => isAncestorOf(sha, input.head, input.fallbackName),
|
|
178
|
+
fallback: input.fallback,
|
|
179
|
+
lookupFailed: lastGreen.failed,
|
|
103
180
|
});
|
|
104
181
|
} catch (err) {
|
|
105
|
-
console.error(
|
|
106
|
-
|
|
182
|
+
console.error(
|
|
183
|
+
`[resolve-push-base] unexpected failure (${err.message}) — using ${input.fallbackName}`,
|
|
184
|
+
);
|
|
185
|
+
result = { base: input.beforeSha ?? "", source: `${input.fallback} (resolver failed)` };
|
|
107
186
|
}
|
|
108
187
|
const { base, source } = result;
|
|
109
188
|
console.error(`[resolve-push-base] base=${base || "(none)"} source=${source}`);
|
|
@@ -116,4 +195,6 @@ export function main(env) {
|
|
|
116
195
|
}
|
|
117
196
|
}
|
|
118
197
|
|
|
119
|
-
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href)
|
|
198
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
|
|
199
|
+
main(process.env, process.argv.slice(2));
|
|
200
|
+
}
|
|
@@ -13,18 +13,26 @@ import fs from "node:fs";
|
|
|
13
13
|
import os from "node:os";
|
|
14
14
|
import path from "node:path";
|
|
15
15
|
import { fileURLToPath } from "node:url";
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
choosePushBase,
|
|
18
|
+
newestRunSha,
|
|
19
|
+
parseArgs,
|
|
20
|
+
repoFromRemoteUrl,
|
|
21
|
+
} from "./resolve-push-base.mjs";
|
|
17
22
|
|
|
18
23
|
const SCRIPT = fileURLToPath(new URL("./resolve-push-base.mjs", import.meta.url));
|
|
19
24
|
|
|
20
|
-
/** Run the script with fake `gh` / `git` binaries first on PATH. */
|
|
21
|
-
function runWithFakes({ gh, git }) {
|
|
25
|
+
/** Run the script with fake `gh` / `git` binaries first on PATH; `gh` calls land in gh.log. */
|
|
26
|
+
function runWithFakes({ gh, git, args = [], env = {} }) {
|
|
22
27
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "push-base-"));
|
|
23
28
|
try {
|
|
24
|
-
|
|
29
|
+
const ghLog = path.join(dir, "gh.log");
|
|
30
|
+
fs.writeFileSync(path.join(dir, "gh"), `#!/bin/sh\necho "$*" >> "${ghLog}"\n${gh}\n`, {
|
|
31
|
+
mode: 0o755,
|
|
32
|
+
});
|
|
25
33
|
fs.writeFileSync(path.join(dir, "git"), `#!/bin/sh\n${git}\n`, { mode: 0o755 });
|
|
26
34
|
const sourceFile = path.join(dir, "source");
|
|
27
|
-
const r = spawnSync(process.execPath, [SCRIPT], {
|
|
35
|
+
const r = spawnSync(process.execPath, [SCRIPT, ...args], {
|
|
28
36
|
encoding: "utf8",
|
|
29
37
|
env: {
|
|
30
38
|
...process.env,
|
|
@@ -33,10 +41,12 @@ function runWithFakes({ gh, git }) {
|
|
|
33
41
|
BRANCH: "dev",
|
|
34
42
|
BEFORE_SHA: "b".repeat(40),
|
|
35
43
|
SOURCE_FILE: sourceFile,
|
|
44
|
+
...env,
|
|
36
45
|
},
|
|
37
46
|
});
|
|
38
47
|
const source = fs.existsSync(sourceFile) ? fs.readFileSync(sourceFile, "utf8").trim() : "";
|
|
39
|
-
|
|
48
|
+
const ghCalls = fs.existsSync(ghLog) ? fs.readFileSync(ghLog, "utf8") : "";
|
|
49
|
+
return { status: r.status, stdout: r.stdout.trim(), stderr: r.stderr, source, ghCalls };
|
|
40
50
|
} finally {
|
|
41
51
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
42
52
|
}
|
|
@@ -136,5 +146,92 @@ test("a green ancestor run reports last-green-run as the source", () => {
|
|
|
136
146
|
assert(r.source === "last-green-run", r.source);
|
|
137
147
|
});
|
|
138
148
|
|
|
149
|
+
test("a run list that could not be read is named in the source", () => {
|
|
150
|
+
const r = choosePushBase({
|
|
151
|
+
lastGreenSha: "",
|
|
152
|
+
beforeSha: BEFORE,
|
|
153
|
+
isAncestor: ancestors(),
|
|
154
|
+
lookupFailed: true,
|
|
155
|
+
});
|
|
156
|
+
assert(r.base === BEFORE, r.base);
|
|
157
|
+
assert(r.source === "event-before (run lookup failed)", r.source);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("local mode names origin/<branch> as the fallback", () => {
|
|
161
|
+
const r = choosePushBase({
|
|
162
|
+
lastGreenSha: GREEN,
|
|
163
|
+
beforeSha: BEFORE,
|
|
164
|
+
isAncestor: ancestors(BEFORE),
|
|
165
|
+
fallback: "origin/dev",
|
|
166
|
+
});
|
|
167
|
+
assert(r.source === "origin/dev (last green run is not an ancestor)", r.source);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("owner/repo comes out of https, ssh and scp-style remote URLs", () => {
|
|
171
|
+
assert(repoFromRemoteUrl("https://github.com/o/r.git") === "o/r", "https .git");
|
|
172
|
+
assert(repoFromRemoteUrl("https://github.com/o/r") === "o/r", "https");
|
|
173
|
+
assert(repoFromRemoteUrl("git@github.com:o/r.git\n") === "o/r", "scp");
|
|
174
|
+
assert(repoFromRemoteUrl("ssh://git@github.com/o/r.git") === "o/r", "ssh");
|
|
175
|
+
assert(repoFromRemoteUrl("") === "", "empty");
|
|
176
|
+
assert(repoFromRemoteUrl(undefined) === "", "missing");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("--local, --branch and --head are read from argv", () => {
|
|
180
|
+
const a = parseArgs(["--local", "--branch=main", `--head=${GREEN}`]);
|
|
181
|
+
assert(a.local && a.branch === "main" && a.head === GREEN, JSON.stringify(a));
|
|
182
|
+
const ci = parseArgs([]);
|
|
183
|
+
assert(!ci.local && ci.branch === "" && ci.head === "", JSON.stringify(ci));
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test("CI mode: an unreadable run list falls back to event.before and says so", () => {
|
|
187
|
+
const r = runWithFakes({ gh: "echo 'HTTP 401' >&2; exit 1", git: "exit 0" });
|
|
188
|
+
assert(r.status === 0 && r.stdout === "b".repeat(40), JSON.stringify(r));
|
|
189
|
+
assert(r.source === "event-before (run lookup failed)", r.source);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Local mode: origin's URL gives the repo, origin/dev the before-sha; ancestry is tested
|
|
193
|
+
// against the pushed commit only ($4 of `git merge-base --is-ancestor <sha> <head>`).
|
|
194
|
+
const ORIGIN = "d".repeat(40);
|
|
195
|
+
const PUSHED = "e".repeat(40);
|
|
196
|
+
const LOCAL_GIT = `case "$1" in
|
|
197
|
+
remote) echo "git@github.com:me/app.git" ;;
|
|
198
|
+
rev-parse) echo "${ORIGIN}" ;;
|
|
199
|
+
merge-base) [ "$4" = "${PUSHED}" ] && exit 0; exit 1 ;;
|
|
200
|
+
*) exit 2 ;;
|
|
201
|
+
esac`;
|
|
202
|
+
const LOCAL_ARGS = ["--local", "--branch=dev", `--head=${PUSHED}`];
|
|
203
|
+
const NO_CI_ENV = { REPO: "ci/repo", BEFORE_SHA: "f".repeat(40) };
|
|
204
|
+
|
|
205
|
+
test("local mode: last green run is an ancestor of --head → that run's head", () => {
|
|
206
|
+
const r = runWithFakes({ gh: RUNS, git: LOCAL_GIT, args: LOCAL_ARGS, env: NO_CI_ENV });
|
|
207
|
+
assert(r.status === 0 && r.stdout === "a".repeat(40), JSON.stringify(r));
|
|
208
|
+
assert(r.source === "last-green-run", r.source);
|
|
209
|
+
assert(r.ghCalls.includes("repos/me/app/actions/workflows/"), r.ghCalls);
|
|
210
|
+
assert(r.ghCalls.includes("branch=dev&event=push&status=success"), r.ghCalls);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("local mode: ancestry is tested against --head, not HEAD", () => {
|
|
214
|
+
const r = runWithFakes({
|
|
215
|
+
gh: RUNS,
|
|
216
|
+
git: LOCAL_GIT,
|
|
217
|
+
args: ["--local", "--branch=dev", `--head=${"9".repeat(40)}`],
|
|
218
|
+
});
|
|
219
|
+
assert(r.stdout === ORIGIN, r.stdout);
|
|
220
|
+
assert(r.source === "origin/dev (last green run is not an ancestor)", r.source);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test("local mode: gh fails → origin/dev, the reason on stderr, env REPO / BEFORE_SHA unused", () => {
|
|
224
|
+
const r = runWithFakes({
|
|
225
|
+
gh: "echo 'gh: not logged in' >&2; exit 4",
|
|
226
|
+
git: LOCAL_GIT,
|
|
227
|
+
args: LOCAL_ARGS,
|
|
228
|
+
env: NO_CI_ENV,
|
|
229
|
+
});
|
|
230
|
+
assert(r.status === 0 && r.stdout === ORIGIN, JSON.stringify(r));
|
|
231
|
+
assert(r.source === "origin/dev (run lookup failed)", r.source);
|
|
232
|
+
assert(r.stderr.includes("gh: not logged in"), r.stderr);
|
|
233
|
+
assert(r.ghCalls.includes("repos/me/app/"), r.ghCalls);
|
|
234
|
+
});
|
|
235
|
+
|
|
139
236
|
console.log(`\n${passed} passed, ${failed} failed`);
|
|
140
237
|
process.exit(failed > 0 ? 1 : 0);
|
|
@@ -87,7 +87,7 @@ function judge(cwd, wt, fid) {
|
|
|
87
87
|
|
|
88
88
|
/** Remove worktree `wt`; null when gone, else why not. */
|
|
89
89
|
function removeWorktree(cwd, wt, fid) {
|
|
90
|
-
const r = spawnSync("pnpm", ["-s", "bkit", "worktrees", "remove", `--fid=${fid}
|
|
90
|
+
const r = spawnSync("pnpm", ["-s", "bkit", "worktrees", "remove", `--fid=${fid}`, "--json"], {
|
|
91
91
|
cwd,
|
|
92
92
|
encoding: "utf8",
|
|
93
93
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Example.
|
|
2
|
+
# Example. Copy to scripts/graphify/ and own it. The bkit .husky/pre-push template runs it
|
|
3
|
+
# above the gates, so a stale register blocks in ~30s, not after the full gate; an older hook
|
|
4
|
+
# copy lacks that call → re-copy the "Capability register" block from the template.
|
|
3
5
|
# bkit install does not write this file and does not overwrite a copy.
|
|
4
6
|
#
|
|
5
7
|
# Capability register current on dev. BLOCKS a push to dev when docs/capabilities.md is not
|