carlos / platform Public

last-seen witnesses through the real routes

People showed "not yet" on flagship for someone who had used ship,
promote and run since the roll. These tests drive a console that has just
started (no reservation, last_seen 0) through the real wiring: a person's
CLI token on channels, releases, apps and a promote, and a browser session
on an app page and on People, each set users.last_seen. The same holds on
the gated store (CARLOS_HOST_CLAIM on). The fixture does not reproduce the
flagship report; no code change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 305c5100c002c29aa4ca16b74b7d065c64b2fe03 parent 5f4df95
1 file changed, +93 −0
  • internal/console/lastseen_test.go +93 −0
diff --git a/internal/console/lastseen_test.go b/internal/console/lastseen_test.go
index 5c551d55c..62ef83b90 100644
--- a/internal/console/lastseen_test.go
+++ b/internal/console/lastseen_test.go
@@ -4,6 +4,7 @@ import (
"database/sql"
"errors"
"net/http"
+ "strings"
"sync"
"testing"
"time"
@@ -293,3 +294,95 @@ BEGIN SELECT RAISE(ABORT, 'test: last_seen refused'); END;`); err != nil {
t.Fatalf("lastSeenWrites after a second GET within the hour = +%d, want +1 (the failed write's reservation kept)", got)
}
}
+
+// rollSeen puts the console where a roll leaves it: a fresh process holds no
+// reservation, and the stored last_seen is the column's default for address.
+func rollSeen(t *testing.T, fx *consoleFixture, address string) {
+ t.Helper()
+ fx.srv.seenMu.Lock()
+ clear(fx.srv.seen)
+ fx.srv.seenMu.Unlock()
+ if _, err := fx.st.db.Exec(`UPDATE users SET last_seen = 0 WHERE address = ?`, address); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// TestLastSeenAfterARollThroughTheRealRoutes is the flagship report's
+// witness (People showed "not yet" for a person who had used ship, promote
+// and run since the roll): through the console's own wiring, a person's CLI
+// token on the deploy doors and a browser session on an app page and on
+// People each set users.last_seen on a console that has just started.
+func TestLastSeenAfterARollThroughTheRealRoutes(t *testing.T) {
+ fx := newConsoleFixture(t)
+ shipVersion(t, fx, "kass", "v3")
+ seedChannel(t, fx, "kass", "beta", "v3")
+ tok := cliToken(t, fx, lastSeenPaul, "code-"+t.Name())
+
+ for _, door := range []string{
+ "/api/cli/apps/" + fx.sqid + "/kass/channels",
+ "/api/cli/apps/" + fx.sqid + "/kass/releases",
+ "/api/cli/apps",
+ } {
+ rollSeen(t, fx, lastSeenPaul)
+ if status, out := getJSON(t, fx.ts.URL+door, tok); status != http.StatusOK {
+ t.Fatalf("GET %s with Paul's CLI token = %d %v", door, status, out)
+ }
+ if seen, _ := lastSeenOf(t, fx, lastSeenPaul); seen == 0 {
+ t.Fatalf("GET %s with Paul's CLI token left last_seen 0", door)
+ }
+ }
+
+ // A promote: the deploy door's POST.
+ rollSeen(t, fx, lastSeenPaul)
+ status, out := postJSON(t, fx.ts.URL+"/api/cli/apps/"+fx.sqid+"/kass/promote",
+ map[string]string{"channel": "canary/x", "version": "v3"}, tok)
+ if status != http.StatusOK {
+ t.Fatalf("POST promote with Paul's CLI token = %d %v", status, out)
+ }
+ if seen, _ := lastSeenOf(t, fx, lastSeenPaul); seen == 0 {
+ t.Fatal("POST promote with Paul's CLI token left last_seen 0")
+ }
+
+ browser := signInPaul(t, fx)
+ if err := fx.st.SetOperator(lastSeenPaul, true); err != nil {
+ t.Fatal(err)
+ }
+ for _, page := range []string{"/apps/kass", "/fleet/people"} {
+ rollSeen(t, fx, lastSeenPaul)
+ u := fx.ts.URL + page
+ if !strings.HasPrefix(page, "/fleet") {
+ u = fx.u(page)
+ }
+ status, _, body := get(t, browser, u)
+ if status != http.StatusOK {
+ t.Fatalf("GET %s = %d", page, status)
+ }
+ if seen, _ := lastSeenOf(t, fx, lastSeenPaul); seen == 0 {
+ t.Fatalf("GET %s in a browser session left last_seen 0", page)
+ }
+ if page == "/fleet/people" && strings.Contains(body, ">not yet<") {
+ t.Fatalf("People shows the viewer as not yet seen:\n%s", body)
+ }
+ }
+}
+
+// TestLastSeenOnTheGatedStore: with CARLOS_HOST_CLAIM on, the database
+// opens gated (OpenGated) and users is a NonApp table; the gate does not
+// refuse the last-seen write on either path.
+func TestLastSeenOnTheGatedStore(t *testing.T) {
+ cx := newClaimCase(t)
+ if !cx.srv.cfg.HostClaim {
+ t.Fatal("the claim console is not enabled")
+ }
+ addr := lastSeenPaul
+ for name, do := range map[string]func(){
+ "a CLI token": func() { cx.apiReply(t, http.MethodGet, "/api/cli/apps", "") },
+ "a session": func() { cx.pageReply(t, "/settings") },
+ } {
+ rollSeen(t, cx.consoleFixture, addr)
+ do()
+ if seen, ok := lastSeenOf(t, cx.consoleFixture, addr); !ok || seen == 0 {
+ t.Errorf("%s on the gated store left last_seen %d (row %v)", name, seen, ok)
+ }
+ }
+}