Public: anyone can read this; the crew can change it.
One notification for every release, sent by the forge #13726
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13708-one-notification-for-every-release-sent → main 4 commits fork 2 threads · 2 unresolved
10 files
changed +327
−12
docs/features/README.md +1
| @@ -179,6 +179,7 @@ Read with the guide page [Tell the crew](../guide-tell-the-crew.md). | ||
| 179 | 179 | |
| 180 | 180 | Read with the guide page [](../guide-ship-and-undo.md). |
| 181 | 181 | |
| 182 | - [](release-notice.md) | |
| 182 | 183 | - [](merge-crash-recovery.md) |
| 183 | 184 | - [](done-on-main.md) |
| 184 | 185 | - [](preview-owner-looks.md) |
docs/features/release-notice.md added +14
| @@ -0,0 +1,14 @@ | ||
| 1 | # One notice per release | |
| 2 | ||
| 3 | Every recorded release (a pull landed on the forge's own repository) sends one message | |
| 4 | (`src/release/announce.ts`) to the notify URL each admin and the repository's owner chose once | |
| 5 | under account settings: | |
| 6 | ||
| 7 | ||
| 8 | <app> <version>: <the note's first line> | |
| 9 | <the forge's address> | |
| 10 | tests passed | tests failed, still serving the last good version | |
| 11 | ||
| 12 | ||
| 13 | The version is the landed commit, short. A release held by code scanning reads as "tests failed". With no `FORGE_URL` the link line is left out. Each send is cut off after four seconds and all go at once. | |
| 14 | It uses the same https-only sender as `crew/notify.ts`; a failed send is logged by host and dropped. |
src/app.ts +25 −6
| @@ -46,7 +46,9 @@ export interface ForgeConfig { | ||
| 46 | 46 | * forge reads the setting's `open`; `main.ts` turns it on. |
| 47 | 47 | */ |
| 48 | 48 | seedSignup?: boolean; |
| 49 | /** The disk probe vitals reads; the volume under `dataDir` when unset. Tests give it a reading. */ | |
| 49 | /** | |
| 50 | * The disk probe vitals reads; the volume under `dataDir` when unset. Tests give it a reading. | |
| 51 | */ | |
| 50 | 52 | disk?: (dir: string) => { freeBytes: number; totalBytes: number }; |
| 51 | 53 | /** |
| 52 | 54 | * The host's free memory probe vitals reads against its floor; `freemem()` |
| @@ -60,7 +62,10 @@ export interface ForgeConfig { | ||
| 60 | 62 | * (`spawn/memory_fit.ts`); its pod's limit or its own when unset. Tests give it a figure. |
| 61 | 63 | */ |
| 62 | 64 | memory?: () => number; |
| 63 | /** How long the search page's first code search may keep starting greps, in ms. @default 30 (CODE_BUDGET_MS) */ | |
| 65 | /** | |
| 66 | * How long the search page's first code search may keep starting greps, in ms. @default 30 | |
| 67 | * (CODE_BUDGET_MS) | |
| 68 | */ | |
| 64 | 69 | codeBudgetMs?: number; |
| 65 | 70 | /** @default 3000 */ |
| 66 | 71 | port?: number; |
| @@ -217,12 +222,23 @@ export interface ForgeConfig { | ||
| 217 | 222 | * The listener is bound with SO_REUSEPORT so the new process can share it. |
| 218 | 223 | */ |
| 219 | 224 | selfSwap?: boolean; |
| 220 | /** The most one proxied app websocket frame may carry, either way (`apps/proxy.ts`). Tests lower it. @default 16 MiB */ | |
| 225 | /** | |
| 226 | * The most one proxied app websocket frame may carry, either way (`apps/proxy.ts`). Tests lower | |
| 227 | * it. @default 16 MiB | |
| 228 | */ | |
| 221 | 229 | wsMaxMessage?: number; |
| 222 | /** A standby: reads are answered, every mutation is a 503 (`FORGE_READ_ONLY=1`; `http/read_only.ts`, #9657). */ | |
| 230 | /** | |
| 231 | * A standby: reads are answered, every mutation is a 503 (`FORGE_READ_ONLY=1`; | |
| 232 | * `http/read_only.ts`, #9657). | |
| 233 | */ | |
| 223 | 234 | readOnly?: boolean; |
| 224 | 235 | /** How long a swapped-in release has to read healthy (`FORGE_SWAP_BUDGET_S`). @default 60000 */ |
| 225 | 236 | swapBudgetMs?: number; |
| 237 | /** | |
| 238 | * The sender release notices go through (`release/announce.ts`); the real https one unless a test | |
| 239 | * says. | |
| 240 | */ | |
| 241 | releaseSend?: (url: string, body: string, headers: Record<string, string>) => Promise<boolean>; | |
| 226 | 242 | } |
| 227 | 243 | |
| 228 | 244 | export interface App { |
| @@ -232,7 +248,9 @@ export interface App { | ||
| 232 | 248 | readonly log: Log; |
| 233 | 249 | readonly reposRoot: string; |
| 234 | 250 | readonly socketPath: string; |
| 235 | /** Where the internal listener answers: `socketPath`, or a loopback port (`git/hook-address.ts`). */ | |
| 251 | /** | |
| 252 | * Where the internal listener answers: `socketPath`, or a loopback port (`git/hook-address.ts`). | |
| 253 | */ | |
| 236 | 254 | readonly hookAddress: { current: string }; |
| 237 | 255 | /** Per-boot secret every internal request must carry (`FORGE_HOOK_SECRET` in a hook's env). */ |
| 238 | 256 | readonly hookSecret: string; |
| @@ -275,7 +293,8 @@ export function createApp(config: ForgeConfig): App { | ||
| 275 | 293 | // A pull opened or merged, a release served, an issue dropped or split: |
| 276 | 294 | // estimates settle (#11955). |
| 277 | 295 | bus.subscribe((event) => settleEstimates(db, event), "local"); |
| 278 | // A push, a merge, a repository change or a build event may move pins: the kept listings go (`git/pins_kept.ts`). | |
| 296 | // A push, a merge, a repository change or a build event may move pins: the kept listings go | |
| 297 | // (`git/pins_kept.ts`). | |
| 279 | 298 | bus.subscribe((event) => { |
| 280 | 299 | const k = event.kind; |
| 281 | 300 | if (k === "push" || k === "pull.merged" || k.startsWith("repo.") || k.startsWith("build.")) dropAllPins(); |
src/checks/landing.ts +12
| @@ -23,6 +23,7 @@ import { beginSwap, endSwap, handover, startRelease } from "../release/swap.ts"; | ||
| 23 | 23 | import { running } from "../kernel/version.ts"; |
| 24 | 24 | import { noteReleased } from "../crew/note_closed.ts"; |
| 25 | 25 | import { recordRelease, type Release } from "../release/record.ts"; |
| 26 | import { announceRelease } from "../release/announce.ts"; | |
| 26 | 27 | import { scanHold } from "../release/scan_hold.ts"; |
| 27 | 28 | import type { Pull } from "../core/pulls.ts"; |
| 28 | 29 | import type { Repo } from "../core/repos.ts"; |
| @@ -211,6 +212,17 @@ async function cut( | ||
| 211 | 212 | } |
| 212 | 213 | // The notes this pull closed learn which release carries their fix (#10564). |
| 213 | 214 | if (verdict.ok && !hold.held) noteReleased(app.db, release); |
| 215 | // One message of one shape to the channel each admin chose (#13708), before a swap drains this | |
| 216 | // process. | |
| 217 | await announceRelease({ | |
| 218 | db: app.db, | |
| 219 | repo, | |
| 220 | pull, | |
| 221 | release, | |
| 222 | passed: verdict.ok && !hold.held, | |
| 223 | warn: (m, f) => app.log.warn(m, f), | |
| 224 | ...(app.config.releaseSend === undefined ? {} : { send: app.config.releaseSend }), | |
| 225 | }).catch((error) => app.log.warn("release notice failed", { error: String(error) })); | |
| 214 | 226 | if (verdict.ok && out.ok && !hold.held) await swapIn(app, by, repo, pull, sha, out.value); |
| 215 | 227 | return release; |
| 216 | 228 | } |
src/engine/crossing.ts +2
| @@ -69,6 +69,8 @@ export const STAYS = { | ||
| 69 | 69 | "an object with a method; no duty of the engine asks it, and one that comes to must make its own on that thread", |
| 70 | 70 | mailer: |
| 71 | 71 | "a function: a test's stand-in for SMTP; `mail`, where real mail goes out, crosses", |
| 72 | releaseSend: | |
| 73 | "a function: a test's stand-in for the notify sender, used where a release is cut on the serving thread", | |
| 72 | 74 | verifyHuman: |
| 73 | 75 | "a function: a test's stand-in for Turnstile, asked at sign-up on the serving thread only", |
| 74 | 76 | } as const satisfies { readonly [K in keyof ForgeConfig]?: string }; |
src/release/announce.ts added +96
| @@ -0,0 +1,96 @@ | ||
| 1 | /** | |
| 2 | * One message for every recorded release (#13708), of one shape: | |
| 3 | * | |
| 4 | * <app> <version>: <the note's first line> | |
| 5 | * <live link> | |
| 6 | * tests passed | tests failed, still serving the last good version | |
| 7 | * | |
| 8 | * It goes to the notify URL each admin chose once (`crew/notify.ts`), through | |
| 9 | * the same sender and the same https-only, no-private-host gate. The parent's | |
| 10 | * own landings call it from `checks/landing.ts`; a message that cannot be | |
| 11 | * sent is dropped and logged without its URL, never thrown. | |
| 12 | */ | |
| 13 | ||
| 14 | import type { Database } from "bun:sqlite"; | |
| 15 | import type { Repo } from "../core/repos.ts"; | |
| 16 | import type { Pull } from "../core/pulls.ts"; | |
| 17 | import { notifyHost, notifyUrlOf, post, type Sender } from "../crew/notify.ts"; | |
| 18 | import { releaseName, type Release } from "./record.ts"; | |
| 19 | ||
| 20 | export const PASSED = "tests passed"; | |
| 21 | export const FAILED = "tests failed, still serving the last good version"; | |
| 22 | const NOTE_MAX = 140; | |
| 23 | /** The longest one send holds the landing queue; sends to every listener run at once. */ | |
| 24 | export const SEND_BUDGET_MS = 4_000; | |
| 25 | ||
| 26 | /** The note's first line: no markup, no control bytes, short; the title when the body has none. */ | |
| 27 | export function firstLine(title: string, body: string): string { | |
| 28 | const clean = (s: string): string => | |
| 29 | // eslint-disable-next-line no-control-regex | |
| 30 | s.replace(/[\u0000-\u001f\u007f]+/g, " ").replace(/^[\s#>*\-`]+/, "").replace(/[`*_]/g, "").replace(/\s+/g, " ").trim(); | |
| 31 | const line = body.split("\n").map(clean).find((l) => l !== "") ?? clean(title); | |
| 32 | return line.length > NOTE_MAX ? `${line.slice(0, NOTE_MAX - 1).trimEnd()}…` : line; | |
| 33 | } | |
| 34 | ||
| 35 | /** The one message; `passed` is the release serving, not merely recorded. */ | |
| 36 | export function releaseMessage( | |
| 37 | app: string, | |
| 38 | release: Release, | |
| 39 | note: string, | |
| 40 | link: string, | |
| 41 | passed: boolean, | |
| 42 | ): string { | |
| 43 | const lines = [`${app} ${releaseName(release)}: ${note}`, link, passed ? PASSED : FAILED]; | |
| 44 | return lines.filter((l) => l !== "").join("\n"); | |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * Everyone who chose a channel and may hear of releases: the forge's admins and the repository's | |
| 49 | * owner. | |
| 50 | */ | |
| 51 | export function listeners(db: Database, repo: Repo): string[] { | |
| 52 | return db | |
| 53 | .query<{ id: string }, [string]>( | |
| 54 | `SELECT id FROM user WHERE kind = 'user' AND is_agent = 0 AND suspended_at IS NULL AND removed_at IS NULL AND (is_admin = 1 OR id = ?1)`, | |
| 55 | ) | |
| 56 | .all(repo.ownerId) | |
| 57 | .map((r) => r.id) | |
| 58 | .filter((id) => notifyUrlOf(db, id) !== undefined); | |
| 59 | } | |
| 60 | ||
| 61 | export interface Announce { | |
| 62 | db: Database; | |
| 63 | repo: Repo; | |
| 64 | pull: Pull; | |
| 65 | release: Release; | |
| 66 | /** Whether the release is the one now serving: preflight green and not held. */ | |
| 67 | passed: boolean; | |
| 68 | forgeUrl?: string; | |
| 69 | send?: Sender; | |
| 70 | /** The most one send may take before it counts as not delivered. */ | |
| 71 | budgetMs?: number; | |
| 72 | warn?: (msg: string, fields: Record<string, string>) => void; | |
| 73 | } | |
| 74 | ||
| 75 | /** Sends the release's message to each listener; how many it reached. */ | |
| 76 | export async function announceRelease(a: Announce): Promise<number> { | |
| 77 | const send = a.send ?? post; | |
| 78 | const base = (a.forgeUrl ?? process.env["FORGE_URL"] ?? "").trim().replace(/\/+$/, ""); | |
| 79 | const link = /^https?:\/\//.test(base) ? base : ""; | |
| 80 | const text = releaseMessage(a.repo.name, a.release, firstLine(a.pull.title, a.pull.body), link, a.passed); | |
| 81 | const sends = listeners(a.db, a.repo).map(async (id) => { | |
| 82 | const url = notifyUrlOf(a.db, id)!; | |
| 83 | let timer: ReturnType<typeof setTimeout> | undefined; | |
| 84 | const late = new Promise<boolean>((res) => { | |
| 85 | timer = setTimeout(() => res(false), a.budgetMs ?? SEND_BUDGET_MS); | |
| 86 | }); | |
| 87 | const ok = await Promise.race([ | |
| 88 | send(url, text, { title: "forge", ...(link === "" ? {} : { click: link }) }).catch(() => false), | |
| 89 | late, | |
| 90 | ]); | |
| 91 | clearTimeout(timer); | |
| 92 | if (!ok) a.warn?.("release notice not delivered", { host: notifyHost(url) ?? "" }); | |
| 93 | return ok; | |
| 94 | }); | |
| 95 | return (await Promise.all(sends)).filter(Boolean).length; | |
| 96 | } |
test/engine-crossing.test.ts +2
| @@ -178,6 +178,7 @@ describe("every setting is on one list, and what crosses is data", () => { | ||
| 178 | 178 | "mailer", |
| 179 | 179 | "memory", |
| 180 | 180 | "memoryWatch", |
| 181 | "releaseSend", | |
| 181 | 182 | "verifyHuman", |
| 182 | 183 | ]); |
| 183 | 184 | expect(Object.keys(STAYS).sort()).toEqual( |
| @@ -205,6 +206,7 @@ const whole = (dataDir: string): Required<ForgeConfig> => ({ | ||
| 205 | 206 | disk: () => ({ freeBytes: 1, totalBytes: 2 }), |
| 206 | 207 | hostFree: () => 1, |
| 207 | 208 | memoryWatch: { grown: () => undefined }, |
| 209 | releaseSend: async () => true, | |
| 208 | 210 | memory: () => 1, |
| 209 | 211 | codeBudgetMs: 30, |
| 210 | 212 | port: 8080, |
test/release-announce.test.ts added +88
| @@ -0,0 +1,88 @@ | ||
| 1 | import { afterEach, beforeEach, expect, test } from "bun:test"; | |
| 2 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 3 | import { tmpdir } from "node:os"; | |
| 4 | import { join } from "node:path"; | |
| 5 | import { createApp, type App } from "../src/app.ts"; | |
| 6 | import { createUser } from "../src/core/users.ts"; | |
| 7 | import { setNotifyUrl } from "../src/crew/notify.ts"; | |
| 8 | import { announceRelease, firstLine, listeners, releaseMessage, FAILED, PASSED } from "../src/release/announce.ts"; | |
| 9 | import { recordRelease } from "../src/release/record.ts"; | |
| 10 | import type { Repo } from "../src/core/repos.ts"; | |
| 11 | import type { Pull } from "../src/core/pulls.ts"; | |
| 12 | ||
| 13 | let dir: string; | |
| 14 | let app: App; | |
| 15 | let aliceId: string; | |
| 16 | beforeEach(async () => { | |
| 17 | dir = await mkdtemp(join(tmpdir(), "forge-announce-")); | |
| 18 | app = createApp({ dataDir: dir, port: 0 }); | |
| 19 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 20 | if (!a.ok) throw new Error(a.error); | |
| 21 | aliceId = a.value.id; | |
| 22 | }); | |
| 23 | afterEach(async () => { | |
| 24 | app.close?.(); | |
| 25 | await rm(dir, { recursive: true, force: true }); | |
| 26 | }); | |
| 27 | ||
| 28 | const repo = (): Repo => ({ id: "r1", ownerId: aliceId, name: "forge" }) as Repo; | |
| 29 | const pull = { title: "Title", body: "\n## Faster feed\nmore" } as Pull; | |
| 30 | const rel = (ok: boolean) => recordRelease(app.db, { sha: "abcdef0123456789", repoId: "r1", pullNumber: 1, ok, line: "x" }); | |
| 31 | ||
| 32 | test("first line drops markup and falls back to the title", () => { | |
| 33 | expect(firstLine("T", "\n## Faster `feed`\nmore")).toBe("Faster feed"); | |
| 34 | expect(firstLine("Only title", "")).toBe("Only title"); | |
| 35 | expect(firstLine("T", "x".repeat(300)).length).toBeLessThanOrEqual(140); | |
| 36 | }); | |
| 37 | ||
| 38 | test("one message of one shape reaches the chosen channel", async () => { | |
| 39 | setNotifyUrl(app.db, aliceId, "https://ntfy.example.test/t"); | |
| 40 | const got: { url: string; body: string }[] = []; | |
| 41 | const n = await announceRelease({ db: app.db, repo: repo(), pull, release: rel(true), passed: true, forgeUrl: "https://f.example.test/", send: async (url, body) => (got.push({ url, body }), true) }); | |
| 42 | expect(n).toBe(1); | |
| 43 | expect(got[0]!.body).toBe(`forge abcdef012345: Faster feed\nhttps://f.example.test\n${PASSED}`); | |
| 44 | }); | |
| 45 | ||
| 46 | test("a failed release says it is still serving the last good version", async () => { | |
| 47 | setNotifyUrl(app.db, aliceId, "https://ntfy.example.test/t"); | |
| 48 | const got: string[] = []; | |
| 49 | await announceRelease({ db: app.db, repo: repo(), pull, release: rel(false), passed: false, forgeUrl: "https://f.example.test", send: async (_u, b) => (got.push(b), true) }); | |
| 50 | expect(got[0]!.endsWith(FAILED)).toBe(true); | |
| 51 | expect(releaseMessage("a", rel(true), "n", "l", true)).toContain(PASSED); | |
| 52 | }); | |
| 53 | ||
| 54 | test("no channel chosen sends nothing; a refusing sender is counted, not thrown", async () => { | |
| 55 | const send = async () => true; | |
| 56 | expect(await announceRelease({ db: app.db, repo: repo(), pull, release: rel(true), passed: true, send })).toBe(0); | |
| 57 | setNotifyUrl(app.db, aliceId, "https://ntfy.example.test/t"); | |
| 58 | const warned: string[] = []; | |
| 59 | const n = await announceRelease({ db: app.db, repo: repo(), pull, release: rel(true), passed: true, send: async () => { throw new Error("x"); }, warn: (m, f) => warned.push(m + f["host"]) }); | |
| 60 | expect(n).toBe(0); | |
| 61 | expect(warned).toEqual(["release notice not deliveredntfy.example.test"]); | |
| 62 | }); | |
| 63 | ||
| 64 | test("only a person who is an admin or the owner, not suspended, is a listener", async () => { | |
| 65 | const mk = async (name: string) => { | |
| 66 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: name, email: `${name}@forge.local`, password: "a-good-passphrase" }); | |
| 67 | if (!u.ok) throw new Error(u.error); | |
| 68 | setNotifyUrl(app.db, u.value.id, `https://ntfy.example.test/${name}`); | |
| 69 | return u.value.id; | |
| 70 | }; | |
| 71 | const agent = await mk("robo7"); | |
| 72 | app.db.query("UPDATE user SET is_agent = 1 WHERE id = ?1").run(agent); | |
| 73 | const gone = await mk("gone7"); | |
| 74 | app.db.query("UPDATE user SET suspended_at = 1 WHERE id = ?1").run(gone); | |
| 75 | await mk("bystander7"); | |
| 76 | setNotifyUrl(app.db, aliceId, "https://ntfy.example.test/alice"); | |
| 77 | expect(listeners(app.db, repo())).toEqual([aliceId]); | |
| 78 | }); | |
| 79 | ||
| 80 | test("a send that never answers is cut off and logged, and the link is omitted without an address", async () => { | |
| 81 | setNotifyUrl(app.db, aliceId, "https://ntfy.example.test/t"); | |
| 82 | const warned: string[] = []; | |
| 83 | const bodies: string[] = []; | |
| 84 | const n = await announceRelease({ db: app.db, repo: repo(), pull, release: rel(true), passed: true, forgeUrl: "", budgetMs: 20, send: (_u, b) => (bodies.push(b), new Promise<boolean>(() => {})), warn: (m) => warned.push(m) }); | |
| 85 | expect(n).toBe(0); | |
| 86 | expect(warned).toEqual(["release notice not delivered"]); | |
| 87 | expect(bodies[0]).toBe(`forge abcdef012345: Faster feed\n${PASSED}`); | |
| 88 | }); |
test/release-landing-notice.test.ts added +63
| @@ -0,0 +1,63 @@ | ||
| 1 | /** | |
| 2 | * `cut` in `checks/landing.ts` sends one notice per recorded release, and a scan hold reads as | |
| 3 | * failed. | |
| 4 | */ | |
| 5 | ||
| 6 | import { afterAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { openPull } from "../src/actions/pulls.ts"; | |
| 11 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { createApp } from "../src/app.ts"; | |
| 13 | import { releaseOnLand } from "../src/checks/landing.ts"; | |
| 14 | import { scanNightly } from "../src/checks/scan.ts"; | |
| 15 | import { setNotifyUrl } from "../src/crew/notify.ts"; | |
| 16 | import { createUser } from "../src/core/users.ts"; | |
| 17 | import { FAILED, PASSED } from "../src/release/announce.ts"; | |
| 18 | import { quietLogs } from "./helpers/globals.ts"; | |
| 19 | ||
| 20 | quietLogs(); | |
| 21 | ||
| 22 | const AWS = "AKIA" + "QX7Z".repeat(4); | |
| 23 | const STAND_IN = `if (process.argv.includes("--preflight")) { console.log("preflight ok: stand-in"); process.exit(0); }\n`; | |
| 24 | const dirs: string[] = []; | |
| 25 | afterAll(async () => { | |
| 26 | for (const d of dirs) await rm(d, { recursive: true, force: true }); | |
| 27 | }); | |
| 28 | ||
| 29 | async function land(extra: { path: string; content: string }[]) { | |
| 30 | const dataDir = await mkdtemp(join(tmpdir(), "forge-notice-land-")); | |
| 31 | dirs.push(dataDir); | |
| 32 | const got: string[] = []; | |
| 33 | const app = createApp({ dataDir, port: 0, forgeRepo: "alice/forge-code", releaseSend: async (_u, b) => (got.push(b), true) }); | |
| 34 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 35 | if (!u.ok) throw new Error("user"); | |
| 36 | setNotifyUrl(app.db, u.value.id, "https://ntfy.example.test/t"); | |
| 37 | const r = await createRepo(app, u.value, { name: "forge-code", visibility: "public" }); | |
| 38 | if (!r.ok) throw new Error("repo"); | |
| 39 | await commitToBranch(app, u.value, r.value, { message: "seed", files: [{ path: "a.txt", content: "a" }] }); | |
| 40 | await commitToBranch(app, u.value, r.value, { message: "b", branch: "change", files: [{ path: "b.txt", content: "b" }] }); | |
| 41 | const pull = await openPull(app, u.value, r.value, { title: "Faster feed", baseBranch: r.value.defaultBranch, headBranch: "change" }); | |
| 42 | if (!pull.ok) throw new Error("pull"); | |
| 43 | const made = await commitToBranch(app, u.value, r.value, { message: "land", files: [{ path: "src/main.ts", content: STAND_IN }, ...extra] }); | |
| 44 | if (!made.ok) throw new Error("commit"); | |
| 45 | if (extra.length > 0) await scanNightly(app, r.value); | |
| 46 | await releaseOnLand(app, u.value, r.value, pull.value, made.value.commitOid); | |
| 47 | app.close(); | |
| 48 | return got; | |
| 49 | } | |
| 50 | ||
| 51 | test("a recorded release sends exactly one message, tests passed", async () => { | |
| 52 | const got = await land([]); | |
| 53 | expect(got.length).toBe(1); | |
| 54 | expect(got[0]).toContain("forge-code "); | |
| 55 | expect(got[0]).toContain("Faster feed"); | |
| 56 | expect(got[0]!.endsWith(PASSED)).toBe(true); | |
| 57 | }, 60_000); | |
| 58 | ||
| 59 | test("a release held by the scan reads tests failed", async () => { | |
| 60 | const got = await land([{ path: "deploy.ts", content: `export const key = "${AWS}";\n` }]); | |
| 61 | expect(got.length).toBe(1); | |
| 62 | expect(got[0]!.endsWith(FAILED)).toBe(true); | |
| 63 | }, 60_000); |
test/timers-named.test.ts +24 −6
| @@ -45,7 +45,10 @@ interface Allowed { | ||
| 45 | 45 | */ |
| 46 | 46 | const PER_CONNECTION = "one per open connection: wrapped, a burst of them evicts the real jobs from the 256-span ring"; |
| 47 | 47 | |
| 48 | /** A one-shot whose callback only settles the promise a caller awaits: the work after the await runs in that caller. */ | |
| 48 | /** | |
| 49 | * A one-shot whose callback only settles the promise a caller awaits: the work after the await runs | |
| 50 | * in that caller. | |
| 51 | */ | |
| 49 | 52 | const SLEEP = "a sleep: it only resolves the promise its caller awaits, and the caller's work after the await is the caller's job"; |
| 50 | 53 | /** A one-shot that rejects, aborts or stops one call in flight: no work of its own. */ |
| 51 | 54 | const DEADLINE = "a one-shot deadline on one call in flight: it settles, aborts or stops that call and does no work of its own"; |
| @@ -119,6 +122,7 @@ const ALLOWED: readonly Allowed[] = [ | ||
| 119 | 122 | ["src/flow/lanes.ts", "resolve"], |
| 120 | 123 | ]), |
| 121 | 124 | ...allow("setTimeout", DEADLINE, [ |
| 125 | ["src/release/announce.ts", "() => res(false)"], | |
| 122 | 126 | ["src/apps/toolbar.ts", "resolve"], |
| 123 | 127 | ["src/flow/lanes.ts", "() => reject("], |
| 124 | 128 | ["src/web/map_snapshot.ts", "() => reject("], |
| @@ -185,7 +189,10 @@ function sources(dir: string, out: string[] = []): string[] { | ||
| 185 | 189 | return out; |
| 186 | 190 | } |
| 187 | 191 | |
| 188 | /** The first argument of each `call(` in `text`: its text, whitespace collapsed, and whether its work runs inside `during`. */ | |
| 192 | /** | |
| 193 | * The first argument of each `call(` in `text`: its text, whitespace collapsed, and whether its | |
| 194 | * work runs inside `during`. | |
| 195 | */ | |
| 189 | 196 | export function callbacks(text: string, call: Call): { callback: string; named: boolean; line: number }[] { |
| 190 | 197 | return callbacksIn(ts.createSourceFile("x.ts", text, ts.ScriptTarget.Latest, false), call); |
| 191 | 198 | } |
| @@ -209,7 +216,10 @@ function callbacksIn(source: ts.SourceFile, call: Call): { callback: string; nam | ||
| 209 | 216 | return found; |
| 210 | 217 | } |
| 211 | 218 | |
| 212 | /** An expression whose work is a `during` call: the call itself, or it behind `void`, `&&`, `.catch`, `.finally` or a `.then(() => during(…))`. */ | |
| 219 | /** | |
| 220 | * An expression whose work is a `during` call: the call itself, or it behind `void`, `&&`, | |
| 221 | * `.catch`, `.finally` or a `.then(() => during(…))`. | |
| 222 | */ | |
| 213 | 223 | function isDuring(expr: ts.Expression): boolean { |
| 214 | 224 | if (ts.isParenthesizedExpression(expr) || ts.isVoidExpression(expr)) return isDuring(expr.expression); |
| 215 | 225 | if (ts.isBinaryExpression(expr)) { |
| @@ -226,7 +236,9 @@ function isDuring(expr: ts.Expression): boolean { | ||
| 226 | 236 | return callee.name.text === "then" && expr.arguments.length > 0 && expr.arguments.every(isNamed); |
| 227 | 237 | } |
| 228 | 238 | |
| 229 | /** A statement that does no work of its own: a guard that returns, or a flag set to a plain value. */ | |
| 239 | /** | |
| 240 | * A statement that does no work of its own: a guard that returns, or a flag set to a plain value. | |
| 241 | */ | |
| 230 | 242 | function isInert(st: ts.Statement): boolean { |
| 231 | 243 | if (ts.isExpressionStatement(st) && isBookkeeping(st.expression)) return true; |
| 232 | 244 | if (ts.isIfStatement(st)) |
| @@ -238,7 +250,10 @@ function isInert(st: ts.Statement): boolean { | ||
| 238 | 250 | return operatorToken.kind === ts.SyntaxKind.EqualsToken && (ts.isLiteralExpression(right) || right.kind === ts.SyntaxKind.TrueKeyword || right.kind === ts.SyntaxKind.FalseKeyword || ts.isIdentifier(right)); |
| 239 | 251 | } |
| 240 | 252 | |
| 241 | /** A counter bump (`looks++`) or a timer forgetting itself (`timers.delete(timer)`): no work of its own. */ | |
| 253 | /** | |
| 254 | * A counter bump (`looks++`) or a timer forgetting itself (`timers.delete(timer)`): no work of its | |
| 255 | * own. | |
| 256 | */ | |
| 242 | 257 | function isBookkeeping(expr: ts.Expression): boolean { |
| 243 | 258 | if (ts.isPostfixUnaryExpression(expr) || ts.isPrefixUnaryExpression(expr)) |
| 244 | 259 | return ts.isIdentifier(expr.operand) && (expr.operator === ts.SyntaxKind.PlusPlusToken || expr.operator === ts.SyntaxKind.MinusMinusToken); |
| @@ -246,7 +261,10 @@ function isBookkeeping(expr: ts.Expression): boolean { | ||
| 246 | 261 | ts.isIdentifier(expr.expression.expression) && expr.arguments.length === 1 && ts.isIdentifier(expr.arguments[0]!); |
| 247 | 262 | } |
| 248 | 263 | |
| 249 | /** Every statement is inert or a `during` (a `try` counts by its block), and at least one is a `during`. */ | |
| 264 | /** | |
| 265 | * Every statement is inert or a `during` (a `try` counts by its block), and at least one is a | |
| 266 | * `during`. | |
| 267 | */ | |
| 250 | 268 | function blockNamed(statements: readonly ts.Statement[]): boolean { |
| 251 | 269 | let any = false; |
| 252 | 270 | for (const st of statements) { |
new above
offline
Awaited inside the landing queue with no timeout, the error is swallowed, and the line is very long. This needs a bounded send, a logged failure and a test.