@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,169 @@
|
|
|
1
|
+
import { filesOf, journeyDetail, stepDetail } from "./structured.js";
|
|
2
|
+
/**
|
|
3
|
+
* World facts predict the access refusal before the server answers: no span will come (O2, gap 3). A payload the server
|
|
4
|
+
* can't decode leaves no span either, and is left out on purpose: a journey's payload is encoded from its declaration
|
|
5
|
+
* before it is sent, so that refusal is not one a journey predicts, and its missing telemetry stays a failure.
|
|
6
|
+
*/
|
|
7
|
+
export const refusedBeforeSpan = (call) => call?.mayCall === false && call.status === 403 &&
|
|
8
|
+
typeof call.body === "object" && call.body !== null && "_tag" in call.body && call.body._tag === "NotAllowed";
|
|
9
|
+
/** A call that has no span of its own to wait for: a refusal the world's facts predicted, the MCP door's tools list (`.tools()`), a step that moves the world's clock or a command to a stand-in, which run no operation. */
|
|
10
|
+
export const noSpanExpected = (call) => call?.tools === true || call?.clock === true || call?.stand === true || refusedBeforeSpan(call);
|
|
11
|
+
/** The distinct spans a call's trace held, by name: what a missing span is read against. Sorted, since start times of concurrent spans differ between runs. */
|
|
12
|
+
const spansCame = (trace) => [...new Set((trace?.spans ?? []).map((s) => s.name))].sort().join(", ");
|
|
13
|
+
/** A step's span checks, now that its trace is in, with what was expected and what came back. */
|
|
14
|
+
const spanFindings = (step, trace, call) => {
|
|
15
|
+
const names = new Set((trace?.spans ?? []).map((s) => s.name));
|
|
16
|
+
if (names.size === 0 && !noSpanExpected(call)) {
|
|
17
|
+
return [{ message: "telemetry missing: no span of this call reached the collector", expected: "spans from the call", got: "none" }];
|
|
18
|
+
}
|
|
19
|
+
return [
|
|
20
|
+
...step.spans.present.filter((n) => !names.has(n)).map((n) => ({
|
|
21
|
+
message: `span ${n} missing: expected present, the call produced ${spansCame(trace)}`, expected: `span ${n} present`, got: spansCame(trace),
|
|
22
|
+
})),
|
|
23
|
+
...step.spans.absent.filter((n) => names.has(n)).map((n) => ({ message: `span ${n} present, expected absent`, expected: `span ${n} absent`, got: "present" })),
|
|
24
|
+
];
|
|
25
|
+
};
|
|
26
|
+
export const spanFailures = (step, trace, call) => spanFindings(step, trace, call).map((f) => f.message);
|
|
27
|
+
/** The defect a call's span recorded when the server died (`BlankReached`, or the error's message), if any. */
|
|
28
|
+
const defectOf = (trace) => {
|
|
29
|
+
const defect = trace?.spans.find((s) => typeof s.attrs["defect"] === "string")?.attrs["defect"];
|
|
30
|
+
const said = typeof defect === "string" ? defect.replace(/:\s*$/, "").trim() : "";
|
|
31
|
+
return said === "" ? undefined : said;
|
|
32
|
+
};
|
|
33
|
+
/** Why a starting world stopped, with the defect the operation's span recorded when the server died. */
|
|
34
|
+
const stoppedLine = (run, traces) => {
|
|
35
|
+
const last = run.calls[run.calls.length - 1];
|
|
36
|
+
const defect = last ? defectOf(traces.get(last.trace)) : undefined;
|
|
37
|
+
return `journey ${run.name} ✘ ${run.stopped}${defect ? ` (${defect})` : ""}; no step ran`;
|
|
38
|
+
};
|
|
39
|
+
/** A failed step whose call died says what it died of, from the call's own span. */
|
|
40
|
+
const diedOf = (trace, call) => {
|
|
41
|
+
const defect = call !== undefined && call.status >= 500 ? defectOf(trace) : undefined;
|
|
42
|
+
return defect ? [`the server died: ${defect}`] : [];
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Where a failing step's operation lives: its handler (`src/<thing>/<verb>.ts`) and the declaration it answers to, both
|
|
46
|
+
* relative to the project root. `undefined` when the step made no call or the model does not know the operation.
|
|
47
|
+
*/
|
|
48
|
+
export const whereLine = (model, call) => {
|
|
49
|
+
const files = filesOf(model, call);
|
|
50
|
+
if (files === undefined)
|
|
51
|
+
return undefined;
|
|
52
|
+
return files.handler === undefined
|
|
53
|
+
? `declared in ${files.declaration} (${files.operation}, a read: no handler)`
|
|
54
|
+
: `handler ${files.handler}, declared in ${files.declaration} (${files.operation})`;
|
|
55
|
+
};
|
|
56
|
+
/** `spans: false` judges the answers, refusals and events only: a staging run has no collector, so no step is failed for the spans it could not read. */
|
|
57
|
+
export const journeyLines = (runs, traces, empty = false, model, spans = true) => {
|
|
58
|
+
const lines = [];
|
|
59
|
+
/** The traces of every call that went wrong, for `prove --view` to point at. */
|
|
60
|
+
const failedTraces = [];
|
|
61
|
+
const details = [];
|
|
62
|
+
let failed = 0;
|
|
63
|
+
for (const run of runs) {
|
|
64
|
+
if (run.stopped) {
|
|
65
|
+
details.push(journeyDetail(run, []));
|
|
66
|
+
lines.push(stoppedLine(run, traces));
|
|
67
|
+
const last = run.calls[run.calls.length - 1];
|
|
68
|
+
if (last)
|
|
69
|
+
failedTraces.push({ trace: last.trace, what: `journey ${run.name}` });
|
|
70
|
+
failed++;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const calls = new Map(run.calls.map((call) => [call.trace, call]));
|
|
74
|
+
const steps = run.steps.map((s) => {
|
|
75
|
+
const trace = traces.get(s.trace);
|
|
76
|
+
const call = calls.get(s.trace);
|
|
77
|
+
const spanned = spans ? spanFindings(s, trace, call) : [];
|
|
78
|
+
const detail = (failures) => stepDetail(model, s, failures, spanned, trace, call);
|
|
79
|
+
if (empty) {
|
|
80
|
+
// prove --empty (M1.16): a step whose handler is blank fails by the defect it reached, first.
|
|
81
|
+
const defect = trace?.spans.find((span) => typeof span.attrs["defect"] === "string")?.attrs["defect"];
|
|
82
|
+
const failedCall = typeof defect === "string" ? [defect] : call && call.status >= 500 ? [`failed with ${call.status}`] : [];
|
|
83
|
+
const failures = [...failedCall, ...s.failures, ...spanned.map((f) => f.message)];
|
|
84
|
+
return { s, failures, detail: detail(failures) };
|
|
85
|
+
}
|
|
86
|
+
const raised = [...s.failures, ...spanned.map((f) => f.message)];
|
|
87
|
+
const failures = raised.length > 0 ? [...raised, ...diedOf(trace, call)] : raised;
|
|
88
|
+
return { s, failures, detail: detail(failures) };
|
|
89
|
+
});
|
|
90
|
+
details.push(journeyDetail(run, steps.map((x) => x.detail)));
|
|
91
|
+
const bad = steps.filter((x) => x.failures.length > 0);
|
|
92
|
+
lines.push(`journey ${run.name} ${bad.length === 0 ? "✔" : "✘"} ${steps.length - bad.length}/${steps.length} steps`);
|
|
93
|
+
if (empty) {
|
|
94
|
+
for (const { s, failures } of steps) {
|
|
95
|
+
lines.push(failures.length === 0
|
|
96
|
+
? ` ✔ "${s.title}": proved by the description`
|
|
97
|
+
: ` ✘ "${s.title}": ${failures.join("; ")}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
for (const { s, failures } of bad) {
|
|
102
|
+
for (const f of failures)
|
|
103
|
+
lines.push(` ✘ "${s.title}": ${f}`);
|
|
104
|
+
const where = whereLine(model, calls.get(s.trace));
|
|
105
|
+
if (where !== undefined)
|
|
106
|
+
lines.push(` ✘ "${s.title}": ${where}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (const s of run.skipped ?? [])
|
|
110
|
+
lines.push(` skipped "${s.step}": it runs ${s.operation}, which ${s.file} omits`);
|
|
111
|
+
for (const { s } of bad)
|
|
112
|
+
failedTraces.push({ trace: s.trace, what: `${run.name} "${s.title}"` });
|
|
113
|
+
failed += bad.length;
|
|
114
|
+
}
|
|
115
|
+
return { lines, failed, failedTraces, details };
|
|
116
|
+
};
|
|
117
|
+
export const evalLines = (model, verdicts) => {
|
|
118
|
+
const lines = [];
|
|
119
|
+
let failed = 0;
|
|
120
|
+
for (const op of Object.keys(model.operations)) {
|
|
121
|
+
const mine = verdicts.filter((v) => v.operation === op);
|
|
122
|
+
for (const v of mine) {
|
|
123
|
+
if (v.failures.length === 0)
|
|
124
|
+
lines.push(`${op} ${v.eval} ✔${v.notes.length ? ` ${v.notes.join("; ")}` : ""}`);
|
|
125
|
+
for (const f of v.failures)
|
|
126
|
+
lines.push(`${op} ${v.eval} ✘ ${f}`);
|
|
127
|
+
}
|
|
128
|
+
const bad = mine.filter((v) => v.failures.length > 0).length;
|
|
129
|
+
const timing = mine.find((v) => v.eval === "performance")?.notes[0];
|
|
130
|
+
lines.push((bad === 0 ? `${op} ${mine.length} evals ✔` : `${op} ${bad} of ${mine.length} evals ✘`) + (timing ? ` ${timing}` : ""));
|
|
131
|
+
failed += bad;
|
|
132
|
+
}
|
|
133
|
+
for (const v of verdicts.filter((x) => x.operation === undefined)) {
|
|
134
|
+
lines.push(`${v.eval} ${v.failures.length === 0 ? "✔" : "✘"} ${v.notes.join("; ")}`);
|
|
135
|
+
for (const f of v.failures)
|
|
136
|
+
lines.push(`${v.eval} ✘ ${f}`);
|
|
137
|
+
if (v.failures.length > 0)
|
|
138
|
+
failed++;
|
|
139
|
+
}
|
|
140
|
+
return { lines, failed };
|
|
141
|
+
};
|
|
142
|
+
/** Optional paths are counted from successful journey calls that actually ran the handler. */
|
|
143
|
+
export const optionalStepLines = (model, runs, evidence) => {
|
|
144
|
+
const optional = Object.values(model.operations).flatMap((op) => Object.values(op.steps).filter((step) => step.optional).map((step) => ({ operation: op.name, step: step.name })));
|
|
145
|
+
if (optional.length === 0)
|
|
146
|
+
return [];
|
|
147
|
+
const journeyTraces = new Set(runs.flatMap((run) => run.steps.map((step) => step.trace)));
|
|
148
|
+
const calls = evidence.flatMap(({ call, trace }) => {
|
|
149
|
+
if (call.status !== 200 || !journeyTraces.has(call.trace))
|
|
150
|
+
return [];
|
|
151
|
+
const answer = trace.spans.filter((span) => span.name === call.operation)
|
|
152
|
+
.sort((a, b) => Number(b.attrs["attempt"] ?? 0) - Number(a.attrs["attempt"] ?? 0) || b.start - a.start)[0];
|
|
153
|
+
if (!answer || answer.attrs["request.replayed"] === true)
|
|
154
|
+
return [];
|
|
155
|
+
const parents = new Set([answer.spanId]);
|
|
156
|
+
const names = new Set();
|
|
157
|
+
for (const id of parents) {
|
|
158
|
+
for (const span of trace.spans.filter((item) => item.parentSpanId === id)) {
|
|
159
|
+
parents.add(span.spanId);
|
|
160
|
+
names.add(span.name);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return [{ operation: call.operation, names }];
|
|
164
|
+
});
|
|
165
|
+
return optional.flatMap(({ operation, step }) => {
|
|
166
|
+
const observed = new Set(calls.filter((call) => call.operation === operation).map(({ names }) => names.has(step)));
|
|
167
|
+
return observed.size === 2 ? [] : [`warning: ${step} never exercised both ways (${observed.has(true) ? "always ran" : "never ran"})`];
|
|
168
|
+
});
|
|
169
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { Model } from "@orthograph/compiler";
|
|
3
|
+
import type { Facts, Project } from "#modules/journeys/types.js";
|
|
4
|
+
import { ProveFailed, type Report } from "../types.ts";
|
|
5
|
+
/**
|
|
6
|
+
* The journeys named in `only` (every one when it is empty), each once and in file order; the first name that is no journey is refused
|
|
7
|
+
* before the address is asked anything. Every chosen journey runs, a failing one too, and the verdict is all of theirs (CX-staging).
|
|
8
|
+
*/
|
|
9
|
+
export declare const provedAt: (model: Model, project: Project, url: string, label: string, only: ReadonlyArray<string>, facts?: Facts) => Effect.Effect<Report, ProveFailed>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// `ortho prove --env staging --run <id>`: the journeys, judged against a Worker that is already deployed, in no world of the run's own.
|
|
2
|
+
import { Duration, Effect } from "effect";
|
|
3
|
+
import { Journeys } from "#modules/journeys/service.js";
|
|
4
|
+
import { ProveFailed } from "../types.js";
|
|
5
|
+
import { journeyLines } from "./report.js";
|
|
6
|
+
import { proveReport } from "./structured.js";
|
|
7
|
+
/**
|
|
8
|
+
* The address answers, and it is the project's server: Better Auth's own health route is not a 404. A Worker that was never deployed
|
|
9
|
+
* answers 404 to every route; nothing listening is no answer at all. One GET, so no operation is asked before the story runs.
|
|
10
|
+
*/
|
|
11
|
+
const answers = (url) => Effect.promise(() => fetch(`${url}/api/auth/ok`, { signal: AbortSignal.timeout(15_000) }).then((r) => r.status !== 404, () => false));
|
|
12
|
+
/**
|
|
13
|
+
* The journeys named in `only` (every one when it is empty), each once and in file order; the first name that is no journey is refused
|
|
14
|
+
* before the address is asked anything. Every chosen journey runs, a failing one too, and the verdict is all of theirs (CX-staging).
|
|
15
|
+
*/
|
|
16
|
+
export const provedAt = (model, project, url, label, only, facts) => Effect.gen(function* () {
|
|
17
|
+
const unknown = only.find((name) => !project.journeys.some((journey) => journey.name === name));
|
|
18
|
+
if (unknown !== undefined)
|
|
19
|
+
return yield* new ProveFailed({ message: `no journey named "${unknown}"` });
|
|
20
|
+
const journeys = only.length === 0 ? project.journeys : project.journeys.filter((journey) => only.includes(journey.name));
|
|
21
|
+
if (journeys.length === 0)
|
|
22
|
+
return yield* new ProveFailed({ message: "the project declares no journeys" });
|
|
23
|
+
if (!(yield* answers(url)))
|
|
24
|
+
return yield* new ProveFailed({ message: `nothing answers as the project's server at ${url} (${label}): it was not deployed, or it is not up` });
|
|
25
|
+
const [took, runs] = yield* Effect.timed(Effect.forEach(journeys, (journey, i) => Journeys.run(project, url, journey, i, "sign-up", facts)));
|
|
26
|
+
const done = journeyLines(runs, new Map(), false, model, false);
|
|
27
|
+
const lines = [...done.lines, done.failed === 0 ? "prove ✔" : `prove ✘ ${done.failed} failing`];
|
|
28
|
+
const passed = done.failed === 0;
|
|
29
|
+
return { lines, passed, structured: proveReport(done.details, 0, Math.round(Duration.toMillis(took)) / 1000, lines, passed) };
|
|
30
|
+
}).pipe(Effect.catchDefect((defect) => Effect.fail(new ProveFailed({ message: defect instanceof Error ? defect.message : `the run could not be judged (${label})` }))));
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Effect, type Scope } from "effect";
|
|
2
|
+
import { type Model } from "@orthograph/compiler";
|
|
3
|
+
import { WorldFailed, type StandIns } from "#modules/world/types.js";
|
|
4
|
+
import type { DeviceHost } from "#modules/journeys/types.js";
|
|
5
|
+
import type { TraceSource } from "#modules/telemetry/types.js";
|
|
6
|
+
import { ProveFailed } from "../types.ts";
|
|
7
|
+
/** The longest window a derived alert names (3 days): the most history a world's feed supplies for monitoring, apart from the Calls page's display window. */
|
|
8
|
+
export declare const PORTAL_HISTORY_MS: number;
|
|
9
|
+
/** The portal reads a world's last half hour: check 21's window, and the portal's own default. */
|
|
10
|
+
export declare const PORTAL_WINDOW_MS: number;
|
|
11
|
+
export interface Stand {
|
|
12
|
+
readonly url: string;
|
|
13
|
+
readonly collector: TraceSource;
|
|
14
|
+
/** Where the run's own spans (the journeys' roots) are exported. */
|
|
15
|
+
readonly otlp: string;
|
|
16
|
+
readonly device: DeviceHost | undefined;
|
|
17
|
+
/** The address of each stand-in this world stood up, by mount; a warm world has none. */
|
|
18
|
+
readonly stands: Readonly<Record<string, string>>;
|
|
19
|
+
/** What to say before the journeys. */
|
|
20
|
+
readonly notes: ReadonlyArray<string>;
|
|
21
|
+
}
|
|
22
|
+
interface Wanted {
|
|
23
|
+
readonly root: string;
|
|
24
|
+
/** Where the world's files live: the project, or the scaffold world of `--empty`. */
|
|
25
|
+
readonly world: string;
|
|
26
|
+
readonly model: Model;
|
|
27
|
+
readonly port: number;
|
|
28
|
+
readonly empty: boolean;
|
|
29
|
+
readonly env: Readonly<Record<string, string | undefined>> | undefined;
|
|
30
|
+
}
|
|
31
|
+
/** Whether a prove of this model needs stand-ins, so a world of its own: a warm `ortho dev` world has none. */
|
|
32
|
+
export declare const needsStandIns: (model: Model) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Each process stand-in of the model, started under `<state>/stands/<mount>` and stopped, all together, when the scope
|
|
35
|
+
* closes. What the Worker is told: `ORTHO_STAND_<MOUNT>` and `<MOUNT>_API_KEY` = `world-<mount>`.
|
|
36
|
+
*/
|
|
37
|
+
export declare const standIns: (root: string, model: Model) => (state: string) => Effect.Effect<StandIns, WorldFailed, Scope.Scope>;
|
|
38
|
+
/** The world warm if there is one to use, else the run's own. */
|
|
39
|
+
export declare const standWorld: (wanted: Wanted) => Effect.Effect<Stand, ProveFailed, Scope.Scope>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// The world a prove runs in: one of its own (started, and stopped when the scope closes), or the warm one `ortho dev` keeps (ST1.24).
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { mkdirSync, readFileSync } from "node:fs";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
import { Names } from "orthograph/server";
|
|
7
|
+
import { packageDir } from "@orthograph/compiler";
|
|
8
|
+
import { Timers, TimersLive } from "@orthograph/language-effect";
|
|
9
|
+
import { WorldFailed } from "#modules/world/types.js";
|
|
10
|
+
import { PortalFeed } from "#modules/portal-feed/service.js";
|
|
11
|
+
import { Sinks } from "#modules/sinks/service.js";
|
|
12
|
+
import { Collectors, FileMetrics, privateKeys } from "#modules/telemetry/service.js";
|
|
13
|
+
import { Warm } from "#modules/warm/service.js";
|
|
14
|
+
import { Worlds } from "#modules/world/service.js";
|
|
15
|
+
import { ProveFailed } from "../types.js";
|
|
16
|
+
import { deviceHost, needsDevice, standChain } from "./device-host.js";
|
|
17
|
+
/** The longest window a derived alert names (3 days): the most history a world's feed supplies for monitoring, apart from the Calls page's display window. */
|
|
18
|
+
export const PORTAL_HISTORY_MS = 3 * 24 * 60 * 60_000;
|
|
19
|
+
/** The portal reads a world's last half hour: check 21's window, and the portal's own default. */
|
|
20
|
+
export const PORTAL_WINDOW_MS = 30 * 60_000;
|
|
21
|
+
const failed = (e) => new ProveFailed({ message: e.message });
|
|
22
|
+
/** A mount's name as the Worker's environment spells it: `fx-backup` is `FX_BACKUP`. */
|
|
23
|
+
const envName = (mount) => mount.toUpperCase().replaceAll("-", "_");
|
|
24
|
+
/** The mounts whose adapter declared a process stand-in (G16-adapter-mounts call 3): the model decides, never what a package names. */
|
|
25
|
+
const processMounts = (model) => Object.entries(model.mounts ?? {}).filter(([, m]) => m.kind === "adapter" && m.standIn?.how === "process");
|
|
26
|
+
/** Whether a prove of this model needs stand-ins, so a world of its own: a warm `ortho dev` world has none. */
|
|
27
|
+
export const needsStandIns = (model) => processMounts(model).length > 0;
|
|
28
|
+
const LINE = /^stand-in listening on (\S+)$/;
|
|
29
|
+
const KEEP = 4096;
|
|
30
|
+
/** How long a stand-in may take to say where it listens, and its grace between SIGTERM and SIGKILL (at most 10 s). */
|
|
31
|
+
const SILENCE = "60 seconds";
|
|
32
|
+
const GRACE = "5 seconds";
|
|
33
|
+
/** `node <entry> --port 0 --dir <dir>` in the package's folder, in a process group of its own so all it starts is stopped with it. */
|
|
34
|
+
const spawnStandIn = (mount, cwd, entry, dir) => {
|
|
35
|
+
const child = spawn(process.execPath, [join(cwd, entry), "--port", "0", "--dir", dir], { cwd, stdio: ["ignore", "pipe", "pipe"], detached: true });
|
|
36
|
+
let tail = "";
|
|
37
|
+
let pending = "";
|
|
38
|
+
let url;
|
|
39
|
+
let closed = false;
|
|
40
|
+
const waiters = [];
|
|
41
|
+
const settle = (found) => { for (const w of waiters.splice(0))
|
|
42
|
+
w(found); };
|
|
43
|
+
const keep = (chunk) => { tail = (tail + chunk).slice(-KEEP); };
|
|
44
|
+
// Both pipes are read for as long as the stand-in lives: one that goes on talking after its line never blocks.
|
|
45
|
+
child.stderr.setEncoding("utf8").on("data", keep);
|
|
46
|
+
child.stdout.setEncoding("utf8").on("data", (chunk) => {
|
|
47
|
+
keep(chunk);
|
|
48
|
+
if (url !== undefined)
|
|
49
|
+
return;
|
|
50
|
+
pending += chunk;
|
|
51
|
+
const lines = pending.split("\n");
|
|
52
|
+
pending = lines.pop();
|
|
53
|
+
const found = lines.map((l) => LINE.exec(l.replace(/\r$/, ""))?.[1]).find((u) => u !== undefined);
|
|
54
|
+
if (found !== undefined) {
|
|
55
|
+
url = found;
|
|
56
|
+
pending = "";
|
|
57
|
+
settle(Effect.succeed(found));
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const gone = (why) => new WorldFailed({ message: `the stand-in for mount ${mount} ${why} before it said where it listens (${join(cwd, entry)}):\n${tail.trimEnd()}` });
|
|
61
|
+
child.once("close", () => { closed = true; });
|
|
62
|
+
// `exit` comes before the pipes are read to the end: what it said last (its crash) is waited for, a second at most, since a child of its own may hold them open.
|
|
63
|
+
const drained = Effect.callback((resume) => { if (closed)
|
|
64
|
+
return resume(Effect.void); child.once("close", () => resume(Effect.void)); });
|
|
65
|
+
const exitedEarly = (why) => Effect.gen(function* () {
|
|
66
|
+
yield* Effect.raceFirst(drained, (yield* Timers).sleep("prove.stand-in.drain", "1 second"));
|
|
67
|
+
return yield* Effect.fail(gone(why));
|
|
68
|
+
});
|
|
69
|
+
const exitWhy = () => `exited (${child.signalCode ?? child.exitCode})`;
|
|
70
|
+
child.once("error", (e) => settle(Effect.fail(gone(`could not start (${e.message})`))));
|
|
71
|
+
child.once("exit", () => { if (url === undefined)
|
|
72
|
+
settle(exitedEarly(exitWhy())); });
|
|
73
|
+
const listening = Effect.callback((resume) => {
|
|
74
|
+
if (url !== undefined)
|
|
75
|
+
return resume(Effect.succeed(url));
|
|
76
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
77
|
+
return resume(exitedEarly(exitWhy()));
|
|
78
|
+
waiters.push(resume);
|
|
79
|
+
});
|
|
80
|
+
return { mount, child, listening };
|
|
81
|
+
};
|
|
82
|
+
/** A signal to the stand-in's whole group; one already gone is no matter. */
|
|
83
|
+
const signalGroup = (child, signal) => Effect.try({ try: () => (child.pid === undefined ? undefined : process.kill(-child.pid, signal)), catch: () => undefined }).pipe(Effect.ignore);
|
|
84
|
+
const exited = (child) => Effect.callback((resume) => {
|
|
85
|
+
if (child.pid === undefined || child.exitCode !== null || child.signalCode !== null)
|
|
86
|
+
return resume(Effect.void);
|
|
87
|
+
child.once("exit", () => resume(Effect.void));
|
|
88
|
+
});
|
|
89
|
+
/** SIGTERM to the stand-in's group, SIGKILL to it once the stand-in has gone or the grace is up: its children go too. */
|
|
90
|
+
const stopStandIn = (child) => Effect.gen(function* () {
|
|
91
|
+
const timers = yield* Timers;
|
|
92
|
+
yield* signalGroup(child, "SIGTERM");
|
|
93
|
+
yield* Effect.raceFirst(exited(child), timers.sleep("prove.stand-in.stop", GRACE));
|
|
94
|
+
yield* signalGroup(child, "SIGKILL");
|
|
95
|
+
yield* exited(child);
|
|
96
|
+
});
|
|
97
|
+
/**
|
|
98
|
+
* Each process stand-in of the model, started under `<state>/stands/<mount>` and stopped, all together, when the scope
|
|
99
|
+
* closes. What the Worker is told: `ORTHO_STAND_<MOUNT>` and `<MOUNT>_API_KEY` = `world-<mount>`.
|
|
100
|
+
*/
|
|
101
|
+
export const standIns = (root, model) => (state) => Effect.gen(function* () {
|
|
102
|
+
const unfit = (message) => Effect.fail(new WorldFailed({ message: `the stand-ins couldn't start: ${message}` }));
|
|
103
|
+
const wanted = yield* Effect.forEach(processMounts(model), ([mount, m]) => {
|
|
104
|
+
const dir = packageDir(root, m.package);
|
|
105
|
+
if (dir === undefined)
|
|
106
|
+
return unfit(`mount ${mount}: ${m.package} is not installed`);
|
|
107
|
+
return Effect.try({
|
|
108
|
+
try: () => JSON.parse(readFileSync(join(dir, "package.json"), "utf8")).orthograph?.standIn,
|
|
109
|
+
catch: () => new WorldFailed({ message: `the stand-ins couldn't start: mount ${mount}: ${m.package}'s package.json can't be read` }),
|
|
110
|
+
}).pipe(Effect.flatMap((entry) => typeof entry === "string" ? Effect.succeed({ mount, dir, entry })
|
|
111
|
+
: unfit(`mount ${mount}: ${m.package}'s package.json names no orthograph.standIn, and its adapter stands in as a process`)));
|
|
112
|
+
});
|
|
113
|
+
if (wanted.length === 0)
|
|
114
|
+
return { env: {}, addresses: {} };
|
|
115
|
+
// Every folder is made before any stand-in starts: a failure here leaves nothing running, and the spawns that follow don't throw.
|
|
116
|
+
const dirs = yield* Effect.try({
|
|
117
|
+
try: () => wanted.map(({ mount }) => { const dir = join(state, "stands", mount); mkdirSync(dir, { recursive: true }); return dir; }),
|
|
118
|
+
catch: (e) => new WorldFailed({ message: `the stand-ins couldn't start: their folders under ${join(state, "stands")} couldn't be made (${String(e)})` }),
|
|
119
|
+
});
|
|
120
|
+
const running = yield* Effect.acquireRelease(Effect.sync(() => wanted.map(({ mount, dir, entry }, i) => spawnStandIn(mount, dir, entry, dirs[i]))), (all) => Effect.forEach(all, (r) => stopStandIn(r.child), { concurrency: "unbounded", discard: true }).pipe(Effect.provide(TimersLive)));
|
|
121
|
+
const urls = yield* Effect.forEach(running, (r) => Effect.raceFirst(r.listening, Effect.gen(function* () { yield* (yield* Timers).sleep("prove.stand-in.listen", SILENCE); }).pipe(Effect.andThen(Effect.fail(new WorldFailed({ message: `the stand-in for mount ${r.mount} said no "stand-in listening on <url>" line within 60 s` }))))), { concurrency: "unbounded" }).pipe(Effect.provide(TimersLive));
|
|
122
|
+
return {
|
|
123
|
+
env: Object.fromEntries(running.flatMap((r, i) => [[`ORTHO_STAND_${envName(r.mount)}`, urls[i]], [`${envName(r.mount)}_API_KEY`, `world-${r.mount}`]])),
|
|
124
|
+
addresses: Object.fromEntries(running.map((r, i) => [r.mount, urls[i]])),
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
/** The warm world of a live `ortho dev`, emptied; `undefined` when a prove must have one of its own (or there is none to use). */
|
|
128
|
+
const warmWorld = ({ root, model, port, empty }) => Effect.gen(function* () {
|
|
129
|
+
// A scaffold world, a chosen port, a device chain and a mount's stand-in are each a world of the run's own making.
|
|
130
|
+
if (empty || port !== 0 || needsDevice(model) || needsStandIns(model))
|
|
131
|
+
return undefined;
|
|
132
|
+
const record = yield* Warm.find(root);
|
|
133
|
+
if (record === undefined)
|
|
134
|
+
return undefined;
|
|
135
|
+
// Another prove is running in it: resetting now would empty the world under that run, so this one starts a world of its own.
|
|
136
|
+
if (!(yield* Warm.lock(root)))
|
|
137
|
+
return undefined;
|
|
138
|
+
yield* Warm.reset(record).pipe(Effect.mapError(failed));
|
|
139
|
+
return { url: record.url, collector: Collectors.read(record.telemetry), otlp: record.collector, device: undefined, stands: {}, notes: [`prove: reusing the world of ortho dev at ${record.url}`] };
|
|
140
|
+
});
|
|
141
|
+
/** A fresh world and collector of the run's own. */
|
|
142
|
+
const ownWorld = ({ root, world, model, port, empty, env }) => Effect.gen(function* () {
|
|
143
|
+
const dir = resolve(world, Names.folder, "prove-telemetry");
|
|
144
|
+
const collector = yield* Collectors.local(dir, privateKeys(model)).pipe(Effect.mapError(failed));
|
|
145
|
+
const sinks = yield* Sinks.resolve({ sinks: empty ? [{ sink: "local" }] : model.environments?.["local"]?.telemetry ?? [{ sink: "local" }], env: env ?? {} });
|
|
146
|
+
// A plugin that runs operations on the device gets a chain in the world (Anvil as a process, K7 Q7), released after the Worker.
|
|
147
|
+
const stood = yield* standChain(model);
|
|
148
|
+
// The world's portal reads this run's telemetry through a feed this process answers (the Worker cannot open the collector's files).
|
|
149
|
+
const feed = yield* PortalFeed.serve({ source: collector, metrics: FileMetrics.open(dir), environment: "local", windowMs: PORTAL_WINDOW_MS, historyMs: PORTAL_HISTORY_MS }).pipe(Effect.mapError(failed));
|
|
150
|
+
const { url, chain, stands } = yield* Worlds.start({ root: world, port, name: "prove", otlp: collector.url, portalFeed: feed.url, environment: "local", secretEnv: sinks.secretEnv, stands: standIns(root, model), ...(stood.chain ? { chain: Effect.succeed(stood.chain) } : {}) }).pipe(Effect.mapError(failed));
|
|
151
|
+
const device = needsDevice(model) ? yield* deviceHost(world, collector.url, chain).pipe(Effect.mapError(failed)) : undefined;
|
|
152
|
+
return { url, collector, otlp: collector.url, device, stands: stands ?? {}, notes: [...sinks.notes, ...stood.notes] };
|
|
153
|
+
});
|
|
154
|
+
/** The world warm if there is one to use, else the run's own. */
|
|
155
|
+
export const standWorld = (wanted) => warmWorld(wanted).pipe(Effect.flatMap((warm) => (warm === undefined ? ownWorld(wanted) : Effect.succeed(warm))));
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type Model } from "@orthograph/compiler";
|
|
2
|
+
import type { CallRecord, JourneyRun, StepResult } from "#modules/journeys/types.js";
|
|
3
|
+
import type { Trace } from "#modules/telemetry/types.js";
|
|
4
|
+
/** One thing that went wrong in a step: the sentence prove prints, and the two halves of it when it has them. */
|
|
5
|
+
export interface FailureDetail {
|
|
6
|
+
readonly message: string;
|
|
7
|
+
readonly expected?: string;
|
|
8
|
+
readonly got?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface StepDetail {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly verdict: "pass" | "fail";
|
|
13
|
+
/** The first failure's halves, for a reader that wants one pair. */
|
|
14
|
+
readonly expected?: string;
|
|
15
|
+
readonly got?: string;
|
|
16
|
+
readonly failures: ReadonlyArray<FailureDetail>;
|
|
17
|
+
/** The operation the step ran, the handler that answers it and the declaration it answers to (relative to the project root). */
|
|
18
|
+
readonly operation?: string;
|
|
19
|
+
/** Absent for a read (answered from the records, no handler). A plugin's client operation has one entry per host: the first is named here. */
|
|
20
|
+
readonly handlerFile?: string;
|
|
21
|
+
readonly declarationFile?: string;
|
|
22
|
+
/** Milliseconds the call's own span took, as the collector heard it; `null` when no span named for the operation reached the collector; absent when the step made no call. */
|
|
23
|
+
readonly ms?: number | null;
|
|
24
|
+
}
|
|
25
|
+
export interface JourneyDetail {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly verdict: "pass" | "fail";
|
|
28
|
+
/** Why its starting world stopped, when it did: no step ran. */
|
|
29
|
+
readonly stopped?: string;
|
|
30
|
+
readonly steps: ReadonlyArray<StepDetail>;
|
|
31
|
+
readonly skipped: ReadonlyArray<{
|
|
32
|
+
readonly step: string;
|
|
33
|
+
readonly operation: string;
|
|
34
|
+
readonly file: string;
|
|
35
|
+
}>;
|
|
36
|
+
readonly ms: number;
|
|
37
|
+
}
|
|
38
|
+
/** The structured report: per journey, per step, totals and timings. */
|
|
39
|
+
export interface ProveReport {
|
|
40
|
+
/** Bumped when a field is renamed or removed; adding one does not. */
|
|
41
|
+
readonly schemaVersion: 1;
|
|
42
|
+
readonly passed: boolean;
|
|
43
|
+
readonly totals: {
|
|
44
|
+
readonly journeys: number;
|
|
45
|
+
readonly journeysPassed: number;
|
|
46
|
+
readonly steps: number;
|
|
47
|
+
readonly stepsPassed: number;
|
|
48
|
+
readonly evalsFailed: number;
|
|
49
|
+
/** What the closing line counts: failing steps and journeys that stopped, plus failing evals. */
|
|
50
|
+
readonly failing: number;
|
|
51
|
+
};
|
|
52
|
+
readonly seconds: number;
|
|
53
|
+
readonly journeys: ReadonlyArray<JourneyDetail>;
|
|
54
|
+
/** The lines of prove's text output, unchanged. */
|
|
55
|
+
readonly lines: ReadonlyArray<string>;
|
|
56
|
+
/** `prove --changed` only: what it ran, what it skipped, and why it ran everything when it did. */
|
|
57
|
+
readonly changed?: ChangedDetail;
|
|
58
|
+
}
|
|
59
|
+
export interface ChangedDetail {
|
|
60
|
+
readonly base: "last proof";
|
|
61
|
+
readonly rerun: ReadonlyArray<string>;
|
|
62
|
+
readonly skipped: ReadonlyArray<string>;
|
|
63
|
+
readonly fellBack: null | {
|
|
64
|
+
readonly reason: string;
|
|
65
|
+
readonly files: ReadonlyArray<string>;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Where an operation's handler and declaration live; both relative to the project root. */
|
|
69
|
+
export declare const filesOf: (model: Model | undefined, call: CallRecord | undefined) => {
|
|
70
|
+
operation: string;
|
|
71
|
+
handler: string | undefined;
|
|
72
|
+
declaration: string;
|
|
73
|
+
} | undefined;
|
|
74
|
+
/** A step as data: its failures matched to the halves checks recorded, then the files and time of the call it ran. */
|
|
75
|
+
export declare const stepDetail: (model: Model | undefined, step: StepResult, failures: ReadonlyArray<string>, extra: ReadonlyArray<FailureDetail>, trace: Trace | undefined, call: CallRecord | undefined) => StepDetail;
|
|
76
|
+
export declare const journeyDetail: (run: JourneyRun, steps: ReadonlyArray<StepDetail>) => JourneyDetail;
|
|
77
|
+
/** The whole report, once the journeys and the evals have been judged. */
|
|
78
|
+
export declare const proveReport: (details: ReadonlyArray<JourneyDetail>, evalsFailed: number, seconds: number, lines: ReadonlyArray<string>, passed: boolean, changed?: ChangedDetail) => ProveReport;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// What `ortho prove --json` and `--report <file>` carry: the journeys, step by step, as data. Built from the same
|
|
2
|
+
// facts as prove's lines; the lines stay the text an agent reads, this is what a tool reads.
|
|
3
|
+
import { handlerFiles } from "@orthograph/compiler";
|
|
4
|
+
/** Where an operation's handler and declaration live; both relative to the project root. */
|
|
5
|
+
export const filesOf = (model, call) => {
|
|
6
|
+
const op = call === undefined ? undefined : model?.operations[call.operation];
|
|
7
|
+
return op === undefined ? undefined : { operation: op.name, handler: handlerFiles(op)[0]?.file, declaration: op.file };
|
|
8
|
+
};
|
|
9
|
+
/** A step as data: its failures matched to the halves checks recorded, then the files and time of the call it ran. */
|
|
10
|
+
export const stepDetail = (model, step, failures, extra, trace, call) => {
|
|
11
|
+
const known = [...(step.findings ?? []), ...extra];
|
|
12
|
+
const details = failures.map((message) => known.find((f) => f.message === message) ?? { message });
|
|
13
|
+
const files = filesOf(model, call);
|
|
14
|
+
const ms = call === undefined ? undefined : trace?.spans.find((s) => s.name === call.operation)?.ms ?? null;
|
|
15
|
+
const first = details[0];
|
|
16
|
+
return {
|
|
17
|
+
name: step.title,
|
|
18
|
+
verdict: details.length === 0 ? "pass" : "fail",
|
|
19
|
+
...(first?.expected === undefined ? {} : { expected: first.expected }),
|
|
20
|
+
...(first?.got === undefined ? {} : { got: first.got }),
|
|
21
|
+
failures: details,
|
|
22
|
+
...(files === undefined ? {} : { operation: files.operation, ...(files.handler === undefined ? {} : { handlerFile: files.handler }), declarationFile: files.declaration }),
|
|
23
|
+
...(ms === undefined ? {} : { ms }),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const journeyDetail = (run, steps) => ({
|
|
27
|
+
name: run.name,
|
|
28
|
+
verdict: run.stopped === undefined && steps.every((s) => s.verdict === "pass") ? "pass" : "fail",
|
|
29
|
+
...(run.stopped === undefined ? {} : { stopped: run.stopped }),
|
|
30
|
+
steps,
|
|
31
|
+
skipped: run.skipped ?? [],
|
|
32
|
+
ms: steps.reduce((total, s) => total + (s.ms ?? 0), 0),
|
|
33
|
+
});
|
|
34
|
+
/** The whole report, once the journeys and the evals have been judged. */
|
|
35
|
+
export const proveReport = (details, evalsFailed, seconds, lines, passed, changed) => {
|
|
36
|
+
const steps = details.flatMap((j) => j.steps);
|
|
37
|
+
const journeysFailing = details.filter((j) => j.verdict === "fail" && j.stopped !== undefined).length;
|
|
38
|
+
const stepsFailing = steps.filter((s) => s.verdict === "fail").length;
|
|
39
|
+
return {
|
|
40
|
+
schemaVersion: 1,
|
|
41
|
+
passed,
|
|
42
|
+
totals: {
|
|
43
|
+
journeys: details.length,
|
|
44
|
+
journeysPassed: details.filter((j) => j.verdict === "pass").length,
|
|
45
|
+
steps: steps.length,
|
|
46
|
+
stepsPassed: steps.length - stepsFailing,
|
|
47
|
+
evalsFailed,
|
|
48
|
+
failing: journeysFailing + stepsFailing + evalsFailed,
|
|
49
|
+
},
|
|
50
|
+
seconds,
|
|
51
|
+
journeys: details,
|
|
52
|
+
lines,
|
|
53
|
+
...(changed === undefined ? {} : { changed }),
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { Model } from "@orthograph/compiler";
|
|
3
|
+
import type { Project } from "#modules/journeys/types.js";
|
|
4
|
+
import { ProveFailed, type ProveApi } from "../types.ts";
|
|
5
|
+
export declare const proveInTest: (model: Model, project: Project, options: Parameters<ProveApi["test"]>[0]) => Effect.Effect<{
|
|
6
|
+
passed: boolean;
|
|
7
|
+
}, ProveFailed, never>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// `prove --env test`: a world in the long-lived test environment, the journeys and evals against it, a signed verdict
|
|
2
|
+
// per operation in the logbook, then the world destroyed (D3 #14, #50, #53).
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
4
|
+
import { Effect } from "effect";
|
|
5
|
+
import { Build } from "#modules/build/service.js";
|
|
6
|
+
import { Environments } from "#modules/environments/service.js";
|
|
7
|
+
import { Releases } from "#modules/releases/service.js";
|
|
8
|
+
import { Collectors } from "#modules/telemetry/service.js";
|
|
9
|
+
import { TestWorlds } from "#modules/test-worlds/service.js";
|
|
10
|
+
import { Verdicts } from "#modules/verdicts/service.js";
|
|
11
|
+
import { ProveFailed } from "../types.js";
|
|
12
|
+
import { closing, exercise } from "./exercise.js";
|
|
13
|
+
const TEST = "test";
|
|
14
|
+
const failed = (e) => new ProveFailed({ message: e.message });
|
|
15
|
+
/** The lifetime in words and in milliseconds: the one asked for, else the environment's own. */
|
|
16
|
+
const lifetimeOf = (model, asked) => {
|
|
17
|
+
const own = model.environments?.[TEST]?.lifetimeMs ?? null;
|
|
18
|
+
if (asked === undefined) {
|
|
19
|
+
return own === null ? new ProveFailed({ message: `environment ${TEST} declares no lifetime, and no ORTHO_LIFETIME was given` }) : { ms: own, text: TestWorlds.formatLifetime(own) };
|
|
20
|
+
}
|
|
21
|
+
const ms = TestWorlds.parseLifetime(asked);
|
|
22
|
+
return ms === undefined ? new ProveFailed({ message: `"${asked}" is not a lifetime (try 20s, 30m or 2 hours)` }) : { ms, text: asked };
|
|
23
|
+
};
|
|
24
|
+
export const proveInTest = (model, project, options) => Effect.gen(function* () {
|
|
25
|
+
const { root, say } = options;
|
|
26
|
+
if (!model.environments?.[TEST])
|
|
27
|
+
return yield* new ProveFailed({ message: `no environment "${TEST}" in blueprint/environments/` });
|
|
28
|
+
const lifetime = lifetimeOf(model, options.lifetime);
|
|
29
|
+
if (lifetime instanceof ProveFailed)
|
|
30
|
+
return yield* lifetime;
|
|
31
|
+
// The environment runs the revision being proved: its bundle is built when there is none, and a running one on another is restarted onto it.
|
|
32
|
+
const revision = yield* Build.revision(root).pipe(Effect.mapError(failed));
|
|
33
|
+
if (yield* Build.dirty(root).pipe(Effect.mapError(failed)))
|
|
34
|
+
return yield* new ProveFailed({ message: "commit or stash changes before proving a revision in test" });
|
|
35
|
+
const built = (yield* Build.find(root, revision).pipe(Effect.mapError(failed))) ?? (yield* Build.build(root, options.env).pipe(Effect.mapError(failed)));
|
|
36
|
+
const environment = yield* Environments.up({ root, name: TEST, revision, env: options.env ?? {} }).pipe(Effect.mapError(failed));
|
|
37
|
+
yield* Environments.verify({ root, name: TEST, pid: environment.pid, revision, sha256: built.sha256 }).pipe(Effect.mapError(failed));
|
|
38
|
+
for (const note of environment.notes ?? [])
|
|
39
|
+
yield* say(note);
|
|
40
|
+
if (!environment.telemetry)
|
|
41
|
+
return yield* new ProveFailed({ message: `environment ${TEST} has no collector of its own` });
|
|
42
|
+
const collector = Collectors.read(environment.telemetry);
|
|
43
|
+
const id = `${TEST}-${randomBytes(4).toString("hex")}`;
|
|
44
|
+
return yield* Effect.acquireUseRelease(TestWorlds.create({ url: environment.url, id, lifetimeMs: lifetime.ms }).pipe(Effect.mapError(failed)), () => Effect.gen(function* () {
|
|
45
|
+
yield* say(`world ${id} · expires in ${lifetime.text}`);
|
|
46
|
+
const done = yield* exercise(model, project, environment.url, collector, undefined, environment.collector);
|
|
47
|
+
for (const line of [...done.journeys.lines, ...done.evals.lines])
|
|
48
|
+
yield* say(line);
|
|
49
|
+
const verdict = closing(done);
|
|
50
|
+
yield* say(verdict.line);
|
|
51
|
+
const results = done.results;
|
|
52
|
+
yield* Environments.verify({ root, name: TEST, pid: environment.pid, revision, sha256: built.sha256 }).pipe(Effect.mapError(failed));
|
|
53
|
+
yield* Build.unchanged(root, built.commit).pipe(Effect.mapError(failed));
|
|
54
|
+
// The portal and `impact` judge a verdict against the model of the revision it proved, so the logbook keeps that model first (D3 #138).
|
|
55
|
+
yield* Releases.keep({ logbook: options.logbook, source: options.token, model, revision }).pipe(Effect.mapError(failed));
|
|
56
|
+
const token = yield* Verdicts.mint(options.token).pipe(Effect.mapError(failed));
|
|
57
|
+
yield* Verdicts.post({ logbook: options.logbook, token, revision, sha256: built.sha256, environment: TEST, results }).pipe(Effect.mapError((e) => new ProveFailed({ message: `the verdicts weren't recorded: ${e.message}` })));
|
|
58
|
+
yield* say(`verdicts ${results.map((r) => `${r.operation} ${r.verdict === "pass" ? "✔" : "✘"}`).join(" ")} (revision ${revision})`);
|
|
59
|
+
return { passed: verdict.passed };
|
|
60
|
+
}),
|
|
61
|
+
// Whether the run passed, failed or was interrupted, the world goes; "world destroyed" is said only when it did.
|
|
62
|
+
() => TestWorlds.destroy({ url: environment.url, id }).pipe(Effect.flatMap(() => say("world destroyed")), Effect.ignore));
|
|
63
|
+
});
|