autotel-pact 2.0.0 → 4.0.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 (91) hide show
  1. package/dist/attrs-DbCs1ou0.cjs +61 -0
  2. package/dist/attrs-DbCs1ou0.cjs.map +1 -0
  3. package/dist/attrs-ElwK54Ym.js +43 -0
  4. package/dist/attrs-ElwK54Ym.js.map +1 -0
  5. package/dist/audit.cjs +155 -394
  6. package/dist/audit.cjs.map +1 -1
  7. package/dist/audit.d.cts +15 -13
  8. package/dist/audit.d.cts.map +1 -0
  9. package/dist/audit.d.ts +15 -13
  10. package/dist/audit.d.ts.map +1 -0
  11. package/dist/audit.js +153 -388
  12. package/dist/audit.js.map +1 -1
  13. package/dist/auto-wrap.cjs +206 -240
  14. package/dist/auto-wrap.cjs.map +1 -1
  15. package/dist/auto-wrap.d.cts +9 -7
  16. package/dist/auto-wrap.d.cts.map +1 -0
  17. package/dist/auto-wrap.d.ts +9 -7
  18. package/dist/auto-wrap.d.ts.map +1 -0
  19. package/dist/auto-wrap.js +205 -233
  20. package/dist/auto-wrap.js.map +1 -1
  21. package/dist/broker.cjs +65 -68
  22. package/dist/broker.cjs.map +1 -1
  23. package/dist/broker.d.cts +11 -9
  24. package/dist/broker.d.cts.map +1 -0
  25. package/dist/broker.d.ts +11 -9
  26. package/dist/broker.d.ts.map +1 -0
  27. package/dist/broker.js +64 -67
  28. package/dist/broker.js.map +1 -1
  29. package/dist/cli.cjs +166 -620
  30. package/dist/cli.cjs.map +1 -1
  31. package/dist/cli.d.cts +3 -2
  32. package/dist/cli.d.cts.map +1 -0
  33. package/dist/cli.d.ts +3 -2
  34. package/dist/cli.d.ts.map +1 -0
  35. package/dist/cli.js +165 -614
  36. package/dist/cli.js.map +1 -1
  37. package/dist/index.cjs +245 -952
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.d.cts +90 -86
  40. package/dist/index.d.cts.map +1 -0
  41. package/dist/index.d.ts +90 -86
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +216 -918
  44. package/dist/index.js.map +1 -1
  45. package/dist/labels-0Cwk5E-8.cjs +41 -0
  46. package/dist/labels-0Cwk5E-8.cjs.map +1 -0
  47. package/dist/labels-BQjT_Zrv.js +23 -0
  48. package/dist/labels-BQjT_Zrv.js.map +1 -0
  49. package/dist/{ledger-D88TzN1c.d.cts → ledger-BAFsRX6y.d.cts} +8 -6
  50. package/dist/ledger-BAFsRX6y.d.cts.map +1 -0
  51. package/dist/ledger-BayQwemz.cjs +267 -0
  52. package/dist/ledger-BayQwemz.cjs.map +1 -0
  53. package/dist/{ledger-BuBmfWNc.d.ts → ledger-Bzh_6tbV.d.ts} +8 -6
  54. package/dist/ledger-Bzh_6tbV.d.ts.map +1 -0
  55. package/dist/ledger-sII3Ig3Y.js +174 -0
  56. package/dist/ledger-sII3Ig3Y.js.map +1 -0
  57. package/dist/pact-file-B8QjVrC7.cjs +76 -0
  58. package/dist/pact-file-B8QjVrC7.cjs.map +1 -0
  59. package/dist/pact-file-CkE4NFZ1.js +57 -0
  60. package/dist/pact-file-CkE4NFZ1.js.map +1 -0
  61. package/dist/processor.cjs +112 -185
  62. package/dist/processor.cjs.map +1 -1
  63. package/dist/processor.d.cts +41 -40
  64. package/dist/processor.d.cts.map +1 -0
  65. package/dist/processor.d.ts +41 -40
  66. package/dist/processor.d.ts.map +1 -0
  67. package/dist/processor.js +111 -179
  68. package/dist/processor.js.map +1 -1
  69. package/dist/provider.cjs +90 -205
  70. package/dist/provider.cjs.map +1 -1
  71. package/dist/provider.d.cts +26 -25
  72. package/dist/provider.d.cts.map +1 -0
  73. package/dist/provider.d.ts +26 -25
  74. package/dist/provider.d.ts.map +1 -0
  75. package/dist/provider.js +88 -199
  76. package/dist/provider.js.map +1 -1
  77. package/dist/tag.cjs +14 -44
  78. package/dist/tag.cjs.map +1 -1
  79. package/dist/tag.d.cts +4 -2
  80. package/dist/tag.d.cts.map +1 -0
  81. package/dist/tag.d.ts +4 -2
  82. package/dist/tag.d.ts.map +1 -0
  83. package/dist/tag.js +13 -42
  84. package/dist/tag.js.map +1 -1
  85. package/dist/types-D_0kgK2e.d.cts +154 -0
  86. package/dist/types-D_0kgK2e.d.cts.map +1 -0
  87. package/dist/types-D_0kgK2e.d.ts +154 -0
  88. package/dist/types-D_0kgK2e.d.ts.map +1 -0
  89. package/package.json +6 -6
  90. package/dist/types-BHGiwqcp.d.cts +0 -157
  91. package/dist/types-BHGiwqcp.d.ts +0 -157
package/dist/audit.js CHANGED
@@ -1,403 +1,168 @@
1
- import path from 'path';
2
- import { existsSync, statSync, readdirSync, readFileSync } from 'fs';
3
- import 'fs/promises';
1
+ import { l as isInteractionLedgerEntry, o as readLedger, s as AUDIT_MATRIX_SPEC, u as isProviderVerificationRun } from "./ledger-sII3Ig3Y.js";
2
+ import { n as listPactFiles, r as parsePactFile, t as interactionsFromPactFile } from "./pact-file-CkE4NFZ1.js";
3
+ import { fetchBrokerVerifications } from "./broker.js";
4
+ import path from "node:path";
4
5
 
5
- // src/audit.ts
6
-
7
- // src/broker.ts
8
- function authHeaders(config) {
9
- const headers = {
10
- Accept: "application/json"
11
- };
12
- if (config.token) {
13
- headers.Authorization = `Bearer ${config.token}`;
14
- } else if (config.username && config.password) {
15
- const encoded = Buffer.from(`${config.username}:${config.password}`).toString("base64");
16
- headers.Authorization = `Basic ${encoded}`;
17
- }
18
- return headers;
19
- }
20
- function trimBaseUrl(url) {
21
- return url.replace(/\/$/, "");
22
- }
23
- function parseBrokerVerificationResult(consumer, provider, json) {
24
- if (!json || typeof json !== "object") return null;
25
- const body = json;
26
- const success = body.success === true || body.success === void 0 && body.result === "success";
27
- const verifiedAt = typeof body.verifiedAt === "string" ? body.verifiedAt : typeof body.verified_at === "string" ? body.verified_at : typeof body.createdAt === "string" ? body.createdAt : void 0;
28
- return {
29
- consumer,
30
- provider,
31
- success: !!success,
32
- verifiedAt
33
- };
34
- }
35
- async function fetchBrokerVerifications(config, pairs) {
36
- const base = trimBaseUrl(config.baseUrl);
37
- const headers = authHeaders(config);
38
- const results = [];
39
- for (const { consumer, provider } of pairs) {
40
- const url = `${base}/pacts/provider/${encodeURIComponent(provider)}/consumer/${encodeURIComponent(consumer)}/latest/verification-results`;
41
- try {
42
- const res = await fetch(url, { headers });
43
- if (!res.ok) {
44
- results.push({
45
- consumer,
46
- provider,
47
- success: false,
48
- error: `HTTP ${res.status} ${res.statusText}`.trim()
49
- });
50
- continue;
51
- }
52
- const json = await res.json();
53
- const parsed = parseBrokerVerificationResult(consumer, provider, json);
54
- results.push(
55
- parsed ?? {
56
- consumer,
57
- provider,
58
- success: false,
59
- error: "Unparseable broker response"
60
- }
61
- );
62
- } catch (error) {
63
- results.push({
64
- consumer,
65
- provider,
66
- success: false,
67
- error: error instanceof Error ? error.message : String(error)
68
- });
69
- }
70
- }
71
- return results;
72
- }
73
-
74
- // src/types.ts
75
- var LEDGER_ENTRY_SPEC = "autotel-pact-ledger-entry/v0.2.0";
76
- var AUDIT_MATRIX_SPEC = "autotel-pact-audit-matrix/v0.2.0";
77
- function isInteractionLedgerEntry(entry) {
78
- return entry.type !== "provider_verification_run";
79
- }
80
- function isProviderVerificationRun(entry) {
81
- return entry.type === "provider_verification_run";
82
- }
83
-
84
- // src/ledger-normalize.ts
85
- function isRecord(value) {
86
- return typeof value === "object" && value !== null;
87
- }
88
- function normalizeLedgerRecord(parsed) {
89
- if (!isRecord(parsed) || parsed.spec !== LEDGER_ENTRY_SPEC) return null;
90
- const { consumer, provider, observed_at } = parsed;
91
- if (typeof consumer !== "string" || typeof provider !== "string" || typeof observed_at !== "string") {
92
- return null;
93
- }
94
- if (parsed.type === "provider_verification_run") {
95
- if (typeof parsed.error !== "string") return null;
96
- const entry2 = {
97
- type: "provider_verification_run",
98
- spec: LEDGER_ENTRY_SPEC,
99
- consumer,
100
- provider,
101
- outcome: "failed",
102
- source: parsed.source === "production" ? "production" : "test",
103
- role: "provider",
104
- observed_at,
105
- error: parsed.error
106
- };
107
- if (typeof parsed.run_id === "string") entry2.run_id = parsed.run_id;
108
- if (typeof parsed.git_sha === "string") entry2.git_sha = parsed.git_sha;
109
- if (typeof parsed.trace_id === "string") entry2.trace_id = parsed.trace_id;
110
- if (typeof parsed.span_id === "string") entry2.span_id = parsed.span_id;
111
- return entry2;
112
- }
113
- if (typeof parsed.interaction !== "string") return null;
114
- const states = Array.isArray(parsed.states) ? parsed.states.filter((s) => typeof s === "string") : [];
115
- const entry = {
116
- type: "interaction",
117
- spec: LEDGER_ENTRY_SPEC,
118
- consumer,
119
- provider,
120
- interaction: parsed.interaction,
121
- states,
122
- kind: parsed.kind === "http" ? "http" : "message",
123
- outcome: parsed.outcome === "failed" ? "failed" : "passed",
124
- source: parsed.source === "production" ? "production" : "test",
125
- role: parsed.role === "provider" ? "provider" : "consumer",
126
- duration_ms: typeof parsed.duration_ms === "number" && parsed.duration_ms >= 0 ? parsed.duration_ms : 0,
127
- observed_at
128
- };
129
- if (typeof parsed.interaction_id === "string" && parsed.interaction_id.length > 0) {
130
- entry.interaction_id = parsed.interaction_id;
131
- }
132
- if (typeof parsed.trace_id === "string") entry.trace_id = parsed.trace_id;
133
- if (typeof parsed.span_id === "string") entry.span_id = parsed.span_id;
134
- if (typeof parsed.run_id === "string") entry.run_id = parsed.run_id;
135
- if (typeof parsed.git_sha === "string") entry.git_sha = parsed.git_sha;
136
- if (typeof parsed.error === "string") entry.error = parsed.error;
137
- return entry;
138
- }
139
-
140
- // src/ledger.ts
141
- var DEFAULT_DIR = ".autotel-pact";
142
- function resolveLedgerDir(opts = {}) {
143
- return path.resolve(process.cwd(), opts.dir ?? process.env.AUTOTEL_PACT_LEDGER_DIR ?? DEFAULT_DIR);
144
- }
145
- function readLedger(opts = {}) {
146
- const dir = resolveLedgerDir(opts);
147
- if (!existsSync(dir)) return [];
148
- const files = readdirSync(dir).filter((f) => f.endsWith(".jsonl"));
149
- const entries = [];
150
- for (const file of files) {
151
- const text = readFileSync(path.join(dir, file), "utf8");
152
- for (const line of text.split("\n")) {
153
- if (!line.trim()) continue;
154
- try {
155
- const normalized = normalizeLedgerRecord(JSON.parse(line));
156
- if (normalized) entries.push(normalized);
157
- } catch {
158
- }
159
- }
160
- }
161
- return entries;
162
- }
163
- Promise.resolve();
164
- function listPactFiles(dir) {
165
- if (!existsSync(dir) || !statSync(dir).isDirectory()) return [];
166
- const out = [];
167
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
168
- const full = path.join(dir, entry.name);
169
- if (entry.isDirectory()) {
170
- out.push(...listPactFiles(full));
171
- } else if (entry.isFile() && entry.name.endsWith(".json")) {
172
- out.push(full);
173
- }
174
- }
175
- return out;
176
- }
177
- function extractInteractionId(metadata) {
178
- if (!metadata) return void 0;
179
- const id = metadata.interactionId ?? metadata.interaction_id;
180
- return typeof id === "string" && id.length > 0 ? id : void 0;
181
- }
182
- function interactionsFromPactFile(pact) {
183
- const consumer = pact.consumer?.name;
184
- const provider = pact.provider?.name;
185
- if (!consumer || !provider) return [];
186
- const keys = [];
187
- for (const m of pact.messages ?? []) {
188
- keys.push({
189
- consumer,
190
- provider,
191
- interaction: m.description,
192
- kind: "message",
193
- interactionId: extractInteractionId(m.metadata)
194
- });
195
- }
196
- for (const i of pact.interactions ?? []) {
197
- keys.push({
198
- consumer,
199
- provider,
200
- interaction: i.description,
201
- kind: "http",
202
- interactionId: extractInteractionId(i.metadata)
203
- });
204
- }
205
- return keys;
206
- }
207
- function parsePactFile(filePath) {
208
- try {
209
- return JSON.parse(readFileSync(filePath, "utf8"));
210
- } catch {
211
- return null;
212
- }
213
- }
214
-
215
- // src/audit.ts
216
- var DEFAULT_PACTS_DIR = "./pacts";
217
- var DEFAULT_WINDOW_DAYS = 14;
6
+ //#region src/audit.ts
7
+ const DEFAULT_PACTS_DIR = "./pacts";
8
+ const DEFAULT_WINDOW_DAYS = 14;
218
9
  function keyOf(k) {
219
- const identity = k.interactionId ?? k.interaction;
220
- return `${k.consumer}::${k.provider}::${k.kind}::${identity}`;
10
+ const identity = k.interactionId ?? k.interaction;
11
+ return `${k.consumer}::${k.provider}::${k.kind}::${identity}`;
221
12
  }
222
13
  function pairKey(consumer, provider) {
223
- return `${consumer}::${provider}`;
14
+ return `${consumer}::${provider}`;
224
15
  }
225
16
  function inWindow(observedAt, cutoff) {
226
- const t = Date.parse(observedAt);
227
- return Number.isFinite(t) && t >= cutoff;
17
+ const t = Date.parse(observedAt);
18
+ return Number.isFinite(t) && t >= cutoff;
228
19
  }
20
+ /**
21
+ * Compute the audit matrix from pact files, ledger, and optional broker data.
22
+ */
229
23
  function computeAuditMatrix(input) {
230
- const windowDays = input.windowDays ?? DEFAULT_WINDOW_DAYS;
231
- const now = input.now ?? /* @__PURE__ */ new Date();
232
- const cutoff = now.getTime() - windowDays * 24 * 60 * 60 * 1e3;
233
- const verificationFailures = [];
234
- const recentInteractions = [];
235
- for (const entry of input.ledger) {
236
- if (!inWindow(entry.observed_at, cutoff)) continue;
237
- if (isProviderVerificationRun(entry)) {
238
- verificationFailures.push(entry);
239
- continue;
240
- }
241
- if (isInteractionLedgerEntry(entry)) {
242
- recentInteractions.push(entry);
243
- }
244
- }
245
- const brokerByPair = /* @__PURE__ */ new Map();
246
- for (const b of input.brokerVerifications ?? []) {
247
- brokerByPair.set(pairKey(b.consumer, b.provider), b);
248
- }
249
- const testSeenByKey = /* @__PURE__ */ new Map();
250
- const prodSeenByKey = /* @__PURE__ */ new Map();
251
- const providerVerifiedByKey = /* @__PURE__ */ new Map();
252
- const anyObservedByKey = /* @__PURE__ */ new Map();
253
- for (const entry of recentInteractions) {
254
- const k = keyOf({
255
- consumer: entry.consumer,
256
- provider: entry.provider,
257
- interaction: entry.interaction,
258
- kind: entry.kind,
259
- interactionId: entry.interaction_id
260
- });
261
- const push = (map) => {
262
- const arr = map.get(k) ?? [];
263
- arr.push(entry);
264
- map.set(k, arr);
265
- };
266
- push(anyObservedByKey);
267
- if (entry.source === "test" && entry.role === "consumer") {
268
- push(testSeenByKey);
269
- }
270
- if (entry.source === "production") {
271
- push(prodSeenByKey);
272
- }
273
- if (entry.role === "provider" && entry.outcome === "passed") {
274
- push(providerVerifiedByKey);
275
- }
276
- }
277
- const contractedByKey = /* @__PURE__ */ new Map();
278
- for (const c of input.contracted) {
279
- contractedByKey.set(keyOf(c), c);
280
- }
281
- const rows = [];
282
- function pushRow(parts, k, isContracted) {
283
- const testObs = testSeenByKey.get(k) ?? [];
284
- const prodObs = prodSeenByKey.get(k) ?? [];
285
- const providerObs = providerVerifiedByKey.get(k) ?? [];
286
- const allObs = anyObservedByKey.get(k) ?? [];
287
- const latest = allObs.toSorted(
288
- (a, b) => b.observed_at.localeCompare(a.observed_at)
289
- )[0];
290
- const broker = brokerByPair.get(pairKey(parts.consumer, parts.provider));
291
- rows.push({
292
- consumer: parts.consumer,
293
- provider: parts.provider,
294
- interaction: parts.interaction,
295
- interaction_id: parts.interactionId ?? latest?.interaction_id,
296
- kind: parts.kind,
297
- contracted: isContracted,
298
- observed: testObs.length > 0 || prodObs.length > 0,
299
- test_seen: testObs.length > 0,
300
- prod_seen: prodObs.length > 0,
301
- provider_verified: providerObs.length > 0,
302
- broker_verified: broker?.success === true,
303
- broker_verified_at: broker?.verifiedAt,
304
- broker_error: broker?.error,
305
- last_observed_at: latest?.observed_at,
306
- last_outcome: latest?.outcome
307
- });
308
- }
309
- for (const [k, contracted] of contractedByKey) {
310
- pushRow(contracted, k, true);
311
- }
312
- for (const [k, observations] of anyObservedByKey) {
313
- if (contractedByKey.has(k)) continue;
314
- const first = observations[0];
315
- pushRow(
316
- {
317
- consumer: first.consumer,
318
- provider: first.provider,
319
- interaction: first.interaction,
320
- kind: first.kind,
321
- interactionId: first.interaction_id
322
- },
323
- k,
324
- false
325
- );
326
- }
327
- rows.sort(
328
- (a, b) => a.consumer.localeCompare(b.consumer) || a.provider.localeCompare(b.provider) || a.interaction.localeCompare(b.interaction)
329
- );
330
- const counts = {
331
- total: rows.length,
332
- contracted: rows.filter((r) => r.contracted).length,
333
- observed: rows.filter((r) => r.observed).length,
334
- contracted_and_test_seen: rows.filter((r) => r.contracted && r.test_seen).length,
335
- contracted_not_test_seen: rows.filter((r) => r.contracted && !r.test_seen).length,
336
- test_or_prod_seen_not_contracted: rows.filter(
337
- (r) => !r.contracted && (r.test_seen || r.prod_seen)
338
- ).length,
339
- test_seen: rows.filter((r) => r.test_seen).length,
340
- prod_seen: rows.filter((r) => r.prod_seen).length,
341
- provider_verified: rows.filter((r) => r.provider_verified).length,
342
- broker_verified: rows.filter((r) => r.broker_verified).length
343
- };
344
- const matrix = {
345
- spec: AUDIT_MATRIX_SPEC,
346
- rows,
347
- counts,
348
- window_days: windowDays,
349
- generated_at: now.toISOString()
350
- };
351
- if (verificationFailures.length > 0) {
352
- matrix.verification_failures = verificationFailures;
353
- }
354
- return matrix;
24
+ const windowDays = input.windowDays ?? DEFAULT_WINDOW_DAYS;
25
+ const now = input.now ?? /* @__PURE__ */ new Date();
26
+ const cutoff = now.getTime() - windowDays * 24 * 60 * 60 * 1e3;
27
+ const verificationFailures = [];
28
+ const recentInteractions = [];
29
+ for (const entry of input.ledger) {
30
+ if (!inWindow(entry.observed_at, cutoff)) continue;
31
+ if (isProviderVerificationRun(entry)) {
32
+ verificationFailures.push(entry);
33
+ continue;
34
+ }
35
+ if (isInteractionLedgerEntry(entry)) recentInteractions.push(entry);
36
+ }
37
+ const brokerByPair = /* @__PURE__ */ new Map();
38
+ for (const b of input.brokerVerifications ?? []) brokerByPair.set(pairKey(b.consumer, b.provider), b);
39
+ const testSeenByKey = /* @__PURE__ */ new Map();
40
+ const prodSeenByKey = /* @__PURE__ */ new Map();
41
+ const providerVerifiedByKey = /* @__PURE__ */ new Map();
42
+ const anyObservedByKey = /* @__PURE__ */ new Map();
43
+ for (const entry of recentInteractions) {
44
+ const k = keyOf({
45
+ consumer: entry.consumer,
46
+ provider: entry.provider,
47
+ interaction: entry.interaction,
48
+ kind: entry.kind,
49
+ interactionId: entry.interaction_id
50
+ });
51
+ const push = (map) => {
52
+ const arr = map.get(k) ?? [];
53
+ arr.push(entry);
54
+ map.set(k, arr);
55
+ };
56
+ push(anyObservedByKey);
57
+ if (entry.source === "test" && entry.role === "consumer") push(testSeenByKey);
58
+ if (entry.source === "production") push(prodSeenByKey);
59
+ if (entry.role === "provider" && entry.outcome === "passed") push(providerVerifiedByKey);
60
+ }
61
+ const contractedByKey = /* @__PURE__ */ new Map();
62
+ for (const c of input.contracted) contractedByKey.set(keyOf(c), c);
63
+ const rows = [];
64
+ function pushRow(parts, k, isContracted) {
65
+ const testObs = testSeenByKey.get(k) ?? [];
66
+ const prodObs = prodSeenByKey.get(k) ?? [];
67
+ const providerObs = providerVerifiedByKey.get(k) ?? [];
68
+ const latest = (anyObservedByKey.get(k) ?? []).toSorted((a, b) => b.observed_at.localeCompare(a.observed_at))[0];
69
+ const broker = brokerByPair.get(pairKey(parts.consumer, parts.provider));
70
+ rows.push({
71
+ consumer: parts.consumer,
72
+ provider: parts.provider,
73
+ interaction: parts.interaction,
74
+ interaction_id: parts.interactionId ?? latest?.interaction_id,
75
+ kind: parts.kind,
76
+ contracted: isContracted,
77
+ observed: testObs.length > 0 || prodObs.length > 0,
78
+ test_seen: testObs.length > 0,
79
+ prod_seen: prodObs.length > 0,
80
+ provider_verified: providerObs.length > 0,
81
+ broker_verified: broker?.success === true,
82
+ broker_verified_at: broker?.verifiedAt,
83
+ broker_error: broker?.error,
84
+ last_observed_at: latest?.observed_at,
85
+ last_outcome: latest?.outcome
86
+ });
87
+ }
88
+ for (const [k, contracted] of contractedByKey) pushRow(contracted, k, true);
89
+ for (const [k, observations] of anyObservedByKey) {
90
+ if (contractedByKey.has(k)) continue;
91
+ const first = observations[0];
92
+ pushRow({
93
+ consumer: first.consumer,
94
+ provider: first.provider,
95
+ interaction: first.interaction,
96
+ kind: first.kind,
97
+ interactionId: first.interaction_id
98
+ }, k, false);
99
+ }
100
+ rows.sort((a, b) => a.consumer.localeCompare(b.consumer) || a.provider.localeCompare(b.provider) || a.interaction.localeCompare(b.interaction));
101
+ const matrix = {
102
+ spec: AUDIT_MATRIX_SPEC,
103
+ rows,
104
+ counts: {
105
+ total: rows.length,
106
+ contracted: rows.filter((r) => r.contracted).length,
107
+ observed: rows.filter((r) => r.observed).length,
108
+ contracted_and_test_seen: rows.filter((r) => r.contracted && r.test_seen).length,
109
+ contracted_not_test_seen: rows.filter((r) => r.contracted && !r.test_seen).length,
110
+ test_or_prod_seen_not_contracted: rows.filter((r) => !r.contracted && (r.test_seen || r.prod_seen)).length,
111
+ test_seen: rows.filter((r) => r.test_seen).length,
112
+ prod_seen: rows.filter((r) => r.prod_seen).length,
113
+ provider_verified: rows.filter((r) => r.provider_verified).length,
114
+ broker_verified: rows.filter((r) => r.broker_verified).length
115
+ },
116
+ window_days: windowDays,
117
+ generated_at: now.toISOString()
118
+ };
119
+ if (verificationFailures.length > 0) matrix.verification_failures = verificationFailures;
120
+ return matrix;
355
121
  }
356
122
  async function runAudit(opts = {}) {
357
- const pactsDir = path.resolve(process.cwd(), opts.pactsDir ?? DEFAULT_PACTS_DIR);
358
- const contracted = [];
359
- const pairs = /* @__PURE__ */ new Set();
360
- for (const file of listPactFiles(pactsDir)) {
361
- const pact = parsePactFile(file);
362
- if (!pact) continue;
363
- const interactions = interactionsFromPactFile(pact);
364
- contracted.push(...interactions);
365
- const consumer = pact.consumer?.name;
366
- const provider = pact.provider?.name;
367
- if (consumer && provider) {
368
- pairs.add(pairKey(consumer, provider));
369
- }
370
- }
371
- const ledger = readLedger(opts);
372
- let brokerVerifications;
373
- if (opts.broker) {
374
- brokerVerifications = await fetchBrokerVerifications(opts.broker, [...pairs].map((p) => {
375
- const [consumer, provider] = p.split("::");
376
- return { consumer, provider };
377
- }));
378
- }
379
- return computeAuditMatrix({
380
- contracted,
381
- ledger,
382
- brokerVerifications,
383
- windowDays: opts.windowDays
384
- });
385
- }
123
+ const pactsDir = path.resolve(process.cwd(), opts.pactsDir ?? DEFAULT_PACTS_DIR);
124
+ const contracted = [];
125
+ const pairs = /* @__PURE__ */ new Set();
126
+ for (const file of listPactFiles(pactsDir)) {
127
+ const pact = parsePactFile(file);
128
+ if (!pact) continue;
129
+ const interactions = interactionsFromPactFile(pact);
130
+ contracted.push(...interactions);
131
+ const consumer = pact.consumer?.name;
132
+ const provider = pact.provider?.name;
133
+ if (consumer && provider) pairs.add(pairKey(consumer, provider));
134
+ }
135
+ const ledger = readLedger(opts);
136
+ let brokerVerifications;
137
+ if (opts.broker) brokerVerifications = await fetchBrokerVerifications(opts.broker, [...pairs].map((p) => {
138
+ const [consumer, provider] = p.split("::");
139
+ return {
140
+ consumer,
141
+ provider
142
+ };
143
+ }));
144
+ return computeAuditMatrix({
145
+ contracted,
146
+ ledger,
147
+ brokerVerifications,
148
+ windowDays: opts.windowDays
149
+ });
150
+ }
151
+ /** Sync audit without broker (backward compatible for tests). */
386
152
  function runAuditSync(opts = {}) {
387
- const pactsDir = path.resolve(process.cwd(), opts.pactsDir ?? DEFAULT_PACTS_DIR);
388
- const contracted = [];
389
- for (const file of listPactFiles(pactsDir)) {
390
- const pact = parsePactFile(file);
391
- if (pact) contracted.push(...interactionsFromPactFile(pact));
392
- }
393
- const ledger = readLedger(opts);
394
- return computeAuditMatrix({
395
- contracted,
396
- ledger,
397
- windowDays: opts.windowDays
398
- });
153
+ const pactsDir = path.resolve(process.cwd(), opts.pactsDir ?? DEFAULT_PACTS_DIR);
154
+ const contracted = [];
155
+ for (const file of listPactFiles(pactsDir)) {
156
+ const pact = parsePactFile(file);
157
+ if (pact) contracted.push(...interactionsFromPactFile(pact));
158
+ }
159
+ return computeAuditMatrix({
160
+ contracted,
161
+ ledger: readLedger(opts),
162
+ windowDays: opts.windowDays
163
+ });
399
164
  }
400
165
 
166
+ //#endregion
401
167
  export { computeAuditMatrix, keyOf, runAudit, runAuditSync };
402
- //# sourceMappingURL=audit.js.map
403
168
  //# sourceMappingURL=audit.js.map