@web-hig/core 1.12.5 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -9
- package/index.mjs +2 -1
- package/lib/config.mjs +44 -79
- package/lib/registry.mjs +43 -43
- package/lib/resolve-root.mjs +3 -0
- package/lib/verification-report.schema.json +58 -0
- package/lib/verification.mjs +39 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @web-hig/core
|
|
2
2
|
|
|
3
|
-
Shared evaluator engine for [The Web HIG](https://github.com/frozonfreak/
|
|
3
|
+
Shared evaluator engine for [The Web HIG](https://github.com/frozonfreak/webhig) — load the rule registry, parse project contracts, and build multidimensional conformance reports.
|
|
4
4
|
|
|
5
5
|
This package is **not** a UI library. It implements tooling around the HIG **behavioural contract** (accessibility, motion, SSR, tokens, and related rule IDs).
|
|
6
6
|
|
|
@@ -22,15 +22,15 @@ The engine reads **`rules/registry.yaml`** from a HIG contract tree on disk. It
|
|
|
22
22
|
|
|
23
23
|
| Setup | `WEB_HIG_ROOT` |
|
|
24
24
|
| --- | --- |
|
|
25
|
-
| [ `@web-hig/install` ](../install/) with
|
|
26
|
-
| Git clone of [frozonfreak/
|
|
25
|
+
| [ `@web-hig/install` ](../install/) with any profile | Automatically discovered `docs/hig` (contains `rules/registry.yaml`) |
|
|
26
|
+
| Git clone of [frozonfreak/webhig](https://github.com/frozonfreak/webhig) | repository root |
|
|
27
27
|
| Custom vendor layout | directory that contains `rules/registry.yaml` |
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
30
|
export WEB_HIG_ROOT=docs/hig # typical product repo after init
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
If unset, `resolveHigRoot()` walks up from `process.cwd()` looking for `rules/registry.yaml`.
|
|
33
|
+
If unset, `resolveHigRoot()` walks up from `process.cwd()` looking for `rules/registry.yaml` or `docs/hig/rules/registry.yaml`. An explicit invalid override returns null.
|
|
34
34
|
|
|
35
35
|
---
|
|
36
36
|
|
|
@@ -91,8 +91,9 @@ console.log(`Applicable static rules: ${staticRules.length}`);
|
|
|
91
91
|
| --- | --- |
|
|
92
92
|
| `loadProjectConfig(cwd, fileName?)` | Parse `web-hig.yaml` (default name) |
|
|
93
93
|
| `defaultProjectConfig(higVersion)` | Defaults when no config file exists |
|
|
94
|
+
| `validateProjectConfig(input)` | Validate profile, archetype, version, scope and gates; reject unknown keys and wrong types |
|
|
94
95
|
|
|
95
|
-
See [web-hig.example.yaml](https://github.com/frozonfreak/
|
|
96
|
+
See [web-hig.example.yaml](https://github.com/frozonfreak/webhig/blob/main/examples/web-hig.example.yaml).
|
|
96
97
|
|
|
97
98
|
### Reports (Layer 8 / evaluator)
|
|
98
99
|
|
|
@@ -102,7 +103,7 @@ See [web-hig.example.yaml](https://github.com/frozonfreak/hig/blob/main/examples
|
|
|
102
103
|
| `printTerminalReport(report)` | Human-readable summary |
|
|
103
104
|
| `severityBucketForRule(severity)` | Maps `error` → `blocking`, `warning` → `warnings`, `info` → `observations` |
|
|
104
105
|
|
|
105
|
-
Finding shape aligns with [EVALUATOR.md](https://github.com/frozonfreak/
|
|
106
|
+
Finding shape aligns with [EVALUATOR.md](https://github.com/frozonfreak/webhig/blob/main/EVALUATOR.md):
|
|
106
107
|
|
|
107
108
|
```json
|
|
108
109
|
{
|
|
@@ -115,6 +116,14 @@ Finding shape aligns with [EVALUATOR.md](https://github.com/frozonfreak/hig/blob
|
|
|
115
116
|
}
|
|
116
117
|
```
|
|
117
118
|
|
|
119
|
+
### Verification evidence
|
|
120
|
+
|
|
121
|
+
`filterRulesByContract(registry, { profile, archetype, evaluation: null })` includes all applicable rules, including manual/runtime rules. The default remains the static subset for compatibility.
|
|
122
|
+
|
|
123
|
+
`createAssessments({ rules, checks, findings, files })` records each rule's declared modes, detector coverage, result, reason and evidence. `summarizeAssessments(assessments)` counts outcomes. Current static detectors are partial: they can identify a potential failure but never prove a pass from absence of findings. Manual-only rules require human review; unsupported or incompletely checked rules remain not assessed.
|
|
124
|
+
|
|
125
|
+
The tooling-owned, independently versioned [verification report schema](./lib/verification-report.schema.json) is exported as `@web-hig/core/verification-report.schema.json`. It requires affirmative evidence and full coverage for any future `passed` result. CLI `check --json` and `coverage --format json` are schema-tested. This additive evidence format does not replace the standard's draft multidimensional report or claim compatibility with a deployed HIG Audit version.
|
|
126
|
+
|
|
118
127
|
---
|
|
119
128
|
|
|
120
129
|
## Rule metadata
|
|
@@ -128,7 +137,7 @@ Each registry entry includes:
|
|
|
128
137
|
- `module`, `hig_section` — links into the spec
|
|
129
138
|
- `eslint_rule` — planned linter id (when present)
|
|
130
139
|
|
|
131
|
-
Normative source: [HIG.md](https://github.com/frozonfreak/
|
|
140
|
+
Normative source: [HIG.md](https://github.com/frozonfreak/webhig/blob/main/HIG.md) · Registry: [rules/registry.yaml](https://github.com/frozonfreak/webhig/blob/main/rules/registry.yaml)
|
|
132
141
|
|
|
133
142
|
---
|
|
134
143
|
|
|
@@ -139,10 +148,10 @@ Normative source: [HIG.md](https://github.com/frozonfreak/hig/blob/main/HIG.md)
|
|
|
139
148
|
| [`@web-hig/cli`](../cli/) | `web-hig check`, `explain`, `init` |
|
|
140
149
|
| [`@web-hig/install`](../install/) | Pin HIG docs and agent rules into your repo |
|
|
141
150
|
|
|
142
|
-
Architecture: [NPM-TOOLING.md](https://github.com/frozonfreak/
|
|
151
|
+
Architecture: [NPM-TOOLING.md](https://github.com/frozonfreak/webhig/blob/main/NPM-TOOLING.md)
|
|
143
152
|
|
|
144
153
|
---
|
|
145
154
|
|
|
146
155
|
## License
|
|
147
156
|
|
|
148
|
-
MIT · [The Web HIG](https://github.com/frozonfreak/
|
|
157
|
+
MIT · [The Web HIG](https://github.com/frozonfreak/webhig)
|
package/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { loadRegistry, parseRegistryYaml, filterRulesByContract } from './lib/registry.mjs';
|
|
2
|
-
export { loadProjectConfig, defaultProjectConfig } from './lib/config.mjs';
|
|
2
|
+
export { loadProjectConfig, defaultProjectConfig, validateProjectConfig } from './lib/config.mjs';
|
|
3
3
|
export { createReport, printTerminalReport, severityBucketForRule } from './lib/report.mjs';
|
|
4
4
|
export { resolveHigRoot } from './lib/resolve-root.mjs';
|
|
5
|
+
export { createAssessments, summarizeAssessments } from './lib/verification.mjs';
|
package/lib/config.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { parse } from 'yaml';
|
|
3
4
|
|
|
5
|
+
const PROFILES = ['quick', 'practical', 'full'];
|
|
6
|
+
const ARCHETYPES = ['content', 'commerce', 'application', 'auth'];
|
|
4
7
|
const DEFAULTS = {
|
|
5
8
|
profile: 'practical',
|
|
6
9
|
archetype: 'application',
|
|
@@ -8,92 +11,54 @@ const DEFAULTS = {
|
|
|
8
11
|
scope: { files: ['src/**'], exclude: [], routes: ['/**'] },
|
|
9
12
|
gates: { blocking: 'fail', warnings: 'report', observations: 'report' },
|
|
10
13
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return {
|
|
14
|
-
version: higVersion,
|
|
15
|
-
...structuredClone(DEFAULTS),
|
|
16
|
-
};
|
|
14
|
+
export function defaultProjectConfig(version) {
|
|
15
|
+
return { version, ...structuredClone(DEFAULTS) };
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
function
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
|
|
18
|
+
export function validateProjectConfig(input) {
|
|
19
|
+
const object = (value) => value && typeof value === 'object' && !Array.isArray(value);
|
|
20
|
+
if (!object(input)) throw new Error('web-hig.yaml must contain a YAML mapping.');
|
|
21
|
+
for (const key of Object.keys(input)) {
|
|
22
|
+
if (!['version', ...Object.keys(DEFAULTS)].includes(key))
|
|
23
|
+
throw new Error(`Unknown configuration key: ${key}`);
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/** Minimal web-hig.yaml parser (no dependency). */
|
|
28
|
-
export function loadProjectConfig(cwd, fileName = 'web-hig.yaml') {
|
|
29
|
-
const configPath = path.join(cwd, fileName);
|
|
30
|
-
if (!fs.existsSync(configPath)) {
|
|
31
|
-
return { configPath: null, config: null, exists: false };
|
|
25
|
+
if (typeof input.version !== 'string' || !/^\d+\.\d+\.\d+$/.test(input.version)) {
|
|
26
|
+
throw new Error('version must be a quoted stable semver, e.g. "1.16.0".');
|
|
32
27
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (/^scope:\s*$/.test(line)) {
|
|
44
|
-
section = 'scope';
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
if (/^framework:\s*$/.test(line)) {
|
|
48
|
-
section = 'framework';
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (/^gates:\s*$/.test(line)) {
|
|
52
|
-
section = 'gates';
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const top = line.match(/^(\w+):\s*(.*)$/);
|
|
57
|
-
if (top && !line.startsWith(' ')) {
|
|
58
|
-
section = null;
|
|
59
|
-
const [, key, value] = top;
|
|
60
|
-
if (key === 'version') version = parseScalar(value);
|
|
61
|
-
if (key === 'profile') config.profile = parseScalar(value);
|
|
62
|
-
if (key === 'archetype') config.archetype = parseScalar(value);
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const nested = line.match(/^\s{2}(\w+):\s*(.*)$/);
|
|
67
|
-
if (!nested) continue;
|
|
68
|
-
const [, key, value] = nested;
|
|
69
|
-
|
|
70
|
-
if (section === 'framework' && key === 'name') {
|
|
71
|
-
config.framework.name = parseScalar(value);
|
|
72
|
-
}
|
|
73
|
-
if (section === 'gates') {
|
|
74
|
-
config.gates[key] = parseScalar(value);
|
|
75
|
-
}
|
|
76
|
-
if (section === 'scope' && (key === 'files' || key === 'exclude' || key === 'routes')) {
|
|
77
|
-
if (!Array.isArray(config.scope[key])) config.scope[key] = [];
|
|
28
|
+
const config = { ...defaultProjectConfig(input.version), ...input };
|
|
29
|
+
if (!PROFILES.includes(config.profile)) throw new Error(`Unknown profile: ${config.profile}`);
|
|
30
|
+
if (!ARCHETYPES.includes(config.archetype))
|
|
31
|
+
throw new Error(`Unknown archetype: ${config.archetype}`);
|
|
32
|
+
for (const section of ['framework', 'scope', 'gates']) {
|
|
33
|
+
if (input[section] === undefined) continue;
|
|
34
|
+
if (!object(input[section])) throw new Error(`${section} must be a mapping.`);
|
|
35
|
+
for (const key of Object.keys(input[section])) {
|
|
36
|
+
if (!Object.hasOwn(DEFAULTS[section], key)) throw new Error(`Unknown ${section} key: ${key}`);
|
|
78
37
|
}
|
|
38
|
+
config[section] = { ...structuredClone(DEFAULTS[section]), ...input[section] };
|
|
79
39
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
for (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
else if (/^\s{2}exclude:\s*$/.test(line)) scopeList = 'exclude';
|
|
87
|
-
else if (/^\s{2}routes:\s*$/.test(line)) scopeList = 'routes';
|
|
88
|
-
else if (/^\s{2}\w/.test(line) && !/^\s{4}-/.test(line)) scopeList = null;
|
|
89
|
-
else if (scopeList && /^\s{4}-\s+(.+)$/.test(line)) {
|
|
90
|
-
config.scope[scopeList].push(parseScalar(line.match(/^\s{4}-\s+(.+)$/)[1]));
|
|
40
|
+
if (config.framework.name !== null && typeof config.framework.name !== 'string') {
|
|
41
|
+
throw new Error('framework.name must be a string or null.');
|
|
42
|
+
}
|
|
43
|
+
for (const [key, value] of Object.entries(config.scope)) {
|
|
44
|
+
if (!Array.isArray(value) || value.some((v) => typeof v !== 'string' || !v.trim())) {
|
|
45
|
+
throw new Error(`scope.${key} must be an array of nonempty strings.`);
|
|
91
46
|
}
|
|
92
47
|
}
|
|
48
|
+
for (const [key, value] of Object.entries(config.gates)) {
|
|
49
|
+
if (!['fail', 'report'].includes(value))
|
|
50
|
+
throw new Error(`gates.${key} must be fail or report.`);
|
|
51
|
+
}
|
|
52
|
+
return config;
|
|
53
|
+
}
|
|
93
54
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
55
|
+
export function loadProjectConfig(cwd, fileName = 'web-hig.yaml') {
|
|
56
|
+
const configPath = path.resolve(cwd, fileName);
|
|
57
|
+
if (!fs.existsSync(configPath)) return { configPath, config: null, exists: false };
|
|
58
|
+
try {
|
|
59
|
+
const input = parse(fs.readFileSync(configPath, 'utf8'));
|
|
60
|
+
return { configPath, exists: true, config: validateProjectConfig(input) };
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw new Error(`${configPath}: ${error.message}`);
|
|
63
|
+
}
|
|
99
64
|
}
|
package/lib/registry.mjs
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { parse } from 'yaml';
|
|
3
4
|
|
|
4
5
|
export function parseRegistryYaml(yaml) {
|
|
5
|
-
const
|
|
6
|
+
const data = parse(yaml);
|
|
7
|
+
if (
|
|
8
|
+
!data ||
|
|
9
|
+
typeof data.version !== 'string' ||
|
|
10
|
+
!/^\d+\.\d+\.\d+$/.test(data.version) ||
|
|
11
|
+
!data.rules ||
|
|
12
|
+
typeof data.rules !== 'object' ||
|
|
13
|
+
!Object.keys(data.rules).length
|
|
14
|
+
) {
|
|
15
|
+
throw new Error('Invalid registry: expected version and a nonempty rules mapping.');
|
|
16
|
+
}
|
|
6
17
|
const rules = new Map();
|
|
7
|
-
for (const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
: []
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
archetypes: archetypeList,
|
|
30
|
-
evaluation: evaluationList,
|
|
31
|
-
autofix: pick('autofix'),
|
|
32
|
-
module: pick('module'),
|
|
33
|
-
hig_section: pick('hig_section')?.replace(/^"|"$/g, ''),
|
|
34
|
-
eslint_rule: pick('eslint_rule'),
|
|
35
|
-
});
|
|
18
|
+
for (const [id, row] of Object.entries(data.rules)) {
|
|
19
|
+
if (
|
|
20
|
+
!/^HIG-[A-Z0-9]+-\d+$/.test(id) ||
|
|
21
|
+
!row ||
|
|
22
|
+
typeof row.requirement !== 'string' ||
|
|
23
|
+
!row.requirement.trim() ||
|
|
24
|
+
!['error', 'warning', 'info'].includes(row.severity)
|
|
25
|
+
)
|
|
26
|
+
throw new Error(`Invalid registry rule: ${id}`);
|
|
27
|
+
for (const [key, allowed] of Object.entries({
|
|
28
|
+
profiles: ['quick', 'practical', 'full'],
|
|
29
|
+
archetypes: ['content', 'commerce', 'application', 'auth'],
|
|
30
|
+
evaluation: ['static', 'runtime', 'manual', 'observation'],
|
|
31
|
+
})) {
|
|
32
|
+
if (
|
|
33
|
+
!Array.isArray(row[key]) ||
|
|
34
|
+
!row[key].length ||
|
|
35
|
+
row[key].some((v) => !allowed.includes(v))
|
|
36
|
+
)
|
|
37
|
+
throw new Error(`${id}: invalid ${key}`);
|
|
38
|
+
}
|
|
39
|
+
rules.set(id, { ...row, id });
|
|
36
40
|
}
|
|
37
|
-
return { version, rules };
|
|
41
|
+
return { version: data.version, rules };
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
export function loadRegistry(higRoot) {
|
|
41
|
-
|
|
42
|
-
const yaml = fs.readFileSync(filePath, 'utf8');
|
|
43
|
-
return parseRegistryYaml(yaml);
|
|
45
|
+
return parseRegistryYaml(fs.readFileSync(path.join(higRoot, 'rules', 'registry.yaml'), 'utf8'));
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
export function filterRulesByContract(registry, { profile, archetype }) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
return applicable;
|
|
48
|
+
export function filterRulesByContract(registry, { profile, archetype, evaluation = 'static' }) {
|
|
49
|
+
return [...registry.rules.values()].filter(
|
|
50
|
+
(rule) =>
|
|
51
|
+
rule.profiles.includes(profile) &&
|
|
52
|
+
rule.archetypes.includes(archetype) &&
|
|
53
|
+
(!evaluation || rule.evaluation.includes(evaluation)),
|
|
54
|
+
);
|
|
55
55
|
}
|
package/lib/resolve-root.mjs
CHANGED
|
@@ -5,11 +5,14 @@ export function resolveHigRoot(startDir = process.cwd()) {
|
|
|
5
5
|
if (process.env.WEB_HIG_ROOT) {
|
|
6
6
|
const root = path.resolve(process.env.WEB_HIG_ROOT);
|
|
7
7
|
if (fs.existsSync(path.join(root, 'rules', 'registry.yaml'))) return root;
|
|
8
|
+
return null;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
let dir = path.resolve(startDir);
|
|
11
12
|
for (let i = 0; i < 12; i += 1) {
|
|
12
13
|
if (fs.existsSync(path.join(dir, 'rules', 'registry.yaml'))) return dir;
|
|
14
|
+
const vendored = path.join(dir, 'docs', 'hig');
|
|
15
|
+
if (fs.existsSync(path.join(vendored, 'rules', 'registry.yaml'))) return vendored;
|
|
13
16
|
const parent = path.dirname(dir);
|
|
14
17
|
if (parent === dir) break;
|
|
15
18
|
dir = parent;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://hig.dev/schema/verification-report.schema.json",
|
|
4
|
+
"title": "Web HIG verification evidence v1",
|
|
5
|
+
"description": "Additive evidence envelope for CLI and independent evaluators. Scores are not inferred from detector silence.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["schema_version", "hig_version", "profile", "archetype", "summary", "assessments"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"schema_version": { "const": "1.0.0" },
|
|
10
|
+
"hig_version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" },
|
|
11
|
+
"profile": { "enum": ["quick", "practical", "full"] },
|
|
12
|
+
"archetype": { "enum": ["content", "commerce", "application", "auth"] },
|
|
13
|
+
"summary": {
|
|
14
|
+
"type": "object",
|
|
15
|
+
"required": ["passed", "failed", "manual_review", "not_assessed"],
|
|
16
|
+
"additionalProperties": false,
|
|
17
|
+
"properties": {
|
|
18
|
+
"passed": { "type": "integer", "minimum": 0 },
|
|
19
|
+
"failed": { "type": "integer", "minimum": 0 },
|
|
20
|
+
"manual_review": { "type": "integer", "minimum": 0 },
|
|
21
|
+
"not_assessed": { "type": "integer", "minimum": 0 }
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"assessments": {
|
|
25
|
+
"type": "array",
|
|
26
|
+
"items": {
|
|
27
|
+
"type": "object",
|
|
28
|
+
"additionalProperties": false,
|
|
29
|
+
"required": ["rule_id", "severity_bucket", "verification_modes", "coverage", "result", "reason", "evidence"],
|
|
30
|
+
"properties": {
|
|
31
|
+
"rule_id": { "type": "string", "pattern": "^HIG-[A-Z0-9]+-\\d+$" },
|
|
32
|
+
"severity_bucket": { "enum": ["blocking", "warnings", "observations"] },
|
|
33
|
+
"verification_modes": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "enum": ["static", "runtime", "manual", "observation"] } },
|
|
34
|
+
"coverage": { "enum": ["none", "partial", "full"] },
|
|
35
|
+
"result": { "enum": ["passed", "failed", "manual_review", "not_assessed"] },
|
|
36
|
+
"reason": { "type": "string", "minLength": 1 },
|
|
37
|
+
"evidence": {
|
|
38
|
+
"type": "array",
|
|
39
|
+
"items": {
|
|
40
|
+
"type": "object",
|
|
41
|
+
"required": ["mode", "message"],
|
|
42
|
+
"additionalProperties": false,
|
|
43
|
+
"properties": {
|
|
44
|
+
"mode": { "enum": ["static", "runtime", "manual", "observation"] },
|
|
45
|
+
"message": { "type": "string", "minLength": 1 },
|
|
46
|
+
"location": { "type": "string" }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"allOf": [
|
|
52
|
+
{ "if": { "properties": { "result": { "enum": ["passed", "failed"] } } }, "then": { "properties": { "evidence": { "type": "array", "minItems": 1 } } } },
|
|
53
|
+
{ "if": { "properties": { "result": { "const": "passed" } } }, "then": { "properties": { "coverage": { "const": "full" } } } }
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { severityBucketForRule } from './report.mjs';
|
|
2
|
+
|
|
3
|
+
/** Shared evidence contract. Detectors never imply a pass from silence. */
|
|
4
|
+
export function createAssessments({ rules, checks = [], findings = [], files = [] }) {
|
|
5
|
+
return rules.map((rule) => {
|
|
6
|
+
const detectors = checks.filter((check) => check.rule_id === rule.id);
|
|
7
|
+
const evidence = findings
|
|
8
|
+
.filter((finding) => finding.rule_id === rule.id)
|
|
9
|
+
.map((finding) => ({
|
|
10
|
+
mode: finding.evaluation,
|
|
11
|
+
message: finding.message,
|
|
12
|
+
location: finding.location,
|
|
13
|
+
}));
|
|
14
|
+
const manualOnly = rule.evaluation.every((mode) => mode === 'manual');
|
|
15
|
+
return {
|
|
16
|
+
rule_id: rule.id,
|
|
17
|
+
severity_bucket: severityBucketForRule(rule.severity),
|
|
18
|
+
verification_modes: rule.evaluation,
|
|
19
|
+
coverage: detectors.length ? 'partial' : 'none',
|
|
20
|
+
result: evidence.length ? 'failed' : manualOnly ? 'manual_review' : 'not_assessed',
|
|
21
|
+
reason: evidence.length
|
|
22
|
+
? 'A detector observed a potential violation; review its evidence.'
|
|
23
|
+
: manualOnly
|
|
24
|
+
? 'Requires human judgment.'
|
|
25
|
+
: !detectors.length
|
|
26
|
+
? 'No implemented detector for this rule.'
|
|
27
|
+
: !files.length
|
|
28
|
+
? 'No source files matched the configured scope.'
|
|
29
|
+
: 'Partial static checks found no violation; full behavior remains unverified.',
|
|
30
|
+
evidence,
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function summarizeAssessments(assessments) {
|
|
36
|
+
const summary = { passed: 0, failed: 0, manual_review: 0, not_assessed: 0 };
|
|
37
|
+
for (const assessment of assessments) summary[assessment.result] += 1;
|
|
38
|
+
return summary;
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@web-hig/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "Shared evaluator engine for The Web HIG conformance tooling",
|
|
5
5
|
"homepage": "https://github.com/frozonfreak/hig/tree/main/packages/core#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"node": ">=20"
|
|
20
20
|
},
|
|
21
21
|
"exports": {
|
|
22
|
-
".": "./index.mjs"
|
|
22
|
+
".": "./index.mjs",
|
|
23
|
+
"./verification-report.schema.json": "./lib/verification-report.schema.json"
|
|
23
24
|
},
|
|
24
25
|
"files": [
|
|
25
26
|
"README.md",
|
|
@@ -34,5 +35,8 @@
|
|
|
34
35
|
},
|
|
35
36
|
"publishConfig": {
|
|
36
37
|
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"yaml": "^2.9.1"
|
|
37
41
|
}
|
|
38
42
|
}
|