@codyswann/lisa 8.8.0 → 8.9.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/README.md +21 -0
- package/all/copy-overwrite/scripts/lib/completion-authorization.mjs +54 -0
- package/all/copy-overwrite/scripts/lib/completion-proof-adapters.mjs +59 -0
- package/all/copy-overwrite/scripts/lib/completion-proof-markdown.mjs +1 -1
- package/all/copy-overwrite/scripts/lib/npm-update-helper-inventory.mjs +1 -0
- package/all/copy-overwrite/scripts/lib/release-switch.d.mts +91 -0
- package/all/copy-overwrite/scripts/lib/release-switch.mjs +1049 -0
- package/all/copy-overwrite/scripts/lisa-release-switch.mjs +203 -0
- package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +17 -4
- package/dist/cli/doctor-release-setting.d.ts +8 -0
- package/dist/cli/doctor-release-setting.d.ts.map +1 -0
- package/dist/cli/doctor-release-setting.js +71 -0
- package/dist/cli/doctor-release-setting.js.map +1 -0
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +2 -0
- package/dist/cli/doctor.js.map +1 -1
- package/dist/core/lisa-owned-hash-ledger.json +112 -4
- package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.json +73 -26
- package/package.json +4 -4
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-doctor/SKILL.md +10 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-drive-pr-to-merge/SKILL.md +9 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-git-submit-pr/SKILL.md +1 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-github-validate-issue/SKILL.md +27 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-github-write-issue/SKILL.md +23 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-implement/SKILL.md +10 -2
- package/plugins/lisa/.codex-plugin/skills/lisa-jira-validate-ticket/SKILL.md +27 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-jira-write-ticket/SKILL.md +23 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-linear-validate-issue/SKILL.md +26 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-linear-write-issue/SKILL.md +23 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-task-decomposition/SKILL.md +1 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-track/SKILL.md +2 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-verify/SKILL.md +4 -1
- package/plugins/lisa/hooks/inject-resolved-config.mjs +235 -3
- package/plugins/lisa/rules/eager/coding-philosophy.md +7 -6
- package/plugins/lisa/rules/reference/coding-philosophy.md +48 -0
- package/plugins/lisa/rules/reference/config-resolution.md +4 -1
- package/plugins/lisa/rules/reference/intent-routing.md +2 -2
- package/plugins/lisa/rules/reference/work-item-definition-of-ready.md +31 -0
- package/plugins/lisa/skills/lisa-doctor/SKILL.md +10 -0
- package/plugins/lisa/skills/lisa-drive-pr-to-merge/SKILL.md +9 -0
- package/plugins/lisa/skills/lisa-git-submit-pr/SKILL.md +1 -0
- package/plugins/lisa/skills/lisa-github-validate-issue/SKILL.md +27 -1
- package/plugins/lisa/skills/lisa-github-write-issue/SKILL.md +23 -0
- package/plugins/lisa/skills/lisa-implement/SKILL.md +10 -2
- package/plugins/lisa/skills/lisa-jira-validate-ticket/SKILL.md +27 -1
- package/plugins/lisa/skills/lisa-jira-write-ticket/SKILL.md +23 -0
- package/plugins/lisa/skills/lisa-linear-validate-issue/SKILL.md +26 -0
- package/plugins/lisa/skills/lisa-linear-write-issue/SKILL.md +23 -0
- package/plugins/lisa/skills/lisa-task-decomposition/SKILL.md +1 -0
- package/plugins/lisa/skills/lisa-track/SKILL.md +2 -0
- package/plugins/lisa/skills/lisa-verify/SKILL.md +4 -1
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-agy/skills/lisa-doctor/SKILL.md +10 -0
- package/plugins/lisa-agy/skills/lisa-drive-pr-to-merge/SKILL.md +9 -0
- package/plugins/lisa-agy/skills/lisa-git-submit-pr/SKILL.md +1 -0
- package/plugins/lisa-agy/skills/lisa-github-validate-issue/SKILL.md +27 -1
- package/plugins/lisa-agy/skills/lisa-github-write-issue/SKILL.md +23 -0
- package/plugins/lisa-agy/skills/lisa-implement/SKILL.md +10 -2
- package/plugins/lisa-agy/skills/lisa-jira-validate-ticket/SKILL.md +27 -1
- package/plugins/lisa-agy/skills/lisa-jira-write-ticket/SKILL.md +23 -0
- package/plugins/lisa-agy/skills/lisa-linear-validate-issue/SKILL.md +26 -0
- package/plugins/lisa-agy/skills/lisa-linear-write-issue/SKILL.md +23 -0
- package/plugins/lisa-agy/skills/lisa-task-decomposition/SKILL.md +1 -0
- package/plugins/lisa-agy/skills/lisa-track/SKILL.md +2 -0
- package/plugins/lisa-agy/skills/lisa-verify/SKILL.md +4 -1
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/hooks/inject-resolved-config.mjs +235 -3
- package/plugins/lisa-copilot/rules/eager/coding-philosophy.md +7 -6
- package/plugins/lisa-copilot/rules/reference/coding-philosophy.md +48 -0
- package/plugins/lisa-copilot/rules/reference/config-resolution.md +4 -1
- package/plugins/lisa-copilot/rules/reference/intent-routing.md +2 -2
- package/plugins/lisa-copilot/rules/reference/work-item-definition-of-ready.md +31 -0
- package/plugins/lisa-copilot/skills/lisa-doctor/SKILL.md +10 -0
- package/plugins/lisa-copilot/skills/lisa-drive-pr-to-merge/SKILL.md +9 -0
- package/plugins/lisa-copilot/skills/lisa-git-submit-pr/SKILL.md +1 -0
- package/plugins/lisa-copilot/skills/lisa-github-validate-issue/SKILL.md +27 -1
- package/plugins/lisa-copilot/skills/lisa-github-write-issue/SKILL.md +23 -0
- package/plugins/lisa-copilot/skills/lisa-implement/SKILL.md +10 -2
- package/plugins/lisa-copilot/skills/lisa-jira-validate-ticket/SKILL.md +27 -1
- package/plugins/lisa-copilot/skills/lisa-jira-write-ticket/SKILL.md +23 -0
- package/plugins/lisa-copilot/skills/lisa-linear-validate-issue/SKILL.md +26 -0
- package/plugins/lisa-copilot/skills/lisa-linear-write-issue/SKILL.md +23 -0
- package/plugins/lisa-copilot/skills/lisa-task-decomposition/SKILL.md +1 -0
- package/plugins/lisa-copilot/skills/lisa-track/SKILL.md +2 -0
- package/plugins/lisa-copilot/skills/lisa-verify/SKILL.md +4 -1
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/hooks/inject-resolved-config.mjs +235 -3
- package/plugins/lisa-cursor/rules/coding-philosophy-reference.mdc +48 -0
- package/plugins/lisa-cursor/rules/coding-philosophy.mdc +7 -6
- package/plugins/lisa-cursor/rules/config-resolution-reference.mdc +4 -1
- package/plugins/lisa-cursor/rules/intent-routing-reference.mdc +2 -2
- package/plugins/lisa-cursor/rules/work-item-definition-of-ready-reference.mdc +31 -0
- package/plugins/lisa-cursor/skills/lisa-doctor/SKILL.md +10 -0
- package/plugins/lisa-cursor/skills/lisa-drive-pr-to-merge/SKILL.md +9 -0
- package/plugins/lisa-cursor/skills/lisa-git-submit-pr/SKILL.md +1 -0
- package/plugins/lisa-cursor/skills/lisa-github-validate-issue/SKILL.md +27 -1
- package/plugins/lisa-cursor/skills/lisa-github-write-issue/SKILL.md +23 -0
- package/plugins/lisa-cursor/skills/lisa-implement/SKILL.md +10 -2
- package/plugins/lisa-cursor/skills/lisa-jira-validate-ticket/SKILL.md +27 -1
- package/plugins/lisa-cursor/skills/lisa-jira-write-ticket/SKILL.md +23 -0
- package/plugins/lisa-cursor/skills/lisa-linear-validate-issue/SKILL.md +26 -0
- package/plugins/lisa-cursor/skills/lisa-linear-write-issue/SKILL.md +23 -0
- package/plugins/lisa-cursor/skills/lisa-task-decomposition/SKILL.md +1 -0
- package/plugins/lisa-cursor/skills/lisa-track/SKILL.md +2 -0
- package/plugins/lisa-cursor/skills/lisa-verify/SKILL.md +4 -1
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/hooks/inject-resolved-config.mjs +235 -3
- package/plugins/lisa-devin/rules/eager/coding-philosophy.md +7 -6
- package/plugins/lisa-devin/rules/reference/coding-philosophy.md +48 -0
- package/plugins/lisa-devin/rules/reference/config-resolution.md +4 -1
- package/plugins/lisa-devin/rules/reference/intent-routing.md +2 -2
- package/plugins/lisa-devin/rules/reference/work-item-definition-of-ready.md +31 -0
- package/plugins/lisa-devin/skills/lisa-doctor/SKILL.md +10 -0
- package/plugins/lisa-devin/skills/lisa-drive-pr-to-merge/SKILL.md +9 -0
- package/plugins/lisa-devin/skills/lisa-git-submit-pr/SKILL.md +1 -0
- package/plugins/lisa-devin/skills/lisa-github-validate-issue/SKILL.md +27 -1
- package/plugins/lisa-devin/skills/lisa-github-write-issue/SKILL.md +23 -0
- package/plugins/lisa-devin/skills/lisa-implement/SKILL.md +10 -2
- package/plugins/lisa-devin/skills/lisa-jira-validate-ticket/SKILL.md +27 -1
- package/plugins/lisa-devin/skills/lisa-jira-write-ticket/SKILL.md +23 -0
- package/plugins/lisa-devin/skills/lisa-linear-validate-issue/SKILL.md +26 -0
- package/plugins/lisa-devin/skills/lisa-linear-write-issue/SKILL.md +23 -0
- package/plugins/lisa-devin/skills/lisa-task-decomposition/SKILL.md +1 -0
- package/plugins/lisa-devin/skills/lisa-track/SKILL.md +2 -0
- package/plugins/lisa-devin/skills/lisa-verify/SKILL.md +4 -1
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/src/base/hooks/inject-resolved-config.mjs +235 -3
- package/plugins/src/base/rules/eager/coding-philosophy.md +7 -6
- package/plugins/src/base/rules/reference/coding-philosophy.md +48 -0
- package/plugins/src/base/rules/reference/config-resolution.md +4 -1
- package/plugins/src/base/rules/reference/intent-routing.md +2 -2
- package/plugins/src/base/rules/reference/work-item-definition-of-ready.md +31 -0
- package/plugins/src/base/skills/lisa-doctor/SKILL.md +10 -0
- package/plugins/src/base/skills/lisa-drive-pr-to-merge/SKILL.md +9 -0
- package/plugins/src/base/skills/lisa-git-submit-pr/SKILL.md +1 -0
- package/plugins/src/base/skills/lisa-github-validate-issue/SKILL.md +27 -1
- package/plugins/src/base/skills/lisa-github-write-issue/SKILL.md +23 -0
- package/plugins/src/base/skills/lisa-implement/SKILL.md +10 -2
- package/plugins/src/base/skills/lisa-jira-validate-ticket/SKILL.md +27 -1
- package/plugins/src/base/skills/lisa-jira-write-ticket/SKILL.md +23 -0
- package/plugins/src/base/skills/lisa-linear-validate-issue/SKILL.md +26 -0
- package/plugins/src/base/skills/lisa-linear-write-issue/SKILL.md +23 -0
- package/plugins/src/base/skills/lisa-task-decomposition/SKILL.md +1 -0
- package/plugins/src/base/skills/lisa-track/SKILL.md +2 -0
- package/plugins/src/base/skills/lisa-verify/SKILL.md +4 -1
- package/scripts/lisa-release-switch.mjs +9 -0
- package/scripts/two-channel-couplings.json +1 -1
- package/typescript/copy-overwrite/.prettierignore +2 -0
|
@@ -0,0 +1,1049 @@
|
|
|
1
|
+
// This file is managed by Lisa and IS replaced on each `lisa` run.
|
|
2
|
+
// Do not edit directly — durable changes belong upstream in Lisa.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The always-promotable contract (CodySwannGT/lisa#5188): one definition of
|
|
6
|
+
* the project setting, the work-item declaration and the checks built on them.
|
|
7
|
+
*
|
|
8
|
+
* The rule: whatever is on a shared branch can be promoted to the next
|
|
9
|
+
* environment as it stands. Most changes meet it by being complete and proven
|
|
10
|
+
* when they merge. Only new behavior that merges before it is finished or
|
|
11
|
+
* verified is switched off, and that switch is removed afterwards.
|
|
12
|
+
*
|
|
13
|
+
* Three things live here so that the validators, the writers, the completion
|
|
14
|
+
* checker, the doctor check and the session-start hook cannot drift apart:
|
|
15
|
+
*
|
|
16
|
+
* 1. `release.*` in `.lisa.config.json`. `release.liveUsers` is a fact about
|
|
17
|
+
* the project, not an "off" flag for a rule: a project with no users has
|
|
18
|
+
* nothing to protect. Absent means the project HAS live users, and a value
|
|
19
|
+
* that is not a boolean is reported and treated as `true`, the stricter
|
|
20
|
+
* option (the same convention as `workItem.estimate.required`).
|
|
21
|
+
* 2. The `## Release Switch` declaration on a work item: live, or switched off
|
|
22
|
+
* behind a named switch that a named work item removes.
|
|
23
|
+
* 3. The switch-removal check: a work item that owns the removal of a switch
|
|
24
|
+
* is not finished while tracked source still references that switch.
|
|
25
|
+
*
|
|
26
|
+
* Lisa deliberately knows nothing about any flag service. A project names its
|
|
27
|
+
* mechanism; this module only carries the name to the agent.
|
|
28
|
+
* @module scripts/lib/release-switch
|
|
29
|
+
*/
|
|
30
|
+
import { spawnSync } from "node:child_process";
|
|
31
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
32
|
+
import { join } from "node:path";
|
|
33
|
+
|
|
34
|
+
import {
|
|
35
|
+
headingKey,
|
|
36
|
+
markdownSection,
|
|
37
|
+
topLevelLines,
|
|
38
|
+
} from "./completion-proof-markdown.mjs";
|
|
39
|
+
|
|
40
|
+
/** Heading of the work-item section that carries the declaration. */
|
|
41
|
+
export const RELEASE_SWITCH_HEADING = "Release Switch";
|
|
42
|
+
|
|
43
|
+
/** The decision class a project lists in `humanGate.humanOnly` to reserve the production turn-on for a person. */
|
|
44
|
+
export const RELEASE_DECISION_CLASS = "feature-release";
|
|
45
|
+
|
|
46
|
+
/** What an agent uses when a project names no mechanism: a plain configuration value that defaults to off. */
|
|
47
|
+
export const FALLBACK_MECHANISM = "config-value";
|
|
48
|
+
|
|
49
|
+
/** The exact text of the live declaration. */
|
|
50
|
+
export const LIVE_DECLARATION = "Live — complete and proven at merge";
|
|
51
|
+
|
|
52
|
+
/** A switch-removal owner written as the item itself. */
|
|
53
|
+
export const THIS_ITEM = "this item";
|
|
54
|
+
|
|
55
|
+
/** Thrown for input this module cannot act on; the CLI maps it to exit 2. */
|
|
56
|
+
export class ReleaseSwitchError extends Error {}
|
|
57
|
+
|
|
58
|
+
const SWITCH_NAME = /^[A-Za-z0-9][A-Za-z0-9._:/-]{2,63}$/;
|
|
59
|
+
// One small pattern per tracker shape (owner/repo#12, #12, ENG-12) instead of
|
|
60
|
+
// one alternation: each stays linear to match and readable on its own.
|
|
61
|
+
const WORK_ITEM_REF_FORMS = [
|
|
62
|
+
/^[\w.-]+\/[\w.-]+#[1-9]\d*$/,
|
|
63
|
+
/^#[1-9]\d*$/,
|
|
64
|
+
/^[A-Z][A-Z0-9]+-[1-9]\d*$/,
|
|
65
|
+
];
|
|
66
|
+
const isWorkItemRef = value =>
|
|
67
|
+
WORK_ITEM_REF_FORMS.some(form => form.test(value));
|
|
68
|
+
// The rendered form uses an em dash. An en dash, a hyphen and a double hyphen
|
|
69
|
+
// are read as the same thing, because that is what people and editors type.
|
|
70
|
+
const LIVE = /^Live\s*(?:--|[—–-])\s*complete and proven at merge\.?$/i;
|
|
71
|
+
const SWITCHED_OFF_LABEL = "switched off";
|
|
72
|
+
const REMOVED_BY_LABEL = "removed by";
|
|
73
|
+
const DASHES = ["--", "—", "–", "-"];
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The text after `<label> —`, read with string operations so a long or odd
|
|
77
|
+
* line cannot make a pattern backtrack.
|
|
78
|
+
* @param {string} line - One declaration line.
|
|
79
|
+
* @param {string} label - Lower-case label the line must start with.
|
|
80
|
+
* @returns {string|null} Trimmed remainder, or `null` when the line has another shape.
|
|
81
|
+
*/
|
|
82
|
+
function afterLabel(line, label) {
|
|
83
|
+
if (!line.toLowerCase().startsWith(label)) return null;
|
|
84
|
+
const rest = line.slice(label.length).trimStart();
|
|
85
|
+
const dash = DASHES.find(candidate => rest.startsWith(candidate));
|
|
86
|
+
return dash === undefined ? null : rest.slice(dash.length).trim();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// JIRA descriptions are written in wiki markup, where a section heading is
|
|
90
|
+
// `h2. Name` and not `## Name`. Both spellings are the same heading here, so a
|
|
91
|
+
// ticket in the JIRA writer's own shape is read like any other.
|
|
92
|
+
//
|
|
93
|
+
// Wiki code blocks (`{code}` … `{code}`) are deliberately NOT understood. An
|
|
94
|
+
// earlier version skipped headings quoted inside them, and every way of
|
|
95
|
+
// pairing the markers could be fooled into hiding the real declaration below a
|
|
96
|
+
// stray one, which let the done gate close an item whose switch was still in
|
|
97
|
+
// use. Without it, a ticket that quotes the section inside a wiki code block
|
|
98
|
+
// has two declarations and is refused as ambiguous: it fails closed.
|
|
99
|
+
const WIKI_HEADING = /^h([1-6])\.[ \t]+/;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* A body with wiki-markup headings rewritten as markdown ones, line for line.
|
|
103
|
+
* @param {string} body - Work-item body.
|
|
104
|
+
* @returns {string} The same lines, with `hN. ` headings as `#` headings.
|
|
105
|
+
*/
|
|
106
|
+
function markdownHeadings(body) {
|
|
107
|
+
return body
|
|
108
|
+
.split("\n")
|
|
109
|
+
.map(line => {
|
|
110
|
+
const wiki = WIKI_HEADING.exec(line);
|
|
111
|
+
return wiki
|
|
112
|
+
? `${"#".repeat(Number(wiki[1]))} ${line.slice(wiki[0].length)}`
|
|
113
|
+
: line;
|
|
114
|
+
})
|
|
115
|
+
.join("\n");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// A `None —` declaration is how `## Target Backend Environment` says the item
|
|
119
|
+
// changes no runtime behavior (or is a container). The em dash is the machine
|
|
120
|
+
// discriminator the validators already use (gate S8).
|
|
121
|
+
const NO_RUNTIME = /^None\s*[—-]/i;
|
|
122
|
+
|
|
123
|
+
const isObject = value =>
|
|
124
|
+
value !== null && typeof value === "object" && !Array.isArray(value);
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A rejected setting value as it may be shown to a person or put in a
|
|
128
|
+
* session's context. An object or a list is named by its kind only: whatever
|
|
129
|
+
* someone put inside a setting that should have been a word or a yes/no is not
|
|
130
|
+
* ours to print, and it could be a credential.
|
|
131
|
+
* @param {unknown} value - The value a project declared.
|
|
132
|
+
* @returns {string} Text safe to show.
|
|
133
|
+
*/
|
|
134
|
+
export function shown(value) {
|
|
135
|
+
if (Array.isArray(value)) return "a list";
|
|
136
|
+
if (value !== null && typeof value === "object") return "an object";
|
|
137
|
+
if (typeof value !== "string") return JSON.stringify(value);
|
|
138
|
+
// A mistyped yes/no or mechanism name is a short plain word, and showing it
|
|
139
|
+
// helps ("no", "false", "hosted flags"). Anything else is not what belonged
|
|
140
|
+
// in the setting, and it is described, never quoted: a URL with a password
|
|
141
|
+
// in it stays a credential however much of it is cut off.
|
|
142
|
+
return PLAIN_WORD.test(value)
|
|
143
|
+
? JSON.stringify(value)
|
|
144
|
+
: `a string of ${value.length} characters`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** A short value made only of letters, digits, spaces, dots, underscores and hyphens. */
|
|
148
|
+
const PLAIN_WORD = /^[\w .-]{0,40}$/;
|
|
149
|
+
|
|
150
|
+
const text = value =>
|
|
151
|
+
typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
152
|
+
|
|
153
|
+
const readJson = path =>
|
|
154
|
+
existsSync(path) ? JSON.parse(readFileSync(path, "utf8")) : {};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The project's Lisa config with `.lisa.config.local.json` layered on top,
|
|
158
|
+
* key by key. One reader for the CLI and the doctor check, so the two cannot
|
|
159
|
+
* disagree about which file wins.
|
|
160
|
+
* @param {string} cwd - Project root.
|
|
161
|
+
* @returns {object} Effective config.
|
|
162
|
+
*/
|
|
163
|
+
export function readProjectConfig(cwd) {
|
|
164
|
+
const merge = (base, override) => {
|
|
165
|
+
// Only an ABSENT local key falls back. A local `null` is a declared value
|
|
166
|
+
// (an invalid one), read the same way the session-start hook and the
|
|
167
|
+
// completion checker read it.
|
|
168
|
+
if (override === undefined) return base;
|
|
169
|
+
if (!isObject(base) || !isObject(override)) return override;
|
|
170
|
+
const keys = new Set([...Object.keys(base), ...Object.keys(override)]);
|
|
171
|
+
return Object.fromEntries(
|
|
172
|
+
[...keys].map(key => [
|
|
173
|
+
key,
|
|
174
|
+
key in override ? merge(base[key], override[key]) : base[key],
|
|
175
|
+
])
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
const committed = readJson(join(cwd, ".lisa.config.json"));
|
|
179
|
+
// A config file that is not an object is handed back as it is, so the
|
|
180
|
+
// problem can be reported; merging would quietly turn it into `{}`.
|
|
181
|
+
if (!isObject(committed)) return committed;
|
|
182
|
+
return merge(committed, readJson(join(cwd, ".lisa.config.local.json")));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Problems for keys a settings block carries that Lisa does not read.
|
|
187
|
+
* @param {object} block - The settings block.
|
|
188
|
+
* @param {string[]} known - Keys Lisa reads.
|
|
189
|
+
* @param {string} path - Dotted path of the block, for the message.
|
|
190
|
+
* @returns {string[]} One problem per unknown key.
|
|
191
|
+
*/
|
|
192
|
+
function unknownKeys(block, known, path) {
|
|
193
|
+
return Object.keys(block)
|
|
194
|
+
.filter(key => !known.includes(key) && !key.startsWith("_"))
|
|
195
|
+
.map(key => {
|
|
196
|
+
const near = known.find(
|
|
197
|
+
candidate => candidate.toLowerCase() === key.toLowerCase()
|
|
198
|
+
);
|
|
199
|
+
return `${path}.${key} is not a setting Lisa reads${near ? `; did you mean ${path}.${near}?` : `; the settings are ${known.map(name => `${path}.${name}`).join(" and ")}.`}`;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The comparable form of a decision class: lower case, with hyphens,
|
|
205
|
+
* underscores and slashes read as spaces. It mirrors `normalizeGateText` in
|
|
206
|
+
* the plugin's `intake-blocker-reprobe.mjs` (not importable from a shipped
|
|
207
|
+
* script), which is what decides whether a hold naming the class is valid; a
|
|
208
|
+
* test pins the two together. Without it `"Feature Release"` would hold a
|
|
209
|
+
* ticket for a person while this module told the agent to go ahead.
|
|
210
|
+
* @param {unknown} value - A decision class as a project wrote it.
|
|
211
|
+
* @returns {string} Normalized text.
|
|
212
|
+
*/
|
|
213
|
+
function decisionClassKey(value) {
|
|
214
|
+
return String(value ?? "")
|
|
215
|
+
.toLowerCase()
|
|
216
|
+
.replace(/[-_/]+/g, " ")
|
|
217
|
+
.replace(/[^a-z0-9' ]+/g, " ")
|
|
218
|
+
.replace(/'/g, "")
|
|
219
|
+
.replace(/\s+/g, " ")
|
|
220
|
+
.trim();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Who turns a finished, switched-off feature on in production: the agent,
|
|
225
|
+
* unless the project reserved that decision for a person by listing
|
|
226
|
+
* `feature-release` in `humanGate.humanOnly`.
|
|
227
|
+
* @param {object} [config] - Effective project config.
|
|
228
|
+
* @returns {"agent"|"human"} Who performs the turn-on.
|
|
229
|
+
*/
|
|
230
|
+
export function turnOnOwner(config = {}) {
|
|
231
|
+
const declared = config?.humanGate?.humanOnly;
|
|
232
|
+
// A project that wrote the class as a bare string meant to reserve the step.
|
|
233
|
+
// Reading that as "not reserved" would hand a production turn-on to the
|
|
234
|
+
// agent because of a typing mistake, so it is read as a one-item list here
|
|
235
|
+
// and reported by {@link turnOnProblems}.
|
|
236
|
+
const reserved = (
|
|
237
|
+
Array.isArray(declared)
|
|
238
|
+
? declared
|
|
239
|
+
: typeof declared === "string"
|
|
240
|
+
? [declared]
|
|
241
|
+
: []
|
|
242
|
+
).filter(entry => typeof entry === "string");
|
|
243
|
+
const wanted = decisionClassKey(RELEASE_DECISION_CLASS);
|
|
244
|
+
return reserved.some(entry => decisionClassKey(entry) === wanted)
|
|
245
|
+
? "human"
|
|
246
|
+
: "agent";
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Problems with how the project reserved decisions for a person, as far as
|
|
251
|
+
* they affect the production turn-on.
|
|
252
|
+
* @param {object} [config] - Effective project config.
|
|
253
|
+
* @returns {string[]} Problems, empty when `humanGate.humanOnly` is absent or a list.
|
|
254
|
+
*/
|
|
255
|
+
export function turnOnProblems(config = {}) {
|
|
256
|
+
const declared = config?.humanGate?.humanOnly;
|
|
257
|
+
if (Array.isArray(declared))
|
|
258
|
+
// An entry that is not text names no decision class. It is reported and
|
|
259
|
+
// skipped, so one bad entry cannot hide a valid reservation beside it.
|
|
260
|
+
return declared.some(entry => typeof entry !== "string")
|
|
261
|
+
? [
|
|
262
|
+
`humanGate.humanOnly holds an entry that is not text; each entry is a decision class such as "${RELEASE_DECISION_CLASS}". That entry is ignored.`,
|
|
263
|
+
]
|
|
264
|
+
: [];
|
|
265
|
+
return declared === undefined
|
|
266
|
+
? []
|
|
267
|
+
: [
|
|
268
|
+
`humanGate.humanOnly is ${shown(declared)}, which is not a list; write it as a list such as ["${RELEASE_DECISION_CLASS}"]. Until then the production turn-on is treated as ${turnOnOwner(config) === "human" ? "reserved for a person" : "the agent's"}.`,
|
|
269
|
+
];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Every problem with how a project set this rule up: invalid `release.*`
|
|
274
|
+
* values, a `humanGate.humanOnly` that is not a list, and a production branch
|
|
275
|
+
* that cannot be read while the project is marked as having no live users (the
|
|
276
|
+
* notice that keeps that opt-out visible could then never print). One list for
|
|
277
|
+
* the CLI and the doctor check, so neither reports less than the other.
|
|
278
|
+
* @param {object} [config] - Effective project config.
|
|
279
|
+
* @returns {string[]} Problems, empty when the setup is sound.
|
|
280
|
+
*/
|
|
281
|
+
export function setupProblems(config = {}) {
|
|
282
|
+
if (!isObject(config))
|
|
283
|
+
return [
|
|
284
|
+
"The Lisa configuration is not a JSON object, so no release setting can be read from it; the project is treated as having live users.",
|
|
285
|
+
];
|
|
286
|
+
const setting = resolveReleaseSetting(config);
|
|
287
|
+
return [
|
|
288
|
+
...setting.problems,
|
|
289
|
+
...turnOnProblems(config),
|
|
290
|
+
...(!setting.liveUsers && productionBranch(config) === null
|
|
291
|
+
? [
|
|
292
|
+
"release.liveUsers is false, but deploy.branches does not name one production branch (it has no production environment, or prod and production name different branches), so the notice on production deployments cannot be printed.",
|
|
293
|
+
]
|
|
294
|
+
: []),
|
|
295
|
+
];
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Resolve `release.*` from an effective project config.
|
|
300
|
+
*
|
|
301
|
+
* Nothing here throws on a bad value: a malformed setting is reported in
|
|
302
|
+
* `problems` and the stricter reading is used, so one typo cannot silently
|
|
303
|
+
* turn the rule off, and cannot stop a session either.
|
|
304
|
+
* @param {object} [config] - Effective `.lisa.config.json` (local overrides applied).
|
|
305
|
+
* @returns {{liveUsers: boolean, liveUsersSource: "declared"|"default"|"invalid", mechanism: string, mechanismSource: "declared"|"default", guide: string|null, problems: string[]}} Resolved setting.
|
|
306
|
+
*/
|
|
307
|
+
export function resolveReleaseSetting(config = {}) {
|
|
308
|
+
const declared = isObject(config) ? config.release : undefined;
|
|
309
|
+
const block = isObject(declared) ? declared : {};
|
|
310
|
+
const switchBlock = isObject(block.switch) ? block.switch : {};
|
|
311
|
+
const liveDeclared = Object.hasOwn(block, "liveUsers");
|
|
312
|
+
const liveValid = typeof block.liveUsers === "boolean";
|
|
313
|
+
const mechanism = text(switchBlock.mechanism);
|
|
314
|
+
const problems = [
|
|
315
|
+
...(declared === undefined || isObject(declared)
|
|
316
|
+
? []
|
|
317
|
+
: [
|
|
318
|
+
`release is ${shown(declared)}, which is not an object; treated as not set.`,
|
|
319
|
+
]),
|
|
320
|
+
...(liveDeclared && !liveValid
|
|
321
|
+
? [
|
|
322
|
+
`release.liveUsers is ${shown(block.liveUsers)}, which is not true or false; treated as true (the project has live users).`,
|
|
323
|
+
]
|
|
324
|
+
: []),
|
|
325
|
+
...(block.switch === undefined || isObject(block.switch)
|
|
326
|
+
? []
|
|
327
|
+
: [
|
|
328
|
+
`release.switch is ${shown(block.switch)}, which is not an object; treated as not set.`,
|
|
329
|
+
]),
|
|
330
|
+
...["mechanism", "guide"].flatMap(key =>
|
|
331
|
+
Object.hasOwn(switchBlock, key) && text(switchBlock[key]) === null
|
|
332
|
+
? [
|
|
333
|
+
`release.switch.${key} is ${shown(switchBlock[key])}, which is not a non-empty string; treated as not set.`,
|
|
334
|
+
]
|
|
335
|
+
: []
|
|
336
|
+
),
|
|
337
|
+
// A misspelt key is the quiet way to believe the rule is off when it is
|
|
338
|
+
// not, so every key Lisa does not read is named.
|
|
339
|
+
...unknownKeys(block, ["liveUsers", "switch"], "release"),
|
|
340
|
+
...unknownKeys(switchBlock, ["mechanism", "guide"], "release.switch"),
|
|
341
|
+
];
|
|
342
|
+
return {
|
|
343
|
+
liveUsers: liveValid ? block.liveUsers : true,
|
|
344
|
+
liveUsersSource: !liveDeclared
|
|
345
|
+
? "default"
|
|
346
|
+
: liveValid
|
|
347
|
+
? "declared"
|
|
348
|
+
: "invalid",
|
|
349
|
+
mechanism: mechanism ?? FALLBACK_MECHANISM,
|
|
350
|
+
mechanismSource: mechanism === null ? "default" : "declared",
|
|
351
|
+
guide: text(switchBlock.guide),
|
|
352
|
+
problems,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Whether an item changes runtime behavior, read off its stored
|
|
358
|
+
* `## Target Backend Environment` declaration.
|
|
359
|
+
*
|
|
360
|
+
* An absent section is `underivable`, never "no": reading absence as "no" is
|
|
361
|
+
* the assumption that once made the environment gates undecidable on a live
|
|
362
|
+
* item, and this gate inherits the same case table on purpose.
|
|
363
|
+
* @param {string} body - Work-item body.
|
|
364
|
+
* @returns {"runtime"|"none"|"underivable"} The item's scope.
|
|
365
|
+
*/
|
|
366
|
+
export function runtimeScope(body) {
|
|
367
|
+
const declaration = markdownSection(
|
|
368
|
+
markdownHeadings(body),
|
|
369
|
+
"Target Backend Environment"
|
|
370
|
+
);
|
|
371
|
+
if (declaration === "") return "underivable";
|
|
372
|
+
return NO_RUNTIME.test(declaration) ? "none" : "runtime";
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Parse the switched-off form's tail: `<switch>; removed by <owner>`.
|
|
377
|
+
* @param {string} tail - Text after `Switched off —`.
|
|
378
|
+
* @returns {{mode: "off", switchName: string, removedBy: string} | {mode: "invalid", problems: string[]}} Parsed form.
|
|
379
|
+
*/
|
|
380
|
+
function parseSwitchedOff(tail) {
|
|
381
|
+
const [nameText = "", ...rest] = tail.split(";");
|
|
382
|
+
const switchName = nameText.trim();
|
|
383
|
+
const ownerText = rest.join(";").trim();
|
|
384
|
+
const named =
|
|
385
|
+
ownerText.toLowerCase().startsWith(REMOVED_BY_LABEL) &&
|
|
386
|
+
/\s/.test(ownerText[REMOVED_BY_LABEL.length] ?? "");
|
|
387
|
+
const removedBy = named
|
|
388
|
+
? ownerText.slice(REMOVED_BY_LABEL.length).trim().replace(/\.$/, "")
|
|
389
|
+
: "";
|
|
390
|
+
const ownerValid =
|
|
391
|
+
removedBy.toLowerCase() === THIS_ITEM || isWorkItemRef(removedBy);
|
|
392
|
+
const problems = [
|
|
393
|
+
...(SWITCH_NAME.test(switchName)
|
|
394
|
+
? []
|
|
395
|
+
: [
|
|
396
|
+
switchName === ""
|
|
397
|
+
? "It names no switch."
|
|
398
|
+
: `Switch name ${JSON.stringify(switchName)} must be 3 to 64 letters, digits, dots, colons, slashes, underscores or hyphens, with no spaces.`,
|
|
399
|
+
]),
|
|
400
|
+
...(ownerValid
|
|
401
|
+
? []
|
|
402
|
+
: [
|
|
403
|
+
removedBy === ""
|
|
404
|
+
? `It does not say which work item removes the switch: end it with "; removed by ${THIS_ITEM}" or "; removed by <work-item ref>".`
|
|
405
|
+
: `${JSON.stringify(removedBy)} is not "${THIS_ITEM}" or a work-item reference such as #123, owner/repo#123 or ENG-123.`,
|
|
406
|
+
]),
|
|
407
|
+
];
|
|
408
|
+
return problems.length
|
|
409
|
+
? { mode: "invalid", problems }
|
|
410
|
+
: {
|
|
411
|
+
mode: "off",
|
|
412
|
+
switchName,
|
|
413
|
+
removedBy:
|
|
414
|
+
removedBy.toLowerCase() === THIS_ITEM ? THIS_ITEM : removedBy,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Parse one declaration line.
|
|
420
|
+
* @param {string} line - The declaration, trimmed.
|
|
421
|
+
* @returns {{mode: "live"} | {mode: "off", switchName: string, removedBy: string} | {mode: "invalid", problems: string[]}} Parsed form.
|
|
422
|
+
*/
|
|
423
|
+
function parseDeclarationLine(line) {
|
|
424
|
+
if (LIVE.test(line)) return { mode: "live" };
|
|
425
|
+
const off = afterLabel(line, SWITCHED_OFF_LABEL);
|
|
426
|
+
if (off !== null) return parseSwitchedOff(off);
|
|
427
|
+
return {
|
|
428
|
+
mode: "invalid",
|
|
429
|
+
problems: [`${JSON.stringify(line)} is neither of the two forms.`],
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* The declaration heading, folded the way the shared section reader folds it.
|
|
435
|
+
* Lookup, replacement and extraction all use this one comparison: a heading the
|
|
436
|
+
* reader accepts (closing hashes after a tab, odd spacing, another case) that a
|
|
437
|
+
* second comparison missed would read as "no declaration", and an item with no
|
|
438
|
+
* declaration owes nothing.
|
|
439
|
+
*/
|
|
440
|
+
const HEADING_KEY = headingKey(`## ${RELEASE_SWITCH_HEADING}`);
|
|
441
|
+
|
|
442
|
+
const WIKI_BLOCK_KINDS = ["code", "noformat"];
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* The wiki code-block markers on a line, left to right, as block kinds.
|
|
446
|
+
* `{code}`, `{code:java}` and `{noformat}` are markers; anything else is text.
|
|
447
|
+
* @param {string} line - One body line.
|
|
448
|
+
* @returns {string[]} `code` or `noformat` for each marker, in order.
|
|
449
|
+
*/
|
|
450
|
+
function wikiMarkers(line) {
|
|
451
|
+
return line
|
|
452
|
+
.split("{")
|
|
453
|
+
.slice(1)
|
|
454
|
+
.flatMap(piece => {
|
|
455
|
+
const kind = WIKI_BLOCK_KINDS.find(
|
|
456
|
+
name => piece.startsWith(`${name}}`) || piece.startsWith(`${name}:`)
|
|
457
|
+
);
|
|
458
|
+
return kind && piece.includes("}") ? [kind] : [];
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* The wiki block that is still open after these lines, if any.
|
|
464
|
+
*
|
|
465
|
+
* It follows JIRA's own rule: outside a block, a marker opens a block of its
|
|
466
|
+
* kind; inside one, only a marker of the SAME kind closes it, and the other
|
|
467
|
+
* kind is text. Counting markers instead cannot tell `{noformat}{code}` (one
|
|
468
|
+
* open block with text in it) from two blocks.
|
|
469
|
+
* @param {string[]} lines - Body lines above the point in question.
|
|
470
|
+
* @returns {string|null} `code`, `noformat`, or `null` when no block is open.
|
|
471
|
+
*/
|
|
472
|
+
function openWikiBlock(lines) {
|
|
473
|
+
return lines
|
|
474
|
+
.flatMap(wikiMarkers)
|
|
475
|
+
.reduce(
|
|
476
|
+
(open, kind) => (open === null ? kind : open === kind ? null : open),
|
|
477
|
+
/** @type {string|null} */ (null)
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Where an item's `## Release Switch` section is and what it holds.
|
|
483
|
+
*
|
|
484
|
+
* Three states matter and must not collapse into each other: no section at all
|
|
485
|
+
* (a legacy item, or a live one nobody declared), a section whose text can be
|
|
486
|
+
* read, and a section that is there but cannot be trusted. The last has two
|
|
487
|
+
* forms. A blank section is unreadable, not evidence that the item removes
|
|
488
|
+
* nothing. And in a JIRA ticket, a section whose `h2.` heading sits inside a
|
|
489
|
+
* `{code}` or `{noformat}` block that is still open may be a quoted example.
|
|
490
|
+
* It is refused as ambiguous: never trusted as the declaration, and never read
|
|
491
|
+
* as absent (which is how an earlier version let a stray marker hide a real
|
|
492
|
+
* declaration from the done gate).
|
|
493
|
+
* @param {string} body - Work-item body.
|
|
494
|
+
* @returns {null | {text: string, problem: string|null}} `null` when there is no section.
|
|
495
|
+
*/
|
|
496
|
+
function declarationState(body) {
|
|
497
|
+
const lines = body
|
|
498
|
+
.split("\n")
|
|
499
|
+
.map(line => (line.endsWith("\r") ? line.slice(0, -1) : line));
|
|
500
|
+
const normalized = markdownHeadings(lines.join("\n"));
|
|
501
|
+
const lineAt = offset => normalized.slice(0, offset).split("\n").length - 1;
|
|
502
|
+
const match = topLevelLines(normalized)
|
|
503
|
+
.filter(row => row.heading)
|
|
504
|
+
.map(row => ({ line: lineAt(row.start), name: headingKey(row.text) }))
|
|
505
|
+
.find(({ name }) => name === HEADING_KEY);
|
|
506
|
+
if (!match) return null;
|
|
507
|
+
// Duplicate sections are refused here, by the shared section reader.
|
|
508
|
+
const text = markdownSection(normalized, RELEASE_SWITCH_HEADING, {
|
|
509
|
+
anyCase: true,
|
|
510
|
+
});
|
|
511
|
+
if (
|
|
512
|
+
WIKI_HEADING.test(lines[match.line]) &&
|
|
513
|
+
openWikiBlock(lines.slice(0, match.line)) !== null
|
|
514
|
+
)
|
|
515
|
+
return {
|
|
516
|
+
text,
|
|
517
|
+
problem:
|
|
518
|
+
"The section follows an unclosed {code} or {noformat} marker, so it may be a quoted example and not the declaration. Close or remove that marker, or move the section above it.",
|
|
519
|
+
};
|
|
520
|
+
return {
|
|
521
|
+
text,
|
|
522
|
+
problem:
|
|
523
|
+
text === ""
|
|
524
|
+
? "The section is empty. Write the declaration on one line."
|
|
525
|
+
: null,
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Parse an item's `## Release Switch` declaration.
|
|
531
|
+
*
|
|
532
|
+
* The declaration is the whole section, on one line: a second line could say
|
|
533
|
+
* anything, and a checker that read only the first would pass an item whose
|
|
534
|
+
* real plan is in the part it skipped.
|
|
535
|
+
* @param {string} body - Work-item body.
|
|
536
|
+
* @returns {null | {mode: "live"} | {mode: "off", switchName: string, removedBy: string} | {mode: "invalid", problems: string[]}} `null` when the section is absent.
|
|
537
|
+
*/
|
|
538
|
+
export function parseDeclaration(body) {
|
|
539
|
+
const state = declarationState(body);
|
|
540
|
+
if (state === null) return null;
|
|
541
|
+
if (state.problem !== null)
|
|
542
|
+
return { mode: "invalid", problems: [state.problem] };
|
|
543
|
+
if (state.text.includes("\n"))
|
|
544
|
+
return {
|
|
545
|
+
mode: "invalid",
|
|
546
|
+
problems: [
|
|
547
|
+
"The declaration must be the only line in the section; move any explanation into Technical Approach.",
|
|
548
|
+
],
|
|
549
|
+
};
|
|
550
|
+
return parseDeclarationLine(state.text);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
const VALID_FORMS = [
|
|
554
|
+
` ${LIVE_DECLARATION}`,
|
|
555
|
+
` Switched off — <switch-name>; removed by ${THIS_ITEM}`,
|
|
556
|
+
" Switched off — <switch-name>; removed by <work-item ref>",
|
|
557
|
+
];
|
|
558
|
+
|
|
559
|
+
const HOW_TO_CHOOSE =
|
|
560
|
+
"Ask one question: if this were promoted to production right now, would a user see something unfinished or unproven? If no, it is live and needs no switch (bug fixes, small tweaks, refactors and dependency updates are live). If yes, it is switched off.";
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Gate S22: does this item say how it is safe to promote?
|
|
564
|
+
*
|
|
565
|
+
* `existing` separates the two populations the readiness gates already treat
|
|
566
|
+
* differently. A proposed item with no declaration fails, because the writer
|
|
567
|
+
* can still add one. An item already in the tracker with none is not
|
|
568
|
+
* applicable: failing it would turn every legacy queue red for a section
|
|
569
|
+
* nobody had a way to add.
|
|
570
|
+
* @param {string} body - Work-item body.
|
|
571
|
+
* @param {{liveUsers: boolean}} setting - Resolved `release.*` setting.
|
|
572
|
+
* @param {{existing?: boolean}} [options] - Whether the item is already stored in the tracker.
|
|
573
|
+
* @returns {{verdict: "PASS"|"FAIL"|"N/A", lines: string[]}} Verdict and reader-facing lines.
|
|
574
|
+
*/
|
|
575
|
+
export function checkDeclaration(body, setting, { existing = false } = {}) {
|
|
576
|
+
if (!setting.liveUsers)
|
|
577
|
+
return {
|
|
578
|
+
verdict: "N/A",
|
|
579
|
+
lines: [
|
|
580
|
+
"This project is marked as having no live users (release.liveUsers is false), so no declaration is needed.",
|
|
581
|
+
],
|
|
582
|
+
};
|
|
583
|
+
const scope = runtimeScope(body);
|
|
584
|
+
if (scope === "none")
|
|
585
|
+
return {
|
|
586
|
+
verdict: "N/A",
|
|
587
|
+
lines: [
|
|
588
|
+
"The item changes no runtime behavior (or is a container), so there is nothing to promote.",
|
|
589
|
+
],
|
|
590
|
+
};
|
|
591
|
+
const declaration = parseDeclaration(body);
|
|
592
|
+
if (declaration === null) {
|
|
593
|
+
if (existing || scope === "underivable")
|
|
594
|
+
return {
|
|
595
|
+
verdict: existing ? "N/A" : "FAIL",
|
|
596
|
+
lines: existing
|
|
597
|
+
? [
|
|
598
|
+
`This existing item has no ## ${RELEASE_SWITCH_HEADING} section. Repair note: whoever claims it adds one of:`,
|
|
599
|
+
...VALID_FORMS,
|
|
600
|
+
]
|
|
601
|
+
: [
|
|
602
|
+
"The item has no ## Target Backend Environment section, so whether it changes runtime behavior cannot be read. Add that section first.",
|
|
603
|
+
],
|
|
604
|
+
};
|
|
605
|
+
return {
|
|
606
|
+
verdict: "FAIL",
|
|
607
|
+
lines: [
|
|
608
|
+
`The item changes runtime behavior but has no ## ${RELEASE_SWITCH_HEADING} section saying how it is safe to promote. Add the section with exactly one of:`,
|
|
609
|
+
...VALID_FORMS,
|
|
610
|
+
HOW_TO_CHOOSE,
|
|
611
|
+
],
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
if (declaration.mode === "invalid")
|
|
615
|
+
return {
|
|
616
|
+
verdict: "FAIL",
|
|
617
|
+
lines: [
|
|
618
|
+
`The ## ${RELEASE_SWITCH_HEADING} declaration is not valid.`,
|
|
619
|
+
...declaration.problems,
|
|
620
|
+
"Valid forms:",
|
|
621
|
+
...VALID_FORMS,
|
|
622
|
+
],
|
|
623
|
+
};
|
|
624
|
+
return {
|
|
625
|
+
verdict: "PASS",
|
|
626
|
+
lines: [
|
|
627
|
+
declaration.mode === "live"
|
|
628
|
+
? "Declared live: complete and proven at merge, no switch."
|
|
629
|
+
: `Declared switched off behind ${JSON.stringify(declaration.switchName)}; removed by ${declaration.removedBy}.`,
|
|
630
|
+
],
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Render the `## Release Switch` section.
|
|
636
|
+
* @param {{mode: string, switchName?: string, removedBy?: string}} input - `live`, or `off` with a switch and its removal owner.
|
|
637
|
+
* @returns {string} The section, ending in a newline.
|
|
638
|
+
*/
|
|
639
|
+
export function renderDeclaration({ mode, switchName, removedBy = THIS_ITEM }) {
|
|
640
|
+
if (mode === "live")
|
|
641
|
+
return `## ${RELEASE_SWITCH_HEADING}\n\n${LIVE_DECLARATION}\n`;
|
|
642
|
+
if (mode !== "off")
|
|
643
|
+
throw new ReleaseSwitchError(
|
|
644
|
+
`--mode must be live or off, not ${JSON.stringify(mode ?? "")}.`
|
|
645
|
+
);
|
|
646
|
+
const parsed = parseSwitchedOff(
|
|
647
|
+
`${switchName ?? ""}; removed by ${removedBy}`
|
|
648
|
+
);
|
|
649
|
+
if (parsed.mode === "invalid")
|
|
650
|
+
throw new ReleaseSwitchError(parsed.problems.join(" "));
|
|
651
|
+
return `## ${RELEASE_SWITCH_HEADING}\n\nSwitched off — ${parsed.switchName}; removed by ${parsed.removedBy}\n`;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* What survives of an old section when its declaration is replaced: every line
|
|
656
|
+
* after the declaration line itself. Deleting them would lose text a person
|
|
657
|
+
* put there (or the closing marker of a block the line sat in); keeping them
|
|
658
|
+
* means the checker still says they must move.
|
|
659
|
+
* @param {string[]} lines - The old section's lines, heading excluded.
|
|
660
|
+
* @returns {string[]} Lines to keep, with no blank edges.
|
|
661
|
+
*/
|
|
662
|
+
function keptAfterDeclaration(lines) {
|
|
663
|
+
const first = lines.findIndex(line => line.trim() !== "");
|
|
664
|
+
if (first < 0) return [];
|
|
665
|
+
const rest = lines.slice(first + 1);
|
|
666
|
+
const start = rest.findIndex(line => line.trim() !== "");
|
|
667
|
+
if (start < 0) return [];
|
|
668
|
+
const end = rest.findLastIndex(line => line.trim() !== "");
|
|
669
|
+
return rest.slice(start, end + 1);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Put a rendered declaration into a body, replacing the one that is there.
|
|
674
|
+
*
|
|
675
|
+
* The section is found the way the parser finds it: top-level headings only, so
|
|
676
|
+
* a quoted example inside a code fence or a comment is never rewritten. The
|
|
677
|
+
* body keeps its own line endings and its own heading spelling (`## Name`, or
|
|
678
|
+
* `h2. Name` in JIRA wiki markup).
|
|
679
|
+
* @param {string} body - Work-item body.
|
|
680
|
+
* @param {string} section - Output of {@link renderDeclaration}.
|
|
681
|
+
* @returns {string} Body with exactly one declaration.
|
|
682
|
+
*/
|
|
683
|
+
export function upsertDeclaration(body, section) {
|
|
684
|
+
const eol = body.includes("\r\n") ? "\r\n" : "\n";
|
|
685
|
+
const lines = body
|
|
686
|
+
.split("\n")
|
|
687
|
+
.map(line => (line.endsWith("\r") ? line.slice(0, -1) : line));
|
|
688
|
+
const normalized = markdownHeadings(lines.join("\n"));
|
|
689
|
+
const lineAt = offset => normalized.slice(0, offset).split("\n").length - 1;
|
|
690
|
+
const headings = topLevelLines(normalized)
|
|
691
|
+
.filter(row => row.heading)
|
|
692
|
+
.map(row => ({ line: lineAt(row.start), name: headingKey(row.text) }));
|
|
693
|
+
const wiki = headings.some(({ line }) => WIKI_HEADING.test(lines[line]));
|
|
694
|
+
const declaration = section.trimEnd().split("\n").at(-1);
|
|
695
|
+
const rendered = [
|
|
696
|
+
`${wiki ? "h2." : "##"} ${RELEASE_SWITCH_HEADING}`,
|
|
697
|
+
"",
|
|
698
|
+
declaration,
|
|
699
|
+
];
|
|
700
|
+
const matches = headings.filter(({ name }) => name === HEADING_KEY);
|
|
701
|
+
if (matches.length > 1)
|
|
702
|
+
throw new ReleaseSwitchError(
|
|
703
|
+
`The body has more than one ${RELEASE_SWITCH_HEADING} section; remove the extra copies first.`
|
|
704
|
+
);
|
|
705
|
+
if (matches.length === 0)
|
|
706
|
+
return written(
|
|
707
|
+
`${lines.join(eol).trimEnd()}${eol}${eol}${rendered.join(eol)}${eol}`,
|
|
708
|
+
declaration
|
|
709
|
+
);
|
|
710
|
+
const start = matches[0].line;
|
|
711
|
+
const next = headings.find(({ line }) => line > start);
|
|
712
|
+
const end = next ? next.line : lines.length;
|
|
713
|
+
const old = lines.slice(start + 1, end);
|
|
714
|
+
// The first line is what gets replaced. If it opens a code block, replacing
|
|
715
|
+
// it would leave the block's closing marker behind to open a new one, and
|
|
716
|
+
// every section after it would stop being read.
|
|
717
|
+
const first = (old.find(line => line.trim() !== "") ?? "").trim();
|
|
718
|
+
if (
|
|
719
|
+
first.startsWith("```") ||
|
|
720
|
+
first.startsWith("~~~") ||
|
|
721
|
+
first.startsWith("<!--") ||
|
|
722
|
+
wikiMarkers(first).length > 0
|
|
723
|
+
)
|
|
724
|
+
throw new ReleaseSwitchError(
|
|
725
|
+
`The ${RELEASE_SWITCH_HEADING} section starts with a code block or a comment. Move it out of the section, then render again.`
|
|
726
|
+
);
|
|
727
|
+
return written(
|
|
728
|
+
[
|
|
729
|
+
...lines.slice(0, start),
|
|
730
|
+
...rendered,
|
|
731
|
+
...(keptAfterDeclaration(old).length
|
|
732
|
+
? ["", ...keptAfterDeclaration(old)]
|
|
733
|
+
: []),
|
|
734
|
+
...(end < lines.length ? ["", ...lines.slice(end)] : [""]),
|
|
735
|
+
].join(eol),
|
|
736
|
+
declaration
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* A body the declaration was just written into, proven readable.
|
|
742
|
+
*
|
|
743
|
+
* A write that the reader cannot see is worse than no write: the caller is told
|
|
744
|
+
* the item now has a declaration and the gate then reports it missing. That is
|
|
745
|
+
* what happens when the body ends inside an unclosed code fence or HTML
|
|
746
|
+
* comment, or when a wiki heading lands under an unclosed code marker. So the
|
|
747
|
+
* result is read back, and a declaration that did not come back is an error
|
|
748
|
+
* naming what to fix.
|
|
749
|
+
* @param {string} body - The body after the write.
|
|
750
|
+
* @param {string} declaration - The line that was written.
|
|
751
|
+
* @returns {string} The same body.
|
|
752
|
+
*/
|
|
753
|
+
function written(body, declaration) {
|
|
754
|
+
const state = declarationState(body);
|
|
755
|
+
const [firstLine = ""] = (state?.text ?? "").split("\n");
|
|
756
|
+
if (
|
|
757
|
+
state === null ||
|
|
758
|
+
state.problem !== null ||
|
|
759
|
+
firstLine.trim() !== declaration
|
|
760
|
+
)
|
|
761
|
+
throw new ReleaseSwitchError(
|
|
762
|
+
`The ${RELEASE_SWITCH_HEADING} section could not be written where it would be read${state?.problem ? `: ${state.problem}` : ": the body ends inside an unclosed code block or comment. Close it, then render again."}`
|
|
763
|
+
);
|
|
764
|
+
return body;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* The switch this item must remove before it can finish, if any.
|
|
769
|
+
*
|
|
770
|
+
* The readiness gate is strict about the section's shape; this is deliberately
|
|
771
|
+
* not. It reads the FIRST line of the section, so text that later landed under
|
|
772
|
+
* the declaration (a trailer appended to the end of the body, a note) cannot
|
|
773
|
+
* make the obligation disappear. A first line that is neither form is reported
|
|
774
|
+
* as `invalid`: an item whose declaration cannot be read is not known to be
|
|
775
|
+
* free of a switch, and the done gate refuses it until the line is corrected.
|
|
776
|
+
* @param {string} body - Work-item body.
|
|
777
|
+
* @param {string} [ref] - The item's own reference, so `removed by <own ref>` counts too.
|
|
778
|
+
* @returns {null | {switchName: string} | {invalid: string[]}} The obligation, `null` when there is none, or why the declaration cannot be read.
|
|
779
|
+
*/
|
|
780
|
+
export function removalObligation(body, ref) {
|
|
781
|
+
const state = declarationState(body);
|
|
782
|
+
if (state === null) return null;
|
|
783
|
+
if (state.problem !== null) return { invalid: [state.problem] };
|
|
784
|
+
const [firstLine = ""] = state.text
|
|
785
|
+
.split("\n")
|
|
786
|
+
.map(line => line.trim())
|
|
787
|
+
.filter(Boolean);
|
|
788
|
+
const declaration = parseDeclarationLine(firstLine);
|
|
789
|
+
if (declaration.mode === "invalid") return { invalid: declaration.problems };
|
|
790
|
+
if (declaration.mode !== "off") return null;
|
|
791
|
+
// Tracker references are not case-sensitive (owner/Repo#7 is owner/repo#7),
|
|
792
|
+
// and a remover this item fails to recognise as itself is a gate that never
|
|
793
|
+
// fires.
|
|
794
|
+
const own = [THIS_ITEM, ref, ref?.replace(/^[^#]*(?=#)/, "")]
|
|
795
|
+
.filter(Boolean)
|
|
796
|
+
.map(value => value.toLowerCase());
|
|
797
|
+
return own.includes(declaration.removedBy.toLowerCase())
|
|
798
|
+
? { switchName: declaration.switchName }
|
|
799
|
+
: null;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// A search "in cwd" means cwd's repository. Git run from inside a hook inherits
|
|
803
|
+
// GIT_DIR and friends, which would silently point this search at the hook's
|
|
804
|
+
// repository instead, so those are dropped.
|
|
805
|
+
const gitEnvironment = () =>
|
|
806
|
+
Object.fromEntries(
|
|
807
|
+
Object.entries(process.env).filter(
|
|
808
|
+
([name]) =>
|
|
809
|
+
![
|
|
810
|
+
"GIT_DIR",
|
|
811
|
+
"GIT_WORK_TREE",
|
|
812
|
+
"GIT_INDEX_FILE",
|
|
813
|
+
"GIT_COMMON_DIR",
|
|
814
|
+
].includes(name)
|
|
815
|
+
)
|
|
816
|
+
);
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* Run git and return its output, or throw with the exit status and stderr.
|
|
820
|
+
*
|
|
821
|
+
* Anything git says on stderr is a failure here, whatever the exit status. A
|
|
822
|
+
* search that could not read part of a tree can still exit 0 or 1, and "no
|
|
823
|
+
* match" from a search that skipped an unreadable file is not an answer.
|
|
824
|
+
* @param {string[]} args - Git arguments.
|
|
825
|
+
* @param {string} cwd - Directory to run in.
|
|
826
|
+
* @returns {string} Standard output.
|
|
827
|
+
*/
|
|
828
|
+
function git(args, cwd) {
|
|
829
|
+
const result = spawnSync("git", args, {
|
|
830
|
+
cwd,
|
|
831
|
+
env: gitEnvironment(),
|
|
832
|
+
encoding: "utf8",
|
|
833
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
834
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
835
|
+
});
|
|
836
|
+
const stderr = result.stderr ?? "";
|
|
837
|
+
if (result.status === 0 && stderr.trim() === "") return result.stdout ?? "";
|
|
838
|
+
throw Object.assign(new Error(stderr || String(result.error ?? "")), {
|
|
839
|
+
status: result.status,
|
|
840
|
+
stderr,
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
const CHANGELOG_FILE = /^changelog(?:\.(?:md|markdown|txt|rst|adoc))?$/i;
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Files that are records of work and are never executed, so a mention in one
|
|
848
|
+
* cannot keep a switch alive:
|
|
849
|
+
*
|
|
850
|
+
* - committed evidence, `evidence/<ticket>/…` at the repository root. The
|
|
851
|
+
* read-back that proves a switch is off in production names the switch.
|
|
852
|
+
* - a changelog (`CHANGELOG`, `CHANGELOG.md`, …), which says what was removed.
|
|
853
|
+
* - Lisa's own machine state under `.lisa/`, such as the learnings ledger.
|
|
854
|
+
*
|
|
855
|
+
* Everything inside those two folders is treated as a record, code included,
|
|
856
|
+
* so nothing that reads a switch belongs there. A submodule that is not
|
|
857
|
+
* checked out has no files to search and is not reported.
|
|
858
|
+
*
|
|
859
|
+
* Everything else counts, prose included: Markdown and MDX can carry template
|
|
860
|
+
* conditionals, a text file can be a flag list, and `ChangelogPage.tsx` or a
|
|
861
|
+
* script sitting directly in `evidence/` is code. This is one definition of
|
|
862
|
+
* "record" for every switch, not a list anyone adds a failing file to.
|
|
863
|
+
* @param {string} path - Repository-relative path.
|
|
864
|
+
* @returns {boolean} True when the file can hold a reference that matters.
|
|
865
|
+
*/
|
|
866
|
+
function isSource(path) {
|
|
867
|
+
const segments = path.split("/");
|
|
868
|
+
const evidence = segments[0] === "evidence" && segments.length >= 3;
|
|
869
|
+
const machineState = segments[0] === ".lisa" && segments.length >= 2;
|
|
870
|
+
return !(
|
|
871
|
+
evidence ||
|
|
872
|
+
machineState ||
|
|
873
|
+
CHANGELOG_FILE.test(segments.at(-1) ?? "")
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* An extended regular expression that matches the switch name as a whole
|
|
879
|
+
* token: not glued to a letter or digit on either side. `new-checkout` then
|
|
880
|
+
* matches `flags["new-checkout"]`, `new-checkout.enabled` and
|
|
881
|
+
* `new-checkout_v2`, and does not match the unrelated `renew-checkout-banner`.
|
|
882
|
+
* @param {string} switchName - A validated switch name.
|
|
883
|
+
* @returns {string} Pattern for `git grep -E`.
|
|
884
|
+
*/
|
|
885
|
+
const tokenPattern = switchName =>
|
|
886
|
+
`(^|[^A-Za-z0-9])${switchName.replaceAll(".", "[.]")}($|[^A-Za-z0-9])`;
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* Git's own switch for ignoring local replacement refs. With one in place, a
|
|
890
|
+
* search "at commit X" would read whatever tree X was locally replaced by,
|
|
891
|
+
* while the caller reports X: the proof's commit would not be the one searched.
|
|
892
|
+
*/
|
|
893
|
+
export const NO_REPLACE = "--no-replace-objects";
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* The root of the repository `cwd` is in.
|
|
897
|
+
* @param {Function} run - Git runner.
|
|
898
|
+
* @param {string} cwd - A directory inside the repository.
|
|
899
|
+
* @param {Function} failed - Builds the error for a search that cannot run.
|
|
900
|
+
* @returns {string} Absolute path of the repository root.
|
|
901
|
+
*/
|
|
902
|
+
function repositoryRoot(run, cwd, failed) {
|
|
903
|
+
try {
|
|
904
|
+
return run([NO_REPLACE, "rev-parse", "--show-toplevel"], cwd).trim();
|
|
905
|
+
} catch (error) {
|
|
906
|
+
throw failed(error);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* Tracked source files that still reference a switch.
|
|
912
|
+
*
|
|
913
|
+
* It searches `revision` when one is given (the production commit after a
|
|
914
|
+
* merge) and the working tree otherwise, always from the repository root, in
|
|
915
|
+
* any letter case. `git grep` exits 1 for "no match", which is the answer and
|
|
916
|
+
* not an error; anything else is surfaced, because a search that could not run
|
|
917
|
+
* must never read as "the switch is gone".
|
|
918
|
+
*
|
|
919
|
+
* What it cannot find is a different spelling of the same switch
|
|
920
|
+
* (`NEW_CHECKOUT` for `new-checkout`): a project uses one spelling everywhere.
|
|
921
|
+
* @param {string} switchName - Switch to look for, matched as a whole token.
|
|
922
|
+
* @param {{cwd?: string, revision?: string, run?: Function}} [options] - Where to search; `run` is injectable for tests.
|
|
923
|
+
* @returns {string[]} Repository-relative paths, sorted.
|
|
924
|
+
*/
|
|
925
|
+
export function switchReferences(
|
|
926
|
+
switchName,
|
|
927
|
+
{ cwd = process.cwd(), revision, run = git } = {}
|
|
928
|
+
) {
|
|
929
|
+
if (!SWITCH_NAME.test(switchName))
|
|
930
|
+
throw new ReleaseSwitchError(
|
|
931
|
+
`${JSON.stringify(switchName)} is not a valid switch name.`
|
|
932
|
+
);
|
|
933
|
+
const failed = error =>
|
|
934
|
+
new ReleaseSwitchError(
|
|
935
|
+
`Could not search tracked source for ${JSON.stringify(switchName)}: ${String(error?.stderr || error?.message || error).trim()}`
|
|
936
|
+
);
|
|
937
|
+
// The search runs from the repository root with no pathspec at all. Git run
|
|
938
|
+
// from a subfolder searches only that folder, and the `:/` pathspec that
|
|
939
|
+
// would widen it stops meaning "the root" when a hook or alias runs under
|
|
940
|
+
// `git --literal-pathspecs`; either way a switch still in use elsewhere would
|
|
941
|
+
// be reported as gone.
|
|
942
|
+
// A value that starts with a dash would be read by git as an option.
|
|
943
|
+
if (revision !== undefined && !/^[A-Za-z0-9]/.test(revision))
|
|
944
|
+
throw new ReleaseSwitchError(
|
|
945
|
+
`${JSON.stringify(revision)} is not a revision this search accepts.`
|
|
946
|
+
);
|
|
947
|
+
const root = repositoryRoot(run, cwd, failed);
|
|
948
|
+
// The closing `--` with nothing after it still means "the whole tree", and
|
|
949
|
+
// it makes git read the value before it as a revision or fail: without it a
|
|
950
|
+
// folder that happens to carry the same name would be searched instead, and
|
|
951
|
+
// the answer would be "not referenced" for a tree that was never looked at.
|
|
952
|
+
const args = [
|
|
953
|
+
NO_REPLACE,
|
|
954
|
+
"-C",
|
|
955
|
+
root,
|
|
956
|
+
"grep",
|
|
957
|
+
"-l",
|
|
958
|
+
"-i",
|
|
959
|
+
"-E",
|
|
960
|
+
"-z",
|
|
961
|
+
"--full-name",
|
|
962
|
+
"--recurse-submodules",
|
|
963
|
+
"-e",
|
|
964
|
+
tokenPattern(switchName),
|
|
965
|
+
...(revision ? [revision] : []),
|
|
966
|
+
"--",
|
|
967
|
+
];
|
|
968
|
+
try {
|
|
969
|
+
return run(args, cwd)
|
|
970
|
+
.split("\0")
|
|
971
|
+
.filter(Boolean)
|
|
972
|
+
.map(path => (revision ? path.slice(revision.length + 1) : path))
|
|
973
|
+
.filter(isSource)
|
|
974
|
+
.sort((left, right) => left.localeCompare(right));
|
|
975
|
+
} catch (error) {
|
|
976
|
+
// Exit 1 with nothing on stderr is git's "no match". Exit 1 WITH a
|
|
977
|
+
// diagnostic is a read that failed partway, and is not a clean answer.
|
|
978
|
+
if (error?.status === 1 && String(error.stderr ?? "").trim() === "")
|
|
979
|
+
return [];
|
|
980
|
+
throw failed(error);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
const HEADS_PREFIX = "refs/heads/";
|
|
985
|
+
|
|
986
|
+
/**
|
|
987
|
+
* A branch name without the `refs/heads/` prefix some tools report.
|
|
988
|
+
* @param {unknown} value - Branch as configured or as reported.
|
|
989
|
+
* @returns {string} Short branch name, or "" when there is none.
|
|
990
|
+
*/
|
|
991
|
+
const branchName = value => {
|
|
992
|
+
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
993
|
+
return trimmed.startsWith(HEADS_PREFIX)
|
|
994
|
+
? trimmed.slice(HEADS_PREFIX.length)
|
|
995
|
+
: trimmed;
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* The branch that deploys to production.
|
|
1000
|
+
*
|
|
1001
|
+
* It reads `deploy.branches` the way the completion checker does, so the two
|
|
1002
|
+
* agree on what "production" is: environment names are not case-sensitive, a
|
|
1003
|
+
* `refs/heads/` prefix is ignored, and a project that configures no deploy
|
|
1004
|
+
* branches at all deploys production from its default branch
|
|
1005
|
+
* (`policy.repository.default_branch`, else `main`). `prod` and `production`
|
|
1006
|
+
* are the same environment; when a project configures both and they name
|
|
1007
|
+
* different branches, it means two things and neither is guessed.
|
|
1008
|
+
* @param {object} [config] - Effective project config.
|
|
1009
|
+
* @returns {string|null} Branch name, or `null` when it cannot be read.
|
|
1010
|
+
*/
|
|
1011
|
+
export function productionBranch(config = {}) {
|
|
1012
|
+
const configured = isObject(config?.deploy?.branches)
|
|
1013
|
+
? Object.entries(config.deploy.branches)
|
|
1014
|
+
: [];
|
|
1015
|
+
const mapped = configured
|
|
1016
|
+
.map(([environment, branch]) => [
|
|
1017
|
+
String(environment).trim().toLowerCase(),
|
|
1018
|
+
branchName(branch),
|
|
1019
|
+
])
|
|
1020
|
+
.filter(([, branch]) => branch !== "");
|
|
1021
|
+
if (mapped.length === 0)
|
|
1022
|
+
return branchName(config?.policy?.repository?.default_branch) || "main";
|
|
1023
|
+
const production = new Set(
|
|
1024
|
+
mapped
|
|
1025
|
+
.filter(([environment]) => ["production", "prod"].includes(environment))
|
|
1026
|
+
.map(([, branch]) => branch)
|
|
1027
|
+
);
|
|
1028
|
+
return production.size === 1 ? [...production][0] : null;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* The plain-English notice for a production deployment in a project that is
|
|
1033
|
+
* marked as having no live users. It keeps the opt-out visible on the one day
|
|
1034
|
+
* it matters most, launch day, without ever blocking a deployment.
|
|
1035
|
+
* @param {object} config - Effective project config.
|
|
1036
|
+
* @param {string} base - Branch the deployment came from.
|
|
1037
|
+
* @returns {string|null} The notice, or `null` when none applies.
|
|
1038
|
+
*/
|
|
1039
|
+
export function productionNotice(config, base) {
|
|
1040
|
+
const setting = resolveReleaseSetting(config);
|
|
1041
|
+
const branch = branchName(base);
|
|
1042
|
+
if (setting.liveUsers || branch === "" || branch !== productionBranch(config))
|
|
1043
|
+
return null;
|
|
1044
|
+
return [
|
|
1045
|
+
`Notice: this project is marked as having no live users (release.liveUsers is false in its Lisa configuration: .lisa.config.json, or the local override .lisa.config.local.json), so Lisa's always-promotable rule is off here.`,
|
|
1046
|
+
`This deployment from ${branch} went to production, and unfinished work can reach production without being switched off.`,
|
|
1047
|
+
"When the project launches, set release.liveUsers to true or remove the line. Nothing was blocked.",
|
|
1048
|
+
].join("\n");
|
|
1049
|
+
}
|