@orthograph/prove 0.0.0-stage → 0.1.0-next.1
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/LICENSE +202 -0
- package/README.md +2 -2
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/modules/build/internal/manifest.d.ts +15 -0
- package/dist/modules/build/internal/manifest.js +38 -0
- package/dist/modules/build/service.d.ts +2 -0
- package/dist/modules/build/service.js +74 -0
- package/dist/modules/build/types.d.ts +39 -0
- package/dist/modules/build/types.js +4 -0
- package/dist/modules/environments/internal/collector.d.ts +2 -0
- package/dist/modules/environments/internal/collector.js +5 -0
- package/dist/modules/environments/internal/config.d.ts +32 -0
- package/dist/modules/environments/internal/config.js +42 -0
- package/dist/modules/environments/internal/identity.d.ts +3 -0
- package/dist/modules/environments/internal/identity.js +17 -0
- package/dist/modules/environments/internal/logbook.d.ts +10 -0
- package/dist/modules/environments/internal/logbook.js +23 -0
- package/dist/modules/environments/internal/process.d.ts +41 -0
- package/dist/modules/environments/internal/process.js +103 -0
- package/dist/modules/environments/internal/secrets.d.ts +9 -0
- package/dist/modules/environments/internal/secrets.js +23 -0
- package/dist/modules/environments/internal/status.d.ts +7 -0
- package/dist/modules/environments/internal/status.js +31 -0
- package/dist/modules/environments/service.d.ts +2 -0
- package/dist/modules/environments/service.js +97 -0
- package/dist/modules/environments/types.d.ts +80 -0
- package/dist/modules/environments/types.js +4 -0
- package/dist/modules/evals/internal/calls.d.ts +19 -0
- package/dist/modules/evals/internal/calls.js +168 -0
- package/dist/modules/evals/internal/evidence.d.ts +13 -0
- package/dist/modules/evals/internal/evidence.js +29 -0
- package/dist/modules/evals/internal/run.d.ts +12 -0
- package/dist/modules/evals/internal/run.js +85 -0
- package/dist/modules/evals/internal/secrets.d.ts +5 -0
- package/dist/modules/evals/internal/secrets.js +72 -0
- package/dist/modules/evals/service.d.ts +2 -0
- package/dist/modules/evals/service.js +29 -0
- package/dist/modules/evals/testing.d.ts +12 -0
- package/dist/modules/evals/testing.js +15 -0
- package/dist/modules/evals/types.d.ts +43 -0
- package/dist/modules/evals/types.js +1 -0
- package/dist/modules/impact/internal/changed.d.ts +6 -0
- package/dist/modules/impact/internal/changed.js +34 -0
- package/dist/modules/impact/internal/closure.d.ts +12 -0
- package/dist/modules/impact/internal/closure.js +69 -0
- package/dist/modules/impact/internal/digest.d.ts +1 -0
- package/dist/modules/impact/internal/digest.js +2 -0
- package/dist/modules/impact/internal/files.d.ts +11 -0
- package/dist/modules/impact/internal/files.js +48 -0
- package/dist/modules/impact/internal/ledger.d.ts +5 -0
- package/dist/modules/impact/internal/ledger.js +25 -0
- package/dist/modules/impact/internal/linked.d.ts +4 -0
- package/dist/modules/impact/internal/linked.js +56 -0
- package/dist/modules/impact/internal/scan.d.ts +12 -0
- package/dist/modules/impact/internal/scan.js +66 -0
- package/dist/modules/impact/service.d.ts +2 -0
- package/dist/modules/impact/service.js +88 -0
- package/dist/modules/impact/types.d.ts +109 -0
- package/dist/modules/impact/types.js +1 -0
- package/dist/modules/journeys/internal/checks.d.ts +25 -0
- package/dist/modules/journeys/internal/checks.js +155 -0
- package/dist/modules/journeys/internal/d1-facts.d.ts +10 -0
- package/dist/modules/journeys/internal/d1-facts.js +53 -0
- package/dist/modules/journeys/internal/database-facts.d.ts +2 -0
- package/dist/modules/journeys/internal/database-facts.js +41 -0
- package/dist/modules/journeys/internal/device.d.ts +16 -0
- package/dist/modules/journeys/internal/device.js +68 -0
- package/dist/modules/journeys/internal/keepers.d.ts +6 -0
- package/dist/modules/journeys/internal/keepers.js +6 -0
- package/dist/modules/journeys/internal/load.d.ts +4 -0
- package/dist/modules/journeys/internal/load.js +94 -0
- package/dist/modules/journeys/internal/stand-call.d.ts +10 -0
- package/dist/modules/journeys/internal/stand-call.js +22 -0
- package/dist/modules/journeys/internal/subject.d.ts +8 -0
- package/dist/modules/journeys/internal/subject.js +15 -0
- package/dist/modules/journeys/internal/world.d.ts +70 -0
- package/dist/modules/journeys/internal/world.js +133 -0
- package/dist/modules/journeys/service.d.ts +2 -0
- package/dist/modules/journeys/service.js +231 -0
- package/dist/modules/journeys/types.d.ts +132 -0
- package/dist/modules/journeys/types.js +5 -0
- package/dist/modules/portal-feed/internal/listen.d.ts +10 -0
- package/dist/modules/portal-feed/internal/listen.js +32 -0
- package/dist/modules/portal-feed/service.d.ts +2 -0
- package/dist/modules/portal-feed/service.js +6 -0
- package/dist/modules/portal-feed/types.d.ts +30 -0
- package/dist/modules/portal-feed/types.js +5 -0
- package/dist/modules/promote/internal/environment.d.ts +6 -0
- package/dist/modules/promote/internal/environment.js +10 -0
- package/dist/modules/promote/internal/gate.d.ts +9 -0
- package/dist/modules/promote/internal/gate.js +37 -0
- package/dist/modules/promote/internal/publishing.d.ts +23 -0
- package/dist/modules/promote/internal/publishing.js +21 -0
- package/dist/modules/promote/service.d.ts +2 -0
- package/dist/modules/promote/service.js +112 -0
- package/dist/modules/promote/types.d.ts +54 -0
- package/dist/modules/promote/types.js +8 -0
- package/dist/modules/prove/internal/changed-run.d.ts +9 -0
- package/dist/modules/prove/internal/changed-run.js +14 -0
- package/dist/modules/prove/internal/device-host.d.ts +16 -0
- package/dist/modules/prove/internal/device-host.js +60 -0
- package/dist/modules/prove/internal/empty-world.d.ts +5 -0
- package/dist/modules/prove/internal/empty-world.js +26 -0
- package/dist/modules/prove/internal/exercise.d.ts +35 -0
- package/dist/modules/prove/internal/exercise.js +47 -0
- package/dist/modules/prove/internal/proof-verdicts.d.ts +5 -0
- package/dist/modules/prove/internal/proof-verdicts.js +37 -0
- package/dist/modules/prove/internal/report.d.ts +35 -0
- package/dist/modules/prove/internal/report.js +169 -0
- package/dist/modules/prove/internal/staged.d.ts +9 -0
- package/dist/modules/prove/internal/staged.js +30 -0
- package/dist/modules/prove/internal/stand.d.ts +40 -0
- package/dist/modules/prove/internal/stand.js +155 -0
- package/dist/modules/prove/internal/structured.d.ts +78 -0
- package/dist/modules/prove/internal/structured.js +55 -0
- package/dist/modules/prove/internal/test-run.d.ts +7 -0
- package/dist/modules/prove/internal/test-run.js +63 -0
- package/dist/modules/prove/service.d.ts +2 -0
- package/dist/modules/prove/service.js +98 -0
- package/dist/modules/prove/types.d.ts +120 -0
- package/dist/modules/prove/types.js +5 -0
- package/dist/modules/publish/internal/bundle.d.ts +24 -0
- package/dist/modules/publish/internal/bundle.js +46 -0
- package/dist/modules/publish/internal/env.d.ts +3 -0
- package/dist/modules/publish/internal/env.js +2 -0
- package/dist/modules/publish/internal/plan.d.ts +28 -0
- package/dist/modules/publish/internal/plan.js +28 -0
- package/dist/modules/publish/internal/registry.d.ts +24 -0
- package/dist/modules/publish/internal/registry.js +55 -0
- package/dist/modules/publish/internal/sea.d.ts +20 -0
- package/dist/modules/publish/internal/sea.js +77 -0
- package/dist/modules/publish/internal/source.d.ts +4 -0
- package/dist/modules/publish/internal/source.js +41 -0
- package/dist/modules/publish/internal/stage.d.ts +14 -0
- package/dist/modules/publish/internal/stage.js +95 -0
- package/dist/modules/publish/internal/tap.d.ts +22 -0
- package/dist/modules/publish/internal/tap.js +61 -0
- package/dist/modules/publish/service.d.ts +2 -0
- package/dist/modules/publish/service.js +99 -0
- package/dist/modules/publish/types.d.ts +80 -0
- package/dist/modules/publish/types.js +4 -0
- package/dist/modules/releases/internal/http.d.ts +12 -0
- package/dist/modules/releases/internal/http.js +14 -0
- package/dist/modules/releases/internal/stale.d.ts +13 -0
- package/dist/modules/releases/internal/stale.js +43 -0
- package/dist/modules/releases/service.d.ts +2 -0
- package/dist/modules/releases/service.js +59 -0
- package/dist/modules/releases/types.d.ts +81 -0
- package/dist/modules/releases/types.js +6 -0
- package/dist/modules/secrets/internal/file.d.ts +5 -0
- package/dist/modules/secrets/internal/file.js +25 -0
- package/dist/modules/secrets/service.d.ts +2 -0
- package/dist/modules/secrets/service.js +38 -0
- package/dist/modules/secrets/types.d.ts +44 -0
- package/dist/modules/secrets/types.js +7 -0
- package/dist/modules/server-config/internal/jsonc.d.ts +2 -0
- package/dist/modules/server-config/internal/jsonc.js +29 -0
- package/dist/modules/server-config/service.d.ts +2 -0
- package/dist/modules/server-config/service.js +21 -0
- package/dist/modules/server-config/types.d.ts +22 -0
- package/dist/modules/server-config/types.js +3 -0
- package/dist/modules/sinks/internal/axiom.d.ts +29 -0
- package/dist/modules/sinks/internal/axiom.js +25 -0
- package/dist/modules/sinks/internal/keychain.d.ts +2 -0
- package/dist/modules/sinks/internal/keychain.js +13 -0
- package/dist/modules/sinks/service.d.ts +2 -0
- package/dist/modules/sinks/service.js +26 -0
- package/dist/modules/sinks/types.d.ts +37 -0
- package/dist/modules/sinks/types.js +5 -0
- package/dist/modules/telemetry/internal/axiom-source.d.ts +2 -0
- package/dist/modules/telemetry/internal/axiom-source.js +108 -0
- package/dist/modules/telemetry/internal/binary.d.ts +11 -0
- package/dist/modules/telemetry/internal/binary.js +66 -0
- package/dist/modules/telemetry/internal/config.d.ts +13 -0
- package/dist/modules/telemetry/internal/config.js +22 -0
- package/dist/modules/telemetry/internal/file-metrics.d.ts +2 -0
- package/dist/modules/telemetry/internal/file-metrics.js +60 -0
- package/dist/modules/telemetry/internal/file-source.d.ts +2 -0
- package/dist/modules/telemetry/internal/file-source.js +38 -0
- package/dist/modules/telemetry/internal/journey-root.d.ts +44 -0
- package/dist/modules/telemetry/internal/journey-root.js +36 -0
- package/dist/modules/telemetry/internal/local.d.ts +11 -0
- package/dist/modules/telemetry/internal/local.js +57 -0
- package/dist/modules/telemetry/internal/otlp.d.ts +15 -0
- package/dist/modules/telemetry/internal/otlp.js +53 -0
- package/dist/modules/telemetry/internal/private-keys.d.ts +7 -0
- package/dist/modules/telemetry/internal/private-keys.js +28 -0
- package/dist/modules/telemetry/internal/process.d.ts +27 -0
- package/dist/modules/telemetry/internal/process.js +96 -0
- package/dist/modules/telemetry/internal/runs.d.ts +17 -0
- package/dist/modules/telemetry/internal/runs.js +48 -0
- package/dist/modules/telemetry/service.d.ts +9 -0
- package/dist/modules/telemetry/service.js +48 -0
- package/dist/modules/telemetry/types.d.ts +138 -0
- package/dist/modules/telemetry/types.js +13 -0
- package/dist/modules/test-worlds/internal/lifetime.d.ts +3 -0
- package/dist/modules/test-worlds/internal/lifetime.js +19 -0
- package/dist/modules/test-worlds/service.d.ts +2 -0
- package/dist/modules/test-worlds/service.js +35 -0
- package/dist/modules/test-worlds/types.d.ts +41 -0
- package/dist/modules/test-worlds/types.js +4 -0
- package/dist/modules/trace-trees/service.d.ts +2 -0
- package/dist/modules/trace-trees/service.js +40 -0
- package/dist/modules/trace-trees/types.d.ts +9 -0
- package/dist/modules/trace-trees/types.js +1 -0
- package/dist/modules/verdicts/internal/proof.d.ts +24 -0
- package/dist/modules/verdicts/internal/proof.js +59 -0
- package/dist/modules/verdicts/service.d.ts +16 -0
- package/dist/modules/verdicts/service.js +71 -0
- package/dist/modules/verdicts/types.d.ts +80 -0
- package/dist/modules/verdicts/types.js +4 -0
- package/dist/modules/warm/internal/source.d.ts +7 -0
- package/dist/modules/warm/internal/source.js +27 -0
- package/dist/modules/warm/service.d.ts +2 -0
- package/dist/modules/warm/service.js +76 -0
- package/dist/modules/warm/types.d.ts +43 -0
- package/dist/modules/warm/types.js +4 -0
- package/dist/modules/watch/internal/choose.d.ts +20 -0
- package/dist/modules/watch/internal/choose.js +24 -0
- package/dist/modules/watch/internal/evidence.d.ts +9 -0
- package/dist/modules/watch/internal/evidence.js +26 -0
- package/dist/modules/watch/internal/report.d.ts +18 -0
- package/dist/modules/watch/internal/report.js +59 -0
- package/dist/modules/watch/internal/tasks.d.ts +5 -0
- package/dist/modules/watch/internal/tasks.js +35 -0
- package/dist/modules/watch/service.d.ts +2 -0
- package/dist/modules/watch/service.js +38 -0
- package/dist/modules/watch/types.d.ts +44 -0
- package/dist/modules/watch/types.js +4 -0
- package/dist/modules/world/internal/ports.d.ts +8 -0
- package/dist/modules/world/internal/ports.js +30 -0
- package/dist/modules/world/internal/wrangler.d.ts +46 -0
- package/dist/modules/world/internal/wrangler.js +112 -0
- package/dist/modules/world/service.d.ts +2 -0
- package/dist/modules/world/service.js +46 -0
- package/dist/modules/world/types.d.ts +97 -0
- package/dist/modules/world/types.js +4 -0
- package/dist/modules/world-clock/internal/door.d.ts +8 -0
- package/dist/modules/world-clock/internal/door.js +9 -0
- package/dist/modules/world-clock/service.d.ts +2 -0
- package/dist/modules/world-clock/service.js +9 -0
- package/dist/modules/world-clock/types.d.ts +34 -0
- package/dist/modules/world-clock/types.js +1 -0
- package/package.json +38 -3
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { type Effect, type Scope } from "effect";
|
|
2
|
+
import type { Env, Reader } from "#modules/sinks/types.js";
|
|
3
|
+
export interface Span {
|
|
4
|
+
readonly traceId: string;
|
|
5
|
+
readonly spanId: string;
|
|
6
|
+
readonly parentSpanId: string;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly attrs: Readonly<Record<string, unknown>>;
|
|
9
|
+
/** 0 unset, 1 ok, 2 error. */
|
|
10
|
+
readonly status: number;
|
|
11
|
+
readonly ms: number;
|
|
12
|
+
/** When it started, in milliseconds since the epoch: the order steps ran in. */
|
|
13
|
+
readonly start: number;
|
|
14
|
+
}
|
|
15
|
+
export interface Log {
|
|
16
|
+
readonly traceId: string;
|
|
17
|
+
readonly spanId: string;
|
|
18
|
+
readonly body: string;
|
|
19
|
+
readonly attrs: Readonly<Record<string, unknown>>;
|
|
20
|
+
}
|
|
21
|
+
export interface Trace {
|
|
22
|
+
readonly spans: ReadonlyArray<Span>;
|
|
23
|
+
readonly logs: ReadonlyArray<Log>;
|
|
24
|
+
}
|
|
25
|
+
declare const CollectorFailed_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
26
|
+
readonly _tag: "CollectorFailed";
|
|
27
|
+
} & Readonly<A>;
|
|
28
|
+
export declare class CollectorFailed extends CollectorFailed_base<{
|
|
29
|
+
readonly message: string;
|
|
30
|
+
}> {
|
|
31
|
+
}
|
|
32
|
+
declare const SourceFailed_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
33
|
+
readonly _tag: "SourceFailed";
|
|
34
|
+
} & Readonly<A>;
|
|
35
|
+
/** A source that couldn't be read: no credential for it, an edge that wouldn't answer, an answer it refused. Never carries a value. */
|
|
36
|
+
export declare class SourceFailed extends SourceFailed_base<{
|
|
37
|
+
readonly message: string;
|
|
38
|
+
}> {
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The first 8 hex characters of every caller span id `prove` makes up for a call's `traceparent`. A trace whose spans point at
|
|
42
|
+
* a parent that starts so was made by a prove run, which judged it already: `watch` leaves it out of what it counts.
|
|
43
|
+
*/
|
|
44
|
+
export declare const PROVE_SPAN_PREFIX = "a2c4e700";
|
|
45
|
+
/** A trace some caller is waiting on: found by its id, complete once the span that is the caller's child is there. */
|
|
46
|
+
export interface Wanted {
|
|
47
|
+
readonly trace: string;
|
|
48
|
+
/** The caller's own span id, from the `traceparent` it sent: the server's root span is its child. */
|
|
49
|
+
readonly parent: string;
|
|
50
|
+
/** The caller's span is itself in the trace (the journey's `journey.<name>`): complete only once it is. */
|
|
51
|
+
readonly rooted?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The server may send nothing for this call: it refused the caller before any span opened (O2, gap 3). An empty
|
|
54
|
+
* trace is then whole. One with spans is still waited for, so a span that should be absent is seen.
|
|
55
|
+
*/
|
|
56
|
+
readonly mayBeEmpty?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Where traces are read from. `prove`, `telemetry trace` and, later, `watch` read through this and never through a
|
|
60
|
+
* file or a vendor directly (O1): a `FileSource` today, an Axiom one in the cloud pass.
|
|
61
|
+
*/
|
|
62
|
+
export interface TraceSource {
|
|
63
|
+
/**
|
|
64
|
+
* Every span and log of these traces, once each is complete: its root span (the child of the caller's span) is
|
|
65
|
+
* present, no span points at a parent that isn't, and nothing new has arrived for a quiet window. A trace still
|
|
66
|
+
* incomplete after 10 s comes back as it is; the evals then name what is missing.
|
|
67
|
+
*/
|
|
68
|
+
readonly traces: (wanted: ReadonlyArray<Wanted>) => Effect.Effect<ReadonlyMap<string, Trace>>;
|
|
69
|
+
/** One trace by id, as it is now: no waiting, `undefined` when this source has none of it. */
|
|
70
|
+
readonly find: (trace: string) => Effect.Effect<Trace | undefined>;
|
|
71
|
+
/**
|
|
72
|
+
* Every trace with a span that started in the last `since` milliseconds (`now` is the clock's, unless given), whole: what
|
|
73
|
+
* `watch` judges. It reads what the source has, without waiting for anything to complete.
|
|
74
|
+
*/
|
|
75
|
+
readonly window: (since: number, now?: number) => Effect.Effect<ReadonlyMap<string, Trace>, SourceFailed>;
|
|
76
|
+
}
|
|
77
|
+
/** One series of a metric over a window: its labels, and how much it grew in the window. */
|
|
78
|
+
export interface MetricPoint {
|
|
79
|
+
readonly name: string;
|
|
80
|
+
readonly labels: Readonly<Record<string, string>>;
|
|
81
|
+
readonly value: number;
|
|
82
|
+
}
|
|
83
|
+
/** Where metrics are read from, beside `TraceSource` (portal.md hole 2): `ortho.calls` counted in the last `since` ms before `now`. History past the window is M7.14. */
|
|
84
|
+
export interface MetricsSource {
|
|
85
|
+
readonly window: (since: number, now: number) => Effect.Effect<ReadonlyArray<MetricPoint>, SourceFailed>;
|
|
86
|
+
}
|
|
87
|
+
export interface FileMetricsApi {
|
|
88
|
+
/** Read the counters in `metrics.jsonl` of these folders, as one source. Missing files are no points, not a failure. */
|
|
89
|
+
readonly open: (dirs: string | ReadonlyArray<string>) => MetricsSource;
|
|
90
|
+
}
|
|
91
|
+
export interface Collector extends TraceSource {
|
|
92
|
+
/** The OTLP/HTTP base URL the Worker exports to. */
|
|
93
|
+
readonly url: string;
|
|
94
|
+
}
|
|
95
|
+
export interface CollectorsApi {
|
|
96
|
+
/** A scoped loopback OTLP/HTTP receiver, writing scrubbed OTLP JSON lines to `dir`. */
|
|
97
|
+
readonly local: (dir: string, strip: ReadonlyArray<string>) => Effect.Effect<Collector, CollectorFailed, Scope.Scope>;
|
|
98
|
+
/**
|
|
99
|
+
* Start a collector process writing to `dir`, owned by this one: stopped when the scope closes. First stops every collector whose
|
|
100
|
+
* owner process is gone (a killed prove's leak). `strip` are attribute keys its `attributes` processor deletes from every span
|
|
101
|
+
* and log (L2.P): the keys the model says may carry a non-public value.
|
|
102
|
+
*/
|
|
103
|
+
readonly start: (dir: string, options?: {
|
|
104
|
+
readonly strip?: ReadonlyArray<string>;
|
|
105
|
+
}) => Effect.Effect<Collector, CollectorFailed, Scope.Scope>;
|
|
106
|
+
/**
|
|
107
|
+
* A collector that outlives this process, for an environment that has one of its own: a detached process writing to a fresh
|
|
108
|
+
* `dir`, on a port the system picks, its marker kept in `dir`. Returns its OTLP/HTTP URL. Whoever launches it stops it.
|
|
109
|
+
*/
|
|
110
|
+
readonly launch: (options: {
|
|
111
|
+
readonly dir: string;
|
|
112
|
+
readonly strip?: ReadonlyArray<string>;
|
|
113
|
+
}) => Effect.Effect<string, CollectorFailed>;
|
|
114
|
+
/** Stop the collector launched in `dir`, if it still runs what was launched. Nothing to stop is not an error. */
|
|
115
|
+
readonly stop: (dir: string) => Effect.Effect<void>;
|
|
116
|
+
/** Read what some collector wrote to `dir`, by trace id. */
|
|
117
|
+
readonly read: (dir: string) => TraceSource;
|
|
118
|
+
}
|
|
119
|
+
export interface AxiomSourceApi {
|
|
120
|
+
/**
|
|
121
|
+
* Axiom's query API as a source: APL over the dataset `<group>-traces` (and `<group>-logs`, for the logs of refused calls),
|
|
122
|
+
* the spans of `environment` told apart by `deployment.environment`. The query token is `AXIOM_QUERY_TOKEN`, else the keychain
|
|
123
|
+
* item `capxul-query`; the edge `AXIOM_DOMAIN`, else `axiom-domain`; the organisation `AXIOM_ORG_ID`, else `axiom-org-id`. Each is
|
|
124
|
+
* read here, held for the queries and never printed or written. `fetch` is a seam for tests.
|
|
125
|
+
*/
|
|
126
|
+
readonly open: (options: {
|
|
127
|
+
readonly group: string;
|
|
128
|
+
readonly environment: string;
|
|
129
|
+
readonly env: Env;
|
|
130
|
+
readonly read?: Reader;
|
|
131
|
+
readonly fetch?: typeof fetch;
|
|
132
|
+
}) => Effect.Effect<TraceSource, SourceFailed>;
|
|
133
|
+
}
|
|
134
|
+
export interface FileSourceApi {
|
|
135
|
+
/** Read OTLP JSON lines (`traces.jsonl`, `logs.jsonl`) from these folders, as one source. */
|
|
136
|
+
readonly open: (dirs: string | ReadonlyArray<string>) => TraceSource;
|
|
137
|
+
}
|
|
138
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Telemetry for prove: a real OpenTelemetry Collector as a pinned binary, its file exporter read back by trace id
|
|
2
|
+
// (spikes/otlp-from-workerd). What a call did is read from here, never from what the server says about itself.
|
|
3
|
+
import { Data } from "effect";
|
|
4
|
+
export class CollectorFailed extends Data.TaggedError("CollectorFailed") {
|
|
5
|
+
}
|
|
6
|
+
/** A source that couldn't be read: no credential for it, an edge that wouldn't answer, an answer it refused. Never carries a value. */
|
|
7
|
+
export class SourceFailed extends Data.TaggedError("SourceFailed") {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The first 8 hex characters of every caller span id `prove` makes up for a call's `traceparent`. A trace whose spans point at
|
|
11
|
+
* a parent that starts so was made by a prove run, which judged it already: `watch` leaves it out of what it counts.
|
|
12
|
+
*/
|
|
13
|
+
export const PROVE_SPAN_PREFIX = "a2c4e700";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// A lifetime as people write it (`20s`, `2 hours`) and as the alarm needs it (milliseconds).
|
|
2
|
+
const UNITS = [
|
|
3
|
+
[/^(ms|millis?|milliseconds?)$/, 1, "ms"],
|
|
4
|
+
[/^(s|secs?|seconds?)$/, 1000, "s"],
|
|
5
|
+
[/^(m|mins?|minutes?)$/, 60_000, "m"],
|
|
6
|
+
[/^(h|hrs?|hours?)$/, 3_600_000, "h"],
|
|
7
|
+
[/^(d|days?)$/, 86_400_000, "d"],
|
|
8
|
+
];
|
|
9
|
+
export const parse = (text) => {
|
|
10
|
+
const match = /^\s*(\d+(?:\.\d+)?)\s*([a-z]+)\s*$/i.exec(text);
|
|
11
|
+
const unit = match ? UNITS.find(([name]) => name.test(match[2].toLowerCase())) : undefined;
|
|
12
|
+
const ms = match && unit ? Number(match[1]) * unit[1] : undefined;
|
|
13
|
+
return ms !== undefined && ms > 0 ? Math.round(ms) : undefined;
|
|
14
|
+
};
|
|
15
|
+
/** The largest unit that divides it exactly. */
|
|
16
|
+
export const format = (ms) => {
|
|
17
|
+
const unit = [...UNITS].reverse().find(([, size]) => ms % size === 0) ?? UNITS[0];
|
|
18
|
+
return `${ms / unit[1]}${unit[2]}`;
|
|
19
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { Environments } from "#modules/environments/service.js";
|
|
3
|
+
import { TestWorldFailed } from "./types.js";
|
|
4
|
+
import { format, parse } from "./internal/lifetime.js";
|
|
5
|
+
const failed = (message) => new TestWorldFailed({ message });
|
|
6
|
+
/** One call to the environment's `/_world/worlds` door: its status and its JSON. */
|
|
7
|
+
const door = (url, path, method, body) => Effect.tryPromise({
|
|
8
|
+
try: () => fetch(`${url}/_world/worlds${path}`, { method, ...(body === undefined ? {} : { headers: { "content-type": "application/json" }, body: JSON.stringify(body) }) }).then((r) => r.json().then((json) => ({ status: r.status, json: json }), () => ({ status: r.status, json: {} }))),
|
|
9
|
+
catch: () => failed(`the test environment at ${url} didn't answer`),
|
|
10
|
+
});
|
|
11
|
+
export const TestWorlds = {
|
|
12
|
+
create: ({ url, id, lifetimeMs }) => Effect.gen(function* () {
|
|
13
|
+
const made = yield* door(url, "", "POST", { id, lifetimeMs });
|
|
14
|
+
if (made.status === 409) {
|
|
15
|
+
return yield* failed(`world ${String(made.json["id"])} is still live in the test environment; \`ortho worlds reap\` destroys it once its lifetime is up`);
|
|
16
|
+
}
|
|
17
|
+
if (made.status === 404)
|
|
18
|
+
return yield* failed("this environment does not host worlds: it declares no lifetime");
|
|
19
|
+
if (made.status !== 201)
|
|
20
|
+
return yield* failed(`the test environment refused the world (${made.status}): ${String(made.json["error"] ?? "")}`);
|
|
21
|
+
return { id, expires: Number(made.json["expires"]) };
|
|
22
|
+
}),
|
|
23
|
+
destroy: ({ url, id }) => door(url, `/${id}`, "DELETE").pipe(Effect.flatMap((r) => (r.status === 200 ? Effect.void : Effect.fail(failed(`the test environment would not destroy world ${id} (${r.status})`))))),
|
|
24
|
+
live: (url) => door(url, "", "GET").pipe(Effect.map((r) => (r.status === 200 && Array.isArray(r.json["worlds"]) ? r.json["worlds"].length : undefined)), Effect.orElseSucceed(() => undefined)),
|
|
25
|
+
reap: ({ root, name }) => Effect.gen(function* () {
|
|
26
|
+
const before = yield* Environments.status({ root, name }).pipe(Effect.mapError((e) => failed(e.message)));
|
|
27
|
+
const environment = yield* Environments.up({ root, name }).pipe(Effect.mapError((e) => failed(e.message)));
|
|
28
|
+
const reaped = yield* door(environment.url, "/reap", "POST").pipe(Effect.flatMap((r) => (r.status === 200 ? Effect.succeed(Number(r.json["reaped"])) : Effect.fail(failed(`${name} would not reap (${r.status})`)))),
|
|
29
|
+
// What this started, it stops again, whether or not the reap went through.
|
|
30
|
+
Effect.ensuring(before.state === "down" ? Environments.down({ root, name }).pipe(Effect.ignore) : Effect.void));
|
|
31
|
+
return reaped;
|
|
32
|
+
}),
|
|
33
|
+
parseLifetime: parse,
|
|
34
|
+
formatLifetime: format,
|
|
35
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Effect } from "effect";
|
|
2
|
+
declare const TestWorldFailed_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
3
|
+
readonly _tag: "TestWorldFailed";
|
|
4
|
+
} & Readonly<A>;
|
|
5
|
+
export declare class TestWorldFailed extends TestWorldFailed_base<{
|
|
6
|
+
readonly message: string;
|
|
7
|
+
}> {
|
|
8
|
+
}
|
|
9
|
+
export interface TestWorld {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
/** Milliseconds since the epoch at which the world's alarm destroys it. */
|
|
12
|
+
readonly expires: number;
|
|
13
|
+
}
|
|
14
|
+
export interface TestWorldsApi {
|
|
15
|
+
/** A world named `id`, living `lifetimeMs`. The environment holds one at a time: another live world is refused, naming it. */
|
|
16
|
+
readonly create: (options: {
|
|
17
|
+
readonly url: string;
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly lifetimeMs: number;
|
|
20
|
+
}) => Effect.Effect<TestWorld, TestWorldFailed>;
|
|
21
|
+
/** Destroy it now: its rows, its cast and its alarm. A world already gone is not an error. */
|
|
22
|
+
readonly destroy: (options: {
|
|
23
|
+
readonly url: string;
|
|
24
|
+
readonly id: string;
|
|
25
|
+
}) => Effect.Effect<void, TestWorldFailed>;
|
|
26
|
+
/** How many worlds the environment at `url` holds now; `undefined` when it does not host worlds. */
|
|
27
|
+
readonly live: (url: string) => Effect.Effect<number | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Start environment `name` if it is down (alarms only fire while a workerd runs), destroy every world past its
|
|
30
|
+
* lifetime, and stop the environment again if this started it. How many worlds this reaped, each counted once.
|
|
31
|
+
*/
|
|
32
|
+
readonly reap: (options: {
|
|
33
|
+
readonly root: string;
|
|
34
|
+
readonly name: string;
|
|
35
|
+
}) => Effect.Effect<number, TestWorldFailed>;
|
|
36
|
+
/** `20s`, `30 minutes`, `2 hours`, `1d` as milliseconds; `undefined` when it isn't a duration. */
|
|
37
|
+
readonly parseLifetime: (text: string) => number | undefined;
|
|
38
|
+
/** Milliseconds as a short duration: `2h`, `20s`. */
|
|
39
|
+
readonly formatLifetime: (ms: number) => string;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const ms = (n) => `${n < 10 ? n.toFixed(1) : Math.round(n)} ms`;
|
|
2
|
+
/** The conventions of O1, in words: a refusal is an outcome, a defect is the only error. */
|
|
3
|
+
const marks = (s) => {
|
|
4
|
+
const defect = s.attrs["defect"];
|
|
5
|
+
const refusal = s.attrs["refusal"];
|
|
6
|
+
return [
|
|
7
|
+
...(typeof defect === "string" ? [`✘ defect: ${defect}`] : s.status === 2 ? ["✘ error"] : []),
|
|
8
|
+
...(typeof refusal === "string" ? [`refused ${refusal}`] : []),
|
|
9
|
+
];
|
|
10
|
+
};
|
|
11
|
+
/** What a person reads off a span without opening it: the step's kind and the move it made. */
|
|
12
|
+
const facts = (s) => [
|
|
13
|
+
...(typeof s.attrs["step.kind"] === "string" ? [`step ${String(s.attrs["step.kind"])}`] : []),
|
|
14
|
+
...(typeof s.attrs["move.name"] === "string" ? [`move ${String(s.attrs["move.name"])}${s.attrs["move.to"] === undefined ? "" : ` → ${String(s.attrs["move.to"])}`}`] : []),
|
|
15
|
+
];
|
|
16
|
+
const spanLine = (s) => [`${s.name} ${ms(s.ms)}`, ...marks(s), ...facts(s)].join(" ");
|
|
17
|
+
export const TraceTrees = {
|
|
18
|
+
render: (id, trace) => {
|
|
19
|
+
const ids = new Set(trace.spans.map((s) => s.spanId));
|
|
20
|
+
const children = (parent) => trace.spans.filter((s) => s.parentSpanId === parent).sort((a, b) => a.start - b.start);
|
|
21
|
+
// A span whose parent isn't in the trace is a root of what was found: the journey's span, or the server's own when prove
|
|
22
|
+
// had no way to export the caller's.
|
|
23
|
+
const roots = trace.spans.filter((s) => s.parentSpanId === "" || !ids.has(s.parentSpanId)).sort((a, b) => a.start - b.start);
|
|
24
|
+
const logsOf = (span) => trace.logs.filter((l) => l.spanId === span);
|
|
25
|
+
const walk = (s, depth) => {
|
|
26
|
+
const pad = " ".repeat(depth);
|
|
27
|
+
return [
|
|
28
|
+
`${pad}${spanLine(s)}`,
|
|
29
|
+
...logsOf(s.spanId).map((l) => `${pad} · ${l.body}`),
|
|
30
|
+
...children(s.spanId).flatMap((c) => walk(c, depth + 1)),
|
|
31
|
+
];
|
|
32
|
+
};
|
|
33
|
+
const detached = trace.logs.filter((l) => l.spanId === "" || !ids.has(l.spanId));
|
|
34
|
+
return [
|
|
35
|
+
`trace ${id} ${trace.spans.length} span${trace.spans.length === 1 ? "" : "s"}`,
|
|
36
|
+
...roots.flatMap((r) => walk(r, 0)),
|
|
37
|
+
...detached.map((l) => `· ${l.body}`),
|
|
38
|
+
];
|
|
39
|
+
},
|
|
40
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Trace } from "#modules/telemetry/types.js";
|
|
2
|
+
export interface TraceTreesApi {
|
|
3
|
+
/**
|
|
4
|
+
* The trace as lines: each span with its duration, indented under its parent in start order, each log line under
|
|
5
|
+
* the span that wrote it. A declared refusal is marked `refused <Tag>` (an ordinary outcome, the span is ok); a defect
|
|
6
|
+
* is marked `✘ defect: <first line>`; a span that failed for any other reason is marked `✘ error`.
|
|
7
|
+
*/
|
|
8
|
+
readonly render: (id: string, trace: Trace) => ReadonlyArray<string>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Model, type OperationModel } from "@orthograph/compiler";
|
|
2
|
+
import type { JourneyVerdict } from "../types.ts";
|
|
3
|
+
export declare const modelHash: (model: Model) => string;
|
|
4
|
+
export declare const handlerHash: (root: string, op: OperationModel) => string | null | undefined;
|
|
5
|
+
export declare const handlerHashes: (root: string, model: Model) => {
|
|
6
|
+
[k: string]: string | null | undefined;
|
|
7
|
+
};
|
|
8
|
+
type JourneyOf = Model["journeys"][string];
|
|
9
|
+
type WorldOf = Model["startingWorlds"][string];
|
|
10
|
+
/** A journey, the starting worlds it stands on (oldest first), and every operation the two call. */
|
|
11
|
+
export interface Scenario {
|
|
12
|
+
readonly journey: JourneyOf;
|
|
13
|
+
readonly worlds: ReadonlyArray<WorldOf>;
|
|
14
|
+
readonly operationNames: ReadonlySet<string>;
|
|
15
|
+
}
|
|
16
|
+
export declare const scenarioOf: (model: Model, journey: JourneyOf) => Scenario;
|
|
17
|
+
/**
|
|
18
|
+
* The fingerprint of the journeys that judged an operation. A journey added later that also exercises it is new evidence
|
|
19
|
+
* for the next prove, not a change to this proof, so it stales nothing (D3 #15.3: a new read is minor, `stale none`).
|
|
20
|
+
*/
|
|
21
|
+
export declare const storyHash: (model: Model, operation: string, judged?: ReadonlyArray<string>) => string;
|
|
22
|
+
/** Compare the specific handler and journey definitions this operation's proof used. */
|
|
23
|
+
export declare const evidenceHolds: (root: string, model: Model, operation: string, story: string, verdicts: ReadonlyArray<JourneyVerdict>) => boolean;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
import { canonical, resolveFrom } from "@orthograph/compiler";
|
|
7
|
+
const digest = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
8
|
+
export const modelHash = (model) => digest(canonical(model));
|
|
9
|
+
export const handlerHash = (root, op) => op.kind === "read" ? null : Effect.runSync(Effect.try(() => {
|
|
10
|
+
const file = op.from.kind === "app"
|
|
11
|
+
? join(root, "src", op.thing, `${op.verb}.ts`)
|
|
12
|
+
// A plugin's operation on the device is judged by its `world` entry, the code a journey runs (M1.29).
|
|
13
|
+
: fileURLToPath(resolveFrom(resolve(root), `${op.from.package}/src/${op.from.thing}/${op.verb}${op.runs === "client" ? ".world" : ""}.js`));
|
|
14
|
+
return digest(readFileSync(file));
|
|
15
|
+
}).pipe(Effect.orElseSucceed(() => undefined)));
|
|
16
|
+
export const handlerHashes = (root, model) => Object.fromEntries(Object.values(model.operations).map((op) => [op.name, handlerHash(root, op)]));
|
|
17
|
+
export const scenarioOf = (model, journey) => {
|
|
18
|
+
const worlds = [];
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
for (let name = journey.starts; name !== null && !seen.has(name);) {
|
|
21
|
+
seen.add(name);
|
|
22
|
+
const world = model.startingWorlds[name];
|
|
23
|
+
if (!world)
|
|
24
|
+
break;
|
|
25
|
+
worlds.unshift(world);
|
|
26
|
+
name = world.from;
|
|
27
|
+
}
|
|
28
|
+
const operationNames = new Set([
|
|
29
|
+
...worlds.flatMap((world) => world.makes.flatMap((call) => call ? [call.operation] : [])),
|
|
30
|
+
...journey.steps.flatMap((step) => "call" in step ? [step.call.operation] : []),
|
|
31
|
+
]);
|
|
32
|
+
return { journey, worlds, operationNames };
|
|
33
|
+
};
|
|
34
|
+
/** The journeys (with their worlds) that exercise an operation; only those named in `judged`, when given. */
|
|
35
|
+
const stories = (model, operation, judged) => Object.values(model.journeys ?? {}).flatMap((journey) => {
|
|
36
|
+
const scenario = scenarioOf(model, journey);
|
|
37
|
+
if (judged !== undefined && !judged.includes(journey.file))
|
|
38
|
+
return [];
|
|
39
|
+
return scenario.operationNames.has(operation) ? [{ journey, worlds: scenario.worlds }] : [];
|
|
40
|
+
}).sort((a, b) => a.journey.file.localeCompare(b.journey.file));
|
|
41
|
+
/**
|
|
42
|
+
* The fingerprint of the journeys that judged an operation. A journey added later that also exercises it is new evidence
|
|
43
|
+
* for the next prove, not a change to this proof, so it stales nothing (D3 #15.3: a new read is minor, `stale none`).
|
|
44
|
+
*/
|
|
45
|
+
export const storyHash = (model, operation, judged) => digest(canonical(stories(model, operation, judged)));
|
|
46
|
+
/** Compare the specific handler and journey definitions this operation's proof used. */
|
|
47
|
+
export const evidenceHolds = (root, model, operation, story, verdicts) => {
|
|
48
|
+
const op = model.operations[operation];
|
|
49
|
+
if (!op || verdicts.length === 0)
|
|
50
|
+
return false;
|
|
51
|
+
const handler = handlerHash(root, op);
|
|
52
|
+
if (verdicts.some((v) => v.verdict !== "pass" || v.handlerHash !== handler))
|
|
53
|
+
return false;
|
|
54
|
+
// Every journey that judged it must still exist, still exercise it, and be unchanged, with its worlds.
|
|
55
|
+
const judged = [...new Set(verdicts.map((v) => v.journey))].sort((a, b) => a.localeCompare(b));
|
|
56
|
+
const declared = stories(model, operation, judged);
|
|
57
|
+
return declared.length === judged.length && declared.every((s, i) => s.journey.file === judged[i])
|
|
58
|
+
&& digest(canonical(declared)) === story;
|
|
59
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { type VerdictsApi } from "./types.ts";
|
|
3
|
+
export declare const VerdictRows: Schema.$Array<Schema.Struct<{
|
|
4
|
+
revision: Schema.String;
|
|
5
|
+
environment: Schema.String;
|
|
6
|
+
operation: Schema.String;
|
|
7
|
+
verdict: Schema.String;
|
|
8
|
+
sha256: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
9
|
+
journeys: Schema.optionalKey<Schema.NullOr<Schema.$Array<Schema.Struct<{
|
|
10
|
+
readonly journey: Schema.String;
|
|
11
|
+
readonly modelHash: Schema.String;
|
|
12
|
+
readonly handlerHash: Schema.NullOr<Schema.String>;
|
|
13
|
+
readonly verdict: Schema.Literals<readonly ["pass", "fail"]>;
|
|
14
|
+
}>>>>;
|
|
15
|
+
}>>;
|
|
16
|
+
export declare const Verdicts: VerdictsApi;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Names } from "orthograph/server";
|
|
2
|
+
import { Effect, Redacted, Schema } from "effect";
|
|
3
|
+
import { VerdictsFailed } from "./types.js";
|
|
4
|
+
const AUDIENCE = "ortho-logbook";
|
|
5
|
+
const failed = (message) => new VerdictsFailed({ message });
|
|
6
|
+
/** The JSON body of a response, whatever shape the other side gave it. */
|
|
7
|
+
const jsonOf = (response) => Effect.tryPromise({ try: () => response.json(), catch: () => failed(`answered ${response.status} with no JSON`) });
|
|
8
|
+
const request = (what, url, init) => Effect.tryPromise({ try: () => fetch(url, init), catch: () => failed(`${what}: couldn't reach ${new URL(url).origin}`) });
|
|
9
|
+
const fromIssuer = (issuer, client) => Effect.gen(function* () {
|
|
10
|
+
const response = yield* request("the issuer", `${issuer}/token`, {
|
|
11
|
+
method: "POST",
|
|
12
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
13
|
+
body: new URLSearchParams({ grant_type: "client_credentials", client_id: client, client_secret: "unused" }),
|
|
14
|
+
});
|
|
15
|
+
if (!response.ok)
|
|
16
|
+
return yield* failed(`the issuer refused a token for client ${client} (${response.status})`);
|
|
17
|
+
const body = yield* jsonOf(response);
|
|
18
|
+
return typeof body["access_token"] === "string" ? body["access_token"] : yield* failed("the issuer's answer has no access_token");
|
|
19
|
+
});
|
|
20
|
+
const fromGithub = (requestUrl, requestToken) => Effect.gen(function* () {
|
|
21
|
+
const url = new URL(requestUrl);
|
|
22
|
+
url.searchParams.set("audience", AUDIENCE);
|
|
23
|
+
const response = yield* request("GitHub's token endpoint", url.toString(), { headers: { authorization: `Bearer ${Redacted.value(requestToken)}` } });
|
|
24
|
+
if (!response.ok)
|
|
25
|
+
return yield* failed(`GitHub refused a token (${response.status}); does the job have id-token: write?`);
|
|
26
|
+
const body = yield* jsonOf(response);
|
|
27
|
+
return typeof body["value"] === "string" ? body["value"] : yield* failed("GitHub's answer has no value");
|
|
28
|
+
});
|
|
29
|
+
const Journeys = Schema.Array(Schema.Struct({
|
|
30
|
+
journey: Schema.String, modelHash: Schema.String, handlerHash: Schema.NullOr(Schema.String), verdict: Schema.Literals(["pass", "fail"]),
|
|
31
|
+
}));
|
|
32
|
+
const verdictFields = {
|
|
33
|
+
revision: Schema.String, environment: Schema.String, operation: Schema.String, verdict: Schema.String,
|
|
34
|
+
sha256: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
35
|
+
journeys: Schema.optionalKey(Schema.NullOr(Journeys)),
|
|
36
|
+
};
|
|
37
|
+
export const VerdictRows = Schema.Array(Schema.Struct(verdictFields));
|
|
38
|
+
const HeldRows = Schema.Array(Schema.Struct({ ...verdictFields, ref: Schema.String }));
|
|
39
|
+
const minted = (source) => source.kind === "given" ? Effect.succeed(Redacted.value(source.token))
|
|
40
|
+
: source.kind === "issuer" ? fromIssuer(source.issuer, source.client)
|
|
41
|
+
: fromGithub(source.requestUrl, source.requestToken);
|
|
42
|
+
export const Verdicts = {
|
|
43
|
+
sourceOf: (env) => {
|
|
44
|
+
const [given, issuer, requestUrl, requestToken] = [env[Names.variable("LOGBOOK_TOKEN")], env[Names.variable("OIDC_ISSUER")], env["ACTIONS_ID_TOKEN_REQUEST_URL"], env["ACTIONS_ID_TOKEN_REQUEST_TOKEN"]];
|
|
45
|
+
if (given)
|
|
46
|
+
return Effect.succeed({ kind: "given", token: Redacted.make(given) });
|
|
47
|
+
if (issuer)
|
|
48
|
+
return Effect.succeed({ kind: "issuer", issuer, client: env[Names.variable("OIDC_CLIENT")] || "ci-main" });
|
|
49
|
+
if (requestUrl && requestToken)
|
|
50
|
+
return Effect.succeed({ kind: "github", requestUrl, requestToken: Redacted.make(requestToken) });
|
|
51
|
+
return Effect.fail(failed("no way to sign a write to the logbook: set ORTHO_OIDC_ISSUER (and ORTHO_OIDC_CLIENT), or ORTHO_LOGBOOK_TOKEN, or run in a GitHub Actions job with id-token: write"));
|
|
52
|
+
},
|
|
53
|
+
mint: (source) => minted(source).pipe(Effect.map(Redacted.make)),
|
|
54
|
+
latest: ({ logbook, revision, environment, ref }) => Effect.gen(function* () {
|
|
55
|
+
const query = new URLSearchParams({ revision, environment, ref });
|
|
56
|
+
const response = yield* request("the logbook", `${logbook}/verdicts/latest?${query}`, {});
|
|
57
|
+
if (!response.ok)
|
|
58
|
+
return yield* failed(`the logbook would not give ${environment}'s verdicts for ${revision} (${response.status})`);
|
|
59
|
+
const body = yield* Effect.tryPromise({ try: () => response.json(), catch: () => failed("the logbook's verdicts were not JSON") });
|
|
60
|
+
return yield* Schema.decodeUnknownEffect(HeldRows)(body).pipe(Effect.mapError((e) => failed(`the logbook's verdicts were not as expected: ${e.message}`)));
|
|
61
|
+
}),
|
|
62
|
+
post: ({ logbook, token, revision, environment, sha256, results }) => Effect.forEach(results, (r) => Effect.gen(function* () {
|
|
63
|
+
const response = yield* request("the logbook", `${logbook}/verdicts`, {
|
|
64
|
+
method: "POST",
|
|
65
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${Redacted.value(token)}` },
|
|
66
|
+
body: JSON.stringify({ revision, environment, ...r, ...(sha256 === undefined ? {} : { sha256 }) }),
|
|
67
|
+
});
|
|
68
|
+
if (!response.ok)
|
|
69
|
+
return yield* failed(`the logbook refused ${r.operation} (${response.status})`);
|
|
70
|
+
}), { discard: true }),
|
|
71
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type Effect, type Redacted } from "effect";
|
|
2
|
+
/** The process environment, as only an entry file reads it. */
|
|
3
|
+
export type Env = Readonly<Record<string, string | undefined>>;
|
|
4
|
+
declare const VerdictsFailed_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
5
|
+
readonly _tag: "VerdictsFailed";
|
|
6
|
+
} & Readonly<A>;
|
|
7
|
+
export declare class VerdictsFailed extends VerdictsFailed_base<{
|
|
8
|
+
readonly message: string;
|
|
9
|
+
}> {
|
|
10
|
+
}
|
|
11
|
+
/** Where the token that signs a write to the logbook comes from. */
|
|
12
|
+
export type TokenSource =
|
|
13
|
+
/** A token already in hand (`ORTHO_LOGBOOK_TOKEN`): another job's, or one a person minted. */
|
|
14
|
+
{
|
|
15
|
+
readonly kind: "given";
|
|
16
|
+
readonly token: Redacted.Redacted<string>;
|
|
17
|
+
}
|
|
18
|
+
/** An OIDC server that mints a token for a client (the local issuer, `ci-main`): client credentials. */
|
|
19
|
+
| {
|
|
20
|
+
readonly kind: "issuer";
|
|
21
|
+
readonly issuer: string;
|
|
22
|
+
readonly client: string;
|
|
23
|
+
}
|
|
24
|
+
/** The CI job's own token: GitHub Actions' request URL and the bearer that asks for it (`id-token: write`). */
|
|
25
|
+
| {
|
|
26
|
+
readonly kind: "github";
|
|
27
|
+
readonly requestUrl: string;
|
|
28
|
+
readonly requestToken: Redacted.Redacted<string>;
|
|
29
|
+
};
|
|
30
|
+
export interface JourneyVerdict {
|
|
31
|
+
readonly journey: string;
|
|
32
|
+
readonly modelHash: string;
|
|
33
|
+
/** Reads have no handler. */
|
|
34
|
+
readonly handlerHash: string | null;
|
|
35
|
+
readonly verdict: "pass" | "fail";
|
|
36
|
+
}
|
|
37
|
+
export interface Result {
|
|
38
|
+
readonly operation: string;
|
|
39
|
+
readonly verdict: "pass" | "fail";
|
|
40
|
+
readonly journeys?: ReadonlyArray<JourneyVerdict>;
|
|
41
|
+
}
|
|
42
|
+
/** A verdict as the logbook holds it (D3 #31): the fields a gate reads. */
|
|
43
|
+
export interface Held {
|
|
44
|
+
readonly revision: string;
|
|
45
|
+
readonly environment: string;
|
|
46
|
+
readonly operation: string;
|
|
47
|
+
readonly verdict: string;
|
|
48
|
+
readonly ref: string;
|
|
49
|
+
/** The signed proof's bundle. Legacy rows may omit it or hold null. */
|
|
50
|
+
readonly sha256?: string | null;
|
|
51
|
+
readonly journeys?: ReadonlyArray<JourneyVerdict> | null;
|
|
52
|
+
}
|
|
53
|
+
export interface VerdictsApi {
|
|
54
|
+
/**
|
|
55
|
+
* The one place a write's token source is decided, for verdicts and releases alike: `ORTHO_LOGBOOK_TOKEN` when set,
|
|
56
|
+
* else the local issuer (`ORTHO_OIDC_ISSUER`, client `ORTHO_OIDC_CLIENT`, default `ci-main`), else the CI job's own
|
|
57
|
+
* (`ACTIONS_ID_TOKEN_REQUEST_URL` and `_TOKEN`, which needs `id-token: write`).
|
|
58
|
+
*/
|
|
59
|
+
readonly sourceOf: (env: Env) => Effect.Effect<TokenSource, VerdictsFailed>;
|
|
60
|
+
/** A token for audience `ortho-logbook`. Redacted: it is never printed, logged or put in an error. */
|
|
61
|
+
readonly mint: (source: TokenSource) => Effect.Effect<Redacted.Redacted<string>, VerdictsFailed>;
|
|
62
|
+
/** One `POST <logbook>/verdicts` per result, in order; the first the logbook refuses stops it. */
|
|
63
|
+
readonly post: (options: {
|
|
64
|
+
readonly logbook: string;
|
|
65
|
+
readonly token: Redacted.Redacted<string>;
|
|
66
|
+
readonly revision: string;
|
|
67
|
+
readonly environment: string;
|
|
68
|
+
/** Omitted only by compatibility callers; such rows cannot authorize a promotion. */
|
|
69
|
+
readonly sha256?: string;
|
|
70
|
+
readonly results: ReadonlyArray<Result>;
|
|
71
|
+
}) => Effect.Effect<void, VerdictsFailed>;
|
|
72
|
+
/** The newest verdict of each operation among those posted from `ref` for `revision` in `environment` (`GET /verdicts/latest`, D3 #31). */
|
|
73
|
+
readonly latest: (options: {
|
|
74
|
+
readonly logbook: string;
|
|
75
|
+
readonly revision: string;
|
|
76
|
+
readonly environment: string;
|
|
77
|
+
readonly ref: string;
|
|
78
|
+
}) => Effect.Effect<ReadonlyArray<Held>, VerdictsFailed>;
|
|
79
|
+
}
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The newest modification time, in milliseconds, of any file under the project's sources (`fingerprint` says which); 0 when there are none. */
|
|
2
|
+
export declare const newestChange: (root: string) => number;
|
|
3
|
+
/**
|
|
4
|
+
* A hash of which source files there are and what each holds. A file added, deleted, renamed or edited changes it, which a
|
|
5
|
+
* newest-modification time cannot say of a deletion.
|
|
6
|
+
*/
|
|
7
|
+
export declare const fingerprint: (root: string) => string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { join, relative } from "node:path";
|
|
4
|
+
/** What a world of dev runs on: the handlers, the blueprint, everything generated, and (at the root) the config, the dependencies and the environment files. */
|
|
5
|
+
const FOLDERS = ["src", "blueprint", "generated"];
|
|
6
|
+
const ROOT_FILE = /^(ortho\.config\.[cm]?[jt]s|package\.json|pnpm-lock\.yaml|package-lock\.json|yarn\.lock|bun\.lockb?|\.env.*)$/;
|
|
7
|
+
/** Never input: installed packages, and wrangler's own bundles (its output). */
|
|
8
|
+
const SKIPPED = new Set(["node_modules", ".wrangler"]);
|
|
9
|
+
const filesUnder = (path) => statSync(path).isDirectory()
|
|
10
|
+
? readdirSync(path).filter((name) => !SKIPPED.has(name)).flatMap((name) => filesUnder(join(path, name)))
|
|
11
|
+
: [path];
|
|
12
|
+
const sourceFiles = (root) => [
|
|
13
|
+
...FOLDERS.map((part) => join(root, part)).filter(existsSync).flatMap(filesUnder),
|
|
14
|
+
...readdirSync(root).filter((name) => ROOT_FILE.test(name)).map((name) => join(root, name)).filter((file) => statSync(file).isFile()),
|
|
15
|
+
].sort();
|
|
16
|
+
/** The newest modification time, in milliseconds, of any file under the project's sources (`fingerprint` says which); 0 when there are none. */
|
|
17
|
+
export const newestChange = (root) => sourceFiles(root).reduce((newest, file) => Math.max(newest, statSync(file).mtimeMs), 0);
|
|
18
|
+
/**
|
|
19
|
+
* A hash of which source files there are and what each holds. A file added, deleted, renamed or edited changes it, which a
|
|
20
|
+
* newest-modification time cannot say of a deletion.
|
|
21
|
+
*/
|
|
22
|
+
export const fingerprint = (root) => {
|
|
23
|
+
const hash = createHash("sha256");
|
|
24
|
+
for (const file of sourceFiles(root))
|
|
25
|
+
hash.update(`${relative(root, file)}\0${createHash("sha256").update(readFileSync(file)).digest("hex")}\n`);
|
|
26
|
+
return hash.digest("hex");
|
|
27
|
+
};
|