@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,231 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
import { Blueprint } from "orthograph";
|
|
4
|
+
import { Scripting } from "orthograph/server";
|
|
5
|
+
import { callDevice, onDevice } from "./internal/device.js";
|
|
6
|
+
import { keepersIn } from "./internal/keepers.js";
|
|
7
|
+
import { loadProject } from "./internal/load.js";
|
|
8
|
+
import { callOperation, callTools, castPeople, doorFacts, makeKey, mayCall, mintCredential, signUpPeople, stateOf } from "./internal/world.js";
|
|
9
|
+
import { databaseFacts } from "./internal/database-facts.js";
|
|
10
|
+
import { d1Facts } from "./internal/d1-facts.js";
|
|
11
|
+
import { subjectId } from "./internal/subject.js";
|
|
12
|
+
import { runChecks, show } from "./internal/checks.js";
|
|
13
|
+
import { sendCommand } from "./internal/stand-call.js";
|
|
14
|
+
import { WorldClock } from "#modules/world-clock/service.js";
|
|
15
|
+
const nameOfOperation = (project, op) => [...project.operations].find(([, o]) => o === op)?.[0];
|
|
16
|
+
const tableOf = (project) => (thing) => [...project.things].find(([, t]) => t === thing)?.[0];
|
|
17
|
+
const run = (project, url, journey, index, how = "world", given, empty = false, device, stands = {}) => Effect.gen(function* () {
|
|
18
|
+
const world = journey.starts === undefined ? undefined : project.startingWorlds.get(journey.starts);
|
|
19
|
+
// A starting world may begin from another: make the oldest first, so each sees what the one before it gave.
|
|
20
|
+
const lineage = [];
|
|
21
|
+
for (let w = world; w && !lineage.includes(w); w = w.from === undefined ? undefined : project.startingWorlds.get(w.from))
|
|
22
|
+
lineage.unshift(w);
|
|
23
|
+
const missingParent = lineage[0]?.from;
|
|
24
|
+
const calls = [];
|
|
25
|
+
const steps = [];
|
|
26
|
+
const skipped = [];
|
|
27
|
+
const done = (stopped) => ({ name: journey.name, calls, steps, stopped, ...(skipped.length > 0 ? { skipped } : {}) });
|
|
28
|
+
if (journey.starts !== undefined && !world)
|
|
29
|
+
return done(`starting world ${journey.starts} is not in blueprint/starting-worlds`);
|
|
30
|
+
if (missingParent !== undefined)
|
|
31
|
+
return done(`starting world ${lineage[0].name} begins from ${missingParent}, which is not in blueprint/starting-worlds`);
|
|
32
|
+
// Each journey has its own people: the same name in two journeys is two people.
|
|
33
|
+
const names = [...new Set([...Object.keys(journey.cast), ...lineage.flatMap((w) => Object.keys(w.cast))])];
|
|
34
|
+
const cast = Object.assign({}, ...lineage.map((w) => w.cast), journey.cast);
|
|
35
|
+
// The system and a service are not people: nobody signs them up, and a world mints each one's token (M2-auth, fork 3).
|
|
36
|
+
// The keeper is no one to sign up either: it is the system's own principal, and it is not built yet (M8.10).
|
|
37
|
+
const keepers = keepersIn(names, [...lineage.map((w) => w.cast), journey.cast]);
|
|
38
|
+
const outsiders = names.filter((n) => keepers.has(n) || cast[n]?.kind === "system" || (cast[n]?.kind === "role" && cast[n]?.service !== undefined));
|
|
39
|
+
// Cast as anyone: not signed up, so the script can sign them up itself; everyone else is, for real.
|
|
40
|
+
const anyone = names.filter((n) => cast[n]?.kind === "anyone" && !lineage.some((w) => n in w.cast));
|
|
41
|
+
const wanted = [names.filter((n) => !anyone.includes(n) && !outsiders.includes(n)).map((n) => `j${index}.${n}`), anyone.map((n) => `j${index}.${n}`)];
|
|
42
|
+
const casting = yield* how === "world"
|
|
43
|
+
? castPeople(url, ...wanted).pipe(Effect.map((c) => ({ cast: c })))
|
|
44
|
+
: signUpPeople(url, ...wanted).pipe(Effect.map((c) => ({ cast: c })), Effect.catch((problem) => Effect.succeed({ problem })));
|
|
45
|
+
if ("problem" in casting)
|
|
46
|
+
return done(`its people couldn't be made: ${casting.problem}`);
|
|
47
|
+
const signedUp = casting.cast;
|
|
48
|
+
const people = Object.fromEntries(names.filter((n) => !outsiders.includes(n)).map((n) => [n, signedUp[`j${index}.${n}`]]));
|
|
49
|
+
// A world with a chain gives the journeys its keys and a payee as `s.world.chain` (K7 Q7); a starting world adds to it.
|
|
50
|
+
const env = { cast: people, ...(device === undefined ? {} : { world: device.given }) };
|
|
51
|
+
const facts = { facts: given ?? doorFacts(url), tableOf: tableOf(project), nameOf: (op) => nameOfOperation(project, op) };
|
|
52
|
+
// `s.clock.now` is what the world's clock reads, from the start and after each step that moves it. A world with no clock door has none.
|
|
53
|
+
const reading = yield* WorldClock.read(url);
|
|
54
|
+
if (reading !== undefined)
|
|
55
|
+
env["clock"] = { now: reading.now };
|
|
56
|
+
// The keeper's call is not built yet (M8.10): it refuses, never pretends.
|
|
57
|
+
const unbuilt = (call, kept = keepers) => call.kind !== "clock-call" && call.kind !== "stand-call" && kept.has(call.actor) ? "time is not built yet: M8.10 (a call made as the keeper)" : undefined;
|
|
58
|
+
/** A step that moves the world's clock: the world's door answers `{ now, fired }` once it is quiet at the target (M8.07). */
|
|
59
|
+
const moveClock = (step, call) => Effect.gen(function* () {
|
|
60
|
+
const moved = yield* WorldClock.move(url, call.move);
|
|
61
|
+
const answer = moved.body;
|
|
62
|
+
if (moved.status === 200)
|
|
63
|
+
env["last"] = moved.body;
|
|
64
|
+
// Whatever the status: a refusal that came after the clock had moved (a wake that failed, a world that never went quiet) carries the
|
|
65
|
+
// instant the move reached, and the journey goes on from the world's real time, not from the one it asked at.
|
|
66
|
+
if (typeof answer?.now === "string" && Number.isFinite(Date.parse(answer.now)))
|
|
67
|
+
env["clock"] = { now: answer.now };
|
|
68
|
+
const record = {
|
|
69
|
+
journey: journey.name, step, actor: "clock", person: "", operation: "clock", payload: { ...call.move }, status: moved.status, body: moved.body,
|
|
70
|
+
trace: randomBytes(16).toString("hex"), parent: randomBytes(8).toString("hex"), mayCall: true, journal: [], clock: true,
|
|
71
|
+
};
|
|
72
|
+
calls.push(record);
|
|
73
|
+
return record;
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* A command to a mount's stand-in, at the address of the one this world's prove started (never prove's own environment). Its args
|
|
77
|
+
* are resolved as a payload is; a 2xx JSON answer is `s.last`, recorded as a 200 so the step's checks judge it as an answer.
|
|
78
|
+
*/
|
|
79
|
+
const commandStand = (step, call) => Effect.gen(function* () {
|
|
80
|
+
const resolved = Scripting.resolve(call.args, env);
|
|
81
|
+
const said = resolved.missing.length > 0
|
|
82
|
+
? { status: undefined, body: null, failure: undefined }
|
|
83
|
+
: yield* sendCommand(Object.hasOwn(stands, call.mount) ? stands[call.mount] : undefined, call.mount, call.command, resolved.value);
|
|
84
|
+
if (said.status !== undefined && said.failure === undefined)
|
|
85
|
+
env["last"] = said.body;
|
|
86
|
+
const record = {
|
|
87
|
+
journey: journey.name, step, actor: "stand", person: "", operation: `${call.mount}/_stand/${call.command}`,
|
|
88
|
+
payload: (resolved.value ?? {}), status: said.failure === undefined && said.status !== undefined ? 200 : said.status !== undefined && (said.status < 200 || said.status > 299) ? said.status : 0, body: said.body,
|
|
89
|
+
trace: randomBytes(16).toString("hex"), parent: randomBytes(8).toString("hex"), mayCall: true, journal: [], stand: true,
|
|
90
|
+
};
|
|
91
|
+
calls.push(record);
|
|
92
|
+
return { record, failures: [...resolved.missing.map((m) => `args: nothing at ${m}`), ...(said.failure === undefined ? [] : [said.failure])] };
|
|
93
|
+
});
|
|
94
|
+
/** What a refused clock step says, in the world's own words: a step that asks for a refusal names it, and any other fails. */
|
|
95
|
+
const refusal = (record) => {
|
|
96
|
+
const said = record.body;
|
|
97
|
+
return `the world refused the clock step: ${said?._tag ?? record.status}${said?.message === undefined ? "" : ` (${said.message})`}`;
|
|
98
|
+
};
|
|
99
|
+
// Each credential the world minted for a cast member's way in, once per journey.
|
|
100
|
+
const minted = new Map();
|
|
101
|
+
const tokenFor = (actor, via) => Effect.gen(function* () {
|
|
102
|
+
const kind = cast[actor]?.kind;
|
|
103
|
+
if (kind === "system")
|
|
104
|
+
return (yield* mintCredential(url, { system: true })) ?? "";
|
|
105
|
+
const mount = kind === "role" ? project.mounts?.get(cast[actor].service) : undefined;
|
|
106
|
+
if (mount !== undefined)
|
|
107
|
+
return (yield* mintCredential(url, { service: mount })) ?? "";
|
|
108
|
+
if (via === undefined || via === "session")
|
|
109
|
+
return people[actor]?.token ?? "";
|
|
110
|
+
const key = `${actor}|${via}`;
|
|
111
|
+
if (!minted.has(key)) {
|
|
112
|
+
const session = people[actor]?.token;
|
|
113
|
+
minted.set(key, how === "world" ? yield* mintCredential(url, { name: `j${index}.${actor}`, via })
|
|
114
|
+
: session !== undefined && (via === "key" || via === "agent") ? yield* makeKey(url, session, via === "agent") : undefined);
|
|
115
|
+
}
|
|
116
|
+
return minted.get(key) ?? "";
|
|
117
|
+
});
|
|
118
|
+
/** Who the call is made as, from the cast member and the way in: what the declaration's `allowed` is read against before the call. */
|
|
119
|
+
const principalOf = (actor, via) => {
|
|
120
|
+
const kind = cast[actor]?.kind;
|
|
121
|
+
if (kind === "system")
|
|
122
|
+
return { kind: "system" };
|
|
123
|
+
if (kind === "role" && cast[actor]?.service !== undefined)
|
|
124
|
+
return { kind: "service", mount: project.mounts?.get(cast[actor].service) ?? "" };
|
|
125
|
+
const who = people[actor];
|
|
126
|
+
if (!who?.person)
|
|
127
|
+
return { kind: "anonymous" };
|
|
128
|
+
const named = { person: who.person, email: who.email };
|
|
129
|
+
return via === "agent" ? { kind: "agent", ...named, via: "agent" } : { kind: "person", ...named, via: via ?? "session" };
|
|
130
|
+
};
|
|
131
|
+
const make = (step, call, startingWorld = false) => Effect.gen(function* () {
|
|
132
|
+
if (call.operation === undefined) {
|
|
133
|
+
// The MCP door's tools, listed with the member's own credential: no operation runs, so no trace comes.
|
|
134
|
+
const listed = yield* callTools(url, yield* tokenFor(call.actor, call.via));
|
|
135
|
+
const record = {
|
|
136
|
+
journey: journey.name, step, actor: call.actor, person: people[call.actor]?.person ?? "", operation: "tools", payload: {}, status: listed.status, body: listed.body,
|
|
137
|
+
trace: listed.trace, parent: listed.parent, mayCall: true, journal: [], tools: true,
|
|
138
|
+
};
|
|
139
|
+
calls.push(record);
|
|
140
|
+
// The answer later steps read as `s.last`, as an operation's is: `{ tools }`, not the step before's.
|
|
141
|
+
if (listed.status === 200)
|
|
142
|
+
env["last"] = listed.body;
|
|
143
|
+
return { record, missing: [] };
|
|
144
|
+
}
|
|
145
|
+
const operation = nameOfOperation(project, call.operation) ?? "an undeclared operation";
|
|
146
|
+
const resolved = Scripting.resolve(call.payload, env);
|
|
147
|
+
const payload = resolved.value;
|
|
148
|
+
const person = people[call.actor]?.person ?? "";
|
|
149
|
+
const may = yield* mayCall(facts.facts, facts.tableOf, call.operation, payload, principalOf(call.actor, call.via), project.mounts);
|
|
150
|
+
const model = project.model.operations[operation];
|
|
151
|
+
// A plugin's operation that runs on the device is run in this process, by its `world` entry, never sent to the server.
|
|
152
|
+
const r = device !== undefined && onDevice(model)
|
|
153
|
+
? yield* callDevice(project, device, operation, call.operation, payload)
|
|
154
|
+
: yield* callOperation(url, facts.facts, operation, call.operation, payload, yield* tokenFor(call.actor, call.via), call.request, empty && startingWorld);
|
|
155
|
+
const id = model?.move && r.status === 200 ? subjectId(model, r.wire, r.body) : undefined;
|
|
156
|
+
const state = id === undefined ? undefined : yield* stateOf(facts.facts, model.thing, id);
|
|
157
|
+
const record = {
|
|
158
|
+
journey: journey.name, step, actor: call.actor, person, operation, payload: r.wire, status: r.status, body: r.body,
|
|
159
|
+
trace: r.trace, parent: r.parent, mayCall: may, journal: r.journal, stored: typeof state === "string" ? state : undefined,
|
|
160
|
+
};
|
|
161
|
+
calls.push(record);
|
|
162
|
+
if (r.status === 200) {
|
|
163
|
+
env["last"] = yield* Schema.decodeUnknownEffect(call.operation.answerSchema)(r.body).pipe(Effect.orElseSucceed(() => r.body));
|
|
164
|
+
}
|
|
165
|
+
return { record, missing: resolved.missing };
|
|
166
|
+
});
|
|
167
|
+
for (const [at, w] of lineage.entries()) {
|
|
168
|
+
// A starting world's own cast is what its lineage so far says: a later world or the journey may recast a name.
|
|
169
|
+
const keptHere = keepersIn(names, lineage.slice(0, at + 1).map((x) => x.cast));
|
|
170
|
+
const script = Scripting.script(Object.fromEntries(names.map((n) => [n, Blueprint.signedIn])));
|
|
171
|
+
for (const call of w.makes(script)) {
|
|
172
|
+
if (call.kind === "clock-call") {
|
|
173
|
+
const moved = yield* moveClock(`starting world ${w.name}`, call);
|
|
174
|
+
if (moved.status !== 200)
|
|
175
|
+
return done(`starting world ${w.name}: ${refusal(moved)}`);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const why = unbuilt(call, keptHere);
|
|
179
|
+
if (why !== undefined)
|
|
180
|
+
return done(`starting world ${w.name}: ${why}`);
|
|
181
|
+
const { record } = yield* make(`starting world ${w.name}`, call, true);
|
|
182
|
+
if (record.status !== 200)
|
|
183
|
+
return done(`starting world ${w.name}: ${record.operation} ${record.status === 500 ? "died" : `answered ${record.status}`}: ${show(record.body)}`);
|
|
184
|
+
}
|
|
185
|
+
const gives = Scripting.resolve(w.gives(script), env);
|
|
186
|
+
if (gives.missing.length > 0)
|
|
187
|
+
return done(`starting world ${w.name} gives nothing at ${gives.missing.join(", ")}`);
|
|
188
|
+
env["world"] = { ...env["world"], ...gives.value };
|
|
189
|
+
}
|
|
190
|
+
for (const step of journey.steps(Scripting.script(journey.cast))) {
|
|
191
|
+
if (step.call.kind === "clock-call") {
|
|
192
|
+
const record = yield* moveClock(step.title, step.call);
|
|
193
|
+
const checked = yield* runChecks(step.checks, record, env, facts);
|
|
194
|
+
// A refused move that no check asks for is a failure, never a pass by silence.
|
|
195
|
+
const unasked = record.status !== 200 && !step.checks.some((c) => c.kind === "refuses") ? [refusal(record)] : [];
|
|
196
|
+
steps.push({
|
|
197
|
+
journey: journey.name, title: step.title, trace: record.trace, spans: checked.spans,
|
|
198
|
+
failures: [...unasked, ...checked.failures], findings: [...unasked.map((message) => ({ message })), ...checked.findings],
|
|
199
|
+
});
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (step.call.kind === "stand-call") {
|
|
203
|
+
// A failed command fails its step and leaves `s.last` as it was; the journey goes on, as after an operation's refusal.
|
|
204
|
+
const { record, failures } = yield* commandStand(step.title, step.call);
|
|
205
|
+
const checked = yield* runChecks(step.checks, record, env, facts);
|
|
206
|
+
steps.push({
|
|
207
|
+
journey: journey.name, title: step.title, trace: record.trace, spans: checked.spans,
|
|
208
|
+
failures: [...failures, ...checked.failures], findings: [...failures.map((message) => ({ message })), ...checked.findings],
|
|
209
|
+
});
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const why = unbuilt(step.call);
|
|
213
|
+
if (why !== undefined)
|
|
214
|
+
return done(`"${step.title}": ${why}`);
|
|
215
|
+
const called = step.call;
|
|
216
|
+
const gone = project.omitted?.get(called.operation);
|
|
217
|
+
if (gone) {
|
|
218
|
+
skipped.push({ step: step.title, ...gone });
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const { record, missing } = yield* make(step.title, called);
|
|
222
|
+
const checked = yield* runChecks(step.checks, record, env, facts);
|
|
223
|
+
steps.push({
|
|
224
|
+
journey: journey.name, title: step.title, trace: record.trace, spans: checked.spans,
|
|
225
|
+
failures: [...missing.map((m) => `payload: nothing at ${m}`), ...checked.failures],
|
|
226
|
+
findings: [...missing.map((m) => ({ message: `payload: nothing at ${m}` })), ...checked.findings],
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return done(undefined);
|
|
230
|
+
});
|
|
231
|
+
export const Journeys = { load: loadProject, run, databaseFacts, d1Facts };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { type Effect } from "effect";
|
|
2
|
+
import type { Journey, Operation, Read, StartingWorld, Thing } from "orthograph";
|
|
3
|
+
import type { Model } from "@orthograph/compiler";
|
|
4
|
+
import type { DeviceWorldOf } from "@orthograph/language-effect/device";
|
|
5
|
+
/** One HTTP call to the world, as `prove` saw it. */
|
|
6
|
+
export interface CallRecord {
|
|
7
|
+
readonly journey: string;
|
|
8
|
+
/** The step's title, or `starting world <name>`. */
|
|
9
|
+
readonly step: string;
|
|
10
|
+
readonly actor: string;
|
|
11
|
+
readonly person: string;
|
|
12
|
+
readonly operation: string;
|
|
13
|
+
readonly payload: Readonly<Record<string, unknown>>;
|
|
14
|
+
readonly status: number;
|
|
15
|
+
readonly body: unknown;
|
|
16
|
+
readonly trace: string;
|
|
17
|
+
/** The caller's own span id, sent in `traceparent`: the server's root span is its child. */
|
|
18
|
+
readonly parent: string;
|
|
19
|
+
/** Decided before the call from the world's facts and the declaration's `allowed`, never from the answer. */
|
|
20
|
+
readonly mayCall: boolean;
|
|
21
|
+
/** The journal entries the call's trace wrote. */
|
|
22
|
+
readonly journal: ReadonlyArray<{
|
|
23
|
+
readonly event: string;
|
|
24
|
+
readonly move: string;
|
|
25
|
+
readonly subject: string;
|
|
26
|
+
readonly fields: Readonly<Record<string, unknown>>;
|
|
27
|
+
}>;
|
|
28
|
+
/** For an answered call whose operation moves: the stored state of what it moved, read right after the call. */
|
|
29
|
+
readonly stored?: string | undefined;
|
|
30
|
+
/** The call listed the MCP door's tools (`.tools()`): it ran no operation, so no span of its own comes, and `body` is `{ tools }`. */
|
|
31
|
+
readonly tools?: true;
|
|
32
|
+
/** The step moved the world's clock (`s.clock.advance`, `.moveTo`): no operation ran and no span comes; `body` is the door's `{ now, fired }` or its refusal. */
|
|
33
|
+
readonly clock?: true;
|
|
34
|
+
/** The step sent a command to a mount's stand-in (`Stand.command`): no operation ran and no span comes; `body` is the stand-in's answer. */
|
|
35
|
+
readonly stand?: true;
|
|
36
|
+
}
|
|
37
|
+
export type { D1Access } from "./internal/d1-facts.ts";
|
|
38
|
+
import type { D1Access } from "./internal/d1-facts.ts";
|
|
39
|
+
/** What `prove` reads back from the environment's database: a row by table and id (wire form), and a trace's journal entries. */
|
|
40
|
+
export interface Facts {
|
|
41
|
+
readonly record: (table: string, id: string) => Effect.Effect<Record<string, unknown> | null>;
|
|
42
|
+
readonly journal: (trace: string) => Effect.Effect<CallRecord["journal"]>;
|
|
43
|
+
}
|
|
44
|
+
export interface StepResult {
|
|
45
|
+
readonly journey: string;
|
|
46
|
+
readonly title: string;
|
|
47
|
+
readonly trace: string;
|
|
48
|
+
/** Empty when the step passed (span checks are added once telemetry is in). */
|
|
49
|
+
readonly failures: ReadonlyArray<string>;
|
|
50
|
+
/** The same failures with what was expected and what came back, for the structured report. */
|
|
51
|
+
readonly findings?: ReadonlyArray<{
|
|
52
|
+
readonly message: string;
|
|
53
|
+
readonly expected?: string;
|
|
54
|
+
readonly got?: string;
|
|
55
|
+
}>;
|
|
56
|
+
/** Span names the step expects present or absent in its trace. */
|
|
57
|
+
readonly spans: {
|
|
58
|
+
readonly present: ReadonlyArray<string>;
|
|
59
|
+
readonly absent: ReadonlyArray<string>;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export interface JourneyRun {
|
|
63
|
+
readonly name: string;
|
|
64
|
+
readonly calls: ReadonlyArray<CallRecord>;
|
|
65
|
+
readonly steps: ReadonlyArray<StepResult>;
|
|
66
|
+
/** Why the journey stopped before its steps, if it did. */
|
|
67
|
+
readonly stopped: string | undefined;
|
|
68
|
+
/** Its steps that run an operation a mount omits: not run, and named (M1-plugins section 3). */
|
|
69
|
+
readonly skipped?: ReadonlyArray<{
|
|
70
|
+
readonly step: string;
|
|
71
|
+
readonly operation: string;
|
|
72
|
+
readonly file: string;
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* What prove gives the plugin code it runs in place of a device (M1.29): the `world` entry of each `runs: "client"`
|
|
77
|
+
* operation, in this process. `world` is what that code may ask of the world (`DeviceWorld`); `given` is what journeys
|
|
78
|
+
* read of it as `s.world` (a world with a chain gives `chain.keys.<host>` and `chain.payee`, K7 Q7); `otlp` is where the
|
|
79
|
+
* code's spans and logs go, so each call's trace holds them as a served operation's does.
|
|
80
|
+
*/
|
|
81
|
+
export interface DeviceHost {
|
|
82
|
+
readonly otlp: string | undefined;
|
|
83
|
+
readonly service: string;
|
|
84
|
+
readonly world: DeviceWorldOf;
|
|
85
|
+
readonly given: Readonly<Record<string, unknown>>;
|
|
86
|
+
}
|
|
87
|
+
/** What the project declares, loaded once: its operations and things by name, its journeys and starting worlds. */
|
|
88
|
+
export interface Project {
|
|
89
|
+
readonly root: string;
|
|
90
|
+
readonly model: Model;
|
|
91
|
+
/** Operations and reads, by name. */
|
|
92
|
+
readonly operations: ReadonlyMap<string, Operation | Read>;
|
|
93
|
+
readonly things: ReadonlyMap<string, Thing>;
|
|
94
|
+
readonly journeys: ReadonlyArray<Journey>;
|
|
95
|
+
readonly journeyFiles?: ReadonlyArray<string>;
|
|
96
|
+
readonly startingWorlds: ReadonlyMap<string, StartingWorld>;
|
|
97
|
+
/** Each operation a mount omits, by its declaration: a journey's step that runs one is skipped. */
|
|
98
|
+
readonly omitted?: ReadonlyMap<unknown, {
|
|
99
|
+
readonly operation: string;
|
|
100
|
+
readonly file: string;
|
|
101
|
+
}>;
|
|
102
|
+
/** Each adapter's mount by the name it is mounted under: what a `service` role in a declaration is read against, and what a journey's service cast member is called by. */
|
|
103
|
+
readonly mounts?: ReadonlyMap<unknown, string>;
|
|
104
|
+
/** The journeys skipped because they still hold blanks (stubs from `ortho add journeys`), by file (K16 e). */
|
|
105
|
+
readonly unfinished?: ReadonlyArray<string>;
|
|
106
|
+
}
|
|
107
|
+
declare const ProjectFailed_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 & {
|
|
108
|
+
readonly _tag: "ProjectFailed";
|
|
109
|
+
} & Readonly<A>;
|
|
110
|
+
export declare class ProjectFailed extends ProjectFailed_base<{
|
|
111
|
+
readonly message: string;
|
|
112
|
+
}> {
|
|
113
|
+
}
|
|
114
|
+
export interface JourneysApi {
|
|
115
|
+
/** Facts read from an environment's database file, for one that has closed its front door (D3 #127). */
|
|
116
|
+
readonly databaseFacts: (state: string) => Facts;
|
|
117
|
+
/** Facts read from a deployed environment's D1 databases through Cloudflare's API, with the operator's credential. */
|
|
118
|
+
readonly d1Facts: (access: D1Access) => Facts;
|
|
119
|
+
readonly load: (root: string, model: Model) => Effect.Effect<Project, ProjectFailed>;
|
|
120
|
+
/**
|
|
121
|
+
* Run one journey against the world at `url`. Span checks wait for telemetry, so they are made later by `check`.
|
|
122
|
+
* `people` is how the cast comes to be: `"world"` (the default) asks the world's `/_world/cast`; `"sign-up"` signs each
|
|
123
|
+
* person up for real through Better Auth's own routes, as someone would on a real environment, which has no cast.
|
|
124
|
+
* `facts` is where the rows and journal are read: by default the world's own front door at `url`; an environment that has
|
|
125
|
+
* closed the door (staging) gives its database instead.
|
|
126
|
+
* `device`: where a plugin's operation that runs on the device is run (its `world` entry, in this process). Without
|
|
127
|
+
* one such a call goes to the server like any other, which has no route for it.
|
|
128
|
+
* `stands`: the address of each stand-in the world's prove started, by mount (G16-adapter-mounts call 4). A step's command
|
|
129
|
+
* to a mount with none fails, and nothing is sent.
|
|
130
|
+
*/
|
|
131
|
+
readonly run: (project: Project, url: string, journey: Journey, index: number, people?: "world" | "sign-up", facts?: Facts, empty?: boolean, device?: DeviceHost, stands?: Readonly<Record<string, string>>) => Effect.Effect<JourneyRun>;
|
|
132
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Running journeys: each starting world made by its declared calls, each step called as its cast member, every call
|
|
2
|
+
// recorded with its trace so the evals can read what really happened.
|
|
3
|
+
import { Data } from "effect";
|
|
4
|
+
export class ProjectFailed extends Data.TaggedError("ProjectFailed") {
|
|
5
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Server } from "node:http";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { PortalFeedFailed, type PortalFeedOptions } from "../types.ts";
|
|
4
|
+
export declare const listen: (options: PortalFeedOptions, startedAt: number) => Effect.Effect<{
|
|
5
|
+
readonly server: Server;
|
|
6
|
+
readonly url: string;
|
|
7
|
+
}, PortalFeedFailed, never>;
|
|
8
|
+
export declare const close: ({ server }: {
|
|
9
|
+
readonly server: Server;
|
|
10
|
+
}) => Effect.Effect<void, never, never>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { Clock, Effect } from "effect";
|
|
3
|
+
import { PortalFeedFailed } from "../types.js";
|
|
4
|
+
/** A read that failed is its reason, beside the other source's answer: one source down never takes the other with it. */
|
|
5
|
+
const attempt = (read) => read.pipe(Effect.map((value) => ({ state: "available", value })), Effect.catch((failure) => Effect.succeed({ state: "unavailable", reason: failure.message })));
|
|
6
|
+
/** The window as it stands now: the `now` it was read at, and each source's answer on its own. */
|
|
7
|
+
const answer = (options, startedAt) => Effect.gen(function* () {
|
|
8
|
+
const now = yield* options.now ?? Clock.currentTimeMillis;
|
|
9
|
+
// What the source can really supply is what this feed has held it for, up to the cap: never more, so a longer alert window is unknown, not judged on the part.
|
|
10
|
+
const historyMs = Math.min(options.historyMs ?? options.windowMs, Math.max(0, now - startedAt));
|
|
11
|
+
// Traces span the history (the portal's calls page filters them to its window); the points stay the display window's.
|
|
12
|
+
const traces = yield* attempt(options.source.window(Math.max(options.windowMs, historyMs), now).pipe(Effect.map((found) => Object.fromEntries(found))));
|
|
13
|
+
const points = yield* attempt(options.metrics.window(options.windowMs, now));
|
|
14
|
+
return { environment: options.environment, now, windowMs: options.windowMs, historyMs, traces, points };
|
|
15
|
+
});
|
|
16
|
+
export const listen = (options, startedAt) => Effect.callback((resume) => {
|
|
17
|
+
const server = createServer((request, response) => {
|
|
18
|
+
if (request.method !== "GET") {
|
|
19
|
+
response.writeHead(405).end();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
Effect.runPromise(answer(options, startedAt)).then((done) => {
|
|
23
|
+
response.writeHead(200, { "content-type": "application/json", "cache-control": "no-store" }).end(JSON.stringify(done));
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
server.once("error", (error) => resume(Effect.fail(new PortalFeedFailed({ message: `the portal's telemetry feed couldn't listen: ${error.message}` }))));
|
|
27
|
+
server.listen(0, "127.0.0.1", () => resume(Effect.succeed({ server, url: `http://127.0.0.1:${server.address().port}` })));
|
|
28
|
+
});
|
|
29
|
+
export const close = ({ server }) => Effect.callback((resume) => {
|
|
30
|
+
server.close(() => resume(Effect.void));
|
|
31
|
+
server.closeAllConnections();
|
|
32
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Clock, Effect } from "effect";
|
|
2
|
+
import { close, listen } from "./internal/listen.js";
|
|
3
|
+
export const PortalFeed = {
|
|
4
|
+
// The feed holds its source from the moment it is served (a world's collector is made just before): that moment is where its history starts.
|
|
5
|
+
serve: (options) => (options.now ?? Clock.currentTimeMillis).pipe(Effect.flatMap((startedAt) => Effect.acquireRelease(listen(options, startedAt), close)), Effect.map(({ url }) => ({ url }))),
|
|
6
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Effect, type Scope } from "effect";
|
|
2
|
+
import type { MetricsSource, TraceSource } from "#modules/telemetry/types.js";
|
|
3
|
+
declare const PortalFeedFailed_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 & {
|
|
4
|
+
readonly _tag: "PortalFeedFailed";
|
|
5
|
+
} & Readonly<A>;
|
|
6
|
+
export declare class PortalFeedFailed extends PortalFeedFailed_base<{
|
|
7
|
+
readonly message: string;
|
|
8
|
+
}> {
|
|
9
|
+
}
|
|
10
|
+
export interface PortalFeedOptions {
|
|
11
|
+
/** Where the world's spans are read from (its collector). */
|
|
12
|
+
readonly source: TraceSource;
|
|
13
|
+
/** Where the world's `ortho.calls` are read from. */
|
|
14
|
+
readonly metrics: MetricsSource;
|
|
15
|
+
/** The environment the world stands for: `local` for a world of prove. */
|
|
16
|
+
readonly environment: string;
|
|
17
|
+
/** The Calls page's display window: what `points` cover and what the page shows. */
|
|
18
|
+
readonly windowMs: number;
|
|
19
|
+
/** The most history the feed will supply for monitoring (an alert's longest window). What it answers as `historyMs` is the least of this and how long the feed has held the source: a world started 10 minutes ago holds 10 minutes. Default: `windowMs`. */
|
|
20
|
+
readonly historyMs?: number;
|
|
21
|
+
/** The window's end for each answer. Default: Effect's clock (the composition root's, never a `Date`). A test injects a fixed one. */
|
|
22
|
+
readonly now?: Effect.Effect<number>;
|
|
23
|
+
}
|
|
24
|
+
export interface PortalFeedApi {
|
|
25
|
+
/** A loopback server answering `GET /` with `{ environment, now, windowMs, historyMs, traces, points }`; its URL goes to the Worker as `ORTHO_PORTAL_FEED`. Closed with the scope. */
|
|
26
|
+
readonly serve: (options: PortalFeedOptions) => Effect.Effect<{
|
|
27
|
+
readonly url: string;
|
|
28
|
+
}, PortalFeedFailed, Scope.Scope>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// The window of a local world's telemetry, answered over loopback to that world's own portal (M1.13). The Worker runs in workerd and cannot
|
|
2
|
+
// open the collector's files; whoever started the world can. The portal reads the answer as `ORTHO_PORTAL_FEED` and takes its `now` as the clock.
|
|
3
|
+
import { Data } from "effect";
|
|
4
|
+
export class PortalFeedFailed extends Data.TaggedError("PortalFeedFailed") {
|
|
5
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { Built } from "#modules/build/types.js";
|
|
3
|
+
import type { Up } from "#modules/environments/types.js";
|
|
4
|
+
import { PromoteFailed, type Target } from "../types.ts";
|
|
5
|
+
/** Start `target` on the bundle (or restart it onto it, its state kept), then check `GET /_ortho/bundle` answers the same revision and hash. */
|
|
6
|
+
export declare const runningOn: (root: string, target: Target, built: Built) => Effect.Effect<Up, PromoteFailed>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// The target environment: started or restarted onto the bundle, and asked what it runs.
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { Environments } from "#modules/environments/service.js";
|
|
4
|
+
import { PromoteFailed } from "../types.js";
|
|
5
|
+
/** Start `target` on the bundle (or restart it onto it, its state kept), then check `GET /_ortho/bundle` answers the same revision and hash. */
|
|
6
|
+
export const runningOn = (root, target, built) => Effect.gen(function* () {
|
|
7
|
+
const up = yield* Environments.up({ root, name: target, revision: built.revision }).pipe(Effect.mapError((e) => new PromoteFailed({ message: e.message })));
|
|
8
|
+
yield* Environments.verify({ root, name: target, pid: up.pid, revision: built.revision, sha256: built.sha256 }).pipe(Effect.mapError((e) => new PromoteFailed({ message: e.message })));
|
|
9
|
+
return up;
|
|
10
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { Model } from "@orthograph/compiler";
|
|
3
|
+
import type { Built } from "#modules/build/types.js";
|
|
4
|
+
import type { Held } from "#modules/verdicts/types.js";
|
|
5
|
+
import { PromoteFailed, PromoteRefused } from "../types.ts";
|
|
6
|
+
/** The revision's bundle, as `ortho build` kept it: refused when the tree isn't that commit, or there is no bundle, or it was altered. */
|
|
7
|
+
export declare const bundleOf: (root: string, revision: string) => Effect.Effect<Built, PromoteRefused | PromoteFailed>;
|
|
8
|
+
/** Every operation of the model has a passing verdict from `main` for the revision in `environment`, or the refusal says which do not. */
|
|
9
|
+
export declare const verdictsIn: (logbook: string, model: Model, revision: string, environment: string, sha256: string) => Effect.Effect<ReadonlyArray<Held>, PromoteRefused | PromoteFailed>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// What a promotion needs before anything starts: a clean tree, the revision's own built bundle, and its verdicts.
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { Build } from "#modules/build/service.js";
|
|
4
|
+
import { Verdicts } from "#modules/verdicts/service.js";
|
|
5
|
+
import { PromoteFailed, PromoteRefused } from "../types.js";
|
|
6
|
+
/** Only verdicts posted from `main` open a gate: a pull request's never do (D3 #8). */
|
|
7
|
+
const MAIN = "refs/heads/main";
|
|
8
|
+
const failed = (e) => new PromoteFailed({ message: e.message });
|
|
9
|
+
/** The revision's bundle, as `ortho build` kept it: refused when the tree isn't that commit, or there is no bundle, or it was altered. */
|
|
10
|
+
export const bundleOf = (root, revision) => Effect.gen(function* () {
|
|
11
|
+
const problems = [];
|
|
12
|
+
if (yield* Build.dirty(root).pipe(Effect.mapError(failed))) {
|
|
13
|
+
problems.push(`refused: the working tree differs from ${revision}: commit or stash what changed, so the bundle is that commit's`);
|
|
14
|
+
}
|
|
15
|
+
const kept = yield* Build.find(root, revision).pipe(Effect.catchTag("BuildFailed", (e) => Effect.sync(() => void problems.push(`refused: the bundle of ${revision} is not what was built: ${e.message}`)).pipe(Effect.as(undefined))));
|
|
16
|
+
if (kept === undefined && problems.length === 0)
|
|
17
|
+
problems.push(`refused: ${revision} has no built bundle: run \`ortho build\``);
|
|
18
|
+
if (problems.length > 0 || kept === undefined)
|
|
19
|
+
return yield* new PromoteRefused({ lines: problems });
|
|
20
|
+
return kept;
|
|
21
|
+
});
|
|
22
|
+
/** Every operation of the model has a passing verdict from `main` for the revision in `environment`, or the refusal says which do not. */
|
|
23
|
+
export const verdictsIn = (logbook, model, revision, environment, sha256) => Effect.gen(function* () {
|
|
24
|
+
const held = yield* Verdicts.latest({ logbook, revision, environment, ref: MAIN }).pipe(Effect.mapError(failed));
|
|
25
|
+
const passed = held.filter((v) => v.verdict === "pass" && v.sha256 === sha256);
|
|
26
|
+
const passing = new Set(passed.map((v) => v.operation));
|
|
27
|
+
const missing = Object.keys(model.operations).filter((op) => !passing.has(op)).sort();
|
|
28
|
+
if (missing.length === 0)
|
|
29
|
+
return passed;
|
|
30
|
+
return yield* new PromoteRefused({
|
|
31
|
+
lines: [
|
|
32
|
+
passing.size === 0 ? `refused: ${revision} has no green verdicts in ${environment}` : `refused: ${revision} has no green verdicts in ${environment} for every operation`,
|
|
33
|
+
`missing: ${missing.join(", ")}`,
|
|
34
|
+
...(held.some((v) => v.verdict === "pass" && v.sha256 !== sha256) ? [`bundle ${sha256}: the latest proof is missing its bundle hash or names different bytes`] : []),
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { Model } from "@orthograph/compiler";
|
|
3
|
+
import { PromoteFailed } from "../types.ts";
|
|
4
|
+
type Common = {
|
|
5
|
+
readonly root: string;
|
|
6
|
+
readonly revision: string;
|
|
7
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
8
|
+
readonly say: (line: string) => Effect.Effect<void>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Staging: `<next>-next.<n>`, n one past the highest the registry has, under the dist-tag `next`. The next version is the one
|
|
12
|
+
* production will release, so it is worked out from the model against the last release. Nothing is published without a registry,
|
|
13
|
+
* and the line says so.
|
|
14
|
+
*/
|
|
15
|
+
export declare const stagingPrerelease: ({ root, revision, env, say, logbook, model }: Common & {
|
|
16
|
+
readonly logbook: string;
|
|
17
|
+
readonly model: Model;
|
|
18
|
+
}) => Effect.Effect<void, PromoteFailed, never>;
|
|
19
|
+
/** Production: the release itself, which takes `latest`. A version the registry already has is left alone, so a promotion can be run again. */
|
|
20
|
+
export declare const productionRelease: ({ root, revision, env, say, version }: Common & {
|
|
21
|
+
readonly version: string;
|
|
22
|
+
}) => Effect.Effect<void, PromoteFailed, never>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// What a promotion publishes (D3 #111): staging the prerelease of the next version, production the release, as each environment's
|
|
2
|
+
// `publish` list in the blueprint says, to the registry in `ORTHO_REGISTRY` (Verdaccio, on this machine).
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
import { Publish } from "#modules/publish/service.js";
|
|
5
|
+
import { Releases } from "#modules/releases/service.js";
|
|
6
|
+
import { PromoteFailed } from "../types.js";
|
|
7
|
+
const failed = (e) => new PromoteFailed({ message: e.message });
|
|
8
|
+
/**
|
|
9
|
+
* Staging: `<next>-next.<n>`, n one past the highest the registry has, under the dist-tag `next`. The next version is the one
|
|
10
|
+
* production will release, so it is worked out from the model against the last release. Nothing is published without a registry,
|
|
11
|
+
* and the line says so.
|
|
12
|
+
*/
|
|
13
|
+
export const stagingPrerelease = ({ root, revision, env, say, logbook, model }) => Effect.gen(function* () {
|
|
14
|
+
if (Publish.registry(env) === undefined)
|
|
15
|
+
return yield* say("skipped npm (set ORTHO_REGISTRY to a registry on this machine to publish to)");
|
|
16
|
+
const next = yield* Releases.next(logbook, model).pipe(Effect.mapError(failed));
|
|
17
|
+
const version = yield* Publish.prerelease({ root, env, version: next }).pipe(Effect.mapError(failed));
|
|
18
|
+
yield* Publish.run({ root, sourceRevision: revision, env, environment: "staging", version, mode: "publish", localTap: false, say }).pipe(Effect.mapError(failed));
|
|
19
|
+
});
|
|
20
|
+
/** Production: the release itself, which takes `latest`. A version the registry already has is left alone, so a promotion can be run again. */
|
|
21
|
+
export const productionRelease = ({ root, revision, env, say, version }) => Publish.run({ root, sourceRevision: revision, env, environment: "production", version, mode: "publish", localTap: false, say }).pipe(Effect.mapError(failed), Effect.asVoid);
|