Skip to content
Myr

smoke.ts

This file

Path

scripts/smoke.ts

195 lines · 5.4 KiB · TypeScript

Last changed by

Merge infra/drop-demo into mainoscabrielbefore adoptionc49b6bf

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

line 1why, one step back
1/**

Merge build/comments-ops into mainoscabrielbefore adoptione4c407e

lines 2–3why, one step back
2 * Usage:
3 * bun scripts/smoke.ts --stage <stage> [--url <origin>] [--web-url <origin>]

Merge observability into mainoscabrielbefore adoption1985111

line 4why, one step back
4 * [--since <instant>]

Merge build/comments-ops into mainoscabrielbefore adoptione4c407e

line 5why, one step back
5 * bun scripts/smoke.ts --stage <stage> --loop [--draft] [--as <handle>]

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

line 6why, one step back
6 *

Merge observability into mainoscabrielbefore adoption1985111

lines 7–11why, one step back
7 * `--since` then reads the stage's Workers Logs since that instant, and fails
8 * on any exception or error-level line: it needs infra's credentials, so the9 * deploy runs it through `varlock run --path infra/`. `--loop` reads10 * `OPERATOR_TOKEN` and `SESSION_TOKENS` (token to handle) from the env, never11 * from an argument.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 12–13why, one step back
12 */
13import { BunRuntime, BunServices } from "@effect/platform-bun";

Add the live-run tooling: smoke --loop, seed --as, a recording lock for deploys, and a Playwright check of the deployed weboscabrielbefore adoption030c4d6

lines 14–24why, one step back
14import { Handle, sameHandle } from "@repo/protocol/ids";
15import {16 Config,17 Console,18 DateTime,19 Effect,20 Option,21 Redacted,22 Schema,23 Stdio,24} from "effect";

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

line 25why, one step back
25

Add the live-run tooling: smoke --loop, seed --as, a recording lock for deploys, and a Playwright check of the deployed weboscabrielbefore adoption030c4d6

lines 26–29why, one step back
26import { main as probeMain } from "../infra/smoke.ts";
27import {28 flagValue,29 platformOrigin,

Add a prod stage served on the brand's own domainoscabrielbefore adoption78a5062

line 30why, one step back
30 publicStages,

Add the live-run tooling: smoke --loop, seed --as, a recording lock for deploys, and a Playwright check of the deployed weboscabrielbefore adoption030c4d6

lines 31–34why, one step back
31 recordedSubdomain,
32 stageOf,33 subdomainFile,34} from "../infra/stages.ts";

Merge infra/drop-demo into mainoscabrielbefore adoptionc49b6bf

line 35why, one step back
35import { PublicStageRefused, LoopFailed, smokeLoop } from "./lib/smoke/loop.ts";

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

line 36why, one step back
36

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 37–45why, one step back
37export class DraftNeedsLoop extends Schema.TaggedError<DraftNeedsLoop>()(
38 "DraftNeedsLoop",39 { flag: Schema.Literal("--draft") }40) {41 override get message() {42 return `${this.flag} drafts an ask on the loop's throwaway project: run it with --loop`;43 }44}45

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

line 46why, one step back
46export {

Merge observability into mainoscabrielbefore adoption1985111

lines 47–49why, one step back
47 BadSince,
48 logProbes,49 NoLogCredentials,

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 50–57why, one step back
50 NoOrigin,
51 platformProbes,52 probes,53 smoke,54 SmokeFailed,55 webProbes,56} from "../infra/smoke.ts";57

Merge observability into mainoscabrielbefore adoption1985111

line 58why, one step back
58export type { LogsCheck, SmokeReport } from "../infra/smoke.ts";

Add the live-run tooling: smoke --loop, seed --as, a recording lock for deploys, and a Playwright check of the deployed weboscabrielbefore adoption030c4d6

line 59why, one step back
59

Merge infra/drop-demo into mainoscabrielbefore adoptionc49b6bf

line 60why, one step back
60export { PublicStageRefused, LoopFailed, smokeLoop } from "./lib/smoke/loop.ts";

Add the live-run tooling: smoke --loop, seed --as, a recording lock for deploys, and a Playwright check of the deployed weboscabrielbefore adoption030c4d6

lines 61–136why, one step back
61
62export type { SmokeLoopReport } from "./lib/smoke/loop.ts";6364const ANSWERER = "bram";6566const failed = (reason: string) => new LoopFailed({ reason, step: "people" });6768const runName = Effect.map(DateTime.now, (now) =>69 DateTime.formatIso(now)70 .slice(0, 19)71 .replaceAll(/[-:]/gu, "")72 .replace("T", "-")73);7475const decodeSessions = Schema.decodeUnknownEffect(76 Schema.fromJsonString(Schema.Record(Schema.String, Handle))77);7879const tokensFrom = (answerer: string) =>80 Effect.gen(function* () {81 const decider = yield* Config.Redacted("OPERATOR_TOKEN").pipe(82 Effect.mapError(() =>83 failed(84 "no OPERATOR_TOKEN in the environment: run with the stage's secrets in the env"85 )86 )87 );8889 const sessions = yield* Config.String("SESSION_TOKENS").pipe(90 Effect.mapError(() =>91 failed(92 "no SESSION_TOKENS in the environment: run with the stage's secrets in the env"93 )94 ),95 Effect.flatMap((raw) =>96 decodeSessions(raw).pipe(97 Effect.mapError(() =>98 failed("SESSION_TOKENS is not a JSON object from token to handle")99 )100 )101 )102 );103104 const token = Object.entries(sessions).find(([, handle]) =>105 sameHandle(handle, Handle.make(answerer))106 )?.[0];107108 return token === undefined109 ? yield* failed(110 `SESSION_TOKENS has no session for ${answerer}: name another with --as`111 )112 : { answerer: Redacted.make(token), decider };113 });114115const originOf = (116 argv: readonly string[],117 stage: Parameters<typeof platformOrigin>[0]118) =>119 Option.match(flagValue(argv, "--url"), {120 onNone: () =>121 recordedSubdomain.pipe(122 Effect.flatMap(Effect.fromOption),123 Effect.mapError(() =>124 failed(125 `no --url, and ${subdomainFile} doesn't record the account's workers.dev subdomain: run bun run bootstrap -- --stage ${stage} first`126 )127 ),128 Effect.map((subdomain) => platformOrigin(stage, subdomain))129 ),130 onSome: (url) => Effect.succeed(url.replace(/\/+$/u, "")),131 });132133const loopMain = (argv: readonly string[]) =>134 Effect.gen(function* () {135 const stage = yield* stageOf(argv);136

Add a prod stage served on the brand's own domainoscabrielbefore adoption78a5062

line 137why, one step back
137 yield* publicStages.has(stage)

Merge infra/drop-demo into mainoscabrielbefore adoptionc49b6bf

line 138why, one step back
138 ? Effect.fail(new PublicStageRefused({ stage }))

Add the live-run tooling: smoke --loop, seed --as, a recording lock for deploys, and a Playwright check of the deployed weboscabrielbefore adoption030c4d6

lines 139–150why, one step back
139 : Effect.void;
140141 const answerer = Option.getOrElse(flagValue(argv, "--as"), () => ANSWERER);142 const tokens = yield* tokensFrom(answerer);143 const origin = yield* originOf(argv, stage);144145 yield* probeMain(argv.filter((arg) => arg !== "--loop"));146147 const run = yield* runName;148149 yield* Console.log(`smoke ${stage}: loop smoke-${run} at ${origin}`);150

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 151–158why, one step back
151 const report = yield* smokeLoop({
152 ...tokens,153 draft: argv.includes("--draft"),154 origin,155 run,156 stage,157 });158

Add the live-run tooling: smoke --loop, seed --as, a recording lock for deploys, and a Playwright check of the deployed weboscabrielbefore adoption030c4d6

lines 159–163why, one step back
159 const total = report.timings.reduce((sum, { ms }) => sum + ms, 0);
160161 yield* Console.log(162 `smoke ${stage}: loop passed in ${total} ms: ${report.project} landed ${report.landed.slice(0, 12)} by ${report.author}, refused first with ${report.refusedWith.join(", ")}; trailers ${report.trailers.join("; ")}`163 );

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 164–171why, one step back
164
165 if (report.draft !== undefined) {166 const { attempts, model, ms, trailers } = report.draft;167168 yield* Console.log(169 `smoke ${stage}: draft by ${model} went red first in ${attempts} of 3 attempts, ${ms} ms from proposal to draft; its ask opened with ${trailers.join("; ")}`170 );171 }

Add the live-run tooling: smoke --loop, seed --as, a recording lock for deploys, and a Playwright check of the deployed weboscabrielbefore adoption030c4d6

lines 172–174why, one step back
172 });
173174export const main = (argv: readonly string[]) =>

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 175–185why, one step back
175 Effect.gen(function* () {
176 if (argv.includes("--loop")) {177 return yield* loopMain(argv);178 }179180 if (argv.includes("--draft")) {181 return yield* new DraftNeedsLoop({ flag: "--draft" });182 }183184 return yield* probeMain(argv);185 });

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 186–195why, one step back
186
187if (import.meta.main) {188 BunRuntime.runMain(189 Effect.gen(function* () {190 const args = yield* (yield* Stdio.Stdio).args;191192 return yield* main(args);193 }).pipe(Effect.provide(BunServices.layer))194 );195}