@cbartens/bkit 6.1.0 → 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 +43 -33
- 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 +99 -36
- package/.bkit/core/.bkit/templates.md +167 -37
- 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 +161 -37
- package/.bkit/core/engine/checks/after/index.ts +18 -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 +124 -19
- package/.bkit/core/engine/commands/ci/push-gate.ts +101 -43
- package/.bkit/core/engine/commands/install/doctor.ts +5 -5
- 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 +202 -26
- 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 +46 -11
- 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/context/bkit-vercel.md +103 -59
- 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-check-accepted-divergences.mjs +1 -6
- package/.bkit/templates/scripts/ci/bkit-machine-lock.sh +511 -103
- package/.bkit/templates/scripts/ci/bkit-test-awake.mjs +314 -28
- package/.bkit/templates/scripts/ci/bkit-test-awake.test.mjs +500 -1
- package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +1 -1
- package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +91 -62
- package/.bkit/templates/scripts/graphify/bkit-graphify.sh +59 -11
- package/.bkit/templates/slop-scan.config.json +2 -0
- package/CHANGELOG.md +79 -0
- package/DETAILS.md +661 -0
- package/README.md +73 -604
- package/dist/checks/after/auth.js +114 -46
- package/dist/checks/after/github.js +138 -35
- package/dist/checks/after/index.js +16 -4
- 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 +113 -20
- package/dist/commands/ci/push-gate.js +79 -44
- package/dist/commands/install/doctor.js +5 -5
- 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 +190 -27
- 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 +21 -12
- 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 +23 -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
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
// The lock holds one line, `{at} {workflow} {fid} {token}`. Release removes only a
|
|
9
9
|
// lock this caller owns (same token, else same workflow and feature), so a Failure
|
|
10
10
|
// Path that never got the lock cannot delete the holder's.
|
|
11
|
-
import { randomBytes } from "node:crypto";
|
|
11
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
12
12
|
import * as fs from "node:fs";
|
|
13
|
+
import * as os from "node:os";
|
|
13
14
|
import * as path from "node:path";
|
|
14
|
-
import { fold, lastRun, statusTimestamp, } from "../../ledgers/status.js";
|
|
15
|
-
import { CommandError, EXIT, parseJson, repoRoot, statusRelPath, utcMonth, } from "../lib.js";
|
|
15
|
+
import { createExclusive, fold, lastRun, statusTimestamp, } from "../../ledgers/status.js";
|
|
16
|
+
import { CommandError, EXIT, git, parseJson, repoRoot, runTool, statusRelPath, utcMonth, } from "../lib.js";
|
|
16
17
|
import { removeRecord } from "./ledgers.js";
|
|
17
18
|
import { str } from "./status.js";
|
|
18
19
|
/** A workflow lock whose holder shows no sign of life for this long is stale. */
|
|
@@ -23,6 +24,8 @@ export const EXIT_SPLIT_BUCKET = 7;
|
|
|
23
24
|
export const EXIT_NOT_OWNER = 4;
|
|
24
25
|
/** Exit code: the lock file is still there after removing it. */
|
|
25
26
|
export const EXIT_REMOVE_FAILED = 5;
|
|
27
|
+
/** Exit code: another run of the feature holds the lock and is still stepping. */
|
|
28
|
+
export const EXIT_LOCK_BUSY = 8;
|
|
26
29
|
const KINDS = ["workflow"];
|
|
27
30
|
// ---------------------------------------------------------------------------
|
|
28
31
|
// Paths
|
|
@@ -67,25 +70,99 @@ export function readHolder(file) {
|
|
|
67
70
|
/** Create `file` only if absent (`set -C`); false when someone else holds it. */
|
|
68
71
|
export function tryCreate(file, line) {
|
|
69
72
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
return createExclusive(file, `${line}\n`);
|
|
74
|
+
}
|
|
75
|
+
const newToken = () => randomBytes(4).toString("hex");
|
|
76
|
+
/** The OS start identity distinguishes a live reused PID from a recorded owner. */
|
|
77
|
+
function processStart(pid, timeoutMs = 1000) {
|
|
78
|
+
const result = runTool("ps", ["-p", String(pid), "-o", "lstart="], process.cwd(), {
|
|
79
|
+
timeoutMs: Math.max(50, Math.min(1000, timeoutMs)),
|
|
80
|
+
});
|
|
81
|
+
return result.found && result.status === 0 && result.stdout.trim() !== ""
|
|
82
|
+
? result.stdout.trim()
|
|
83
|
+
: null;
|
|
84
|
+
}
|
|
85
|
+
function publicationHolder(file) {
|
|
86
|
+
const parsed = parseJson(fs.readFileSync(file, "utf8"));
|
|
87
|
+
if (!parsed.ok || typeof parsed.value !== "object" || parsed.value === null)
|
|
88
|
+
return null;
|
|
89
|
+
const raw = parsed.value;
|
|
90
|
+
return typeof raw.token === "string" &&
|
|
91
|
+
/^[a-f0-9]{32}$/.test(raw.token) &&
|
|
92
|
+
typeof raw.path === "string" &&
|
|
93
|
+
typeof raw.owner?.host === "string" &&
|
|
94
|
+
Number.isInteger(raw.owner.pid) &&
|
|
95
|
+
raw.owner.pid > 0 &&
|
|
96
|
+
typeof raw.owner.startTime === "string" &&
|
|
97
|
+
Number.isFinite(Date.parse(raw.owner.startTime))
|
|
98
|
+
? { path: file, token: raw.token, owner: raw.owner }
|
|
99
|
+
: null;
|
|
76
100
|
}
|
|
77
|
-
|
|
101
|
+
/** A separate best-effort lock for one issue and invocation; age never establishes death. */
|
|
102
|
+
export async function acquirePublicationLock(cwd, options) {
|
|
78
103
|
try {
|
|
79
|
-
|
|
104
|
+
const end = performance.now() + Math.min(30_000, Math.max(0, options.timeoutMs ?? 30_000));
|
|
105
|
+
const common = git(cwd, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
|
|
106
|
+
const startTime = processStart(process.pid, end - performance.now());
|
|
107
|
+
if (!common || !startTime || !options.target || !options.invocation)
|
|
108
|
+
return null;
|
|
109
|
+
const digest = createHash("sha256")
|
|
110
|
+
.update(`${options.target}\0${options.invocation}`)
|
|
111
|
+
.digest("hex");
|
|
112
|
+
const file = path.join(common, "bkit-outbox", "publication-locks", `${digest}.lock`);
|
|
113
|
+
const lock = {
|
|
114
|
+
path: file,
|
|
115
|
+
token: randomBytes(16).toString("hex"),
|
|
116
|
+
owner: { host: os.hostname(), pid: process.pid, startTime },
|
|
117
|
+
};
|
|
118
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
119
|
+
do {
|
|
120
|
+
if (tryCreate(file, JSON.stringify(lock)))
|
|
121
|
+
return lock;
|
|
122
|
+
const holder = publicationHolder(file);
|
|
123
|
+
if (!holder || holder.owner.host !== lock.owner.host)
|
|
124
|
+
return null;
|
|
125
|
+
let dead = false;
|
|
126
|
+
try {
|
|
127
|
+
process.kill(holder.owner.pid, 0);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
dead = error.code === "ESRCH";
|
|
131
|
+
}
|
|
132
|
+
if (dead) {
|
|
133
|
+
if (publicationHolder(file)?.token !== holder.token)
|
|
134
|
+
return null;
|
|
135
|
+
fs.unlinkSync(file);
|
|
136
|
+
if (tryCreate(file, JSON.stringify(lock)))
|
|
137
|
+
return lock;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (processStart(holder.owner.pid, end - performance.now()) !== holder.owner.startTime)
|
|
141
|
+
return null;
|
|
142
|
+
const remaining = end - performance.now();
|
|
143
|
+
if (remaining <= 0)
|
|
144
|
+
return null;
|
|
145
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(20, remaining)));
|
|
146
|
+
} while (performance.now() <= end);
|
|
147
|
+
return null;
|
|
80
148
|
}
|
|
81
|
-
catch
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
149
|
+
catch {
|
|
150
|
+
// Lock failures select standalone publication rather than fail substantive work.
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** Remove only this publication token; filesystem errors leave append unavailable. */
|
|
155
|
+
export async function releasePublicationLock(lock) {
|
|
156
|
+
try {
|
|
157
|
+
if (publicationHolder(lock.path)?.token !== lock.token)
|
|
158
|
+
return false;
|
|
159
|
+
fs.unlinkSync(lock.path);
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return false;
|
|
86
164
|
}
|
|
87
165
|
}
|
|
88
|
-
const newToken = () => randomBytes(4).toString("hex");
|
|
89
166
|
const lockLine = (workflow, fid, token) => `${statusTimestamp()} ${workflow} ${fid} ${token}`;
|
|
90
167
|
/** The caller owns the lock: same token when it gave one, else same workflow and feature. */
|
|
91
168
|
export function owns(holder, who) {
|
|
@@ -103,7 +180,15 @@ function liveReason(root, month, fid, holder, now) {
|
|
|
103
180
|
if (run?.status === "IN_PROGRESS" && lastAt) {
|
|
104
181
|
const idle = Math.floor((now - Date.parse(lastAt)) / 1000);
|
|
105
182
|
if (idle < WORKFLOW_LOCK_IDLE_S)
|
|
106
|
-
return {
|
|
183
|
+
return {
|
|
184
|
+
live: {
|
|
185
|
+
workflow: holder.workflow ?? null,
|
|
186
|
+
since: holder.at ?? null,
|
|
187
|
+
lastStepAt: lastAt,
|
|
188
|
+
idleSeconds: idle,
|
|
189
|
+
line: holder.line,
|
|
190
|
+
},
|
|
191
|
+
};
|
|
107
192
|
}
|
|
108
193
|
if (run === undefined)
|
|
109
194
|
return { reason: "orphaned" };
|
|
@@ -146,7 +231,12 @@ export function workflowLockFresh(root, fid) {
|
|
|
146
231
|
return stat !== undefined && (Date.now() - stat.mtimeMs) / 1000 < WORKFLOW_LOCK_IDLE_S;
|
|
147
232
|
});
|
|
148
233
|
}
|
|
149
|
-
|
|
234
|
+
const busyMessage = (fid, by) => `workflow already running for ${fid} (workflow=${by.workflow ?? "?"}, ${by.idleSeconds === null ? "just started" : `idle ${by.idleSeconds}s`})`;
|
|
235
|
+
/**
|
|
236
|
+
* Take the feature's workflow lock, reclaiming an idle holder's. A holder still
|
|
237
|
+
* stepping keeps its lock, and the result names it in `heldBy`.
|
|
238
|
+
*/
|
|
239
|
+
export function tryAcquireWorkflowLock(opts) {
|
|
150
240
|
const root = repoRoot(opts.cwd);
|
|
151
241
|
const month = resolveMonth(root, opts.fid, opts.month);
|
|
152
242
|
const file = workflowLockPath(root, month, opts.fid);
|
|
@@ -156,15 +246,34 @@ export function acquireWorkflowLock(opts) {
|
|
|
156
246
|
return { path: file, month, token, reclaimed: null };
|
|
157
247
|
const holder = readHolder(file) ?? { line: "" };
|
|
158
248
|
const verdict = liveReason(root, month, opts.fid, holder, Date.now());
|
|
159
|
-
if ("live" in verdict)
|
|
160
|
-
|
|
161
|
-
}
|
|
249
|
+
if ("live" in verdict)
|
|
250
|
+
return { path: file, month, heldBy: verdict.live };
|
|
162
251
|
opts.log(`reclaiming ${verdict.reason} lock for ${opts.fid}: ${holder.line}`);
|
|
163
252
|
fs.rmSync(file, { force: true });
|
|
164
|
-
if (!tryCreate(file, line))
|
|
165
|
-
|
|
253
|
+
if (!tryCreate(file, line)) {
|
|
254
|
+
// Another acquirer took the lock between the removal and this create.
|
|
255
|
+
const winner = readHolder(file) ?? { line: "" };
|
|
256
|
+
return {
|
|
257
|
+
path: file,
|
|
258
|
+
month,
|
|
259
|
+
heldBy: {
|
|
260
|
+
workflow: winner.workflow ?? null,
|
|
261
|
+
since: winner.at ?? null,
|
|
262
|
+
lastStepAt: null,
|
|
263
|
+
idleSeconds: null,
|
|
264
|
+
line: winner.line,
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
}
|
|
166
268
|
return { path: file, month, token, reclaimed: { holder: holder.line, reason: verdict.reason } };
|
|
167
269
|
}
|
|
270
|
+
/** {@link tryAcquireWorkflowLock}, refusing with {@link EXIT_LOCK_BUSY} when a live run holds the lock. */
|
|
271
|
+
export function acquireWorkflowLock(opts) {
|
|
272
|
+
const lock = tryAcquireWorkflowLock(opts);
|
|
273
|
+
if ("heldBy" in lock)
|
|
274
|
+
throw new CommandError(EXIT_LOCK_BUSY, busyMessage(opts.fid, lock.heldBy));
|
|
275
|
+
return lock;
|
|
276
|
+
}
|
|
168
277
|
/**
|
|
169
278
|
* Remove a lock this caller owns. Missing is fine (already released); another
|
|
170
279
|
* owner's lock is left in place and reported.
|
|
@@ -212,29 +321,41 @@ export const locksCommand = {
|
|
|
212
321
|
summary: "Acquire and release the per-feature workflow lock.",
|
|
213
322
|
verbs: {
|
|
214
323
|
acquire: {
|
|
215
|
-
summary: "Take the workflow lock, reclaiming a dead holder's.",
|
|
324
|
+
summary: "Take the workflow lock, reclaiming a dead holder's; a live holder exits 8 and prints heldBy.",
|
|
216
325
|
use: "workflow",
|
|
217
326
|
flags: [KIND_FLAG, LOCK_WORKFLOW_FLAG, FID_FLAG, MONTH_FLAG],
|
|
218
327
|
output: {
|
|
219
328
|
kind: "workflow",
|
|
220
329
|
path: "absolute path of the lock file",
|
|
221
|
-
token: "this holder's token; pass it to release",
|
|
330
|
+
token: "this holder's token; pass it to release (null when busy)",
|
|
222
331
|
month: "the month bucket",
|
|
223
332
|
reclaimed: "{holder, reason: finished|stale|orphaned}; null when none",
|
|
333
|
+
heldBy: "{workflow, since, lastStepAt, idleSeconds, line} of the live run that keeps the lock; null when this call took it",
|
|
334
|
+
route: "go when this call took the lock; stop when a live run keeps it (exit 8). An error exit prints no route",
|
|
335
|
+
message: "for stop: the line for the owner naming the holder, when it took the lock and last stepped, and when this run can start again; empty for go",
|
|
224
336
|
},
|
|
225
337
|
exitCodes: {
|
|
226
338
|
[EXIT_SPLIT_BUCKET]: "the feature has logs in more than one month bucket",
|
|
339
|
+
[EXIT_LOCK_BUSY]: "another run of the feature holds the lock and stepped in the last 30 minutes; nothing was taken or changed",
|
|
227
340
|
},
|
|
228
341
|
run: (ctx) => {
|
|
229
342
|
const kind = kindOf(ctx);
|
|
230
|
-
const
|
|
343
|
+
const fid = String(ctx.flags.fid);
|
|
344
|
+
const lock = tryAcquireWorkflowLock({
|
|
231
345
|
cwd: ctx.cwd,
|
|
232
346
|
workflow: String(ctx.flags.workflow),
|
|
233
|
-
fid
|
|
347
|
+
fid,
|
|
234
348
|
month: str(ctx.flags.month),
|
|
235
349
|
log: ctx.log,
|
|
236
350
|
});
|
|
237
|
-
|
|
351
|
+
if ("heldBy" in lock) {
|
|
352
|
+
const by = lock.heldBy;
|
|
353
|
+
const message = `${by.workflow ?? "another run"} has held ${fid} since ${by.since ?? "an unknown time"} and last stepped at ${by.lastStepAt ?? "no step yet"}. Nothing changed; this run can start again once that run ends or has been idle ${WORKFLOW_LOCK_IDLE_S / 60} minutes.`;
|
|
354
|
+
ctx.emit({ kind, ...lock, token: null, reclaimed: null, route: "stop", message });
|
|
355
|
+
ctx.log(busyMessage(fid, lock.heldBy));
|
|
356
|
+
return EXIT_LOCK_BUSY;
|
|
357
|
+
}
|
|
358
|
+
ctx.emit({ kind, ...lock, heldBy: null, route: "go", message: "" });
|
|
238
359
|
return EXIT.OK;
|
|
239
360
|
},
|
|
240
361
|
},
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// The build fix loops, and the step whose test-run rows judge each fix round.
|
|
2
|
+
// Kept apart from decisions.ts and status.ts so both can import it without an import cycle.
|
|
3
|
+
export const LOOPS = {
|
|
4
|
+
verify: {
|
|
5
|
+
title: "Verify",
|
|
6
|
+
check: "build-plan-verify",
|
|
7
|
+
fix: "build-plan-gaps-remediate",
|
|
8
|
+
point: "verify",
|
|
9
|
+
gate: "build-group-gate",
|
|
10
|
+
gateTitle: "Group gate",
|
|
11
|
+
grouped: true,
|
|
12
|
+
},
|
|
13
|
+
// The whole-feature check reopens after each clean round, so its loop starts there. Its allowance is `build.holistic`.
|
|
14
|
+
holistic: {
|
|
15
|
+
title: "Holistic verify",
|
|
16
|
+
check: "build-plan-verify-holistic",
|
|
17
|
+
fix: "build-plan-gaps-remediate-holistic",
|
|
18
|
+
point: "holistic",
|
|
19
|
+
sinceClean: true,
|
|
20
|
+
gate: "build-holistic-gate",
|
|
21
|
+
gateTitle: "Holistic gate",
|
|
22
|
+
},
|
|
23
|
+
tests: {
|
|
24
|
+
title: "Tests",
|
|
25
|
+
check: "build-run-tests",
|
|
26
|
+
fix: "build-failure-diagnose",
|
|
27
|
+
point: "tests",
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
/** Fix steps outside the build loops, and the test step each one's rounds are judged by. */
|
|
31
|
+
const OTHER_FIX_TESTS = {
|
|
32
|
+
"debug-failure-diagnose": "debug-run-tests",
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The test-run step a loop's gate writes: the gate, with `-{group}` appended for a grouped
|
|
36
|
+
* loop. Undefined for a loop with no gate, or a grouped loop given no group.
|
|
37
|
+
*/
|
|
38
|
+
export function loopGateStep(loop, group) {
|
|
39
|
+
if (loop.gate === undefined)
|
|
40
|
+
return undefined;
|
|
41
|
+
if (loop.grouped !== true)
|
|
42
|
+
return loop.gate;
|
|
43
|
+
return group === undefined ? undefined : `${loop.gate}-${group}`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The step whose test-run rows show what a fix step's rounds left failing: the loop's gate
|
|
47
|
+
* (with the group for a grouped loop), else its check; `debug-failure-diagnose` gives
|
|
48
|
+
* `debug-run-tests`. Undefined for any other step, or a grouped loop given no group.
|
|
49
|
+
*/
|
|
50
|
+
export function fixTestStep(fix, group) {
|
|
51
|
+
const other = OTHER_FIX_TESTS[fix];
|
|
52
|
+
if (other !== undefined)
|
|
53
|
+
return other;
|
|
54
|
+
const loop = Object.values(LOOPS).find((l) => l.fix === fix);
|
|
55
|
+
if (loop === undefined)
|
|
56
|
+
return undefined;
|
|
57
|
+
return loop.gate === undefined ? loop.check : loopGateStep(loop, group);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The check step whose current attempt a fix step's round follows, for a loop whose gate
|
|
61
|
+
* does not run on every round: the gate's newest row can belong to an older attempt.
|
|
62
|
+
* Undefined for a loop with no gate, whose test step is the check itself.
|
|
63
|
+
*/
|
|
64
|
+
export function gatedCheckStep(fix) {
|
|
65
|
+
const loop = Object.values(LOOPS).find((l) => l.fix === fix);
|
|
66
|
+
return loop?.gate === undefined ? undefined : loop.check;
|
|
67
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Read a build Decision Pause file: its header, its items, the run's open pause, and the two
|
|
2
|
+
// rules read from them — whether a resume re-runs a red gate (`gateRerun`) and whether a
|
|
3
|
+
// pause may route `continue` (`skipProblem`). `decisions.ts` writes these files; this module
|
|
4
|
+
// only reads them and imports nothing from the command modules, so `status.ts`, `steps.ts`
|
|
5
|
+
// and `workflows.ts` read it without an import cycle.
|
|
6
|
+
import * as fs from "node:fs";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
/** Splits a decision file before each `**Q{n} — ` item line. */
|
|
9
|
+
export const ITEM_SPLIT = /^(?=\*\*Q\d+ — )/m;
|
|
10
|
+
const lineOf = (text, key) => new RegExp(`^${key}:[ \\t]*(.+?)[ \\t]*$`, "m").exec(text)?.[1] ?? null;
|
|
11
|
+
/** `A`, `B`, … for option index `i`. */
|
|
12
|
+
export const letterAt = (i) => String.fromCharCode(65 + i);
|
|
13
|
+
/** An option entry's leading letter (`A) `) dropped, so a parsed name stays bare. */
|
|
14
|
+
const bareName = (s) => s.replace(/^[A-Z]\)[ \t]*/, "");
|
|
15
|
+
/** A reply opening on an option letter: `B`, `B)`, `B — …`, `B) {option} …`, `B {option} …`. */
|
|
16
|
+
const LETTER_REPLY = /^([A-Za-z])(?:\)|(?=[ \t—:,.-]|$))[ \t]*(?:[—:,.-][ \t]*)?/;
|
|
17
|
+
/**
|
|
18
|
+
* An answer read as the option it names. A leading letter of `options` (either case, with or
|
|
19
|
+
* without `)`) becomes the option it labels: `B`, `B) Reject` and `B — too risky` read as
|
|
20
|
+
* `Reject`, `Reject` and `Reject — too risky`. Any other answer is returned unchanged; with
|
|
21
|
+
* no options known, only a leading `A) ` is dropped.
|
|
22
|
+
*/
|
|
23
|
+
export function optionAnswer(answer, options) {
|
|
24
|
+
if (options.length === 0)
|
|
25
|
+
return bareName(answer);
|
|
26
|
+
const m = LETTER_REPLY.exec(answer);
|
|
27
|
+
const name = m === null ? undefined : options[m[1].toUpperCase().charCodeAt(0) - 65];
|
|
28
|
+
if (m === null || name === undefined)
|
|
29
|
+
return answer;
|
|
30
|
+
const rest = answer.slice(m[0].length);
|
|
31
|
+
if (rest.toLowerCase().startsWith(name.toLowerCase()))
|
|
32
|
+
return name + rest.slice(name.length);
|
|
33
|
+
if (rest === "")
|
|
34
|
+
return name;
|
|
35
|
+
return /[)—:,.-]/.test(m[0]) ? `${name} — ${rest}` : answer;
|
|
36
|
+
}
|
|
37
|
+
/** A `Fix task:` value as a positive integer, else null. */
|
|
38
|
+
const fixTaskOf = (v) => v !== null && /^[1-9][0-9]*$/.test(v) ? Number(v) : null;
|
|
39
|
+
/** The `Key: value` lines before the file's first blank line. */
|
|
40
|
+
export function decisionHeader(text) {
|
|
41
|
+
const out = {};
|
|
42
|
+
for (const line of text.split("\n")) {
|
|
43
|
+
if (line.trim() === "" || line.startsWith("**Q"))
|
|
44
|
+
break;
|
|
45
|
+
const m = /^([A-Za-z][\w ]*):[ \t]*(.*?)[ \t]*$/.exec(line);
|
|
46
|
+
if (m !== null && !(m[1] in out))
|
|
47
|
+
out[m[1]] = m[2];
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
/** The items of a decision file's text, in file order. */
|
|
52
|
+
export function parseDecisionItems(text) {
|
|
53
|
+
return text
|
|
54
|
+
.split(ITEM_SPLIT)
|
|
55
|
+
.slice(1)
|
|
56
|
+
.map((part) => {
|
|
57
|
+
const head = /^\*\*Q(\d+) — (.+?):\*\*/.exec(part);
|
|
58
|
+
const rec = lineOf(part, "Recommended");
|
|
59
|
+
const [option, ...why] = (rec ?? "").split(" — ");
|
|
60
|
+
const none = /^No recommendation\b/m.test(part) || /^none$/i.test((option ?? "").trim());
|
|
61
|
+
const perLine = [...part.matchAll(/^[A-Z]\)[ \t]+(.+?)[ \t]*$/gm)].map((m) => (m[1] ?? "").split(" — ")[0].trim());
|
|
62
|
+
const options = perLine.length > 0
|
|
63
|
+
? perLine.filter(Boolean)
|
|
64
|
+
: (lineOf(part, "Options") ?? "")
|
|
65
|
+
.split(" / ")
|
|
66
|
+
.map((o) => bareName(o.trim()))
|
|
67
|
+
.filter(Boolean);
|
|
68
|
+
const answer = lineOf(part, "Decision");
|
|
69
|
+
const decision = answer === null ? null : optionAnswer(answer, options);
|
|
70
|
+
return {
|
|
71
|
+
n: Number(head?.[1] ?? 0),
|
|
72
|
+
title: head?.[2] ?? "",
|
|
73
|
+
text: part.trimEnd(),
|
|
74
|
+
options,
|
|
75
|
+
recommended: none || rec === null ? null : bareName((option ?? "").trim()),
|
|
76
|
+
reason: why.join(" — ").trim(),
|
|
77
|
+
decision,
|
|
78
|
+
fixTask: fixTaskOf(lineOf(part, "Fix task")),
|
|
79
|
+
assumed: decision !== null && /^Accept \(assumed\)/.test(decision),
|
|
80
|
+
rejected: lineOf(part, "Rejected") !== null,
|
|
81
|
+
deferred: lineOf(part, "Deferred") !== null,
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Whether Q1 is the loop question (the text before the first item holds a `## Progress`
|
|
87
|
+
* block), and the questions besides it that nobody answered, rejected or deferred.
|
|
88
|
+
*/
|
|
89
|
+
export function undecidedBesidesLoop(text) {
|
|
90
|
+
const hasLoop = /^## Progress$/m.test(text.split(ITEM_SPLIT, 1)[0] ?? "");
|
|
91
|
+
const undecided = parseDecisionItems(text)
|
|
92
|
+
.filter((i) => (hasLoop ? i.n !== 1 : true) && i.decision === null && !i.rejected && !i.deferred)
|
|
93
|
+
.map((i) => `Q${i.n}`);
|
|
94
|
+
return { hasLoop, undecided };
|
|
95
|
+
}
|
|
96
|
+
/** The checks a red-gate pause re-runs, by the decision file's `From` header. */
|
|
97
|
+
export const RERUN_FROM = ["verify", "holistic", "tests"];
|
|
98
|
+
/**
|
|
99
|
+
* Whether a resume re-runs the pause's gate instead of asking it again: its `Gate` header is
|
|
100
|
+
* `FAIL`, its `Status` is `OPEN`, the loop question is its only undecided question, and its
|
|
101
|
+
* `From` names a check that re-runs. `rerunFrom` is that check, null when `gateRerun` is false.
|
|
102
|
+
*/
|
|
103
|
+
export function gateRerun(open, text) {
|
|
104
|
+
const from = RERUN_FROM.find((f) => f === open?.from);
|
|
105
|
+
const { hasLoop, undecided } = undecidedBesidesLoop(text);
|
|
106
|
+
const rerun = open?.gate === "FAIL" &&
|
|
107
|
+
open.status === "OPEN" &&
|
|
108
|
+
from !== undefined &&
|
|
109
|
+
hasLoop &&
|
|
110
|
+
undecided.length === 0;
|
|
111
|
+
return { gateRerun: rerun, rerunFrom: rerun ? from : null };
|
|
112
|
+
}
|
|
113
|
+
/** An item answer that accepts the item: `Accept` or `Accept (assumed)`, with or without words. */
|
|
114
|
+
const ACCEPTED = /^Accept(?: \(assumed\))?(?:$|[ \t]+—)/;
|
|
115
|
+
/**
|
|
116
|
+
* The first fact that stops a settled pause from routing `continue`, or null when all five
|
|
117
|
+
* hold: `From` is `verify` or `holistic`; every item is `Accept` or `Accept (assumed)`; the
|
|
118
|
+
* loop question, when asked, is `Decide`; no `Gate: FAIL` header; and a `Source changed`
|
|
119
|
+
* header that reads `false`. Headers count only in the header block, so a line inside an item
|
|
120
|
+
* never stands in for one. A missing fact refuses; it is never guessed.
|
|
121
|
+
*/
|
|
122
|
+
export function skipProblem(text) {
|
|
123
|
+
const header = decisionHeader(text);
|
|
124
|
+
const from = header.From;
|
|
125
|
+
if (from === undefined)
|
|
126
|
+
return "no From header";
|
|
127
|
+
if (from !== "verify" && from !== "holistic")
|
|
128
|
+
return `From is "${from}", not verify or holistic`;
|
|
129
|
+
const { hasLoop } = undecidedBesidesLoop(text);
|
|
130
|
+
const items = parseDecisionItems(text);
|
|
131
|
+
for (const it of items) {
|
|
132
|
+
if (hasLoop && it.n === 1)
|
|
133
|
+
continue;
|
|
134
|
+
if (it.rejected)
|
|
135
|
+
return `Q${it.n} is rejected, not Accept`;
|
|
136
|
+
if (it.decision === null || !ACCEPTED.test(it.decision))
|
|
137
|
+
return `Q${it.n} is ${it.decision === null ? "undecided" : `"${it.decision}"`}, not Accept`;
|
|
138
|
+
}
|
|
139
|
+
const loop = hasLoop ? items.find((i) => i.n === 1) : undefined;
|
|
140
|
+
if (loop !== undefined && !/^Decide\b/.test(loop.decision ?? ""))
|
|
141
|
+
return `the loop question Q1 is ${loop.decision === null ? "undecided" : `"${loop.decision}"`}, not Decide`;
|
|
142
|
+
if (/^FAIL\b/.test(header.Gate ?? ""))
|
|
143
|
+
return "Gate: FAIL header: the gate is red";
|
|
144
|
+
const changed = header["Source changed"];
|
|
145
|
+
if (changed === undefined)
|
|
146
|
+
return "no Source changed header";
|
|
147
|
+
if (changed !== "false")
|
|
148
|
+
return `Source changed is "${changed}", not false`;
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The highest-numbered `{workflow}-decision-{run}-{N}.md` in `logDir` whose header holds
|
|
153
|
+
* `Status: OPEN`, or a `DECIDED` / `ASSUMED` file that none of the run's `{workflow}-decision`
|
|
154
|
+
* rows names (a pause stopped after its answers were written, before the step finished), or
|
|
155
|
+
* null. Only the given run's files count, so an earlier run's pause never resurfaces.
|
|
156
|
+
* `file` is relative to `tree`; `finished` lists the paths the run's decision rows name.
|
|
157
|
+
*/
|
|
158
|
+
export function openDecision(logDir, tree, workflow, run, finished = []) {
|
|
159
|
+
if (!fs.existsSync(logDir))
|
|
160
|
+
return null;
|
|
161
|
+
const name = new RegExp(`^${workflow}-decision-${run}-([0-9]+)\\.md$`);
|
|
162
|
+
const found = fs
|
|
163
|
+
.readdirSync(logDir)
|
|
164
|
+
.map((f) => ({ f, m: name.exec(f) }))
|
|
165
|
+
.filter((x) => x.m !== null)
|
|
166
|
+
.map(({ f, m }) => ({ f, n: Number(m[1]) }))
|
|
167
|
+
.sort((a, b) => b.n - a.n);
|
|
168
|
+
for (const { f, n } of found) {
|
|
169
|
+
const text = fs.readFileSync(path.join(logDir, f), "utf-8");
|
|
170
|
+
const field = (key) => new RegExp(`^${key}:[ \\t]*(.+?)[ \\t]*$`, "m").exec(text)?.[1] ?? null;
|
|
171
|
+
const status = field("Status");
|
|
172
|
+
const rel = path.relative(tree, path.join(logDir, f));
|
|
173
|
+
const unfinished = (status === "DECIDED" || status === "ASSUMED") && !finished.includes(rel);
|
|
174
|
+
if (status !== "OPEN" && !unfinished)
|
|
175
|
+
continue;
|
|
176
|
+
// `Gate:` counts only in the header block (the lines before the first blank line).
|
|
177
|
+
const header = text.split(/\r?\n[ \t]*\r?\n/, 1)[0] ?? "";
|
|
178
|
+
const gate = /^Gate:[ \t]*(.+?)[ \t]*$/m.exec(header)?.[1] ?? null;
|
|
179
|
+
const num = (key) => {
|
|
180
|
+
const v = field(key);
|
|
181
|
+
return v !== null && /^[0-9]+$/.test(v) ? Number(v) : null;
|
|
182
|
+
};
|
|
183
|
+
return {
|
|
184
|
+
file: rel,
|
|
185
|
+
decision: n,
|
|
186
|
+
question: field("Question"),
|
|
187
|
+
from: field("From"),
|
|
188
|
+
pauseStep: num("Pause step"),
|
|
189
|
+
group: num("Group"),
|
|
190
|
+
verifyAttempt: num("Verify attempt"),
|
|
191
|
+
testAttempt: num("Test attempt"),
|
|
192
|
+
plan: field("Plan"),
|
|
193
|
+
gate,
|
|
194
|
+
sourceChanged: field("Source changed"),
|
|
195
|
+
status: status ?? "OPEN",
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
@@ -53,6 +53,12 @@ function firstTable(lines, heading) {
|
|
|
53
53
|
return null;
|
|
54
54
|
return { head, cols: tableCells(lines[head]) };
|
|
55
55
|
}
|
|
56
|
+
/** The test tier `docs/testing.md` records for a test file's name. */
|
|
57
|
+
export const testTier = (file) => /\.integration\.test\./.test(file)
|
|
58
|
+
? "Integration"
|
|
59
|
+
: /\.live\.test\./.test(file)
|
|
60
|
+
? "@live (golden)"
|
|
61
|
+
: "Unit";
|
|
56
62
|
/**
|
|
57
63
|
* The plan's Reuse Inventory: the first table under the first heading naming Reuse
|
|
58
64
|
* Inventory, before the next heading of the same or a higher level. Each row's `File`
|
|
@@ -197,7 +197,7 @@ export const plansCommand = {
|
|
|
197
197
|
month: String(ctx.flags.month),
|
|
198
198
|
fid: String(ctx.flags.fid),
|
|
199
199
|
});
|
|
200
|
-
ctx.emit({ comment: body, commentFile: commentFileOf(ctx.cwd, body), plans });
|
|
200
|
+
ctx.emit({ comment: body, commentFile: commentFileOf(ctx.cwd, body, ctx), plans });
|
|
201
201
|
return EXIT.OK;
|
|
202
202
|
},
|
|
203
203
|
},
|