@webpieces/rules-config 0.4.847 → 0.4.849
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 +10 -7
- package/src/WebpiecesRulesConfig.d.ts +1 -2
- package/src/WebpiecesRulesConfig.js +0 -1
- package/src/WebpiecesRulesConfig.js.map +1 -1
- package/src/client-module-resolution.d.ts +9 -0
- package/src/client-module-resolution.js +102 -0
- package/src/client-module-resolution.js.map +1 -0
- package/src/config-error-banner.d.ts +0 -2
- package/src/config-error-banner.js +1 -3
- package/src/config-error-banner.js.map +1 -1
- package/src/config-file.d.ts +3 -6
- package/src/config-file.js +14 -1
- package/src/config-file.js.map +1 -1
- package/src/config-key-rules.js +16 -5
- package/src/config-key-rules.js.map +1 -1
- package/src/config-pruner.d.ts +5 -42
- package/src/config-pruner.js +31 -76
- package/src/config-pruner.js.map +1 -1
- package/src/config-repair-access.d.ts +4 -0
- package/src/config-repair-access.js +17 -0
- package/src/config-repair-access.js.map +1 -0
- package/src/config-repair-bootstrap-source.d.ts +2 -0
- package/src/config-repair-bootstrap-source.js +7 -0
- package/src/config-repair-bootstrap-source.js.map +1 -0
- package/src/config-repair-probe.d.ts +13 -0
- package/src/config-repair-probe.js +115 -0
- package/src/config-repair-probe.js.map +1 -0
- package/src/first-path-match.d.ts +14 -0
- package/src/first-path-match.js +35 -0
- package/src/first-path-match.js.map +1 -0
- package/src/index.d.ts +15 -8
- package/src/index.js +40 -10
- package/src/index.js.map +1 -1
- package/src/legacy-config-upgrade.d.ts +22 -0
- package/src/legacy-config-upgrade.js +328 -0
- package/src/legacy-config-upgrade.js.map +1 -0
- package/src/load-config.d.ts +11 -23
- package/src/load-config.js +50 -138
- package/src/load-config.js.map +1 -1
- package/src/pack-policy-files.d.ts +29 -0
- package/src/pack-policy-files.js +194 -0
- package/src/pack-policy-files.js.map +1 -0
- package/src/policy-field-constraints.d.ts +9 -0
- package/src/policy-field-constraints.js +31 -0
- package/src/policy-field-constraints.js.map +1 -0
- package/src/repository-path.d.ts +7 -0
- package/src/repository-path.js +50 -0
- package/src/repository-path.js.map +1 -0
- package/src/rule-pack-artifacts.d.ts +23 -0
- package/src/rule-pack-artifacts.js +180 -0
- package/src/rule-pack-artifacts.js.map +1 -0
- package/src/rule-pack-registry.d.ts +7 -0
- package/src/rule-pack-registry.js +149 -47
- package/src/rule-pack-registry.js.map +1 -1
- package/src/rule-pack-sync.d.ts +26 -0
- package/src/rule-pack-sync.js +236 -0
- package/src/rule-pack-sync.js.map +1 -0
- package/src/rule-runtime-modules.d.ts +27 -0
- package/src/rule-runtime-modules.js +135 -0
- package/src/rule-runtime-modules.js.map +1 -0
- package/src/rules-sync-cli.d.ts +7 -0
- package/src/rules-sync-cli.js +48 -0
- package/src/rules-sync-cli.js.map +1 -0
- package/src/seed-entry.js +1 -3
- package/src/seed-entry.js.map +1 -1
- package/src/types.d.ts +4 -6
- package/src/types.js +4 -7
- package/src/types.js.map +1 -1
- package/src/validate-config.d.ts +3 -29
- package/src/validate-config.js +99 -244
- package/src/validate-config.js.map +1 -1
- package/src/validate-pr-gate.d.ts +8 -0
- package/src/validate-pr-gate.js +161 -0
- package/src/validate-pr-gate.js.map +1 -0
- package/templates/webpieces.guard-matrix.md +5 -4
- package/src/rule-pack-selection.d.ts +0 -6
- package/src/rule-pack-selection.js +0 -50
- package/src/rule-pack-selection.js.map +0 -1
package/src/validate-config.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validatePrGateSection = exports.seedEntryForRule = exports.recommendedSeedModeFor = exports.recommendedSeedMode = exports.allRuleNames = exports.validateChecklistsSection = exports.MAX_TURN_OFF_EPOCH_DAYS = void 0;
|
|
4
4
|
exports.validateWebpiecesConfig = validateWebpiecesConfig;
|
|
5
|
-
exports.validatePrGateSection = validatePrGateSection;
|
|
6
5
|
exports.validateExcludePaths = validateExcludePaths;
|
|
7
6
|
exports.validateMatchRulesSection = validateMatchRulesSection;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const config_error_banner_1 = require("./config-error-banner");
|
|
12
|
-
const sections_1 = require("./sections");
|
|
7
|
+
const policy_field_constraints_1 = require("./policy-field-constraints");
|
|
8
|
+
var policy_field_constraints_2 = require("./policy-field-constraints");
|
|
9
|
+
Object.defineProperty(exports, "MAX_TURN_OFF_EPOCH_DAYS", { enumerable: true, get: function () { return policy_field_constraints_2.MAX_TURN_OFF_EPOCH_DAYS; } });
|
|
13
10
|
const seed_entry_1 = require("./seed-entry");
|
|
14
11
|
const rules_sdk_1 = require("@webpieces/rules-sdk");
|
|
15
12
|
const pr_gate_section_validators_1 = require("./pr-gate-section-validators");
|
|
@@ -36,8 +33,6 @@ const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
|
36
33
|
* out, six times this cap). The branch hatch fires only on ONE exact branch name — a big refactor
|
|
37
34
|
* legitimately runs 35+ days, and capping that would only interrupt the one branch that opted in.
|
|
38
35
|
*/
|
|
39
|
-
exports.MAX_TURN_OFF_EPOCH_DAYS = 7;
|
|
40
|
-
const SECONDS_PER_DAY = 24 * 60 * 60;
|
|
41
36
|
/**
|
|
42
37
|
* Reject a `turnOffRuleUntilEpoch` more than MAX_TURN_OFF_EPOCH_DAYS into the future.
|
|
43
38
|
*
|
|
@@ -47,18 +42,7 @@ const SECONDS_PER_DAY = 24 * 60 * 60;
|
|
|
47
42
|
*/
|
|
48
43
|
// webpieces-disable no-function-outside-class -- module-scope validator helper, matching every other check in this file
|
|
49
44
|
function epochCapError(label, value) {
|
|
50
|
-
|
|
51
|
-
if (value <= maxEpoch)
|
|
52
|
-
return null;
|
|
53
|
-
const daysOut = Math.round((value - Date.now() / 1000) / SECONDS_PER_DAY);
|
|
54
|
-
const maxDate = new Date(maxEpoch * 1000).toISOString().split('T')[0];
|
|
55
|
-
return (`${label} "turnOffRuleUntilEpoch": ${value} is ${daysOut} days in the future — the maximum is ` +
|
|
56
|
-
`${exports.MAX_TURN_OFF_EPOCH_DAYS} days. A rule switched off for longer than that is off for work nobody ` +
|
|
57
|
-
`had in mind when it was written, because this hatch is REPO-WIDE while it lasts.\n` +
|
|
58
|
-
` CURE: set it to at most ${maxEpoch} (${maxDate}), then re-set it WEEKLY for as long as you ` +
|
|
59
|
-
`still need it — that renewal is the intended workflow, not a workaround. If the rule is off for ` +
|
|
60
|
-
`ONE branch's work, use "turnOffRuleWhileOnBranch": "<exact branch name>" instead; that one has ` +
|
|
61
|
-
`no cap.`);
|
|
45
|
+
return new policy_field_constraints_1.PolicyFieldConstraints().epochError(label, value);
|
|
62
46
|
}
|
|
63
47
|
function valueHint(def, key) {
|
|
64
48
|
// The two universal escape hatches, REQUIRED on every rule so they're always visible. Spell out the
|
|
@@ -69,10 +53,14 @@ function valueHint(def, key) {
|
|
|
69
53
|
return 'null (null = always on; an EXACT branch name — no globs — disables the rule while that branch is checked out)';
|
|
70
54
|
return def.enumValues
|
|
71
55
|
? `"${def.enumValues.join(' | ')}"`
|
|
72
|
-
: def.type === 'string[]'
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
56
|
+
: def.type === 'string[]'
|
|
57
|
+
? '["<string>", ...]'
|
|
58
|
+
: def.type === 'object[]'
|
|
59
|
+
? objectListHint(def)
|
|
60
|
+
: def.type === 'number'
|
|
61
|
+
? '<number>'
|
|
62
|
+
: def.type === 'boolean'
|
|
63
|
+
? '<boolean>'
|
|
76
64
|
: '"<string>"';
|
|
77
65
|
}
|
|
78
66
|
/** `[{ "paths": ["<string>", ...], "suffixes": ["<string>", ...] }, ...]` — one element spelled out from its schema. */
|
|
@@ -85,8 +73,7 @@ function objectListHint(def) {
|
|
|
85
73
|
return `[{ ${fields.join(', ')} }, ...]`;
|
|
86
74
|
}
|
|
87
75
|
/**
|
|
88
|
-
* A config key
|
|
89
|
-
* to supply custom rules). THE FALLBACK: it fires for any name the table in retired-config-keys.ts does not
|
|
76
|
+
* A config key whose schema is absent from every explicitly selected owner manifest. THE FALLBACK: it fires for any name the table in retired-config-keys.ts does not
|
|
90
77
|
* know, which very much includes RETIRED names on a tree whose validator predates the retirement — the
|
|
91
78
|
* ordinary linked-worktree layout, where the worktree is on one release and the parent checkout that
|
|
92
79
|
* supplies the hook's resolution is on an older one. So this text has to be useful with NO table entry.
|
|
@@ -104,10 +91,10 @@ function objectListHint(def) {
|
|
|
104
91
|
* a secondary note, so a valid-but-newer key is never dropped without the reader being told the case exists.
|
|
105
92
|
*/
|
|
106
93
|
function unknownRuleError(ruleName) {
|
|
107
|
-
return (`[${ruleName}] Unknown rule — the running @webpieces validator has no schema for it
|
|
108
|
-
`"
|
|
109
|
-
`
|
|
110
|
-
`
|
|
94
|
+
return (`[${ruleName}] Unknown rule — the running @webpieces validator has no selected owner schema for it. A key no validator knows controls NOTHING, so ` +
|
|
95
|
+
`DELETE the "${ruleName}" key from the direct policy-ID map in its declared owner config file. ` +
|
|
96
|
+
`Run \`${constants_1.PRUNE_UNKNOWN_COMMAND}\` to remove unknown entries from declared owner files mechanically. ` +
|
|
97
|
+
`It may be RETIRED: a newer release can move ` +
|
|
111
98
|
`a setting out of this file entirely, in which case deleting the key here is the WHOLE fix. ` +
|
|
112
99
|
`MACHINE-LOCAL settings in particular now live in ~/.webpieces/config.json under "experimental" — ` +
|
|
113
100
|
`an optional file tracked by no repo, whose absence is the default behaviour — so if ` +
|
|
@@ -116,7 +103,7 @@ function unknownRuleError(ruleName) {
|
|
|
116
103
|
`and the version-drift guard reports THAT separately with its own cure (bump the pin) before this ` +
|
|
117
104
|
`validator ever runs — so it is not what you are looking at.`);
|
|
118
105
|
}
|
|
119
|
-
/** Schema advice
|
|
106
|
+
/** Schema advice names the selected owner rather than a retired root section. */
|
|
120
107
|
class RuleConfigAdvice {
|
|
121
108
|
registry;
|
|
122
109
|
constructor(registry) {
|
|
@@ -139,15 +126,16 @@ class RuleConfigAdvice {
|
|
|
139
126
|
// (turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch) are now REQUIRED, so they land in that block —
|
|
140
127
|
// which is the whole point: every seeded rule shows both hatches. Optional fields are listed separately.
|
|
141
128
|
const fields = Object.keys(schema);
|
|
142
|
-
const required = fields.filter(f => !schema[f].optional);
|
|
143
|
-
const optional = fields.filter(f => schema[f].optional);
|
|
144
|
-
const requiredLines = required.map(f => ` "${f}": ${valueHint(schema[f], f)}`);
|
|
145
|
-
const
|
|
146
|
-
let out = `[${ruleName}] Not configured in
|
|
129
|
+
const required = fields.filter((f) => !schema[f].optional);
|
|
130
|
+
const optional = fields.filter((f) => schema[f].optional);
|
|
131
|
+
const requiredLines = required.map((f) => ` "${f}": ${valueHint(schema[f], f)}`);
|
|
132
|
+
const owner = this.registry.ownerOf(ruleName);
|
|
133
|
+
let out = `[${ruleName}] Not configured in the declared owner config file for ${owner}. ` +
|
|
134
|
+
`Add this entry directly to that file's policy-ID map\n` +
|
|
147
135
|
`(choose values appropriate for your project):\n\n` +
|
|
148
136
|
` "${ruleName}": {\n${requiredLines.join(',\n')}\n }`;
|
|
149
137
|
if (optional.length > 0) {
|
|
150
|
-
const optionalLines = optional.map(f => ` "${f}": ${valueHint(schema[f], f)}`);
|
|
138
|
+
const optionalLines = optional.map((f) => ` "${f}": ${valueHint(schema[f], f)}`);
|
|
151
139
|
out +=
|
|
152
140
|
`\n\nOptional fields you may add to this rule (omit if not needed):\n` +
|
|
153
141
|
`${optionalLines.join(',\n')}`;
|
|
@@ -162,10 +150,6 @@ class RuleConfigAdvice {
|
|
|
162
150
|
// Universal field renames (apply to EVERY rule/guard AND every match-rule, unlike the per-rule
|
|
163
151
|
// RETIRED_FIELD_HINTS). When an entry still uses the old escape-hatch name, the generic unknown-field
|
|
164
152
|
// error is replaced with a precise "renamed to X — rename it" instruction so the fix is mechanical.
|
|
165
|
-
const RENAMED_FIELD_ALIASES = {
|
|
166
|
-
ignoreModifiedUntilEpoch: 'turnOffRuleUntilEpoch',
|
|
167
|
-
ignoreRuleWhileOnBranch: 'turnOffRuleWhileOnBranch',
|
|
168
|
-
};
|
|
169
153
|
// The renamed-field message shared by keyed rules and match-rules.
|
|
170
154
|
// webpieces-disable no-function-outside-class -- module-level config validator, matches the rest of this file
|
|
171
155
|
function renamedFieldError(scope, oldKey, newKey) {
|
|
@@ -180,17 +164,21 @@ function renamedFieldError(scope, oldKey, newKey) {
|
|
|
180
164
|
*/
|
|
181
165
|
// webpieces-disable no-any-unknown -- one config entry as opaque JSON; every field is typed-checked below
|
|
182
166
|
// webpieces-disable no-function-outside-class -- module-scope validator helper, matching every other check in this file
|
|
183
|
-
function fieldErrors(ruleName,
|
|
167
|
+
function fieldErrors(ruleName,
|
|
168
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
169
|
+
entry, schema, registry) {
|
|
184
170
|
const errors = [];
|
|
185
171
|
for (const [key, value] of Object.entries(entry)) {
|
|
186
172
|
const fieldDef = schema[key];
|
|
187
173
|
if (!fieldDef) {
|
|
188
|
-
const renamedTo =
|
|
174
|
+
const renamedTo = new policy_field_constraints_1.PolicyFieldConstraints().renamedField(key);
|
|
189
175
|
if (renamedTo) {
|
|
190
176
|
errors.push(renamedFieldError(`[${ruleName}]`, key, renamedTo));
|
|
191
177
|
continue;
|
|
192
178
|
}
|
|
193
|
-
const retiredHint = registry
|
|
179
|
+
const retiredHint = registry
|
|
180
|
+
.migrations()
|
|
181
|
+
.find((entry) => entry.scope === 'field' && entry.key === `${ruleName}.${key}`)?.instruction;
|
|
194
182
|
const suffix = retiredHint ? ` ${retiredHint}` : '';
|
|
195
183
|
errors.push(`[${ruleName}] Unknown field "${key}". Valid fields: [${Object.keys(schema).join(', ')}].${suffix}`);
|
|
196
184
|
continue;
|
|
@@ -212,8 +200,9 @@ function fieldErrors(ruleName, entry, schema, registry) {
|
|
|
212
200
|
if (capError)
|
|
213
201
|
errors.push(capError);
|
|
214
202
|
}
|
|
215
|
-
else if (ruleName === 'branch-state-guard' &&
|
|
216
|
-
|
|
203
|
+
else if (ruleName === 'branch-state-guard' &&
|
|
204
|
+
key === 'maxCommitsBehind' &&
|
|
205
|
+
(!Number.isInteger(value) || value < 0)) {
|
|
217
206
|
errors.push('[branch-state-guard] "maxCommitsBehind" must be a non-negative integer.');
|
|
218
207
|
}
|
|
219
208
|
}
|
|
@@ -227,16 +216,23 @@ function fieldErrors(ruleName, entry, schema, registry) {
|
|
|
227
216
|
*/
|
|
228
217
|
// webpieces-disable no-any-unknown -- a config field value is opaque JSON until this checks its shape
|
|
229
218
|
// webpieces-disable no-function-outside-class -- module-scope validator helper, matching every other check in this file
|
|
219
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
230
220
|
function arrayFieldErrors(label, value, def) {
|
|
231
221
|
const isObjects = def.type === 'object[]';
|
|
232
222
|
// webpieces-disable no-any-unknown -- one list element as opaque JSON; this line is what checks its shape
|
|
233
|
-
const elementOk = (v) => isObjects
|
|
223
|
+
const elementOk = (v) => isObjects
|
|
224
|
+
? typeof v === 'object' && v !== null && !Array.isArray(v)
|
|
225
|
+
: typeof v === 'string';
|
|
234
226
|
if (!Array.isArray(value) || !value.every(elementOk)) {
|
|
235
227
|
const shape = isObjects ? 'a list of objects' : 'string[]';
|
|
236
|
-
return [
|
|
228
|
+
return [
|
|
229
|
+
`${label} must be ${shape}, got ${Array.isArray(value) ? 'a list holding something else' : typeof value}.`,
|
|
230
|
+
];
|
|
237
231
|
}
|
|
238
232
|
if (def.nonEmpty && value.length === 0) {
|
|
239
|
-
return [
|
|
233
|
+
return [
|
|
234
|
+
`${label} must not be empty — an empty list judges nothing while reading as configured. Add ${valueHint(def)}.`,
|
|
235
|
+
];
|
|
240
236
|
}
|
|
241
237
|
if (!isObjects || def.elementSchema === undefined)
|
|
242
238
|
return [];
|
|
@@ -265,31 +261,32 @@ function arrayFieldErrors(label, value, def) {
|
|
|
265
261
|
return errors;
|
|
266
262
|
}
|
|
267
263
|
// webpieces-disable no-any-unknown -- rawRules values are opaque JSON; each field is validated individually
|
|
268
|
-
function validateWebpiecesConfig(
|
|
264
|
+
function validateWebpiecesConfig(
|
|
265
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
266
|
+
rawRules, registry) {
|
|
269
267
|
const errors = [];
|
|
270
268
|
const advice = new RuleConfigAdvice(registry);
|
|
271
269
|
// Check field-level correctness for rules that are present
|
|
272
270
|
for (const [ruleName, entry] of Object.entries(rawRules)) {
|
|
273
271
|
const schema = registry.hasRule(ruleName) ? registry.schemaFor(ruleName) : undefined;
|
|
274
272
|
if (!schema) {
|
|
275
|
-
if (registry.isSafeguard(ruleName) &&
|
|
273
|
+
if (registry.isSafeguard(ruleName) &&
|
|
274
|
+
!registry
|
|
275
|
+
.migrations()
|
|
276
|
+
.some((entry) => entry.scope === 'rule' && entry.key === ruleName)) {
|
|
276
277
|
errors.push(`[${ruleName}] is a cataloged safeguard, not a configurable policy. Delete its config entry; fixed safety cannot be disabled.`);
|
|
277
278
|
continue;
|
|
278
279
|
}
|
|
279
280
|
// A name we KNOW is retired beats the generic unknown-rule message, because only the table
|
|
280
281
|
// knows WHERE the setting went — a rename carries its value over, and a bare "delete it"
|
|
281
|
-
// would throw that value away.
|
|
282
|
-
// must not reuse a retired name.
|
|
282
|
+
// would throw that value away. Client packs must not reuse a retired canonical ID.
|
|
283
283
|
const retired = (0, retired_config_keys_1.retiredRuleFor)(ruleName, registry);
|
|
284
284
|
if (retired) {
|
|
285
285
|
errors.push((0, retired_config_keys_1.retiredKeyError)(retired));
|
|
286
286
|
continue;
|
|
287
287
|
}
|
|
288
|
-
//
|
|
289
|
-
|
|
290
|
-
// lingers here otherwise). With a rulesDir it may be a legitimate custom rule → skip.
|
|
291
|
-
if (!hasCustomRulesDir)
|
|
292
|
-
errors.push(unknownRuleError(ruleName));
|
|
288
|
+
// Client policies require a schema from an explicitly selected owner.
|
|
289
|
+
errors.push(unknownRuleError(ruleName));
|
|
293
290
|
continue;
|
|
294
291
|
}
|
|
295
292
|
errors.push(...fieldErrors(ruleName, entry, schema, registry));
|
|
@@ -313,152 +310,16 @@ function validateWebpiecesConfig(rawRules, registry, hasCustomRulesDir = false)
|
|
|
313
310
|
}
|
|
314
311
|
return errors;
|
|
315
312
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
// pr-gate-config import cycle; the canonical list + semantics live in pr-gate-config.ts.
|
|
319
|
-
const PR_GATE_MERGE_MODES = ['AUTO', 'NONE'];
|
|
320
|
-
// Spelled out because the choice is a POLICY decision with a consequence the chooser cannot see:
|
|
321
|
-
// only the AUTO path can put the compact risk/flags body in main's history, because a UI merge is
|
|
322
|
-
// composed from the repo's squash_merge_commit_title/message settings, which the tooling pins.
|
|
323
|
-
const MERGE_MODE_HELP = (`Must be one of: ${PR_GATE_MERGE_MODES.join(', ')}.\n` +
|
|
324
|
-
` "AUTO" — wp-finish-upsert-pr lands the PR: it squash-merges when mergeable, else enables\n` +
|
|
325
|
-
` GitHub auto-merge, both with an explicit --subject/--body-file so main's history\n` +
|
|
326
|
-
` gets the PR title + the compact risk/flags body. Needs allow_auto_merge on the repo\n` +
|
|
327
|
-
` (gh api repos/{owner}/{repo} --jq .allow_auto_merge).\n` +
|
|
328
|
-
` "NONE" — wp-finish-upsert-pr only opens/updates the PR; a human merges it, and that still\n` +
|
|
329
|
-
` lands the compact body: the PR DESCRIPTION *is* that body, and stage \u2462 keeps the repo's\n` +
|
|
330
|
-
` squash_merge_commit_title/message pinned to PR_TITLE/PR_BODY so a UI merge copies it\n` +
|
|
331
|
-
` verbatim (SquashSettingsEnforcer). Nothing to set by hand.`);
|
|
332
|
-
// Copy-paste example for the top-level `pr-gate` block (sibling of `rules`). Kept inline rather
|
|
333
|
-
// than imported from pr-gate-config.ts to avoid a load-config ↔ pr-gate-config import cycle.
|
|
334
|
-
function prGateExample() {
|
|
335
|
-
return (` "pr-gate": {\n` +
|
|
336
|
-
` "mode": "ON",\n` +
|
|
337
|
-
` "buildCommand": "<command CI runs to validate a PR, e.g. pnpm nx affected --target=ci --base=$(git merge-base origin/main HEAD)>",\n` +
|
|
338
|
-
` "gates": [\n` +
|
|
339
|
-
` { "name": "API Changed", "patterns": ["libraries/apis/**", "**/*Api.ts"], "warningColor": "yellow" }\n` +
|
|
340
|
-
` ],\n` +
|
|
341
|
-
` "reviewerAgents": 1, // REQUIRED — 0 disables reviews; positive values cap subagents per round\n` +
|
|
342
|
-
` "maxReviewerRounds": 2, // REQUIRED positive integer — caps complete global review rounds\n` +
|
|
343
|
-
` "checklists": [ // OPTIONAL — per-area review, each against its own doc\n` +
|
|
344
|
-
` { "id": "db-migrations", "doc": ".claude/review/db-migrations.md", "patterns": ["**/*.sql"], "required": true }\n` +
|
|
345
|
-
` ]\n` +
|
|
346
|
-
` }`);
|
|
347
|
-
}
|
|
348
|
-
// The `gates` array: dashboard-only warning flags. Extracted from validatePrGateSection to keep that
|
|
349
|
-
// method inside the length limit.
|
|
350
|
-
// webpieces-disable no-any-unknown -- `value` is the opaque consumer `gates` value until narrowed here
|
|
351
|
-
// webpieces-disable no-function-outside-class -- module-level config validator, matches the rest of this file
|
|
352
|
-
function validateGatesSection(value) {
|
|
353
|
-
if (!Array.isArray(value)) {
|
|
354
|
-
return [`[pr-gate] "gates" must be an array of { name, patterns, warningColor, disabled? }.`];
|
|
355
|
-
}
|
|
356
|
-
const errors = [];
|
|
357
|
-
for (let i = 0; i < value.length; i += 1) {
|
|
358
|
-
errors.push(...validateGate(value[i], i));
|
|
359
|
-
}
|
|
360
|
-
return errors;
|
|
361
|
-
}
|
|
362
|
-
// webpieces-disable no-any-unknown -- one gate entry from opaque consumer JSON, validated field-by-field
|
|
363
|
-
function validateGate(gate, index) {
|
|
364
|
-
if (typeof gate !== 'object' || gate === null) {
|
|
365
|
-
return [`[pr-gate] gates[${index}] must be an object { name, patterns, warningColor, disabled? }.`];
|
|
366
|
-
}
|
|
367
|
-
// webpieces-disable no-any-unknown -- narrowing one opaque gate object from consumer JSON
|
|
368
|
-
const g = gate;
|
|
369
|
-
const errors = [];
|
|
370
|
-
if (typeof g['name'] !== 'string')
|
|
371
|
-
errors.push(`[pr-gate] gates[${index}].name must be a string.`);
|
|
372
|
-
if (!Array.isArray(g['patterns']) || !g['patterns'].every(p => typeof p === 'string'))
|
|
373
|
-
errors.push(`[pr-gate] gates[${index}].patterns must be string[].`);
|
|
374
|
-
if (g['warningColor'] === undefined)
|
|
375
|
-
errors.push(`[pr-gate] gates[${index}].warningColor is required — set it to "yellow" or "red" (green is implicit when nothing matches).`);
|
|
376
|
-
else if (g['warningColor'] !== 'yellow' && g['warningColor'] !== 'red')
|
|
377
|
-
errors.push(`[pr-gate] gates[${index}].warningColor must be "yellow" or "red" (green is implicit when nothing matches).`);
|
|
378
|
-
if (g['disabled'] !== undefined && typeof g['disabled'] !== 'boolean')
|
|
379
|
-
errors.push(`[pr-gate] gates[${index}].disabled must be a boolean (example/inactive gate kept in the file).`);
|
|
380
|
-
return errors;
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* Validate the top-level `pr-gate` section. It is REQUIRED (a client that opts out sets mode "OFF").
|
|
384
|
-
* `buildCommand` is required unless mode is "OFF". Returns human-readable, copy-paste-friendly errors
|
|
385
|
-
* — never throws. The pr-gate block lives outside the FieldDef-driven `rules` schema because its
|
|
386
|
-
* nested `gates`/`checklists` arrays can't be expressed there, so they get structural validation here.
|
|
387
|
-
* `repoRoot` (when known) lets the `checklists[].docs` existence check run.
|
|
388
|
-
*/
|
|
389
|
-
// webpieces-disable no-any-unknown -- `section` is opaque consumer JSON until narrowed below
|
|
390
|
-
// webpieces-disable no-function-outside-class -- module-level config validator, matches the rest of this file
|
|
391
|
-
function validatePrGateSection(section, repoRoot) {
|
|
392
|
-
if (section === undefined || section === null) {
|
|
393
|
-
return [
|
|
394
|
-
`[pr-gate] Not configured in webpieces.config.json. Add this block under the "commands" ` +
|
|
395
|
-
`section (set "mode": "OFF" to opt out):\n\n${prGateExample()}`,
|
|
396
|
-
];
|
|
397
|
-
}
|
|
398
|
-
if (typeof section !== 'object' || Array.isArray(section)) {
|
|
399
|
-
return [`[pr-gate] Must be an object. Example:\n\n${prGateExample()}`];
|
|
400
|
-
}
|
|
401
|
-
// webpieces-disable no-any-unknown -- narrowing the opaque pr-gate section from consumer JSON
|
|
402
|
-
const s = section;
|
|
403
|
-
const errors = [];
|
|
404
|
-
if (!('mode' in s)) {
|
|
405
|
-
errors.push(`[pr-gate] Missing required field "mode". Must be one of: ${PR_GATE_MODES.join(', ')}.`);
|
|
406
|
-
}
|
|
407
|
-
else if (typeof s['mode'] !== 'string' || !PR_GATE_MODES.includes(s['mode'])) {
|
|
408
|
-
errors.push(`[pr-gate] "mode" = "${String(s['mode'])}" is not valid. Must be one of: ${PR_GATE_MODES.join(', ')}.`);
|
|
409
|
-
}
|
|
410
|
-
// buildCommand and mergeMode are both required whenever the gate is active (mode !== OFF). There
|
|
411
|
-
// is deliberately NO default for mergeMode: whether the tooling may land your PRs is a policy
|
|
412
|
-
// decision, and either guess is wrong for somebody.
|
|
413
|
-
if (s['mode'] !== 'OFF') {
|
|
414
|
-
const cmd = s['buildCommand'];
|
|
415
|
-
if (typeof cmd !== 'string' || cmd.trim() === '') {
|
|
416
|
-
errors.push(`[pr-gate] Missing required field "buildCommand" — the command CI runs to validate a PR. ` +
|
|
417
|
-
`Add e.g. "buildCommand": "pnpm nx affected --target=ci --base=$(git merge-base origin/main HEAD)".`);
|
|
418
|
-
}
|
|
419
|
-
const mm = s['mergeMode'];
|
|
420
|
-
if (!('mergeMode' in s)) {
|
|
421
|
-
errors.push(`[pr-gate] Missing required field "mergeMode". ${MERGE_MODE_HELP}`);
|
|
422
|
-
}
|
|
423
|
-
else if (typeof mm !== 'string' || !PR_GATE_MERGE_MODES.includes(mm)) {
|
|
424
|
-
errors.push(`[pr-gate] "mergeMode" = "${String(mm)}" is not valid. ${MERGE_MODE_HELP}`);
|
|
425
|
-
}
|
|
426
|
-
errors.push(...(0, pr_gate_section_validators_1.validateReviewerAgentKeys)(s, repoRoot));
|
|
427
|
-
}
|
|
428
|
-
if ('gates' in s)
|
|
429
|
-
errors.push(...validateGatesSection(s['gates']));
|
|
430
|
-
// Optional extension point: company review checklists, as an ARRAY right here in the config. Absent ⇒
|
|
431
|
-
// none. The removed { doc } manifest shape is rejected with the exact migration edit.
|
|
432
|
-
if ('checklists' in s)
|
|
433
|
-
errors.push(...(0, pr_gate_section_validators_1.validateChecklistsSection)(s['checklists'], repoRoot));
|
|
434
|
-
// Optional server-token salt. Absent ⇒ no token minted, CI enforcement is a no-op. Present ⇒ must be
|
|
435
|
-
// a non-empty string (an empty salt would mint a token anyone can forge from a known-empty secret).
|
|
436
|
-
if ('gateSalt' in s) {
|
|
437
|
-
const salt = s['gateSalt'];
|
|
438
|
-
if (typeof salt !== 'string' || salt.trim() === '') {
|
|
439
|
-
errors.push(`[pr-gate] "gateSalt" must be a non-empty string — it is the shared secret the gate token is HMAC'd with. Omit the key entirely to disable server-side token enforcement.`);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
// Optional: what happens to the LOCAL branch once its PR lands. Absent ⇒ "archive-tag".
|
|
443
|
-
if ('landPr' in s)
|
|
444
|
-
errors.push(...(0, pr_gate_section_validators_1.validateLandPrSection)(s['landPr']));
|
|
445
|
-
// Optional: where wp-push-dev publishes the disposable copy. Absent ⇒ "dev-include" / "dev".
|
|
446
|
-
if ('devDeploy' in s)
|
|
447
|
-
errors.push(...(0, pr_gate_section_validators_1.validateDevDeploySection)(s['devDeploy']));
|
|
448
|
-
errors.push(...(0, pr_gate_section_validators_1.validateNoGateSaltRationale)(s));
|
|
449
|
-
// Optional: publish reviewer output as a PR comment (defaults true). Must be a boolean when present.
|
|
450
|
-
if ('checklistComments' in s && typeof s['checklistComments'] !== 'boolean') {
|
|
451
|
-
errors.push(`[pr-gate] "checklistComments" must be a boolean (defaults to true; set false to keep the PR body-only).`);
|
|
452
|
-
}
|
|
453
|
-
return errors;
|
|
454
|
-
}
|
|
313
|
+
var validate_pr_gate_1 = require("./validate-pr-gate");
|
|
314
|
+
Object.defineProperty(exports, "validatePrGateSection", { enumerable: true, get: function () { return validate_pr_gate_1.validatePrGateSection; } });
|
|
455
315
|
function excludePathsExample() {
|
|
456
316
|
return '"excludePaths": ["repositories/**"]';
|
|
457
317
|
}
|
|
458
318
|
// A glob list: must be a string[] (may be empty). `key` names it for the error.
|
|
459
319
|
// webpieces-disable no-any-unknown -- `value` is opaque consumer JSON until narrowed here
|
|
460
320
|
function validateExcludeList(value, key) {
|
|
461
|
-
|
|
321
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
322
|
+
if (!(Array.isArray(value) && value.every((p) => typeof p === 'string'))) {
|
|
462
323
|
return [`[excludePaths] "${key}" must be a string[] of glob paths (use [] for none).`];
|
|
463
324
|
}
|
|
464
325
|
return [];
|
|
@@ -485,7 +346,9 @@ function validateExcludePaths(section) {
|
|
|
485
346
|
if (Array.isArray(section))
|
|
486
347
|
return validateExcludeList(section, 'excludePaths');
|
|
487
348
|
if (typeof section !== 'object') {
|
|
488
|
-
return [
|
|
349
|
+
return [
|
|
350
|
+
`[excludePaths] Must be a string[] of glob paths. Example:\n\n ${excludePathsExample()}`,
|
|
351
|
+
];
|
|
489
352
|
}
|
|
490
353
|
// webpieces-disable no-any-unknown -- narrowing the opaque excludePaths section from consumer JSON
|
|
491
354
|
const s = section;
|
|
@@ -494,7 +357,9 @@ function validateExcludePaths(section) {
|
|
|
494
357
|
if (retired && (s['rules'] !== undefined || s['guards'] !== undefined)) {
|
|
495
358
|
return [`${(0, retired_config_keys_1.retiredKeyError)(retired)}\n\n ${excludePathsExample()}`];
|
|
496
359
|
}
|
|
497
|
-
return [
|
|
360
|
+
return [
|
|
361
|
+
`[excludePaths] Must be a string[] of glob paths. Example:\n\n ${excludePathsExample()}`,
|
|
362
|
+
];
|
|
498
363
|
}
|
|
499
364
|
// ---------------------------------------------------------------------------
|
|
500
365
|
// match-rules — a new top-level ARRAY section (parallel to pr-gate/excludePaths). Each entry is a
|
|
@@ -506,7 +371,8 @@ function matchRulesExample() {
|
|
|
506
371
|
}
|
|
507
372
|
// webpieces-disable no-any-unknown -- generic type guard over an opaque JSON value
|
|
508
373
|
function isStringArray(value) {
|
|
509
|
-
|
|
374
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
375
|
+
return Array.isArray(value) && value.every((v) => typeof v === 'string');
|
|
510
376
|
}
|
|
511
377
|
// Compile a pattern to validate it; returns the error message, or undefined when it compiles.
|
|
512
378
|
function regexError(pattern) {
|
|
@@ -515,6 +381,7 @@ function regexError(pattern) {
|
|
|
515
381
|
// Constructed only to validate the syntax; the object is intentionally discarded.
|
|
516
382
|
void new RegExp(pattern);
|
|
517
383
|
return undefined;
|
|
384
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
518
385
|
}
|
|
519
386
|
catch (err) {
|
|
520
387
|
const error = (0, to_error_1.toError)(err);
|
|
@@ -525,7 +392,9 @@ function regexError(pattern) {
|
|
|
525
392
|
// webpieces-disable no-any-unknown -- one match-rule entry from opaque consumer JSON, validated field-by-field
|
|
526
393
|
function validateMatchRule(entry, index) {
|
|
527
394
|
if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
|
|
528
|
-
return [
|
|
395
|
+
return [
|
|
396
|
+
`[match-rules] entry[${index}] must be an object { name, patterns, mainMessage, mode, turnOffRuleUntilEpoch, turnOffRuleWhileOnBranch, ... }.`,
|
|
397
|
+
];
|
|
529
398
|
}
|
|
530
399
|
// webpieces-disable no-any-unknown -- narrowing one opaque match-rule entry from consumer JSON
|
|
531
400
|
const e = entry;
|
|
@@ -545,27 +414,10 @@ function validateMatchRule(entry, index) {
|
|
|
545
414
|
}
|
|
546
415
|
if (typeof e['mainMessage'] !== 'string' || e['mainMessage'].trim() === '')
|
|
547
416
|
errors.push(`[match-rules] ${label}.mainMessage must be a non-empty string.`);
|
|
548
|
-
if (typeof e['mode'] !== 'string' ||
|
|
417
|
+
if (typeof e['mode'] !== 'string' ||
|
|
418
|
+
!rules_sdk_1.MODIFIED_CODE_MODES.includes(e['mode']))
|
|
549
419
|
errors.push(`[match-rules] ${label}.mode must be one of: ${rules_sdk_1.MODIFIED_CODE_MODES.join(', ')}.`);
|
|
550
|
-
|
|
551
|
-
// visible. turnOffRuleUntilEpoch: number (0 = active; a future unix-epoch in seconds = temporarily
|
|
552
|
-
// off). turnOffRuleWhileOnBranch: string | null (null = always on; an EXACT branch name — matched
|
|
553
|
-
// with ===, never as a glob — disables the rule while that branch is checked out).
|
|
554
|
-
if (typeof e['turnOffRuleUntilEpoch'] !== 'number') {
|
|
555
|
-
errors.push(`[match-rules] ${label}.turnOffRuleUntilEpoch must be a number (0 = active; future unix-epoch seconds = temporarily off).`);
|
|
556
|
-
}
|
|
557
|
-
else {
|
|
558
|
-
const capError = epochCapError(`[match-rules] ${label}`, e['turnOffRuleUntilEpoch']);
|
|
559
|
-
if (capError)
|
|
560
|
-
errors.push(capError);
|
|
561
|
-
}
|
|
562
|
-
if (!(e['turnOffRuleWhileOnBranch'] === null || typeof e['turnOffRuleWhileOnBranch'] === 'string'))
|
|
563
|
-
errors.push(`[match-rules] ${label}.turnOffRuleWhileOnBranch must be a string or null (null = no branch / always on; a string is an EXACT branch name, globs are not supported).`);
|
|
564
|
-
// The old escape-hatch names were renamed — flag them precisely.
|
|
565
|
-
for (const oldKey of Object.keys(RENAMED_FIELD_ALIASES)) {
|
|
566
|
-
if (oldKey in e)
|
|
567
|
-
errors.push(renamedFieldError(`[match-rules] ${label}`, oldKey, RENAMED_FIELD_ALIASES[oldKey]));
|
|
568
|
-
}
|
|
420
|
+
errors.push(...validateMatchRuleHatches(e, label));
|
|
569
421
|
if (e['options'] !== undefined && !isStringArray(e['options']))
|
|
570
422
|
errors.push(`[match-rules] ${label}.options must be a string[] (omit if not needed).`);
|
|
571
423
|
if (e['allowedPaths'] !== undefined && !isStringArray(e['allowedPaths']))
|
|
@@ -590,7 +442,9 @@ function validateMatchRulesSection(section) {
|
|
|
590
442
|
];
|
|
591
443
|
}
|
|
592
444
|
if (!Array.isArray(section)) {
|
|
593
|
-
return [
|
|
445
|
+
return [
|
|
446
|
+
`[match-rules] Must be an array of content-guard objects. Example:\n\n${matchRulesExample()}`,
|
|
447
|
+
];
|
|
594
448
|
}
|
|
595
449
|
const errors = [];
|
|
596
450
|
const seen = new Set();
|
|
@@ -606,28 +460,29 @@ function validateMatchRulesSection(section) {
|
|
|
606
460
|
}
|
|
607
461
|
return errors;
|
|
608
462
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
* "move it" message so the split stays clean. Unknown/custom names are ignored (they may be custom
|
|
613
|
-
* rules from rulesDir). Presence ("every built-in must be configured") is checked separately by
|
|
614
|
-
* validateWebpiecesConfig against the merged map.
|
|
615
|
-
*/
|
|
616
|
-
// webpieces-disable no-any-unknown -- section maps are opaque consumer JSON
|
|
617
|
-
function validateSectionPlacement(rulesSection, hookGuardsSection, registry) {
|
|
463
|
+
// webpieces-disable no-any-unknown -- explicit match-rule JSON is checked field by field
|
|
464
|
+
// webpieces-disable no-function-outside-class -- pure validation helper
|
|
465
|
+
function validateMatchRuleHatches(e, label) {
|
|
618
466
|
const errors = [];
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
467
|
+
// Both escape hatches are REQUIRED on every match-rule too (same as keyed rules), so they are always
|
|
468
|
+
// visible. turnOffRuleUntilEpoch: number (0 = active; a future unix-epoch in seconds = temporarily
|
|
469
|
+
// off). turnOffRuleWhileOnBranch: string | null (null = always on; an EXACT branch name — matched
|
|
470
|
+
// with ===, never as a glob — disables the rule while that branch is checked out).
|
|
471
|
+
if (typeof e['turnOffRuleUntilEpoch'] !== 'number') {
|
|
472
|
+
errors.push(`[match-rules] ${label}.turnOffRuleUntilEpoch must be a number (0 = active; future unix-epoch seconds = temporarily off).`);
|
|
624
473
|
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
if (
|
|
628
|
-
errors.push(
|
|
629
|
-
|
|
630
|
-
|
|
474
|
+
else {
|
|
475
|
+
const capError = epochCapError(`[match-rules] ${label}`, e['turnOffRuleUntilEpoch']);
|
|
476
|
+
if (capError)
|
|
477
|
+
errors.push(capError);
|
|
478
|
+
}
|
|
479
|
+
if (!(e['turnOffRuleWhileOnBranch'] === null ||
|
|
480
|
+
typeof e['turnOffRuleWhileOnBranch'] === 'string'))
|
|
481
|
+
errors.push(`[match-rules] ${label}.turnOffRuleWhileOnBranch must be a string or null (null = no branch / always on; a string is an EXACT branch name, globs are not supported).`);
|
|
482
|
+
// The old escape-hatch names were renamed — flag them precisely.
|
|
483
|
+
for (const oldKey of new policy_field_constraints_1.PolicyFieldConstraints().retiredFields()) {
|
|
484
|
+
if (oldKey in e)
|
|
485
|
+
errors.push(renamedFieldError(`[match-rules] ${label}`, oldKey, new policy_field_constraints_1.PolicyFieldConstraints().renamedField(oldKey)));
|
|
631
486
|
}
|
|
632
487
|
return errors;
|
|
633
488
|
}
|