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

On a preview, the forge toolbar's 'Home' returns to the previewed app's own page on the forge, not the forge's front page #15670

Merged opened this

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

Merged

The toolbar's "Home" link now goes to the app's page on the forge. On a pull preview it goes to that pull's page instead. The toolbar size test, tsc, scripts/gate.ts --fix and the toolbar tests I ran all pass, but I did not load a real preview to click it.

Notes

shipped production is serving it deploy 496afdb

opened this

The toolbar's "Home" link now goes to the app's page on the forge. On a pull preview it goes to that pull's page instead. The toolbar size test, tsc, scripts/gate.ts --fix and the toolbar tests I ran all pass, but I did not load a real preview to click it.

  • Where it goes:
    • On a pull preview, Home goes to <forge>/<repo>/pulls/<n>.
    • On production, Home goes to <forge>/<repo>.
    • The link is built from the stored data-repo, data-pull and data-forge values. It never uses the Host header or the page's own origin.
  • Fallback: a page with no repo id, or a malformed one such as a/b/c, still gets the old behaviour. Home then goes to the same-origin forge referrer, or to the forge's /.
  • Change: a few lines in src/apps/toolbar.ts, with no new script and the toolbar size test still green.
  • Tests: three new cases in test/toolbar-back.test.ts check the production href, the preview href, and the malformed-repo fallback. The preview case sets the page host to a foreign origin, so it fails if the link were built from the page's host.
  • Not done:
    • On a preview, the "Pull #N" link and Home now point to the same page. I left the "Pull #N" link alone because it carries the check word and title.
    • The existing repo-id pattern accepts ../x. The URL resolves it to /x, which is still on the forge's origin, so I did not tighten it.

Review:

[
  {"go": "https://lab--15657--forge-trevato-apps.open-platform.sh/", "look": "open the forge pill and read the Home link's address", "expect": "it ends in /<repo>/pulls/15657"},
  {"go": "https://lab--forge-trevato-apps.open-platform.sh/", "look": "open the forge pill and read the Home link's address", "expect": "it ends in /<repo>, the app's page on the forge"}
]

🤖 Generated with Claude Code

Closes #15657

Show 2 earlier items

7 earlier comments · 1 event
commented

The toolbar's Home link goes to the app's page on the forge, and to the pull's page on a preview. It builds the address from the stored repo and pull ids. The referrer is used only when a page carries no ids.

The failing "pill's script" test failed because my last refactor dropped the check that the built Home address is on the forge's origin. I put the check back in src/apps/toolbar.ts, and Home is set only when the origin matches. The assertion in test/apps-toolbar.test.ts that Home's href is set before it is appended went back to its original form.

The pill, toolbar, back, lost-journey, spawn-reach and changelog-chapters tests pass here (90 tests), and tsc is clean.

I did not touch the other two failures from the check. The #13794 reach-door test and the 500-pulls chapters budget test don't touch this code, and the first reads like a timing budget on a loaded shard. Both pass in the targeted run. If they fail again on the next full check, they need their own look.

gate.ts still reports that homeFor and homeHref in test/toolbar-back.test.ts look like one implementation, and I left that as is.

To try it, open a preview of a pull and open the pill. Home should land on the pull's page on the forge.

commented

The toolbar's Home link now goes to the app's page on the forge, and to the pull's page on a preview. The failing byte-budget test, "the addition stays under 300 bytes", now passes.

The script was 5 bytes over its allowance. Comments are stripped from the shipped script, so shortening the comment I tried first changed nothing, and that push was also red. The fix that counted was dropping the || "" fallback from three RE.test(d.repo) calls. A missing repo id still fails the pattern, so Home behaves as before.

The toolbar state, pill, toolbar and lost-journey tests pass here, and tsc is clean. I did not touch the other two failures from the check ("past its deep budget an address gets 429…" and "a reload's first size redraws the screen…"). Neither is in code this change reaches, and the "pull's red" line in the log named only the toolbar-state test. If they fail again on the next full check, they need their own look.

Home takes the repo and pull ids the toolbar already holds. It falls back to the referrer only on a page that carries no ids. The built address is still accepted only if it is on the forge's origin.

To try it, open a preview of a pull and open the pill. Home should land on the pull's page on the forge.

bun scripts/gate.ts still notes that homeFor and homeHref in test/toolbar-back.test.ts look like one implementation. I left that as is.

Changes requested — before the latest push

I opened the preview: it serves the forge front page with 200 and no layout problem, but the toolbar is injected into previewed apps, so I could not click Home there and judged it from the source and tests. Home now goes to the right place and the three new tests pin it. Three things to fix in one round:

  1. On a preview with a pull, Home and the Pull #N link now both go to the same page. Box 1 asks for one link to the app page (the pull page on a pull preview). Keep one: fold the check word and title into Home, or hide Home when the Pull link is shown.
  2. The repo pattern accepts ../x and ../.. , which resolve to /x or /. Tighten it to reject a segment made only of dots, and add a test with ../x.
  3. lost-journey no longer fetches Home on a preview; it only checks the path, and the stranger case skips the fetch too. Keep a fetch of the pull page, or make the fixture answer 200 for it.
commented

On a pull preview, the toolbar now shows one link to the pull's page. On production it still shows Home, which goes to the app's page on the forge. lost-journey, toolbar-back and toolbar-budget pass, and tsc is clean. I did not run the rest of the toolbar tests after this edit. bun scripts/gate.ts --fix left test/toolbar-back.test.ts with a comment line over 100 columns and a similarity note, and I did not address either.

  1. Duplicate links. I hid Home when the Pull #N link is shown, rather than folding the check word and title into Home. The Pull link already carries the check word and title, and it already had the comment box tied to it. If you'd rather keep a Home link and drop the Pull link instead, say so.
  2. Repo pattern. The pattern now rejects a segment made only of dots, so ../x, x/.., ../.. and ./x build no link. Production falls back to the referrer, and a preview shows no Pull link. toolbar-back.test.ts and lost-journey.test.ts each have a test for this.
  3. Journey test. The fixture's pulls now have a head row, so the pull page answers 200. The preview journey follows the Pull link for the owner and for a stranger. It also asserts that Home is absent on a preview and present on production. That fixture change made the "Newest preview" link appear, so the same-origin loop allows that app preview host, as it already does for "Open on production".

One test gap: the fake document in toolbar-back.test.ts doesn't record which elements get appended. The absence of Home on a preview is therefore asserted only in lost-journey.test.ts, not there.

To try it, open a pull preview's toolbar panel: it should show Pull #N once and no Home.

🤖 Generated with Claude Code

commented

I fixed the toolbar byte-budget failure and pushed, but I couldn't reproduce the three web-code failures, so they may still show red.

Byte budget. The check runs against the pull merged with main, and with main's 27 new commits the toolbar script came to 1851 bytes against a limit of 1850. I merged main into the branch and renamed one local in the Home code (target to tg) to save the bytes. apps-toolbar-state, toolbar-budget, toolbar-back and lost-journey now pass on the merged tree, and tsc is clean.

web-code failures. The three "code browser on the web" tests failed in shard 10 of the check. Run on its own, test/web-code.test.ts passes on the merged tree, so I couldn't reproduce them. This pull doesn't touch the code browser, and the log says only the toolbar test was re-checked on main. If they fail again, I'd treat them as a shard-order or flaky problem and look at that file next.

The pull description from my earlier message still stands. The only change since is the merge of main and the shorter local name.

🤖 Generated with Claude Code

commented

I fixed the two gate failures and pushed. The gate now exits 0 locally. tsc --noEmit is clean, and test/toolbar-back.test.ts and test/lost-journey.test.ts pass (25 tests). I did not re-run the forge's full check.

  • src/spawn/template_record.ts: my earlier gate --fix had rewrapped a comment this pull did not write. I restored the file to main, so it is no longer in the diff.
  • test/toolbar-back.test.ts: homeHref and homeFor each built the same fake document and ran the toolbar script. They now share one linkHref helper, and both functions are thin wrappers over it. The assertions are unchanged.

The gate still prints a note about a comment line over 100 columns in that test file. It does not fail the gate, and I left it because the nightly rewrap handles it on main.

commented

Two of the three failures came from my toolbar change, and I fixed both. I couldn't reproduce the third. I pushed the fix; the forge's check hasn't run on it yet.

  • Cause: in src/apps/toolbar.ts I had renamed the Home link's target variable to tg. test/apps-pill-where.test.ts and test/apps-toolbar.test.ts look for the literal strings target.origin === fo and link.href = target.href, so they failed. I put the target name back and left the tests alone, since they were right.
  • Third failure: "a writer queues a check and gets the run" in test/pull-check-again.test.ts passes locally. I treated it as a flake rather than something this pull caused.

Locally, tsc --noEmit, the gate and those two suites pass, as do test/toolbar-back.test.ts, test/lost-journey.test.ts and test/pull-check-again.test.ts (82 tests, 0 failures).

commented

The size test passes locally now; the forge's check hasn't run on the fix yet. I also pushed the previous commit while this test was still failing locally, which I shouldn't have done.

The toolbar script grew past the pinned 300-byte addition budget in test/apps-toolbar-state.test.ts. After merging main, which had raised that limit to 1900, the script measured 1920 bytes. Comments are stripped from the shipped script, so shortening mine had no effect. I did not golf the code, since the growth is the Home change this pull is for. I added a HOME_ALLOWANCE of 30 bytes, named and commented like the other allowances there.

With that, tsc --noEmit and the gate are clean. The size test and the toolbar tests (apps-toolbar, apps-pill-where, toolbar-back, lost-journey) pass, 78 in all.

commented

The three toolbar size tests were failing because the toolbar script came out a few bytes over its allowance. I pushed a fix, and the toolbar tests now pass locally (246 pass, 0 fail). tsc --noEmit is clean, and bun scripts/gate.ts --fix ran. The forge's own check on the push is still to come.

Home now builds its link from a stricter repo pattern, which added about 14 bytes on the wire and 6 raw over the limits. I didn't raise any limit. I took the bytes back inside src/apps/toolbar.ts with no change in behaviour:

  • Pattern: the repo pattern is now declared once as RE and reused, and its two lookaheads are merged into one.
  • Comment: I deleted the comment above the pull-link block.
  • Locals: I renamed two locals, pullHref to ph and cword to cv.

I left target and hasHome as they are, because test/apps-toolbar.test.ts looks for those exact strings in the script.

The gate also notes one comment line over 100 columns in test/toolbar-back.test.ts. I didn't rewrap it, because the nightly rewrap does that on main.

To try it, open a preview and tap Home in the toolbar: it goes to the repo's page on the forge, or to the same-origin referrer where the app has one.

🤖 Generated with Claude Code

Approved

Earlier asks, all met in the diff since f87037502eeb: (1) one link on a preview, since Home is now hidden when the Pull #N link shows (hasHome = !ph) and lost-journey asserts it; (2) the repo pattern RE rejects dots-only segments (../x, x/.., ./x) and both toolbar-back and lost-journey test it; (3) the fixture pulls have a head row, so the journey follows the pull link to a 200 for owner and stranger. Links are built from stored ids against the forge origin, never the Host header, and the preview test sets a foreign page origin. Two things I would do next, both non-blocking: (a) tidy the odd assertion in the lost-journey dots test (/\/x$/.test(h) && !h.includes("/alice/")); assert the exact set of anchor hrefs instead; (b) fix the [ "Comment... spacing in the for-of, and give the fake document in toolbar-back.test.ts a record of appended children so Home absence on a preview is also asserted there.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs