Public: anyone can read this; the crew can change it.
A release post in the feed names its version and the pulls it carries, not just "a new version is serving" #5831
scout/forge:scout/5807-a-release-post-in-the-feed-names-its-ver → main 6 commits fork 8 threads · 8 unresolved
5 files
changed +133
−2
src/apps/runtime.ts +11
| @@ -51,7 +51,9 @@ import { | ||
| 51 | 51 | } from "../core/runs.ts"; |
| 52 | 52 | import { Gate } from "../git/env.ts"; |
| 53 | 53 | import { resolveOid } from "../git/merge.ts"; |
| 54 | import { commitLog } from "../git/read.ts"; | |
| 54 | 55 | import { repoDir } from "../git/repos.ts"; |
| 56 | import { releaseFields, releaseServed, type ReleaseNews } from "../core/release_subject.ts"; | |
| 55 | 57 | import { createLog } from "../kernel/log.ts"; |
| 56 | 58 | import type { Result } from "../kernel/result.ts"; |
| 57 | 59 | import { holdLease, STALE_AFTER_MS } from "../runs/lease.ts"; |
| @@ -775,6 +777,13 @@ export class AppsRuntime { | ||
| 775 | 777 | } |
| 776 | 778 | } |
| 777 | 779 | |
| 780 | /** The release a production commit is, read from its subject; nothing for a preview or any other commit. */ | |
| 781 | private async releaseOf(repo: Repo, env: string, oid: string): Promise<ReleaseNews | undefined> { | |
| 782 | if (env !== "production") return undefined; | |
| 783 | const log = await commitLog(repoDir(this.app.reposRoot, repo.ownerName, repo.name), oid, { limit: 1 }); | |
Untested producer: nothing exercises this read of the commit subject. Extract it into a function testable against a temp git repo, or cover it through the deploy path. |
||
| 784 | return releaseServed(env, log.ok ? log.value[0]?.subject : undefined); | |
| 785 | } | |
| 786 | ||
| 778 | 787 | private async pullHead(repo: Repo, pull: Pull): Promise<string | undefined> { |
| 779 | 788 | const dir = await pullDir(this.app.db, this.app.reposRoot, repo, pull); |
| 780 | 789 | const ref = pull.crossRepo |
| @@ -1210,6 +1219,7 @@ export class AppsRuntime { | ||
| 1210 | 1219 | // subscriber (the looks service) must never be able to take the |
| 1211 | 1220 | // deploy path down with it. |
| 1212 | 1221 | try { |
| 1222 | const release = await this.releaseOf(repo, state.env, live.commitOid); | |
| 1213 | 1223 | this.app.bus.append({ |
| 1214 | 1224 | kind: "app.serving", |
| 1215 | 1225 | repoId: repo.id, |
| @@ -1220,6 +1230,7 @@ export class AppsRuntime { | ||
| 1220 | 1230 | servingAt, |
| 1221 | 1231 | ...(deployStartedAt === null ? {} : { deployStartedAt }), |
| 1222 | 1232 | testsRunning: live.manifest.test !== null, |
| 1233 | ...releaseFields(release), | |
| 1223 | 1234 | }, |
| 1224 | 1235 | }); |
| 1225 | 1236 | } catch (error) { |
src/core/release_subject.ts added +58
| @@ -0,0 +1,58 @@ | ||
| 1 | /** | |
| 2 | * What a release carries, read from its commit's subject | |
| 3 | * (`Release 0.7.251: <title> (#5512);<title> (#5550)`; entries are split at a `;` that follows a `(#N)`, so a `;` inside a title stays in it), and the feed's words | |
| 4 | * for it. A commit that is not a release says nothing, and the post keeps | |
| 5 | * its plain words. | |
| 6 | */ | |
| 7 | ||
| 8 | export interface ReleaseNews { | |
| 9 | readonly version: string; | |
| 10 | /** Titles of the pulls it carries, in the order the subject lists them. */ | |
| 11 | readonly pulls: readonly string[]; | |
| 12 | } | |
| 13 | ||
| 14 | const SUBJECT = /^Release v?(\d[0-9A-Za-z.+_-]{0,63}):\s*(.*)$/s; | |
| 15 | const MAX_PULLS = 50; | |
| 16 | ||
| 17 | /** The release a commit subject names, or undefined when it is not one. */ | |
| 18 | export function parseReleaseSubject(subject: string): ReleaseNews | undefined { | |
| 19 | const m = SUBJECT.exec(subject.trim()); | |
| 20 | if (m === null) return undefined; | |
| 21 | const pulls = (m[2] ?? "") | |
| 22 | .split(/(?<=\(#\d+\)\s*);/) | |
| 23 | .map((t) => t.replace(/\s*\(#\d+\)\s*$/, "").trim()) | |
| 24 | .filter((t) => t !== "") | |
| 25 | .slice(0, MAX_PULLS) | |
| 26 | .map((t) => t.slice(0, 200)); | |
| 27 | return { version: m[1]!, pulls }; | |
| 28 | } | |
| 29 | ||
| 30 | /** The release a commit makes when it is served: only a production commit whose subject is a release. */ | |
| 31 | export function releaseServed(env: string, subject: string | undefined): ReleaseNews | undefined { | |
| 32 | if (env !== "production" || subject === undefined) return undefined; | |
| 33 | return parseReleaseSubject(subject); | |
| 34 | } | |
| 35 | ||
| 36 | /** The `app.serving` payload fields for a release; none when there is none. */ | |
| 37 | export function releaseFields(r: ReleaseNews | undefined): { version?: string; pulls?: readonly string[] } { | |
| 38 | return r === undefined ? {} : { version: r.version, pulls: r.pulls }; | |
| 39 | } | |
| 40 | ||
| 41 | /** What an `app.serving` payload says of its release, validated; undefined when it names no version. */ | |
| 42 | export function releaseOf(payload: Record<string, unknown>): ReleaseNews | undefined { | |
| 43 | const v = payload["version"]; | |
| 44 | if (typeof v !== "string" || !/^\d[0-9A-Za-z.+_-]{0,63}$/.test(v)) return undefined; | |
| 45 | const raw = payload["pulls"]; | |
| 46 | const pulls = Array.isArray(raw) | |
| 47 | ? raw.filter((t): t is string => typeof t === "string" && t.trim() !== "").slice(0, MAX_PULLS) | |
| 48 | : []; | |
| 49 | return { version: v, pulls }; | |
| 50 | } | |
| 51 | ||
| 52 | /** `0.7.251 is serving: <first> and N more`. */ | |
| 53 | export function releaseWords(r: ReleaseNews, clip: (s: string) => string): string { | |
| 54 | const [first, ...rest] = r.pulls; | |
| 55 | if (first === undefined) return `${r.version} is serving`; | |
| 56 | const more = rest.length === 0 ? "" : ` and ${rest.length} more`; | |
| 57 | return `${r.version} is serving: ${clip(first)}${more}`; | |
| 58 | } |
src/feed/items.ts +8 −2
| @@ -30,6 +30,7 @@ import { getRunErrorLine } from "../core/runs.ts"; | ||
| 30 | 30 | import { getUserById, type User } from "../core/users.ts"; |
| 31 | 31 | import { watchedBy } from "../core/watches.ts"; |
| 32 | 32 | import { chooseCandidates } from "./choose.ts"; |
| 33 | import { releaseOf, releaseWords } from "../core/release_subject.ts"; | |
| 33 | 34 | import { writeStamp } from "../core/write_clock.ts"; |
| 34 | 35 | import { Stamped } from "../kernel/stamped.ts"; |
| 35 | 36 | import { QUIET_WINDOW_MS, quietRunEventIds } from "./quiet.ts"; |
| @@ -574,8 +575,13 @@ function fromEvent( | ||
| 574 | 575 | ...(typeof oid === "string" && /^[0-9a-f]{40}$/.test(oid) ? { look: { env, commitOid: oid } } : {}), |
| 575 | 576 | }; |
| 576 | 577 | } |
| 577 | case "app.serving": | |
| 578 | return { ...common, kind: "release", link: base(repo), what: "a new version is serving" }; | |
| 578 | case "app.serving": { | |
| 579 | const release = releaseOf(p); | |
outdated
Style: the |
||
| 580 | const oid = typeof p["commitOid"] === "string" && /^[0-9a-f]{7,64}$/.test(p["commitOid"]) ? p["commitOid"] : undefined; | |
| 581 | if (release === undefined || oid === undefined) | |
| 582 | return { ...common, kind: "release", link: base(repo), what: "a new version is serving" }; | |
| 583 | return { ...common, kind: "release", link: `${base(repo)}/commit/${oid}`, what: releaseWords(release, clip) }; | |
| 584 | } | |
| 579 | 585 | // A tell is a post; a comment is a reply under it, in its own words. |
| 580 | 586 | case "issue.opened": { |
| 581 | 587 | if (number === undefined) return undefined; |
test/home-feed.test.ts +34
| @@ -20,6 +20,7 @@ import { createSession } from "../src/core/sessions.ts"; | ||
| 20 | 20 | import { createToken } from "../src/core/tokens.ts"; |
| 21 | 21 | import { createUser, type User } from "../src/core/users.ts"; |
| 22 | 22 | import { readFeed } from "../src/feed/feed.ts"; |
| 23 | import { parseReleaseSubject } from "../src/core/release_subject.ts"; | |
| 23 | 24 | import { serve, type Servers } from "../src/http/server.ts"; |
| 24 | 25 | import { promote } from "./helpers/members.ts"; |
| 25 | 26 | |
| @@ -358,6 +359,39 @@ describe("home is the feed", () => { | ||
| 358 | 359 | expect(after).not.toContain("ancient musing"); |
| 359 | 360 | }); |
| 360 | 361 | |
| 362 | test("a release post names its version and the pulls it carries, and links its commit", async () => { | |
| 363 | const oid = "ab".repeat(20); | |
| 364 | const release = parseReleaseSubject("Release 0.7.251: Dialog is a component (#5512);Text utilities are named (#5550)")!; | |
| 365 | expect(release).toEqual({ version: "0.7.251", pulls: ["Dialog is a component", "Text utilities are named"] }); | |
| 366 | expect(parseReleaseSubject("Fix a thing (#1)")).toBeUndefined(); | |
| 367 | app.bus.append({ | |
| 368 | kind: "app.serving", | |
| 369 | repoId: garden.id, | |
| 370 | actorId: alice.id, | |
| 371 | payload: { app: "garden", env: "production", commitOid: oid, version: release.version, pulls: release.pulls }, | |
| 372 | }); | |
| 373 | const words = "0.7.251 is serving: Dialog is a component and 1 more"; | |
| 374 | const link = `/alice/garden/commit/${oid}`; | |
| 375 | const page = await get("/", aliceCookie).then((r) => r.text()); | |
| 376 | expect(page).toContain(words); | |
| 377 | expect(page).toContain(`href="${link}"`); | |
| 378 | const token = createToken(app.db, alice.id, "ro", "ro").token; | |
| 379 | const res = await fetch(`${servers.url}/mcp`, { | |
| 380 | method: "POST", | |
| 381 | headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${token}` }, | |
| 382 | body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "feed", arguments: { limit: 50 } } }), | |
| 383 | }); | |
| 384 | const items = JSON.parse(((await res.json()) as any).result.content[0].text).items as any[]; | |
| 385 | const post = items.find((i) => i.what === words); | |
| 386 | expect(post?.link).toBe(link); | |
| 387 | }); | |
| 388 | ||
| 389 | test("a release event with no version keeps today's words", () => { | |
| 390 | app.bus.append({ kind: "app.serving", repoId: garden.id, actorId: alice.id, payload: { commitOid: "cd".repeat(20) } }); | |
| 391 | const plain = readFeed(app.db, alice, { limit: 50 }).items.find((i) => i.what === "a new version is serving"); | |
| 392 | expect(plain?.link).toBe("/alice/garden"); | |
| 393 | }); | |
| 394 | ||
| 361 | 395 | test("the MCP feed answers the same posts, page by page", async () => { |
| 362 | 396 | const token = createToken(app.db, alice.id, "ro", "ro").token; |
| 363 | 397 | const call = async (args: unknown) => { |
test/release-subject.test.ts added +22
| @@ -0,0 +1,22 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import { parseReleaseSubject, releaseFields, releaseServed } from "../src/core/release_subject.ts"; | |
| 3 | ||
| 4 | const SUBJECT = "Release 0.7.251: Dialog is a component (#5512);Text utilities are named (#5550)"; | |
| 5 | ||
| 6 | describe("the release an app.serving payload carries", () => { | |
| 7 | test("a production release commit yields version and pulls", () => { | |
| 8 | const r = releaseServed("production", SUBJECT); | |
| 9 | expect(releaseFields(r)).toEqual({ version: "0.7.251", pulls: ["Dialog is a component", "Text utilities are named"] }); | |
| 10 | }); | |
| 11 | ||
| 12 | test("a preview, a non-release commit, or an unreadable log yields none", () => { | |
| 13 | expect(releaseFields(releaseServed("5831", SUBJECT))).toEqual({}); | |
| 14 | expect(releaseFields(releaseServed("production", "Fix a thing (#1)"))).toEqual({}); | |
| 15 | expect(releaseFields(releaseServed("production", undefined))).toEqual({}); | |
| 16 | }); | |
| 17 | ||
| 18 | test("a semicolon inside a title does not split it", () => { | |
| 19 | const r = parseReleaseSubject("Release 1.2.3: Add a; b (#1);Other (#2)")!; | |
| 20 | expect(r.pulls).toEqual(["Add a; b", "Other"]); | |
| 21 | }); | |
| 22 | }); |
new above
offline
This is the new behaviour with no test. Cover production vs preview vs non-release subject, and the commitLog failure path.