@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
|
@@ -16,10 +16,12 @@ import * as path from "node:path";
|
|
|
16
16
|
import { parseJson } from "../../shared/json.js";
|
|
17
17
|
import { CommandError, EXIT, git, runGit } from "../lib.js";
|
|
18
18
|
import { EXIT_DIFF_FAILED, fetchRemoteRef } from "./branches.js";
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
19
|
+
import { decisionHeader, parseDecisionItems } from "./open-decision.js";
|
|
20
|
+
const DIFF_BASE = "origin/dev";
|
|
21
|
+
import { derivedTestMatrix, NO_MARKERS_REASON, parsePlanBlocks, testTier, } from "./plan-blocks.js";
|
|
22
|
+
import { positiveInt, readStatusRows, str } from "./status.js";
|
|
23
|
+
import { writeStepRow } from "./steps.js";
|
|
24
|
+
import { doneTasks, readTestFirst, redEntries, redKey, sameTestName, TAKEOVER_STEP, } from "./tests.js";
|
|
23
25
|
/** A task's heading line: the box and the number the tick addresses. */
|
|
24
26
|
const TASK_BOX = /^(\s*)- \[([ xX])\] \*\*TASK (\d+):\*\*/;
|
|
25
27
|
/** A `tests green` report's gap line: `- Task {N} \`{kind}\` — …`. */
|
|
@@ -70,18 +72,77 @@ function taskNumbers(values, flag) {
|
|
|
70
72
|
}
|
|
71
73
|
/**
|
|
72
74
|
* The task numbers a `bkit tests green` report gaps: the `- Task {N} \`{kind}\`` lines of
|
|
73
|
-
* its `## Gaps` section, or the `gaps` array of its `--json` payload.
|
|
75
|
+
* its `## Gaps` section, or the `gaps` array of its `--json` payload. Null when the report
|
|
76
|
+
* holds neither: a report with no Gaps section says nothing about which tasks are green.
|
|
74
77
|
*/
|
|
75
78
|
export function gappedTasks(text) {
|
|
79
|
+
const json = jsonGaps(text);
|
|
80
|
+
if (json !== null)
|
|
81
|
+
return json
|
|
82
|
+
.map((g) => (typeof g === "object" && g !== null ? g.task : null))
|
|
83
|
+
.filter((t) => typeof t === "number");
|
|
84
|
+
const section = gapsSection(text);
|
|
85
|
+
return section === null ? null : [...section.matchAll(REPORT_GAP)].map((m) => Number(m[1]));
|
|
86
|
+
}
|
|
87
|
+
/** The `gaps` array of a `--json` report, else null. */
|
|
88
|
+
function jsonGaps(text) {
|
|
76
89
|
const json = parseJson(text);
|
|
77
|
-
if (json.ok
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
if (!json.ok || typeof json.value !== "object" || json.value === null)
|
|
91
|
+
return null;
|
|
92
|
+
const gaps = json.value.gaps;
|
|
93
|
+
return Array.isArray(gaps) ? gaps : null;
|
|
94
|
+
}
|
|
95
|
+
/** A text report's `## Gaps` section, up to the next `## ` heading; null when it has none. */
|
|
96
|
+
function gapsSection(text) {
|
|
97
|
+
const start = text.search(/^## Gaps\b/m);
|
|
98
|
+
if (start < 0)
|
|
99
|
+
return null;
|
|
100
|
+
const rest = text.slice(start).replace(/^## Gaps[^\n]*\n?/, "");
|
|
101
|
+
const end = rest.search(/^## /m);
|
|
102
|
+
return end < 0 ? rest : rest.slice(0, end);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Why a text report's Gaps section cannot be trusted: its header's `Gaps: N` counts more gap
|
|
106
|
+
* lines (`- Task {N}` or `- Plan`) than the section holds, so a line inside a gap's detail
|
|
107
|
+
* cut the section short. Null when the counts agree, or for a JSON report or one with no
|
|
108
|
+
* `Gaps:` header.
|
|
109
|
+
*/
|
|
110
|
+
export function gapsShortfall(text) {
|
|
111
|
+
if (jsonGaps(text) !== null)
|
|
112
|
+
return null;
|
|
113
|
+
const header = text.split(/\r?\n[ \t]*\r?\n/, 1)[0] ?? "";
|
|
114
|
+
const want = /^Gaps:[ \t]*([0-9]+)[ \t]*$/m.exec(header)?.[1];
|
|
115
|
+
const section = gapsSection(text);
|
|
116
|
+
if (want === undefined || section === null)
|
|
117
|
+
return null;
|
|
118
|
+
const read = [...section.matchAll(/^-\s+(?:Task\s+\d+|Plan)\s+`/gm)].length;
|
|
119
|
+
return read < Number(want)
|
|
120
|
+
? `the header says Gaps: ${want} but the Gaps section holds ${read} gap line${read === 1 ? "" : "s"}`
|
|
121
|
+
: null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The first header fact that stops `--decision` from ticking, or null: `From` is `verify` or
|
|
125
|
+
* `holistic`, no `Gate: FAIL` header, and a verify file's `Group` is `group`. Headers count
|
|
126
|
+
* only in the header block (`decisionHeader`).
|
|
127
|
+
*/
|
|
128
|
+
function decisionProblem(text, group) {
|
|
129
|
+
const header = decisionHeader(text);
|
|
130
|
+
const from = header.From;
|
|
131
|
+
if (from === undefined)
|
|
132
|
+
return "no From header";
|
|
133
|
+
if (from !== "verify" && from !== "holistic")
|
|
134
|
+
return `From is "${from}", not verify or holistic`;
|
|
135
|
+
if (/^FAIL\b/.test(header.Gate ?? ""))
|
|
136
|
+
return "Gate: FAIL header: the gate is red";
|
|
137
|
+
if (from === "holistic")
|
|
138
|
+
return null;
|
|
139
|
+
if (header.Group === undefined)
|
|
140
|
+
return "no Group header";
|
|
141
|
+
if (group === undefined)
|
|
142
|
+
return "missing required flag --group for a From: verify file";
|
|
143
|
+
if (header.Group !== String(group))
|
|
144
|
+
return `Group is "${header.Group}", not group ${group}`;
|
|
145
|
+
return null;
|
|
85
146
|
}
|
|
86
147
|
/** `task`'s heading line inside its block: its box and number, or null when the block holds none. */
|
|
87
148
|
function headBox(lines, task) {
|
|
@@ -119,12 +180,136 @@ export function needleOf(symbol) {
|
|
|
119
180
|
const splitPaths = (stdout) => stdout.split("\0").filter(Boolean);
|
|
120
181
|
/** A workflow run log: another feature's record, never code a plan task reads or changes. */
|
|
121
182
|
const RUN_LOG = /^docs\/plans\/[^/]+\/logs\//;
|
|
183
|
+
/** The status file's `build-takeover` rows, in file order; none when the file does not exist. */
|
|
184
|
+
function takeoverRows(statusPath) {
|
|
185
|
+
if (!fs.existsSync(statusPath))
|
|
186
|
+
return [];
|
|
187
|
+
return readStatusRows(statusPath)
|
|
188
|
+
.filter((r) => r.type === "step-done" &&
|
|
189
|
+
r.workflow === "build" &&
|
|
190
|
+
r.step === TAKEOVER_STEP &&
|
|
191
|
+
typeof r.task === "number" &&
|
|
192
|
+
typeof r.test === "string" &&
|
|
193
|
+
typeof r.name === "string")
|
|
194
|
+
.map((r) => ({
|
|
195
|
+
task: r.task,
|
|
196
|
+
from: typeof r.from === "number" ? r.from : 0,
|
|
197
|
+
test: r.test,
|
|
198
|
+
name: r.name,
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The group of takeover tasks whose tests half has not run: the plan's tasks a
|
|
203
|
+
* `build-takeover` row names, grouped, the latest group holding a planned test with no
|
|
204
|
+
* `tests red` entry. Null when every takeover group's tests are recorded.
|
|
205
|
+
*/
|
|
206
|
+
function pendingTakeovers(text, statusPath) {
|
|
207
|
+
const named = new Set(takeoverRows(statusPath).map((r) => r.task));
|
|
208
|
+
const tasks = parsePlanBlocks(text).tasks.filter((t) => named.has(t.task));
|
|
209
|
+
const groups = [...new Set(tasks.map((t) => t.group))].sort((a, b) => b - a);
|
|
210
|
+
for (const group of groups) {
|
|
211
|
+
const reds = redEntries(statusPath, "build", group);
|
|
212
|
+
const open = readTestFirst(text, group).some((s) => named.has(s.task) &&
|
|
213
|
+
s.kind === "test" &&
|
|
214
|
+
s.tests.some((t) => !reds.has(redKey(s.task, t.test, t.name))));
|
|
215
|
+
if (open)
|
|
216
|
+
return { group, tasks: tasks.filter((t) => t.group === group).map((t) => t.task) };
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
/** A plan line's text: one line, no backticks or pipes, so it never breaks a field or a table cell. */
|
|
221
|
+
const planWords = (s) => s.replace(/\s+/g, " ").replace(/[`|]/g, "'").trim();
|
|
222
|
+
/** The lines of one pure takeover task block. */
|
|
223
|
+
function takeoverTask(n, t, dependsOn) {
|
|
224
|
+
const until = dependsOn === undefined
|
|
225
|
+
? "the change that contradicts it exists"
|
|
226
|
+
: `TASK ${dependsOn}'s code exists`;
|
|
227
|
+
return [
|
|
228
|
+
`<!-- bkit:task ${n} start -->`,
|
|
229
|
+
"",
|
|
230
|
+
`- [ ] **TASK ${n}:** Take over \`${t.name}\` from TASK ${t.from}`,
|
|
231
|
+
...(dependsOn === undefined ? [] : [` - **DEPENDS ON:** ${dependsOn}`]),
|
|
232
|
+
` - **DONE WHEN:** \`${t.test}\` \`${t.name}\` passes`,
|
|
233
|
+
" - **TEST FIRST:**",
|
|
234
|
+
` - \`${t.test}\` \`${t.name}\` fails until ${until}: ${planWords(t.reason)}`,
|
|
235
|
+
"",
|
|
236
|
+
`<!-- bkit:task ${n} end -->`,
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The plan with takeover task `n` added: into the last group when it is a takeover group
|
|
241
|
+
* whose tests half has not run (`into`), else as a new last group after the last group's
|
|
242
|
+
* end marker; plus a Derived Test Matrix row when the plan has a matrix.
|
|
243
|
+
*/
|
|
244
|
+
function withTakeoverTask(text, task, n, group, into, row) {
|
|
245
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
246
|
+
const lines = text.split(/\r?\n/);
|
|
247
|
+
const matrix = derivedTestMatrix(text);
|
|
248
|
+
if (matrix !== null) {
|
|
249
|
+
const at = matrix.rows.at(-1)?.number ?? matrix.line + 1;
|
|
250
|
+
lines.splice(at, 0, `| Take over ${planWords(row.name)} from TASK ${row.from} | ${testTier(row.test)} | \`${row.test}\` | ${n} |`);
|
|
251
|
+
}
|
|
252
|
+
const endMarker = (g) => lines.findIndex((l) => l.trim() === `<!-- bkit:group ${g} end -->`);
|
|
253
|
+
if (into) {
|
|
254
|
+
lines.splice(endMarker(group), 0, ...task, "");
|
|
255
|
+
return lines.join(eol);
|
|
256
|
+
}
|
|
257
|
+
const last = Math.max(...parsePlanBlocks(text).groups.map((g) => g.group));
|
|
258
|
+
lines.splice(endMarker(last) + 1, 0, "", `<!-- bkit:group ${group} start -->`, "", `### TASK GROUP ${group}: Planned tests the build took over`, "", ...task, "", `<!-- bkit:group ${group} end -->`);
|
|
259
|
+
return lines.join(eol);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Adds one pure takeover task per entry to the plan at `planFile`, plus its Derived Test
|
|
263
|
+
* Matrix row and its `build-takeover` row in `statusPath`. Safe to repeat: an open takeover
|
|
264
|
+
* task whose `TEST FIRST` already names the entry's file and name is reused, and only a
|
|
265
|
+
* missing row is written, so a second run or a run stopped between the two writes leaves one
|
|
266
|
+
* task and one row. The task goes into the plan's last group while that group is a takeover
|
|
267
|
+
* group whose tests half has not run, else into a new last group. Returns the takeover task
|
|
268
|
+
* number per entry, in entry order.
|
|
269
|
+
*/
|
|
270
|
+
export function addTakeoverTasks(cwd, planFile, statusPath, entries, log) {
|
|
271
|
+
const out = [];
|
|
272
|
+
for (const e of entries) {
|
|
273
|
+
const test = path.posix.normalize(e.test);
|
|
274
|
+
const text = fs.readFileSync(planFile, "utf-8");
|
|
275
|
+
const plan = parsePlanBlocks(text);
|
|
276
|
+
const open = plan.tasks.find((t) => !t.done &&
|
|
277
|
+
t.title.startsWith("Take over ") &&
|
|
278
|
+
(t.testFirst?.tests ?? []).some((x) => path.posix.normalize(x.test) === test && sameTestName(x.name, e.name)));
|
|
279
|
+
let n;
|
|
280
|
+
if (open !== undefined) {
|
|
281
|
+
n = open.task;
|
|
282
|
+
log(`TASK ${n} already takes over "${e.name}" in ${test}`);
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
n = Math.max(...plan.tasks.map((t) => t.task)) + 1;
|
|
286
|
+
const lastGroup = Math.max(...plan.groups.map((g) => g.group));
|
|
287
|
+
const pending = pendingTakeovers(text, statusPath);
|
|
288
|
+
const into = pending !== null && pending.group === lastGroup;
|
|
289
|
+
const group = into ? lastGroup : lastGroup + 1;
|
|
290
|
+
const dependsOn = e.task !== null && plan.tasks.some((t) => t.task === e.task) ? e.task : undefined;
|
|
291
|
+
fs.writeFileSync(planFile, withTakeoverTask(text, takeoverTask(n, { test, name: e.name, from: e.from, reason: e.reason }, dependsOn), n, group, into, { name: e.name, test, from: e.from }));
|
|
292
|
+
log(`added TASK ${n} in group ${group}: takes over "${e.name}" in ${test} from TASK ${e.from}`);
|
|
293
|
+
}
|
|
294
|
+
if (!takeoverRows(statusPath).some((r) => r.task === n))
|
|
295
|
+
writeStepRow(cwd, {
|
|
296
|
+
file: statusPath,
|
|
297
|
+
workflow: "build",
|
|
298
|
+
step: TAKEOVER_STEP,
|
|
299
|
+
artifacts: [path.relative(cwd, planFile)],
|
|
300
|
+
extras: { task: n, from: e.from, test, name: e.name, reason: e.reason },
|
|
301
|
+
commit: "none",
|
|
302
|
+
}, log);
|
|
303
|
+
out.push(n);
|
|
304
|
+
}
|
|
305
|
+
return out;
|
|
306
|
+
}
|
|
122
307
|
export const tasksCommand = {
|
|
123
308
|
noun: "tasks",
|
|
124
309
|
summary: "Tick a plan's task boxes, from the tasks a verify judged satisfied.",
|
|
125
310
|
verbs: {
|
|
126
311
|
tick: {
|
|
127
|
-
summary: "Tick the named tasks of one task group, less those a `tests green` report gaps; exit 0 ticked (including none), 1 a plan with no task blocks, 2 a bad flag value or plan.",
|
|
312
|
+
summary: "Tick the named tasks of one task group, less those a `tests green` report gaps; exit 0 ticked (including none), 1 a plan with no task blocks, 2 a bad flag value or plan, a `--green` report with no Gaps section or fewer gap lines than its `Gaps:` header, or a `--decision` file that is not a verify or holistic pause of this group with a green gate.",
|
|
128
313
|
use: "workflow",
|
|
129
314
|
flags: [
|
|
130
315
|
{
|
|
@@ -136,40 +321,59 @@ export const tasksCommand = {
|
|
|
136
321
|
{
|
|
137
322
|
name: "group",
|
|
138
323
|
type: "string",
|
|
139
|
-
required:
|
|
140
|
-
help: "the task group whose tasks are candidates (positive integer)",
|
|
324
|
+
help: "the task group whose tasks are candidates (positive integer); required, except with a `From: holistic` --decision alone, whose accepted tasks are ticked in their own groups",
|
|
141
325
|
},
|
|
142
326
|
{
|
|
143
327
|
name: "tasks",
|
|
144
328
|
type: "string",
|
|
145
329
|
repeatable: true,
|
|
146
|
-
help: "the task numbers to tick, comma-separated or once per number; `none` ticks nothing (one of --tasks / --green)",
|
|
330
|
+
help: "the task numbers to tick, comma-separated or once per number; `none` ticks nothing (one of --tasks / --green / --decision)",
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
name: "decision",
|
|
334
|
+
type: "string",
|
|
335
|
+
help: "a decision file with a `From: verify` (whose `Group` is --group) or `From: holistic` header and no `Gate: FAIL` header: the task each item answered `Accept` or `Accept (assumed)` names at the start of its title (`Task {N}`) is ticked; `Fix now` and undecided items tick nothing (one of --tasks / --green / --decision)",
|
|
147
336
|
},
|
|
148
337
|
{
|
|
149
338
|
name: "green",
|
|
150
339
|
type: "string",
|
|
151
|
-
help: "a `bkit tests green` report: every task it gaps stays unticked (one of --tasks / --green)",
|
|
340
|
+
help: "a `bkit tests green` report: every task it gaps stays unticked (one of --tasks / --green / --decision)",
|
|
152
341
|
},
|
|
153
342
|
],
|
|
154
343
|
output: {
|
|
155
344
|
plan: "the plan file ticked, as given",
|
|
156
|
-
group: "the group whose tasks were candidates",
|
|
345
|
+
group: "the group whose tasks were candidates; null for a holistic --decision without --group",
|
|
157
346
|
ticked: "[task numbers] ticked by this call; a task already ticked is not repeated",
|
|
158
347
|
},
|
|
159
348
|
run: (ctx) => {
|
|
160
349
|
const planArg = String(ctx.flags.plan);
|
|
161
350
|
const group = positiveInt(ctx.flags.group, "group");
|
|
162
|
-
if (group === undefined)
|
|
163
|
-
throw new CommandError(EXIT.USAGE, "missing required flag --group");
|
|
164
351
|
const tasksFlag = ctx.flags.tasks;
|
|
165
352
|
const greenArg = str(ctx.flags.green);
|
|
166
353
|
if (greenArg === "")
|
|
167
354
|
throw new CommandError(EXIT.USAGE, "--green must be non-empty");
|
|
168
|
-
|
|
169
|
-
|
|
355
|
+
const decisionArg = str(ctx.flags.decision);
|
|
356
|
+
if (decisionArg === "")
|
|
357
|
+
throw new CommandError(EXIT.USAGE, "--decision must be non-empty");
|
|
358
|
+
if (tasksFlag === undefined && greenArg === undefined && decisionArg === undefined)
|
|
359
|
+
throw new CommandError(EXIT.USAGE, "give one of --tasks, --green and --decision");
|
|
360
|
+
let decisionText;
|
|
361
|
+
if (decisionArg !== undefined) {
|
|
362
|
+
const decisionFile = path.resolve(ctx.cwd, decisionArg);
|
|
363
|
+
if (fs.statSync(decisionFile, { throwIfNoEntry: false })?.isFile() !== true)
|
|
364
|
+
throw new CommandError(EXIT.USAGE, `--decision ${decisionArg} does not exist`);
|
|
365
|
+
decisionText = fs.readFileSync(decisionFile, "utf-8");
|
|
366
|
+
}
|
|
367
|
+
// Only a holistic decision alone may leave out --group: its accepted tasks span groups.
|
|
368
|
+
const holisticOnly = decisionText !== undefined &&
|
|
369
|
+
decisionHeader(decisionText).From === "holistic" &&
|
|
370
|
+
tasksFlag === undefined &&
|
|
371
|
+
greenArg === undefined;
|
|
372
|
+
if (group === undefined && !holisticOnly)
|
|
373
|
+
throw new CommandError(EXIT.USAGE, "missing required flag --group");
|
|
170
374
|
const plan = readPlan(ctx.cwd, planArg);
|
|
171
|
-
const candidates = groupTasks(plan, planArg, group);
|
|
172
|
-
|
|
375
|
+
const candidates = group === undefined ? plan.tasks : groupTasks(plan, planArg, group);
|
|
376
|
+
let named = tasksFlag === undefined ? undefined : taskNumbers(tasksFlag, "tasks");
|
|
173
377
|
for (const n of named ?? []) {
|
|
174
378
|
const task = plan.tasks.find((t) => t.task === n);
|
|
175
379
|
if (task === undefined)
|
|
@@ -177,12 +381,34 @@ export const tasksCommand = {
|
|
|
177
381
|
if (task.group !== group)
|
|
178
382
|
throw new CommandError(EXIT.USAGE, `TASK ${n} is in group ${task.group}, not group ${group}`);
|
|
179
383
|
}
|
|
384
|
+
if (decisionText !== undefined) {
|
|
385
|
+
const problem = decisionProblem(decisionText, group);
|
|
386
|
+
if (problem !== null)
|
|
387
|
+
throw new CommandError(EXIT.USAGE, `--decision ${decisionArg}: ${problem}, so nothing is ticked`);
|
|
388
|
+
// A title names its task only at its start (`Task {N}`): a gap that mentions a task elsewhere ticks nothing.
|
|
389
|
+
const accepted = parseDecisionItems(decisionText)
|
|
390
|
+
.filter((it) => it.decision !== null && /^Accept\b/.test(it.decision))
|
|
391
|
+
.map((it) => /^task\s+(\d+)\b/i.exec(it.title.trim()))
|
|
392
|
+
.filter((m) => m !== null)
|
|
393
|
+
.map((m) => Number(m[1]));
|
|
394
|
+
named = [
|
|
395
|
+
...(named ?? []),
|
|
396
|
+
...accepted.filter((n) => candidates.some((t) => t.task === n)),
|
|
397
|
+
];
|
|
398
|
+
}
|
|
180
399
|
const gapped = new Set();
|
|
181
400
|
if (greenArg !== undefined) {
|
|
182
401
|
const greenFile = path.resolve(ctx.cwd, greenArg);
|
|
183
402
|
if (fs.statSync(greenFile, { throwIfNoEntry: false })?.isFile() !== true)
|
|
184
403
|
throw new CommandError(EXIT.USAGE, `--green ${greenArg} does not exist`);
|
|
185
|
-
|
|
404
|
+
const greenText = fs.readFileSync(greenFile, "utf-8");
|
|
405
|
+
const gaps = gappedTasks(greenText);
|
|
406
|
+
if (gaps === null)
|
|
407
|
+
throw new CommandError(EXIT.USAGE, `--green ${greenArg}: report has no Gaps section, so nothing is ticked`);
|
|
408
|
+
const shortfall = gapsShortfall(greenText);
|
|
409
|
+
if (shortfall !== null)
|
|
410
|
+
throw new CommandError(EXIT.USAGE, `--green ${greenArg}: ${shortfall}, so nothing is ticked`);
|
|
411
|
+
for (const n of gaps)
|
|
186
412
|
gapped.add(n);
|
|
187
413
|
}
|
|
188
414
|
const wanted = named ?? candidates.map((t) => t.task);
|
|
@@ -207,7 +433,7 @@ export const tasksCommand = {
|
|
|
207
433
|
ctx.log(`ticked TASK ${n}`);
|
|
208
434
|
ctx.emit({
|
|
209
435
|
plan: planArg,
|
|
210
|
-
group,
|
|
436
|
+
group: group ?? null,
|
|
211
437
|
ticked,
|
|
212
438
|
});
|
|
213
439
|
return EXIT.OK;
|
|
@@ -262,6 +488,47 @@ export const tasksCommand = {
|
|
|
262
488
|
return EXIT.OK;
|
|
263
489
|
},
|
|
264
490
|
},
|
|
491
|
+
takeover: {
|
|
492
|
+
summary: "Print the takeover group whose tests half has not run: the plan's takeover tasks (added by `steps finish` on a code step that contradicts a ticked task's planned test, each named by a build-takeover row) in the latest group holding a planned test with no `tests red` entry yet, or null. Writes nothing. Exit 0 (including nothing pending), 1 a plan with no task blocks, 2 a bad flag value or plan.",
|
|
493
|
+
use: "workflow",
|
|
494
|
+
flags: [
|
|
495
|
+
{
|
|
496
|
+
name: "plan",
|
|
497
|
+
type: "string",
|
|
498
|
+
required: true,
|
|
499
|
+
help: "plan file holding the task blocks",
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
name: "file",
|
|
503
|
+
type: "string",
|
|
504
|
+
required: true,
|
|
505
|
+
help: "the run's status.jsonl: its build-takeover and tests red rows are read",
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
name: "pending",
|
|
509
|
+
type: "boolean",
|
|
510
|
+
help: "print the takeover group whose tests half has not run, or null; required, since the verb only reads",
|
|
511
|
+
},
|
|
512
|
+
],
|
|
513
|
+
output: {
|
|
514
|
+
plan: "the plan file, as given",
|
|
515
|
+
pending: "{group, tasks} the takeover group whose tests have no tests red entry yet, else null",
|
|
516
|
+
},
|
|
517
|
+
run: (ctx) => {
|
|
518
|
+
const planArg = String(ctx.flags.plan);
|
|
519
|
+
const statusArg = String(ctx.flags.file);
|
|
520
|
+
if (statusArg === "")
|
|
521
|
+
throw new CommandError(EXIT.USAGE, "--file must be non-empty");
|
|
522
|
+
if (ctx.flags.pending !== true)
|
|
523
|
+
throw new CommandError(EXIT.USAGE, "tasks takeover only reads, with --pending: steps finish adds the takeover tasks");
|
|
524
|
+
const plan = readPlan(ctx.cwd, planArg);
|
|
525
|
+
const pending = pendingTakeovers(plan.text, path.resolve(ctx.cwd, statusArg));
|
|
526
|
+
if (pending !== null)
|
|
527
|
+
ctx.log(`takeover group ${pending.group} has tests to record: TASK ${pending.tasks.join(", ")}`);
|
|
528
|
+
ctx.emit({ plan: planArg, pending });
|
|
529
|
+
return EXIT.OK;
|
|
530
|
+
},
|
|
531
|
+
},
|
|
265
532
|
currency: {
|
|
266
533
|
summary: "Print each task whose CREATE / READ / UPDATE / DELETE paths or symbols moved between --base and --against, with its matched paths, needles and diff hunks (run logs under docs/plans/*/logs/ are left out); exit 0 (including no match), 1 a plan with no task blocks, 2 a bad plan.",
|
|
267
534
|
use: "by-hand",
|
|
@@ -0,0 +1,266 @@
|
|
|
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
|
+
import * as fs from "node:fs";
|
|
12
|
+
import * as os from "node:os";
|
|
13
|
+
import * as path from "node:path";
|
|
14
|
+
import { BKIT_TEST_FILE_SCRIPT } from "../../install/manifest.js";
|
|
15
|
+
import { parseJson } from "../../shared/json.js";
|
|
16
|
+
import { readBkitConfig } from "../../shared/settings.js";
|
|
17
|
+
import { readPackageJson } from "../../shared/package-json.js";
|
|
18
|
+
import { withCleanup } from "../ci/ci.js";
|
|
19
|
+
import { dropLandTree } from "../land.js";
|
|
20
|
+
import { CommandError, EXIT, git, mainCheckoutRoot, runGh, runGit } from "../lib.js";
|
|
21
|
+
import { reportFailures, runTestFile } from "./junit.js";
|
|
22
|
+
import { latestRuntimeRow } from "./runtime.js";
|
|
23
|
+
import { resolveOwnerRepo } from "./repo.js";
|
|
24
|
+
import { copyListed, devBase, install } from "./worktrees.js";
|
|
25
|
+
/** A repo-relative path with no `..` segment and no root, in `/` form; else null. */
|
|
26
|
+
function safeRelative(p) {
|
|
27
|
+
const norm = path.posix.normalize(p.replace(/\\/g, "/"));
|
|
28
|
+
if (norm === "." || norm.startsWith("/") || /^[a-z]:/i.test(norm))
|
|
29
|
+
return null;
|
|
30
|
+
if (norm.split("/").includes(".."))
|
|
31
|
+
return null;
|
|
32
|
+
return norm;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The tracked repo file a failing case ran in: its `file` attribute when that is a tracked
|
|
36
|
+
* repo-relative path, else its `classname` when that is one, else the one tracked file whose
|
|
37
|
+
* basename is the `classname`'s. Null when none applies or two match. An untracked, absolute
|
|
38
|
+
* or `..` path is never returned.
|
|
39
|
+
*/
|
|
40
|
+
export function caseFile(c, tracked) {
|
|
41
|
+
const set = new Set(tracked);
|
|
42
|
+
for (const candidate of [c.file, c.classname]) {
|
|
43
|
+
if (candidate === null)
|
|
44
|
+
continue;
|
|
45
|
+
const rel = safeRelative(candidate);
|
|
46
|
+
if (rel !== null && set.has(rel))
|
|
47
|
+
return rel;
|
|
48
|
+
}
|
|
49
|
+
if (c.classname === null)
|
|
50
|
+
return null;
|
|
51
|
+
const rel = safeRelative(c.classname);
|
|
52
|
+
if (rel === null)
|
|
53
|
+
return null;
|
|
54
|
+
const base = path.posix.basename(rel);
|
|
55
|
+
const hits = tracked.filter((t) => path.posix.basename(t) === base);
|
|
56
|
+
return hits.length === 1 ? hits[0] : null;
|
|
57
|
+
}
|
|
58
|
+
/** Fold per-case base outcomes into one verdict with counts. */
|
|
59
|
+
export function baseVerdict(cases) {
|
|
60
|
+
const failing = cases.length;
|
|
61
|
+
const baseRed = cases.filter((c) => c.atBase === "red").length;
|
|
62
|
+
const branch = cases.filter((c) => c.atBase === "pass" || c.atBase === "absent").length;
|
|
63
|
+
const undetermined = failing - baseRed - branch;
|
|
64
|
+
const counts = { failing, baseRed, branch, undetermined };
|
|
65
|
+
if (failing === 0)
|
|
66
|
+
return { verdict: "unknown", reason: "gate red with no failing test case", ...counts };
|
|
67
|
+
if (baseRed === failing)
|
|
68
|
+
return { verdict: "all", reason: null, ...counts };
|
|
69
|
+
if (baseRed === 0 && undetermined === 0)
|
|
70
|
+
return { verdict: "none", reason: null, ...counts };
|
|
71
|
+
if (baseRed === 0)
|
|
72
|
+
return {
|
|
73
|
+
verdict: "unknown",
|
|
74
|
+
reason: `${undetermined} case(s) with no resolvable result at the base commit`,
|
|
75
|
+
...counts,
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
verdict: "some",
|
|
79
|
+
reason: undetermined > 0
|
|
80
|
+
? `${undetermined} case(s) with no resolvable result at the base commit`
|
|
81
|
+
: null,
|
|
82
|
+
...counts,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const str = (v) => (typeof v === "string" && v !== "" ? v : undefined);
|
|
86
|
+
function readRows(file) {
|
|
87
|
+
if (!fs.existsSync(file))
|
|
88
|
+
throw new CommandError(EXIT.USAGE, `--file ${file} does not exist`);
|
|
89
|
+
const rows = [];
|
|
90
|
+
for (const line of fs.readFileSync(file, "utf-8").split("\n")) {
|
|
91
|
+
if (line.trim() === "")
|
|
92
|
+
continue;
|
|
93
|
+
const read = parseJson(line);
|
|
94
|
+
// A malformed line is not a row.
|
|
95
|
+
if (read.ok && typeof read.value === "object" && read.value !== null)
|
|
96
|
+
rows.push(read.value);
|
|
97
|
+
}
|
|
98
|
+
return rows;
|
|
99
|
+
}
|
|
100
|
+
export const testsBaseVerb = {
|
|
101
|
+
summary: "Check whether the failing tests of a red gate also fail on the commit the branch started from; exit 0 for every verdict.",
|
|
102
|
+
use: "workflow",
|
|
103
|
+
flags: [
|
|
104
|
+
{ name: "log", type: "string", help: "the gate log; its JUnit reports are in {log}.reports" },
|
|
105
|
+
{ name: "file", type: "string", help: "the run's status.jsonl" },
|
|
106
|
+
{ name: "workflow", type: "string", help: "the workflow whose runtime row sets `adopt`" },
|
|
107
|
+
{ name: "out", type: "string", help: "also write the output JSON to this path" },
|
|
108
|
+
],
|
|
109
|
+
output: {
|
|
110
|
+
verdict: "all / some / none / unknown",
|
|
111
|
+
reason: "why the verdict is unknown, or which cases could not be checked for some; else null",
|
|
112
|
+
base: "the base commit sha, or null",
|
|
113
|
+
source: "ci (a passing push-event CI run at the base sha), local (a run at the base commit), or null",
|
|
114
|
+
failing: "the gate's failing test cases",
|
|
115
|
+
baseRed: "of those, how many also fail at the base commit",
|
|
116
|
+
branch: "of those, how many pass or do not exist at the base commit",
|
|
117
|
+
undetermined: "of those, how many could not be checked",
|
|
118
|
+
adopt: "true when the run has no worktrees (runtimeWorktrees false)",
|
|
119
|
+
cases: "each failing case: {name, file, atBase: red / pass / absent / unknown}",
|
|
120
|
+
},
|
|
121
|
+
run: async (ctx) => {
|
|
122
|
+
const log = str(ctx.flags.log);
|
|
123
|
+
const file = str(ctx.flags.file);
|
|
124
|
+
const workflow = str(ctx.flags.workflow);
|
|
125
|
+
for (const [flag, value] of [
|
|
126
|
+
["log", log],
|
|
127
|
+
["file", file],
|
|
128
|
+
["workflow", workflow],
|
|
129
|
+
])
|
|
130
|
+
if (value === undefined)
|
|
131
|
+
throw new CommandError(EXIT.USAGE, `--${flag} is required`);
|
|
132
|
+
const out = str(ctx.flags.out);
|
|
133
|
+
const top = git(ctx.cwd, ["rev-parse", "--show-toplevel"]) ?? ctx.cwd;
|
|
134
|
+
const runtime = latestRuntimeRow(readRows(file), workflow);
|
|
135
|
+
const adopt = runtime?.runtimeWorktrees === false;
|
|
136
|
+
const finish = (r) => {
|
|
137
|
+
const output = { ...r, adopt };
|
|
138
|
+
if (out) {
|
|
139
|
+
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
140
|
+
fs.writeFileSync(out, `${JSON.stringify(output, null, 2)}\n`);
|
|
141
|
+
}
|
|
142
|
+
ctx.emit({ ...output });
|
|
143
|
+
return EXIT.OK;
|
|
144
|
+
};
|
|
145
|
+
const unknown = (reason, base, cases = []) => finish({
|
|
146
|
+
...baseVerdict(cases),
|
|
147
|
+
verdict: "unknown",
|
|
148
|
+
reason,
|
|
149
|
+
base,
|
|
150
|
+
source: null,
|
|
151
|
+
cases,
|
|
152
|
+
});
|
|
153
|
+
const reports = `${log}.reports`;
|
|
154
|
+
const failures = fs.existsSync(reports) ? reportFailures(reports) : null;
|
|
155
|
+
if (failures === null)
|
|
156
|
+
return unknown("no JUnit report", null);
|
|
157
|
+
if (failures.length === 0)
|
|
158
|
+
return finish({ ...noCases(), base: null, source: null, cases: [] });
|
|
159
|
+
const tracked = (git(top, ["ls-files", "-z"]) ?? "").split("\0").filter(Boolean);
|
|
160
|
+
const resolved = failures.map((c) => ({ c, file: caseFile(c, tracked) }));
|
|
161
|
+
const rowsWith = (at) => resolved.map(({ c, file: f }) => ({ name: c.name, file: f, atBase: at(c, f) }));
|
|
162
|
+
const mergeBase = git(top, ["merge-base", "HEAD", devBase(top)]);
|
|
163
|
+
if (mergeBase === null)
|
|
164
|
+
return unknown("no base commit", null, rowsWith(() => "unknown"));
|
|
165
|
+
const base = mergeBase;
|
|
166
|
+
// A passing push-event CI run at the exact base sha settles "none" without a checkout.
|
|
167
|
+
const repo = resolveOwnerRepo(top);
|
|
168
|
+
if (repo !== null) {
|
|
169
|
+
const { shipGate } = await import("./runs.js");
|
|
170
|
+
const gate = shipGate({ root: top, head: base, repo: repo.ownerRepo, event: "push" }, (args) => runGh(top, args), ctx.log);
|
|
171
|
+
if (gate.passed && gate.skippedLanes.length === 0) {
|
|
172
|
+
const cases = rowsWith(() => "pass");
|
|
173
|
+
return finish({ ...baseVerdict(cases), base, source: "ci", cases });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (!readBkitConfig(top).worktreeInstall)
|
|
177
|
+
return unknown("no install at the base commit (worktreeInstall off)", base, rowsWith(() => "unknown"));
|
|
178
|
+
const files = [...new Set(resolved.flatMap((r) => (r.file === null ? [] : [r.file])))];
|
|
179
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "bkit-base-"));
|
|
180
|
+
const logDir = `${log}.base`;
|
|
181
|
+
const baseRun = () => {
|
|
182
|
+
const result = { reason: null, files: new Map(), exits: new Map() };
|
|
183
|
+
const added = runGit(top, [
|
|
184
|
+
"-c",
|
|
185
|
+
"core.hooksPath=/dev/null",
|
|
186
|
+
"worktree",
|
|
187
|
+
"add",
|
|
188
|
+
"-q",
|
|
189
|
+
"--detach",
|
|
190
|
+
tmp,
|
|
191
|
+
base,
|
|
192
|
+
]);
|
|
193
|
+
if (!added.ok)
|
|
194
|
+
return { ...result, reason: "base checkout failed" };
|
|
195
|
+
copyListed(mainCheckoutRoot(top) ?? top, tmp, readBkitConfig(top).worktreeCopy, ctx.log);
|
|
196
|
+
const pkg = readPackageJson(tmp);
|
|
197
|
+
const scripts = pkg.ok ? pkg.pkg.scripts : undefined;
|
|
198
|
+
const declared = typeof scripts === "object" &&
|
|
199
|
+
scripts !== null &&
|
|
200
|
+
typeof scripts[BKIT_TEST_FILE_SCRIPT] === "string";
|
|
201
|
+
if (!declared)
|
|
202
|
+
return { ...result, reason: `${BKIT_TEST_FILE_SCRIPT} not declared at the base commit` };
|
|
203
|
+
const status = install(tmp, ctx.log, { preferOffline: true });
|
|
204
|
+
if (status !== 0)
|
|
205
|
+
return { ...result, reason: `base install failed (exit ${status})` };
|
|
206
|
+
files.forEach((f, n) => {
|
|
207
|
+
if (!fs.existsSync(path.join(tmp, f)))
|
|
208
|
+
return;
|
|
209
|
+
const ran = runTestFile(tmp, f, path.join(logDir, `${n}.log`));
|
|
210
|
+
result.files.set(f, ran.cases);
|
|
211
|
+
result.exits.set(f, ran.exitCode);
|
|
212
|
+
});
|
|
213
|
+
return result;
|
|
214
|
+
};
|
|
215
|
+
const run = await withCleanup(baseRun, () => dropLandTree(top, tmp));
|
|
216
|
+
if (run.reason !== null)
|
|
217
|
+
return unknown(run.reason, base, rowsWith(() => "unknown"));
|
|
218
|
+
let noReport = false;
|
|
219
|
+
let crashed = null;
|
|
220
|
+
let skipped = 0;
|
|
221
|
+
const cases = rowsWith((c, f) => {
|
|
222
|
+
if (f === null)
|
|
223
|
+
return "unknown";
|
|
224
|
+
if (!run.files.has(f))
|
|
225
|
+
return "absent";
|
|
226
|
+
const ran = run.files.get(f);
|
|
227
|
+
if (ran === null || ran === undefined) {
|
|
228
|
+
noReport = true;
|
|
229
|
+
return "unknown";
|
|
230
|
+
}
|
|
231
|
+
const same = ran.find((b) => b.name === c.name);
|
|
232
|
+
if (same === undefined) {
|
|
233
|
+
const exit = run.exits.get(f) ?? 0;
|
|
234
|
+
if (exit !== 0) {
|
|
235
|
+
crashed ??= exit;
|
|
236
|
+
return "unknown";
|
|
237
|
+
}
|
|
238
|
+
return "absent";
|
|
239
|
+
}
|
|
240
|
+
if (same.state === "failure" || same.state === "error")
|
|
241
|
+
return "red";
|
|
242
|
+
if (same.state === "passed")
|
|
243
|
+
return "pass";
|
|
244
|
+
skipped += 1;
|
|
245
|
+
return "unknown";
|
|
246
|
+
});
|
|
247
|
+
const verdict = baseVerdict(cases);
|
|
248
|
+
if (verdict.verdict === "unknown" || verdict.verdict === "some") {
|
|
249
|
+
const unresolved = cases.filter((c) => c.file === null).length;
|
|
250
|
+
const reason = noReport
|
|
251
|
+
? "no report from the base run"
|
|
252
|
+
: crashed !== null
|
|
253
|
+
? `the base run of a test file exited ${crashed} without the failing case`
|
|
254
|
+
: unresolved > 0
|
|
255
|
+
? `${unresolved} case(s) with no resolvable file`
|
|
256
|
+
: skipped > 0
|
|
257
|
+
? `${skipped} case(s) skipped at the base commit`
|
|
258
|
+
: verdict.reason;
|
|
259
|
+
return finish({ ...verdict, reason, base, source: "local", cases });
|
|
260
|
+
}
|
|
261
|
+
return finish({ ...verdict, base, source: "local", cases });
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
function noCases() {
|
|
265
|
+
return baseVerdict([]);
|
|
266
|
+
}
|