@ontrails/core 1.0.0-beta.2 → 1.0.0-beta.21
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 +283 -5
- package/README.md +113 -33
- package/package.json +11 -1
- package/src/activation-provenance.ts +111 -0
- package/src/activation-source-compatibility.ts +430 -0
- package/src/activation-source-projection.ts +221 -0
- package/src/activation-source.ts +91 -0
- package/src/blob-ref.ts +51 -0
- package/src/branded.ts +1 -1
- package/src/compose-batch.ts +69 -0
- package/src/compose-schema.ts +36 -0
- package/src/context.ts +44 -10
- package/src/contour.ts +346 -0
- package/src/derive.ts +59 -18
- package/src/detours.ts +8 -0
- package/src/draft.ts +342 -0
- package/src/error-projection.ts +51 -0
- package/src/errors.ts +309 -48
- package/src/execute.ts +1577 -0
- package/src/fire.ts +1169 -0
- package/src/index.ts +477 -32
- package/src/internal/fork-ctx.ts +69 -0
- package/src/layer-projection.ts +193 -0
- package/src/layer.ts +43 -6
- package/src/observe.ts +361 -0
- package/src/path-security.ts +1 -1
- package/src/permits.ts +12 -0
- package/src/redaction/patterns.ts +6 -3
- package/src/resilience.ts +11 -11
- package/src/resource-config.ts +792 -0
- package/src/resource.ts +194 -0
- package/src/result.ts +36 -4
- package/src/run.ts +76 -0
- package/src/schedule-runtime.ts +689 -0
- package/src/schedule.ts +326 -0
- package/src/serialization.ts +119 -39
- package/src/signal-diagnostics.ts +633 -0
- package/src/signal-ref.ts +87 -0
- package/src/signal.ts +104 -0
- package/src/store/accessor-protocol.ts +56 -0
- package/src/store/index.ts +4 -0
- package/src/structured-examples.ts +248 -0
- package/src/surface-derivation.ts +91 -0
- package/src/surface-filter.ts +176 -0
- package/src/surface-versioning.ts +42 -0
- package/src/topo.ts +769 -57
- package/src/tracing.ts +345 -0
- package/src/trail.ts +1161 -29
- package/src/trails/derive-trail.ts +842 -0
- package/src/trails/index.ts +9 -0
- package/src/trails/ingest.ts +139 -0
- package/src/trails-db.ts +208 -0
- package/src/transport-error-map.ts +174 -0
- package/src/type-utils.ts +87 -0
- package/src/types.ts +254 -12
- package/src/validate-established-topo.ts +69 -0
- package/src/validate-topo.ts +442 -35
- package/src/validation.ts +152 -4
- package/src/version-marker.ts +716 -0
- package/src/version-resolution.ts +308 -0
- package/src/version-runtime.ts +120 -0
- package/src/webhook.ts +278 -0
- package/src/workspace.ts +1 -1
- package/src/zod-wrappers.ts +72 -0
- package/.turbo/turbo-build.log +0 -1
- package/.turbo/turbo-lint.log +0 -3
- package/.turbo/turbo-typecheck.log +0 -1
- package/dist/adapters.d.ts +0 -39
- package/dist/adapters.d.ts.map +0 -1
- package/dist/adapters.js +0 -2
- package/dist/adapters.js.map +0 -1
- package/dist/blob-ref.d.ts +0 -20
- package/dist/blob-ref.d.ts.map +0 -1
- package/dist/blob-ref.js +0 -22
- package/dist/blob-ref.js.map +0 -1
- package/dist/branded.d.ts +0 -36
- package/dist/branded.d.ts.map +0 -1
- package/dist/branded.js +0 -89
- package/dist/branded.js.map +0 -1
- package/dist/collections.d.ts +0 -31
- package/dist/collections.d.ts.map +0 -1
- package/dist/collections.js +0 -60
- package/dist/collections.js.map +0 -1
- package/dist/context.d.ts +0 -10
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -15
- package/dist/context.js.map +0 -1
- package/dist/derive.d.ts +0 -33
- package/dist/derive.d.ts.map +0 -1
- package/dist/derive.js +0 -122
- package/dist/derive.js.map +0 -1
- package/dist/errors.d.ts +0 -83
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -142
- package/dist/errors.js.map +0 -1
- package/dist/event.d.ts +0 -45
- package/dist/event.d.ts.map +0 -1
- package/dist/event.js +0 -17
- package/dist/event.js.map +0 -1
- package/dist/fetch.d.ts +0 -15
- package/dist/fetch.d.ts.map +0 -1
- package/dist/fetch.js +0 -102
- package/dist/fetch.js.map +0 -1
- package/dist/guards.d.ts +0 -17
- package/dist/guards.d.ts.map +0 -1
- package/dist/guards.js +0 -25
- package/dist/guards.js.map +0 -1
- package/dist/health.d.ts +0 -18
- package/dist/health.d.ts.map +0 -1
- package/dist/health.js +0 -5
- package/dist/health.js.map +0 -1
- package/dist/hike.d.ts +0 -36
- package/dist/hike.d.ts.map +0 -1
- package/dist/hike.js +0 -20
- package/dist/hike.js.map +0 -1
- package/dist/index.d.ts +0 -34
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -38
- package/dist/index.js.map +0 -1
- package/dist/job.d.ts +0 -24
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -17
- package/dist/job.js.map +0 -1
- package/dist/layer.d.ts +0 -17
- package/dist/layer.d.ts.map +0 -1
- package/dist/layer.js +0 -21
- package/dist/layer.js.map +0 -1
- package/dist/path-security.d.ts +0 -28
- package/dist/path-security.d.ts.map +0 -1
- package/dist/path-security.js +0 -63
- package/dist/path-security.js.map +0 -1
- package/dist/patterns/bulk.d.ts +0 -15
- package/dist/patterns/bulk.d.ts.map +0 -1
- package/dist/patterns/bulk.js +0 -14
- package/dist/patterns/bulk.js.map +0 -1
- package/dist/patterns/change.d.ts +0 -10
- package/dist/patterns/change.d.ts.map +0 -1
- package/dist/patterns/change.js +0 -10
- package/dist/patterns/change.js.map +0 -1
- package/dist/patterns/date-range.d.ts +0 -10
- package/dist/patterns/date-range.d.ts.map +0 -1
- package/dist/patterns/date-range.js +0 -10
- package/dist/patterns/date-range.js.map +0 -1
- package/dist/patterns/index.d.ts +0 -9
- package/dist/patterns/index.d.ts.map +0 -1
- package/dist/patterns/index.js +0 -9
- package/dist/patterns/index.js.map +0 -1
- package/dist/patterns/pagination.d.ts +0 -18
- package/dist/patterns/pagination.d.ts.map +0 -1
- package/dist/patterns/pagination.js +0 -18
- package/dist/patterns/pagination.js.map +0 -1
- package/dist/patterns/progress.d.ts +0 -11
- package/dist/patterns/progress.d.ts.map +0 -1
- package/dist/patterns/progress.js +0 -11
- package/dist/patterns/progress.js.map +0 -1
- package/dist/patterns/sorting.d.ts +0 -13
- package/dist/patterns/sorting.d.ts.map +0 -1
- package/dist/patterns/sorting.js +0 -10
- package/dist/patterns/sorting.js.map +0 -1
- package/dist/patterns/status.d.ts +0 -15
- package/dist/patterns/status.d.ts.map +0 -1
- package/dist/patterns/status.js +0 -9
- package/dist/patterns/status.js.map +0 -1
- package/dist/patterns/timestamps.d.ts +0 -10
- package/dist/patterns/timestamps.d.ts.map +0 -1
- package/dist/patterns/timestamps.js +0 -10
- package/dist/patterns/timestamps.js.map +0 -1
- package/dist/redaction/index.d.ts +0 -4
- package/dist/redaction/index.d.ts.map +0 -1
- package/dist/redaction/index.js +0 -3
- package/dist/redaction/index.js.map +0 -1
- package/dist/redaction/patterns.d.ts +0 -9
- package/dist/redaction/patterns.d.ts.map +0 -1
- package/dist/redaction/patterns.js +0 -39
- package/dist/redaction/patterns.js.map +0 -1
- package/dist/redaction/redactor.d.ts +0 -27
- package/dist/redaction/redactor.d.ts.map +0 -1
- package/dist/redaction/redactor.js +0 -89
- package/dist/redaction/redactor.js.map +0 -1
- package/dist/resilience.d.ts +0 -34
- package/dist/resilience.d.ts.map +0 -1
- package/dist/resilience.js +0 -164
- package/dist/resilience.js.map +0 -1
- package/dist/result.d.ts +0 -57
- package/dist/result.d.ts.map +0 -1
- package/dist/result.js +0 -145
- package/dist/result.js.map +0 -1
- package/dist/serialization.d.ts +0 -27
- package/dist/serialization.d.ts.map +0 -1
- package/dist/serialization.js +0 -115
- package/dist/serialization.js.map +0 -1
- package/dist/topo.d.ts +0 -18
- package/dist/topo.d.ts.map +0 -1
- package/dist/topo.js +0 -74
- package/dist/topo.js.map +0 -1
- package/dist/trail.d.ts +0 -83
- package/dist/trail.d.ts.map +0 -1
- package/dist/trail.js +0 -16
- package/dist/trail.js.map +0 -1
- package/dist/types.d.ts +0 -46
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/validate-topo.d.ts +0 -24
- package/dist/validate-topo.d.ts.map +0 -1
- package/dist/validate-topo.js +0 -108
- package/dist/validate-topo.js.map +0 -1
- package/dist/validation.d.ts +0 -27
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -134
- package/dist/validation.js.map +0 -1
- package/dist/workspace.d.ts +0 -25
- package/dist/workspace.d.ts.map +0 -1
- package/dist/workspace.js +0 -57
- package/dist/workspace.js.map +0 -1
- package/src/__tests__/blob-ref.test.ts +0 -103
- package/src/__tests__/branded.test.ts +0 -148
- package/src/__tests__/collections.test.ts +0 -126
- package/src/__tests__/context.test.ts +0 -66
- package/src/__tests__/derive.test.ts +0 -159
- package/src/__tests__/errors.test.ts +0 -309
- package/src/__tests__/event.test.ts +0 -82
- package/src/__tests__/fetch.test.ts +0 -217
- package/src/__tests__/guards.test.ts +0 -102
- package/src/__tests__/hike.test.ts +0 -117
- package/src/__tests__/job.test.ts +0 -98
- package/src/__tests__/layer.test.ts +0 -224
- package/src/__tests__/path-security.test.ts +0 -114
- package/src/__tests__/patterns.test.ts +0 -273
- package/src/__tests__/redaction.test.ts +0 -244
- package/src/__tests__/resilience.test.ts +0 -246
- package/src/__tests__/result.test.ts +0 -155
- package/src/__tests__/serialization.test.ts +0 -236
- package/src/__tests__/topo.test.ts +0 -184
- package/src/__tests__/trail.test.ts +0 -179
- package/src/__tests__/validate-topo.test.ts +0 -201
- package/src/__tests__/validation.test.ts +0 -283
- package/src/__tests__/workspace.test.ts +0 -183
- package/src/adapters.ts +0 -68
- package/src/event.ts +0 -77
- package/src/health.ts +0 -23
- package/src/hike.ts +0 -77
- package/src/job.ts +0 -20
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
package/src/validate-topo.ts
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Structural validation for a Topo graph.
|
|
3
3
|
*
|
|
4
|
-
* Checks
|
|
5
|
-
* references, and output schema completeness. Returns
|
|
6
|
-
* issues collected into a single ValidationError.
|
|
4
|
+
* Checks trail composing references, example input validity, signal origin
|
|
5
|
+
* references, activation source kinds, and output schema completeness. Returns
|
|
6
|
+
* a Result with all issues collected into a single ValidationError.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import type { ActivationSchemaIssue } from './activation-source-compatibility.js';
|
|
10
|
+
import { getActivationSourceInputCompatibilityIssues } from './activation-source-compatibility.js';
|
|
11
|
+
import {
|
|
12
|
+
activationSourceDeclarationSignature,
|
|
13
|
+
activationSourceKey,
|
|
14
|
+
} from './activation-source-projection.js';
|
|
15
|
+
import type { AnyContour } from './contour.js';
|
|
16
|
+
import { getContourReferences } from './contour.js';
|
|
9
17
|
import { ValidationError } from './errors.js';
|
|
10
|
-
import type {
|
|
11
|
-
import
|
|
18
|
+
import type { ActivationEntry } from './activation-source.js';
|
|
19
|
+
import { isKnownActivationSourceKind } from './activation-source.js';
|
|
20
|
+
import { isDraftId } from './draft.js';
|
|
21
|
+
import type { AnySignal } from './signal.js';
|
|
22
|
+
import { validateScheduleSource } from './schedule.js';
|
|
12
23
|
import { Result } from './result.js';
|
|
13
24
|
import type { Topo } from './topo.js';
|
|
14
|
-
import type { AnyTrail } from './trail.js';
|
|
25
|
+
import type { AnyTrail, TrailVersionForkEntry } from './trail.js';
|
|
26
|
+
import {
|
|
27
|
+
getTrailVersionEntryKind,
|
|
28
|
+
isArchivedTrailVersionEntry,
|
|
29
|
+
} from './trail.js';
|
|
15
30
|
import { validateInput } from './validation.js';
|
|
31
|
+
import { validateWebhookSource } from './webhook.js';
|
|
16
32
|
|
|
17
33
|
// ---------------------------------------------------------------------------
|
|
18
34
|
// Issue shape
|
|
@@ -22,34 +38,191 @@ export interface TopoIssue {
|
|
|
22
38
|
readonly trailId: string;
|
|
23
39
|
readonly rule: string;
|
|
24
40
|
readonly message: string;
|
|
41
|
+
readonly inputPath?: readonly (string | number)[];
|
|
42
|
+
readonly schemaIssues?: readonly TopoSchemaIssue[];
|
|
43
|
+
readonly sourceId?: string;
|
|
44
|
+
readonly sourceKind?: string;
|
|
25
45
|
}
|
|
26
46
|
|
|
47
|
+
export type TopoSchemaIssue = ActivationSchemaIssue;
|
|
48
|
+
|
|
27
49
|
// ---------------------------------------------------------------------------
|
|
28
50
|
// Validators
|
|
29
51
|
// ---------------------------------------------------------------------------
|
|
30
52
|
|
|
31
|
-
const
|
|
32
|
-
|
|
53
|
+
const WHITE = 0;
|
|
54
|
+
const GRAY = 1;
|
|
55
|
+
const BLACK = 2;
|
|
56
|
+
|
|
57
|
+
/** Build an adjacency list and initial color map from trails with compositions. */
|
|
58
|
+
const buildComposeGraph = (
|
|
59
|
+
trails: ReadonlyMap<string, AnyTrail>
|
|
60
|
+
): {
|
|
61
|
+
graph: Map<string, readonly string[]>;
|
|
62
|
+
color: Map<string, number>;
|
|
63
|
+
} => {
|
|
64
|
+
const graph = new Map<string, readonly string[]>();
|
|
65
|
+
for (const [id, trail] of trails) {
|
|
66
|
+
const composedIds = new Set<string>(trail.composes);
|
|
67
|
+
for (const entry of Object.values(trail.versions ?? {})) {
|
|
68
|
+
if (
|
|
69
|
+
isArchivedTrailVersionEntry(entry) ||
|
|
70
|
+
getTrailVersionEntryKind(entry) !== 'fork'
|
|
71
|
+
) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const fork = entry as TrailVersionForkEntry;
|
|
76
|
+
for (const composed of fork.composes ?? []) {
|
|
77
|
+
composedIds.add(typeof composed === 'string' ? composed : composed.id);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (composedIds.size > 0) {
|
|
82
|
+
graph.set(id, [...composedIds]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const color = new Map<string, number>();
|
|
86
|
+
for (const id of graph.keys()) {
|
|
87
|
+
color.set(id, WHITE);
|
|
88
|
+
}
|
|
89
|
+
return { color, graph };
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/** Detect multi-node cycles in the trail composing graph via DFS. */
|
|
93
|
+
const detectComposeCycles = (
|
|
94
|
+
trails: ReadonlyMap<string, AnyTrail>
|
|
95
|
+
): TopoIssue[] => {
|
|
96
|
+
const issues: TopoIssue[] = [];
|
|
97
|
+
const { color, graph } = buildComposeGraph(trails);
|
|
98
|
+
|
|
99
|
+
const dfs = (node: string, path: string[]): void => {
|
|
100
|
+
color.set(node, GRAY);
|
|
101
|
+
for (const next of graph.get(node) ?? []) {
|
|
102
|
+
if (!graph.has(next)) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const c = color.get(next) ?? WHITE;
|
|
106
|
+
if (c === GRAY) {
|
|
107
|
+
const cycle = [...path.slice(path.indexOf(next)), next];
|
|
108
|
+
issues.push({
|
|
109
|
+
message: `Cycle detected: ${cycle.join(' → ')}`,
|
|
110
|
+
rule: 'compose-cycle',
|
|
111
|
+
trailId: next,
|
|
112
|
+
});
|
|
113
|
+
} else if (c === WHITE) {
|
|
114
|
+
dfs(next, [...path, next]);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
color.set(node, BLACK);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
for (const id of graph.keys()) {
|
|
121
|
+
if (color.get(id) === WHITE) {
|
|
122
|
+
dfs(id, [id]);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return issues;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const checkComposes = (
|
|
129
|
+
trails: ReadonlyMap<string, AnyTrail>,
|
|
33
130
|
topo: Topo
|
|
34
131
|
): TopoIssue[] => {
|
|
35
132
|
const issues: TopoIssue[] = [];
|
|
36
|
-
for (const [id,
|
|
37
|
-
for (const
|
|
38
|
-
if (
|
|
133
|
+
for (const [id, trail] of trails) {
|
|
134
|
+
for (const composedId of trail.composes) {
|
|
135
|
+
if (composedId === id) {
|
|
39
136
|
issues.push({
|
|
40
|
-
message: `
|
|
41
|
-
rule: 'no-self-
|
|
137
|
+
message: `Trail composes itself`,
|
|
138
|
+
rule: 'no-self-compose',
|
|
42
139
|
trailId: id,
|
|
43
140
|
});
|
|
44
|
-
} else if (!topo.has(
|
|
141
|
+
} else if (!topo.has(composedId) && !isDraftId(composedId)) {
|
|
45
142
|
issues.push({
|
|
46
|
-
message: `
|
|
47
|
-
rule: '
|
|
143
|
+
message: `Composes "${composedId}" which is not in the topo`,
|
|
144
|
+
rule: 'compose-exists',
|
|
48
145
|
trailId: id,
|
|
49
146
|
});
|
|
50
147
|
}
|
|
51
148
|
}
|
|
149
|
+
for (const [rawVersion, entry] of Object.entries(trail.versions ?? {})) {
|
|
150
|
+
if (
|
|
151
|
+
isArchivedTrailVersionEntry(entry) ||
|
|
152
|
+
getTrailVersionEntryKind(entry) !== 'fork'
|
|
153
|
+
) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const version = Number(rawVersion);
|
|
158
|
+
const fork = entry as TrailVersionForkEntry;
|
|
159
|
+
for (const composed of fork.composes ?? []) {
|
|
160
|
+
const composedId =
|
|
161
|
+
typeof composed === 'string' ? composed : composed.id;
|
|
162
|
+
if (composedId === id) {
|
|
163
|
+
issues.push({
|
|
164
|
+
message: `Trail version ${version} composes itself`,
|
|
165
|
+
rule: 'no-self-compose',
|
|
166
|
+
trailId: id,
|
|
167
|
+
});
|
|
168
|
+
} else if (!topo.has(composedId) && !isDraftId(composedId)) {
|
|
169
|
+
issues.push({
|
|
170
|
+
message: `Version ${version} composes "${composedId}" which is not in the topo`,
|
|
171
|
+
rule: 'compose-exists',
|
|
172
|
+
trailId: id,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
52
177
|
}
|
|
178
|
+
issues.push(...detectComposeCycles(trails));
|
|
179
|
+
return issues;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const checkResources = (
|
|
183
|
+
trails: ReadonlyMap<string, AnyTrail>,
|
|
184
|
+
topo: Topo
|
|
185
|
+
): TopoIssue[] => {
|
|
186
|
+
const issues: TopoIssue[] = [];
|
|
187
|
+
|
|
188
|
+
for (const [id, trail] of trails) {
|
|
189
|
+
for (const declaredResource of trail.resources) {
|
|
190
|
+
if (
|
|
191
|
+
!topo.hasResource(declaredResource.id) &&
|
|
192
|
+
!isDraftId(declaredResource.id)
|
|
193
|
+
) {
|
|
194
|
+
issues.push({
|
|
195
|
+
message: `Resource "${declaredResource.id}" is not in the topo`,
|
|
196
|
+
rule: 'resource-exists',
|
|
197
|
+
trailId: id,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
for (const [rawVersion, entry] of Object.entries(trail.versions ?? {})) {
|
|
202
|
+
if (
|
|
203
|
+
isArchivedTrailVersionEntry(entry) ||
|
|
204
|
+
getTrailVersionEntryKind(entry) !== 'fork'
|
|
205
|
+
) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const version = Number(rawVersion);
|
|
210
|
+
const fork = entry as TrailVersionForkEntry;
|
|
211
|
+
for (const declaredResource of fork.resources ?? []) {
|
|
212
|
+
if (
|
|
213
|
+
!topo.hasResource(declaredResource.id) &&
|
|
214
|
+
!isDraftId(declaredResource.id)
|
|
215
|
+
) {
|
|
216
|
+
issues.push({
|
|
217
|
+
message: `Version ${version} resource "${declaredResource.id}" is not in the topo`,
|
|
218
|
+
rule: 'resource-exists',
|
|
219
|
+
trailId: id,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
53
226
|
return issues;
|
|
54
227
|
};
|
|
55
228
|
|
|
@@ -62,20 +235,21 @@ const checkOneExample = (
|
|
|
62
235
|
error?: string | undefined;
|
|
63
236
|
},
|
|
64
237
|
inputSchema: { safeParse: (data: unknown) => { success: boolean } },
|
|
65
|
-
hasOutput: boolean
|
|
238
|
+
hasOutput: boolean,
|
|
239
|
+
label = `Example "${example.name}"`
|
|
66
240
|
): TopoIssue[] => {
|
|
67
241
|
const issues: TopoIssue[] = [];
|
|
68
242
|
const result = validateInput(inputSchema as AnyTrail['input'], example.input);
|
|
69
|
-
if (result.isErr() && example.error
|
|
243
|
+
if (result.isErr() && example.error !== 'ValidationError') {
|
|
70
244
|
issues.push({
|
|
71
|
-
message:
|
|
245
|
+
message: `${label} input does not parse against schema`,
|
|
72
246
|
rule: 'example-input-valid',
|
|
73
247
|
trailId: id,
|
|
74
248
|
});
|
|
75
249
|
}
|
|
76
250
|
if (example.expected !== undefined && !hasOutput) {
|
|
77
251
|
issues.push({
|
|
78
|
-
message:
|
|
252
|
+
message: `${label} has expected output but trail has no output schema`,
|
|
79
253
|
rule: 'output-schema-present',
|
|
80
254
|
trailId: id,
|
|
81
255
|
});
|
|
@@ -83,38 +257,265 @@ const checkOneExample = (
|
|
|
83
257
|
return issues;
|
|
84
258
|
};
|
|
85
259
|
|
|
260
|
+
const checkVersionExamples = (id: string, trail: AnyTrail): TopoIssue[] =>
|
|
261
|
+
Object.entries(trail.versions ?? {}).flatMap(([version, entry]) => {
|
|
262
|
+
if (isArchivedTrailVersionEntry(entry)) {
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return (entry.examples ?? []).flatMap((example) =>
|
|
267
|
+
checkOneExample(
|
|
268
|
+
id,
|
|
269
|
+
example,
|
|
270
|
+
entry.input,
|
|
271
|
+
true,
|
|
272
|
+
`Example "${example.name}" on version ${version}`
|
|
273
|
+
)
|
|
274
|
+
);
|
|
275
|
+
});
|
|
276
|
+
|
|
86
277
|
const checkExamples = (trails: ReadonlyMap<string, AnyTrail>): TopoIssue[] => {
|
|
87
278
|
const issues: TopoIssue[] = [];
|
|
88
279
|
for (const [id, trail] of trails) {
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
280
|
+
if (trail.examples) {
|
|
281
|
+
for (const example of trail.examples) {
|
|
282
|
+
issues.push(
|
|
283
|
+
...checkOneExample(id, example, trail.input, !!trail.output)
|
|
284
|
+
);
|
|
285
|
+
}
|
|
94
286
|
}
|
|
287
|
+
issues.push(...checkVersionExamples(id, trail));
|
|
95
288
|
}
|
|
96
289
|
return issues;
|
|
97
290
|
};
|
|
98
291
|
|
|
99
|
-
const
|
|
100
|
-
|
|
292
|
+
const checkSignalOrigins = (
|
|
293
|
+
signals: ReadonlyMap<string, AnySignal>,
|
|
101
294
|
topo: Topo
|
|
102
295
|
): TopoIssue[] => {
|
|
103
296
|
const issues: TopoIssue[] = [];
|
|
104
|
-
for (const [id, evt] of
|
|
297
|
+
for (const [id, evt] of signals) {
|
|
105
298
|
if (!evt.from) {
|
|
106
299
|
continue;
|
|
107
300
|
}
|
|
108
301
|
for (const originId of evt.from) {
|
|
109
|
-
if (!topo.has(originId)) {
|
|
302
|
+
if (!topo.has(originId) && !isDraftId(originId)) {
|
|
303
|
+
issues.push({
|
|
304
|
+
message: `Signal origin "${originId}" is not in the topo`,
|
|
305
|
+
rule: 'signal-origin-exists',
|
|
306
|
+
trailId: id,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return issues;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
const checkSignalReferences = (
|
|
315
|
+
trails: ReadonlyMap<string, AnyTrail>,
|
|
316
|
+
signals: ReadonlyMap<string, AnySignal>
|
|
317
|
+
): TopoIssue[] => {
|
|
318
|
+
const issues: TopoIssue[] = [];
|
|
319
|
+
|
|
320
|
+
for (const [id, trail] of trails) {
|
|
321
|
+
for (const signalId of trail.fires ?? []) {
|
|
322
|
+
if (!signals.has(signalId) && !isDraftId(signalId)) {
|
|
323
|
+
issues.push({
|
|
324
|
+
message: `Trail fires signal "${signalId}" which is not in the topo`,
|
|
325
|
+
rule: 'signal-fire-exists',
|
|
326
|
+
trailId: id,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
for (const signalId of trail.on ?? []) {
|
|
332
|
+
if (!signals.has(signalId) && !isDraftId(signalId)) {
|
|
110
333
|
issues.push({
|
|
111
|
-
message: `
|
|
112
|
-
rule: '
|
|
334
|
+
message: `Trail declares on signal "${signalId}" which is not in the topo`,
|
|
335
|
+
rule: 'signal-on-exists',
|
|
113
336
|
trailId: id,
|
|
114
337
|
});
|
|
115
338
|
}
|
|
116
339
|
}
|
|
117
340
|
}
|
|
341
|
+
|
|
342
|
+
return issues;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const checkActivationSources = (
|
|
346
|
+
trails: ReadonlyMap<string, AnyTrail>
|
|
347
|
+
): TopoIssue[] => {
|
|
348
|
+
const issues: TopoIssue[] = [];
|
|
349
|
+
const sourceDeclarations = new Map<
|
|
350
|
+
string,
|
|
351
|
+
{
|
|
352
|
+
readonly signature: string;
|
|
353
|
+
readonly trailId: string;
|
|
354
|
+
}
|
|
355
|
+
>();
|
|
356
|
+
const trailSourceEdges = new Set<string>();
|
|
357
|
+
|
|
358
|
+
for (const [id, trail] of trails) {
|
|
359
|
+
for (const activation of trail.activationSources ?? []) {
|
|
360
|
+
if (!isKnownActivationSourceKind(activation.source.kind)) {
|
|
361
|
+
issues.push({
|
|
362
|
+
message: `Trail declares on source "${activation.source.id}" with unsupported source kind "${activation.source.kind}"`,
|
|
363
|
+
rule: 'activation-source-kind-known',
|
|
364
|
+
trailId: id,
|
|
365
|
+
});
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const sourceKey = activationSourceKey(activation.source);
|
|
370
|
+
const edgeKey = `${id}\0${sourceKey}`;
|
|
371
|
+
if (trailSourceEdges.has(edgeKey)) {
|
|
372
|
+
issues.push({
|
|
373
|
+
message: `Trail declares activation source "${activation.source.id}" (${activation.source.kind}) more than once. Keep one source-to-trail activation edge, or split distinct activation behavior into distinct source ids.`,
|
|
374
|
+
rule: 'activation-source-edge-unique',
|
|
375
|
+
sourceId: activation.source.id,
|
|
376
|
+
sourceKind: activation.source.kind,
|
|
377
|
+
trailId: id,
|
|
378
|
+
});
|
|
379
|
+
} else {
|
|
380
|
+
trailSourceEdges.add(edgeKey);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (!isDraftId(activation.source.id)) {
|
|
384
|
+
const signature = activationSourceDeclarationSignature(
|
|
385
|
+
activation.source
|
|
386
|
+
);
|
|
387
|
+
const previous = sourceDeclarations.get(sourceKey);
|
|
388
|
+
if (previous === undefined) {
|
|
389
|
+
sourceDeclarations.set(sourceKey, { signature, trailId: id });
|
|
390
|
+
} else if (previous.signature !== signature) {
|
|
391
|
+
issues.push({
|
|
392
|
+
message: `Activation source "${activation.source.id}" (${activation.source.kind}) is declared with conflicting source options by trails "${previous.trailId}" and "${id}". Use one canonical source declaration per source id, or give distinct source configurations distinct ids.`,
|
|
393
|
+
rule: 'activation-source-definition-unique',
|
|
394
|
+
sourceId: activation.source.id,
|
|
395
|
+
sourceKind: activation.source.kind,
|
|
396
|
+
trailId: id,
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const scheduleIssues = validateScheduleSource(activation.source);
|
|
402
|
+
for (const issue of scheduleIssues) {
|
|
403
|
+
issues.push({
|
|
404
|
+
inputPath: [issue.field],
|
|
405
|
+
message: `Trail declares schedule source "${activation.source.id}" with invalid ${issue.field}: ${issue.message}`,
|
|
406
|
+
rule: 'activation-schedule-valid',
|
|
407
|
+
schemaIssues: [
|
|
408
|
+
{ code: issue.field, message: issue.message, path: [issue.field] },
|
|
409
|
+
],
|
|
410
|
+
sourceId: activation.source.id,
|
|
411
|
+
sourceKind: activation.source.kind,
|
|
412
|
+
trailId: id,
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const webhookIssues = validateWebhookSource(activation.source);
|
|
417
|
+
for (const issue of webhookIssues) {
|
|
418
|
+
issues.push({
|
|
419
|
+
inputPath: [issue.field],
|
|
420
|
+
message: `Trail declares webhook source "${activation.source.id}" with invalid ${issue.field}: ${issue.message}`,
|
|
421
|
+
rule: 'activation-webhook-valid',
|
|
422
|
+
schemaIssues: [
|
|
423
|
+
{ code: issue.field, message: issue.message, path: [issue.field] },
|
|
424
|
+
],
|
|
425
|
+
sourceId: activation.source.id,
|
|
426
|
+
sourceKind: activation.source.kind,
|
|
427
|
+
trailId: id,
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return issues;
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
const issuePathText = (path: readonly (string | number)[]): string =>
|
|
437
|
+
path.length > 0 ? path.join('.') : '<root>';
|
|
438
|
+
|
|
439
|
+
const createSourceCompatibilityIssue = (
|
|
440
|
+
trailId: string,
|
|
441
|
+
activation: ActivationEntry,
|
|
442
|
+
schemaIssues: readonly TopoSchemaIssue[]
|
|
443
|
+
): TopoIssue => {
|
|
444
|
+
const [firstIssue] = schemaIssues;
|
|
445
|
+
const inputPath = firstIssue?.path ?? Object.freeze([]);
|
|
446
|
+
return {
|
|
447
|
+
inputPath,
|
|
448
|
+
message: `Activation source "${activation.source.id}" (${activation.source.kind}) does not satisfy trail input at ${issuePathText(inputPath)}: ${firstIssue?.message ?? 'source payload is incompatible with trail input'}`,
|
|
449
|
+
rule: 'activation-source-input-compatible',
|
|
450
|
+
schemaIssues,
|
|
451
|
+
sourceId: activation.source.id,
|
|
452
|
+
sourceKind: activation.source.kind,
|
|
453
|
+
trailId,
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
const checkSourcePayloadCompatibility = (
|
|
458
|
+
trail: AnyTrail,
|
|
459
|
+
activation: ActivationEntry,
|
|
460
|
+
signals: ReadonlyMap<string, AnySignal>
|
|
461
|
+
): TopoIssue | undefined => {
|
|
462
|
+
if (
|
|
463
|
+
!isKnownActivationSourceKind(activation.source.kind) ||
|
|
464
|
+
isDraftId(activation.source.id)
|
|
465
|
+
) {
|
|
466
|
+
return undefined;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const schemaIssues = getActivationSourceInputCompatibilityIssues(
|
|
470
|
+
trail.input,
|
|
471
|
+
activation.source,
|
|
472
|
+
signals
|
|
473
|
+
);
|
|
474
|
+
if (!schemaIssues) {
|
|
475
|
+
return undefined;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
return schemaIssues.length > 0
|
|
479
|
+
? createSourceCompatibilityIssue(trail.id, activation, schemaIssues)
|
|
480
|
+
: undefined;
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
const checkActivationSourceInputCompatibility = (
|
|
484
|
+
trails: ReadonlyMap<string, AnyTrail>,
|
|
485
|
+
signals: ReadonlyMap<string, AnySignal>
|
|
486
|
+
): TopoIssue[] => {
|
|
487
|
+
const issues: TopoIssue[] = [];
|
|
488
|
+
|
|
489
|
+
for (const trail of trails.values()) {
|
|
490
|
+
for (const activation of trail.activationSources ?? []) {
|
|
491
|
+
const issue = checkSourcePayloadCompatibility(trail, activation, signals);
|
|
492
|
+
if (issue) {
|
|
493
|
+
issues.push(issue);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return issues;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
const checkContourReferences = (
|
|
502
|
+
contours: ReadonlyMap<string, AnyContour>,
|
|
503
|
+
topo: Topo
|
|
504
|
+
): TopoIssue[] => {
|
|
505
|
+
const issues: TopoIssue[] = [];
|
|
506
|
+
|
|
507
|
+
for (const [name, contourDef] of contours) {
|
|
508
|
+
for (const ref of getContourReferences(contourDef)) {
|
|
509
|
+
if (!topo.hasContour(ref.contour) && !isDraftId(ref.contour)) {
|
|
510
|
+
issues.push({
|
|
511
|
+
message: `Contour "${name}" references "${ref.contour}" which is not in the topo`,
|
|
512
|
+
rule: 'contour-reference-exists',
|
|
513
|
+
trailId: name,
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
118
519
|
return issues;
|
|
119
520
|
};
|
|
120
521
|
|
|
@@ -125,15 +526,21 @@ const checkEventOrigins = (
|
|
|
125
526
|
/**
|
|
126
527
|
* Validate the structural integrity of a Topo graph.
|
|
127
528
|
*
|
|
128
|
-
* Checks
|
|
129
|
-
* schema presence. Returns `Result.ok()` when no
|
|
529
|
+
* Checks composing references, example inputs, signal origins, activation
|
|
530
|
+
* source kinds, and output schema presence. Returns `Result.ok()` when no
|
|
531
|
+
* issues are found, or
|
|
130
532
|
* `Result.err(ValidationError)` with all issues in the error context.
|
|
131
533
|
*/
|
|
132
534
|
export const validateTopo = (topo: Topo): Result<void, ValidationError> => {
|
|
133
535
|
const issues = [
|
|
134
|
-
...
|
|
536
|
+
...checkComposes(topo.trails, topo),
|
|
537
|
+
...checkResources(topo.trails, topo),
|
|
538
|
+
...checkContourReferences(topo.contours, topo),
|
|
135
539
|
...checkExamples(topo.trails),
|
|
136
|
-
...
|
|
540
|
+
...checkSignalOrigins(topo.signals, topo),
|
|
541
|
+
...checkSignalReferences(topo.trails, topo.signals),
|
|
542
|
+
...checkActivationSources(topo.trails),
|
|
543
|
+
...checkActivationSourceInputCompatibility(topo.trails, topo.signals),
|
|
137
544
|
];
|
|
138
545
|
|
|
139
546
|
if (issues.length === 0) {
|