@systemfsoftware/trace-spec 0.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @systemfsoftware/trace-spec
2
+
3
+ ## 0.0.0
4
+
5
+ ### Minor Changes
6
+
7
+ - New package: hold a behaviour to the trace it produced. `Contract.of(taxonomy).stimulate(stimulus).holds(relation)` composes a spec; `Contract.judge(contract, input)` runs the behaviour under a trace id it mints, decodes the finished trace against the taxonomy, and answers the verdict with the dump path of a break; `Contract.check` fails a break with `Contract.TraceDisparityError`. `Graph.decode` is pure, answering `Result<TraceGraph, ContractDecodeError>`.
8
+
9
+ `ObservationWindow.make(serviceName)` is the in-memory observation resource: `.scoped` acquires a window handle read with `ObservationWindow.collect`, and `.layer` provides `Observation | OtelTracer.OtelTracer`, one window per acquisition. `Suite.make({ it, layer })` registers a `Case` per input or a `Case.prop` per Schema, shrinking through `it.effect.prop` to one dump of the minimal failing input.
package/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+ Copyright (c) 2026 Ryan Lee (systemfsoftware)
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright 2026 Ryan Lee (systemfsoftware)
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # @systemfsoftware/trace-spec
2
+
3
+ Hold a behaviour to the trace it produced.
4
+
5
+ In a system with queues, workers, and background consumers, a `200` is not the observable output of a behaviour: the response can arrive before the work fails, and the failure lands in a later span nobody is watching. The completed trace is the observable output. This package runs a behaviour under a trace id it owns, reads the finished trace back, decodes it against a declared taxonomy, and answers with a relation that holds or breaks.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ pnpm add @systemfsoftware/trace-spec @systemfsoftware/trace-taxonomy effect
11
+ ```
12
+
13
+ The package exports seven namespaces — `Contract`, `Graph`, `Observation`, `ObservationWindow`, `Rel`, `Stimulus`, `Suite`. Errors and verdicts belong to the capability that raises them: `Contract.ContractDecodeError`, `Contract.TraceDisparityError`, `Observation.EmptyObservationError`, `Suite.StimulusFailure`, and `Rel.Hold`/`Rel.Break`/`Rel.Verdict`.
14
+
15
+ ## Write a contract
16
+
17
+ A stimulus is the behaviour under test made callable: `stimulus(input)` runs it under a trace id the contract owns, injecting the matching `traceparent`. A relation is the judgement made callable: `relation(graph)` answers a verdict.
18
+
19
+ ```ts
20
+ import { Contract, Rel, Stimulus } from '@systemfsoftware/trace-spec'
21
+ import { checkout, PaymentCapture, PlaceOrder } from './checkout.schema.js'
22
+
23
+ const placeOrder = Stimulus.make({
24
+ name: 'checkout.place',
25
+ run: ({ input, traceparent }) => client.place(input, { traceparent }),
26
+ })
27
+
28
+ const paymentUnderCheckout = Contract.of(checkout)
29
+ .stimulate(placeOrder)
30
+ .holds(Rel.all(
31
+ Rel.exists(PlaceOrder),
32
+ Rel.child(PlaceOrder, PaymentCapture),
33
+ Rel.attrs(PlaceOrder, { 'app.order.items.count': 1 }),
34
+ ))
35
+ ```
36
+
37
+ `Contract.of(taxonomy)` takes the identity first; `Contract.stimulate` and `Contract.holds` are `dual` combinators on Pipeable stages, so the same builder composes in a pipe — `Contract.of(checkout).pipe(Contract.stimulate(placeOrder), Contract.holds(relation))` — and the stage types refuse an out-of-order builder.
38
+
39
+ ## Run the contract
40
+
41
+ `Contract.judge(contract, input)` stimulates the behaviour under its minted trace, collects that trace's spans, decodes them against the taxonomy (`Graph.decode` answers `Result<TraceGraph, Contract.ContractDecodeError>`), applies the relation, and on a break writes the decoded graph under `artifacts/traces/`. It answers a `Contract.Judgment` — the run, the verdict, and the dump path — so a break is a value, not a failure. Behaviour failures and infrastructure refusals (`Contract.ContractDecodeError`, `Observation.EmptyObservationError`) stay on the error channel.
42
+
43
+ `Contract.check(contract, input)` is the test edge over `judge`: a break fails with `Contract.TraceDisparityError`. Navigation over the decoded graph is standalone: `Graph.byId`, `Graph.children`, and `Graph.descendants`.
44
+
45
+ | Outcome | Failure | Meaning |
46
+ | --------------------------------------------- | ----------------------------------- | --------------------------------------------------------------------------------------- |
47
+ | The relation broke | `Contract.TraceDisparityError` | names the broken conjunct, the spans inspected, and where the decoded graph was written |
48
+ | A contracted span lacked a required attribute | `Contract.ContractDecodeError` | names the declaration and the attribute — never reported as a broken relation |
49
+ | Nothing ran under the owned trace | `Observation.EmptyObservationError` | the observation was empty, which is its own outcome, not a break |
50
+
51
+ ## Register cases
52
+
53
+ ```ts
54
+ import { NodeFileSystem } from '@effect/platform-node'
55
+ import { it, layer } from '@effect/vitest'
56
+ import { Observation, ObservationWindow, Suite } from '@systemfsoftware/trace-spec'
57
+ import { Layer } from 'effect'
58
+
59
+ const TraceSuite = Suite.make({ it, layer })
60
+ const harness = Layer.mergeAll(ObservationWindow.make('checkout').layer, NodeFileSystem.layer, CheckoutDoubles)
61
+
62
+ TraceSuite('checkout.place_order')
63
+ .withScenarioLayer(harness)
64
+ .body(({ Case }) => {
65
+ Case('one item is paid for under the order', paymentUnderCheckout, { userId, items: 1 })
66
+ })
67
+ ```
68
+
69
+ `Suite.make({ it, layer })(name)` stages a suite as a Pipeable builder, and `withLayer`/`withScenarioLayer` are `dual` combinators whose terminal `body` registers the cases. The scenario layer is built fresh per case and must provide `Observation.Observation` and a `FileSystem` for failure dumps, plus whatever the stimulated behaviour needs — the requirement is enforced at the type level. A failing case fails with the harness's own error channel — the three outcomes above, or `Suite.StimulusFailure` when the behaviour itself failed before its trace could be judged. Cases run on the live clock.
70
+
71
+ `.withLayer(shared)` registers the suite over a layer built once for the whole suite; the shared layer then carries the observation harness, and `.withScenarioLayer(scenario)` can follow it for what each case needs fresh.
72
+
73
+ `Case.prop(title, contract, schema)` runs the contract over inputs drawn from the Schema's derived arbitrary through `it.effect.prop` on the suite's runner, so shrinking is the runner's own: a failing draw fails the property and the runner reports the smallest failing input. The dump is named after the case title, so every failing draw overwrites one file and the surviving dump is the reported counterexample's evidence. When a case fails with a `Contract.TraceDisparityError`, the test carries a Vitest annotation naming that dump, so the decoded graph is found from the failing test.
74
+
75
+ ## Observe in memory
76
+
77
+ `ObservationWindow.make(serviceName)` is the cold resource; the service name is required. `.scoped` acquires an `ObservationWindow` handle for one scope — an OpenTelemetry in-memory exporter behind a simple span processor and an always-on sampler, shut down when the scope closes — and `ObservationWindow.collect(window, traceId)` reads one trace back. `.layer` binds a window as `Observation.Observation` plus the Effect tracer, one window per layer build, so two acquisitions never see each other's spans. Only the handle module imports the OpenTelemetry SDK. The export happens outside any test-clock boundary.
78
+
79
+ ## Relations
80
+
81
+ `Rel.exists`, `Rel.absent`, `Rel.unique`, `Rel.child`, `Rel.descendant`, `Rel.status`, `Rel.errorType`, `Rel.attrs`, `Rel.durationLessThan`, `Rel.forall`, `Rel.event`, `Rel.order`, `Rel.any`, `Rel.not`, `Rel.soft`, `Rel.all`, `Rel.fromTaxonomy`.
82
+
83
+ A relation is callable: `relation(graph)` answers a `Rel.Verdict` — `Rel.Hold` or `Rel.Break` — carrying the conjunct and the span ids it inspected, so the failure output names what broke without a debugger.
84
+
85
+ `Rel.forall(spec, predicate, detail)` holds when the span was emitted and every node satisfies the predicate; `Rel.event(spec, name)` when every node carries that event; `Rel.order(before, after)` when every `after` span starts at or after some `before` span. All three break when no matching span was emitted. `Rel.any(...relations)` holds when one conjunct holds and names every conjunct when none does; `Rel.not(relation)` holds when its inner relation breaks. `any` and `not` are never soft.
86
+
87
+ `Rel.fromTaxonomy(taxonomy, { path })` turns the taxonomy itself into a relation: every declared edge must place each child span under a matching parent (directly for `child`, anywhere above for `descendant`), and every forbidden span must be absent unless its `unless` tag names the given path. Edges constrain placement, not existence — pair it with `Rel.exists` for the spans a scenario requires.
88
+
89
+ `Rel.all` evaluates hard conjuncts in order and stops at the first hard break; soft conjuncts are all evaluated and reported together. `exists` and `absent` are never soft — a spec cannot go green while the span it is about is missing. `Rel.soft` marks a relation soft when it is softenable at all.
90
+
91
+ ## Assert the graph, not the tool
92
+
93
+ Span names and attributes come from [`@systemfsoftware/trace-taxonomy`](../trace-taxonomy) declarations, so no spec mentions a raw span name. A renamed span or a new required attribute is a compile error at the declaration's start call sites, not a silently green suite.
@@ -0,0 +1,344 @@
1
+ import { Context, Effect, FileSystem, Layer, Result, Schema } from "effect";
2
+ import { Pipeable } from "effect/Pipeable";
3
+ import { Span, Taxonomy } from "@systemfsoftware/trace-taxonomy";
4
+ import * as OtelTracer from "@effect/opentelemetry/OtelTracer";
5
+ import { BasicTracerProvider, InMemorySpanExporter } from "@opentelemetry/sdk-trace-base";
6
+ import { Suite } from "@systemfsoftware/effect-spec-runtime";
7
+ import * as Scope from "effect/Scope";
8
+ import * as Arbitrary from "effect/unstable/arbitrary/Arbitrary";
9
+ //#region src/ContractDecodeError.schema.d.ts
10
+ declare const ContractDecodeError_base: Schema.Class<ContractDecodeError, Schema.TaggedStruct<"ContractDecodeError", {
11
+ readonly declarationId: Schema.String;
12
+ readonly spanName: Schema.String;
13
+ readonly spanId: Schema.String;
14
+ readonly attribute: Schema.String;
15
+ readonly detail: Schema.String;
16
+ }>, import("effect/Cause").YieldableError>;
17
+ declare class ContractDecodeError extends ContractDecodeError_base {}
18
+ //#endregion
19
+ //#region src/EmptyObservationError.schema.d.ts
20
+ declare const EmptyObservationError_base: Schema.Class<EmptyObservationError, Schema.TaggedStruct<"EmptyObservationError", {
21
+ readonly traceId: Schema.String;
22
+ readonly detail: Schema.String;
23
+ }>, import("effect/Cause").YieldableError>;
24
+ declare class EmptyObservationError extends EmptyObservationError_base {}
25
+ //#endregion
26
+ //#region src/TraceGraph.schema.d.ts
27
+ declare const Status: Schema.Literals<readonly ["ok", "unset", "error"]>;
28
+ type Status = typeof Status.Type;
29
+ declare const AttributeValue: Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean]>>]>;
30
+ type AttributeValue = typeof AttributeValue.Type;
31
+ declare const Attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean]>>]>>;
32
+ type Attributes = typeof Attributes.Type;
33
+ declare const SpanEvent: Schema.Struct<{
34
+ readonly name: Schema.String;
35
+ readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean]>>]>>;
36
+ }>;
37
+ type SpanEvent = typeof SpanEvent.Type;
38
+ declare const SpanLink: Schema.Struct<{
39
+ readonly traceId: Schema.String;
40
+ readonly spanId: Schema.String;
41
+ }>;
42
+ type SpanLink = typeof SpanLink.Type;
43
+ declare const SpanRecord: Schema.Struct<{
44
+ readonly traceId: Schema.String;
45
+ readonly spanId: Schema.String;
46
+ readonly parentSpanId: Schema.NullOr<Schema.String>;
47
+ readonly name: Schema.String;
48
+ readonly status: Schema.Literals<readonly ["ok", "unset", "error"]>;
49
+ readonly errorType: Schema.NullOr<Schema.String>;
50
+ readonly startMillis: Schema.Finite;
51
+ readonly durationMillis: Schema.Finite;
52
+ readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean]>>]>>;
53
+ readonly events: Schema.$Array<Schema.Struct<{
54
+ readonly name: Schema.String;
55
+ readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean]>>]>>;
56
+ }>>;
57
+ readonly links: Schema.$Array<Schema.Struct<{
58
+ readonly traceId: Schema.String;
59
+ readonly spanId: Schema.String;
60
+ }>>;
61
+ }>;
62
+ type SpanRecord = typeof SpanRecord.Type;
63
+ declare const GraphNode: Schema.Struct<{
64
+ readonly spanId: Schema.String;
65
+ readonly parentSpanId: Schema.NullOr<Schema.String>;
66
+ readonly name: Schema.String;
67
+ readonly status: Schema.Literals<readonly ["ok", "unset", "error"]>;
68
+ readonly errorType: Schema.NullOr<Schema.String>;
69
+ readonly startMillis: Schema.Finite;
70
+ readonly durationMillis: Schema.Finite;
71
+ readonly attrs: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean]>>]>>;
72
+ readonly events: Schema.$Array<Schema.Struct<{
73
+ readonly name: Schema.String;
74
+ readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean]>>]>>;
75
+ }>>;
76
+ readonly links: Schema.$Array<Schema.Struct<{
77
+ readonly traceId: Schema.String;
78
+ readonly spanId: Schema.String;
79
+ }>>;
80
+ }>;
81
+ type GraphNode = typeof GraphNode.Type;
82
+ declare const TraceGraph: Schema.Struct<{
83
+ readonly traceId: Schema.String;
84
+ readonly nodes: Schema.$Array<Schema.Struct<{
85
+ readonly spanId: Schema.String;
86
+ readonly parentSpanId: Schema.NullOr<Schema.String>;
87
+ readonly name: Schema.String;
88
+ readonly status: Schema.Literals<readonly ["ok", "unset", "error"]>;
89
+ readonly errorType: Schema.NullOr<Schema.String>;
90
+ readonly startMillis: Schema.Finite;
91
+ readonly durationMillis: Schema.Finite;
92
+ readonly attrs: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean]>>]>>;
93
+ readonly events: Schema.$Array<Schema.Struct<{
94
+ readonly name: Schema.String;
95
+ readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean]>>]>>;
96
+ }>>;
97
+ readonly links: Schema.$Array<Schema.Struct<{
98
+ readonly traceId: Schema.String;
99
+ readonly spanId: Schema.String;
100
+ }>>;
101
+ }>>;
102
+ }>;
103
+ type TraceGraph = typeof TraceGraph.Type;
104
+ declare namespace Graph_d_exports {
105
+ export { AttributeValue, Attributes, GraphNode, SpanEvent, SpanLink, SpanRecord, Status, TraceGraph, byId, children, decode, descendants };
106
+ }
107
+ declare const byId: (graph: TraceGraph, spec: Span.Span) => ReadonlyArray<GraphNode>;
108
+ declare const children: (graph: TraceGraph, node: GraphNode) => ReadonlyArray<GraphNode>;
109
+ declare const descendants: (graph: TraceGraph, node: GraphNode) => ReadonlyArray<GraphNode>;
110
+ /**
111
+ * Decodes the recorded spans of one trace against a taxonomy, purely: a declared span
112
+ * whose required attributes do not decode refuses with {@link ContractDecodeError}
113
+ * naming the declaration and the attribute, and a span no declaration accounts for enters
114
+ * the graph as recorded. Failure is a `Result`, so the phase that reads the trace cannot
115
+ * fail the pipeline by accident.
116
+ */
117
+ declare const decode: (traceId: string, spans: ReadonlyArray<SpanRecord>, taxonomy: Taxonomy.Taxonomy) => Result.Result<TraceGraph, ContractDecodeError>;
118
+ declare namespace Observation_service_d_exports {
119
+ export { Collector, EmptyObservationError, Observation };
120
+ }
121
+ interface Collector {
122
+ readonly collect: (traceId: string) => Effect.Effect<ReadonlyArray<SpanRecord>, EmptyObservationError>;
123
+ }
124
+ declare const Observation_base: Context.ServiceClass<Observation, "@systemfsoftware/trace-spec/Observation", Collector>;
125
+ declare class Observation extends Observation_base {}
126
+ //#endregion
127
+ //#region src/Verdict.schema.d.ts
128
+ declare const VerdictTypeId: unique symbol;
129
+ type VerdictTypeId = typeof VerdictTypeId;
130
+ declare const Hold_base: Schema.Class<Hold, Schema.TaggedStruct<"Hold", {
131
+ readonly conjunct: Schema.String;
132
+ readonly inspected: Schema.$Array<Schema.String>;
133
+ }>, {}>;
134
+ declare class Hold extends Hold_base {
135
+ readonly [VerdictTypeId]: symbol;
136
+ }
137
+ declare const Break_base: Schema.Class<Break, Schema.TaggedStruct<"Break", {
138
+ readonly conjunct: Schema.String;
139
+ readonly inspected: Schema.$Array<Schema.String>;
140
+ readonly detail: Schema.String;
141
+ }>, {}>;
142
+ declare class Break extends Break_base {
143
+ readonly [VerdictTypeId]: symbol;
144
+ }
145
+ declare const Verdict: Schema.Union<readonly [typeof Hold, typeof Break]>;
146
+ type Verdict = typeof Verdict.Type;
147
+ declare namespace Rel_d_exports {
148
+ export { Break, Hold, Relation, Verdict, absent, all, any, attrs, child, descendant, durationLessThan, errorType, event, exists, forall, fromTaxonomy, not, order, soft, status, unique };
149
+ }
150
+ interface Relation {
151
+ readonly id: string;
152
+ readonly soft: boolean;
153
+ readonly softenable: boolean;
154
+ (graph: TraceGraph): Verdict;
155
+ }
156
+ declare const exists: <S extends Span.Span>(spec: S) => Relation;
157
+ declare const absent: <S extends Span.Span>(spec: S) => Relation;
158
+ declare const unique: <S extends Span.Span>(spec: S) => Relation;
159
+ declare const child: (parent: Span.Span, childSpan: Span.Span) => Relation;
160
+ declare const descendant: (parent: Span.Span, childSpan: Span.Span) => Relation;
161
+ declare const order: (before: Span.Span, after: Span.Span) => Relation;
162
+ declare const status: (spec: Span.Span, expected: Status) => Relation;
163
+ declare const errorType: (spec: Span.Span, expected: string) => Relation;
164
+ declare const attrs: <S extends Span.Span>(spec: S, partial: Partial<Span.AttrsOf<S>>) => Relation;
165
+ declare const durationLessThan: (spec: Span.Span, millis: number) => Relation;
166
+ declare const event: (spec: Span.Span, name: string) => Relation;
167
+ declare const forall: (spec: Span.Span, predicate: (node: GraphNode) => boolean, detail: string) => Relation;
168
+ declare const soft: (self: Relation) => Relation;
169
+ declare const not: (self: Relation) => Relation;
170
+ declare const all: (...relations: ReadonlyArray<Relation>) => Relation;
171
+ declare const any: (...relations: ReadonlyArray<Relation>) => Relation;
172
+ declare const fromTaxonomy: (taxonomy: Taxonomy.Taxonomy, options: {
173
+ readonly path: string;
174
+ }) => Relation;
175
+ declare namespace Stimulus_d_exports {
176
+ export { Run, Stimulus, TraceContext, make$3 as make, traceContext };
177
+ }
178
+ interface TraceContext {
179
+ readonly traceId: string;
180
+ readonly spanId: string;
181
+ readonly traceparent: string;
182
+ }
183
+ declare const traceContext: Effect.Effect<TraceContext>;
184
+ interface Run<Input, Output> {
185
+ readonly input: Input;
186
+ readonly traceId: string;
187
+ readonly output: Output;
188
+ }
189
+ interface Stimulus<Input, Output, E, R> {
190
+ readonly name: string;
191
+ (input: Input): Effect.Effect<Run<Input, Output>, E, R>;
192
+ }
193
+ declare const make$3: <Input, Output, E, R>(options: {
194
+ readonly name: string;
195
+ readonly run: (context: {
196
+ readonly input: Input;
197
+ readonly traceId: string;
198
+ readonly traceparent: string;
199
+ }) => Effect.Effect<Output, E, R>;
200
+ }) => Stimulus<Input, Output, E, R>;
201
+ //#endregion
202
+ //#region src/TraceDisparityError.schema.d.ts
203
+ declare const TraceDisparityError_base: Schema.Class<TraceDisparityError, Schema.TaggedStruct<"TraceDisparityError", {
204
+ readonly relationId: Schema.String;
205
+ readonly traceId: Schema.String;
206
+ readonly breaks: Schema.$Array<typeof Break>;
207
+ readonly dumpPath: Schema.NullOr<Schema.String>;
208
+ }>, import("effect/Cause").YieldableError>;
209
+ declare class TraceDisparityError extends TraceDisparityError_base {}
210
+ declare namespace Contract_d_exports {
211
+ export { CheckFailure, CheckOptions, Contract, ContractDecodeError, Declared$1 as Declared, EmptyObservationError, JudgeFailure, Judgment, Services, Stimulated, TraceDisparityError, TypeId$3 as TypeId, check, holds, judge, of, stimulate };
212
+ }
213
+ declare const TypeId$3: unique symbol;
214
+ type TypeId$3 = typeof TypeId$3;
215
+ interface Declared$1 extends Pipeable {
216
+ readonly [TypeId$3]: typeof TypeId$3;
217
+ readonly taxonomy: Taxonomy.Taxonomy;
218
+ readonly stimulate: <Input, Output, E, R>(stimulus: Stimulus<Input, Output, E, R>) => Stimulated<Input, Output, E, R>;
219
+ }
220
+ interface Stimulated<Input, Output, E, R> extends Pipeable {
221
+ readonly [TypeId$3]: typeof TypeId$3;
222
+ readonly taxonomy: Taxonomy.Taxonomy;
223
+ readonly stimulus: Stimulus<Input, Output, E, R>;
224
+ readonly holds: (relation: Relation) => Contract<Input, Output, E, R>;
225
+ }
226
+ interface Contract<Input, Output, E, R> extends Pipeable {
227
+ readonly [TypeId$3]: typeof TypeId$3;
228
+ readonly taxonomy: Taxonomy.Taxonomy;
229
+ readonly stimulus: Stimulus<Input, Output, E, R>;
230
+ readonly relation: Relation;
231
+ }
232
+ declare const of: (taxonomy: Taxonomy.Taxonomy) => Declared$1;
233
+ declare const stimulate: {
234
+ <Input, Output, E, R>(stimulus: Stimulus<Input, Output, E, R>): (self: Declared$1) => Stimulated<Input, Output, E, R>;
235
+ <Input, Output, E, R>(self: Declared$1, stimulus: Stimulus<Input, Output, E, R>): Stimulated<Input, Output, E, R>;
236
+ };
237
+ declare const holds: {
238
+ (relation: Relation): <Input, Output, E, R>(self: Stimulated<Input, Output, E, R>) => Contract<Input, Output, E, R>;
239
+ <Input, Output, E, R>(self: Stimulated<Input, Output, E, R>, relation: Relation): Contract<Input, Output, E, R>;
240
+ };
241
+ interface Judgment<Input, Output> {
242
+ readonly run: Run<Input, Output>;
243
+ readonly verdict: Verdict;
244
+ readonly dumpPath: string | null;
245
+ }
246
+ interface CheckOptions {
247
+ readonly dumpName?: string | undefined;
248
+ }
249
+ type JudgeFailure<E> = E | ContractDecodeError | EmptyObservationError;
250
+ type CheckFailure<E> = JudgeFailure<E> | TraceDisparityError;
251
+ type Services<R> = R | Observation | FileSystem.FileSystem;
252
+ declare const judge: {
253
+ <Input>(input: Input, options?: CheckOptions): <Output, E, R>(self: Contract<Input, Output, E, R>) => Effect.Effect<Judgment<Input, Output>, JudgeFailure<E>, Services<R>>;
254
+ <Input, Output, E, R>(self: Contract<Input, Output, E, R>, input: Input, options?: CheckOptions): Effect.Effect<Judgment<Input, Output>, JudgeFailure<E>, Services<R>>;
255
+ };
256
+ declare const check: {
257
+ <Input>(input: Input, options?: CheckOptions): <Output, E, R>(self: Contract<Input, Output, E, R>) => Effect.Effect<Judgment<Input, Output>, CheckFailure<E>, Services<R>>;
258
+ <Input, Output, E, R>(self: Contract<Input, Output, E, R>, input: Input, options?: CheckOptions): Effect.Effect<Judgment<Input, Output>, CheckFailure<E>, Services<R>>;
259
+ };
260
+ //#endregion
261
+ //#region src/ObservationWindowSpec.schema.d.ts
262
+ declare const ObservationWindowSpec_base: Schema.Class<ObservationWindowSpec, Schema.Struct<{
263
+ readonly serviceName: Schema.NonEmptyString;
264
+ }>, {}>;
265
+ declare class ObservationWindowSpec extends ObservationWindowSpec_base {}
266
+ declare namespace observation_window_handle_d_exports {
267
+ export { ObservationWindow, TypeId$2 as TypeId, collect, context, isObservationWindow, make$2 as make, shutdown };
268
+ }
269
+ declare const TypeId$2: unique symbol;
270
+ type TypeId$2 = typeof TypeId$2;
271
+ declare const ExporterId: unique symbol;
272
+ declare const ProviderId: unique symbol;
273
+ interface ObservationWindow extends Pipeable {
274
+ readonly [TypeId$2]: typeof TypeId$2;
275
+ readonly [ExporterId]: InMemorySpanExporter;
276
+ readonly [ProviderId]: BasicTracerProvider;
277
+ readonly serviceName: string;
278
+ }
279
+ declare const isObservationWindow: (u: unknown) => u is ObservationWindow;
280
+ declare const make$2: (spec: ObservationWindowSpec) => ObservationWindow;
281
+ declare const shutdown: (self: ObservationWindow) => Effect.Effect<void>;
282
+ declare const collect: {
283
+ (traceId: string): (self: ObservationWindow) => Effect.Effect<ReadonlyArray<SpanRecord>, EmptyObservationError>;
284
+ (self: ObservationWindow, traceId: string): Effect.Effect<ReadonlyArray<SpanRecord>, EmptyObservationError>;
285
+ };
286
+ declare const context: (self: ObservationWindow) => Context.Context<Observation | OtelTracer.OtelTracerProvider>;
287
+ declare namespace observation_window_resource_d_exports {
288
+ export { ObservationWindow, ObservationWindowResource, ObservationWindowSpec, TypeId$2 as ObservationWindowTypeId, TypeId$1 as TypeId, collect, isObservationWindow, make$1 as make };
289
+ }
290
+ declare const TypeId$1: unique symbol;
291
+ type TypeId$1 = typeof TypeId$1;
292
+ interface ObservationWindowResource extends Pipeable {
293
+ readonly [TypeId$1]: typeof TypeId$1;
294
+ readonly spec: ObservationWindowSpec;
295
+ readonly scoped: Effect.Effect<ObservationWindow, never, Scope.Scope>;
296
+ readonly layer: Layer.Layer<Observation | OtelTracer.OtelTracer>;
297
+ }
298
+ declare const make$1: (serviceName: string) => ObservationWindowResource;
299
+ //#endregion
300
+ //#region src/StimulusFailure.schema.d.ts
301
+ declare const StimulusFailure_base: Schema.Class<StimulusFailure, Schema.TaggedStruct<"StimulusFailure", {
302
+ readonly stimulus: Schema.String;
303
+ readonly detail: Schema.String;
304
+ }>, import("effect/Cause").YieldableError>;
305
+ declare class StimulusFailure extends StimulusFailure_base {}
306
+ declare namespace Suite_d_exports {
307
+ export { ArbitraryInput, CaseFailure, CaseRegistrar, CaseTools, Declared, Harness, Opened, Shared, StimulusFailure, TypeId, make, withLayer, withScenarioLayer };
308
+ }
309
+ declare const TypeId: unique symbol;
310
+ type TypeId = typeof TypeId;
311
+ type CaseFailure = ContractDecodeError | EmptyObservationError | TraceDisparityError | StimulusFailure;
312
+ type Harness = Observation | FileSystem.FileSystem;
313
+ type ArbitraryInput<Input> = Schema.Schema<Input> | Arbitrary.Arbitrary<Input>;
314
+ interface CaseRegistrar<Provided> {
315
+ <Input, Output, E>(name: string, contract: Contract<Input, Output, E, Provided>, input: Input): void;
316
+ prop: <Input, Output, E>(name: string, contract: Contract<Input, Output, E, Provided>, arbitrary: ArbitraryInput<Input>) => void;
317
+ }
318
+ interface CaseTools<Provided> {
319
+ readonly Case: CaseRegistrar<Provided>;
320
+ }
321
+ interface Opened<Provided> {
322
+ readonly body: (use: (tools: CaseTools<Provided>) => void) => void;
323
+ }
324
+ interface Declared extends Pipeable {
325
+ readonly [TypeId]: typeof TypeId;
326
+ readonly withLayer: <SharedProvided>(shared: Layer.Layer<SharedProvided | Harness>) => Shared<SharedProvided>;
327
+ readonly withScenarioLayer: <Provided>(scenario: Layer.Layer<Provided | Harness>) => Opened<Provided | Harness>;
328
+ }
329
+ interface Shared<SharedProvided> extends Pipeable {
330
+ readonly [TypeId]: typeof TypeId;
331
+ readonly withScenarioLayer: <Provided>(scenario: Layer.Layer<Provided | Harness, never, SharedProvided>) => Opened<Provided | SharedProvided>;
332
+ readonly body: (use: (tools: CaseTools<SharedProvided>) => void) => void;
333
+ }
334
+ declare const withLayer: {
335
+ <SharedProvided>(shared: Layer.Layer<SharedProvided | Harness>): (self: Declared) => Shared<SharedProvided>;
336
+ <SharedProvided>(self: Declared, shared: Layer.Layer<SharedProvided | Harness>): Shared<SharedProvided>;
337
+ };
338
+ declare const withScenarioLayer: {
339
+ <Provided>(scenario: Layer.Layer<Provided | Harness>): (self: Declared) => Opened<Provided | Harness>;
340
+ <Provided>(self: Declared, scenario: Layer.Layer<Provided | Harness>): Opened<Provided | Harness>;
341
+ };
342
+ declare const make: (bindings: Suite.Bindings) => (name: string) => Declared;
343
+ //#endregion
344
+ export { Contract_d_exports as Contract, Graph_d_exports as Graph, Observation_service_d_exports as Observation, observation_window_resource_d_exports as ObservationWindow, Rel_d_exports as Rel, Stimulus_d_exports as Stimulus, Suite_d_exports as Suite };