@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,112 @@
|
|
|
1
|
+
import { Names } from "orthograph/server";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
import { Compiler, nodeSource } from "@orthograph/compiler";
|
|
5
|
+
import { Environments } from "#modules/environments/service.js";
|
|
6
|
+
import { Build } from "#modules/build/service.js";
|
|
7
|
+
import { Prove } from "#modules/prove/service.js";
|
|
8
|
+
import { Releases } from "#modules/releases/service.js";
|
|
9
|
+
import { Secrets } from "#modules/secrets/service.js";
|
|
10
|
+
import { Verdicts } from "#modules/verdicts/service.js";
|
|
11
|
+
import { PromoteFailed, PromoteRefused } from "./types.js";
|
|
12
|
+
import { runningOn } from "./internal/environment.js";
|
|
13
|
+
import { bundleOf, verdictsIn } from "./internal/gate.js";
|
|
14
|
+
import { productionRelease, stagingPrerelease } from "./internal/publishing.js";
|
|
15
|
+
const failed = (e) => new PromoteFailed({ message: e.message });
|
|
16
|
+
const live = (root, target, up, built) => Environments.verify({ root, name: target, pid: up.pid, revision: built.revision, sha256: built.sha256 }).pipe(Effect.mapError(failed));
|
|
17
|
+
const stable = (root, target, up, built) => Build.unchanged(root, built.commit).pipe(Effect.mapError(failed), Effect.flatMap(() => live(root, target, up, built)));
|
|
18
|
+
/** Retry completes only missing or hash-mismatched carried facts; complete facts are not duplicated. */
|
|
19
|
+
const carry = ({ root, up, built, logbook, env, model, earned }) => Effect.gen(function* () {
|
|
20
|
+
const held = yield* Verdicts.latest({ logbook, revision: built.revision, environment: "production", ref: "refs/heads/main" }).pipe(Effect.mapError(failed));
|
|
21
|
+
const complete = new Set(held.filter((v) => v.verdict === "pass" && v.sha256 === built.sha256).map((v) => v.operation));
|
|
22
|
+
const missing = Object.keys(model.operations).filter((operation) => !complete.has(operation)).map((operation) => {
|
|
23
|
+
const journeys = earned.find((row) => row.operation === operation)?.journeys;
|
|
24
|
+
return { operation, verdict: "pass", ...(journeys ? { journeys } : {}) };
|
|
25
|
+
});
|
|
26
|
+
yield* live(root, "production", up, built);
|
|
27
|
+
if (missing.length === 0)
|
|
28
|
+
return;
|
|
29
|
+
const token = yield* Verdicts.sourceOf(env).pipe(Effect.flatMap(Verdicts.mint), Effect.mapError(failed));
|
|
30
|
+
yield* live(root, "production", up, built);
|
|
31
|
+
yield* Verdicts.post({ logbook, token, revision: built.revision, sha256: built.sha256, environment: "production", results: missing }).pipe(Effect.mapError((e) => new PromoteFailed({ message: `the verdicts weren't recorded: ${e.message}` })));
|
|
32
|
+
});
|
|
33
|
+
/** Which environment's verdicts a target needs: test for staging, and for production what it declares (`promotesFrom`), else staging. */
|
|
34
|
+
const earnedIn = (target, environment) => (target === "staging" ? "test" : (environment.promotesFrom ?? "staging"));
|
|
35
|
+
/** What the local pass can't reach, said so: the real cloud, and each domain it would be served at. */
|
|
36
|
+
const skipped = (environment) => [
|
|
37
|
+
...(environment.cloud ? [`skipped ${environment.cloud.provider} (cloud pass)`] : []),
|
|
38
|
+
...Object.entries(environment.deploy).flatMap(([what, d]) => (d.domain ? [`skipped ${what} domain ${d.domain} (cloud pass)`] : [])),
|
|
39
|
+
];
|
|
40
|
+
const to = ({ root, env, target, say }) => Effect.gen(function* () {
|
|
41
|
+
const model = yield* Compiler.model.pipe(Effect.provide(nodeSource(root)), Effect.mapError((e) => new PromoteFailed({ message: e._tag === "BlueprintInvalid" ? `the blueprint is invalid:\n - ${e.problems.join("\n - ")}` : e.message })));
|
|
42
|
+
const environment = model.environments?.[target];
|
|
43
|
+
if (!environment)
|
|
44
|
+
return yield* new PromoteFailed({ message: `no environment "${target}" in blueprint/environments/` });
|
|
45
|
+
// Refusals first: nothing is started for a promotion the rules turn away.
|
|
46
|
+
// A stored runtime secret with no value in the target would start a place that can't use it: each is named (M2.04).
|
|
47
|
+
const unset = yield* Secrets.missing({ root, target, model });
|
|
48
|
+
if (unset.length > 0) {
|
|
49
|
+
return yield* new PromoteRefused({ lines: [`refused: ${target} has stored runtime secrets with no value`, ...unset.map((name) => `missing: ${name} has no value in ${target}: ortho secrets set ${name} --env ${target}`)] });
|
|
50
|
+
}
|
|
51
|
+
const revision = yield* Build.revision(root).pipe(Effect.mapError(failed));
|
|
52
|
+
const built = yield* bundleOf(root, revision);
|
|
53
|
+
yield* Build.unchanged(root, built.commit).pipe(Effect.mapError(failed));
|
|
54
|
+
const logbook = yield* Releases.locate({ root, env }).pipe(Effect.mapError(failed));
|
|
55
|
+
if (logbook === undefined)
|
|
56
|
+
return yield* new PromoteFailed({ message: "no logbook: start one with `ortho env up logbook`, or set ORTHO_LOGBOOK_URL" });
|
|
57
|
+
const from = earnedIn(target, environment);
|
|
58
|
+
const earned = yield* verdictsIn(logbook, model, revision, from, built.sha256);
|
|
59
|
+
yield* say(`${target} from ${from} ${revision} sha256:${built.sha256}`);
|
|
60
|
+
const up = yield* runningOn(root, target, built);
|
|
61
|
+
yield* say(`${target} up ${up.url} bundle ${revision} sha256:${built.sha256} ✔`);
|
|
62
|
+
if (target === "staging") {
|
|
63
|
+
// The staging verdicts: the journeys and evals, run where staging runs, by people who really sign up.
|
|
64
|
+
if (up.telemetry === undefined)
|
|
65
|
+
return yield* new PromoteFailed({ message: "staging records no telemetry, so its evals have nothing to judge: another environment must declare promotesFrom: \"staging\"" });
|
|
66
|
+
const proved = yield* Prove.against({ root, url: up.url, telemetry: up.telemetry, state: join(resolve(root), Names.folder, "environments", target, "state"), say }).pipe(Effect.mapError(failed));
|
|
67
|
+
yield* stable(root, target, up, built);
|
|
68
|
+
// Staleness judges these verdicts against the model of the revision they proved, so the logbook keeps that model first.
|
|
69
|
+
yield* Releases.keep({ logbook, env, model, revision }).pipe(Effect.mapError(failed));
|
|
70
|
+
const source = yield* Verdicts.sourceOf(env).pipe(Effect.mapError(failed));
|
|
71
|
+
// Minted just before posting: the issuer's tokens live ten minutes and a prove can take longer.
|
|
72
|
+
const token = yield* Verdicts.mint(source).pipe(Effect.mapError(failed));
|
|
73
|
+
// The prerelease goes out only for a revision that proved itself where it runs, and before the verdicts are said.
|
|
74
|
+
if (proved.passed) {
|
|
75
|
+
yield* stable(root, target, up, built);
|
|
76
|
+
yield* stagingPrerelease({ root, env, say, logbook, model, revision: built.commit });
|
|
77
|
+
}
|
|
78
|
+
else
|
|
79
|
+
yield* say("skipped publish (staging's proof failed: nothing is published for a revision that did not pass)");
|
|
80
|
+
yield* live(root, target, up, built);
|
|
81
|
+
yield* Verdicts.post({ logbook, token, revision, sha256: built.sha256, environment: "staging", results: proved.results }).pipe(Effect.mapError((e) => new PromoteFailed({ message: `the verdicts weren't recorded: ${e.message}` })));
|
|
82
|
+
yield* say(`verdicts ${proved.results.map((r) => `${r.operation} ${r.verdict === "pass" ? "✔" : "✘"}`).join(" ")} (revision ${revision})`);
|
|
83
|
+
for (const line of skipped(environment))
|
|
84
|
+
yield* say(line);
|
|
85
|
+
return { revision, sha256: built.sha256, passed: proved.passed };
|
|
86
|
+
}
|
|
87
|
+
// Production: what staging proved is what runs, and the release is the logbook's record of it.
|
|
88
|
+
const last = yield* Releases.last(logbook).pipe(Effect.mapError(failed));
|
|
89
|
+
if (last?.revision === revision) {
|
|
90
|
+
// A retry verifies existing package bytes before reporting the prior release as recovered.
|
|
91
|
+
yield* productionRelease({ root, env, say, version: last.version, revision: built.commit });
|
|
92
|
+
yield* live(root, target, up, built);
|
|
93
|
+
yield* carry({ root, up, built, logbook, env, model, earned });
|
|
94
|
+
yield* say(`release ${last.version} already recorded for ${revision}`);
|
|
95
|
+
for (const line of skipped(environment))
|
|
96
|
+
yield* say(line);
|
|
97
|
+
return { revision, sha256: built.sha256, passed: true, version: last.version };
|
|
98
|
+
}
|
|
99
|
+
const version = yield* Releases.next(logbook, model).pipe(Effect.mapError(failed));
|
|
100
|
+
// Publication may be partial on an npm error, but it must not create a new release or carried pass first.
|
|
101
|
+
yield* productionRelease({ root, env, say, version, revision: built.commit });
|
|
102
|
+
yield* live(root, target, up, built);
|
|
103
|
+
yield* Releases.record({ logbook, env, model, revision, version }).pipe(Effect.mapError(failed));
|
|
104
|
+
yield* say(`released ${version}`);
|
|
105
|
+
// Nobody runs journeys in production: its verdict is staging's, carried to the same bundle the environment just reported. It
|
|
106
|
+
// is what puts production in the logbook beside staging, so a change that unproves an operation stales it there too.
|
|
107
|
+
yield* carry({ root, up, built, logbook, env, model, earned });
|
|
108
|
+
for (const line of skipped(environment))
|
|
109
|
+
yield* say(line);
|
|
110
|
+
return { revision, sha256: built.sha256, passed: true, version };
|
|
111
|
+
});
|
|
112
|
+
export const Promote = { to };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type Effect } from "effect";
|
|
2
|
+
import type { Env } from "#modules/verdicts/types.js";
|
|
3
|
+
export type Target = "staging" | "production";
|
|
4
|
+
declare const PromoteRefused_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: "PromoteRefused";
|
|
6
|
+
} & Readonly<A>;
|
|
7
|
+
/** A promotion the rules refuse: what is wrong, one line each, the first being the verdict (`refused: <rev> has no green verdicts in <env>`). */
|
|
8
|
+
export declare class PromoteRefused extends PromoteRefused_base<{
|
|
9
|
+
readonly lines: ReadonlyArray<string>;
|
|
10
|
+
}> {
|
|
11
|
+
}
|
|
12
|
+
declare const PromoteFailed_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 & {
|
|
13
|
+
readonly _tag: "PromoteFailed";
|
|
14
|
+
} & Readonly<A>;
|
|
15
|
+
/** A promotion that couldn't be carried out: no logbook, an environment that wouldn't start, a bundle that isn't the one asked for. */
|
|
16
|
+
export declare class PromoteFailed extends PromoteFailed_base<{
|
|
17
|
+
readonly message: string;
|
|
18
|
+
}> {
|
|
19
|
+
}
|
|
20
|
+
export interface Promoted {
|
|
21
|
+
readonly revision: string;
|
|
22
|
+
/** Bare hex of the bundle every environment runs. */
|
|
23
|
+
readonly sha256: string;
|
|
24
|
+
/** For staging: every journey and eval passed in the environment. Production has nothing to prove again. */
|
|
25
|
+
readonly passed: boolean;
|
|
26
|
+
/** For production: the version recorded in the logbook. */
|
|
27
|
+
readonly version?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface PromoteApi {
|
|
30
|
+
/**
|
|
31
|
+
* Move the revision at `root` (the git commit) to `target`. In order:
|
|
32
|
+
*
|
|
33
|
+
* 1. It refuses a dirty working tree, and a revision with no built bundle or one whose file no longer matches the hash
|
|
34
|
+
* recorded when it was built. The bundle is never rebuilt here: it is the one `ortho build` made.
|
|
35
|
+
* 2. It refuses a revision whose verdicts, among those posted from `main` (a pull request's never count), are not all
|
|
36
|
+
* passing for every operation and naming this exact bundle hash: `test` for staging, `staging` (the environment's `promotesFrom`) for production. Nothing
|
|
37
|
+
* is started for a refused promotion.
|
|
38
|
+
* 3. It starts the target environment on that bundle, or restarts it onto it with its state kept, and checks
|
|
39
|
+
* `GET /_ortho/bundle` answers the bundle's own revision and sha256.
|
|
40
|
+
* 4. Staging: the journeys and evals run against it, the people signing up for real, and a verdict per operation is
|
|
41
|
+
* posted with `environment: "staging"`. Production: the release is recorded in the logbook with the version the
|
|
42
|
+
* model gives (`Releases.next`), unless this revision is already the last release.
|
|
43
|
+
*
|
|
44
|
+
* What the local pass can't reach (the real cloud, a domain) is `say`d as `skipped <destination> (cloud pass)`.
|
|
45
|
+
*/
|
|
46
|
+
readonly to: (options: {
|
|
47
|
+
readonly root: string;
|
|
48
|
+
/** The process environment, passed in because only `main.ts` reads it: the logbook's address and who signs for the run. */
|
|
49
|
+
readonly env: Env;
|
|
50
|
+
readonly target: Target;
|
|
51
|
+
readonly say: (line: string) => Effect.Effect<void>;
|
|
52
|
+
}) => Effect.Effect<Promoted, PromoteRefused | PromoteFailed>;
|
|
53
|
+
}
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// `ortho promote --to staging|production`: the exact built bundle, moved on only with the verdicts that earn it (D3 #14, #92).
|
|
2
|
+
import { Data } from "effect";
|
|
3
|
+
/** A promotion the rules refuse: what is wrong, one line each, the first being the verdict (`refused: <rev> has no green verdicts in <env>`). */
|
|
4
|
+
export class PromoteRefused extends Data.TaggedError("PromoteRefused") {
|
|
5
|
+
}
|
|
6
|
+
/** A promotion that couldn't be carried out: no logbook, an environment that wouldn't start, a bundle that isn't the one asked for. */
|
|
7
|
+
export class PromoteFailed extends Data.TaggedError("PromoteFailed") {
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Model } from "@orthograph/compiler";
|
|
2
|
+
import type { Selection } from "#modules/impact/types.js";
|
|
3
|
+
import type { Project } from "#modules/journeys/types.js";
|
|
4
|
+
import type { ChangedDetail } from "./structured.ts";
|
|
5
|
+
/** The project with only the journeys it will run, files and all (each journey's file is kept at its index). */
|
|
6
|
+
export declare const narrowed: (project: Project, run: ReadonlyArray<string>) => Project;
|
|
7
|
+
/** What it will do, then each journey it leaves alone. */
|
|
8
|
+
export declare const headline: (model: Model, selection: Selection, ran: number, total: number) => ReadonlyArray<string>;
|
|
9
|
+
export declare const detail: (model: Model, selection: Selection, rerun: ReadonlyArray<string>) => ChangedDetail;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The project with only the journeys it will run, files and all (each journey's file is kept at its index). */
|
|
2
|
+
export const narrowed = (project, run) => {
|
|
3
|
+
const keep = project.journeys.flatMap((_, index) => (run.includes(project.journeyFiles?.[index] ?? "") ? [index] : []));
|
|
4
|
+
return { ...project, journeys: keep.map((i) => project.journeys[i]), ...(project.journeyFiles === undefined ? {} : { journeyFiles: keep.map((i) => project.journeyFiles[i]) }) };
|
|
5
|
+
};
|
|
6
|
+
/** A journey's name, as `Blueprint.journey` gives it, from its file. */
|
|
7
|
+
const nameOf = (model, file) => model.journeys[file]?.name ?? file;
|
|
8
|
+
/** What it will do, then each journey it leaves alone. */
|
|
9
|
+
export const headline = (model, selection, ran, total) => selection.fellBack === null
|
|
10
|
+
? [`prove --changed: proving ${ran} of ${total} journeys`, ...selection.skipped.map((file) => `journey ${nameOf(model, file)} skipped: nothing it calls changed`)]
|
|
11
|
+
: [`prove --changed: proving all ${total} journeys: ${selection.fellBack.reason}${selection.fellBack.files.length > 0 ? " (nothing in the model says which journeys they touch)" : ""}`];
|
|
12
|
+
export const detail = (model, selection, rerun) => ({
|
|
13
|
+
base: "last proof", rerun: rerun.map((file) => nameOf(model, file)), skipped: selection.skipped.map((file) => nameOf(model, file)), fellBack: selection.fellBack,
|
|
14
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Effect, type Scope } from "effect";
|
|
2
|
+
import type { Model } from "@orthograph/compiler";
|
|
3
|
+
import type { DeviceHost } from "#modules/journeys/types.js";
|
|
4
|
+
import { WorldFailed, type ChainStand } from "#modules/world/types.js";
|
|
5
|
+
/** Whether a mounted plugin runs operations on the device, so that its journeys need a device and a chain to run on. */
|
|
6
|
+
export declare const needsDevice: (model: Model) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The world's chain, when the plugins need one: Anvil as a process of the world's scope. Without Foundry's `anvil` on the
|
|
9
|
+
* path the world has none, and says so; the journeys that need a key then fail naming `world.chain`, not the world.
|
|
10
|
+
*/
|
|
11
|
+
export declare const standChain: (model: Model) => Effect.Effect<{
|
|
12
|
+
readonly chain: ChainStand | undefined;
|
|
13
|
+
readonly notes: ReadonlyArray<string>;
|
|
14
|
+
}, never, Scope.Scope>;
|
|
15
|
+
/** The device for a run: what its `world` entries are given, and what the journeys read of the world. */
|
|
16
|
+
export declare const deviceHost: (root: string, otlp: string | undefined, chain: ChainStand | undefined) => Effect.Effect<DeviceHost, WorldFailed, Scope.Scope>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// The device prove stands in for (M1.29, K7 Q7): when a plugin runs operations on the device, the world gets a chain (Anvil
|
|
2
|
+
// as a process, always silent), a funded key for each host the journeys can name, and a folder of its own.
|
|
3
|
+
import { mkdirSync, rmSync } from "node:fs";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import { Effect, Redacted } from "effect";
|
|
6
|
+
import { Names } from "orthograph/server";
|
|
7
|
+
import { Anvil } from "@orthograph/chain-evm";
|
|
8
|
+
import { TimersLive } from "@orthograph/language-effect";
|
|
9
|
+
import { WorldFailed } from "#modules/world/types.js";
|
|
10
|
+
/** The hosts a wallet's key can live on (K7 F4, F5): a funded key for each, then one more account, the payee's. */
|
|
11
|
+
const HOSTS = ["node", "browser", "keystore", "world"];
|
|
12
|
+
/**
|
|
13
|
+
* What the device's chain declares for confirmation (M1.38): depth three, a block a second. A journey can't name its chain and
|
|
14
|
+
* a plugin can't ship a starting world, so the one chain every device journey meets is the deep one: each send in a
|
|
15
|
+
* journey waits for three blocks, which is what a real chain asks of it, and the wallet's depth-three story is the common case.
|
|
16
|
+
*/
|
|
17
|
+
const DEPTH = 3;
|
|
18
|
+
const BLOCK_SECONDS = 1;
|
|
19
|
+
/** Whether a mounted plugin runs operations on the device, so that its journeys need a device and a chain to run on. */
|
|
20
|
+
export const needsDevice = (model) => Object.values(model.operations).some((op) => op.runs === "client" && op.from.kind !== "app");
|
|
21
|
+
/**
|
|
22
|
+
* The world's chain, when the plugins need one: Anvil as a process of the world's scope. Without Foundry's `anvil` on the
|
|
23
|
+
* path the world has none, and says so; the journeys that need a key then fail naming `world.chain`, not the world.
|
|
24
|
+
*/
|
|
25
|
+
export const standChain = (model) => needsDevice(model)
|
|
26
|
+
? Anvil.start({ accounts: HOSTS.length + 1, blockTime: BLOCK_SECONDS }).pipe(Effect.provide(TimersLive), Effect.map((anvil) => ({ chain: { rpcUrl: anvil.rpcUrl, chainId: anvil.chainId, accounts: anvil.accounts }, notes: [] })), Effect.catch((failed) => Effect.succeed({ chain: undefined, notes: [`world chain: none, ${failed.message} (the plugins here run on a device and some journeys need a chain)`] })))
|
|
27
|
+
: Effect.succeed({ chain: undefined, notes: [] });
|
|
28
|
+
const account = (chainId, address) => `eip155:${chainId}:${address}`;
|
|
29
|
+
/** The device for a run: what its `world` entries are given, and what the journeys read of the world. */
|
|
30
|
+
export const deviceHost = (root, otlp, chain) => Effect.gen(function* () {
|
|
31
|
+
const directory = resolve(root, Names.folder, "prove-device");
|
|
32
|
+
// Fresh each run, and gone when the world is: a keystore file made here never outlives it.
|
|
33
|
+
yield* Effect.acquireRelease(Effect.sync(() => { rmSync(directory, { recursive: true, force: true }); mkdirSync(directory, { recursive: true, mode: 0o700 }); }), () => Effect.sync(() => rmSync(directory, { recursive: true, force: true }))).pipe(Effect.mapError(() => new WorldFailed({ message: `${directory} could not be made` })));
|
|
34
|
+
const kept = new Map();
|
|
35
|
+
const accounts = chain?.accounts ?? [];
|
|
36
|
+
const keys = Object.fromEntries(HOSTS.flatMap((host, i) => (accounts[i] === undefined ? [] : [[host, accounts[i].privateKey]])));
|
|
37
|
+
const given = chain === undefined || accounts.length < HOSTS.length + 1
|
|
38
|
+
? {}
|
|
39
|
+
: {
|
|
40
|
+
chain: {
|
|
41
|
+
// A secret key for the hosts that hold them; for the browser, the account its provider holds.
|
|
42
|
+
keys: Object.fromEntries(HOSTS.map((host, i) => [host, host === "browser" ? account(chain.chainId, accounts[i].address) : Redacted.value(accounts[i].privateKey)])),
|
|
43
|
+
payee: account(chain.chainId, accounts[HOSTS.length].address),
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
otlp,
|
|
48
|
+
service: "prove-device",
|
|
49
|
+
given,
|
|
50
|
+
world: {
|
|
51
|
+
chain: chain === undefined ? undefined : { rpcUrl: chain.rpcUrl, chainId: chain.chainId, keys, depth: DEPTH },
|
|
52
|
+
directory: join(directory),
|
|
53
|
+
remember: (key, make) => {
|
|
54
|
+
if (!kept.has(key))
|
|
55
|
+
kept.set(key, make());
|
|
56
|
+
return kept.get(key);
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Model } from "@orthograph/compiler";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { ProveFailed } from "../types.ts";
|
|
4
|
+
/** Keep the test-only route switch and scaffold modules out of the project's source and generated tree. */
|
|
5
|
+
export declare const emptyWorld: (at: string, model: Model) => Effect.Effect<string, ProveFailed, import("effect/Scope").Scope>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Names } from "orthograph/server";
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
4
|
+
import { Render } from "@orthograph/generators/render";
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
import { ProveFailed } from "../types.js";
|
|
7
|
+
const io = (work) => Effect.try({ try: work, catch: (error) => new ProveFailed({ message: `couldn't prepare the scaffold world: ${String(error)}` }) });
|
|
8
|
+
/** Keep the test-only route switch and scaffold modules out of the project's source and generated tree. */
|
|
9
|
+
export const emptyWorld = (at, model) => Effect.gen(function* () {
|
|
10
|
+
const root = resolve(at);
|
|
11
|
+
const dir = join(root, Names.folder);
|
|
12
|
+
yield* io(() => mkdirSync(dir, { recursive: true }));
|
|
13
|
+
const scratch = yield* Effect.acquireRelease(io(() => mkdtempSync(join(dir, "empty-"))), (path) => Effect.sync(() => rmSync(path, { recursive: true, force: true })));
|
|
14
|
+
yield* io(() => {
|
|
15
|
+
mkdirSync(join(scratch, "generated"), { recursive: true });
|
|
16
|
+
for (const path of ["blueprint", "src", "generated/api", "generated/mcp", "generated/portal"]) {
|
|
17
|
+
symlinkSync(join(root, path), join(scratch, path), "dir");
|
|
18
|
+
}
|
|
19
|
+
for (const file of Render.emptyServer({ name: basename(root), model })) {
|
|
20
|
+
const path = join(scratch, file.path);
|
|
21
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
22
|
+
writeFileSync(path, file.content);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return scratch;
|
|
26
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { Model } from "@orthograph/compiler";
|
|
3
|
+
import type { Verdict } from "#modules/evals/types.js";
|
|
4
|
+
import type { DeviceHost, Facts, Project } from "#modules/journeys/types.js";
|
|
5
|
+
import type { TraceSource } from "#modules/telemetry/types.js";
|
|
6
|
+
import { handlerHashes } from "#modules/verdicts/internal/proof.js";
|
|
7
|
+
import type { Result } from "#modules/verdicts/types.js";
|
|
8
|
+
import { evalLines, journeyLines } from "./report.ts";
|
|
9
|
+
export interface Exercised {
|
|
10
|
+
readonly journeys: ReturnType<typeof journeyLines>;
|
|
11
|
+
readonly evals: ReturnType<typeof evalLines>;
|
|
12
|
+
readonly verdicts: ReadonlyArray<Verdict>;
|
|
13
|
+
/** A run with a failing journey proves nothing: its operations are judged and not passed (D2 #80). */
|
|
14
|
+
readonly judged: ReadonlyArray<Verdict>;
|
|
15
|
+
readonly results: ReadonlyArray<Result>;
|
|
16
|
+
/** The trace of every call that went wrong, in a journey or an eval: what `prove --view` points at. */
|
|
17
|
+
readonly failedTraces: ReadonlyArray<{
|
|
18
|
+
readonly trace: string;
|
|
19
|
+
readonly what: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Run every journey, then read each call's trace back. When prove can reach the collector (`otlp`), it first exports
|
|
24
|
+
* the journey's own span as each trace's root, `journey.<name>` (O1), and reads the traces again with it in.
|
|
25
|
+
*/
|
|
26
|
+
export declare const exercise: (model: Model, project: Project, url: string, collector: TraceSource, people?: "world" | "sign-up", otlp?: string, facts?: Facts, empty?: boolean, handlers?: ReturnType<typeof handlerHashes>, device?: DeviceHost,
|
|
27
|
+
/** `prove --changed`: judge the evals of these operations only (what changed); the rest keep their recorded verdicts. */
|
|
28
|
+
judging?: ReadonlySet<string>,
|
|
29
|
+
/** The address of each stand-in the world's prove started, by mount: where a journey's `Stand.command` goes. */
|
|
30
|
+
stands?: Readonly<Record<string, string>>) => Effect.Effect<Exercised>;
|
|
31
|
+
/** The last line: every journey and every eval passed, or how many did not. */
|
|
32
|
+
export declare const closing: (x: Exercised) => {
|
|
33
|
+
line: string;
|
|
34
|
+
passed: boolean;
|
|
35
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// What every prove does once it has a world to talk to: run each journey, read back what the collector heard, judge.
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { Evals } from "#modules/evals/service.js";
|
|
4
|
+
import { Journeys } from "#modules/journeys/service.js";
|
|
5
|
+
import { exportRoots, rootOf } from "#modules/telemetry/service.js";
|
|
6
|
+
import { proofVerdicts } from "./proof-verdicts.js";
|
|
7
|
+
import { handlerHashes } from "#modules/verdicts/internal/proof.js";
|
|
8
|
+
import { evalLines, journeyLines, noSpanExpected, optionalStepLines } from "./report.js";
|
|
9
|
+
/**
|
|
10
|
+
* Run every journey, then read each call's trace back. When prove can reach the collector (`otlp`), it first exports
|
|
11
|
+
* the journey's own span as each trace's root, `journey.<name>` (O1), and reads the traces again with it in.
|
|
12
|
+
*/
|
|
13
|
+
export const exercise = (model, project, url, collector, people, otlp, facts, empty = false, handlers, device,
|
|
14
|
+
/** `prove --changed`: judge the evals of these operations only (what changed); the rest keep their recorded verdicts. */
|
|
15
|
+
judging,
|
|
16
|
+
/** The address of each stand-in the world's prove started, by mount: where a journey's `Stand.command` goes. */
|
|
17
|
+
stands) => Effect.gen(function* () {
|
|
18
|
+
const bodies = handlers ?? handlerHashes(project.root, model);
|
|
19
|
+
const runs = yield* Effect.forEach(project.journeys, (j, i) => Journeys.run(project, url, j, i, people, facts, empty, device, stands));
|
|
20
|
+
const calls = runs.flatMap((r) => r.calls);
|
|
21
|
+
const first = yield* collector.traces(calls.map((c) => ({ trace: c.trace, parent: c.parent, mayBeEmpty: noSpanExpected(c) })));
|
|
22
|
+
const roots = otlp === undefined ? [] : calls.filter((c) => c.tools !== true && c.clock !== true && c.stand !== true).flatMap((c) => rootOf({ trace: c.trace, span: c.parent, journey: c.journey, step: c.step, operation: c.operation, status: c.status }, first.get(c.trace)) ?? []);
|
|
23
|
+
if (otlp !== undefined)
|
|
24
|
+
yield* exportRoots(otlp, roots);
|
|
25
|
+
const rooted = new Set(roots.map((r) => r.traceId));
|
|
26
|
+
const traces = roots.length === 0 ? first : yield* collector.traces(calls.map((c) => ({ trace: c.trace, parent: c.parent, rooted: rooted.has(c.trace), mayBeEmpty: noSpanExpected(c) })));
|
|
27
|
+
const journeys = journeyLines(runs, traces, empty, model);
|
|
28
|
+
if (empty)
|
|
29
|
+
return { journeys, evals: { lines: [], failed: 0 }, verdicts: [], judged: [], results: [], failedTraces: journeys.failedTraces };
|
|
30
|
+
// The tools list is not an operation's call: no eval reads it, and it has no operation span to find.
|
|
31
|
+
const evidence = Evals.gather(calls.filter((c) => c.tools !== true && c.clock !== true && c.stand !== true), traces);
|
|
32
|
+
const everything = Evals.judge(project, evidence);
|
|
33
|
+
const verdicts = judging === undefined ? everything : everything.filter((v) => v.operation !== undefined && judging.has(v.operation));
|
|
34
|
+
const judged = journeys.failed === 0 ? verdicts : verdicts.map((v) => ({ ...v, failures: [...v.failures, "a journey failed"] }));
|
|
35
|
+
// The traces of what went wrong: a journey's own, and the calls an eval named by their `where`.
|
|
36
|
+
const named = calls.filter((c) => verdicts.some((v) => v.failures.some((f) => f.startsWith(`${Evals.where(c)}:`))));
|
|
37
|
+
const failedTraces = [...journeys.failedTraces, ...named.map((c) => ({ trace: c.trace, what: `${c.journey} "${c.step}"` }))]
|
|
38
|
+
.filter((f, i, all) => all.findIndex((o) => o.trace === f.trace) === i);
|
|
39
|
+
const evals = evalLines(judging === undefined ? model : { ...model, operations: Object.fromEntries(Object.entries(model.operations).filter(([name]) => judging.has(name))) }, verdicts);
|
|
40
|
+
const results = proofVerdicts(project, runs, traces, judged, bodies);
|
|
41
|
+
return { journeys, evals: { ...evals, lines: [...evals.lines, ...(judging === undefined ? optionalStepLines(model, runs, evidence) : [])] }, verdicts, judged, results, failedTraces };
|
|
42
|
+
});
|
|
43
|
+
/** The last line: every journey and every eval passed, or how many did not. */
|
|
44
|
+
export const closing = (x) => {
|
|
45
|
+
const failures = x.journeys.failed + x.evals.failed;
|
|
46
|
+
return { line: failures === 0 ? "prove ✔" : `prove ✘ ${failures} failing`, passed: failures === 0 };
|
|
47
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Verdict } from "#modules/evals/types.js";
|
|
2
|
+
import type { JourneyRun, Project } from "#modules/journeys/types.js";
|
|
3
|
+
import type { Trace } from "#modules/telemetry/types.js";
|
|
4
|
+
import type { Result } from "#modules/verdicts/types.js";
|
|
5
|
+
export declare const proofVerdicts: (project: Project, runs: ReadonlyArray<JourneyRun>, traces: ReadonlyMap<string, Trace>, judged: ReadonlyArray<Verdict>, handlers: Readonly<Record<string, string | null | undefined>>) => ReadonlyArray<Result>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { modelHash, scenarioOf } from "#modules/verdicts/internal/proof.js";
|
|
2
|
+
import { spanFailures } from "./report.js";
|
|
3
|
+
export const proofVerdicts = (project, runs, traces, judged, handlers) => {
|
|
4
|
+
const { model } = project;
|
|
5
|
+
const hash = modelHash(model);
|
|
6
|
+
const byOperation = new Map();
|
|
7
|
+
for (const [index, run] of runs.entries()) {
|
|
8
|
+
const journey = project.journeyFiles?.[index];
|
|
9
|
+
if (journey === undefined)
|
|
10
|
+
continue;
|
|
11
|
+
const declared = model.journeys[journey];
|
|
12
|
+
if (!declared)
|
|
13
|
+
continue;
|
|
14
|
+
const byTrace = new Map(run.calls.map((call) => [call.trace, call]));
|
|
15
|
+
const failed = run.stopped !== undefined || run.steps.some((step) => step.failures.length > 0 || spanFailures(step, traces.get(step.trace), byTrace.get(step.trace)).length > 0);
|
|
16
|
+
const operations = scenarioOf(model, declared).operationNames;
|
|
17
|
+
const called = new Set(run.calls.map((call) => call.operation));
|
|
18
|
+
for (const operation of operations) {
|
|
19
|
+
const handlerHash = handlers[operation];
|
|
20
|
+
if (handlerHash === undefined)
|
|
21
|
+
continue;
|
|
22
|
+
const evidence = { journey, modelHash: hash, handlerHash, verdict: failed || !called.has(operation) ? "fail" : "pass" };
|
|
23
|
+
const entries = byOperation.get(operation);
|
|
24
|
+
if (entries)
|
|
25
|
+
entries.push(evidence);
|
|
26
|
+
else
|
|
27
|
+
byOperation.set(operation, [evidence]);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return Object.keys(model.operations).map((operation) => {
|
|
31
|
+
const journeys = byOperation.get(operation) ?? [];
|
|
32
|
+
const mine = judged.filter((v) => v.operation === operation);
|
|
33
|
+
const passed = journeys.length > 0 && journeys.every((v) => v.verdict === "pass")
|
|
34
|
+
&& mine.length > 0 && mine.every((v) => v.failures.length === 0);
|
|
35
|
+
return { operation, verdict: passed ? "pass" : "fail", journeys };
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Model } from "@orthograph/compiler";
|
|
2
|
+
import type { Evidence, Verdict } from "#modules/evals/types.js";
|
|
3
|
+
import type { CallRecord, JourneyRun, StepResult } from "#modules/journeys/types.js";
|
|
4
|
+
import type { Trace } from "#modules/telemetry/types.js";
|
|
5
|
+
import { type JourneyDetail } from "./structured.ts";
|
|
6
|
+
/**
|
|
7
|
+
* World facts predict the access refusal before the server answers: no span will come (O2, gap 3). A payload the server
|
|
8
|
+
* can't decode leaves no span either, and is left out on purpose: a journey's payload is encoded from its declaration
|
|
9
|
+
* before it is sent, so that refusal is not one a journey predicts, and its missing telemetry stays a failure.
|
|
10
|
+
*/
|
|
11
|
+
export declare const refusedBeforeSpan: (call: CallRecord | undefined) => boolean;
|
|
12
|
+
/** 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. */
|
|
13
|
+
export declare const noSpanExpected: (call: CallRecord | undefined) => boolean;
|
|
14
|
+
export declare const spanFailures: (step: StepResult, trace: Trace | undefined, call: CallRecord | undefined) => ReadonlyArray<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Where a failing step's operation lives: its handler (`src/<thing>/<verb>.ts`) and the declaration it answers to, both
|
|
17
|
+
* relative to the project root. `undefined` when the step made no call or the model does not know the operation.
|
|
18
|
+
*/
|
|
19
|
+
export declare const whereLine: (model: Model | undefined, call: CallRecord | undefined) => string | undefined;
|
|
20
|
+
/** `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. */
|
|
21
|
+
export declare const journeyLines: (runs: ReadonlyArray<JourneyRun>, traces: ReadonlyMap<string, Trace>, empty?: boolean, model?: Model, spans?: boolean) => {
|
|
22
|
+
lines: string[];
|
|
23
|
+
failed: number;
|
|
24
|
+
failedTraces: {
|
|
25
|
+
readonly trace: string;
|
|
26
|
+
readonly what: string;
|
|
27
|
+
}[];
|
|
28
|
+
details: JourneyDetail[];
|
|
29
|
+
};
|
|
30
|
+
export declare const evalLines: (model: Model, verdicts: ReadonlyArray<Verdict>) => {
|
|
31
|
+
lines: string[];
|
|
32
|
+
failed: number;
|
|
33
|
+
};
|
|
34
|
+
/** Optional paths are counted from successful journey calls that actually ran the handler. */
|
|
35
|
+
export declare const optionalStepLines: (model: Model, runs: ReadonlyArray<JourneyRun>, evidence: ReadonlyArray<Evidence>) => string[];
|