autotel-schema 2.0.4 → 3.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 (37) hide show
  1. package/LICENSE +191 -21
  2. package/README.md +62 -3
  3. package/dist/contract-Ymh_Q37N.d.cts +305 -0
  4. package/dist/contract-Ymh_Q37N.d.cts.map +1 -0
  5. package/dist/contract-Ymh_Q37N.d.ts +305 -0
  6. package/dist/contract-Ymh_Q37N.d.ts.map +1 -0
  7. package/dist/{diff-D7qkNn0-.d.ts → diff-B1DoDhUn.d.ts} +2 -2
  8. package/dist/{diff-D7qkNn0-.d.ts.map → diff-B1DoDhUn.d.ts.map} +1 -1
  9. package/dist/{diff-BQPh72vY.d.cts → diff-Cjs6OPFN.d.cts} +2 -2
  10. package/dist/{diff-BQPh72vY.d.cts.map → diff-Cjs6OPFN.d.cts.map} +1 -1
  11. package/dist/diff.d.cts +1 -1
  12. package/dist/diff.d.ts +1 -1
  13. package/dist/index.cjs +8 -1
  14. package/dist/index.d.cts +4 -4
  15. package/dist/index.d.ts +4 -4
  16. package/dist/index.js +2 -2
  17. package/dist/processor-BPp_DewZ.js +635 -0
  18. package/dist/processor-BPp_DewZ.js.map +1 -0
  19. package/dist/{processor-CkBkzK6y.d.cts → processor-BsO4WD73.d.cts} +2 -2
  20. package/dist/{processor-CkBkzK6y.d.cts.map → processor-BsO4WD73.d.cts.map} +1 -1
  21. package/dist/{processor-CK7LAdaa.d.ts → processor-CIEfOOYi.d.ts} +2 -2
  22. package/dist/{processor-CK7LAdaa.d.ts.map → processor-CIEfOOYi.d.ts.map} +1 -1
  23. package/dist/processor-Gu8Yl_dS.cjs +737 -0
  24. package/dist/processor-Gu8Yl_dS.cjs.map +1 -0
  25. package/dist/processor.cjs +1 -1
  26. package/dist/processor.d.cts +1 -1
  27. package/dist/processor.d.ts +1 -1
  28. package/dist/processor.js +1 -1
  29. package/package.json +3 -3
  30. package/dist/contract-DGjxR9nb.d.cts +0 -123
  31. package/dist/contract-DGjxR9nb.d.cts.map +0 -1
  32. package/dist/contract-DGjxR9nb.d.ts +0 -123
  33. package/dist/contract-DGjxR9nb.d.ts.map +0 -1
  34. package/dist/processor-D93TAXvZ.cjs +0 -366
  35. package/dist/processor-D93TAXvZ.cjs.map +0 -1
  36. package/dist/processor-FmvKYllX.js +0 -306
  37. package/dist/processor-FmvKYllX.js.map +0 -1
package/LICENSE CHANGED
@@ -1,21 +1,191 @@
1
- MIT License
2
-
3
- Copyright (c) Jag Reehal 2025
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control with
17
+ that entity. For the purposes of this definition, "control" means (i) the
18
+ power, direct or indirect, to cause the direction or management of such
19
+ entity, whether by contract or otherwise, or (ii) ownership of fifty
20
+ percent (50%) or more of the outstanding shares, or (iii) beneficial
21
+ ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation source,
28
+ and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation
31
+ or translation of a Source form, including but not limited to compiled
32
+ object code, generated documentation, and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or Object form,
35
+ made available under the License, as indicated by a copyright notice that
36
+ is included in or attached to the work (an example is provided in the
37
+ Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object form,
40
+ that is based on (or derived from) the Work and for which the editorial
41
+ revisions, annotations, elaborations, or other modifications represent, as
42
+ a whole, an original work of authorship. For the purposes of this License,
43
+ Derivative Works shall not include works that remain separable from, or
44
+ merely link (or bind by name) to the interfaces of, the Work and Derivative
45
+ Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including the original
48
+ version of the Work and any modifications or additions to that Work or
49
+ Derivative Works thereof, that is intentionally submitted to Licensor for
50
+ inclusion in the Work by the copyright owner or by an individual or Legal
51
+ Entity authorized to submit on behalf of the copyright owner. For the
52
+ purposes of this definition, "submitted" means any form of electronic,
53
+ verbal, or written communication sent to the Licensor or its
54
+ representatives, including but not limited to communication on electronic
55
+ mailing lists, source code control systems, and issue tracking systems that
56
+ are managed by, or on behalf of, the Licensor for the purpose of discussing
57
+ and improving the Work, but excluding communication that is conspicuously
58
+ marked or otherwise designated in writing by the copyright owner as "Not a
59
+ Contribution."
60
+
61
+ "Contributor" shall mean Licensor and any individual or Legal Entity on
62
+ behalf of whom a Contribution has been received by Licensor and
63
+ subsequently incorporated within the Work.
64
+
65
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
66
+ License, each Contributor hereby grants to You a perpetual, worldwide,
67
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
68
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
69
+ sublicense, and distribute the Work and such Derivative Works in Source or
70
+ Object form.
71
+
72
+ 3. Grant of Patent License. Subject to the terms and conditions of this
73
+ License, each Contributor hereby grants to You a perpetual, worldwide,
74
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in
75
+ this section) patent license to make, have made, use, offer to sell, sell,
76
+ import, and otherwise transfer the Work, where such license applies only to
77
+ those patent claims licensable by such Contributor that are necessarily
78
+ infringed by their Contribution(s) alone or by combination of their
79
+ Contribution(s) with the Work to which such Contribution(s) was submitted.
80
+ If You institute patent litigation against any entity (including a
81
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
82
+ Contribution incorporated within the Work constitutes direct or
83
+ contributory patent infringement, then any patent licenses granted to You
84
+ under this License for that Work shall terminate as of the date such
85
+ litigation is filed.
86
+
87
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
88
+ Derivative Works thereof in any medium, with or without modifications, and
89
+ in Source or Object form, provided that You meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative Works
92
+ a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works that
98
+ You distribute, all copyright, patent, trademark, and attribution notices
99
+ from the Source form of the Work, excluding those notices that do not
100
+ pertain to any part of the Derivative Works; and
101
+
102
+ (d) If the Work includes a "NOTICE" text file as part of its
103
+ distribution, then any Derivative Works that You distribute must include a
104
+ readable copy of the attribution notices contained within such NOTICE file,
105
+ excluding those notices that do not pertain to any part of the Derivative
106
+ Works, in at least one of the following places: within a NOTICE text file
107
+ distributed as part of the Derivative Works; within the Source form or
108
+ documentation, if provided along with the Derivative Works; or, within a
109
+ display generated by the Derivative Works, if and wherever such third-party
110
+ notices normally appear. The contents of the NOTICE file are for
111
+ informational purposes only and do not modify the License. You may add Your
112
+ own attribution notices within Derivative Works that You distribute,
113
+ alongside or as an addendum to the NOTICE text from the Work, provided that
114
+ such additional attribution notices cannot be construed as modifying the
115
+ License.
116
+
117
+ You may add Your own copyright statement to Your modifications and may
118
+ provide additional or different license terms and conditions for use,
119
+ reproduction, or distribution of Your modifications, or for any such
120
+ Derivative Works as a whole, provided Your use, reproduction, and
121
+ distribution of the Work otherwise complies with the conditions stated in
122
+ this License.
123
+
124
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
125
+ Contribution intentionally submitted for inclusion in the Work by You to
126
+ the Licensor shall be under the terms and conditions of this License,
127
+ without any additional terms or conditions. Notwithstanding the above,
128
+ nothing herein shall supersede or modify the terms of any separate license
129
+ agreement you may have executed with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor, except
133
+ as required for reasonable and customary use in describing the origin of
134
+ the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to
137
+ in writing, Licensor provides the Work (and each Contributor provides its
138
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
139
+ KIND, either express or implied, including, without limitation, any
140
+ warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or
141
+ FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for
142
+ determining the appropriateness of using or redistributing the Work and
143
+ assume any risks associated with Your exercise of permissions under this
144
+ License.
145
+
146
+ 8. Limitation of Liability. In no event and under no legal theory, whether
147
+ in tort (including negligence), contract, or otherwise, unless required by
148
+ applicable law (such as deliberate and grossly negligent acts) or agreed to
149
+ in writing, shall any Contributor be liable to You for damages, including
150
+ any direct, indirect, special, incidental, or consequential damages of any
151
+ character arising as a result of this License or out of the use or
152
+ inability to use the Work (including but not limited to damages for loss of
153
+ goodwill, work stoppage, computer failure or malfunction, or any and all
154
+ other commercial damages or losses), even if such Contributor has been
155
+ advised of the possibility of such damages.
156
+
157
+ 9. Accepting Warranty or Additional Liability. While redistributing the
158
+ Work or Derivative Works thereof, You may choose to offer, and charge a fee
159
+ for, acceptance of support, warranty, indemnity, or other liability
160
+ obligations and/or rights consistent with this License. However, in
161
+ accepting such obligations, You may act only on Your own behalf and on Your
162
+ sole responsibility, not on behalf of any other Contributor, and only if
163
+ You agree to indemnify, defend, and hold each Contributor harmless for any
164
+ liability incurred by, or claims asserted against, such Contributor by
165
+ reason of your accepting any such warranty or additional liability.
166
+
167
+ END OF TERMS AND CONDITIONS
168
+
169
+ APPENDIX: How to apply the Apache License to your work.
170
+
171
+ To apply the Apache License to your work, attach the following boilerplate
172
+ notice, with the fields enclosed by brackets "[]" replaced with your own
173
+ identifying information. (Don't include the brackets!) The text should be
174
+ enclosed in the appropriate comment syntax for the file format. We also
175
+ recommend that a file or class name and description of purpose be included
176
+ on the same "printed page" as the copyright notice for easier
177
+ identification within third-party archives.
178
+
179
+ Copyright [yyyy] [name of copyright owner]
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
package/README.md CHANGED
@@ -121,11 +121,70 @@ init({
121
121
  });
122
122
  ```
123
123
 
124
+ ## 5. Scenario conformance: contract one exercised flow
125
+
126
+ Spans and attributes contract your telemetry *surface*. A **scenario** contracts the *behaviour* of one exercised flow: which events must fire, how many times, in what topology — and, for async flows, **when the observation is complete**, because without a completion boundary a missing event and an event that hasn't fired *yet* are indistinguishable.
127
+
128
+ ```ts
129
+ export const contract = defineContract({
130
+ service: 'transfer',
131
+ version: '1.3.0',
132
+ spans: { /* ... */ },
133
+ scenarios: {
134
+ 'transfer.accept': {
135
+ completion: { mode: 'terminal-event', event: 'transfer.queued', observationBudgetMs: 5000 },
136
+ events: {
137
+ 'transfer.request': { cardinality: 'exactly 1' },
138
+ 'transfer.validate': { cardinality: 'exactly 1' },
139
+ 'transfer.queued': { cardinality: 'exactly 1' },
140
+ 'transfer.retry': { cardinality: 'at most 3' },
141
+ },
142
+ edges: [['transfer.request', 'transfer.validate']], // ancestor→descendant, infra spans in between are fine
143
+ },
144
+ },
145
+ });
146
+ ```
147
+
148
+ Checking yields **three** outcomes, not two — infrastructure slowness is not reported as behavioural regression:
149
+
150
+ ```ts
151
+ import { checkScenario, formatScenarioResult } from 'autotel-schema';
152
+
153
+ const result = await checkScenario(
154
+ contract.scenarios!['transfer.accept'],
155
+ () => collector.peekTrace(traceId), // TestSpanCollector from autotel — or any ScenarioSpan[] source
156
+ { name: 'transfer.accept' },
157
+ );
158
+ // result.outcome:
159
+ // 'conformant' — boundary closed, signature satisfied
160
+ // 'non-conformant' — required behaviour missing or invalid (definitive)
161
+ // 'incomplete' — boundary didn't close within the observation budget
162
+ if (result.outcome !== 'conformant') throw new Error(formatScenarioResult(result));
163
+ ```
164
+
165
+ Semantics worth knowing:
166
+
167
+ - **Absence is definitive only after closure** (closed-world). Excess is definitive immediately: an unexpected error span or an exceeded `max` cardinality fails fast while the flow is still open.
168
+ - **Undeclared events are additive** — reported in `result.additions`, never a failure. Improving instrumentation must not break CI.
169
+ - **The observation budget bounds how long the checker waits.** It is not a business SLO — assert deadlines separately on `result.spans`.
170
+ - An `externally-reconciled` boundary never closes in-process: use it for phases verified by a deferred job keyed by a durable business ID.
171
+
172
+ Don't hand-write the first draft — record it:
173
+
174
+ ```ts
175
+ import { proposeScenario } from 'autotel-schema';
176
+
177
+ const { scenario, notes } = proposeScenario(runs); // runs: ScenarioSpan[][] from N controlled executions
178
+ // notes: 'transfer.validate: exactly 1 (20/20 runs)', 'notification.send: 0..1 (14/20 runs) — review: variable', ...
179
+ ```
180
+
181
+ Stable events become required cardinality, variable ones get ranges flagged for review, and the completion boundary + budget are suggested from observed timings. Review, trim, commit.
182
+
124
183
  ## What this is / isn't
125
184
 
126
- - **Is**: a contract for your telemetry surface: span names, attribute keys, types, enums, stability, and breaking-vs-additive evolution.
127
- - **Isn't**: a contract for application message payloads (use [`autotel-message-contract`](../autotel-message-contract)) or evidence that interactions ran (use [`autotel-pact`](../autotel-pact)). It does not require the OpenTelemetry SDK. The processor works against structural span types.
185
+ - **Is**: a contract for your telemetry surface: span names, attribute keys, types, enums, stability, and breaking-vs-additive evolution — and, per scenario, the behavioural signature of one exercised flow (events, cardinality, topology, completion).
186
+ - **Isn't**: a contract for application message payloads (use [`autotel-message-contract`](../autotel-message-contract)) or evidence that contracted interactions ran (use [`autotel-pact`](../autotel-pact)). It does not require the OpenTelemetry SDK. The processor works against structural span types.
128
187
 
129
188
  ## License
130
189
 
131
- MIT © Jag Reehal
190
+ Apache-2.0 © Jag Reehal
@@ -0,0 +1,305 @@
1
+ //#region src/scenario.d.ts
2
+ /**
3
+ * Scenario conformance — a flow-level contract checked against collected spans.
4
+ *
5
+ * Where {@link ./contract} declares the *surface* of your telemetry (span
6
+ * names + attributes), a scenario declares the *behaviour* of one exercised
7
+ * flow: which events must fire, how many times, in what parent/child
8
+ * topology, and — critically — **when the observation is complete**, because
9
+ * for an async flow a missing event and an event that has not fired *yet* are
10
+ * indistinguishable without a completion boundary.
11
+ *
12
+ * Checking a scenario yields one of three outcomes, not two:
13
+ *
14
+ * - `conformant` — the boundary closed and the signature satisfied the contract
15
+ * - `non-conformant` — required behaviour was missing or invalid (definitive)
16
+ * - `incomplete` — the boundary did not close within the observation budget;
17
+ * infrastructure slowness is *not* reported as behavioural regression
18
+ *
19
+ * Absence is definitive only after closure (closed-world semantics). Excess
20
+ * is definitive immediately: a `max` cardinality violation or an unexpected
21
+ * error span fails the check even while the flow is still open.
22
+ *
23
+ * Undeclared events are **additive**: reported in `result.additions`, never a
24
+ * failure — improving instrumentation must not break CI.
25
+ *
26
+ * The span input shape is structurally compatible with `SerializedSpan` from
27
+ * `autotel/test-span-collector`, so a test can feed a collector's output
28
+ * straight in. Like the rest of this package the module is dependency-free —
29
+ * usable from vitest, a deferred reconciliation job, or a CLI alike.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const result = await checkScenario(
34
+ * contract.scenarios!['transfer.accept'],
35
+ * () => collector.peekTrace(traceId),
36
+ * { name: 'transfer.accept' },
37
+ * );
38
+ * if (result.outcome === 'non-conformant') throw new Error(formatScenarioResult(result));
39
+ * ```
40
+ */
41
+ /** A finished span/event as the scenario checker sees it. */
42
+ interface ScenarioSpan {
43
+ spanId: string;
44
+ parentSpanId?: string;
45
+ name: string;
46
+ status: 'ok' | 'error' | 'unset';
47
+ attributes?: Record<string, unknown>;
48
+ /** Epoch ms. Optional — used by {@link proposeScenario} to suggest budgets. */
49
+ startTimeMs?: number;
50
+ durationMs?: number;
51
+ }
52
+ /** Canonical cardinality range. `max` omitted = unbounded. */
53
+ interface Cardinality {
54
+ min: number;
55
+ max?: number;
56
+ }
57
+ /**
58
+ * Parse a cardinality shorthand: `'exactly 1'`, `'at least 1'`, `'at most 3'`,
59
+ * `'0..1'`, `'2..'`. A canonical {@link Cardinality} passes through.
60
+ */
61
+ declare function parseCardinality(input: string | Cardinality): Cardinality;
62
+ /** Declaration for one event (span name) a scenario expects to observe. */
63
+ interface ScenarioEventSpec {
64
+ /** How many occurrences are permitted. Defaults to `'at least 1'`. */
65
+ cardinality?: string | Cardinality;
66
+ /**
67
+ * Expected terminal status. Defaults to non-error: an `error` status on an
68
+ * event not declared `status: 'error'` is a definitive violation.
69
+ */
70
+ status?: 'ok' | 'error';
71
+ description?: string;
72
+ }
73
+ /**
74
+ * How the observed phase of a scenario becomes complete. Every async
75
+ * conformance check must declare this — it is what makes absence meaningful.
76
+ *
77
+ * `externally-reconciled` never closes in-process: the phase is verified
78
+ * elsewhere (a deferred reconciliation job keyed by a durable business ID),
79
+ * so an in-process check reports at most definitive violations, never absence.
80
+ */
81
+ type CompletionBoundary = {
82
+ mode: 'root-span-closed';
83
+ observationBudgetMs: number;
84
+ } | {
85
+ mode: 'terminal-event';
86
+ event: string;
87
+ observationBudgetMs: number;
88
+ } | {
89
+ mode: 'externally-reconciled';
90
+ reconciliationDeadlineMs: number;
91
+ };
92
+ /** The flow-level contract for one exercised scenario (or one phase of one). */
93
+ interface ScenarioSpec {
94
+ description?: string;
95
+ /** When the observed phase is complete. See {@link CompletionBoundary}. */
96
+ completion: CompletionBoundary;
97
+ /** Events this scenario must (or may) observe, keyed by span name. */
98
+ events: Record<string, ScenarioEventSpec>;
99
+ /**
100
+ * Required ancestor→descendant edges by span name. Ancestor — not immediate
101
+ * parent — so a framework span inserted between the two does not break the
102
+ * contract (canonicalisation: infrastructure spans are not behaviour).
103
+ */
104
+ edges?: ReadonlyArray<readonly [string, string]>;
105
+ /** Edges that may appear but are not required. Documented, never enforced. */
106
+ optionalEdges?: ReadonlyArray<readonly [string, string]>;
107
+ }
108
+ type ScenarioOutcome = 'conformant' | 'non-conformant' | 'incomplete';
109
+ type ScenarioViolationCode = 'missing_event' | 'cardinality_violation' | 'missing_edge' | 'unexpected_error';
110
+ /** A definitive (breaking) discrepancy between observed spans and the scenario. */
111
+ interface ScenarioViolation {
112
+ code: ScenarioViolationCode;
113
+ event?: string;
114
+ edge?: readonly [string, string];
115
+ message: string;
116
+ }
117
+ /** An additive observation — reported, never a failure. */
118
+ interface ScenarioAddition {
119
+ code: 'undeclared_event';
120
+ event: string;
121
+ count: number;
122
+ message: string;
123
+ }
124
+ interface ScenarioResult {
125
+ scenario: string;
126
+ outcome: ScenarioOutcome;
127
+ /** Whether the completion boundary closed within the observation window. */
128
+ closed: boolean;
129
+ violations: ScenarioViolation[];
130
+ additions: ScenarioAddition[];
131
+ /** The evaluated snapshot — assert business values on this in your test. */
132
+ spans: ScenarioSpan[];
133
+ }
134
+ /**
135
+ * Structural validation for one scenario declaration. Called by
136
+ * `defineContract()` so a malformed scenario throws at module load.
137
+ */
138
+ declare function validateScenarioSpec(name: string, spec: ScenarioSpec): void;
139
+ /** Whether the scenario's completion boundary has closed for these spans. */
140
+ declare function isScenarioClosed(spec: ScenarioSpec, spans: readonly ScenarioSpan[]): boolean;
141
+ interface EvaluateScenarioOptions {
142
+ /** Name used in the result/messages. Defaults to `'scenario'`. */
143
+ name?: string;
144
+ /** Override closure detection (e.g. the poller already knows). */
145
+ closed?: boolean;
146
+ }
147
+ /**
148
+ * Pure three-state evaluation of collected spans against a scenario.
149
+ *
150
+ * Definitive at any time (no closure needed): an unexpected error status, a
151
+ * `max` cardinality exceeded. Meaningful only after closure: a missing event,
152
+ * a `min` cardinality not reached, a missing required edge.
153
+ */
154
+ declare function evaluateScenario(spec: ScenarioSpec, spans: readonly ScenarioSpan[], options?: EvaluateScenarioOptions): ScenarioResult;
155
+ interface CheckScenarioOptions {
156
+ /** Name used in the result/messages. Defaults to `'scenario'`. */
157
+ name?: string;
158
+ /** Poll interval while waiting for closure. Default 25ms. */
159
+ pollIntervalMs?: number;
160
+ /** Override the boundary's observation budget (how long the checker waits). */
161
+ budgetMs?: number;
162
+ }
163
+ /**
164
+ * Poll `getSpans` until the scenario's completion boundary closes, a
165
+ * definitive violation appears (fail fast), or the observation budget is
166
+ * spent — then evaluate.
167
+ *
168
+ * The observation budget bounds how long *this checker* waits; it is not a
169
+ * statement that the operation is allowed to take that long. Express a
170
+ * business deadline as its own assertion on the returned spans.
171
+ *
172
+ * An `externally-reconciled` boundary never closes in-process: the check
173
+ * evaluates the current snapshot once and reports `incomplete` unless a
174
+ * definitive violation is already present.
175
+ */
176
+ declare function checkScenario(spec: ScenarioSpec, getSpans: () => readonly ScenarioSpan[] | Promise<readonly ScenarioSpan[]>, options?: CheckScenarioOptions): Promise<ScenarioResult>;
177
+ /** Human-readable summary of a scenario result, for assertion messages. */
178
+ declare function formatScenarioResult(result: ScenarioResult): string;
179
+ interface ScenarioProposal {
180
+ scenario: ScenarioSpec;
181
+ /** Review annotations — what was observed and what to double-check. */
182
+ notes: string[];
183
+ }
184
+ /**
185
+ * Draft a scenario contract from repeated controlled runs (record → propose →
186
+ * commit). Events stable across every run become required with their observed
187
+ * cardinality; variable ones get a range and a review note. The draft is a
188
+ * starting point for human curation, not a finished contract.
189
+ */
190
+ declare function proposeScenario(runs: ReadonlyArray<ReadonlyArray<ScenarioSpan>>, options?: {
191
+ name?: string;
192
+ }): ScenarioProposal;
193
+ //#endregion
194
+ //#region src/contract.d.ts
195
+ /** Scalar and array attribute types permitted on a span (OTLP value shapes). */
196
+ type AttributeType = 'string' | 'number' | 'boolean' | 'string[]' | 'number[]' | 'boolean[]';
197
+ declare const ATTRIBUTE_TYPES: readonly AttributeType[];
198
+ /**
199
+ * Lifecycle of a span or attribute, mirroring how the OpenTelemetry semantic
200
+ * conventions stage their own surface. `stable` is a promise to agent readers
201
+ * that the name will not change without a major contract bump.
202
+ */
203
+ type Stability = 'stable' | 'experimental' | 'deprecated';
204
+ declare const STABILITIES: readonly Stability[];
205
+ /** Declaration for a single attribute key on a span. */
206
+ interface AttributeSpec {
207
+ /** OTLP value shape. Validated at runtime against the emitted value. */
208
+ type: AttributeType;
209
+ /** Lifecycle stage. Defaults to `stable`. */
210
+ stability?: Stability;
211
+ /** When `true`, the attribute must be present on every matching span. */
212
+ required?: boolean;
213
+ /** Human/agent-facing description of what the attribute means. */
214
+ description?: string;
215
+ /**
216
+ * Marks an attribute as intentionally high-cardinality (user id, sender
217
+ * domain, request id). For an agent reader these are the single most useful
218
+ * fields on a trace, so {@link ./redaction.highCardinalityKeys} surfaces them
219
+ * as a *protect* list — telling redactors/normalizers NOT to strip them.
220
+ */
221
+ highCardinality?: boolean;
222
+ /** Closed set of permitted values. Reported as `enum_violation` if exceeded. */
223
+ enum?: readonly (string | number)[];
224
+ /** Set when `stability: 'deprecated'`; explains what to use instead. */
225
+ replacedBy?: string;
226
+ /** Free-text note shown alongside deprecation warnings. */
227
+ deprecatedReason?: string;
228
+ }
229
+ /** Declaration for a single span name your service emits. */
230
+ interface SpanSpec {
231
+ /** Human/agent-facing description of when this span is produced. */
232
+ description?: string;
233
+ /** Lifecycle stage. Defaults to `stable`. */
234
+ stability?: Stability;
235
+ /** Attributes specific to this span, keyed by attribute name. */
236
+ attributes?: Record<string, AttributeSpec>;
237
+ /**
238
+ * When `true`, attributes not declared here are allowed without an
239
+ * `unknown_attribute` violation. Defaults to the contract-level setting.
240
+ */
241
+ additionalAttributes?: boolean;
242
+ }
243
+ /** The full telemetry contract for one service. */
244
+ interface TelemetryContract {
245
+ /** `service.name` this contract describes. */
246
+ service: string;
247
+ /**
248
+ * Semver of the *contract itself* (not the app). Bumped when the trace
249
+ * surface changes; surfaced to readers as the `telemetry.schema.version`
250
+ * resource attribute via {@link ./attrs.SCHEMA_ATTRS}.
251
+ */
252
+ version: string;
253
+ /** Spans this service emits, keyed by span name. */
254
+ spans: Record<string, SpanSpec>;
255
+ /** Attributes permitted on *any* span (e.g. `user.id`, `tenant.id`). */
256
+ commonAttributes?: Record<string, AttributeSpec>;
257
+ /**
258
+ * Default for `SpanSpec.additionalAttributes` when a span does not set it.
259
+ * Defaults to `false` (declared-only — the stricter, agent-friendlier mode).
260
+ */
261
+ additionalAttributes?: boolean;
262
+ /**
263
+ * Flow-level scenario contracts, keyed by scenario name: which events one
264
+ * exercised flow must emit, their cardinality and topology, and when the
265
+ * observation is complete. Checked with `checkScenario` ({@link ./scenario}).
266
+ */
267
+ scenarios?: Record<string, ScenarioSpec>;
268
+ }
269
+ /**
270
+ * Validate and freeze a telemetry contract. Throws on structural mistakes
271
+ * (bad semver, unknown attribute type, deprecation with no replacement) so the
272
+ * contract fails loudly at module load, not silently at runtime.
273
+ *
274
+ * @example
275
+ * ```ts
276
+ * export const contract = defineContract({
277
+ * service: 'checkout',
278
+ * version: '1.2.0',
279
+ * commonAttributes: {
280
+ * 'user.id': { type: 'string', highCardinality: true, description: 'Authenticated user' },
281
+ * },
282
+ * spans: {
283
+ * 'checkout.charge': {
284
+ * description: 'Charge a payment method',
285
+ * attributes: {
286
+ * 'payment.provider': { type: 'string', required: true, enum: ['stripe', 'paypal'] },
287
+ * 'payment.amount_cents': { type: 'number', required: true },
288
+ * },
289
+ * },
290
+ * },
291
+ * });
292
+ * ```
293
+ */
294
+ declare function defineContract(contract: TelemetryContract): TelemetryContract;
295
+ /**
296
+ * Resolve the effective attribute spec for `key` on `spanName`: span-specific
297
+ * attributes win over common attributes. Returns `undefined` when the key is
298
+ * declared nowhere.
299
+ */
300
+ declare function resolveAttributeSpec(contract: TelemetryContract, spanName: string, key: string): AttributeSpec | undefined;
301
+ /** Whether attributes outside the declared set are tolerated for a span. */
302
+ declare function allowsAdditionalAttributes(contract: TelemetryContract, spanName: string): boolean;
303
+ //#endregion
304
+ export { validateScenarioSpec as A, ScenarioViolationCode as C, isScenarioClosed as D, formatScenarioResult as E, parseCardinality as O, ScenarioViolation as S, evaluateScenario as T, ScenarioOutcome as _, SpanSpec as a, ScenarioSpan as b, allowsAdditionalAttributes as c, Cardinality as d, CheckScenarioOptions as f, ScenarioEventSpec as g, ScenarioAddition as h, STABILITIES as i, proposeScenario as k, defineContract as l, EvaluateScenarioOptions as m, AttributeSpec as n, Stability as o, CompletionBoundary as p, AttributeType as r, TelemetryContract as s, ATTRIBUTE_TYPES as t, resolveAttributeSpec as u, ScenarioProposal as v, checkScenario as w, ScenarioSpec as x, ScenarioResult as y };
305
+ //# sourceMappingURL=contract-Ymh_Q37N.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-Ymh_Q37N.d.cts","names":[],"sources":["../src/scenario.ts","../src/contract.ts"],"mappings":";;AAyCA;;;;;;;;;;;;;AAQY;AAIZ;;;;AAEK;AAOL;;;;;;;;AAA0E;AAgC1E;;;;;;;;;AAQa;AAWb;AAAA,UAxEiB,YAAA;EACf,MAAA;EACA,YAAA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