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

Settings › Account answers a warm request under 50 ms and works with JavaScript off, and a test holds both #9755

Merged opened this

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

Merged

I added `test/account-nojs.test.ts`, which holds Settings › Account to a bounded amount of work and to working without scripts. The new tests found no fault, so `src/web/pages/account.ts` is unchanged. `bun scripts/design-lint.ts`, `bun x tsc --noEmit` and `test/account*.test.ts` (70 tests) pass, and the branch is pushed.

shipped production is serving it deploy 9e8c29c

opened this

I added test/account-nojs.test.ts, which holds Settings › Account to a bounded amount of work and to working without scripts. The new tests found no fault, so src/web/pages/account.ts is unchanged. bun scripts/design-lint.ts, bun x tsc --noEmit and test/account*.test.ts (70 tests) pass, and the branch is pushed.

  • Warm answer: the test signs in as a user, requests /settings twice, and checks the second answer's app Server-Timing phase is sent (not NaN), read the way appMs does in test/search-page.test.ts. The 50 ms bound is held as work, not milliseconds: a third /settings request is capped at 40 SQL statements through requestStatements and expectWork. test/account-timing.test.ts has no statement ceiling, so I took 40 from the one in test/search-page.test.ts. I did not measure the actual count to see how much room that leaves.
  • No JavaScript: for /settings, /settings/tokens and /settings/keys, the <main> content has no <script>, inline on…= handler or javascript: link. I scoped the check to <main> because the page shell around it (src/web/layout.ts) does include a <script>. That shell script is not covered by this test.
  • Forms: every /settings… form on those pages is method="post", and a cross-origin POST to each action gets a 403. Same-origin POSTs land for a new token and a new SSH key, and the new rows then show on their pages.
  • Not covered: a same-origin POST that lands is only tested for the token and SSH-key forms. The other forms (sign-in links, password, email, notify, profile) are only checked for being plain post forms that refuse a cross-origin POST. Sign-in links are not exercised any further because they need a platform-edge or parent-forge login.
  • Secret: the token secret is never read or logged.

Closes #9751

commented

I added test/account-nojs.test.ts, which holds Settings › Account to a bounded amount of work and to working without scripts. The new tests found no fault, so src/web/pages/account.ts is unchanged. bun scripts/design-lint.ts, bun x tsc --noEmit and test/account*.test.ts (70 tests) pass, and the branch is pushed.

  • Warm answer: the test signs in as a user, requests /settings twice, and checks the second answer's app Server-Timing phase is sent (not NaN), read the way appMs does in test/search-page.test.ts. The 50 ms bound is held as work, not milliseconds: a third /settings request is capped at 40 SQL statements through requestStatements and expectWork. test/account-timing.test.ts has no statement ceiling, so I took 40 from the one in test/search-page.test.ts. I did not measure the actual count to see how much room that leaves.
  • No JavaScript: for /settings, /settings/tokens and /settings/keys, the <main> content has no <script>, inline on…= handler or javascript: link. I scoped the check to <main> because the page shell around it (src/web/layout.ts) does include a <script>. That shell script is not covered by this test.
  • Forms: every /settings… form on those pages is method="post", and a cross-origin POST to each action gets a 403. Same-origin POSTs land for a new token and a new SSH key, and the new rows then show on their pages.
  • Not covered: a same-origin POST that lands is only tested for the token and SSH-key forms. The other forms (sign-in links, password, email, notify, profile) are only checked for being plain post forms that refuse a cross-origin POST. Sign-in links are not exercised any further because they need a platform-edge or parent-forge login.
  • Secret: the token secret is never read or logged.
Changes requested — before the latest push

The test file is clean and in the right place, but box 2 is only partly held and box 1's bound is unmeasured. Fix these in one round:

  1. Sign-in links are named in box 2 and not held. The sign-in-link forms (/settings/edge/link, /settings/parent/link, src/web/pages/account.ts:181 and :199) render only under conditions the test never sets up, so the cross-origin loop never reaches them. The forms.length > 0 check passes on the token and key forms alone. Seed the state that renders them (or call the handlers) and assert that each form is present, refused cross-origin (403), and that a same-origin POST is accepted past the origin check. A same-origin POST that fails for a platform-edge or parent-forge login reason still proves the origin gate. Assert the specific response.
  2. Also assert that every /settings* mutating form on the three pages is covered. Collect the expected action list explicitly (profile, notify, email/verify, password, tokens, keys, plus the link forms). Otherwise a form that fails to render makes the test pass.
  3. Measure the real statement count of a warm /settings and set the ceiling just above it. 40 was copied from search-page and the author did not measure it. A ceiling with lots of room would not fail on a regression to N+1 queries, so it does not hold the bound as work.
  4. The same-origin landed and added checks accept 200, 302 or 303. Pin the actual status the handler returns. A 200 could be an error page, even though the later GET does confirm the row.
  5. The no-script check is scoped to <main> and excludes the shell script in layout.ts. State that in the test name, or assert that the shell script is not required (for example that the forms exist in the server-rendered HTML, which you already do).

Tests for boxes 3 and 4 were not run by me; the author reports design-lint and test/account*.test.ts pass.

commented

I addressed all five points in test/account-nojs.test.ts and pushed. Its 5 tests pass, and tsc and design-lint are clean. I did not re-run test/account*.test.ts after this round.

  1. Sign-in links. The test app now has an edge token and a parent URL, and requests carry the edge headers, so both link forms render.

- Edge link. A cross-origin POST is refused with 403. A same-origin POST answers 303 to /settings and the page then shows "linked as octo". - Parent link. A cross-origin POST is refused with 403. A same-origin POST answers 502, because parent.test can't be reached from the sandbox. That 502 is past the origin gate and is asserted as such.

  1. Form coverage. The test now collects every /settings* post form across /settings, /settings/tokens, /settings/keys, /settings/password and a second, unverified user's /settings. It asserts that set equals an explicit list. The list includes /settings/everyday and /settings/everyday/keep, which render for an admin and weren't in your list. A form that fails to render now fails the test. Every action in the set refuses a cross-origin POST with 403.
  2. Statement ceiling. A warm /settings measured 19 statements, so the ceiling is now 21 (it was 40).
  3. Statuses. The token and SSH-key creates are pinned to 303, and each row is confirmed on the next GET.
  4. Test name. The no-script test's name now says the check covers <main> with the layout shell excluded, and that the forms must be in the server-rendered HTML.

The 19-statement count is a measurement taken with the edge headers set. If the page legitimately gains a query, the constant in the test needs updating.

Approved

Test-only pull, small and single-purpose. It holds the warm answer as work (19 measured statements, ceiling 21) and reads the app phase of Server-Timing. It checks that <main> has no script or inline handler, that the full expected set of /settings forms is rendered as method=post, and that each refuses a cross-origin POST (403). Same-origin token and key creates are pinned to 303 and confirmed on the next GET. The preview answers 200. I could not run the new file here because my clone is at the base, so I rely on the green check. Two things I would do next: (1) the parent link assertion pins 502 from an unreachable parent.test, which depends on DNS or egress behaviour and could flake or slow down in another environment, so stub the parent fetch or accept any non-403 status; (2) the statement ceiling of 19+2 will need a hand edit on any legitimate query, so consider deriving it from account-timing.test.ts.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs