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

A child forge reads its parent's releases over HTTPS and says how many it is behind #1728

Closed opened this
Closed without merging

A child forge now reads its parent's releases and shows "N releases behind " on the following card. bun test test/following.test.ts passes (22 tests) and tsc --noEmit is clean. I did not run the forge's full check.

Notes

stopped closed without shipping deploy 42608fb

opened this

A child forge now reads its parent's releases and shows "N releases behind <parent>" on the following card. bun test test/following.test.ts passes (22 tests) and tsc --noEmit is clean. I did not run the forge's full check.

  • Configuration: FORGE_PARENT_URL is checked at boot by parentUrlProblem. It must be https and carry no credentials or query. If it's wrong, boot exits with the reason. Unset, nothing changes.
  • Fetch and cache: src/core/parent_releases.ts fetches <parent>/releases.json with a 3 s timeout, no redirects and a 256 KB cap. The expected shape is {"releases":[{"name","url"}]}, newest first. Entries with a bad name or a non-http(s) link are dropped. The result is cached in FORGE_APP_DATA/parent-releases.json for 10 minutes. A failed try is not repeated for a minute.
  • Parent down: the read never throws. A down parent, a 500 or garbage leaves the page up. It shows the last good copy with its age ("a copy from 3 hours ago"), or "could not be reached" when there is no copy.
  • Page: src/web/pages/following.ts adds releasesBlock to the following card. It lists each release newer than this forge's running version, with its name and link, and html escapes every field. If the running version isn't in the parent's list (for example dev), every listed release counts as behind.
  • Tests: test/following.test.ts is already in GATE, so no gate change was needed. A fake parent on a loopback port gives the count of 2, and the test checks escaping and that a javascript: link is dropped. It also covers cache reuse, a 500 with a stale copy and its age, garbage, and no copy at all. A small URL-validation test is added too. The loopback test uses a parentLoopback config flag to allow http; boot never sets it.

Left out, so look at these:

  • No /releases.json route on the parent: I did not add one, because adding a route would touch the API contract. Until a parent serves that document, a child shows "could not be reached". A follow-up should publish it, probably from src/core/releases.json, which today has no links.
  • Where it shows: the block appears on the card of a repo that is a fork, not on every page of the forge.
  • No dependencies added.
  • No way to take a release: this change is read-only.

Closes #1569

3 earlier comments · 2 events
Changes requested — before the latest push

The web path is careful: https only, no redirects, a 3s timeout, a byte cap counted from the stream, a cache with a stale copy and its age, escaped output, and a test that covers down and garbage parents. Three misses against the list.

  1. Both doors: the releases-behind line exists only on the web following card. The terminal/TUI (src/tui) shows nothing of it, so what a person sees on the page they cannot see in the terminal. Fix first: surface the same sentence (N releases behind host, or 'could not be reached; copy from X ago') in the terminal's repo/following view, built from the same readParentReleases and releasesBehind, with a test.
  2. README: FORGE_PARENT_URL is not documented anywhere (README, docs/FOLLOWING.md). Add what it is, that it must be https, that the parent serves /releases.json as {releases:[{name,url}]} newest first, and the 10-minute cache.
  3. Rendering blocks on the network: followingOf awaits the fetch in the request path, so once the cache expires a slow parent adds up to 3s to a page view (every view when no copy exists, then once a minute). Refresh in the background and render the cached copy immediately, or at least cut the timeout to well under the 50 ms budget's spirit.

Smaller: releasesBehind returns releases.length when the running version is not in the list, saying 'N releases behind' for a forge that is simply on an unknown or newer build; say 'version not in the parent's list' instead. Also drop the kept.fetchedAt! non-null assertion by narrowing once. The preview shows nothing without FORGE_PARENT_URL set, so it could not demonstrate the feature by eye.

commented

I addressed all three points and the smaller ones in d4362ab7. bun test test/following.test.ts passes (23 tests) and tsc --noEmit is clean. I did not run the forge's full check.

  • No network in the request path. parentReleases reads only the cache. If the copy is older than 10 minutes, or there is none and no try in the last minute, it starts one background refresh per cache. The page renders the old copy immediately and the next view shows the new one.
    • With no copy yet, the first view says "Checking <host> for releases…". A test shows that view returns in under 250 ms while the fake parent takes 300 ms to answer.
  • Terminal. The About card (I) in src/tui/screens/about.ts now has a "releases" row for a fork when parentUrl is set. The web card and the terminal build the sentence from the same releasesSentence and the same cache. A test covers it.
  • Docs. README and docs/FOLLOWING.md now document FORGE_PARENT_URL:
    • what it is, and that it must be https;
    • the /releases.json shape, newest first;
    • the 10-minute cache and the background refresh.
  • Unknown version. releasesBehind returns undefined when the running version isn't in the list. The sentence then reads "This version (X) is not in <host>'s list of releases." and no releases are listed as behind. A test covers it.
  • Non-null assertion. The kept.fetchedAt! assertion is gone.

Not changed:

  • Preview: it will still show nothing unless FORGE_PARENT_URL is set in its environment. forge.json has no per-preview env, and I didn't want to invent one.
  • Parent route: this forge still doesn't publish /releases.json itself; the README says so.
  • TUI placement: the terminal has no following view, so I put the sentence in the About card.
Changes requested — before the latest push

The caching and bounded read are well done: no network in the request path, escaped output, 3 s timeout, 256 KB cap by bytes read, no redirects, https-only links, and the terminal About card now gets the same sentence. Two things block it.

  1. Fix first: the README edit splits the Turnstile/trusted-proxies paragraph. The new FORGE_PARENT_URL paragraph is inserted mid-paragraph, so "Behind a proxy, FORGE_TRUSTED_PROXIES ..." now reads as part of the parent-releases section. Move the new paragraph after the proxy paragraph and remove the trailing space after "not checked.".
  2. It cannot be seen working. The preview has no FORGE_PARENT_URL, so the card shows nothing, and this forge does not publish /releases.json, so no forge can feed it. Done means reachable and seen by eye. Add the smallest thing that makes it visible: serve /releases.json from this forge (read-only), or set FORGE_PARENT_URL for the preview, and say which in the pull.

Smaller: settled() is a test-only export in production code; ctx.app.config.parentUrl! in releasesBlock could take the url as an argument. The terminal shows the count but not the release names; say so in the README.

commented

I changed the three review items and pushed 1ea0e4ac. A preview still shows nothing by itself, because I did not set FORGE_PARENT_URL for it. The tests in test/following.test.ts and test/standards.test.ts pass, plus check-list, api-errors, schema-additive, hollow and the contract tests. tsc --noEmit is clean, and I did not run the forge's full check.

  • Visible: this forge now serves a public, read-only GET /releases.json from src/core/releases.json. It returns {releases:[{name,url}]}, newest first. Each link points at the document itself with the version as a fragment, because there is no page per release.
    • test/standards.test.ts checks that the document parses with the same reader a child uses.
    • To see it, start a child with FORGE_PARENT_URL=<this forge's https URL>.
  • README: the FORGE_PARENT_URL paragraph now sits after the proxy paragraph, so the Turnstile and trusted-proxies text is whole again, and the trailing space is gone. It now says this forge publishes /releases.json and that the terminal shows the count, not the release names. docs/FOLLOWING.md has the same wording.
  • Smaller items: settled() is no longer exported from production code; the tests poll the cache file instead. releasesBlock takes the URL as an argument.
  • Fix found on the way: release links with a #fragment were being rejected by the https-only URL check that also guards the parent URL. They now get their own check: http(s) only (http only in loopback tests), no credentials, fragments allowed.

Left out: I did not set FORGE_PARENT_URL on the preview, because forge.json has no per-preview environment and I did not want to invent one. Setting it on a preview or child is a deploy setting for you to choose.

commented

I merged main into this branch and pushed it. The only conflicts were in src/app.ts and src/main.ts, and I kept both sides in each.

  • src/app.ts: ForgeConfig now has parentUrl and parentLoopback from this pull, plus releasesKeep from main.
  • src/main.ts: both imports stay, parentUrlProblem and releaseEnv. The releaseEnv spread that main added in createApp merged without conflict.

bun x tsc --noEmit is clean. I ran the tests whose file names matched "parent" or "releases". Two failed, and I did not investigate either:

  • the scaffolded app typecheck under strict settings;
  • the capacity admin test.

Neither touches the parent-releases code. I did not run the full bun test: it timed out here at 120 seconds. I also did not check whether those two fail on main, so the forge's check will show whether they do.

commented

Parked by the crew: the check failed ("reserved names > every top-level page of the forge is a reserved name") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs