@webpieces/pr-gate 0.4.847 → 0.4.848
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/package.json +6 -6
- package/src/scripts/workflow/active-hatches.d.ts +4 -8
- package/src/scripts/workflow/active-hatches.js +18 -18
- package/src/scripts/workflow/active-hatches.js.map +1 -1
- package/src/scripts/workflow/repo-config-testkit.js +1 -2
- package/src/scripts/workflow/repo-config-testkit.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/pr-gate",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.848",
|
|
4
4
|
"description": "Gated PR system: 3-point squash-merge, merge validation gate, and red/yellow/green PR dashboard. Standalone scripts, no Nx dependency required.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
19
|
-
"@webpieces/hook-runtime": "0.4.
|
|
20
|
-
"@webpieces/rules-config": "0.4.
|
|
19
|
+
"@webpieces/hook-runtime": "0.4.848",
|
|
20
|
+
"@webpieces/rules-config": "0.4.848",
|
|
21
21
|
"inversify": "7.10.4",
|
|
22
22
|
"reflect-metadata": "0.2.2",
|
|
23
|
-
"@webpieces/tooling-common": "0.4.
|
|
24
|
-
"@webpieces/repo-workflow-core": "0.4.
|
|
23
|
+
"@webpieces/tooling-common": "0.4.848",
|
|
24
|
+
"@webpieces/repo-workflow-core": "0.4.848"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@webpieces/tooling-testkit": "0.4.
|
|
30
|
+
"@webpieces/tooling-testkit": "0.4.848"
|
|
31
31
|
},
|
|
32
32
|
"types": "./src/index.d.ts",
|
|
33
33
|
"bin": {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigFile } from '@webpieces/rules-config';
|
|
1
|
+
import { ConfigFile, PackPolicyFiles } from '@webpieces/rules-config';
|
|
2
2
|
/** One rule that is currently NOT being enforced, and which of the two hatches is doing it. Data-only. */
|
|
3
3
|
export declare class ActiveHatch {
|
|
4
4
|
/** The rule/guard/match-rule name as it appears in webpieces.config.json. */
|
|
@@ -35,7 +35,8 @@ export declare class ConfigEntry {
|
|
|
35
35
|
*/
|
|
36
36
|
export declare class ActiveHatchReport {
|
|
37
37
|
private readonly configFile;
|
|
38
|
-
|
|
38
|
+
private readonly files;
|
|
39
|
+
constructor(configFile: ConfigFile, files: PackPolicyFiles);
|
|
39
40
|
/**
|
|
40
41
|
* Every active hatch in the repo's config: a non-null `turnOffRuleWhileOnBranch`, or a
|
|
41
42
|
* `turnOffRuleUntilEpoch` still in the future. An epoch in the PAST is inert — it skips nothing — and
|
|
@@ -44,12 +45,7 @@ export declare class ActiveHatchReport {
|
|
|
44
45
|
scan(repoRoot: string): ActiveHatch[];
|
|
45
46
|
/** The section, or an empty string when nothing is hatched — the common case prints nothing at all. */
|
|
46
47
|
render(hatches: readonly ActiveHatch[]): string;
|
|
47
|
-
/**
|
|
48
|
-
* Every named block in the config that can carry a hatch: the keyed `rules` and `hookGuards` maps, plus
|
|
49
|
-
* the `match-rules` array, whose entries name themselves.
|
|
50
|
-
*/
|
|
51
|
-
private namedEntries;
|
|
52
|
-
/** A `name → block` map (`rules`, `hookGuards`) as entries. */
|
|
48
|
+
/** An owner file's `name → block` map as entries, without requiring valid lock/schema data. */
|
|
53
49
|
private keyedEntries;
|
|
54
50
|
/** The `match-rules` array, whose elements carry their own `name`. Typed `unknown` in RawConfigFile. */
|
|
55
51
|
private matchRuleEntries;
|
|
@@ -52,8 +52,10 @@ exports.ConfigEntry = ConfigEntry;
|
|
|
52
52
|
*/
|
|
53
53
|
let ActiveHatchReport = class ActiveHatchReport {
|
|
54
54
|
configFile;
|
|
55
|
-
|
|
55
|
+
files;
|
|
56
|
+
constructor(configFile, files) {
|
|
56
57
|
this.configFile = configFile;
|
|
58
|
+
this.files = files;
|
|
57
59
|
}
|
|
58
60
|
/**
|
|
59
61
|
* Every active hatch in the repo's config: a non-null `turnOffRuleWhileOnBranch`, or a
|
|
@@ -63,7 +65,10 @@ let ActiveHatchReport = class ActiveHatchReport {
|
|
|
63
65
|
scan(repoRoot) {
|
|
64
66
|
const raw = this.configFile.readRawConfig(path.join(repoRoot, rules_config_1.CONFIG_FILENAME));
|
|
65
67
|
const found = [];
|
|
66
|
-
|
|
68
|
+
const declarations = this.files.declarations(raw.rulePacks, repoRoot);
|
|
69
|
+
const entries = declarations.flatMap((declaration) => this.keyedEntries(this.files.read(this.files.configPath(repoRoot, declaration.config))));
|
|
70
|
+
entries.push(...this.matchRuleEntries(raw['match-rules']));
|
|
71
|
+
for (const entry of entries)
|
|
67
72
|
found.push(...this.hatchesOf(entry));
|
|
68
73
|
return found;
|
|
69
74
|
}
|
|
@@ -74,23 +79,15 @@ let ActiveHatchReport = class ActiveHatchReport {
|
|
|
74
79
|
const width = Math.max(...hatches.map((h) => h.ruleName.length));
|
|
75
80
|
const lines = hatches.map((h) => ` ${h.ruleName.padEnd(width)} ${h.hatchField.padEnd(24)} = ${h.value}`);
|
|
76
81
|
return (`\n⚠️ ${hatches.length} rule hatch(es) are currently active in ${rules_config_1.CONFIG_FILENAME}:\n` +
|
|
77
|
-
lines.join('\n') +
|
|
82
|
+
lines.join('\n') +
|
|
83
|
+
'\n' +
|
|
78
84
|
' Not blocking, and not necessarily wrong — just so a rule that is OFF is never off silently.\n');
|
|
79
85
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Every named block in the config that can carry a hatch: the keyed `rules` and `hookGuards` maps, plus
|
|
82
|
-
* the `match-rules` array, whose entries name themselves.
|
|
83
|
-
*/
|
|
84
|
-
namedEntries(raw) {
|
|
85
|
-
const entries = [];
|
|
86
|
-
entries.push(...this.keyedEntries(raw.rules));
|
|
87
|
-
entries.push(...this.keyedEntries(raw.hookGuards));
|
|
88
|
-
entries.push(...this.matchRuleEntries(raw['match-rules']));
|
|
89
|
-
return entries;
|
|
90
|
-
}
|
|
91
|
-
/** A `name → block` map (`rules`, `hookGuards`) as entries. */
|
|
86
|
+
/** An owner file's `name → block` map as entries, without requiring valid lock/schema data. */
|
|
92
87
|
// webpieces-disable no-any-unknown -- an unvalidated config section: opaque JSON in, type-checked fields out
|
|
93
|
-
keyedEntries(
|
|
88
|
+
keyedEntries(
|
|
89
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
90
|
+
section) {
|
|
94
91
|
if (!section)
|
|
95
92
|
return [];
|
|
96
93
|
return Object.keys(section).map((name) => new ConfigEntry(name, section[name]));
|
|
@@ -101,7 +98,9 @@ let ActiveHatchReport = class ActiveHatchReport {
|
|
|
101
98
|
if (!Array.isArray(section))
|
|
102
99
|
return [];
|
|
103
100
|
// webpieces-disable no-any-unknown -- one opaque config block per element
|
|
104
|
-
return section.map(
|
|
101
|
+
return section.map(
|
|
102
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
103
|
+
(entry) => {
|
|
105
104
|
const name = entry['name'];
|
|
106
105
|
return new ConfigEntry(typeof name === 'string' ? name : '(unnamed match-rule)', entry);
|
|
107
106
|
});
|
|
@@ -125,6 +124,7 @@ let ActiveHatchReport = class ActiveHatchReport {
|
|
|
125
124
|
exports.ActiveHatchReport = ActiveHatchReport;
|
|
126
125
|
exports.ActiveHatchReport = ActiveHatchReport = tslib_1.__decorate([
|
|
127
126
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
128
|
-
tslib_1.__metadata("design:paramtypes", [rules_config_1.ConfigFile
|
|
127
|
+
tslib_1.__metadata("design:paramtypes", [rules_config_1.ConfigFile,
|
|
128
|
+
rules_config_1.PackPolicyFiles])
|
|
129
129
|
], ActiveHatchReport);
|
|
130
130
|
//# sourceMappingURL=active-hatches.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"active-hatches.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/active-hatches.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAE7B,0DAAqF;AACrF,yCAA2D;AAE3D,0GAA0G;AAC1G,MAAa,WAAW;IACpB,6EAA6E;IAC7E,QAAQ,CAAS;IACjB,+GAA+G;IAC/G,UAAU,CAAS;IACnB,6FAA6F;IAC7F,KAAK,CAAS;IAEd,YAAY,QAAgB,EAAE,UAAkB,EAAE,KAAa;QAC3D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAbD,kCAaC;AAED;;;GAGG;AACH,MAAa,WAAW;IACpB,QAAQ,CAAS;IACjB,2JAA2J;IAC3J,MAAM,CAA0B;IAEhC,0DAA0D;IAC1D,YAAY,QAAgB,EAAE,MAA+B;QACzD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAVD,kCAUC;AAED;;;;;;;;;;;;;;GAcG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IACG;IAA7B,YAA6B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAEvD;;;;OAIG;IACH,IAAI,CAAC,QAAgB;QACjB,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,8BAAe,CAAC,CAAC,CAAC;QAChF,MAAM,KAAK,GAAkB,EAAE,CAAC;QAChC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;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,CAAC,QAAQ,EAAE,uBAAuB,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChG,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAEO,OAAO,CAAC,YAAoB;QAChC,OAAO,IAAI,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,CAAC;CACJ,CAAA;AA1EY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEI,yBAAU;GAD1C,iBAAiB,CA0E7B","sourcesContent":["import * as path from 'path';\n\nimport { CONFIG_FILENAME, ConfigFile, RawConfigFile } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/** One rule that is currently NOT being enforced, and which of the two hatches is doing it. Data-only. */\nexport class ActiveHatch {\n /** The rule/guard/match-rule name as it appears in webpieces.config.json. */\n ruleName: string;\n /** `turnOffRuleWhileOnBranch` or `turnOffRuleUntilEpoch` — the field, spelled the way the config spells it. */\n hatchField: string;\n /** Already rendered for a human: a quoted branch name, or the ISO date the epoch expires. */\n value: string;\n\n constructor(ruleName: string, hatchField: string, value: string) {\n this.ruleName = ruleName;\n this.hatchField = hatchField;\n this.value = value;\n }\n}\n\n/**\n * One named block of webpieces.config.json — a `rules`/`hookGuards` entry, or a `match-rules` array element\n * that carries its own `name`. Data-only, so the three config shapes are scanned as one list.\n */\nexport class ConfigEntry {\n ruleName: string;\n // webpieces-disable no-any-unknown -- an unvalidated config block: the values are opaque JSON here, and each hatch field is type-checked before it is read\n fields: Record<string, unknown>;\n\n // webpieces-disable no-any-unknown -- see the field above\n constructor(ruleName: string, fields: Record<string, unknown>) {\n this.ruleName = ruleName;\n this.fields = fields;\n }\n}\n\n/**\n * The active-hatch section of the `wp-review-upsert-pr` dashboard: every rule that is currently switched\n * off, listed once per PR.\n *\n * PURELY INFORMATIONAL — it never fails a build, never blocks a PR, and never asks for anything. It exists\n * because a hatch is the one config change that makes the build QUIETER, so nothing else in the flow will\n * ever mention it. The motivating case is an EPOCH hatch: it is repo-wide while it lasts, so a long window\n * shelters every unrelated change landing in it, and a fleet repo was found with max-file-lines and\n * max-method-lines switched off until 2026-10-01 — 43 days out — with nobody aware. (The ONE-WEEK cap in\n * rules-config stops new ones from getting that far; this is how you SEE the ones you have.)\n *\n * A branch hatch is listed for completeness, not as a complaint. It fires on ONE exact branch name, so a\n * stale one is close to harmless — and deliberately there is NO \"does that branch still exist on the\n * remote?\" check here, because a pruned remote would make that a false alarm on every PR.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ActiveHatchReport {\n constructor(private readonly configFile: ConfigFile) {}\n\n /**\n * Every active hatch in the repo's config: a non-null `turnOffRuleWhileOnBranch`, or a\n * `turnOffRuleUntilEpoch` still in the future. An epoch in the PAST is inert — it skips nothing — and\n * listing those would bury the live ones under every rule in the file.\n */\n scan(repoRoot: string): ActiveHatch[] {\n const raw = this.configFile.readRawConfig(path.join(repoRoot, CONFIG_FILENAME));\n const found: ActiveHatch[] = [];\n for (const entry of this.namedEntries(raw)) found.push(...this.hatchesOf(entry));\n return found;\n }\n\n /** The section, or an empty string when nothing is hatched — the common case prints nothing at all. */\n render(hatches: readonly ActiveHatch[]): string {\n if (hatches.length === 0) return '';\n const width = Math.max(...hatches.map((h: ActiveHatch): number => h.ruleName.length));\n const lines = hatches.map((h: ActiveHatch): string =>\n ` ${h.ruleName.padEnd(width)} ${h.hatchField.padEnd(24)} = ${h.value}`);\n return (\n `\\n⚠️ ${hatches.length} rule hatch(es) are currently active in ${CONFIG_FILENAME}:\\n` +\n lines.join('\\n') + '\\n' +\n ' Not blocking, and not necessarily wrong — just so a rule that is OFF is never off silently.\\n'\n );\n }\n\n /**\n * Every named block in the config that can carry a hatch: the keyed `rules` and `hookGuards` maps, plus\n * the `match-rules` array, whose entries name themselves.\n */\n private namedEntries(raw: RawConfigFile): ConfigEntry[] {\n const entries: ConfigEntry[] = [];\n entries.push(...this.keyedEntries(raw.rules));\n entries.push(...this.keyedEntries(raw.hookGuards));\n entries.push(...this.matchRuleEntries(raw['match-rules']));\n return entries;\n }\n\n /** A `name → block` map (`rules`, `hookGuards`) as entries. */\n // webpieces-disable no-any-unknown -- an unvalidated config section: opaque JSON in, type-checked fields out\n private keyedEntries(section: Record<string, Record<string, unknown>> | undefined): ConfigEntry[] {\n if (!section) return [];\n return Object.keys(section).map((name: string): ConfigEntry => new ConfigEntry(name, section[name]));\n }\n\n /** The `match-rules` array, whose elements carry their own `name`. Typed `unknown` in RawConfigFile. */\n // webpieces-disable no-any-unknown -- RawConfigFile types this section unknown on purpose; it is validated structurally elsewhere\n private matchRuleEntries(section: unknown): ConfigEntry[] {\n if (!Array.isArray(section)) return [];\n // webpieces-disable no-any-unknown -- one opaque config block per element\n return (section as Record<string, unknown>[]).map((entry: Record<string, unknown>): ConfigEntry => {\n const name = entry['name'];\n return new ConfigEntry(typeof name === 'string' ? name : '(unnamed match-rule)', entry);\n });\n }\n\n private hatchesOf(entry: ConfigEntry): ActiveHatch[] {\n const hatches: ActiveHatch[] = [];\n const branch = entry.fields['turnOffRuleWhileOnBranch'];\n if (typeof branch === 'string' && branch !== '') {\n hatches.push(new ActiveHatch(entry.ruleName, 'turnOffRuleWhileOnBranch', `\"${branch}\"`));\n }\n const epoch = entry.fields['turnOffRuleUntilEpoch'];\n if (typeof epoch === 'number' && epoch > Date.now() / 1000) {\n hatches.push(new ActiveHatch(entry.ruleName, 'turnOffRuleUntilEpoch', this.isoDate(epoch)));\n }\n return hatches;\n }\n\n private isoDate(epochSeconds: number): string {\n return new Date(epochSeconds * 1000).toISOString().split('T')[0];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"active-hatches.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/active-hatches.ts"],"names":[],"mappings":";;;;AAAA,mD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CAAC;IACnB,CAAC;IAEO,OAAO,CAAC,YAAoB;QAChC,OAAO,IAAI,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,CAAC;CACJ,CAAA;AAxFY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGJ,yBAAU;QACf,8BAAe;GAHlC,iBAAiB,CAwF7B","sourcesContent":["import * as path from 'path';\n\nimport {\n CONFIG_FILENAME,\n ConfigFile,\n PackPolicyFiles,\n PackPolicyDeclaration,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/** One rule that is currently NOT being enforced, and which of the two hatches is doing it. Data-only. */\nexport class ActiveHatch {\n /** The rule/guard/match-rule name as it appears in webpieces.config.json. */\n ruleName: string;\n /** `turnOffRuleWhileOnBranch` or `turnOffRuleUntilEpoch` — the field, spelled the way the config spells it. */\n hatchField: string;\n /** Already rendered for a human: a quoted branch name, or the ISO date the epoch expires. */\n value: string;\n\n constructor(ruleName: string, hatchField: string, value: string) {\n this.ruleName = ruleName;\n this.hatchField = hatchField;\n this.value = value;\n }\n}\n\n/**\n * One named block of webpieces.config.json — a `rules`/`hookGuards` entry, or a `match-rules` array element\n * that carries its own `name`. Data-only, so the three config shapes are scanned as one list.\n */\nexport class ConfigEntry {\n ruleName: string;\n // webpieces-disable no-any-unknown -- an unvalidated config block: the values are opaque JSON here, and each hatch field is type-checked before it is read\n fields: Record<string, unknown>;\n\n // webpieces-disable no-any-unknown -- see the field above\n constructor(ruleName: string, fields: Record<string, unknown>) {\n this.ruleName = ruleName;\n this.fields = fields;\n }\n}\n\n/**\n * The active-hatch section of the `wp-review-upsert-pr` dashboard: every rule that is currently switched\n * off, listed once per PR.\n *\n * PURELY INFORMATIONAL — it never fails a build, never blocks a PR, and never asks for anything. It exists\n * because a hatch is the one config change that makes the build QUIETER, so nothing else in the flow will\n * ever mention it. The motivating case is an EPOCH hatch: it is repo-wide while it lasts, so a long window\n * shelters every unrelated change landing in it, and a fleet repo was found with max-file-lines and\n * max-method-lines switched off until 2026-10-01 — 43 days out — with nobody aware. (The ONE-WEEK cap in\n * rules-config stops new ones from getting that far; this is how you SEE the ones you have.)\n *\n * A branch hatch is listed for completeness, not as a complaint. It fires on ONE exact branch name, so a\n * stale one is close to harmless — and deliberately there is NO \"does that branch still exist on the\n * remote?\" check here, because a pruned remote would make that a false alarm on every PR.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ActiveHatchReport {\n constructor(\n private readonly configFile: ConfigFile,\n private readonly files: PackPolicyFiles,\n ) {}\n\n /**\n * Every active hatch in the repo's config: a non-null `turnOffRuleWhileOnBranch`, or a\n * `turnOffRuleUntilEpoch` still in the future. An epoch in the PAST is inert — it skips nothing — and\n * listing those would bury the live ones under every rule in the file.\n */\n scan(repoRoot: string): ActiveHatch[] {\n const raw = this.configFile.readRawConfig(path.join(repoRoot, CONFIG_FILENAME));\n const found: ActiveHatch[] = [];\n const declarations = this.files.declarations(raw.rulePacks, repoRoot);\n const entries = declarations.flatMap((declaration: PackPolicyDeclaration) =>\n this.keyedEntries(this.files.read(this.files.configPath(repoRoot, declaration.config))),\n );\n entries.push(...this.matchRuleEntries(raw['match-rules']));\n for (const entry of entries) found.push(...this.hatchesOf(entry));\n return found;\n }\n\n /** The section, or an empty string when nothing is hatched — the common case prints nothing at all. */\n render(hatches: readonly ActiveHatch[]): string {\n if (hatches.length === 0) return '';\n const width = Math.max(...hatches.map((h: ActiveHatch): number => h.ruleName.length));\n const lines = hatches.map(\n (h: ActiveHatch): string =>\n ` ${h.ruleName.padEnd(width)} ${h.hatchField.padEnd(24)} = ${h.value}`,\n );\n return (\n `\\n⚠️ ${hatches.length} rule hatch(es) are currently active in ${CONFIG_FILENAME}:\\n` +\n lines.join('\\n') +\n '\\n' +\n ' Not blocking, and not necessarily wrong — just so a rule that is OFF is never off silently.\\n'\n );\n }\n\n /** An owner file's `name → block` map as entries, without requiring valid lock/schema data. */\n // webpieces-disable no-any-unknown -- an unvalidated config section: opaque JSON in, type-checked fields out\n private keyedEntries(\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n section: Record<string, Record<string, unknown>> | undefined,\n ): ConfigEntry[] {\n if (!section) return [];\n return Object.keys(section).map(\n (name: string): ConfigEntry => new ConfigEntry(name, section[name]),\n );\n }\n\n /** The `match-rules` array, whose elements carry their own `name`. Typed `unknown` in RawConfigFile. */\n // webpieces-disable no-any-unknown -- RawConfigFile types this section unknown on purpose; it is validated structurally elsewhere\n private matchRuleEntries(section: unknown): ConfigEntry[] {\n if (!Array.isArray(section)) return [];\n // webpieces-disable no-any-unknown -- one opaque config block per element\n return (section as Record<string, unknown>[]).map(\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n (entry: Record<string, unknown>): ConfigEntry => {\n const name = entry['name'];\n return new ConfigEntry(\n typeof name === 'string' ? name : '(unnamed match-rule)',\n entry,\n );\n },\n );\n }\n\n private hatchesOf(entry: ConfigEntry): ActiveHatch[] {\n const hatches: ActiveHatch[] = [];\n const branch = entry.fields['turnOffRuleWhileOnBranch'];\n if (typeof branch === 'string' && branch !== '') {\n hatches.push(\n new ActiveHatch(entry.ruleName, 'turnOffRuleWhileOnBranch', `\"${branch}\"`),\n );\n }\n const epoch = entry.fields['turnOffRuleUntilEpoch'];\n if (typeof epoch === 'number' && epoch > Date.now() / 1000) {\n hatches.push(\n new ActiveHatch(entry.ruleName, 'turnOffRuleUntilEpoch', this.isoDate(epoch)),\n );\n }\n return hatches;\n }\n\n private isoDate(epochSeconds: number): string {\n return new Date(epochSeconds * 1000).toISOString().split('T')[0];\n }\n}\n"]}
|
|
@@ -74,8 +74,7 @@ class RepoConfigFixture {
|
|
|
74
74
|
/** Write `config` (usually a `load()` result a spec has edited) as the config of `dir`. */
|
|
75
75
|
// webpieces-disable no-any-unknown -- see load()
|
|
76
76
|
writeTo(dir, config) {
|
|
77
|
-
|
|
78
|
-
tooling_testkit_1.policyFixture.declareIn(dir);
|
|
77
|
+
tooling_testkit_1.policyFixture.writeOwnerConfig(dir, config);
|
|
79
78
|
}
|
|
80
79
|
// webpieces-disable no-any-unknown -- see load()
|
|
81
80
|
completeRulesFromSeed(config) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repo-config-testkit.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/repo-config-testkit.ts"],"names":[],"mappings":";;;;AAAA,gEAA2D;AAC3D,0DAA2D;AAC3D,MAAM,mBAAmB,GAAG,IAAI,+BAAgB,CAAC,+BAAa,CAAC,SAAS,EAAE,CAAC,CAAC;AAC5E,+CAAyB;AACzB,mDAA6B;AAE7B,0DAEiC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAa,iBAAiB;IAC1B,iGAAiG;IACjG,mGAAmG;IACnG,IAAI;QACA,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,uBAAuB,CAAC,CAAC;QACjG,mFAAmF;QACnF,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAA4B,CAAC;QACtF,mEAAmE;QACnE,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAA4C,CAAC;QAC/E,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,CAAC;QACzC,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,CAAC;QAC5C,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;QACnC,6FAA6F;QAC7F,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,MAAM,CAAC,uBAAuB,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,0CAA2B,EAAE,CAAC;YAC1G,OAAO,MAAM,CAAC,mBAAmB,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAC9B,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;QACnC,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,8FAA8F;IAC9F,iDAAiD;IACzC,gBAAgB,CAAC,MAA+B;QACpD,KAAK,MAAM,OAAO,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE,CAAC;YAC5C,iEAAiE;YACjE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAwC,CAAC;YACvE,IAAI,OAAO,KAAK,SAAS;gBAAE,SAAS;YACpC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBACtC,IAAI,IAAA,6BAAc,EAAC,IAAI,EAAE,mBAAmB,CAAC,KAAK,IAAI;oBAAE,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;YACjF,CAAC;QACL,CAAC;IACL,CAAC;IAED,2FAA2F;IAC3F,iDAAiD;IACjD,OAAO,CAAC,GAAW,EAAE,MAA+B;QAChD,
|
|
1
|
+
{"version":3,"file":"repo-config-testkit.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/repo-config-testkit.ts"],"names":[],"mappings":";;;;AAAA,gEAA2D;AAC3D,0DAA2D;AAC3D,MAAM,mBAAmB,GAAG,IAAI,+BAAgB,CAAC,+BAAa,CAAC,SAAS,EAAE,CAAC,CAAC;AAC5E,+CAAyB;AACzB,mDAA6B;AAE7B,0DAEiC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAa,iBAAiB;IAC1B,iGAAiG;IACjG,mGAAmG;IACnG,IAAI;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IAAA,6BAAc,EAAC,IAAI,EAAE,mBAAmB,CAAC,KAAK,IAAI;oBAAE,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;YACjF,CAAC;QACL,CAAC;IACL,CAAC;IAED,2FAA2F;IAC3F,iDAAiD;IACjD,OAAO,CAAC,GAAW,EAAE,MAA+B;QAChD,+BAAa,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,iDAAiD;IACzC,qBAAqB,CAAC,MAA+B;QACzD,sEAAsE;QACtE,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAA4B,CAAC;QACzD,sEAAsE;QACtE,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAA4B,CAAC;QAC/D,KAAK,MAAM,IAAI,IAAI,IAAA,2BAAY,EAAC,mBAAmB,CAAC,EAAE,CAAC;YACnD,MAAM,OAAO,GAAG,IAAA,6BAAc,EAAC,IAAI,EAAE,mBAAmB,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;YAC5F,MAAM,IAAI,GAAG,IAAA,+BAAgB,EAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;YACzD,iGAAiG;YACjG,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAwC,CAAC;YACtE,OAAO,CAAC,IAAI,CAAC,GAAG,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC7E,CAAC;IACL,CAAC;CACJ;AAvDD,8CAuDC","sourcesContent":["import { policyFixture } from '@webpieces/tooling-testkit';\nimport { RulePackRegistry } from '@webpieces/rules-config';\nconst fixtureRuleRegistry = new RulePackRegistry(policyFixture.manifests());\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nimport {\n allRuleNames, DEFAULT_REVIEWER_AGENT_NAME, retiredRuleFor, sectionForRule, seedEntryForRule,\n} from '@webpieces/rules-config';\n\n/**\n * THIS repo's own `webpieces.config.json`, prepared for use inside a temp clone.\n *\n * Specs that exercise a command end-to-end need a config the REAL validator accepts, and using the\n * repo's own file (rather than a hand-rolled minimal one) is what keeps them honest — a stub drifts out\n * from under the validator on the next config change. These adjustments are needed to make that file\n * usable outside this checkout, and all are the same for every such spec, so they live here once:\n *\n * 1. `checklists` is dropped. Its `doc` paths are validated REPO-RELATIVE and point at\n * `.claude/review/*.md`, which exist here and not in a temp clone.\n * 2. Every locally-known rule is completed from its SEED. The repo's config is validated by the PUBLISHED\n * validator and therefore lags local source by one release\n * (`.claude/rules/published-vs-local-source.md`): a rule added in this working tree cannot get a\n * config entry or newly-required field until its release ships,\n * while the LOCAL validator a spec runs already demands one. Without this, adding any rule turns\n * these specs red for exactly one release — a failure that says nothing about the code under test.\n * 3. Every RETIRED rule entry is dropped — the same one-release lag pointing the other way. When a rule\n * is retired in this working tree, the repo's config must KEEP its entry until the release carrying\n * the retirement ships (deleting it early would fail the published validator and block every Bash\n * call), while the LOCAL validator already REJECTS it. Same trade as (2), same fix.\n * 4. A `commands.pr-gate.reviewerAgentName` naming the webpieces default WITHOUT `overrideReviewerAgent`\n * is dropped — the same one-release lag again (issue #947). The published validator still REQUIRES the\n * key, so the repo's config must carry it until the release making it optional ships, while the LOCAL\n * validator already rejects a name without the override. A follow-up PR removes it from the live config.\n *\n * A testkit, not product code: nothing in a published bin imports it (same role as ai-hook-rules'\n * `shim-testkit.ts`).\n */\nexport class RepoConfigFixture {\n /** The repo's config as a mutable object, checklists dropped and local seed fields completed. */\n // webpieces-disable no-any-unknown -- the repo's own config document, opaque until a spec edits it\n load(): Record<string, unknown> {\n const source = path.join(__dirname, '..', '..', '..', '..', '..', '..', 'webpieces.config.json');\n // webpieces-disable no-any-unknown -- parsed JSON, narrowed by the accessors below\n const config = JSON.parse(fs.readFileSync(source, 'utf8')) as Record<string, unknown>;\n // webpieces-disable no-any-unknown -- narrowing one nested section\n const commands = config['commands'] as Record<string, Record<string, unknown>>;\n delete commands['pr-gate']['checklists'];\n delete commands['pr-gate']['checklistsWhy'];\n const prGate = commands['pr-gate'];\n // Local source requires this before the published validator permits the live repo to add it.\n prGate['maxReviewerRounds'] = 2;\n if (prGate['overrideReviewerAgent'] !== true && prGate['reviewerAgentName'] === DEFAULT_REVIEWER_AGENT_NAME) {\n delete prGate['reviewerAgentName'];\n }\n this.dropRetiredRules(config);\n this.completeRulesFromSeed(config);\n return config;\n }\n\n // Drop every rule/guard name this build knows to be RETIRED, from whichever section holds it.\n // webpieces-disable no-any-unknown -- see load()\n private dropRetiredRules(config: Record<string, unknown>): void {\n for (const section of ['rules', 'hookGuards']) {\n // webpieces-disable no-any-unknown -- narrowing one rule section\n const entries = config[section] as Record<string, unknown> | undefined;\n if (entries === undefined) continue;\n for (const name of Object.keys(entries)) {\n if (retiredRuleFor(name, fixtureRuleRegistry) !== null) delete entries[name];\n }\n }\n }\n\n /** Write `config` (usually a `load()` result a spec has edited) as the config of `dir`. */\n // webpieces-disable no-any-unknown -- see load()\n writeTo(dir: string, config: Record<string, unknown>): void {\n policyFixture.writeOwnerConfig(dir, config);\n }\n\n // webpieces-disable no-any-unknown -- see load()\n private completeRulesFromSeed(config: Record<string, unknown>): void {\n // webpieces-disable no-any-unknown -- narrowing the two rule sections\n const rules = config['rules'] as Record<string, unknown>;\n // webpieces-disable no-any-unknown -- narrowing the two rule sections\n const guards = config['hookGuards'] as Record<string, unknown>;\n for (const name of allRuleNames(fixtureRuleRegistry)) {\n const section = sectionForRule(name, fixtureRuleRegistry) === 'hookGuards' ? guards : rules;\n const seed = seedEntryForRule(name, fixtureRuleRegistry);\n // webpieces-disable no-any-unknown -- one rule's opaque config entry, merged over its typed seed\n const existing = section[name] as Record<string, unknown> | undefined;\n section[name] = existing === undefined ? seed : { ...seed, ...existing };\n }\n }\n}\n"]}
|