architecture-harness 0.10.0 → 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/package.json +1 -1
- package/src/cli/check.mjs +168 -6
- package/src/cli/registry-history.mjs +53 -0
- package/src/cli/registry-history.test.mjs +88 -0
- package/src/config.mjs +55 -0
- package/src/descriptions.mjs +7 -0
- package/src/gates/closed-set-writers.mjs +36 -0
- package/src/gates/closed-set-writers.test.mjs +46 -0
- package/src/gates/doc-claims.mjs +45 -0
- package/src/gates/doc-claims.test.mjs +33 -0
- package/src/gates/integration-imports.mjs +49 -0
- package/src/gates/integration-imports.test.mjs +35 -0
- package/src/gates/migration-numbers.mjs +33 -0
- package/src/gates/migration-numbers.test.mjs +35 -0
- package/src/gates/parity.mjs +163 -0
- package/src/gates/parity.test.mjs +108 -0
- package/src/gates/registry-literal.mjs +137 -0
- package/src/gates/registry-literal.test.mjs +68 -0
- package/src/gates/sql-identifiers.mjs +72 -9
- package/src/gates/sql-identifiers.test.mjs +70 -1
- package/src/gates/tenant-predicate.mjs +108 -58
- package/src/gates/tenant-predicate.test.mjs +61 -39
- package/src/gates/threshold-ratchet.mjs +46 -0
- package/src/gates/threshold-ratchet.test.mjs +60 -0
- package/templates/quality-thresholds.json +2 -2
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// A threshold only tightens, unless a decision says why it loosens. Every brief says "never lower a
|
|
2
|
+
// threshold", and a rule a gate checks holds under pressure where a sentence does not.
|
|
3
|
+
|
|
4
|
+
import { escape } from "../eslint/options.mjs";
|
|
5
|
+
|
|
6
|
+
function loosened(comparator, was, now) {
|
|
7
|
+
if (comparator === "max") return now > was;
|
|
8
|
+
if (comparator === "min") return now < was;
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {object} before the registry's `gates` at the merge base
|
|
14
|
+
* @param {object} after the registry's `gates` now
|
|
15
|
+
* @param {{path: string, text: string}[]} adrs the ADR files the diff changes, with their text
|
|
16
|
+
* @param {{registry: string}} options the registry path, as a problem names it
|
|
17
|
+
*/
|
|
18
|
+
export function checkThresholdRatchet(before, after, adrs, { registry }) {
|
|
19
|
+
const problems = [];
|
|
20
|
+
const citedByAdr = (key) => {
|
|
21
|
+
const named = new RegExp(`\\b${escape(key)}\\b`);
|
|
22
|
+
return adrs.some((adr) => named.test(adr.text));
|
|
23
|
+
};
|
|
24
|
+
for (const [key, entry] of Object.entries(after)) {
|
|
25
|
+
const was = before[key];
|
|
26
|
+
// The comparator in force before the change is the policy the change answers to.
|
|
27
|
+
if (typeof was?.value !== "number" || typeof entry?.value !== "number") continue;
|
|
28
|
+
if (!loosened(was.comparator, was.value, entry.value)) continue;
|
|
29
|
+
if (citedByAdr(key)) continue;
|
|
30
|
+
problems.push({
|
|
31
|
+
path: registry,
|
|
32
|
+
rule: "loosened-threshold",
|
|
33
|
+
detail: `'${key}' moves from ${was.value} to ${entry.value}, and a ${was.comparator} that moves this way loosens; a changed ADR must name '${key}'`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
// Dropping a limit is the widest loosening of all, so it answers to the same rule.
|
|
37
|
+
for (const [key, was] of Object.entries(before)) {
|
|
38
|
+
if (key in after || typeof was?.value !== "number" || citedByAdr(key)) continue;
|
|
39
|
+
problems.push({
|
|
40
|
+
path: registry,
|
|
41
|
+
rule: "removed-threshold",
|
|
42
|
+
detail: `'${key}' (${was.comparator} ${was.value}) is removed; a changed ADR must name '${key}'`,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return problems;
|
|
46
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { checkThresholdRatchet } from "./threshold-ratchet.mjs";
|
|
4
|
+
|
|
5
|
+
const REGISTRY = "quality-thresholds.json";
|
|
6
|
+
const base = {
|
|
7
|
+
filelength: { value: 500, comparator: "max" },
|
|
8
|
+
coverage: { value: 70, comparator: "min" },
|
|
9
|
+
};
|
|
10
|
+
const moved = (key, value) => ({ ...base, [key]: { ...base[key], value } });
|
|
11
|
+
const check = (after, adrs = []) => checkThresholdRatchet(base, after, adrs, { registry: REGISTRY });
|
|
12
|
+
|
|
13
|
+
test("a max that rises fails", () => {
|
|
14
|
+
const problems = check(moved("filelength", 550));
|
|
15
|
+
assert.equal(problems.length, 1);
|
|
16
|
+
assert.equal(problems[0].rule, "loosened-threshold");
|
|
17
|
+
assert.equal(problems[0].path, REGISTRY);
|
|
18
|
+
assert.match(problems[0].detail, /filelength.*500.*550/);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("a min that falls fails", () => {
|
|
22
|
+
assert.equal(check(moved("coverage", 60))[0].rule, "loosened-threshold");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("a changed ADR whose text names the key lets the loosening through", () => {
|
|
26
|
+
const adrs = [{ path: "docs/decisions/0031-longer-files.md", text: "We raise `filelength` to 550." }];
|
|
27
|
+
assert.deepEqual(check(moved("filelength", 550), adrs), []);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("an ADR that names another key does not", () => {
|
|
31
|
+
const adrs = [{ path: "docs/decisions/0031-coverage.md", text: "The coverage floor and filelengths stay." }];
|
|
32
|
+
assert.equal(check(moved("filelength", 550), adrs).length, 1);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("a tightening passes", () => {
|
|
36
|
+
assert.deepEqual(check({ ...moved("filelength", 450), coverage: { value: 80, comparator: "min" } }), []);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("a new entry passes", () => {
|
|
40
|
+
assert.deepEqual(check({ ...base, nesting: { value: 9, comparator: "max" } }), []);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("a removed entry fails, because dropping a limit is the widest loosening", () => {
|
|
44
|
+
const { coverage, ...rest } = base;
|
|
45
|
+
const problems = check(rest);
|
|
46
|
+
assert.equal(problems.length, 1);
|
|
47
|
+
assert.equal(problems[0].rule, "removed-threshold");
|
|
48
|
+
assert.match(problems[0].detail, /coverage/);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("a removed entry passes when a changed ADR names it", () => {
|
|
52
|
+
const { coverage, ...rest } = base;
|
|
53
|
+
const adrs = [{ path: "docs/decisions/0032-coverage.md", text: "We retire `coverage` in favour of mutation score." }];
|
|
54
|
+
assert.deepEqual(check(rest, adrs), []);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("the comparator in force at the base judges the change", () => {
|
|
58
|
+
const after = { ...base, filelength: { value: 550, comparator: "min" } };
|
|
59
|
+
assert.equal(check(after).length, 1);
|
|
60
|
+
});
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"note": "The one home for a number a quality gate enforces. Docs carry a token, never a figure; every eslint config, the coverage config and CI import this file rather than restating it. Loosening a threshold is one edit here, visible in one diff.",
|
|
3
3
|
"updated": "replace with the date you adopted this",
|
|
4
4
|
"policy": {
|
|
5
|
-
"loosening": "Raising a limit or lowering coverage needs the same review as a spec change: the diff on this file is the record. A per-file override belongs in the config that needs it, with a comment naming why, never here.",
|
|
6
|
-
"match": "A threshold has no distinctive spelling the way a version number does, so each gate lists the phrases a page or a config would use when stating it.
|
|
5
|
+
"loosening": "Raising a limit or lowering coverage needs the same review as a spec change: the diff on this file is the record. The threshold-ratchet gate of `qc check` fails a max that rises or a min that falls against the merge base, unless a changed ADR names the entry key. A per-file override belongs in the config that needs it, with a comment naming why, never here.",
|
|
6
|
+
"match": "A threshold has no distinctive spelling the way a version number does, so each gate lists the phrases a page or a config would use when stating it. The registry-literal gate of `qc check` reports the entry's own number within six words of one of them, in any doc outside the ADR log. Add a phrase when a new wording appears; the phrases are the whole reason the literal check can exist.",
|
|
7
7
|
"readers": "An entry that code reads can carry `names`, regular expressions for the identifiers that would restate it, each matched against the whole identifier and case-insensitive, and `readers`, the paths that may hold its number. qc/registry-literal reports a matching literal anywhere else, and the registry-readers gate fails a reader that is missing or never names the entry.",
|
|
8
8
|
"notThresholds": "A performance budget is not a quality gate. Latency, memory and render budgets live in docs/performance.md, because they are measured per surface rather than enforced repository-wide."
|
|
9
9
|
},
|