@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,98 @@
|
|
|
1
|
+
import { Names } from "orthograph/server";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { Clock, Duration, Effect } from "effect";
|
|
5
|
+
import { Compiler, nodeSource } from "@orthograph/compiler";
|
|
6
|
+
import { Collectors, FileMetrics, privateKeys } from "#modules/telemetry/service.js";
|
|
7
|
+
import { PortalFeed } from "#modules/portal-feed/service.js";
|
|
8
|
+
import { Sinks } from "#modules/sinks/service.js";
|
|
9
|
+
import { Journeys } from "#modules/journeys/service.js";
|
|
10
|
+
import { Worlds } from "#modules/world/service.js";
|
|
11
|
+
import { Impact } from "#modules/impact/service.js";
|
|
12
|
+
import { ProveFailed } from "./types.js";
|
|
13
|
+
import { handlerHashes } from "#modules/verdicts/internal/proof.js";
|
|
14
|
+
import { closing, exercise } from "./internal/exercise.js";
|
|
15
|
+
import { PORTAL_HISTORY_MS, PORTAL_WINDOW_MS, standWorld } from "./internal/stand.js";
|
|
16
|
+
import { Warm } from "#modules/warm/service.js";
|
|
17
|
+
import { fingerprint } from "#modules/warm/internal/source.js";
|
|
18
|
+
import { proveInTest } from "./internal/test-run.js";
|
|
19
|
+
import { emptyWorld } from "./internal/empty-world.js";
|
|
20
|
+
import { proveReport } from "./internal/structured.js";
|
|
21
|
+
import { detail, headline, narrowed } from "./internal/changed-run.js";
|
|
22
|
+
import { provedAt } from "./internal/staged.js";
|
|
23
|
+
const failed = (e) => new ProveFailed({ message: e.message });
|
|
24
|
+
/** The compiled model and the project's journeys, or why prove can't run. */
|
|
25
|
+
const load = (root, empty = false) => Effect.gen(function* () {
|
|
26
|
+
const model = yield* Compiler.model.pipe(Effect.provide(nodeSource(root)), Effect.mapError((e) => new ProveFailed({ message: e._tag === "BlueprintInvalid" ? `the blueprint is invalid:\n - ${e.problems.join("\n - ")}` : e.message })));
|
|
27
|
+
const project = yield* Journeys.load(root, model).pipe(Effect.mapError(failed));
|
|
28
|
+
if (project.journeys.length === 0 && !empty)
|
|
29
|
+
return yield* new ProveFailed({ message: `no journeys in ${resolve(root, "journeys")}` });
|
|
30
|
+
return { model, project };
|
|
31
|
+
});
|
|
32
|
+
/** One line per journey skipped for its blanks, so a stub is never silently counted as proved. */
|
|
33
|
+
const unfinishedIn = (project) => (project.unfinished ?? []).map((file) => `journey ${file} skipped: it still has blanks (ortho check names them)`);
|
|
34
|
+
export const Prove = {
|
|
35
|
+
run: ({ root, port, empty = false, only, env, changed = false, say }) => Effect.gen(function* () {
|
|
36
|
+
const { model, project: loaded } = yield* load(root, empty);
|
|
37
|
+
// `--changed`: what the last proof's record and today's files say to run; with nothing to run or judge, no world is made at all.
|
|
38
|
+
// What a proof rests on is read once, before anything runs, and is what the run is recorded against.
|
|
39
|
+
const stamp = !empty && only === undefined ? yield* Impact.stamp(root, model) : undefined;
|
|
40
|
+
const selection = changed && stamp !== undefined ? yield* Impact.select(root, model, stamp) : undefined;
|
|
41
|
+
const judging = selection !== undefined && selection.fellBack === null ? new Set(selection.judge) : undefined;
|
|
42
|
+
const project = selection !== undefined && judging !== undefined ? narrowed(loaded, selection.rerun) : loaded;
|
|
43
|
+
const said = selection === undefined ? [] : headline(model, selection, project.journeys.length, loaded.journeys.length);
|
|
44
|
+
if (say !== undefined)
|
|
45
|
+
for (const line of said)
|
|
46
|
+
yield* say(line);
|
|
47
|
+
const report = selection === undefined ? undefined : detail(model, selection, project.journeyFiles ?? []);
|
|
48
|
+
if (selection !== undefined && judging !== undefined && project.journeys.length === 0 && judging.size === 0) {
|
|
49
|
+
yield* Impact.settle(root, model, { journeys: [], operations: [] }, stamp);
|
|
50
|
+
const lines = [...said, ...unfinishedIn(loaded), "prove ✔"];
|
|
51
|
+
return { lines, passed: true, structured: proveReport([], 0, 0, lines, true, report), ...(say === undefined ? {} : { said: said.length }) };
|
|
52
|
+
}
|
|
53
|
+
const journeys = only === undefined ? project.journeys : project.journeys.filter((journey) => journey.name === only);
|
|
54
|
+
if (journeys.length === 0 && !(empty && only === undefined) && !(judging !== undefined && judging.size > 0))
|
|
55
|
+
return yield* new ProveFailed({ message: `no journey named "${only}"` });
|
|
56
|
+
const bodies = handlerHashes(root, model);
|
|
57
|
+
const world = empty ? yield* emptyWorld(root, model) : root;
|
|
58
|
+
const stand = yield* standWorld({ root, world, model, port, empty, env });
|
|
59
|
+
const [took, done] = yield* Effect.timed(exercise(model, { ...project, journeys }, stand.url, stand.collector, undefined, stand.otlp, undefined, empty, bodies, stand.device, judging, stand.stands));
|
|
60
|
+
// A run with a failing journey proves nothing: its operations are recorded as judged and not passed (D2 #80).
|
|
61
|
+
if (stamp !== undefined) {
|
|
62
|
+
yield* Impact.record(root, model, done.judged, judging === undefined ? done.results : done.results.filter((r) => judging.has(r.operation)));
|
|
63
|
+
yield* Impact.settle(root, model, {
|
|
64
|
+
journeys: done.journeys.details.flatMap((d, i) => (project.journeyFiles?.[i] === undefined ? [] : [{ file: project.journeyFiles[i], passed: d.verdict === "pass" }])),
|
|
65
|
+
operations: [...new Set(done.judged.flatMap((v) => (v.operation === undefined ? [] : [v.operation])))].map((operation) => ({ operation, passed: done.judged.every((v) => v.operation !== operation || v.failures.length === 0) })),
|
|
66
|
+
}, stamp);
|
|
67
|
+
}
|
|
68
|
+
const verdict = closing(done);
|
|
69
|
+
const lines = [...said, ...stand.notes, ...unfinishedIn(loaded), ...done.journeys.lines, ...done.evals.lines, verdict.line];
|
|
70
|
+
const seconds = Math.round(Duration.toMillis(took)) / 1000;
|
|
71
|
+
return { lines, passed: verdict.passed, structured: proveReport(done.journeys.details, done.evals.failed, seconds, lines, verdict.passed, report), ...(say === undefined ? {} : { said: said.length }) };
|
|
72
|
+
}),
|
|
73
|
+
dev: ({ root, port, env, pid }) => Effect.gen(function* () {
|
|
74
|
+
const startedAt = yield* Clock.currentTimeMillis;
|
|
75
|
+
const sources = fingerprint(root);
|
|
76
|
+
const nonce = randomBytes(16).toString("hex");
|
|
77
|
+
const model = yield* Compiler.model.pipe(Effect.provide(nodeSource(root)), Effect.mapError((e) => failed(e._tag === "BlueprintInvalid" ? { message: `the blueprint is invalid:\n - ${e.problems.join("\n - ")}` } : e)));
|
|
78
|
+
const sinks = yield* Sinks.resolve({ sinks: model.environments?.["local"]?.telemetry ?? [{ sink: "local" }], env: env ?? {} });
|
|
79
|
+
// The collector and the world outlive each prove: a prove that finds them uses them (ST1.24).
|
|
80
|
+
const dir = resolve(root, Names.folder, "dev-telemetry");
|
|
81
|
+
const collector = yield* Collectors.local(dir, privateKeys(model)).pipe(Effect.mapError(failed));
|
|
82
|
+
const feed = yield* PortalFeed.serve({ source: collector, metrics: FileMetrics.open(dir), environment: "local", windowMs: PORTAL_WINDOW_MS, historyMs: PORTAL_HISTORY_MS }).pipe(Effect.mapError(failed));
|
|
83
|
+
const { url, log } = yield* Worlds.start({ root, port, name: "dev", otlp: collector.url, portalFeed: feed.url, environment: "local", secretEnv: sinks.secretEnv, nonce }).pipe(Effect.mapError(failed));
|
|
84
|
+
yield* Warm.publish(root, { pid, url, collector: collector.url, telemetry: dir, startedAt, sources, nonce }).pipe(Effect.mapError(failed));
|
|
85
|
+
return { url, log, notes: sinks.notes };
|
|
86
|
+
}),
|
|
87
|
+
test: (options) => load(options.root).pipe(Effect.flatMap(({ model, project }) => proveInTest(model, project, options))),
|
|
88
|
+
staged: ({ root, url, label, only, d1 }) => load(root).pipe(Effect.flatMap(({ model, project }) => provedAt(model, project, url, label, only ?? [], d1 === undefined ? undefined : Journeys.d1Facts(d1)))),
|
|
89
|
+
against: ({ root, url, telemetry, state, say }) => Effect.gen(function* () {
|
|
90
|
+
const { model, project } = yield* load(root);
|
|
91
|
+
const done = yield* exercise(model, project, url, Collectors.read(telemetry), "sign-up", undefined, state === undefined ? undefined : Journeys.databaseFacts(state));
|
|
92
|
+
for (const line of [...unfinishedIn(project), ...done.journeys.lines, ...done.evals.lines])
|
|
93
|
+
yield* say(line);
|
|
94
|
+
const verdict = closing(done);
|
|
95
|
+
yield* say(verdict.line);
|
|
96
|
+
return { passed: verdict.passed, results: done.results };
|
|
97
|
+
}),
|
|
98
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { type Effect, type Scope } from "effect";
|
|
2
|
+
import type { Result, TokenSource } from "#modules/verdicts/types.js";
|
|
3
|
+
import type { D1Access } from "#modules/journeys/types.js";
|
|
4
|
+
import type { ProveReport } from "./internal/structured.ts";
|
|
5
|
+
export type { ChangedDetail, FailureDetail, JourneyDetail, ProveReport, StepDetail } from "./internal/structured.ts";
|
|
6
|
+
declare const ProveFailed_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 & {
|
|
7
|
+
readonly _tag: "ProveFailed";
|
|
8
|
+
} & Readonly<A>;
|
|
9
|
+
export declare class ProveFailed extends ProveFailed_base<{
|
|
10
|
+
readonly message: string;
|
|
11
|
+
}> {
|
|
12
|
+
}
|
|
13
|
+
export interface Report {
|
|
14
|
+
/** What prove says, line by line: journeys, then each operation's evals, then coverage, then the verdict. */
|
|
15
|
+
readonly lines: ReadonlyArray<string>;
|
|
16
|
+
readonly passed: boolean;
|
|
17
|
+
/** The same run as data (`ortho prove --json`, `--report <file>`): per journey, per step, totals and timings. */
|
|
18
|
+
readonly structured: ProveReport;
|
|
19
|
+
/** How many leading `lines` were already said through `say` as they became true: a caller that printed them prints the rest. */
|
|
20
|
+
readonly said?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface ProveApi {
|
|
23
|
+
/**
|
|
24
|
+
* Prove the project at `root` on a local world served on `port` (0: any free port). Nothing is left running when the scope closes:
|
|
25
|
+
* wrangler is stopped and the collector is closed. A project that runs and fails its journeys or evals is a
|
|
26
|
+
* report with `passed: false`.
|
|
27
|
+
*/
|
|
28
|
+
readonly run: (options: {
|
|
29
|
+
readonly root: string;
|
|
30
|
+
readonly port: number;
|
|
31
|
+
/** Run journey calls on scaffolds and print results without recording proof verdicts. */
|
|
32
|
+
readonly empty?: boolean;
|
|
33
|
+
/** Run one journey by its declared name, without recording proof verdicts. */
|
|
34
|
+
readonly only?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Run only the journeys a change since the last proof's record touches (and judge the evals of what changed), naming each
|
|
37
|
+
* it skipped; run everything, saying why, when it cannot tell. The proof it leaves is recorded as a full run's is.
|
|
38
|
+
*/
|
|
39
|
+
readonly changed?: boolean;
|
|
40
|
+
/** Said as it is true, ahead of the report: `--changed` says what it will run before a world that cannot start can hide it. */
|
|
41
|
+
readonly say?: (line: string) => Effect.Effect<void>;
|
|
42
|
+
/** The process environment, for the sinks' tokens (`AXIOM_TOKEN`): only an entry file reads it. */
|
|
43
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
44
|
+
}) => Effect.Effect<Report, ProveFailed, Scope.Scope>;
|
|
45
|
+
/**
|
|
46
|
+
* `ortho dev`: a local world on `port` and a collector (writing `.ortho/dev-telemetry`) that stay up while the scope is open; the
|
|
47
|
+
* local environment's sinks get what they are named for. A `prove` that finds them uses them (`warm`, ST1.24).
|
|
48
|
+
*/
|
|
49
|
+
readonly dev: (options: {
|
|
50
|
+
readonly root: string;
|
|
51
|
+
readonly port: number;
|
|
52
|
+
/** This process's id, which `ortho prove` reads to tell a live `ortho dev` from a record one left behind. */
|
|
53
|
+
readonly pid: number;
|
|
54
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
55
|
+
}) => Effect.Effect<{
|
|
56
|
+
readonly url: string;
|
|
57
|
+
readonly log: string;
|
|
58
|
+
readonly notes: ReadonlyArray<string>;
|
|
59
|
+
}, ProveFailed, Scope.Scope>;
|
|
60
|
+
/**
|
|
61
|
+
* Prove the project in a world of the test environment, which it starts if it is down, on the revision it was asked
|
|
62
|
+
* to prove (the git commit). Each line is `say`d as it is true, so a run that dies part-way has said where it was:
|
|
63
|
+
* `world test-<id> · expires in <lifetime>` once the world exists, the journeys and evals, `verdicts <op> ✔ …
|
|
64
|
+
* (revision <rev>)` once the logbook holds them, and `world destroyed` last. The world is destroyed whether the run
|
|
65
|
+
* passes, fails or is interrupted; only a killed process leaves it, for its alarm and `worlds reap`.
|
|
66
|
+
* `lifetime` overrides the environment's own (`20s`, `2 hours`).
|
|
67
|
+
*/
|
|
68
|
+
readonly test: (options: {
|
|
69
|
+
readonly root: string;
|
|
70
|
+
readonly lifetime?: string;
|
|
71
|
+
/** The process environment, for the telemetry sinks' tokens (`AXIOM_TOKEN`): only an entry file reads it. */
|
|
72
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
73
|
+
readonly logbook: string;
|
|
74
|
+
readonly token: TokenSource;
|
|
75
|
+
readonly say: (line: string) => Effect.Effect<void>;
|
|
76
|
+
}) => Effect.Effect<{
|
|
77
|
+
readonly passed: boolean;
|
|
78
|
+
}, ProveFailed>;
|
|
79
|
+
/**
|
|
80
|
+
* Prove the journeys against a deployed Worker at `url` (`ortho prove --env staging --run <id>`, M7.04), in no world of its
|
|
81
|
+
* own. The Worker's `/_world` is closed, so each journey's people sign up through Better Auth's routes. There is no
|
|
82
|
+
* collector, so the journeys are judged and the nine evals are not (`totals.evalsFailed` is 0). `url` that nothing answers,
|
|
83
|
+
* or that answers 404 to everything (a Worker never deployed), is a `ProveFailed` naming it, before any journey runs.
|
|
84
|
+
*/
|
|
85
|
+
readonly staged: (options: {
|
|
86
|
+
readonly root: string;
|
|
87
|
+
readonly url: string;
|
|
88
|
+
/** What the address is called in a refusal, e.g. `run r4417`. */
|
|
89
|
+
readonly label: string;
|
|
90
|
+
/**
|
|
91
|
+
* The journeys to judge, by name (`--only`, any number of times): each once, in file order, every one run even after one fails, and
|
|
92
|
+
* `passed` is all of theirs. The first name that is no journey is a `ProveFailed` naming it, before the address is asked anything.
|
|
93
|
+
* Empty or absent, every journey (CX-staging).
|
|
94
|
+
*/
|
|
95
|
+
readonly only?: ReadonlyArray<string>;
|
|
96
|
+
/** The deployed environment's database, read through Cloudflare's API with the operator's credential. Without it the journeys' facts come from the Worker's own `/_world`, which only a local world has. */
|
|
97
|
+
readonly d1?: D1Access;
|
|
98
|
+
}) => Effect.Effect<Report, ProveFailed>;
|
|
99
|
+
/**
|
|
100
|
+
* Prove the project against an environment that is already running (staging), and post nothing. A real environment has
|
|
101
|
+
* no `/_world/cast`, so each journey's people sign up for real through Better Auth's own routes, with credentials of
|
|
102
|
+
* their own; the journeys and the nine evals are otherwise the same, judged from the environment's own collector
|
|
103
|
+
* (`telemetry`, the folder it writes). Each line is `say`d as it is true. Returns the verdict of each operation, which the
|
|
104
|
+
* caller records: a failing one too.
|
|
105
|
+
*/
|
|
106
|
+
readonly against: (options: {
|
|
107
|
+
readonly root: string;
|
|
108
|
+
readonly url: string;
|
|
109
|
+
readonly telemetry: string;
|
|
110
|
+
/**
|
|
111
|
+
* The environment's state folder (`.ortho/environments/<env>/state`). Its `/_world/*` is closed, so the rows and
|
|
112
|
+
* journal the evals read come from its database file instead (D3 #127). Without it, from the world's own front door.
|
|
113
|
+
*/
|
|
114
|
+
readonly state?: string;
|
|
115
|
+
readonly say: (line: string) => Effect.Effect<void>;
|
|
116
|
+
}) => Effect.Effect<{
|
|
117
|
+
readonly passed: boolean;
|
|
118
|
+
readonly results: ReadonlyArray<Result>;
|
|
119
|
+
}, ProveFailed>;
|
|
120
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// `ortho prove --env local`: a fresh local world and a real collector, every journey run, the nine evals judged.
|
|
2
|
+
// `ortho prove --env test`: the same, in a world of the long-lived test environment, with a signed verdict per operation.
|
|
3
|
+
import { Data } from "effect";
|
|
4
|
+
export class ProveFailed extends Data.TaggedError("ProveFailed") {
|
|
5
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { PublishFailed } from "../types.ts";
|
|
3
|
+
/** The package an import names: `effect/cli` is `effect`, `@effect/platform-node/Foo` is `@effect/platform-node`. */
|
|
4
|
+
export declare const packageOf: (specifier: string) => string;
|
|
5
|
+
/** The version of a package as the project has it installed, looking up from the project like node does; undefined when it is not there. */
|
|
6
|
+
export declare const installedVersion: (root: string, name: string) => string | undefined;
|
|
7
|
+
export interface Bundled {
|
|
8
|
+
/** The packages the bundle still imports (and so needs installed), sorted. */
|
|
9
|
+
readonly imports: ReadonlyArray<string>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The release version reaches the generated CLI as a constant the bundler replaces (`ORTHO_VERSION`), not as text in the
|
|
13
|
+
* generated source: generated files are the same on every machine and every release, and a CLI run from source says 0.0.0.
|
|
14
|
+
*/
|
|
15
|
+
export declare const bundle: (options: {
|
|
16
|
+
readonly root: string;
|
|
17
|
+
readonly entry: string;
|
|
18
|
+
readonly outfile: string;
|
|
19
|
+
readonly format: "esm" | "cjs";
|
|
20
|
+
readonly platform: "node" | "neutral";
|
|
21
|
+
readonly version: string;
|
|
22
|
+
/** With `inline`, nothing stays outside: a single executable has no node_modules to find a package in. */
|
|
23
|
+
readonly inline?: boolean;
|
|
24
|
+
}) => Effect.Effect<Bundled, PublishFailed>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// A generated entry file (the SDK's index, the CLI's main) bundled into one file, with the project's own sources inside it and every
|
|
2
|
+
// package it imports left outside, as a dependency. Shared by the npm packages (ESM) and the single executable (CommonJS).
|
|
3
|
+
import { Names } from "orthograph/server";
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { isBuiltin } from "node:module";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
import { Effect } from "effect";
|
|
8
|
+
import { build } from "esbuild";
|
|
9
|
+
import { PublishFailed } from "../types.js";
|
|
10
|
+
/** The package an import names: `effect/cli` is `effect`, `@effect/platform-node/Foo` is `@effect/platform-node`. */
|
|
11
|
+
export const packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
12
|
+
/** The version of a package as the project has it installed, looking up from the project like node does; undefined when it is not there. */
|
|
13
|
+
export const installedVersion = (root, name) => {
|
|
14
|
+
for (let at = resolve(root);; at = dirname(at)) {
|
|
15
|
+
const file = join(at, "node_modules", name, "package.json");
|
|
16
|
+
if (existsSync(file))
|
|
17
|
+
return JSON.parse(readFileSync(file, "utf8")).version;
|
|
18
|
+
if (dirname(at) === at)
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The release version reaches the generated CLI as a constant the bundler replaces (`ORTHO_VERSION`), not as text in the
|
|
24
|
+
* generated source: generated files are the same on every machine and every release, and a CLI run from source says 0.0.0.
|
|
25
|
+
*/
|
|
26
|
+
export const bundle = (options) => Effect.tryPromise({
|
|
27
|
+
try: () => build({
|
|
28
|
+
absWorkingDir: resolve(options.root),
|
|
29
|
+
entryPoints: [options.entry],
|
|
30
|
+
outfile: options.outfile,
|
|
31
|
+
bundle: true,
|
|
32
|
+
format: options.format,
|
|
33
|
+
platform: options.platform,
|
|
34
|
+
target: "node24",
|
|
35
|
+
...(options.inline ? { mainFields: ["module", "main"] } : { packages: "external", mainFields: ["module", "main"] }),
|
|
36
|
+
define: { [Names.variable("VERSION")]: JSON.stringify(options.version) },
|
|
37
|
+
legalComments: "none",
|
|
38
|
+
metafile: true,
|
|
39
|
+
logLevel: "silent",
|
|
40
|
+
}).then((result) => {
|
|
41
|
+
const output = Object.values(result.metafile.outputs)[0];
|
|
42
|
+
const external = (output?.imports ?? []).filter((i) => i.external && !isBuiltin(i.path)).map((i) => packageOf(i.path));
|
|
43
|
+
return { imports: [...new Set(external)].sort() };
|
|
44
|
+
}),
|
|
45
|
+
catch: (e) => new PublishFailed({ message: `couldn't bundle ${options.entry}: ${String(e.message ?? e)}` }),
|
|
46
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { EnvironmentModel } from "@orthograph/compiler";
|
|
2
|
+
export type Kind = "sdk" | "cli";
|
|
3
|
+
export interface NpmPackage {
|
|
4
|
+
readonly kind: Kind;
|
|
5
|
+
/** `@acme/sdk`, `@acme/cli`. */
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly tag: string;
|
|
8
|
+
}
|
|
9
|
+
export interface Plan {
|
|
10
|
+
readonly project: string;
|
|
11
|
+
readonly version: string;
|
|
12
|
+
readonly npm: ReadonlyArray<NpmPackage>;
|
|
13
|
+
/** The tap the blueprint names (`acme/tap`), when the CLI is published through Homebrew. */
|
|
14
|
+
readonly homebrew: string | undefined;
|
|
15
|
+
/** The CLI's binaries go to GitHub releases, which only the cloud pass can reach. */
|
|
16
|
+
readonly githubReleases: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** `1.1.0-next.2` is a prerelease: a version with a hyphen. */
|
|
19
|
+
export declare const isPrerelease: (version: string) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The dist-tag a package goes out under. A release takes the blueprint's tag, else `latest`. A prerelease never takes `latest`:
|
|
22
|
+
* npm would otherwise make it what `npm install` gives people (pnpm does so silently), so it goes under `next` whatever the
|
|
23
|
+
* blueprint says (D3 #9).
|
|
24
|
+
*/
|
|
25
|
+
export declare const tagFor: (declared: string | null | undefined, version: string) => string;
|
|
26
|
+
/** The project's name is its folder's, the way the generators name it (`generated/cli` is `acme` because the folder is). */
|
|
27
|
+
export declare const projectName: (root: string) => string;
|
|
28
|
+
export declare const planOf: (root: string, environment: EnvironmentModel, version: string) => Plan;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// What an environment's `publish` list comes to at a version: pure, so the rules (the project's names, the dist-tag) are plain to test.
|
|
2
|
+
import { basename, resolve } from "node:path";
|
|
3
|
+
/** `1.1.0-next.2` is a prerelease: a version with a hyphen. */
|
|
4
|
+
export const isPrerelease = (version) => version.includes("-");
|
|
5
|
+
/**
|
|
6
|
+
* The dist-tag a package goes out under. A release takes the blueprint's tag, else `latest`. A prerelease never takes `latest`:
|
|
7
|
+
* npm would otherwise make it what `npm install` gives people (pnpm does so silently), so it goes under `next` whatever the
|
|
8
|
+
* blueprint says (D3 #9).
|
|
9
|
+
*/
|
|
10
|
+
export const tagFor = (declared, version) => {
|
|
11
|
+
if (!isPrerelease(version))
|
|
12
|
+
return declared ?? "latest";
|
|
13
|
+
return declared === undefined || declared === null || declared === "latest" ? "next" : declared;
|
|
14
|
+
};
|
|
15
|
+
/** The project's name is its folder's, the way the generators name it (`generated/cli` is `acme` because the folder is). */
|
|
16
|
+
export const projectName = (root) => basename(resolve(root));
|
|
17
|
+
const withHow = (list, how) => (list ?? []).filter((p) => p.how === how);
|
|
18
|
+
export const planOf = (root, environment, version) => {
|
|
19
|
+
const project = projectName(root);
|
|
20
|
+
const npm = ["sdk", "cli"].flatMap((kind) => withHow(environment.publish[kind], "npm").map((p) => ({ kind, name: `@${project}/${kind}`, tag: tagFor(p.tag, version) })));
|
|
21
|
+
return {
|
|
22
|
+
project,
|
|
23
|
+
version,
|
|
24
|
+
npm,
|
|
25
|
+
homebrew: withHow(environment.publish["cli"], "homebrew")[0]?.tap,
|
|
26
|
+
githubReleases: withHow(environment.publish["cli"], "binaries").length > 0,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { PublishFailed, type Env } from "../types.ts";
|
|
3
|
+
/** The registry from `ORTHO_REGISTRY`, with its trailing slash; undefined when none is set. */
|
|
4
|
+
export declare const registryOf: (env: Env) => string | undefined;
|
|
5
|
+
/** The real npm is the cloud pass's: this machine's pass only ever publishes to a registry of its own. */
|
|
6
|
+
export declare const isNpmjs: (registry: string) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The versions a package has on the registry (none when it has never been published), and its dist-tags. A kept-alive connection
|
|
9
|
+
* the registry closed while a long build ran fails once, so a second try is made before the registry is said not to answer.
|
|
10
|
+
*/
|
|
11
|
+
export declare const versionsOf: (registry: string, name: string) => Effect.Effect<{
|
|
12
|
+
readonly versions: ReadonlyArray<string>;
|
|
13
|
+
readonly tags: Readonly<Record<string, string>>;
|
|
14
|
+
readonly integrities: Readonly<Record<string, string>>;
|
|
15
|
+
}, PublishFailed>;
|
|
16
|
+
/** `<version>-next.<n>`, one past the highest `n` any of the packages already has. */
|
|
17
|
+
export declare const nextPrerelease: (registry: string, names: ReadonlyArray<string>, version: string) => Effect.Effect<string, PublishFailed, never>;
|
|
18
|
+
/** `npm publish` of a built package under a dist-tag, to the registry given: the token is in the npmrc `NPM_CONFIG_USERCONFIG` names, never on the command line. */
|
|
19
|
+
export declare const publishPackage: (options: {
|
|
20
|
+
readonly dir: string;
|
|
21
|
+
readonly registry: string;
|
|
22
|
+
readonly tag: string;
|
|
23
|
+
readonly env: Env;
|
|
24
|
+
}) => Effect.Effect<void, PublishFailed>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// The npm registry on this machine (Verdaccio): what versions a package has, the next free prerelease, and `npm publish` to it.
|
|
2
|
+
import { Names } from "orthograph/server";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { Effect } from "effect";
|
|
5
|
+
import { PublishFailed } from "../types.js";
|
|
6
|
+
import { cleanEnv } from "./env.js";
|
|
7
|
+
/** The registry from `ORTHO_REGISTRY`, with its trailing slash; undefined when none is set. */
|
|
8
|
+
export const registryOf = (env) => {
|
|
9
|
+
const given = env[Names.variable("REGISTRY")]?.trim();
|
|
10
|
+
return given ? given.replace(/\/*$/, "/") : undefined;
|
|
11
|
+
};
|
|
12
|
+
/** The real npm is the cloud pass's: this machine's pass only ever publishes to a registry of its own. */
|
|
13
|
+
export const isNpmjs = (registry) => new URL(registry).hostname.endsWith("npmjs.org");
|
|
14
|
+
const packument = (registry, name) => fetch(`${registry}${name.replace("/", "%2f")}`, { headers: { accept: "application/json" } }).then((r) => r.status === 404
|
|
15
|
+
? { versions: [], tags: {}, integrities: {} }
|
|
16
|
+
: r.json().then((body) => {
|
|
17
|
+
const found = body;
|
|
18
|
+
const integrities = Object.fromEntries(Object.entries(found.versions ?? {}).flatMap(([version, pkg]) => {
|
|
19
|
+
const dist = typeof pkg === "object" && pkg !== null && "dist" in pkg ? pkg.dist : undefined;
|
|
20
|
+
return typeof dist === "object" && dist !== null && "integrity" in dist && typeof dist.integrity === "string" ? [[version, dist.integrity]] : [];
|
|
21
|
+
}));
|
|
22
|
+
return { versions: Object.keys(found.versions ?? {}), tags: found["dist-tags"] ?? {}, integrities };
|
|
23
|
+
}));
|
|
24
|
+
/**
|
|
25
|
+
* The versions a package has on the registry (none when it has never been published), and its dist-tags. A kept-alive connection
|
|
26
|
+
* the registry closed while a long build ran fails once, so a second try is made before the registry is said not to answer.
|
|
27
|
+
*/
|
|
28
|
+
export const versionsOf = (registry, name) => Effect.tryPromise({
|
|
29
|
+
try: () => packument(registry, name).catch(() => packument(registry, name)),
|
|
30
|
+
catch: () => new PublishFailed({ message: `the registry at ${registry} didn't answer: is it running?` }),
|
|
31
|
+
});
|
|
32
|
+
/** `<version>-next.<n>`, one past the highest `n` any of the packages already has. */
|
|
33
|
+
export const nextPrerelease = (registry, names, version) => Effect.gen(function* () {
|
|
34
|
+
const prefix = `${version}-next.`;
|
|
35
|
+
let highest = 0;
|
|
36
|
+
for (const name of names) {
|
|
37
|
+
for (const have of (yield* versionsOf(registry, name)).versions) {
|
|
38
|
+
const n = have.startsWith(prefix) ? Number(have.slice(prefix.length)) : NaN;
|
|
39
|
+
if (Number.isInteger(n) && n > highest)
|
|
40
|
+
highest = n;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return `${prefix}${highest + 1}`;
|
|
44
|
+
});
|
|
45
|
+
/** `npm publish` of a built package under a dist-tag, to the registry given: the token is in the npmrc `NPM_CONFIG_USERCONFIG` names, never on the command line. */
|
|
46
|
+
export const publishPackage = (options) => Effect.try({
|
|
47
|
+
try: () => {
|
|
48
|
+
const run = spawnSync("npm", ["publish", "--registry", options.registry, "--tag", options.tag, "--access", "public", "--ignore-scripts"], {
|
|
49
|
+
cwd: options.dir, encoding: "utf8", env: cleanEnv(options.env), maxBuffer: 16 * 1024 * 1024,
|
|
50
|
+
});
|
|
51
|
+
if (run.status !== 0)
|
|
52
|
+
throw new Error(`npm publish to ${options.registry} failed:\n${(run.stderr || run.stdout).trim().split("\n").slice(0, 8).join("\n")}`);
|
|
53
|
+
},
|
|
54
|
+
catch: (e) => new PublishFailed({ message: String(e.message ?? e) }),
|
|
55
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { PublishFailed, type Binary } from "../types.ts";
|
|
3
|
+
export declare const NODE_VERSION = "24.22.2";
|
|
4
|
+
export type Target = "darwin-arm64" | "linux-x64";
|
|
5
|
+
/** The platform this machine is, when a single executable can be built for it here. */
|
|
6
|
+
export declare const hostTarget: () => Target | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Node's official binary for a platform, from nodejs.org, checked against the release's `SHASUMS256.txt` and kept in the cache:
|
|
9
|
+
* downloaded once for every project and every run after.
|
|
10
|
+
*/
|
|
11
|
+
export declare const nodeBinary: (cache: string, target: Target) => Effect.Effect<string, PublishFailed>;
|
|
12
|
+
/** Build `<project>-<version>-<target>.tar.gz` in `out`: the executable named `<project>`, and the tarball's sha256. */
|
|
13
|
+
export declare const buildBinary: (options: {
|
|
14
|
+
readonly root: string;
|
|
15
|
+
readonly project: string;
|
|
16
|
+
readonly version: string;
|
|
17
|
+
readonly out: string;
|
|
18
|
+
readonly cache: string;
|
|
19
|
+
readonly target: Target;
|
|
20
|
+
}) => Effect.Effect<Binary, PublishFailed>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The generated CLI as a Node single executable (D3 #9; spikes/single-binary): the official Node binary for a platform, with the CLI's
|
|
2
|
+
// bundle injected as a blob by postject. Built here for the platform this machine is; Node's own cross-build works too, and CI builds the
|
|
3
|
+
// other one on its own runner.
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { Effect } from "effect";
|
|
10
|
+
import { PublishFailed } from "../types.js";
|
|
11
|
+
import { bundle } from "./bundle.js";
|
|
12
|
+
export const NODE_VERSION = "24.22.2";
|
|
13
|
+
/** The fuse sentinel Node's single-executable support looks for, the same in every Node release. */
|
|
14
|
+
const SENTINEL = "NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2";
|
|
15
|
+
/** The platform this machine is, when a single executable can be built for it here. */
|
|
16
|
+
export const hostTarget = () => process.platform === "darwin" && process.arch === "arm64" ? "darwin-arm64" : process.platform === "linux" && process.arch === "x64" ? "linux-x64" : undefined;
|
|
17
|
+
const run = (what, command, args, cwd) => Effect.try({
|
|
18
|
+
try: () => {
|
|
19
|
+
const r = spawnSync(command, [...args], { encoding: "utf8", ...(cwd === undefined ? {} : { cwd }), maxBuffer: 64 * 1024 * 1024 });
|
|
20
|
+
if (r.status !== 0)
|
|
21
|
+
throw new Error(`${what} failed (${command} exited ${r.status}): ${(r.stderr || r.stdout).trim().split("\n").slice(-4).join(" | ")}`);
|
|
22
|
+
return r.stdout;
|
|
23
|
+
},
|
|
24
|
+
catch: (e) => new PublishFailed({ message: String(e.message ?? e) }),
|
|
25
|
+
});
|
|
26
|
+
const sha256 = (file) => createHash("sha256").update(readFileSync(file)).digest("hex");
|
|
27
|
+
/**
|
|
28
|
+
* Node's official binary for a platform, from nodejs.org, checked against the release's `SHASUMS256.txt` and kept in the cache:
|
|
29
|
+
* downloaded once for every project and every run after.
|
|
30
|
+
*/
|
|
31
|
+
export const nodeBinary = (cache, target) => Effect.gen(function* () {
|
|
32
|
+
const kept = join(cache, `node-v${NODE_VERSION}-${target}`, "node");
|
|
33
|
+
if (existsSync(kept))
|
|
34
|
+
return kept;
|
|
35
|
+
const base = `https://nodejs.org/dist/v${NODE_VERSION}`;
|
|
36
|
+
const archive = `node-v${NODE_VERSION}-${target}.tar.gz`;
|
|
37
|
+
const work = join(cache, `download-${process.pid}`);
|
|
38
|
+
yield* Effect.try({ try: () => { rmSync(work, { recursive: true, force: true }); mkdirSync(work, { recursive: true }); }, catch: (e) => new PublishFailed({ message: String(e) }) });
|
|
39
|
+
yield* run("the download of Node's checksums", "curl", ["-fsS", "--max-time", "600", "-o", join(work, "SHASUMS256.txt"), `${base}/SHASUMS256.txt`]);
|
|
40
|
+
yield* run(`the download of ${archive}`, "curl", ["-fsS", "--max-time", "900", "-o", join(work, archive), `${base}/${archive}`]);
|
|
41
|
+
const expected = readFileSync(join(work, "SHASUMS256.txt"), "utf8").split("\n").find((l) => l.endsWith(` ${archive}`))?.split(/\s+/)[0];
|
|
42
|
+
if (expected === undefined || sha256(join(work, archive)) !== expected) {
|
|
43
|
+
rmSync(work, { recursive: true, force: true });
|
|
44
|
+
return yield* new PublishFailed({ message: `${archive} does not match nodejs.org's SHASUMS256.txt; nothing was installed` });
|
|
45
|
+
}
|
|
46
|
+
yield* run(`unpacking ${archive}`, "tar", ["-xzf", archive, "--strip-components=2", `node-v${NODE_VERSION}-${target}/bin/node`], work);
|
|
47
|
+
yield* Effect.try({
|
|
48
|
+
try: () => { mkdirSync(dirname(kept), { recursive: true }); renameSync(join(work, "node"), kept); rmSync(work, { recursive: true, force: true }); },
|
|
49
|
+
catch: (e) => new PublishFailed({ message: String(e) }),
|
|
50
|
+
});
|
|
51
|
+
return kept;
|
|
52
|
+
});
|
|
53
|
+
/** Build `<project>-<version>-<target>.tar.gz` in `out`: the executable named `<project>`, and the tarball's sha256. */
|
|
54
|
+
export const buildBinary = (options) => Effect.gen(function* () {
|
|
55
|
+
const { root, project, version, out, target } = options;
|
|
56
|
+
const node = yield* nodeBinary(options.cache, target);
|
|
57
|
+
const work = join(out, `sea-${target}`);
|
|
58
|
+
yield* Effect.try({ try: () => { rmSync(work, { recursive: true, force: true }); mkdirSync(work, { recursive: true }); }, catch: (e) => new PublishFailed({ message: String(e) }) });
|
|
59
|
+
// CommonJS, with every package inside: the single executable has no node_modules to look in.
|
|
60
|
+
yield* bundle({ root, entry: "generated/cli/src/main.ts", outfile: join(work, "bundle.cjs"), format: "cjs", platform: "node", version, inline: true });
|
|
61
|
+
// The blob without a code cache, which is platform-specific, so one blob serves every target.
|
|
62
|
+
writeFileSync(join(work, "sea-config.json"), JSON.stringify({ main: join(work, "bundle.cjs"), output: join(work, "sea.blob"), disableExperimentalSEAWarning: true, useCodeCache: false }));
|
|
63
|
+
yield* run("the single-executable blob", node, ["--experimental-sea-config", join(work, "sea-config.json")]);
|
|
64
|
+
const binary = join(work, project);
|
|
65
|
+
const postject = join(dirname(createRequire(import.meta.url).resolve("postject/package.json")), "dist/cli.js");
|
|
66
|
+
yield* Effect.try({ try: () => { copyFileSync(node, binary); chmodSync(binary, 0o755); }, catch: (e) => new PublishFailed({ message: String(e) }) });
|
|
67
|
+
// On macOS the copied Node's signature goes before the blob and an ad hoc one is made after (a downloaded binary also wants Apple's: the cloud pass's).
|
|
68
|
+
if (target === "darwin-arm64")
|
|
69
|
+
yield* run("removing Node's signature", "codesign", ["--remove-signature", binary]);
|
|
70
|
+
yield* run("injecting the CLI into Node", process.execPath, [postject, binary, "NODE_SEA_BLOB", join(work, "sea.blob"), "--sentinel-fuse", SENTINEL, ...(target === "darwin-arm64" ? ["--macho-segment-name", "NODE_SEA"] : [])]);
|
|
71
|
+
if (target === "darwin-arm64")
|
|
72
|
+
yield* run("signing the executable", "codesign", ["--sign", "-", binary]);
|
|
73
|
+
const tarball = join(out, `${project}-${version}-${target}.tar.gz`);
|
|
74
|
+
yield* run("tarring the executable", "tar", ["-czf", tarball, "-C", work, project]);
|
|
75
|
+
yield* Effect.try({ try: () => rmSync(work, { recursive: true, force: true }), catch: (e) => new PublishFailed({ message: String(e) }) });
|
|
76
|
+
return { target, tarball, sha256: sha256(tarball), bytes: statSync(tarball).size };
|
|
77
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { PublishFailed } from "../types.ts";
|
|
3
|
+
/** Only the source tree is temporary. All packages, binaries and formula URLs are owned by the original root. */
|
|
4
|
+
export declare const withSource: <A, E, R>(root: string, revision: string | undefined, use: (source: string) => Effect.Effect<A, E, R>) => Effect.Effect<A, E | PublishFailed, R>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
import { PublishFailed } from "../types.js";
|
|
7
|
+
const io = (work) => Effect.try({ try: work, catch: (e) => new PublishFailed({ message: String(e) }) });
|
|
8
|
+
const git = (root, ...args) => Effect.gen(function* () {
|
|
9
|
+
const result = yield* io(() => spawnSync("git", [...args], { cwd: root, encoding: "utf8" }));
|
|
10
|
+
if (result.status !== 0)
|
|
11
|
+
return yield* new PublishFailed({ message: `cannot capture publication source: ${result.stderr || result.error?.message || result.status}` });
|
|
12
|
+
return result.stdout.trim();
|
|
13
|
+
});
|
|
14
|
+
/** Archive the whole committed tree so nested projects retain ancestor configs; dependencies remain installed tooling. */
|
|
15
|
+
const capture = (root, revision, scratch) => Effect.gen(function* () {
|
|
16
|
+
if (!/^[0-9a-f]{40}$/.test(revision))
|
|
17
|
+
return yield* new PublishFailed({ message: "publication sourceRevision must be a full Git commit" });
|
|
18
|
+
const project = yield* io(() => realpathSync(resolve(root)));
|
|
19
|
+
const top = yield* git(project, "rev-parse", "--show-toplevel");
|
|
20
|
+
const repo = yield* io(() => realpathSync(top));
|
|
21
|
+
const commit = yield* git(repo, "rev-parse", "--verify", "--end-of-options", `${revision}^{commit}`);
|
|
22
|
+
const tree = join(scratch, basename(repo));
|
|
23
|
+
yield* io(() => mkdirSync(tree));
|
|
24
|
+
const archive = yield* io(() => spawnSync("git", ["archive", "--format=tar", commit], { cwd: repo, maxBuffer: 256 * 1024 * 1024 }));
|
|
25
|
+
if (archive.status !== 0)
|
|
26
|
+
return yield* new PublishFailed({ message: "git could not archive the captured publication revision" });
|
|
27
|
+
const unpacked = yield* io(() => spawnSync("tar", ["-xf", "-", "-C", tree], { input: archive.stdout, encoding: "utf8" }));
|
|
28
|
+
if (unpacked.status !== 0)
|
|
29
|
+
return yield* new PublishFailed({ message: `cannot unpack captured publication source: ${unpacked.stderr}` });
|
|
30
|
+
for (let original = project;; original = dirname(original)) {
|
|
31
|
+
const installed = join(original, "node_modules");
|
|
32
|
+
const target = join(tree, relative(repo, original), "node_modules");
|
|
33
|
+
if (existsSync(installed) && !existsSync(target))
|
|
34
|
+
yield* io(() => symlinkSync(installed, target, "dir"));
|
|
35
|
+
if (original === repo)
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
return join(tree, relative(repo, project));
|
|
39
|
+
});
|
|
40
|
+
/** Only the source tree is temporary. All packages, binaries and formula URLs are owned by the original root. */
|
|
41
|
+
export const withSource = (root, revision, use) => revision === undefined ? use(root) : Effect.acquireUseRelease(io(() => mkdtempSync(join(realpathSync(tmpdir()), "ortho-publish-source-"))), (scratch) => capture(root, revision, scratch).pipe(Effect.flatMap(use)), (scratch) => io(() => rmSync(scratch, { recursive: true, force: true })).pipe(Effect.ignore));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { PublishFailed, type Env, type Staged } from "../types.ts";
|
|
3
|
+
import type { Kind } from "./plan.ts";
|
|
4
|
+
/** `node_modules/.bin/<name>` in the project or the nearest folder above it that has one. */
|
|
5
|
+
export declare const binOf: (root: string, name: string) => string | undefined;
|
|
6
|
+
/** Build `@<project>/<kind>` at `version` into `<out>/<kind>/`, ready for `npm publish`. */
|
|
7
|
+
export declare const stage: (options: {
|
|
8
|
+
readonly root: string;
|
|
9
|
+
readonly env: Env;
|
|
10
|
+
readonly project: string;
|
|
11
|
+
readonly kind: Kind;
|
|
12
|
+
readonly version: string;
|
|
13
|
+
readonly out: string;
|
|
14
|
+
}) => Effect.Effect<Staged, PublishFailed>;
|