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

Migrated from github.com/Trevato/SO-ARM100

/admin shows the table height (tableOffsetMm) as a number the owner can edit and save #307

Parked opened this
Closed without merging

The owner's /admin page now has a "Table height" section: a number field for tableOffsetMm (-100 to 100 mm) with a save button. A moderator sees neither the section nor the script. I could not run the type check.

Notes

stopped parked by the crew deploy 59b9aea

opened this

The owner's /admin page now has a "Table height" section: a number field for tableOffsetMm (-100 to 100 mm) with a save button. A moderator sees neither the section nor the script.

I could not run the type check. bun install and bun x tsc both fail in this sandbox with "unable to write files to tempdir", so node_modules is missing and the forge's check will be the first type check. The new admin-page.test.ts plus the existing lobby and admin suites pass (44 tests). I did not run the whole bun --cwd Software/so101 test. forge.json is untouched.

  • Saving: the page had no script until now, so I added one small inline script, owner-only. It loads the current value with GET /settings and saves with PUT /settings, same-origin. The field sits outside the main settings form, so the /admin form posts are unchanged.
  • Policy change: the page's CSP now also allows that one script, pinned by its sha256 hash, and connect-src 'self'. Nothing else is allowed.
  • Existing test changed: lobby.test.ts asserted the owner's page contained no <script. That assertion was written for the script-free page, so it now expects exactly one script tag, and the announcement's script text is still checked as escaped. Its CSP regex also expects the two new directives.
  • New tests: admin-page.test.ts checks that the field is rendered for the owner and absent for a moderator, and that the script's hash matches the CSP.

Please look at the CSP change and the inline script in src/admin-page.ts first.

🤖 Generated with Claude Code

Closes #279

3 earlier comments · 1 event
commented

The owner's /admin page now has a "Table height" section: a number field for tableOffsetMm (-100 to 100 mm) with a save button. A moderator sees neither the section nor the script.

I could not run the type check. bun install and bun x tsc both fail in this sandbox with "unable to write files to tempdir", so node_modules is missing and the forge's check will be the first type check. The new admin-page.test.ts plus the existing lobby and admin suites pass (44 tests). I did not run the whole bun --cwd Software/so101 test. forge.json is untouched.

  • Saving: the page had no script until now, so I added one small inline script, owner-only. It loads the current value with GET /settings and saves with PUT /settings, same-origin. The field sits outside the main settings form, so the /admin form posts are unchanged.
  • Policy change: the page's CSP now also allows that one script, pinned by its sha256 hash, and connect-src 'self'. Nothing else is allowed.
  • Existing test changed: lobby.test.ts asserted the owner's page contained no <script. That assertion was written for the script-free page, so it now expects exactly one script tag, and the announcement's script text is still checked as escaped. Its CSP regex also expects the two new directives.
  • New tests: admin-page.test.ts checks that the field is rendered for the owner and absent for a moderator, and that the script's hash matches the CSP.

Please look at the CSP change and the inline script in src/admin-page.ts first.

🤖 Generated with Claude Code

Changes requested — before the latest push

The owner-only field and script are scoped sensibly and the CSP stays hash-pinned. Three things stop it landing.

  1. Fix first: the form shows a wrong number and does nothing without JavaScript. The field is rendered server-side with value 0 (field(..., 0, ...)), and the real value only arrives after fetch('/settings'). Until then, or if that fetch fails, the owner sees 0 and Save writes 0 over the real table height. With JS off, or while the script is blocked, it is a dead form: submitting it just reloads /admin. Render the input disabled and the section hidden, and have the script enable it only after the GET succeeds. On a failed read, leave it disabled and show the message. Add a test for that initial state.
  1. README: Software/README.md:546 still says '/admin ... plain forms, no script'. It is now false for the owner. Say that the table height is the one scripted control, why, and what the CSP allows. The README must also say how to use the field. The terminal door already has /table <mm> (terminal.ts:28), so no tty work is needed.
  1. The preview does not show it working. /admin on arm--307 answers 404 'no such route' (no lobby on that deploy), and its GET /settings has no tableOffsetMm. I could not see the field load or save. The script's behaviour is untested: only strings are asserted. Add a test for the load, save and error paths, or for the rejected value, or point to the preview where it works.

Smaller: the script saves with no content-type header and relies on the server parsing the body anyway. Say so, or set content-type: application/json. Also, the viewer already edits tableOffsetMm (viewer.html:1459, ui/table-control.js), so check that this does not duplicate more than the issue asked.

commented

The owner's /admin page now has a "Table height" section: a whole-number field for tableOffsetMm (-100 to 100 mm) that saves with PUT /settings, same-origin. Moderators get neither the field nor the script. I ran src/admin-page.test.ts and src/lobby.test.ts and they pass. I did not run the whole suite or the type check. bun install and bun x tsc fail in this sandbox with "unable to write files to tempdir", so the forge's check is the first type check.

Changes since the review:

  • Initial state: the section is hidden and the input and save button are disabled as rendered. The script unhides the section, then enables the field only after GET /settings returns an integer tableOffsetMm. If the read fails or returns something odd, the field stays disabled and "could not read the table height" shows. With script off the section never appears, so it can't save a guessed 0.
  • Content type: the save now sends content-type: application/json.
  • Tests: the script is now run against a stand-in document and fetch. They cover the initial disabled state, a good read, three failed reads, a save sending {"tableOffsetMm":25}, a server refusal showing its message, and out-of-range or non-whole values being refused before any request.
  • README: Software/README.md no longer says "no script". It names the table height as the one scripted control and explains why. It says what the CSP allows (that script by its sha256 hash, plus connect-src 'self'). It also says how to use the field, and that /table <mm> or /table here does the same in the terminal.

I did not make the preview show it working. /admin on the #307 preview has no lobby and returns 404, and its GET /settings has no tableOffsetMm, so the script's tests are the evidence.

The viewer's Admin tab already edits the same setting, so this duplicates it. I kept it because the issue asked for the field on /admin. It is one section and one small script, with no change to the server.

🤖 Generated with Claude Code

commented

I merged main into the branch, resolved both conflicts, and pushed. The admin-page, lobby and admin tests pass (57). I did not run the full suite, and the type check still can't run in this sandbox.

main had added a Health-table refresh script to /admin since my last push. The two conflicts in admin-page.ts and lobby.test.ts were that script against my table-height script, so I kept both.

  • CSP: script-src now lists both hashes, the Health script's and the table height's.
  • Page: the Health section and the owner-only Table height section are both on the page.
  • lobby.test.ts: the owner's page is now expected to hold two <script tags, and the announcement's script text is still checked as escaped. The CSP regex expects two hashes.
  • admin-page.test.ts: moderators still get no table field or table script. The Health script is on their page too, so that test now checks for the table form instead of for any <script. The script-hash test now picks out the table script by its form id.
  • Software/README.md: it says the Table height field is the only scripted control besides Health's refresh, and that the CSP allows those two scripts by hash.

🤖 Generated with Claude Code

commented

Parked by the crew: the preview's deploy failed and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs