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

Migrated from github.com/Trevato/SO-ARM100

/admin shows today's peak viewers and joins per hour for the last 24 h, owner only, kept under FORGE_APP_DATA across a restart #414

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

/admin now shows the owner a "Visitors" section: today's peak viewers and a 24-row text chart of joins per hour, oldest first. The counts are saved under FORGEAPPDATA and come back after a restart. The new test and the existing /admin and visitor-counts tests pass.

Notes

shipped merged

opened this

/admin now shows the owner a "Visitors" section: today's peak viewers and a 24-row text chart of joins per hour, oldest first. The counts are saved under FORGE_APP_DATA and come back after a restart.

The new test and the existing /admin and visitor-counts tests pass. The full bun test run had one failure, in the model-routes test in server.test.ts (it serves the model, its meshes and the vendored libraries). I didn't investigate it and I'm not sure why it fails here. I didn't run the suite on a clean checkout, so I can't say whether it fails without my change. bun x tsc --noEmit printed nothing. forge.json is unchanged.

  • Counting: the lobby feeds one VisitorCounts on every /live connect and disconnect. It saves to visitors.json at most once a minute, and again on close. bench/fake-serve.ts passes the file path.
  • Who sees it: only the owner. A moderator sees the page without the section, and anyone else still gets the existing 404. I used a text chart because the page's CSP pins its style by hash, so inline per-bar styles would be blocked.
  • Restart: I added VisitorCounts.clearHere(), which the lobby calls after loading the file. Live connections don't survive a restart, so without it here would stay above zero until reset. The peak and hourly counts are kept.
  • Test: src/admin-visitors.test.ts drives real /live sockets. It checks the owner sees the peak and 24 rows, a moderator and a plain user don't, and the counts survive a relay restart on the same data directory.

I couldn't run bun --cwd Software/so101 test as written. I ran bun test from inside Software/so101 instead.

🤖 Generated with Claude Code

Closes #399

4 earlier comments · 3 events
commented

/admin now shows the owner a "Visitors" section: today's peak viewers and a 24-row text chart of joins per hour, oldest first. The counts are saved under FORGE_APP_DATA and come back after a restart.

The new test and the existing /admin and visitor-counts tests pass. The full bun test run had one failure, in the model-routes test in server.test.ts (it serves the model, its meshes and the vendored libraries). I didn't investigate it and I'm not sure why it fails here. I didn't run the suite on a clean checkout, so I can't say whether it fails without my change. bun x tsc --noEmit printed nothing. forge.json is unchanged.

  • Counting: the lobby feeds one VisitorCounts on every /live connect and disconnect. It saves to visitors.json at most once a minute, and again on close. bench/fake-serve.ts passes the file path.
  • Who sees it: only the owner. A moderator sees the page without the section, and anyone else still gets the existing 404. I used a text chart because the page's CSP pins its style by hash, so inline per-bar styles would be blocked.
  • Restart: I added VisitorCounts.clearHere(), which the lobby calls after loading the file. Live connections don't survive a restart, so without it here would stay above zero until reset. The peak and hourly counts are kept.
  • Test: src/admin-visitors.test.ts drives real /live sockets. It checks the owner sees the peak and 24 rows, a moderator and a plain user don't, and the counts survive a relay restart on the same data directory.

I couldn't run bun --cwd Software/so101 test as written. I ran bun test from inside Software/so101 instead.

🤖 Generated with Claude Code

Changes requested — before the latest push

The Visitors section and the persistence look sound, and the owner-only gating is right (moderator sees no section, plain user gets 404). Three things block it.

  1. Fix first: the terminal door is missing. src/tty.ts has no way to see the peak or joins per hour, so the owner can see them on the page but not in the terminal. Add an owner-only read there that uses the same lobby.visitors.peakToday() and joinsPerHour(), refuses a guest and a moderator the way the page does, and add a test for it.
  2. No README says how to use it. Add a line about the Visitors section on /admin (owner only) and where the counts are kept.
  3. Nothing in the diff passes countsFile to a Lobby except bench/fake-serve.ts. I found no other Lobby construction under Software/so101/src, so I could not confirm that the real server keeps visitors.json under FORGE_APP_DATA. Wire it where the real Lobby is built, and make the test prove the default path, or say in the pull where it is wired.

Smaller points: the doc comment "One frame per window..." now sits above saveCounts instead of presenceChanged, so move it back. The test only asserts peak >= 1, so assert the exact peak from the sockets you opened. smith also reported an unexplained model-routes failure in server.test.ts, so run it on a clean checkout and say whether it is yours.

commented

The feedback is addressed and pushed. Type check is clean, and the tests I ran for this change pass (82 tests across the visitors, terminal, fake-serve, lobby and visitor-counts suites).

  • Terminal door: the owner can type /visitors and get today's peak and the 24 joins-per-hour numbers, oldest first. It sends a {"type":"visitors"} frame over /live, and the lobby answers from lobby.visitors.peakToday() and joinsPerHour(). A plain user and a moderator are refused with "only the owner can do that". A guest is refused too, but with "join to take part", because that check comes first. This is a refusal on /live, not the page's 404. src/terminal.test.ts covers the typed line and the printed answer. src/admin-visitors.test.ts covers owner, moderator, plain user and guest over a real socket.
  • README: Software/README.md has a "Visitors" bullet in the Admin section. It covers the owner-only section, /visitors, and that the counts live in $FORGE_APP_DATA/so101/visitors.json.
  • Wiring: bench/fake-serve.ts is the only place a Lobby is built for the real app, because forge.json's run is that script. I found no other construction under Software/so101/src other than in tests, and tests build Lobby without a countsFile, so they don't write visitors.json. A new test in src/fake-serve.test.ts starts the real script with FORGE_APP_DATA set, connects once, and checks that so101/visitors.json appears with a peak of 1.
  • Smaller points: the "One frame per window…" comment is back above presenceChanged. The peak assertion is now exact, using sockets that overlap: 3 for the page test, 2 for the /live test.
  • Model-routes failure: it also fails with my changes stashed and the commit checked out at 2b72f13, which is the base the branch started from. It is not mine, and I left it alone.

🤖 Generated with Claude Code

Changes requested — before the latest push

Security, both doors, tests and README are right: owner-only on the page, 404 for others, the /live frame refuses non-owners, /visitors in the terminal, counts persist under FORGE_APP_DATA. Two experience problems on the new chart (the owner's /admin is 404 without identity, so I read the source, not a rendered owner view).

Fix first: the bars are unreadable for a screen reader and overflow a 360px phone. Each row repeats a block character up to 30 times, so a screen reader reads "full block full block ..." 24 times, and 30 monospace glyphs plus the 5rem label column plus gaps is wider than 360px; the inherited ol li {overflow-wrap:anywhere} will wrap the bar into a ragged stack. Put the bar in a span with aria-hidden="true" and the count in its own visible span (so the number is the accessible text), cap the bar at about 16 blocks (or wrap the list in the existing .scroll), and use a label column that fits (e.g. 4rem, "now" for the last row).

commented

I changed the Visitors chart as you asked and pushed. Only the chart and its test changed. Type check is clean, and the admin-visitors and admin-page tests pass (7 tests). I haven't looked at a rendered owner view, so the 360px fit rests on the sizing change, not a screenshot.

  • Screen reader: each row's block run sits in <span aria-hidden="true">. The count is a separate visible <b>, so it is the only thing read aloud for the bar.
  • Width: bars are at most 16 blocks. The label column is 3.5rem with a .5rem gap. The row sets overflow-wrap: normal, so a bar won't break mid-run.
  • Labels: rows read -23h … -1h, then now for the current hour. I used -Nh instead of "Nh ago" because the longer label wouldn't fit the narrower column.
  • Test: src/admin-visitors.test.ts now expects 24 labelled rows (now or -Nh), the aria-hidden span, and no run longer than 16 blocks.

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed. The only conflict was Software/so101/src/lobby.ts, in two places, and I kept both sides each time:

  • Imports: both the node:fs import (for saving the visitor counts) and the new node:crypto import from main.
  • Socket close handler: both the visitor-count decrement and save, and main's guest release (if (seat.guest) this.release(seat.guest.id)).

Type check is clean and bun test gives 654 pass, 1 fail. The failure is the same model-routes test in server.test.ts that already fails on main.

🤖 Generated with Claude Code

Approved — before the latest push

Approved from the diff. I did not exercise the owner view on the preview, because it needs the forge-signed owner identity, which I do not have.

What I checked:

  • The Visitors section is owner-only. A moderator gets the page without it, and anyone else gets the 404.
  • The terminal has the same door: /visitors is refused for non-owners on /live, and /live is the only door to the counts.
  • The counts are numbers only, so there is nothing to escape.
  • The chart is plain HTML with no script. The bar runs are aria-hidden and the count is visible text, so a screen reader reads the count once.
  • The bars are at most 16 blocks wide, so they should fit a 360px phone.
  • The counts are saved atomically, at most once a minute and on close, to visitors.json under FORGE_APP_DATA.
  • Tests cover the owner page, the moderator, plain-user and guest refusals, a restart, and the real fake-serve writing the file.
  • The README is updated.

Two things to do next:

  1. Look at the owner view at 360px once, with the 24 rows and the -Nh labels, and confirm the rows read well and none of them wrap.
  2. The server.test.ts model-routes test already fails on main. Fix it in its own pull so the green check means something.
commented

I merged main into the branch again and pushed it. The only conflict was Software/so101/src/lobby.ts, in one place near the presence code.

  • Resolution: I kept both sides. My saveCounts and countsChanged stay, and so does main's new people() method. I only had to close countsChanged before people() began.
  • Checks: type check is clean. bun test gives 662 pass, 1 fail. The failure is the same model-routes test in server.test.ts that already fails on main, and it isn't from this change.

🤖 Generated with Claude Code

Approved

Approved. The owner gets a Visitors section on /admin: peak today plus 24 joins-per-hour rows, as plain server-rendered text with no script and no layout shift. The terminal has /visitors. The /live frame is owner-only (moderators and users get "only the owner can do that", guests get "join to take part"). The page hides the section from moderators and 404s everyone else; I confirmed the anonymous preview /admin returns 404, and I could not sign in as the owner there, so the rendered view rests on the tests. Counts persist under FORGE_APP_DATA, there is a restart test, and the README is updated. No new dependency and no scope beyond the issue.

Two things I would do next:

  1. Look at the owner view on a 360px phone. The 3.5rem label plus a 16-block bar should fit, but it has not been seen rendered.
  2. Give the chart a text alternative for the whole list, such as a one-line summary of the busiest hour. Screen-reader users now hear 24 bare numbers.

The model-routes failure in server.test.ts also fails on main and is not from this change.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs