@gate-forge/cli 0.11.1 → 0.12.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/CHANGELOG.md +34 -0
- package/README.md +1 -0
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +1 -0
- package/dist/args.js.map +1 -1
- package/dist/business-rules.d.ts +223 -0
- package/dist/business-rules.d.ts.map +1 -0
- package/dist/business-rules.js +383 -0
- package/dist/business-rules.js.map +1 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +96 -18
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/enforcement.d.ts.map +1 -1
- package/dist/commands/enforcement.js +5 -11
- package/dist/commands/enforcement.js.map +1 -1
- package/dist/commands/init.d.ts +3 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +39 -3
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/next.d.ts.map +1 -1
- package/dist/commands/next.js +55 -1
- package/dist/commands/next.js.map +1 -1
- package/dist/commands/pre-commit.d.ts.map +1 -1
- package/dist/commands/pre-commit.js +5 -8
- package/dist/commands/pre-commit.js.map +1 -1
- package/dist/commands/test-gates.d.ts.map +1 -1
- package/dist/commands/test-gates.js +62 -5
- package/dist/commands/test-gates.js.map +1 -1
- package/dist/commands/tests.d.ts +1 -1
- package/dist/commands/tests.d.ts.map +1 -1
- package/dist/commands/tests.js +101 -11
- package/dist/commands/tests.js.map +1 -1
- package/dist/evaluate.d.ts +16 -0
- package/dist/evaluate.d.ts.map +1 -1
- package/dist/evaluate.js +26 -2
- package/dist/evaluate.js.map +1 -1
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +10 -2
- package/dist/execution.js.map +1 -1
- package/dist/input-snapshot.d.ts.map +1 -1
- package/dist/input-snapshot.js +17 -7
- package/dist/input-snapshot.js.map +1 -1
- package/dist/mapping.d.ts +10 -1
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +5 -0
- package/dist/mapping.js.map +1 -1
- package/dist/pipeline.d.ts +9 -1
- package/dist/pipeline.d.ts.map +1 -1
- package/dist/pipeline.js +1 -0
- package/dist/pipeline.js.map +1 -1
- package/dist/staged-candidate.d.ts +1 -36
- package/dist/staged-candidate.d.ts.map +1 -1
- package/dist/staged-candidate.js +0 -47
- package/dist/staged-candidate.js.map +1 -1
- package/guides/QUICKSTART.md +20 -7
- package/guides/REFERENCE.md +62 -0
- package/package.json +10 -10
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI seam for owner-declared BUSINESS RULES
|
|
3
|
+
* (plan 2026-10-05 §5 D3/D4/D5, WP4).
|
|
4
|
+
*
|
|
5
|
+
* One module owns every fact a rule needs, because the three consumers
|
|
6
|
+
* — `check`, `next` and `tests mark`/`explain` — must never disagree
|
|
7
|
+
* about what a case is worth:
|
|
8
|
+
*
|
|
9
|
+
* - the OWNER rules come from the owner-answers document, which the
|
|
10
|
+
* pipeline already read (never a second read of the same file);
|
|
11
|
+
* - the CLAIM IDS come from the cases those rules declare, and are what
|
|
12
|
+
* the one mapping resolver validates a `business-rule:` claim against;
|
|
13
|
+
* - the RUN FACTS come from a SEALED execution result plus the sealed
|
|
14
|
+
* records and the owner's WITNESSED suite declarations. A run with no
|
|
15
|
+
* sealed execution result passes `null`, and `null` grades everything
|
|
16
|
+
* mapped as `unproven` — a declaration is never proof.
|
|
17
|
+
*
|
|
18
|
+
* Two invariants this module exists to hold:
|
|
19
|
+
* - **run-wide.** Rule grading reads the FULL rule list and the FULL
|
|
20
|
+
* rule bindings, never the changed-file selection, so a `--scope
|
|
21
|
+
* changed` run cannot scope a rule away. A case whose test sits
|
|
22
|
+
* outside that run's graded slice is reported as `unproven (outside
|
|
23
|
+
* this run's graded slice)` — visible, not absent, and never
|
|
24
|
+
* satisfied by a receipt that never covered it.
|
|
25
|
+
* - **advisory never hides.** `enforcement: advisory` routes a case's
|
|
26
|
+
* finding into the report's existing `advisories` channel; only
|
|
27
|
+
* `enforcement: block` findings reach `blocking` and the exit code.
|
|
28
|
+
* Both channels carry the same typed cause, and the channel is decided
|
|
29
|
+
* by the OWNER's declaration on the rule, never by a new severity.
|
|
30
|
+
*/
|
|
31
|
+
import { BUSINESS_RULE_TYPE_TABLE, businessRuleClaimId, EvidenceRecordSchema, casesOf, evaluateBusinessRules, } from '@gate-forge/core';
|
|
32
|
+
import { UsageError } from './errors.js';
|
|
33
|
+
/** Every rule-case claim id this rule list declares, sorted. */
|
|
34
|
+
export function businessRuleClaimIds(rules) {
|
|
35
|
+
const ids = rules.flatMap((rule) => casesOf(rule).map((entry) => businessRuleClaimId(rule.id, entry.id)));
|
|
36
|
+
return [...new Set(ids)].sort();
|
|
37
|
+
}
|
|
38
|
+
/** The runner each catalog row executes under, keyed by logical key. */
|
|
39
|
+
export function catalogRunnerIndex(catalog) {
|
|
40
|
+
return new Map(catalog.entries.map((entry) => [entry.logicalKey, entry.runner]));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The logical test keys whose FILE the catalog observed intercepting the
|
|
44
|
+
* system under test. A mocked spec can never satisfy a rule: it proves
|
|
45
|
+
* the mock, not the rule (plan invariant 6).
|
|
46
|
+
*/
|
|
47
|
+
export function mockedTestKeys(catalog) {
|
|
48
|
+
return new Set(catalog.entries
|
|
49
|
+
.filter((entry) => entry.suppressionSignals.some((signal) => signal.kind === 'mock'))
|
|
50
|
+
.map((entry) => entry.logicalKey));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The resolver's rule bindings projected onto the evaluator's binding
|
|
54
|
+
* shape. Pure; the resolver has already dropped quarantined, stale and
|
|
55
|
+
* wildcard-rejected declarations, and the evaluator independently
|
|
56
|
+
* refuses anything but `native`/`sidecar` origins.
|
|
57
|
+
*
|
|
58
|
+
* A binding whose selector bound no catalog instance contributes no
|
|
59
|
+
* runner, which the evaluator reads as "not an accepted kind" rather
|
|
60
|
+
* than guessing one: a declaration with no resolvable instance is not
|
|
61
|
+
* proof of anything.
|
|
62
|
+
*/
|
|
63
|
+
export function businessRuleBindingsOf(ruleBindings, runners, mockedKeys) {
|
|
64
|
+
const bindings = new Map();
|
|
65
|
+
for (const claim of ruleBindings) {
|
|
66
|
+
bindings.set(claim.claimId, claim.bindings.map((binding) => ({
|
|
67
|
+
logicalKey: binding.logicalKey,
|
|
68
|
+
origin: binding.origin,
|
|
69
|
+
declaredKind: binding.declaredKind,
|
|
70
|
+
runner: runners.get(binding.logicalKey) ?? '',
|
|
71
|
+
mocked: mockedKeys.has(binding.logicalKey),
|
|
72
|
+
reason: binding.reason,
|
|
73
|
+
file: binding.instances[0]?.file ?? binding.logicalKey,
|
|
74
|
+
})));
|
|
75
|
+
}
|
|
76
|
+
return bindings;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Reads the OWNER's declared `witnessed` diagnostic suites as the set of
|
|
80
|
+
* runner names whose proof this repository can produce. A suite the
|
|
81
|
+
* owner did not mark witnessed contributes nothing: the pytest row of
|
|
82
|
+
* the type table requires one, and an unwitnessed suite is not proof
|
|
83
|
+
* (owner decision, 2026-10-04).
|
|
84
|
+
*/
|
|
85
|
+
export function witnessedRunnersOf(config) {
|
|
86
|
+
const runners = new Set();
|
|
87
|
+
for (const suite of config.diagnostics?.suites ?? []) {
|
|
88
|
+
if (suite.witnessed === true)
|
|
89
|
+
runners.add('pytest');
|
|
90
|
+
}
|
|
91
|
+
return runners;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* One test's sealed facts.
|
|
95
|
+
*
|
|
96
|
+
* The GRADED SLICE is the selection the supervisor fixed BEFORE the run:
|
|
97
|
+
* a test the selection did not name is outside the slice even when the
|
|
98
|
+
* runner happened to execute it, which is exactly the `--scope changed`
|
|
99
|
+
* case the plan calls out. Status is the supervisor's own normalized
|
|
100
|
+
* outcome, never a reporter summary.
|
|
101
|
+
*/
|
|
102
|
+
function testFactOf(result, logicalKey, executionKey, runners) {
|
|
103
|
+
const planned = result.planned.find((instance) => instance.logicalKey === executionKey);
|
|
104
|
+
const outcome = result.outcomes.find((row) => row.logicalKey === executionKey);
|
|
105
|
+
// The session trace joins on the INSTANCE identity (project, file,
|
|
106
|
+
// title path). Runner adapters may use a reconciliation key in the
|
|
107
|
+
// sealed result while the catalog and sidecar use the catalog key.
|
|
108
|
+
const trace = (result.sessionTrace ?? []).find((test) => planned !== undefined &&
|
|
109
|
+
test.file === planned.file &&
|
|
110
|
+
test.project === planned.project &&
|
|
111
|
+
test.titlePath.join('>') === planned.titlePath.join('>'));
|
|
112
|
+
return {
|
|
113
|
+
logicalKey,
|
|
114
|
+
runner: runners.get(logicalKey) ?? '',
|
|
115
|
+
status: outcome?.status ?? 'not-run',
|
|
116
|
+
inGradedSlice: result.selection.logicalKeys.includes(executionKey),
|
|
117
|
+
sessionIds: (trace?.sessions ?? []).map((session) => session.sessionId),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** Stable join key shared by catalog, planned, and executed test instances. */
|
|
121
|
+
function instanceKey(project, file, titlePath) {
|
|
122
|
+
return `${project ?? ''}\u0000${file}\u0000${titlePath.join('>')}`;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Builds the evaluator's run facts from a SEALED execution result.
|
|
126
|
+
*
|
|
127
|
+
* Args:
|
|
128
|
+
* input: the sealed execution result (null when none exists), the
|
|
129
|
+
* sealed records, the witnessed runners, the receipt's scope, and the
|
|
130
|
+
* run's catalog.
|
|
131
|
+
*
|
|
132
|
+
* Returns:
|
|
133
|
+
* BusinessRuleRunFacts | null: the facts, or null for no sealed run —
|
|
134
|
+
* which is what makes a static `check` grade everything mapped as
|
|
135
|
+
* `unproven` instead of quietly satisfied.
|
|
136
|
+
*/
|
|
137
|
+
export function businessRuleRunFacts(input) {
|
|
138
|
+
if (input.result === null)
|
|
139
|
+
return null;
|
|
140
|
+
const runners = catalogRunnerIndex(input.catalog);
|
|
141
|
+
const logicalKeyByInstance = new Map(input.catalog.entries.map((entry) => [
|
|
142
|
+
instanceKey(entry.project, entry.file, entry.titlePath),
|
|
143
|
+
entry.logicalKey,
|
|
144
|
+
]));
|
|
145
|
+
const logicalKeyOf = (project, file, titlePath, fallback) => logicalKeyByInstance.get(instanceKey(project, file, titlePath)) ?? fallback;
|
|
146
|
+
const tests = new Map();
|
|
147
|
+
// Planned instances first (the expected set), then any outcome for a
|
|
148
|
+
// key the plan never listed: the plan is pre-run, the outcome is what
|
|
149
|
+
// actually ran, and an executed-but-unplanned key is still a fact.
|
|
150
|
+
for (const planned of input.result.planned) {
|
|
151
|
+
const logicalKey = logicalKeyOf(planned.project, planned.file, planned.titlePath, planned.logicalKey);
|
|
152
|
+
tests.set(logicalKey, testFactOf(input.result, logicalKey, planned.logicalKey, runners));
|
|
153
|
+
}
|
|
154
|
+
for (const outcome of input.result.outcomes) {
|
|
155
|
+
const logicalKey = logicalKeyOf(outcome.project, outcome.file, outcome.titlePath, outcome.logicalKey);
|
|
156
|
+
if (tests.has(logicalKey))
|
|
157
|
+
continue;
|
|
158
|
+
tests.set(logicalKey, testFactOf(input.result, logicalKey, outcome.logicalKey, runners));
|
|
159
|
+
}
|
|
160
|
+
// Runner adapters use their reconciliation identity (`file#title`)
|
|
161
|
+
// in execution results, while catalog/sidecar mappings use the
|
|
162
|
+
// declared logical key (`pytest:suite:file:title`). Bridge only rows
|
|
163
|
+
// from the runner whose execution this result records, and only when
|
|
164
|
+
// the planned instance identifies one unambiguous catalog row.
|
|
165
|
+
for (const entry of input.catalog.entries) {
|
|
166
|
+
if (entry.runner !== input.result.selection.runner || tests.has(entry.logicalKey))
|
|
167
|
+
continue;
|
|
168
|
+
const matchingInstances = input.result.planned.filter((planned) => planned.file === entry.file &&
|
|
169
|
+
planned.titlePath.join('>') === entry.titlePath.join('>'));
|
|
170
|
+
const instance = matchingInstances[0];
|
|
171
|
+
if (matchingInstances.length !== 1 || instance === undefined)
|
|
172
|
+
continue;
|
|
173
|
+
tests.set(entry.logicalKey, testFactOf(input.result, entry.logicalKey, instance.logicalKey, runners));
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
scope: input.scope,
|
|
177
|
+
docsOnly: input.docsOnly,
|
|
178
|
+
tests,
|
|
179
|
+
records: authorizedRecords(input.records),
|
|
180
|
+
witnessedRunners: input.witnessedRunners,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Validates the run's AUTHORIZED records into the typed shape the
|
|
185
|
+
* evaluator reads.
|
|
186
|
+
*
|
|
187
|
+
* `evaluateRun` returns them as `unknown[]` because all that has been
|
|
188
|
+
* established at that point is AUTHORIZATION, not shape. This is where
|
|
189
|
+
* the shape is established: a record that does not parse contributes no
|
|
190
|
+
* proof, which is the fail-closed direction. Parsing here rather than
|
|
191
|
+
* asserting a type keeps a malformed or tampered ledger from being
|
|
192
|
+
* attributed to a rule case.
|
|
193
|
+
*
|
|
194
|
+
* Args:
|
|
195
|
+
* records: the authorized, quarantine-filtered records.
|
|
196
|
+
*
|
|
197
|
+
* Returns:
|
|
198
|
+
* EvidenceRecord[]: the records that satisfy the schema, in input order.
|
|
199
|
+
*/
|
|
200
|
+
function authorizedRecords(records) {
|
|
201
|
+
const valid = [];
|
|
202
|
+
for (const record of records) {
|
|
203
|
+
const parsed = EvidenceRecordSchema.safeParse(record);
|
|
204
|
+
if (parsed.success)
|
|
205
|
+
valid.push(parsed.data);
|
|
206
|
+
}
|
|
207
|
+
return valid;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Grades every declared rule case for one run.
|
|
211
|
+
*
|
|
212
|
+
* Args:
|
|
213
|
+
* input: rules, rule bindings, the inventory, the sealed facts and the
|
|
214
|
+
* catalog.
|
|
215
|
+
*
|
|
216
|
+
* Returns:
|
|
217
|
+
* BusinessRuleEvaluation: config errors plus every case result, sorted
|
|
218
|
+
* by rule id then case id.
|
|
219
|
+
*
|
|
220
|
+
* Throws:
|
|
221
|
+
* UsageError: when a rule names a `subject` the inventory cannot see
|
|
222
|
+
* (exit 2 — a silently uncheckable name is a configuration error, the
|
|
223
|
+
* same posture as an unknown coverage table).
|
|
224
|
+
*/
|
|
225
|
+
export function gradeBusinessRules(input) {
|
|
226
|
+
const evaluation = evaluateBusinessRules({
|
|
227
|
+
rules: input.rules,
|
|
228
|
+
bindings: businessRuleBindingsOf(input.ruleBindings, catalogRunnerIndex(input.catalog), mockedTestKeys(input.catalog)),
|
|
229
|
+
inventory: input.inventory,
|
|
230
|
+
runFacts: input.runFacts,
|
|
231
|
+
});
|
|
232
|
+
if (evaluation.configErrors.length > 0) {
|
|
233
|
+
const first = evaluation.configErrors[0];
|
|
234
|
+
throw new UsageError(`${first?.detail ?? 'a business rule names an unknown subject'}${evaluation.configErrors.length > 1
|
|
235
|
+
? ` (and ${String(evaluation.configErrors.length - 1)} more business-rule configuration error(s))`
|
|
236
|
+
: ''}`);
|
|
237
|
+
}
|
|
238
|
+
return evaluation;
|
|
239
|
+
}
|
|
240
|
+
/** One case result projected onto the report's blocking-entry shape. */
|
|
241
|
+
function blockingEntryOf(result) {
|
|
242
|
+
const finding = result.finding;
|
|
243
|
+
return {
|
|
244
|
+
kind: 'finding',
|
|
245
|
+
resourceId: null,
|
|
246
|
+
name: result.ruleId,
|
|
247
|
+
detail: finding?.detail ?? '',
|
|
248
|
+
location: null,
|
|
249
|
+
cause: finding?.cause ?? 'BUSINESS_RULE_TEST_MISSING',
|
|
250
|
+
nextAction: finding?.nextAction ?? '',
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Splits a graded evaluation into the report's TWO channels.
|
|
255
|
+
*
|
|
256
|
+
* `enforcement: advisory` is decided by the OWNER's declaration on the
|
|
257
|
+
* rule, not by how bad the case looks: an advisory rule's findings are
|
|
258
|
+
* printed and serialized every run and only stay out of `blocking` and
|
|
259
|
+
* the exit code (plan invariant 7). The codes are identical in both
|
|
260
|
+
* channels, so a reader tells an advisory finding from a blocking one by
|
|
261
|
+
* where it is, never by a new severity.
|
|
262
|
+
*/
|
|
263
|
+
export function partitionBusinessRuleEntries(rules, cases) {
|
|
264
|
+
const enforcement = new Map(rules.map((rule) => [rule.id, rule.enforcement]));
|
|
265
|
+
const blocking = [];
|
|
266
|
+
const advisories = [];
|
|
267
|
+
for (const result of cases) {
|
|
268
|
+
if (result.finding === null)
|
|
269
|
+
continue;
|
|
270
|
+
const entry = blockingEntryOf(result);
|
|
271
|
+
if (enforcement.get(result.ruleId) === 'advisory')
|
|
272
|
+
advisories.push(entry);
|
|
273
|
+
else
|
|
274
|
+
blocking.push(entry);
|
|
275
|
+
}
|
|
276
|
+
return { blocking, advisories };
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* The resource names one run's inventory offers as a rule `subject`.
|
|
280
|
+
* Ranking and display only — a subject is never proof, and a rule
|
|
281
|
+
* without one is graded regardless of this list.
|
|
282
|
+
*/
|
|
283
|
+
export function businessRuleInventory(graph) {
|
|
284
|
+
return [
|
|
285
|
+
...new Set(graph.resources.flatMap((resource) => (resource.name === null ? [] : [resource.name]))),
|
|
286
|
+
].sort();
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Serializes every graded rule case for the report's `businessRules`
|
|
290
|
+
* section (plan §7.5, invariant 6): a SATISFIED case must be visible
|
|
291
|
+
* naming the channel that proved it — "satisfied" read as "the rule
|
|
292
|
+
* holds" is exactly the overclaim the channel naming exists to prevent —
|
|
293
|
+
* and a demoted (advisory) case appears here beside its advisory-channel
|
|
294
|
+
* entry, so the section is the one place that lists EVERY case with its
|
|
295
|
+
* status. The section rides the json document only when rules are
|
|
296
|
+
* declared, so a repository without the feature keeps its exact report.
|
|
297
|
+
*
|
|
298
|
+
* Args:
|
|
299
|
+
* rules: the owner's declared rules (status and channel context).
|
|
300
|
+
* cases: the graded case results, sorted by rule id then case id.
|
|
301
|
+
*
|
|
302
|
+
* Returns:
|
|
303
|
+
* BusinessRuleReportEntry[]: the serialized cases, input order.
|
|
304
|
+
*/
|
|
305
|
+
export function businessRuleReportEntries(rules, cases) {
|
|
306
|
+
const typeOf = new Map(rules.map((rule) => [rule.id, rule.test]));
|
|
307
|
+
const enforcementOf = new Map(rules.map((rule) => [rule.id, rule.enforcement]));
|
|
308
|
+
return cases.map((result) => ({
|
|
309
|
+
ruleId: result.ruleId,
|
|
310
|
+
caseId: result.caseId,
|
|
311
|
+
test: typeOf.get(result.ruleId) ?? 'e2e',
|
|
312
|
+
enforcement: enforcementOf.get(result.ruleId) ?? 'block',
|
|
313
|
+
status: result.status,
|
|
314
|
+
channel: result.channel,
|
|
315
|
+
mappedTests: result.mappedTests,
|
|
316
|
+
finding: result.finding === null
|
|
317
|
+
? null
|
|
318
|
+
: {
|
|
319
|
+
cause: result.finding.cause,
|
|
320
|
+
detail: result.finding.detail,
|
|
321
|
+
nextAction: result.finding.nextAction,
|
|
322
|
+
tests: result.finding.tests,
|
|
323
|
+
},
|
|
324
|
+
}));
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* The `next` guidance for the run's rule findings (plan D6, §7.2): one
|
|
328
|
+
* block per graded case that carries a finding — the rule title, the
|
|
329
|
+
* case describe, the declared proof type — and, for a case with NO
|
|
330
|
+
* mapped test, the printed starter test (the type table's `starter`
|
|
331
|
+
* field picks the template: a Playwright test on the Gateforge fixture
|
|
332
|
+
* for `e2e`, a pytest function for `pytest`) plus the exact
|
|
333
|
+
* `tests mark --rule` line that maps it once written. A case that IS
|
|
334
|
+
* mapped gets the finding statement only: its gap is proof, not a
|
|
335
|
+
* missing declaration, and inventing a second mark line would steer the
|
|
336
|
+
* owner to map a duplicate instead of running the gate.
|
|
337
|
+
*
|
|
338
|
+
* Pure text; `next` prints these lines for EVERY finding case (§7.2:
|
|
339
|
+
* two starter tests and two mark lines for a two-case rule), not only
|
|
340
|
+
* for the top-ranked candidate.
|
|
341
|
+
*/
|
|
342
|
+
export function businessRuleGuidanceLines(rules, cases) {
|
|
343
|
+
const lines = [];
|
|
344
|
+
for (const result of cases) {
|
|
345
|
+
if (result.finding === null)
|
|
346
|
+
continue;
|
|
347
|
+
const rule = rules.find((entry) => entry.id === result.ruleId);
|
|
348
|
+
if (rule === undefined)
|
|
349
|
+
continue;
|
|
350
|
+
const businessCase = casesOf(rule).find((entry) => entry.id === result.caseId);
|
|
351
|
+
const describe = businessCase?.describe ?? result.caseId;
|
|
352
|
+
const row = BUSINESS_RULE_TYPE_TABLE[rule.test];
|
|
353
|
+
lines.push(`business rule '${rule.id}' case '${result.caseId}' needs a '${row.label}' test ` +
|
|
354
|
+
`(${row.acceptedKinds.join(' or ')} under runner '${row.runner}') — ${rule.title}`);
|
|
355
|
+
if (result.status !== 'unmapped')
|
|
356
|
+
continue;
|
|
357
|
+
if (row.starter === 'playwright') {
|
|
358
|
+
const title = `business rule ${rule.id}: ${describe}`;
|
|
359
|
+
const file = `e2e/${rule.id}.spec.mjs`;
|
|
360
|
+
lines.push(` starter (the fixture's page is what routes the journey through the witness):`);
|
|
361
|
+
lines.push(` import { test, expect } from '@gate-forge/pack-playwright/fixture';`);
|
|
362
|
+
lines.push(` test('${title}', async ({ page }) => {`);
|
|
363
|
+
lines.push(` // Prove "${rule.title}" — ${describe}`);
|
|
364
|
+
lines.push(` });`);
|
|
365
|
+
lines.push(` then map it: gateforge tests mark --rule ${rule.id}/${result.caseId}` +
|
|
366
|
+
` --test '${file}#${title}' --kind ${row.acceptedKinds[0] ?? 'browser-e2e'}` +
|
|
367
|
+
` --reason 'asserts ${rule.id}/${result.caseId} in the real app'`);
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
const slug = (value) => value.replace(/[^a-z0-9]+/g, '_');
|
|
371
|
+
const pytestName = `test_business_rule_${slug(rule.id)}_${slug(result.caseId)}`;
|
|
372
|
+
const file = `tests/test_${slug(rule.id)}.py`;
|
|
373
|
+
lines.push(` starter (inside the WITNESSED pytest suite the run supervises):`);
|
|
374
|
+
lines.push(` def ${pytestName}():`);
|
|
375
|
+
lines.push(` """Prove "${rule.title}" — ${describe}."""`);
|
|
376
|
+
lines.push(` then map it: gateforge tests mark --rule ${rule.id}/${result.caseId}` +
|
|
377
|
+
` --test '${file}#${pytestName}' --kind ${row.acceptedKinds[0] ?? 'unit'}` +
|
|
378
|
+
` --reason 'asserts ${rule.id}/${result.caseId} in the witnessed suite'`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return lines;
|
|
382
|
+
}
|
|
383
|
+
//# sourceMappingURL=business-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"business-rules.js","sourceRoot":"","sources":["../src/business-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACpB,OAAO,EACP,qBAAqB,GAatB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,gEAAgE;AAChE,MAAM,UAAU,oBAAoB,CAAC,KAA8B;IACjE,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACjC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CACrE,CAAC;IACF,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAClC,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,kBAAkB,CAAC,OAAoB;IACrD,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACnF,CAAC;AAED;;;;GAIG;AACH,MAAM,U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AC,MAAM,CAAC,EAAE,CAAC;YAChF,MAAM,IAAI,GAAG,cAAc,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC;YAC9C,KAAK,CAAC,IAAI,CAAC,mEAAmE,CAAC,CAAC;YAChF,KAAK,CAAC,IAAI,CAAC,WAAW,UAAU,KAAK,CAAC,CAAC;YACvC,KAAK,CAAC,IAAI,CAAC,qBAAqB,IAAI,CAAC,KAAK,OAAO,QAAQ,MAAM,CAAC,CAAC;YACjE,KAAK,CAAC,IAAI,CACR,8CAA8C,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC,MAAM,EAAE;gBACtE,YAAY,IAAI,IAAI,UAAU,YAAY,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE;gBAC1E,sBAAsB,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC,MAAM,0BAA0B,CAC3E,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAwIA,OAAO,EA0BL,KAAK,aAAa,EACnB,MAAM,kBAAkB,CAAC;AAc1B,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAwIA,OAAO,EA0BL,KAAK,aAAa,EACnB,MAAM,kBAAkB,CAAC;AAc1B,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AA6CnC,OAAO,EAA4B,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAqCvF,OAAO,EAA0B,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AA8TnF,eAAO,MAAM,WAAW,QAM2F,CAAC;AAEpH,8EAA8E;AAC9E,MAAM,WAAW,gBAAgB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G,OAAO,CAE9E;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,GACf,MAAM,CAeR;AAsCD;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAy2CrF"}
|
package/dist/commands/check.js
CHANGED
|
@@ -148,18 +148,19 @@ import { singletonPerTenantAdvisories } from '../singleton-guidance.js';
|
|
|
148
148
|
import { responseFieldAdvisories } from '../response-field-guidance.js';
|
|
149
149
|
import { unmatchedRouteBannerLines } from '../unmatched-routes.js';
|
|
150
150
|
import { annotationMapSyncAdvisories, loadOptionalTestMap, mappedCoverageFrom, mappingBlocking, nativeInventoryBlocking, resolveRepositoryMappings, TEST_MAP_RELATIVE } from '../mapping.js';
|
|
151
|
+
import { businessRuleInventory, businessRuleReportEntries, businessRuleRunFacts, gradeBusinessRules, partitionBusinessRuleEntries, witnessedRunnersOf, } from '../business-rules.js';
|
|
151
152
|
import { runnerConfigPaths, runtimeDeclaredInputs } from '../test-infrastructure.js';
|
|
152
153
|
import { collectInputFiles, computeInputSnapshot, diffInputFiles, SnapshotUnavailableError, UnsupportedSnapshotError, } from '../input-snapshot.js';
|
|
153
154
|
import { runPipeline, sourcesByResourceId } from '../pipeline.js';
|
|
154
155
|
import { digestPytestInputs, interpreterIdentity, pytestCacheKey, readPytestCache, resolveCacheControl, writePytestCache, } from '../run-cache.js';
|
|
155
156
|
import { RuntimeBlockError, loadRuntimeConfigAt, prepareRuntime } from '../runtime.js';
|
|
156
157
|
import { digestRuntimeReuseMounts } from '../runtime-reuse.js';
|
|
157
|
-
import { authenticatedChangedInputs, loadReceiptFor, receiptGateBlocking, scopedReceiptCoverageBlocking, } from '../receipts.js';
|
|
158
|
+
import { authenticatedChangedInputs, loadReceiptFor, receiptGateBlocking, receiptScope, scopedReceiptCoverageBlocking, } from '../receipts.js';
|
|
158
159
|
import { resealChainBlocking, retainedCarriedEvidence } from '../reseal-chain.js';
|
|
159
160
|
import { evaluateAdoptionCommit } from '../adoption-mode.js';
|
|
160
161
|
import { changeBaseTextReader, mergeRequestScopePreflight, resolveProvider, textReaderAtRevision } from '../providers.js';
|
|
161
162
|
import { computeEvaluationScope, detectStagedWorkingTreeMismatches, testToolingSourceConflicts, } from '../scope.js';
|
|
162
|
-
import { assertRuntimeReuseOwnerApproval, freezeCommitCandidate, freezeStagedCandidate, materializeStagedCandidate,
|
|
163
|
+
import { assertRuntimeReuseOwnerApproval, freezeCommitCandidate, freezeStagedCandidate, materializeStagedCandidate, recheckStagedCandidate, releaseStagedCandidate, StagedCandidateBlockError, } from '../staged-candidate.js';
|
|
163
164
|
import { httpRoutesView, readCandidateTreeEntries, readStateDocument, resolveStateDir } from '../state.js';
|
|
164
165
|
import { engineGeneratedStateFileFilter } from '../state-artifacts.js';
|
|
165
166
|
import { assertReceiptApprovedPolicy, evaluateApprovedPolicy, resolveApprovedPolicyDigest, } from '../trusted-policy.js';
|
|
@@ -597,23 +598,16 @@ async function stagedCheckCommand(io, options) {
|
|
|
597
598
|
let cacheExclusions = [];
|
|
598
599
|
try {
|
|
599
600
|
checkoutDir = materializeStagedCandidate(io.cwd, io.env, frozen);
|
|
600
|
-
//
|
|
601
|
-
//
|
|
602
|
-
//
|
|
603
|
-
//
|
|
604
|
-
//
|
|
605
|
-
//
|
|
606
|
-
//
|
|
607
|
-
// so all of them compute the same digest for the same bytes. The bytes
|
|
608
|
-
// stay exactly the staged tree; only the marker-relevant empty dirs are
|
|
609
|
-
// mirrored, and only for a STAGED index (a candidate commit tree is
|
|
610
|
-
// gated on its own contents, never on the worktree around it).
|
|
601
|
+
// An EMPTY optional config directory (`.gateforge/adapters/`,
|
|
602
|
+
// `.gateforge/waivers/` — exactly what `gateforge init` leaves) is
|
|
603
|
+
// digested and snapshotted exactly like an ABSENT one, on every
|
|
604
|
+
// surface: the markers live in the digest entry list and the input
|
|
605
|
+
// snapshot, so a materialized checkout needs no worktree shaping for
|
|
606
|
+
// its digest to match — the bytes of the tree under test are the
|
|
607
|
+
// whole story, for a staged index and a candidate commit alike.
|
|
611
608
|
const checkoutConfig = loadConfigAt(checkoutDir);
|
|
612
609
|
docsExclusions = loadDocsExclusions(checkoutDir, checkoutConfig);
|
|
613
610
|
cacheExclusions = loadCacheExclusions(checkoutDir, checkoutConfig);
|
|
614
|
-
mirrorEmptyConfigDirs(io.cwd, checkoutDir, checkoutConfig, {
|
|
615
|
-
fromStagedIndex: options.candidateCommitSha === undefined,
|
|
616
|
-
});
|
|
617
611
|
// The candidate's own staged-runtime document prepares ITS checkout
|
|
618
612
|
// (dependency reuse + tracked preparation command) — discovery reads
|
|
619
613
|
// installed tooling from the candidate, never the worktree. The
|
|
@@ -1444,12 +1438,18 @@ export async function runCheckGate(io, options) {
|
|
|
1444
1438
|
}
|
|
1445
1439
|
return result;
|
|
1446
1440
|
};
|
|
1447
|
-
|
|
1441
|
+
// A repository that declares business rules but ships no sidecar must
|
|
1442
|
+
// still be graded: every case reads `unmapped` (a blocking finding), so
|
|
1443
|
+
// skipping the resolution here would hide the feature's whole point.
|
|
1444
|
+
let ruleBindings = [];
|
|
1445
|
+
let ruleCatalog = null;
|
|
1446
|
+
if (currentTestMap !== null || pipeline.businessRules.length > 0) {
|
|
1448
1447
|
const mapped = await resolveRepositoryMappings({
|
|
1449
1448
|
cwd: io.cwd,
|
|
1450
1449
|
config,
|
|
1451
1450
|
stateDir,
|
|
1452
1451
|
obligations: pipeline.policy.obligations,
|
|
1452
|
+
businessRules: pipeline.businessRules,
|
|
1453
1453
|
claimBindings,
|
|
1454
1454
|
behaviorCatalog: pipeline.behaviorCatalog,
|
|
1455
1455
|
pytestCollection,
|
|
@@ -1461,6 +1461,8 @@ export async function runCheckGate(io, options) {
|
|
|
1461
1461
|
...nativeInventoryBlocking(mapped.nativeLoadProblem),
|
|
1462
1462
|
];
|
|
1463
1463
|
mappedCoverage = mappedCoverageFrom(mapped.resolution, pipeline.policy.obligations, pipeline.graph);
|
|
1464
|
+
ruleBindings = mapped.resolution.ruleBindings;
|
|
1465
|
+
ruleCatalog = mapped.catalog;
|
|
1464
1466
|
}
|
|
1465
1467
|
const adoptedBaseline = resolveAdoptedBaseline(io.cwd, config.baselines);
|
|
1466
1468
|
// A re-sealed run grades the evidence UNION: this run's own records
|
|
@@ -1619,6 +1621,13 @@ export async function runCheckGate(io, options) {
|
|
|
1619
1621
|
.map((obligation) => ({ id: obligation.id, fingerprint: obligationFingerprint(obligation) }));
|
|
1620
1622
|
};
|
|
1621
1623
|
let receiptBlocking = [];
|
|
1624
|
+
// The digest-verified receipt load, hoisted out of the `--require-e2e`
|
|
1625
|
+
// block because the business-rule grader reads its SEALED execution
|
|
1626
|
+
// result. `check` never re-parses `execution-result.json` itself: that
|
|
1627
|
+
// document is suite-writable state, and only the receipt's own MAC and
|
|
1628
|
+
// execution digest make it trustworthy. Absent (no `--require-e2e`, or
|
|
1629
|
+
// no receipt) rules grade as `unproven` — a declaration is never proof.
|
|
1630
|
+
let verifiedRuleReceipt = null;
|
|
1622
1631
|
if (requireE2E) {
|
|
1623
1632
|
if (snapshotUnavailable || expectedDigest === null) {
|
|
1624
1633
|
receiptBlocking = [
|
|
@@ -1679,6 +1688,10 @@ export async function runCheckGate(io, options) {
|
|
|
1679
1688
|
});
|
|
1680
1689
|
diagnosticEvidenceState = load.status === 'ok' ? 'receipt-verified' : `receipt-${load.status}`;
|
|
1681
1690
|
if (load.status === 'ok') {
|
|
1691
|
+
// Retained for the business-rule grader below; cleared again at
|
|
1692
|
+
// the end of this branch if any refusal landed, because a
|
|
1693
|
+
// receipt this check is refusing must not grade anything.
|
|
1694
|
+
verifiedRuleReceipt = load;
|
|
1682
1695
|
if (load.receipt.engine !== undefined &&
|
|
1683
1696
|
load.receipt.engine.version !== engineIdentity().version) {
|
|
1684
1697
|
const detail = `require-e2e: receipt engine version '${load.receipt.engine.version}' differs from ` +
|
|
@@ -1768,6 +1781,8 @@ export async function runCheckGate(io, options) {
|
|
|
1768
1781
|
}
|
|
1769
1782
|
if (receiptBlocking.length > 0)
|
|
1770
1783
|
diagnosticEvidenceState = 'receipt-verified-with-blocking-entry';
|
|
1784
|
+
if (receiptBlocking.length > 0)
|
|
1785
|
+
verifiedRuleReceipt = null;
|
|
1771
1786
|
}
|
|
1772
1787
|
else {
|
|
1773
1788
|
receiptBlocking = receiptGateBlocking(load);
|
|
@@ -1802,6 +1817,49 @@ export async function runCheckGate(io, options) {
|
|
|
1802
1817
|
}
|
|
1803
1818
|
}
|
|
1804
1819
|
}
|
|
1820
|
+
// Owner-declared business rules (plan 2026-10-05 D4/D5). Graded
|
|
1821
|
+
// RUN-WIDE and deliberately OUTSIDE `evaluateRun`: rule findings are
|
|
1822
|
+
// never diff-scoped away by `--changed`, and the evaluator's own
|
|
1823
|
+
// named-scope projection would drop them (they name no obligation).
|
|
1824
|
+
// A case whose test sits outside the sealed run's graded slice is
|
|
1825
|
+
// reported `unproven (outside this run's graded slice)` — visible, not
|
|
1826
|
+
// absent, and never satisfied by a receipt that never covered it.
|
|
1827
|
+
let rulePartition = {
|
|
1828
|
+
blocking: [],
|
|
1829
|
+
advisories: [],
|
|
1830
|
+
};
|
|
1831
|
+
// Every graded case (satisfied ones included) for the report's
|
|
1832
|
+
// `businessRules` section: a satisfied case names the channel that
|
|
1833
|
+
// proved it, and an advisory case is listed here beside its
|
|
1834
|
+
// advisory-channel entry (invariant 6: the output says what was
|
|
1835
|
+
// proven; invariant 7: a demoted rule never hides).
|
|
1836
|
+
let ruleCases = [];
|
|
1837
|
+
// `ruleCatalog` is non-null here by construction: declaring rules is
|
|
1838
|
+
// exactly what makes the mapping resolution above run. The guard says
|
|
1839
|
+
// so to the type checker rather than asserting it.
|
|
1840
|
+
if (pipeline.businessRules.length > 0 && ruleCatalog !== null) {
|
|
1841
|
+
const runFacts = verifiedRuleReceipt === null
|
|
1842
|
+
? null
|
|
1843
|
+
: businessRuleRunFacts({
|
|
1844
|
+
result: verifiedRuleReceipt.executionResult,
|
|
1845
|
+
// The AUTHORIZED records `evaluateRun` graded from, never a
|
|
1846
|
+
// raw `records.json` read: a rule case must not be attributed
|
|
1847
|
+
// to evidence the obligation grader rejected.
|
|
1848
|
+
records: evaluated.records,
|
|
1849
|
+
witnessedRunners: witnessedRunnersOf(config),
|
|
1850
|
+
scope: receiptScope(verifiedRuleReceipt.receipt),
|
|
1851
|
+
docsOnly: verifiedRuleReceipt.receipt.docsOnly === true,
|
|
1852
|
+
catalog: ruleCatalog,
|
|
1853
|
+
});
|
|
1854
|
+
ruleCases = gradeBusinessRules({
|
|
1855
|
+
rules: pipeline.businessRules,
|
|
1856
|
+
ruleBindings,
|
|
1857
|
+
inventory: businessRuleInventory(pipeline.graph),
|
|
1858
|
+
runFacts,
|
|
1859
|
+
catalog: ruleCatalog,
|
|
1860
|
+
}).cases;
|
|
1861
|
+
rulePartition = partitionBusinessRuleEntries(pipeline.businessRules, ruleCases);
|
|
1862
|
+
}
|
|
1805
1863
|
const inScopeSourcePaths = diffScoped && scopeDecision.mode === 'changed'
|
|
1806
1864
|
? sourcesByResourceId(pipeline.graph, pipeline.behaviorCatalog)
|
|
1807
1865
|
: null;
|
|
@@ -1822,7 +1880,9 @@ export async function runCheckGate(io, options) {
|
|
|
1822
1880
|
.filter((file) => changedSourcePaths.has(file))
|
|
1823
1881
|
.sort(),
|
|
1824
1882
|
}));
|
|
1825
|
-
|
|
1883
|
+
// Rule findings join the run's OWN blocking set, unconditionally: a
|
|
1884
|
+
// `--changed` run never scopes a declared rule away (plan invariant 8).
|
|
1885
|
+
const evaluatedBlocking = [...evaluated.blocking, ...receiptBlocking, ...rulePartition.blocking];
|
|
1826
1886
|
const newDebt = diffScoped
|
|
1827
1887
|
? reportVerdicts
|
|
1828
1888
|
.filter((verdict) => BLOCKING_VERDICTS.includes(verdict.verdict))
|
|
@@ -1855,6 +1915,11 @@ export async function runCheckGate(io, options) {
|
|
|
1855
1915
|
// the entries are already out of `pipeline.policy.blocking`, so
|
|
1856
1916
|
// the exit code and `check --changed` are untouched.
|
|
1857
1917
|
...pipeline.unmatchedRouteAdvisories,
|
|
1918
|
+
// Advisory business rules (plan D5): the same typed cause codes,
|
|
1919
|
+
// in the report's existing advisory channel, out of `blocking` and
|
|
1920
|
+
// out of the exit code — but printed and serialized every run, so a
|
|
1921
|
+
// demoted rule never hides.
|
|
1922
|
+
...rulePartition.advisories,
|
|
1858
1923
|
],
|
|
1859
1924
|
waiverCounts: evaluated.waiverCounts,
|
|
1860
1925
|
baseline: baselineReport,
|
|
@@ -1938,6 +2003,19 @@ export async function runCheckGate(io, options) {
|
|
|
1938
2003
|
report = `${report}\ncache: ${String(cacheCounts.hits)} hit(s), ${String(cacheCounts.misses)} miss(es)`;
|
|
1939
2004
|
}
|
|
1940
2005
|
}
|
|
2006
|
+
if (ruleCases.length > 0 && format === 'json') {
|
|
2007
|
+
// Owner-declared business rules (plan §7.5, invariant 6): every
|
|
2008
|
+
// graded case is serialized with its status and the channel that
|
|
2009
|
+
// proved it — a satisfied case must be VISIBLE naming its channel,
|
|
2010
|
+
// because "satisfied" read as "the rule holds" is exactly the
|
|
2011
|
+
// overclaim the naming exists to prevent. Additive: no declared
|
|
2012
|
+
// rules, no section, byte-identical report (invariant 1).
|
|
2013
|
+
const document = JSON.parse(report);
|
|
2014
|
+
report = canonicalJson({
|
|
2015
|
+
...document,
|
|
2016
|
+
businessRules: businessRuleReportEntries(pipeline.businessRules, ruleCases),
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
1941
2019
|
// Owner-chosen strictness: the decision
|
|
1942
2020
|
// is a pure mapping of the strict result that was ALREADY computed, so
|
|
1943
2021
|
// no mode can change what was evaluated. Exit 2 (config/usage) keeps
|