Public: anyone can read this; the crew can change it.

Production's /api/v1/changelog reports the live version 1.0.0 and lists its releases #15598

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15585-production-s-api-v1-changelog-reports-th → main 0 commits fork 3 threads · 3 unresolved

  • Merged. scout/15585-production-s-api-v1-changelog-reports-th was merged into main as d1fb0b7.

Review

Sign in to review this change.
6 files changed +47 −10
src/http/api/forge_origin.ts +1 −3
@@ -14,14 +14,12 @@
1414 import { listReposByOwner, visibleReposMarker, type Repo } from "../../core/repos.ts";
1515 import type { Ctx, Handler } from "../context.ts";
1616 import { limitRefusal, limitSays, pageRefusal, parseLimit, parsePage } from "../../contract/page_query.ts";
17 import { FORGE_API_VERSION } from "../../kernel/version.ts";
1718 import { holds, weakEtag } from "../etag.ts";
1819 import { json, unauthorized } from "../respond.ts";
1920 import type { Router } from "../router.ts";
2021 import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts";
2122
22 /** The Gitea API generation this answers: the calls above, and no more. */
23 export const FORGE_API_VERSION = "1.0.0";
24
2523 const PAGE_MAX = 100;
2624 const OWNED_MAX = 1000;
outdated

Importing a name and then re-exporting it keeps an alias that is not needed. Point the remaining importers at kernel/version.ts and drop the re-export, or keep a single export ... from.

2725
src/kernel/version.ts +16
@@ -89,3 +89,19 @@ export function announcedVersion(r: Running = running()): string | null {
8989 * known.
9090 */
9191 export const announcedOr = (r: Running = running()): string => announcedVersion(r) ?? "unreleased";
92
93 /**
94 * The version `GET /api/v1/version` answers, and what the changelog says when the build names no
95 * release.
96 */
97 export const FORGE_API_VERSION = "1.0.0";
98
99 /**
100 * The release a build names (`release`, null when none) and the version a probe is told
101 * (`version`, never null: the API generation when the build names none), so the changelog's two
102 * fields come from one place and cannot drift apart (#15585).
103 */
104 export function releaseNamed(r: Running = running()): { release: string | null; version: string } {
105 const release = releaseOf({ version: r.version, commit: r.commit });
106 return { release, version: releaseOf(r) ?? FORGE_API_VERSION };
107 }
src/release/answer.ts +4 −3
@@ -9,7 +9,7 @@ import { listPublicReleases } from "../core/app_releases.ts";
99 import { getRepoById } from "../core/repos.ts";
1010 import { publicForgeRepo } from "../core/forge_repo.ts";
1111 import type { User } from "../core/users.ts";
12 import { releaseOf, running, shortOf } from "../kernel/version.ts";
12 import { releaseNamed, running, shortOf } from "../kernel/version.ts";
1313 import { BOOTED, mayRead } from "./gate.ts";
1414 import { withWaves } from "./chapter_waves.ts";
1515 import { chapterEntries, groupByChapter, wavesOf } from "./chapter_groups.ts";
@@ -73,8 +73,9 @@ export async function shippedAnswer(app: App, asked: string | null = null) {
7373 const tags = tagged === undefined ? [] : await publicTagReleases(app, tagged);
7474 const waves = wavesOf(groupByChapter(live, await withWaves(app, chapterEntries(app.db, live, undefined))));
7575 return {
76 // The release number, or null for a build that is not one: never the word "dev".
77 version: releaseOf({ version: read.version, commit: read.commit }),
76 // `release` is what the build itself names, or null (the feeds name such a build by its
77 // commit); `version` is never null, so it says what /api/v1/version says (#15585).
78 ...releaseNamed({ ...running(), version: read.version, commit: read.commit }),
outdated

This line calls running() three times and builds the object twice, and it is over 150 columns. Compute const r = running() once. Better, add one releaseNamed() helper in kernel/version.ts, so that version and release cannot drift apart.

7879 commit: read.commit,
7980 short: read.commit === null ? null : shortOf(read.commit),
8081 liveSince: BOOTED,
src/web/feeds.ts +2 −2
@@ -309,9 +309,9 @@ export async function changelogAtom(ctx: Ctx): Promise<Response> {
309309 const own = `${ownerName}/${repoName}`;
310310 // A build with no version stamp is named by its commit, as /changelog names it (#15482): the
311311 // generator carries it, and the tag changes with it so a cached feed never outlives a release.
312 const named = answer.version ?? answer.short;
312 const named = answer.release ?? answer.short;
313313 const alone = live.length === 0 && releases.length === 0 && answer.commit !== null;
314 const etag = changelogTag(answer.version ?? answer.commit ?? "dev", live, [
314 const etag = changelogTag(answer.release ?? answer.commit ?? "dev", live, [
315315 tip,
316316 releases.map((r) => [r.repo, r.version, r.commit, r.servedAt, r.subject]),
317317 alone ? answer.liveSince : "",
test/changelog-api.test.ts +23 −1
@@ -73,7 +73,9 @@ describe("GET /api/v1/changelog", () => {
7373 expect(res.status).toBe(200);
7474 const b: any = await res.json();
7575 expect(b.commit).toBe("a".repeat(40));
76 expect(b.version).toBeNull();
76 expect(b.version).toBe("1.0.0");
77 const v: any = await (await fetch(`${servers.url}/api/v1/version`)).json();
78 expect(b.version).toBe(v.version);
7779 expect(b.short).toBe("aaaaaaa");
7880 expect(new Date(b.liveSince).toISOString()).toBe(b.liveSince);
7981 const row = [...b.live, ...b.onItsWay][0];
@@ -125,6 +127,26 @@ describe("GET /api/v1/changelog", () => {
125127 }
126128 });
127129
130 test("a 500-entry release record lists its newest 50, 1.0.0 among them with its date", async () => {
131 const repo: any = app.db.query("SELECT id FROM repo WHERE name = 'forge'").get();
132 const ins = app.db.query(
133 `INSERT INTO app_release (id, repo_id, version, commit_oid, subject, note, tests, serving_ms, served_at) VALUES (?1, ?2, ?3, ?4, 's', '', 'none', NULL, ?5)`,
134 );
135 try {
136 for (let n = 0; n < 500; n++) {
137 const version = n === 0 ? "1.0.0" : `0.${n}.0`;
138 // 1.0.0 is dated 2026-11-20, later than every other row (all in 2026-01..09).
139 ins.run(`r${n}`, repo.id, version, "c".repeat(40), n === 0 ? "2026-11-20T10:00:00.000Z" : `2026-0${1 + (n % 9)}-01T00:00:00.000Z`);
140 }
141 const b: any = await (await get("")).json();
142 expect(b.version).not.toBeNull();
143 expect(b.releases.length).toBe(50);
outdated

This comment is stale: nothing makes 1.0.0 the newest here beyond the dates. Also DELETE FROM app_release runs only if the assertions pass, so a failure leaks 500 rows into later tests. Use try/finally or an afterEach. The took < 500 assertion is wall-clock and can flake (see the review body).

144 expect(b.releases.find((r: any) => r.version === "1.0.0")?.servedAt).toBe("2026-11-20T10:00:00.000Z");
145 } finally {
146 app.db.query("DELETE FROM app_release").run();
147 }
148 });
149
128150 test("MCP releases returns the same rows", async () => {
129151 for (const repo of ["all", "alice/notes"]) {
130152 const viaMcp = await mcp({ shipped: true, repo }, admin);
test/version-etag.test.ts +1 −1
@@ -6,7 +6,7 @@ import { join } from "node:path";
66 import { createApp, type App } from "../src/app.ts";
77 import { createToken } from "../src/core/tokens.ts";
88 import { createUser } from "../src/core/users.ts";
9 import { FORGE_API_VERSION } from "../src/http/api/forge_origin.ts";
9 import { FORGE_API_VERSION } from "../src/kernel/version.ts";
1010 import { weakEtag } from "../src/http/etag.ts";
1111 import { serve, type Servers } from "../src/http/server.ts";
1212

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs