@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
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
// commands/workflow/tests-base.ts — `bkit tests base`: do the gate's failing tests also fail on
|
|
2
|
+
// the commit the branch started from?
|
|
3
|
+
//
|
|
4
|
+
// A red group gate or final run pauses the build. Whether a fix round could help depends on
|
|
5
|
+
// where the failure comes from: the branch, or `dev`. This verb answers that from a passing CI
|
|
6
|
+
// run at the base sha, else from a throwaway checkout of the base commit that re-runs only the
|
|
7
|
+
// failing test files. Exit 0 for every verdict; only a usage error exits non-zero.
|
|
8
|
+
//
|
|
9
|
+
// A leaf of the verb graph: it imports nothing from `tests.ts`, and reaches `runs.ts` only
|
|
10
|
+
// through a dynamic import inside the handler.
|
|
11
|
+
|
|
12
|
+
import * as fs from "node:fs";
|
|
13
|
+
import * as os from "node:os";
|
|
14
|
+
import * as path from "node:path";
|
|
15
|
+
|
|
16
|
+
import { BKIT_TEST_FILE_SCRIPT } from "../../install/manifest.js";
|
|
17
|
+
import { parseJson } from "../../shared/json.js";
|
|
18
|
+
import { readBkitConfig } from "../../shared/settings.js";
|
|
19
|
+
import { readPackageJson } from "../../shared/package-json.js";
|
|
20
|
+
import { withCleanup } from "../ci/ci.js";
|
|
21
|
+
import { dropLandTree } from "../land.js";
|
|
22
|
+
import { CommandError, EXIT, git, mainCheckoutRoot, runGh, runGit, type VerbSpec } from "../lib.js";
|
|
23
|
+
import { reportFailures, runTestFile, type JunitCase } from "./junit.js";
|
|
24
|
+
import { latestRuntimeRow } from "./runtime.js";
|
|
25
|
+
import { resolveOwnerRepo } from "./repo.js";
|
|
26
|
+
import { copyListed, devBase, install } from "./worktrees.js";
|
|
27
|
+
|
|
28
|
+
export type AtBase = "red" | "pass" | "absent" | "unknown";
|
|
29
|
+
export type Verdict = "all" | "some" | "none" | "unknown";
|
|
30
|
+
|
|
31
|
+
export interface CaseRow {
|
|
32
|
+
name: string;
|
|
33
|
+
file: string | null;
|
|
34
|
+
atBase: AtBase;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface BaseVerdict {
|
|
38
|
+
verdict: Verdict;
|
|
39
|
+
reason: string | null;
|
|
40
|
+
failing: number;
|
|
41
|
+
baseRed: number;
|
|
42
|
+
branch: number;
|
|
43
|
+
undetermined: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A repo-relative path with no `..` segment and no root, in `/` form; else null. */
|
|
47
|
+
function safeRelative(p: string): string | null {
|
|
48
|
+
const norm = path.posix.normalize(p.replace(/\\/g, "/"));
|
|
49
|
+
if (norm === "." || norm.startsWith("/") || /^[a-z]:/i.test(norm)) return null;
|
|
50
|
+
if (norm.split("/").includes("..")) return null;
|
|
51
|
+
return norm;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The tracked repo file a failing case ran in: its `file` attribute when that is a tracked
|
|
56
|
+
* repo-relative path, else its `classname` when that is one, else the one tracked file whose
|
|
57
|
+
* basename is the `classname`'s. Null when none applies or two match. An untracked, absolute
|
|
58
|
+
* or `..` path is never returned.
|
|
59
|
+
*/
|
|
60
|
+
export function caseFile(c: JunitCase, tracked: readonly string[]): string | null {
|
|
61
|
+
const set = new Set(tracked);
|
|
62
|
+
for (const candidate of [c.file, c.classname]) {
|
|
63
|
+
if (candidate === null) continue;
|
|
64
|
+
const rel = safeRelative(candidate);
|
|
65
|
+
if (rel !== null && set.has(rel)) return rel;
|
|
66
|
+
}
|
|
67
|
+
if (c.classname === null) return null;
|
|
68
|
+
const rel = safeRelative(c.classname);
|
|
69
|
+
if (rel === null) return null;
|
|
70
|
+
const base = path.posix.basename(rel);
|
|
71
|
+
const hits = tracked.filter((t) => path.posix.basename(t) === base);
|
|
72
|
+
return hits.length === 1 ? hits[0]! : null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Fold per-case base outcomes into one verdict with counts. */
|
|
76
|
+
export function baseVerdict(cases: readonly CaseRow[]): BaseVerdict {
|
|
77
|
+
const failing = cases.length;
|
|
78
|
+
const baseRed = cases.filter((c) => c.atBase === "red").length;
|
|
79
|
+
const branch = cases.filter((c) => c.atBase === "pass" || c.atBase === "absent").length;
|
|
80
|
+
const undetermined = failing - baseRed - branch;
|
|
81
|
+
const counts = { failing, baseRed, branch, undetermined };
|
|
82
|
+
if (failing === 0)
|
|
83
|
+
return { verdict: "unknown", reason: "gate red with no failing test case", ...counts };
|
|
84
|
+
if (baseRed === failing) return { verdict: "all", reason: null, ...counts };
|
|
85
|
+
if (baseRed === 0 && undetermined === 0) return { verdict: "none", reason: null, ...counts };
|
|
86
|
+
if (baseRed === 0)
|
|
87
|
+
return {
|
|
88
|
+
verdict: "unknown",
|
|
89
|
+
reason: `${undetermined} case(s) with no resolvable result at the base commit`,
|
|
90
|
+
...counts,
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
verdict: "some",
|
|
94
|
+
reason:
|
|
95
|
+
undetermined > 0
|
|
96
|
+
? `${undetermined} case(s) with no resolvable result at the base commit`
|
|
97
|
+
: null,
|
|
98
|
+
...counts,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface BaseRun {
|
|
103
|
+
/** Set when no case could be run at base; the reason is the verdict's. */
|
|
104
|
+
reason: string | null;
|
|
105
|
+
/** Per file: its cases at base; null when the run wrote no report; absent key = file not at base. */
|
|
106
|
+
files: Map<string, JunitCase[] | null>;
|
|
107
|
+
/** Per file: the exit code of its base run. */
|
|
108
|
+
exits: Map<string, number>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
interface Output extends BaseVerdict {
|
|
112
|
+
base: string | null;
|
|
113
|
+
source: "ci" | "local" | null;
|
|
114
|
+
adopt: boolean;
|
|
115
|
+
cases: CaseRow[];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const str = (v: unknown): string | undefined => (typeof v === "string" && v !== "" ? v : undefined);
|
|
119
|
+
|
|
120
|
+
function readRows(file: string): Record<string, unknown>[] {
|
|
121
|
+
if (!fs.existsSync(file)) throw new CommandError(EXIT.USAGE, `--file ${file} does not exist`);
|
|
122
|
+
const rows: Record<string, unknown>[] = [];
|
|
123
|
+
for (const line of fs.readFileSync(file, "utf-8").split("\n")) {
|
|
124
|
+
if (line.trim() === "") continue;
|
|
125
|
+
const read = parseJson(line);
|
|
126
|
+
// A malformed line is not a row.
|
|
127
|
+
if (read.ok && typeof read.value === "object" && read.value !== null)
|
|
128
|
+
rows.push(read.value as Record<string, unknown>);
|
|
129
|
+
}
|
|
130
|
+
return rows;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const testsBaseVerb: VerbSpec = {
|
|
134
|
+
summary:
|
|
135
|
+
"Check whether the failing tests of a red gate also fail on the commit the branch started from; exit 0 for every verdict.",
|
|
136
|
+
use: "workflow",
|
|
137
|
+
flags: [
|
|
138
|
+
{ name: "log", type: "string", help: "the gate log; its JUnit reports are in {log}.reports" },
|
|
139
|
+
{ name: "file", type: "string", help: "the run's status.jsonl" },
|
|
140
|
+
{ name: "workflow", type: "string", help: "the workflow whose runtime row sets `adopt`" },
|
|
141
|
+
{ name: "out", type: "string", help: "also write the output JSON to this path" },
|
|
142
|
+
],
|
|
143
|
+
output: {
|
|
144
|
+
verdict: "all / some / none / unknown",
|
|
145
|
+
reason: "why the verdict is unknown, or which cases could not be checked for some; else null",
|
|
146
|
+
base: "the base commit sha, or null",
|
|
147
|
+
source:
|
|
148
|
+
"ci (a passing push-event CI run at the base sha), local (a run at the base commit), or null",
|
|
149
|
+
failing: "the gate's failing test cases",
|
|
150
|
+
baseRed: "of those, how many also fail at the base commit",
|
|
151
|
+
branch: "of those, how many pass or do not exist at the base commit",
|
|
152
|
+
undetermined: "of those, how many could not be checked",
|
|
153
|
+
adopt: "true when the run has no worktrees (runtimeWorktrees false)",
|
|
154
|
+
cases: "each failing case: {name, file, atBase: red / pass / absent / unknown}",
|
|
155
|
+
},
|
|
156
|
+
run: async (ctx) => {
|
|
157
|
+
const log = str(ctx.flags.log);
|
|
158
|
+
const file = str(ctx.flags.file);
|
|
159
|
+
const workflow = str(ctx.flags.workflow);
|
|
160
|
+
for (const [flag, value] of [
|
|
161
|
+
["log", log],
|
|
162
|
+
["file", file],
|
|
163
|
+
["workflow", workflow],
|
|
164
|
+
] as const)
|
|
165
|
+
if (value === undefined) throw new CommandError(EXIT.USAGE, `--${flag} is required`);
|
|
166
|
+
const out = str(ctx.flags.out);
|
|
167
|
+
const top = git(ctx.cwd, ["rev-parse", "--show-toplevel"]) ?? ctx.cwd;
|
|
168
|
+
const runtime = latestRuntimeRow(readRows(file!), workflow);
|
|
169
|
+
const adopt = runtime?.runtimeWorktrees === false;
|
|
170
|
+
|
|
171
|
+
const finish = (r: Omit<Output, "adopt">): number => {
|
|
172
|
+
const output: Output = { ...r, adopt };
|
|
173
|
+
if (out) {
|
|
174
|
+
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
175
|
+
fs.writeFileSync(out, `${JSON.stringify(output, null, 2)}\n`);
|
|
176
|
+
}
|
|
177
|
+
ctx.emit({ ...output });
|
|
178
|
+
return EXIT.OK;
|
|
179
|
+
};
|
|
180
|
+
const unknown = (reason: string, base: string | null, cases: CaseRow[] = []) =>
|
|
181
|
+
finish({
|
|
182
|
+
...baseVerdict(cases),
|
|
183
|
+
verdict: "unknown",
|
|
184
|
+
reason,
|
|
185
|
+
base,
|
|
186
|
+
source: null,
|
|
187
|
+
cases,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const reports = `${log}.reports`;
|
|
191
|
+
const failures = fs.existsSync(reports) ? reportFailures(reports) : null;
|
|
192
|
+
if (failures === null) return unknown("no JUnit report", null);
|
|
193
|
+
if (failures.length === 0) return finish({ ...noCases(), base: null, source: null, cases: [] });
|
|
194
|
+
|
|
195
|
+
const tracked = (git(top, ["ls-files", "-z"]) ?? "").split("\0").filter(Boolean);
|
|
196
|
+
const resolved = failures.map((c) => ({ c, file: caseFile(c, tracked) }));
|
|
197
|
+
const rowsWith = (at: (c: JunitCase, f: string | null) => AtBase): CaseRow[] =>
|
|
198
|
+
resolved.map(({ c, file: f }) => ({ name: c.name, file: f, atBase: at(c, f) }));
|
|
199
|
+
|
|
200
|
+
const mergeBase = git(top, ["merge-base", "HEAD", devBase(top)]);
|
|
201
|
+
if (mergeBase === null)
|
|
202
|
+
return unknown(
|
|
203
|
+
"no base commit",
|
|
204
|
+
null,
|
|
205
|
+
rowsWith(() => "unknown"),
|
|
206
|
+
);
|
|
207
|
+
const base: string = mergeBase;
|
|
208
|
+
|
|
209
|
+
// A passing push-event CI run at the exact base sha settles "none" without a checkout.
|
|
210
|
+
const repo = resolveOwnerRepo(top);
|
|
211
|
+
if (repo !== null) {
|
|
212
|
+
const { shipGate } = await import("./runs.js");
|
|
213
|
+
const gate = shipGate(
|
|
214
|
+
{ root: top, head: base, repo: repo.ownerRepo, event: "push" },
|
|
215
|
+
(args) => runGh(top, args),
|
|
216
|
+
ctx.log,
|
|
217
|
+
);
|
|
218
|
+
if (gate.passed && gate.skippedLanes.length === 0) {
|
|
219
|
+
const cases = rowsWith(() => "pass");
|
|
220
|
+
return finish({ ...baseVerdict(cases), base, source: "ci", cases });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (!readBkitConfig(top).worktreeInstall)
|
|
225
|
+
return unknown(
|
|
226
|
+
"no install at the base commit (worktreeInstall off)",
|
|
227
|
+
base,
|
|
228
|
+
rowsWith(() => "unknown"),
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const files = [...new Set(resolved.flatMap((r) => (r.file === null ? [] : [r.file])))];
|
|
232
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "bkit-base-"));
|
|
233
|
+
const logDir = `${log}.base`;
|
|
234
|
+
const baseRun = (): BaseRun => {
|
|
235
|
+
const result: BaseRun = { reason: null, files: new Map(), exits: new Map() };
|
|
236
|
+
const added = runGit(top, [
|
|
237
|
+
"-c",
|
|
238
|
+
"core.hooksPath=/dev/null",
|
|
239
|
+
"worktree",
|
|
240
|
+
"add",
|
|
241
|
+
"-q",
|
|
242
|
+
"--detach",
|
|
243
|
+
tmp,
|
|
244
|
+
base,
|
|
245
|
+
]);
|
|
246
|
+
if (!added.ok) return { ...result, reason: "base checkout failed" };
|
|
247
|
+
copyListed(mainCheckoutRoot(top) ?? top, tmp, readBkitConfig(top).worktreeCopy, ctx.log);
|
|
248
|
+
const pkg = readPackageJson(tmp);
|
|
249
|
+
const scripts = pkg.ok ? pkg.pkg.scripts : undefined;
|
|
250
|
+
const declared =
|
|
251
|
+
typeof scripts === "object" &&
|
|
252
|
+
scripts !== null &&
|
|
253
|
+
typeof (scripts as Record<string, unknown>)[BKIT_TEST_FILE_SCRIPT] === "string";
|
|
254
|
+
if (!declared)
|
|
255
|
+
return { ...result, reason: `${BKIT_TEST_FILE_SCRIPT} not declared at the base commit` };
|
|
256
|
+
const status = install(tmp, ctx.log, { preferOffline: true });
|
|
257
|
+
if (status !== 0) return { ...result, reason: `base install failed (exit ${status})` };
|
|
258
|
+
files.forEach((f, n) => {
|
|
259
|
+
if (!fs.existsSync(path.join(tmp, f))) return;
|
|
260
|
+
const ran = runTestFile(tmp, f, path.join(logDir, `${n}.log`));
|
|
261
|
+
result.files.set(f, ran.cases);
|
|
262
|
+
result.exits.set(f, ran.exitCode);
|
|
263
|
+
});
|
|
264
|
+
return result;
|
|
265
|
+
};
|
|
266
|
+
const run = await withCleanup(baseRun, () => dropLandTree(top, tmp));
|
|
267
|
+
if (run.reason !== null)
|
|
268
|
+
return unknown(
|
|
269
|
+
run.reason,
|
|
270
|
+
base,
|
|
271
|
+
rowsWith(() => "unknown"),
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
let noReport = false;
|
|
275
|
+
let crashed: number | null = null;
|
|
276
|
+
let skipped = 0;
|
|
277
|
+
const cases = rowsWith((c, f) => {
|
|
278
|
+
if (f === null) return "unknown";
|
|
279
|
+
if (!run.files.has(f)) return "absent";
|
|
280
|
+
const ran = run.files.get(f);
|
|
281
|
+
if (ran === null || ran === undefined) {
|
|
282
|
+
noReport = true;
|
|
283
|
+
return "unknown";
|
|
284
|
+
}
|
|
285
|
+
const same = ran.find((b) => b.name === c.name);
|
|
286
|
+
if (same === undefined) {
|
|
287
|
+
const exit = run.exits.get(f) ?? 0;
|
|
288
|
+
if (exit !== 0) {
|
|
289
|
+
crashed ??= exit;
|
|
290
|
+
return "unknown";
|
|
291
|
+
}
|
|
292
|
+
return "absent";
|
|
293
|
+
}
|
|
294
|
+
if (same.state === "failure" || same.state === "error") return "red";
|
|
295
|
+
if (same.state === "passed") return "pass";
|
|
296
|
+
skipped += 1;
|
|
297
|
+
return "unknown";
|
|
298
|
+
});
|
|
299
|
+
const verdict = baseVerdict(cases);
|
|
300
|
+
if (verdict.verdict === "unknown" || verdict.verdict === "some") {
|
|
301
|
+
const unresolved = cases.filter((c) => c.file === null).length;
|
|
302
|
+
const reason = noReport
|
|
303
|
+
? "no report from the base run"
|
|
304
|
+
: crashed !== null
|
|
305
|
+
? `the base run of a test file exited ${crashed} without the failing case`
|
|
306
|
+
: unresolved > 0
|
|
307
|
+
? `${unresolved} case(s) with no resolvable file`
|
|
308
|
+
: skipped > 0
|
|
309
|
+
? `${skipped} case(s) skipped at the base commit`
|
|
310
|
+
: verdict.reason;
|
|
311
|
+
return finish({ ...verdict, reason, base, source: "local", cases });
|
|
312
|
+
}
|
|
313
|
+
return finish({ ...verdict, base, source: "local", cases });
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
function noCases(): BaseVerdict {
|
|
318
|
+
return baseVerdict([]);
|
|
319
|
+
}
|
|
@@ -5,96 +5,161 @@
|
|
|
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
7
|
|
|
8
|
-
import { spawnSync } from "node:child_process";
|
|
9
8
|
import * as fs from "node:fs";
|
|
10
9
|
import * as os from "node:os";
|
|
11
10
|
import * as path from "node:path";
|
|
12
11
|
|
|
13
12
|
import { BKIT_GATE_CHANGED_SCRIPT } from "../../install/manifest.js";
|
|
14
|
-
import {
|
|
15
|
-
classifyLockExit,
|
|
16
|
-
CommandError,
|
|
17
|
-
EXIT,
|
|
18
|
-
git,
|
|
19
|
-
testsLockHolder,
|
|
20
|
-
wholeNumber,
|
|
21
|
-
type VerbSpec,
|
|
22
|
-
} from "../lib.js";
|
|
13
|
+
import { CommandError, EXIT, git, runGit, wholeNumber, type VerbSpec } from "../lib.js";
|
|
23
14
|
import { readPackageJson } from "../../shared/package-json.js";
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
scriptCommand,
|
|
27
|
-
testCommand,
|
|
28
|
-
} from "../../shared/package-manager.js";
|
|
15
|
+
import { COULD_NOT_RUN_EXIT_CODES, scriptCommand } from "../../shared/package-manager.js";
|
|
16
|
+
import { runGateUnderLock } from "./junit.js";
|
|
29
17
|
|
|
30
18
|
/** Exit code: neither `bkit:gate:changed` nor the --fallback gate is declared. */
|
|
31
19
|
const EXIT_NO_GATE = 3;
|
|
32
20
|
/** Exit code: the gate could not run (exit 126 / 127, or the package runner is missing). */
|
|
33
21
|
const EXIT_COULD_NOT_RUN = 4;
|
|
34
22
|
|
|
23
|
+
/** The NUL-separated paths `git <args>` prints in `top`; none when it fails. */
|
|
24
|
+
const gitPaths = (top: string, args: string[]) =>
|
|
25
|
+
(git(top, args) ?? "").split("\0").filter(Boolean);
|
|
26
|
+
|
|
35
27
|
/**
|
|
36
28
|
* Files changed since `base`, repo-relative and sorted: uncommitted (staged or not),
|
|
37
|
-
* untracked and not ignored, plus every file a commit after `base` touched.
|
|
38
|
-
*
|
|
29
|
+
* untracked and not ignored, plus every file a commit after `base` touched. Existing
|
|
30
|
+
* files only: a deleted file is a change `deletedFiles` lists, and `importersOf` turns
|
|
31
|
+
* into the files that still mention it.
|
|
39
32
|
*/
|
|
40
33
|
export function changedFiles(top: string, base: string): string[] {
|
|
41
|
-
const list = (args: string[]) => (git(top, args) ?? "").split("\0").filter(Boolean);
|
|
42
34
|
const all = new Set([
|
|
43
|
-
...
|
|
44
|
-
...
|
|
45
|
-
...
|
|
35
|
+
...gitPaths(top, ["diff", "--name-only", "--no-renames", "-z", "HEAD"]),
|
|
36
|
+
...gitPaths(top, ["ls-files", "--others", "--exclude-standard", "-z"]),
|
|
37
|
+
...gitPaths(top, ["diff", "--name-only", "--no-renames", "-z", `${base}...HEAD`]),
|
|
46
38
|
]);
|
|
47
39
|
return [...all].filter((f) => fs.existsSync(path.join(top, f))).sort();
|
|
48
40
|
}
|
|
49
41
|
|
|
50
|
-
/** Whether `dir/package.json` declares `name` as a non-empty script. */
|
|
51
|
-
function declares(dir: string, name: string): boolean {
|
|
52
|
-
const read = readPackageJson(dir);
|
|
53
|
-
const scripts = read.ok ? read.pkg.scripts : undefined;
|
|
54
|
-
if (typeof scripts !== "object" || scripts === null) return false;
|
|
55
|
-
const body = (scripts as Record<string, unknown>)[name];
|
|
56
|
-
return typeof body === "string" && body.trim() !== "";
|
|
57
|
-
}
|
|
58
|
-
|
|
59
42
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
43
|
+
* A commit holding the working tree as it is now: tracked files as edited, untracked files
|
|
44
|
+
* that are not ignored, deleted files gone; its parent is HEAD (none before the first
|
|
45
|
+
* commit). It is built in a copy of the index, so no ref, the index and the working tree
|
|
46
|
+
* stay as they were; no ref points at it, and `git gc` prunes it once unreachable objects
|
|
47
|
+
* expire. Null when git cannot build it.
|
|
62
48
|
*/
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
cwd: string,
|
|
66
|
-
log: (line: string) => void,
|
|
67
|
-
env: Record<string, string>,
|
|
68
|
-
): number {
|
|
69
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "bkit-tests-changed-"));
|
|
70
|
-
const file = path.join(dir, "out.log");
|
|
49
|
+
export function snapshotTree(top: string): string | null {
|
|
50
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "bkit-snapshot-"));
|
|
71
51
|
try {
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
52
|
+
const index = path.join(dir, "index");
|
|
53
|
+
const real = git(top, ["rev-parse", "--path-format=absolute", "--git-path", "index"]);
|
|
54
|
+
// The real index's stat data lets `git add -A` skip unchanged files instead of hashing them.
|
|
55
|
+
if (real !== null && fs.existsSync(real)) fs.copyFileSync(real, index);
|
|
56
|
+
const env = { GIT_INDEX_FILE: index };
|
|
57
|
+
if (!runGit(top, ["add", "-A"], env).ok) return null;
|
|
58
|
+
const tree = runGit(top, ["write-tree"], env);
|
|
59
|
+
if (!tree.ok) return null;
|
|
60
|
+
const head = git(top, ["rev-parse", "-q", "--verify", "HEAD^{commit}"]);
|
|
61
|
+
const commit = runGit(top, [
|
|
62
|
+
"-c",
|
|
63
|
+
"user.name=bkit",
|
|
64
|
+
"-c",
|
|
65
|
+
"user.email=bkit@localhost",
|
|
66
|
+
"commit-tree",
|
|
67
|
+
"--no-gpg-sign",
|
|
68
|
+
tree.stdout,
|
|
69
|
+
...(head === null ? [] : ["-p", head]),
|
|
70
|
+
"-m",
|
|
71
|
+
"bkit tested snapshot",
|
|
72
|
+
]);
|
|
73
|
+
return commit.ok ? commit.stdout : null;
|
|
91
74
|
} finally {
|
|
92
75
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
93
76
|
}
|
|
94
77
|
}
|
|
95
78
|
|
|
79
|
+
/** Whether `sha` names a commit the object store still holds. */
|
|
80
|
+
export const commitExists = (top: string, sha: string) =>
|
|
81
|
+
git(top, ["cat-file", "-e", `${sha}^{commit}`]) !== null;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The files that differ between snapshot `from` and the working tree now (`now`, else a
|
|
85
|
+
* fresh `snapshotTree`), sorted: `files` the ones that exist now, `deleted` the ones that do
|
|
86
|
+
* not. Null when `from` is gone from the object store or the tree cannot be snapshotted.
|
|
87
|
+
*/
|
|
88
|
+
export function changedBetween(
|
|
89
|
+
top: string,
|
|
90
|
+
from: string,
|
|
91
|
+
now: string | null = snapshotTree(top),
|
|
92
|
+
): { files: string[]; deleted: string[] } | null {
|
|
93
|
+
if (now === null || !commitExists(top, from)) return null;
|
|
94
|
+
const listed = runGit(top, ["diff", "--name-only", "--no-renames", "-z", from, now]);
|
|
95
|
+
if (!listed.ok) return null;
|
|
96
|
+
const all = listed.stdout.split("\0").filter(Boolean).sort();
|
|
97
|
+
const exists = (f: string) => fs.existsSync(path.join(top, f));
|
|
98
|
+
return { files: all.filter(exists), deleted: all.filter((f) => !exists(f)) };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Files removed since `base`, repo-relative and sorted: deleted in the working tree or
|
|
103
|
+
* the index, or by a commit after `base`, and missing from the working tree now.
|
|
104
|
+
*/
|
|
105
|
+
export function deletedFiles(top: string, base: string): string[] {
|
|
106
|
+
const all = new Set([
|
|
107
|
+
...gitPaths(top, ["diff", "--name-only", "--no-renames", "--diff-filter=D", "-z", "HEAD"]),
|
|
108
|
+
...gitPaths(top, [
|
|
109
|
+
"diff",
|
|
110
|
+
"--name-only",
|
|
111
|
+
"--no-renames",
|
|
112
|
+
"--diff-filter=D",
|
|
113
|
+
"-z",
|
|
114
|
+
`${base}...HEAD`,
|
|
115
|
+
]),
|
|
116
|
+
]);
|
|
117
|
+
return [...all].filter((f) => !fs.existsSync(path.join(top, f))).sort();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* For each deleted file, the files of the `base` tree that mention its name without the
|
|
122
|
+
* extension (`git grep -l -F`) and still exist, sorted; a file nothing mentions maps to
|
|
123
|
+
* `[]`. Null when a search fails (`base` names no tree, or the tree cannot be read):
|
|
124
|
+
* the caller cannot tell which tests the deletion touches.
|
|
125
|
+
*/
|
|
126
|
+
export function importersOf(
|
|
127
|
+
top: string,
|
|
128
|
+
base: string,
|
|
129
|
+
deleted: readonly string[],
|
|
130
|
+
): Map<string, string[]> | null {
|
|
131
|
+
const found = new Map<string, string[]>();
|
|
132
|
+
for (const file of deleted) {
|
|
133
|
+
const name = path.basename(file, path.extname(file));
|
|
134
|
+
const res = runGit(top, ["grep", "-l", "-z", "-F", "-e", name, base, "--"]);
|
|
135
|
+
// Exit 1 with nothing on stderr is "no match". Any stderr fails the search: git grep
|
|
136
|
+
// exits 0 when it found a match even though it could not read another blob.
|
|
137
|
+
if (res.stderr !== "") return null;
|
|
138
|
+
const prefix = `${base}:`;
|
|
139
|
+
found.set(
|
|
140
|
+
file,
|
|
141
|
+
res.stdout
|
|
142
|
+
.split("\0")
|
|
143
|
+
.filter(Boolean)
|
|
144
|
+
.map((hit) => (hit.startsWith(prefix) ? hit.slice(prefix.length) : hit))
|
|
145
|
+
.filter((hit) => !deleted.includes(hit) && fs.existsSync(path.join(top, hit)))
|
|
146
|
+
.sort(),
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return found;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Whether `dir/package.json` declares `name` as a non-empty script. */
|
|
153
|
+
export function declares(dir: string, name: string): boolean {
|
|
154
|
+
const read = readPackageJson(dir);
|
|
155
|
+
const scripts = read.ok ? read.pkg.scripts : undefined;
|
|
156
|
+
if (typeof scripts !== "object" || scripts === null) return false;
|
|
157
|
+
const body = (scripts as Record<string, unknown>)[name];
|
|
158
|
+
return typeof body === "string" && body.trim() !== "";
|
|
159
|
+
}
|
|
160
|
+
|
|
96
161
|
export const testsChangedVerb: VerbSpec = {
|
|
97
|
-
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.`,
|
|
162
|
+
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).`,
|
|
98
163
|
use: "by-hand",
|
|
99
164
|
flags: [
|
|
100
165
|
{
|
|
@@ -174,25 +239,24 @@ export const testsChangedVerb: VerbSpec = {
|
|
|
174
239
|
const scope = scriptCommand(gate).join(" ");
|
|
175
240
|
ctx.log(`running ${scope}`);
|
|
176
241
|
const who = `bkit tests changed ${gate}`;
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
(
|
|
182
|
-
lines.push(line);
|
|
183
|
-
ctx.log(line);
|
|
184
|
-
},
|
|
185
|
-
{
|
|
242
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "bkit-tests-changed-"));
|
|
243
|
+
const log = path.join(dir, "out.log");
|
|
244
|
+
let run;
|
|
245
|
+
try {
|
|
246
|
+
run = runGateUnderLock(argv, top, log, {
|
|
186
247
|
LOCAL_STACK_LOCK_WAIT_S: String(waitS),
|
|
187
248
|
LOCAL_STACK_LOCK_WHO: who,
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
249
|
+
});
|
|
250
|
+
for (const line of fs.readFileSync(log, "utf-8").split(/\r?\n/))
|
|
251
|
+
if (line !== "") ctx.log(line);
|
|
252
|
+
} finally {
|
|
253
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
254
|
+
}
|
|
255
|
+
const { exitCode, status: lockStatus, lock: lockExit } = run;
|
|
192
256
|
const couldNotRun = lockExit === "could-not-run" || COULD_NOT_RUN_EXIT_CODES.has(exitCode);
|
|
193
257
|
const lockWait = lockExit === "lock-wait";
|
|
194
258
|
const verdict = couldNotRun || lockWait ? null : exitCode === 0 ? "PASS" : "FAIL";
|
|
195
|
-
const lockHolder = lockWait ?
|
|
259
|
+
const lockHolder = lockWait ? (lockStatus?.holder ?? null) : null;
|
|
196
260
|
ctx.emit({ files, gate, scope, exitCode, verdict, lockHolder });
|
|
197
261
|
if (lockWait) return EXIT.AGENT_WAIT;
|
|
198
262
|
if (couldNotRun) return EXIT_COULD_NOT_RUN;
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
|
|
10
|
+
import { spawnSync } from "node:child_process";
|
|
11
|
+
import * as path from "node:path";
|
|
12
|
+
|
|
13
|
+
import { CommandError, EXIT, type VerbSpec } from "../lib.js";
|
|
14
|
+
import { getTemplatesRoot } from "../../shared/package-roots.js";
|
|
15
|
+
|
|
16
|
+
/** Exit code: the lock script could not read the queue or write the jump marker. */
|
|
17
|
+
export const EXIT_JUMP_FAILED = 3;
|
|
18
|
+
|
|
19
|
+
/** Run a queue subcommand of the template's lock script on the tests lock. */
|
|
20
|
+
function lockScript(args: string[]): { status: number; stdout: string; stderr: string } {
|
|
21
|
+
const script = path.join(getTemplatesRoot(), "scripts", "ci", "bkit-machine-lock.sh");
|
|
22
|
+
const res = spawnSync("bash", [script, args[0]!, "--lock", "tests", ...args.slice(1)], {
|
|
23
|
+
encoding: "utf-8",
|
|
24
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
25
|
+
});
|
|
26
|
+
if (res.error) {
|
|
27
|
+
throw new CommandError(EXIT_JUMP_FAILED, `cannot run ${script}: ${res.error.message}`);
|
|
28
|
+
}
|
|
29
|
+
return { status: res.status ?? 1, stdout: res.stdout, stderr: res.stderr.trim() };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const lines = (text: string) => text.split("\n").filter((line) => line !== "");
|
|
33
|
+
|
|
34
|
+
export const testsJumpVerb: VerbSpec = {
|
|
35
|
+
summary:
|
|
36
|
+
"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.",
|
|
37
|
+
use: "by-hand",
|
|
38
|
+
flags: [
|
|
39
|
+
{
|
|
40
|
+
name: "run",
|
|
41
|
+
type: "string",
|
|
42
|
+
positional: true,
|
|
43
|
+
required: true,
|
|
44
|
+
help: "the waiting run's name, as the waiting note prints it",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "checkout",
|
|
48
|
+
type: "string",
|
|
49
|
+
help: "the waiting run's checkout path, to pick one when several runs share the name",
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
output: {
|
|
53
|
+
run: "the run name moved to the front",
|
|
54
|
+
checkout: "the checkout path of the run moved",
|
|
55
|
+
},
|
|
56
|
+
exitCodes: {
|
|
57
|
+
[EXIT_JUMP_FAILED]: "the lock script could not read the queue or write the jump marker",
|
|
58
|
+
},
|
|
59
|
+
run: (ctx) => {
|
|
60
|
+
const run = String(ctx.flags.run);
|
|
61
|
+
const wanted = typeof ctx.flags.checkout === "string" ? [ctx.flags.checkout] : [];
|
|
62
|
+
const res = lockScript(["jump", run, ...wanted]);
|
|
63
|
+
if (res.status === 1) {
|
|
64
|
+
const waiting = lockScript(["queue"]);
|
|
65
|
+
const queued = waiting.status === 0 ? lines(waiting.stdout) : [];
|
|
66
|
+
throw new CommandError(
|
|
67
|
+
EXIT.NO,
|
|
68
|
+
`no run named ${run} waits for tests` +
|
|
69
|
+
(queued.length > 0
|
|
70
|
+
? `\nwaiting now:\n${queued.map((line) => ` ${line}`).join("\n")}`
|
|
71
|
+
: ""),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
if (res.status === 3) {
|
|
75
|
+
throw new CommandError(
|
|
76
|
+
EXIT.NO,
|
|
77
|
+
`several runs named ${run} wait for tests:\n${lines(res.stdout)
|
|
78
|
+
.map((line) => ` ${line}`)
|
|
79
|
+
.join("\n")}\npass --checkout <path> to pick one`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (res.status !== 0) {
|
|
83
|
+
throw new CommandError(
|
|
84
|
+
EXIT_JUMP_FAILED,
|
|
85
|
+
res.stderr || `the lock script's jump exited ${res.status}`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const line = lines(res.stdout)[0] ?? "";
|
|
89
|
+
ctx.log(`${run} moves to the front of the tests line`);
|
|
90
|
+
ctx.emit({ run, checkout: line.slice(`${run} — `.length) });
|
|
91
|
+
return EXIT.OK;
|
|
92
|
+
},
|
|
93
|
+
};
|