@intentset/verification 0.6.0 → 0.7.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.
Files changed (51) hide show
  1. package/README.md +50 -0
  2. package/dist/adapters/common.d.ts +6 -0
  3. package/dist/adapters/common.d.ts.map +1 -1
  4. package/dist/adapters/common.js +2 -0
  5. package/dist/adapters/common.js.map +1 -1
  6. package/dist/adapters/playwright.d.ts +3 -0
  7. package/dist/adapters/playwright.d.ts.map +1 -0
  8. package/dist/adapters/playwright.js +78 -0
  9. package/dist/adapters/playwright.js.map +1 -0
  10. package/dist/binding.d.ts +31 -0
  11. package/dist/binding.d.ts.map +1 -0
  12. package/dist/binding.js +46 -0
  13. package/dist/binding.js.map +1 -0
  14. package/dist/classify.d.ts +35 -7
  15. package/dist/classify.d.ts.map +1 -1
  16. package/dist/classify.js +104 -14
  17. package/dist/classify.js.map +1 -1
  18. package/dist/fixture.d.ts +18 -2
  19. package/dist/fixture.d.ts.map +1 -1
  20. package/dist/fixture.js +23 -3
  21. package/dist/fixture.js.map +1 -1
  22. package/dist/index.d.ts +4 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +4 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/records.d.ts +8 -1
  27. package/dist/records.d.ts.map +1 -1
  28. package/dist/records.js +24 -1
  29. package/dist/records.js.map +1 -1
  30. package/dist/report.d.ts.map +1 -1
  31. package/dist/report.js +4 -0
  32. package/dist/report.js.map +1 -1
  33. package/dist/stale.d.ts +65 -0
  34. package/dist/stale.d.ts.map +1 -0
  35. package/dist/stale.js +95 -0
  36. package/dist/stale.js.map +1 -0
  37. package/dist/subject.d.ts +92 -0
  38. package/dist/subject.d.ts.map +1 -0
  39. package/dist/subject.js +247 -0
  40. package/dist/subject.js.map +1 -0
  41. package/package.json +9 -2
  42. package/src/adapters/common.ts +8 -0
  43. package/src/adapters/playwright.ts +94 -0
  44. package/src/binding.ts +68 -0
  45. package/src/classify.ts +165 -14
  46. package/src/fixture.ts +36 -3
  47. package/src/index.ts +4 -0
  48. package/src/records.ts +40 -2
  49. package/src/report.ts +4 -0
  50. package/src/stale.ts +160 -0
  51. package/src/subject.ts +277 -0
@@ -0,0 +1,247 @@
1
+ /**
2
+ * The subject of a verification (Core §8, ADR 0013): a hash of what the check
3
+ * is about, so a run record can stay current while the subject is unchanged.
4
+ * Pure: it reads nothing but what it is given, so the same inputs give the
5
+ * same hash on every machine.
6
+ *
7
+ * The subject is:
8
+ *
9
+ * - the verification record and what it verifies (each verified behavior, the
10
+ * rules that govern it and the scenarios that illustrate it), each by the
11
+ * source hash of its whole record: its prose is its promise;
12
+ * - the slices that implement the verified behaviors, the transitive closure
13
+ * of their `dependsOn`, and those the verification names in
14
+ * `verification.exercises`: each by the hash of its **binding fields**
15
+ * (`implements`, `dependsOn`, `claims`, `usesResources`, `entrypoints`;
16
+ * never its prose) and the content of every file its claims resolve to;
17
+ * - the resources those slices use, and any resource `exercises` names: each
18
+ * by its registry entry and the content of the files its path matches;
19
+ * - the test file (`locator`) and the local files it imports, transitively,
20
+ * which the caller resolves (`localImports`) with the architecture
21
+ * package's resolver and stops at a package boundary;
22
+ * - the repository's global inputs, which the caller has expanded to paths.
23
+ *
24
+ * The slices' and resources' files are resolved by the architecture package
25
+ * and passed in, so this package does not depend on it. The hash is the
26
+ * SHA-256 of the canonical JSON of the sorted entries (ADR 0005), like
27
+ * `graphHash`; a file is its content's SHA-256, a missing one the word
28
+ * `absent`, so a deleted file moves the subject. `parts` carries each entry,
29
+ * so a report can say which part moved (`movedParts`).
30
+ */
31
+ import { canonicalJson, sha256Hex } from "@intentset/core";
32
+ export const SUBJECT_PART_KINDS = [
33
+ "verification",
34
+ "verified",
35
+ "slice",
36
+ "slice-file",
37
+ "resource",
38
+ "resource-file",
39
+ "test",
40
+ "test-import",
41
+ "global-input",
42
+ ];
43
+ /** What a missing file hashes as, so a deleted file moves the subject and is told apart from an empty one. */
44
+ export const ABSENT = "absent";
45
+ const cmp = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
46
+ /** The verification's `verification.exercises`, or none. */
47
+ export function exercisesOf(graph, id) {
48
+ const list = graph.artifacts.get(id)?.meta.verification?.exercises;
49
+ return Array.isArray(list) ? list.filter((x) => typeof x === "string") : [];
50
+ }
51
+ /** The behaviors a verification is about: those it verifies, those governed by a rule it verifies, those a scenario it verifies illustrates. */
52
+ export function verifiedBehaviors(graph, verificationId) {
53
+ const behaviors = new Set();
54
+ for (const edge of graph.out.get(verificationId) ?? []) {
55
+ if (edge.kind !== "verifies")
56
+ continue;
57
+ const target = graph.artifacts.get(edge.to);
58
+ if (target === undefined)
59
+ continue;
60
+ if (target.meta.type === "behavior")
61
+ behaviors.add(target.meta.id);
62
+ else if (target.meta.type === "rule") {
63
+ for (const back of graph.in.get(target.meta.id) ?? [])
64
+ if (back.kind === "governedBy")
65
+ behaviors.add(back.from);
66
+ }
67
+ else if (target.meta.type === "scenario") {
68
+ for (const out of graph.out.get(target.meta.id) ?? [])
69
+ if (out.kind === "illustrates")
70
+ behaviors.add(out.to);
71
+ }
72
+ }
73
+ return [...behaviors].filter((id) => graph.artifacts.get(id)?.meta.type === "behavior").sort(cmp);
74
+ }
75
+ /** The slices a subject includes, each with why: implementers, their `dependsOn` closure, and the exercised slices. */
76
+ export function includedSlices(graph, verificationId) {
77
+ const why = new Map();
78
+ const add = (id, reason) => {
79
+ const set = why.get(id) ?? new Set();
80
+ set.add(reason);
81
+ why.set(id, set);
82
+ };
83
+ const queue = [];
84
+ const seed = (id, reason) => {
85
+ if (graph.artifacts.get(id)?.meta.type !== "slice")
86
+ return;
87
+ if (!why.has(id))
88
+ queue.push(id);
89
+ add(id, reason);
90
+ };
91
+ for (const behavior of verifiedBehaviors(graph, verificationId)) {
92
+ for (const edge of graph.in.get(behavior) ?? [])
93
+ if (edge.kind === "implements")
94
+ seed(edge.from, "implements");
95
+ }
96
+ for (const id of exercisesOf(graph, verificationId))
97
+ seed(id, "exercises");
98
+ while (queue.length > 0) {
99
+ const id = queue.pop();
100
+ for (const edge of graph.out.get(id) ?? []) {
101
+ if (edge.kind !== "dependsOn")
102
+ continue;
103
+ if (!why.has(edge.to))
104
+ queue.push(edge.to);
105
+ if (graph.artifacts.get(edge.to)?.meta.type === "slice")
106
+ add(edge.to, "dependsOn");
107
+ }
108
+ }
109
+ return new Map([...why].sort(([a], [b]) => cmp(a, b)).map(([id, set]) => [id, [...set].sort(cmp).join(",")]));
110
+ }
111
+ /** The binding fields of a slice record, canonical: what the subject hashes of it instead of the whole record. */
112
+ export function sliceBinding(graph, id) {
113
+ const artifact = graph.artifacts.get(id);
114
+ if (artifact === undefined)
115
+ return null;
116
+ const links = artifact.meta.links;
117
+ const slice = artifact.meta.slice;
118
+ const sorted = (list) => [...(list ?? [])].sort(cmp);
119
+ return {
120
+ implements: sorted(links.implements),
121
+ dependsOn: sorted(links.dependsOn),
122
+ claims: (slice?.claims ?? [])
123
+ .map((c) => ({ kind: c.kind, path: c.path }))
124
+ .sort((a, b) => cmp(a.kind, b.kind) || cmp(a.path, b.path)),
125
+ usesResources: sorted(slice?.usesResources),
126
+ entrypoints: sorted(slice?.entrypoints),
127
+ };
128
+ }
129
+ export function computeSubject(input) {
130
+ const { graph, verificationId, readFile, globalInputs } = input;
131
+ const verification = graph.artifacts.get(verificationId);
132
+ if (verification === undefined || verification.meta.type !== "verification") {
133
+ throw new Error(`${verificationId} is not a verification in the graph`);
134
+ }
135
+ const claimed = (id) => input.sliceFiles instanceof Map
136
+ ? (input.sliceFiles.get(id) ?? [])
137
+ : (input.sliceFiles[id] ?? []);
138
+ const fileHash = input.fileHash ??
139
+ ((path) => {
140
+ const bytes = readFile(path);
141
+ return bytes === undefined ? ABSENT : sha256Hex(bytes);
142
+ });
143
+ const recordPart = (kind, id, extra = {}) => {
144
+ const artifact = graph.artifacts.get(id);
145
+ return {
146
+ kind,
147
+ id,
148
+ hash: artifact === undefined ? ABSENT : artifact.sourceHash,
149
+ ...extra,
150
+ ...(artifact === undefined ? {} : { path: artifact.path }),
151
+ };
152
+ };
153
+ const parts = [recordPart("verification", verificationId)];
154
+ const targets = new Set();
155
+ for (const edge of graph.out.get(verificationId) ?? [])
156
+ if (edge.kind === "verifies")
157
+ targets.add(edge.to);
158
+ for (const id of verifiedBehaviors(graph, verificationId)) {
159
+ targets.add(id);
160
+ for (const edge of graph.out.get(id) ?? [])
161
+ if (edge.kind === "governedBy")
162
+ targets.add(edge.to);
163
+ for (const edge of graph.in.get(id) ?? [])
164
+ if (edge.kind === "illustrates")
165
+ targets.add(edge.from);
166
+ }
167
+ for (const id of targets)
168
+ parts.push(recordPart("verified", id));
169
+ const resourceWhy = new Map();
170
+ const useResource = (id, reason) => {
171
+ if (input.resources?.has(id) !== true)
172
+ return;
173
+ const set = resourceWhy.get(id) ?? new Set();
174
+ set.add(reason);
175
+ resourceWhy.set(id, set);
176
+ };
177
+ for (const id of exercisesOf(graph, verificationId))
178
+ useResource(id, "exercises");
179
+ for (const [id, why] of includedSlices(graph, verificationId)) {
180
+ const artifact = graph.artifacts.get(id);
181
+ parts.push({
182
+ kind: "slice",
183
+ id,
184
+ hash: artifact === undefined ? ABSENT : sha256Hex(canonicalJson(sliceBinding(graph, id))),
185
+ why,
186
+ ...(artifact === undefined ? {} : { path: artifact.path }),
187
+ });
188
+ for (const path of [...new Set(claimed(id))].sort(cmp)) {
189
+ parts.push({ kind: "slice-file", id: path, hash: fileHash(path), owner: id, path });
190
+ }
191
+ for (const resource of artifact?.meta.slice?.usesResources ?? [])
192
+ useResource(resource, "usesResources");
193
+ }
194
+ for (const [id, set] of resourceWhy) {
195
+ const resource = input.resources?.get(id);
196
+ parts.push({
197
+ kind: "resource",
198
+ id,
199
+ hash: sha256Hex(canonicalJson(resource.record)),
200
+ why: [...set].sort(cmp).join(","),
201
+ });
202
+ for (const path of [...new Set(resource.files)].sort(cmp)) {
203
+ parts.push({ kind: "resource-file", id: path, hash: fileHash(path), owner: id, path });
204
+ }
205
+ }
206
+ const locator = verification.meta.verification?.locator;
207
+ if (locator !== undefined && locator !== "") {
208
+ parts.push({ kind: "test", id: locator, hash: fileHash(locator), path: locator });
209
+ for (const path of [...new Set(input.localImports?.(locator) ?? [])].sort(cmp)) {
210
+ if (path !== locator)
211
+ parts.push({ kind: "test-import", id: path, hash: fileHash(path), path });
212
+ }
213
+ }
214
+ for (const path of [...new Set(globalInputs)]) {
215
+ parts.push({ kind: "global-input", id: path, hash: fileHash(path), path });
216
+ }
217
+ parts.sort((a, b) => cmp(a.kind, b.kind) || cmp(a.id, b.id) || cmp(a.owner ?? "", b.owner ?? ""));
218
+ const entries = parts.map(({ kind, id, hash, why, owner }) => ({ kind, id, hash, why, owner }));
219
+ return { hash: sha256Hex(canonicalJson(entries)), parts };
220
+ }
221
+ const partKey = (p) => `${p.kind} ${p.id}${p.owner === undefined ? "" : ` (${p.owner})`}`;
222
+ /** The parts that differ between two subjects, as `kind id` keys, sorted: added, removed or changed. */
223
+ export function movedParts(before, after) {
224
+ const a = new Map(before.parts.map((p) => [partKey(p), p.hash]));
225
+ const b = new Map(after.parts.map((p) => [partKey(p), p.hash]));
226
+ const moved = [];
227
+ for (const [k, h] of a)
228
+ if (b.get(k) !== h)
229
+ moved.push(k);
230
+ for (const k of b.keys())
231
+ if (!a.has(k))
232
+ moved.push(k);
233
+ return moved.sort(cmp);
234
+ }
235
+ /**
236
+ * The parts of a subject whose file or record is among `changed`: what a
237
+ * `git diff --name-only` since a record's commit says may have moved. A record
238
+ * file that changed only in prose is named too, since the diff cannot tell it
239
+ * from a change to a binding field; the hash decided the subject moved.
240
+ */
241
+ export function partsChangedAmong(subject, changed) {
242
+ return subject.parts
243
+ .filter((p) => p.path !== undefined && changed.has(p.path))
244
+ .map(partKey)
245
+ .sort(cmp);
246
+ }
247
+ //# sourceMappingURL=subject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subject.js","sourceRoot":"","sources":["../src/subject.ts"],"names":[],"mappings":"AAAA;;;;;;;;;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CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC;QAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1D,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE;QAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAAE,OAA4B;IAC9E,OAAO,OAAO,CAAC,KAAK;SACjB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SAC1D,GAAG,CAAC,OAAO,CAAC;SACZ,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@intentset/verification",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Run records, evidence freshness classification, and test-reporter adapters.",
5
+ "keywords": [
6
+ "intentset",
7
+ "verification",
8
+ "test-evidence",
9
+ "vitest",
10
+ "traceability"
11
+ ],
5
12
  "license": "MIT",
6
13
  "type": "module",
7
14
  "engines": {
@@ -28,6 +35,6 @@
28
35
  }
29
36
  },
30
37
  "dependencies": {
31
- "@intentset/core": "^0.6.0"
38
+ "@intentset/core": "^0.7.0"
32
39
  }
33
40
  }
@@ -34,6 +34,12 @@ export interface ToRunRecordsOptions {
34
34
  finishedAt: string;
35
35
  /** Where the run's report lives; each record's uri is this plus `#` and the verification ID. */
36
36
  uriBase: string;
37
+ /**
38
+ * Verification ID -> the hash of its subject, when the effective binding is subject (Core §8): a record is then
39
+ * written with `binding: "subject"` and that hash, and the commit and graph hash stay as provenance. A
40
+ * verification with no entry, or no map at all, gets a commit-binding record.
41
+ */
42
+ subjects?: ReadonlyMap<string, string>;
37
43
  }
38
44
 
39
45
  export interface ConvertedRun {
@@ -114,6 +120,7 @@ export function toRunRecords(parsed: ParsedRun, options: ToRunRecordsOptions): C
114
120
  .map(([r, n]) => `${n} ${r}`)
115
121
  .join(", ");
116
122
  const names = [...selectors].sort(compareStrings).join(", ");
123
+ const subjectHash = options.subjects?.get(verificationId);
117
124
  records.push({
118
125
  evidenceId: deriveEvidenceId(verificationId, options.commit, options.graphHash, options.finishedAt),
119
126
  verificationId,
@@ -127,6 +134,7 @@ export function toRunRecords(parsed: ParsedRun, options: ToRunRecordsOptions): C
127
134
  finishedAt: options.finishedAt,
128
135
  result,
129
136
  uri: `${options.uriBase}#${encodeURIComponent(verificationId)}`,
137
+ ...(subjectHash === undefined ? {} : { binding: "subject" as const, subjectHash }),
130
138
  rationale: `${results.length} test${results.length === 1 ? "" : "s"} matched ${names}: ${counts}.`,
131
139
  });
132
140
  }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * `playwright test --reporter=json`: `suites[]`, each a file whose `suites[]` are `describe` groups and whose
3
+ * `specs[]` are the tests, each spec holding one `tests[]` entry per project it ran in. A test's full name is its
4
+ * describe titles and its own, joined with " > " (the file's own suite is left out, as the runner's list reporter
5
+ * leaves it out), so a selector is matched as it is for the other runners; a test that runs in several projects makes
6
+ * one `ParsedTest` for each, and the worst of them is the verification's result.
7
+ *
8
+ * Results follow the test's own `status`: expected is pass (a `test.fail()` that failed as declared is expected),
9
+ * skipped is skip (`test.skip` and `test.fixme` are skipped), flaky is pass (it failed and passed on a retry, and the
10
+ * retry policy is the project's), and unexpected is fail when its last attempt was an assertion and error when it
11
+ * timed out, was interrupted or threw anything else. Errors the report lists for the whole run (a global setup that
12
+ * failed) are listed in `problems`, since no test title can carry them to a selector.
13
+ */
14
+ import type { RunResult } from "../records.ts";
15
+ import type { ParsedRun, ParsedTest } from "./common.ts";
16
+
17
+ export function parsePlaywrightJson(json: unknown): ParsedRun {
18
+ if (!isRecord(json) || !Array.isArray(json.suites)) {
19
+ throw new TypeError("This is not Playwright JSON reporter output: expected an object with a suites array.");
20
+ }
21
+ const tests: ParsedTest[] = [];
22
+ const problems: string[] = [];
23
+ if (Array.isArray(json.errors)) {
24
+ for (const error of json.errors) {
25
+ problems.push(`The run reported an error: ${firstLine(isRecord(error) ? error.message : error) || "no message"}`);
26
+ }
27
+ }
28
+ json.suites.forEach((file, index) => {
29
+ if (!isRecord(file)) throw new TypeError(`suites[${index}] is not an object.`);
30
+ walk(file, [], tests, problems);
31
+ });
32
+ return { tests, problems };
33
+ }
34
+
35
+ function walk(suite: Record<string, unknown>, ancestors: string[], tests: ParsedTest[], problems: string[]): void {
36
+ for (const spec of Array.isArray(suite.specs) ? suite.specs : []) {
37
+ if (!isRecord(spec)) throw new TypeError("A spec in the report is not an object.");
38
+ const title = typeof spec.title === "string" ? spec.title : "";
39
+ const fullName = [...ancestors, title].join(" > ");
40
+ for (const test of Array.isArray(spec.tests) ? spec.tests : []) {
41
+ if (!isRecord(test)) throw new TypeError(`${fullName} has a test entry that is not an object.`);
42
+ const result = resultOf(test, fullName, problems);
43
+ tests.push({ fullName, result, durationMs: durationOf(test) });
44
+ }
45
+ }
46
+ for (const child of Array.isArray(suite.suites) ? suite.suites : []) {
47
+ if (!isRecord(child)) throw new TypeError("A suite in the report is not an object.");
48
+ const title = typeof child.title === "string" ? child.title : "";
49
+ walk(child, title === "" ? ancestors : [...ancestors, title], tests, problems);
50
+ }
51
+ }
52
+
53
+ function resultOf(test: Record<string, unknown>, fullName: string, problems: string[]): RunResult {
54
+ switch (test.status) {
55
+ case "expected":
56
+ case "flaky":
57
+ return "pass";
58
+ case "skipped":
59
+ return "skip";
60
+ case "unexpected":
61
+ return failureKind(lastResult(test));
62
+ default:
63
+ problems.push(`${fullName} has the unknown status ${JSON.stringify(test.status)}, read as error`);
64
+ return "error";
65
+ }
66
+ }
67
+
68
+ /** A timeout or an interrupted run is an error; an assertion that did not hold is a fail; anything else thrown is an error. */
69
+ function failureKind(last: Record<string, unknown> | undefined): RunResult {
70
+ if (last === undefined) return "fail";
71
+ if (last.status === "timedOut" || last.status === "interrupted") return "error";
72
+ const error = isRecord(last.error) ? last.error : undefined;
73
+ const message = typeof error?.message === "string" ? error.message : "";
74
+ return /\bexpect\(|AssertionError/.test(message) || message === "" ? "fail" : "error";
75
+ }
76
+
77
+ function lastResult(test: Record<string, unknown>): Record<string, unknown> | undefined {
78
+ const results = Array.isArray(test.results) ? test.results : [];
79
+ const last = results[results.length - 1];
80
+ return isRecord(last) ? last : undefined;
81
+ }
82
+
83
+ function durationOf(test: Record<string, unknown>): number | null {
84
+ const duration = lastResult(test)?.duration;
85
+ return typeof duration === "number" && Number.isFinite(duration) ? duration : null;
86
+ }
87
+
88
+ function firstLine(value: unknown): string {
89
+ return typeof value === "string" ? (value.trim().split("\n")[0] ?? "") : "";
90
+ }
91
+
92
+ function isRecord(value: unknown): value is Record<string, unknown> {
93
+ return typeof value === "object" && value !== null && !Array.isArray(value);
94
+ }
package/src/binding.ts ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Which binding judges run evidence (Core §8, ADR 0013) and the subjects it
3
+ * needs. The decision is pure: the repository's configuration and whether it
4
+ * has slice claims. Computing a subject needs what the architecture package
5
+ * resolves (claimed files, import closures), which this package does not
6
+ * depend on, so a caller hands it in as a `SubjectSource`.
7
+ */
8
+ import type { EvidenceBinding, EvidenceBindingReason, Graph } from "@intentset/core";
9
+ import { compareStrings } from "./diagnostic.ts";
10
+ import { ABSENT, computeSubject, type Subject, type SubjectInput } from "./subject.ts";
11
+ import { sha256Hex } from "@intentset/core";
12
+
13
+ export interface BindingDecision {
14
+ binding: EvidenceBinding;
15
+ /** `configured`, `default` (subject, since slices exist) or `no-slices` (commit, since there is nothing to hash). */
16
+ reason: EvidenceBindingReason;
17
+ }
18
+
19
+ /**
20
+ * Core §8: `binding: subject` is the default wherever the repository has slice
21
+ * claims; `binding: commit` is the stricter mode a repository or gate asks
22
+ * for; a repository with no slice claims is judged by commit binding unless it
23
+ * asked for that, and says so (EVID004), whatever it asked for.
24
+ */
25
+ export function resolveBinding(configured: EvidenceBinding | null, hasSlices: boolean): BindingDecision {
26
+ if (configured === "commit") return { binding: "commit", reason: "configured" };
27
+ if (!hasSlices) return { binding: "commit", reason: "no-slices" };
28
+ return { binding: "subject", reason: configured === "subject" ? "configured" : "default" };
29
+ }
30
+
31
+ /** True when some slice that is not retired claims files: the repository has a subject to hash. */
32
+ export function hasSliceClaims(graph: Graph): boolean {
33
+ for (const artifact of graph.artifacts.values()) {
34
+ if (
35
+ artifact.meta.type === "slice" &&
36
+ artifact.meta.status !== "retired" &&
37
+ (artifact.meta.slice?.claims.length ?? 0) > 0
38
+ )
39
+ return true;
40
+ }
41
+ return false;
42
+ }
43
+
44
+ /** What a caller resolves for the subject hash: the architecture package's claims and imports, over one tree. */
45
+ export type SubjectSource = Omit<SubjectInput, "graph" | "verificationId"> & {
46
+ /** True for a file that can move some subject: a slice's, a used resource's, a global input, a test, a record. */
47
+ covers: (path: string) => boolean;
48
+ };
49
+
50
+ /** The subject of every verification in the graph, by ID, with each file hashed once. */
51
+ export function subjectsFor(graph: Graph, source: SubjectSource): Map<string, Subject> {
52
+ const hashes = new Map<string, string>();
53
+ const fileHash = (path: string): string => {
54
+ let hash = hashes.get(path);
55
+ if (hash === undefined) {
56
+ const bytes = source.readFile(path);
57
+ hash = bytes === undefined ? ABSENT : sha256Hex(bytes);
58
+ hashes.set(path, hash);
59
+ }
60
+ return hash;
61
+ };
62
+ const subjects = new Map<string, Subject>();
63
+ const ids = [...graph.artifacts.keys()].filter((id) => graph.artifacts.get(id)?.meta.type === "verification");
64
+ for (const id of ids.sort(compareStrings)) {
65
+ subjects.set(id, computeSubject({ ...source, graph, verificationId: id, fileHash }));
66
+ }
67
+ return subjects;
68
+ }