carlos / platform Public

console: linked deployments fix round 1

Astra's Task 6 review.

- A removing card keeps its published apps in view: a pending one's may
  still answer.
- Each card knows whether its apps read succeeded: the Fleet tab says the
  apps could not be read rather than none, and the CLI list answers 503
  rather than an empty apps array.
- A removing card whose registry state cannot be read says so (draft
  copyLinkRemovingUnknown; the CLI says revocation "unknown"), apart from
  an observed pending revocation.
- The links-unlink parity row is a gap (wp-cli-verbs) with no note.
- Tests: the apps read failing, the registry unreadable, and another
  account's link ID at both person doors (404, that link untouched).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev aaf1e53b01edb068841d6fc62b74676443711adb parent a386503
7 files changed, +180 −24
  • docs/parity.md +4 −3
  • internal/console/accountlinks.go +42 −15
  • internal/console/accountlinks_test.go +121 −1
  • internal/console/links_copy.go +4 −0
  • internal/console/server.go +4 −0
  • internal/console/templates/account_fleet.html +4 −4
  • parity/parity.tsv +1 −1
diff --git a/docs/parity.md b/docs/parity.md
index 7bf284777..97d71fc2d 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -12,9 +12,9 @@ CLI rows are checked against the command registry (`parity/cli.tsv`).
|---|---:|
| both | 42 |
| partial | 9 |
-| gap | 62 |
+| gap | 63 |
| cli-only | 15 |
-| console-only | 18 |
+| console-only | 17 |
| Total | 146 |
## account
@@ -137,7 +137,7 @@ CLI rows are checked against the command registry (`parity/cli.tsv`).
| fleets-detach-box | both | `fleets detach-box` | `POST /a/{sqid}/fleets/{fleet}/detach` | | |
| fleets-drain | gap | `fleets drain` | | [wp-fleets-relay](#wp-fleets-relay) | |
| fleets-secrets-key | gap | `fleets secrets-key` | | [wp-fleets-relay](#wp-fleets-relay) | The fleet page shows the fingerprint and prints the CLI command. |
-| links-unlink | console-only | | `POST /a/{sqid}/links/{id}/unlink` | | No carlos command unlinks from the account side yet. carlos link remove unlinks from the home. |
+| links-unlink | gap | | `POST /a/{sqid}/links/{id}/unlink` | [wp-cli-verbs](#wp-cli-verbs) | |
## instances
@@ -328,6 +328,7 @@ Discussion #738.
- `activity` (observe), console has `GET /a/{sqid}/apps/{app}/activity`
- `account-error-level` (observe), console has `POST /a/{sqid}/errors/level`
- `account-analytics` (observe), console has `POST /a/{sqid}/analytics/setting`
+- `links-unlink` (fleets), console has `POST /a/{sqid}/links/{id}/unlink`
- `team-list` (team), console has `GET /a/{sqid}/team`
- `team-invite` (team), console has `POST /a/{sqid}/invite`, `POST /a/{sqid}/invite/revoke`
- `team-remove` (team), console has `POST /a/{sqid}/members/remove`
diff --git a/internal/console/accountlinks.go b/internal/console/accountlinks.go
index 4398743fc..a232a390a 100644
--- a/internal/console/accountlinks.go
+++ b/internal/console/accountlinks.go
@@ -13,8 +13,11 @@ package console
// registry, and no apps row naming it. While the registry still holds the
// channel or a forward row the card says the revocation is pending (the
// apps may still answer); after that, only leftover apps rows remain, which
-// serve nothing and linkSyncPass removes. The person doors offer Unlink on
-// a removing card too, which runs the remaining steps again.
+// serve nothing and linkSyncPass removes. A registry that cannot be read
+// leaves the card removing with its completion unknown, said as such. A
+// removing card still lists its apps, since a pending one's may still
+// answer. The person doors offer Unlink on a removing card too, which runs
+// the remaining steps again.
import (
"context"
@@ -38,12 +41,17 @@ type accountLinkCard struct {
Reachable bool
LastSeen time.Time
SeenKnown bool
+ // Apps are the link's apps rows; AppsKnown says that read succeeded,
+ // so an empty Apps may be shown as "none" (false: "could not be read").
Apps []accountLinkApp
+ AppsKnown bool
// Removing: the link is unlinked, and something of it is left (see the
- // file comment). Pending: what is left includes the registry's channel
- // or a forward row, or the registry could not be read to say otherwise.
+ // file comment). Pending: the registry was read and still holds the
+ // link's channel or a forward row, so its apps may still answer.
+ // Unknown: the registry could not be read to say either way.
Removing bool
Pending bool
+ Unknown bool
// The card's sentences, filled from the deck: when and by whom it was
// linked, and its state line under the reachable chip ("" for none).
LinkedText string
@@ -130,7 +138,11 @@ func (s *Server) accountLinks(acct *Account) accountLinksView {
for i := range links {
l := &links[i]
- apps, appsErr := s.store.LinkedApps(l.ID)
+ read := s.store.LinkedApps
+ if s.linkedAppsRead != nil {
+ read = s.linkedAppsRead
+ }
+ apps, appsErr := read(l.ID)
if appsErr != nil {
warn("apps of %s: %v", l.ID, appsErr)
}
@@ -140,21 +152,25 @@ func (s *Server) accountLinks(acct *Account) accountLinksView {
c := accountLinkCard{ID: l.ID, Name: l.Name, CreatedBy: l.CreatedBy, CreatedAt: l.CreatedAt,
LinkedText: linkCopy(copyLD17, "date", l.CreatedAt.UTC().Format("2 Jan 2006"), "person", l.CreatedBy)}
if !l.RevokedAt.IsZero() {
- regClear := false
+ // What the registry still holds of the link: nothing (clear),
+ // its channel or a forward row (held), or unknown (a read
+ // failed). Only a clear registry and no apps rows end the card.
+ regClear, regHeld := false, false
if reg != nil && act {
- if _, held := active[registry.LinkChannelName(l.ID)]; !held {
- fwd, err := reg.LinkForwards(l.ID)
- if err != nil {
- warn("forward rows of %s: %v", l.ID, err)
- }
- regClear = err == nil && len(fwd) == 0
+ if _, held := active[registry.LinkChannelName(l.ID)]; held {
+ regHeld = true
+ } else if fwd, err := reg.LinkForwards(l.ID); err != nil {
+ warn("forward rows of %s: %v", l.ID, err)
+ } else {
+ regClear, regHeld = len(fwd) == 0, len(fwd) > 0
}
}
if regClear && appsErr == nil && len(apps) == 0 {
continue // nothing of it is left: unlinked
}
- c.Removing, c.Pending = true, !regClear
+ c.Removing, c.Pending, c.Unknown = true, regHeld, !regClear && !regHeld
}
+ c.AppsKnown = appsErr == nil
for _, a := range apps {
c.Apps = append(c.Apps, accountLinkApp{Name: a.App, URL: s.linkAppURL(acct, a.App)})
}
@@ -167,6 +183,8 @@ func (s *Server) accountLinks(acct *Account) accountLinksView {
switch {
case c.Pending:
c.StateText = copyLinkRemovingPending
+ case c.Unknown:
+ c.StateText = copyLinkRemovingUnknown
case c.Removing:
c.StateText = copyLD22
case !c.SeenKnown || c.Reachable:
@@ -285,7 +303,8 @@ func (s *Server) handleLinkUnlinkPage(w http.ResponseWriter, r *http.Request) {
// linkWire is one linked deployment on GET /api/cli/links/{account}.
// Reachable is null when the hub's connection record could not be read;
// LastSeen is absent when the link never connected. Revocation is
-// "pending" on a removing link the hub has not cut yet.
+// "pending" on a removing link the hub has not cut yet, and "unknown" on
+// one whose registry state could not be read.
type linkWire struct {
ID string `json:"id"`
Name string `json:"name"`
@@ -318,6 +337,11 @@ func (s *Server) handleAPILinksList(w http.ResponseWriter, r *http.Request) {
}
out := make([]linkWire, 0, len(v.Cards))
for _, c := range v.Cards {
+ if !c.AppsKnown {
+ // An empty apps array would claim the link publishes nothing.
+ jsonError(w, http.StatusServiceUnavailable, copyLinksReadFailed)
+ return
+ }
lw := linkWire{ID: c.ID, Name: c.Name, CreatedBy: c.CreatedBy, CreatedAt: c.CreatedAt.UTC(),
Removing: c.Removing, Apps: make([]linkAppWire, 0, len(c.Apps))}
if c.SeenKnown {
@@ -328,8 +352,11 @@ func (s *Server) handleAPILinksList(w http.ResponseWriter, r *http.Request) {
lw.LastSeen = &at
}
}
- if c.Pending {
+ switch {
+ case c.Pending:
lw.Revocation = "pending"
+ case c.Unknown:
+ lw.Revocation = "unknown"
}
for _, a := range c.Apps {
lw.Apps = append(lw.Apps, linkAppWire{App: a.Name, URL: a.URL})
diff --git a/internal/console/accountlinks_test.go b/internal/console/accountlinks_test.go
index 3fb541415..b6bd272b2 100644
--- a/internal/console/accountlinks_test.go
+++ b/internal/console/accountlinks_test.go
@@ -2,6 +2,7 @@ package console
import (
"context"
+ "errors"
"net/http"
"net/url"
"strings"
@@ -195,9 +196,11 @@ func TestUnlinkFromConsole(t *testing.T) {
t.Fatalf("pending unlink = %d", status)
}
_, _, page = get(t, browser, fx.ts.URL+loc)
+ // The pending card still lists the app it may still be serving.
pageHas(t, "the Fleet tab with the unlink pending", page,
esc(linkCopy(copyLinkUnlinkPending, "home", "blog-home")), "blog-home", esc(copyLinkRemovingPending),
- `action="/a/`+fx.sqid+`/links/`+l2.id+`/unlink"`)
+ `action="/a/`+fx.sqid+`/links/`+l2.id+`/unlink"`,
+ esc(copyLD23), `>notes</a>`, `href="https://`+linkHost(fx, "notes")+`"`)
if hosts := linkForwardHosts(t, fx, l2.id); len(hosts) != 1 {
t.Fatalf("forward rows while pending = %v", hosts)
}
@@ -348,3 +351,120 @@ func claimLinkUnlinked(t *testing.T, cx *claimCase, _ claimReply) string {
}
return claimLinkChannelIs(t, cx, "")
}
+
+// TestLinkedDeploymentsAppsReadFailure: a link's apps that cannot be read
+// are said to be unreadable on the Fleet tab, never "No apps published
+// yet", and the CLI list refuses rather than answer an empty apps array.
+func TestLinkedDeploymentsAppsReadFailure(t *testing.T) {
+ fx := newLinkFixture(t, "tunnel.example.com")
+ browser := signInPaul(t, fx)
+ token := cliToken(t, fx, "paul@keymail.dev", "code-links-apps-fail")
+ l := mintLink(t, fx, browser, "shop-home")
+ if status, out := publish(t, fx, l.token, "shop"); status != http.StatusCreated {
+ t.Fatalf("publish = %d %v", status, out)
+ }
+ fx.srv.linkedAppsRead = func(string) ([]linkedApp, error) { return nil, errors.New("injected apps read failure") }
+
+ _, _, page := get(t, browser, fx.u("/fleet"))
+ pageHas(t, "the Fleet tab with the apps read failing", page, "shop-home", esc(copyLD23), esc(copyLinksReadFailed))
+ pageLacks(t, "the Fleet tab with the apps read failing", page, esc(copyLD24))
+
+ status, _, out := rawReq(t, http.MethodGet, fx.ts.URL+"/api/cli/links/"+fx.sqid, token, "")
+ if status != http.StatusServiceUnavailable || linkJSONErr(out) != copyLinksReadFailed {
+ t.Fatalf("CLI list with the apps read failing = %d %s, want 503 %q", status, out, copyLinksReadFailed)
+ }
+}
+
+// TestLinkedDeploymentsRegistryUnknown: a revoked link whose registry state
+// cannot be read keeps its card and Unlink, said as unknown, not as an
+// observed pending revocation; the CLI says "unknown".
+func TestLinkedDeploymentsRegistryUnknown(t *testing.T) {
+ fx := newLinkFixture(t, "tunnel.example.com")
+ browser := signInPaul(t, fx)
+ token := cliToken(t, fx, "paul@keymail.dev", "code-links-unknown")
+ l := mintLink(t, fx, browser, "shop-home")
+ if status, out := publish(t, fx, l.token, "shop"); status != http.StatusCreated {
+ t.Fatalf("publish = %d %v", status, out)
+ }
+ // Revoked on the console only: the registry still holds the channel.
+ if err := fx.st.RevokeLink(l.id, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ // Observed: the registry is read and holds it, so pending.
+ _, _, page := get(t, browser, fx.u("/fleet"))
+ pageHas(t, "the Fleet tab with the revocation observed pending", page, esc(copyLinkRemovingPending))
+
+ fx.srv.linkRegistry = func() (consoleRegistry, error) { return nil, errors.New("injected registry outage") }
+ _, _, page = get(t, browser, fx.u("/fleet"))
+ pageHas(t, "the Fleet tab with the registry unreadable", page,
+ "shop-home", esc(copyLinkRemovingUnknown), `action="/a/`+fx.sqid+`/links/`+l.id+`/unlink"`,
+ `href="https://`+linkHost(fx, "shop")+`"`)
+ pageLacks(t, "the Fleet tab with the registry unreadable", page, esc(copyLinkRemovingPending), esc(copyLD22))
+
+ status, body := getJSON(t, fx.ts.URL+"/api/cli/links/"+fx.sqid, token)
+ links, _ := body["links"].([]any)
+ if status != http.StatusOK || len(links) != 1 {
+ t.Fatalf("CLI list with the registry unreadable = %d %v", status, body)
+ }
+ if got := links[0].(map[string]any); got["removing"] != true || got["revocation"] != "unknown" || got["reachable"] != nil {
+ t.Fatalf("listed link with the registry unreadable = %v, want removing, revocation unknown, reachable null", got)
+ }
+}
+
+// TestPersonUnlinkRefusesAnotherAccountsLink: an account the caller owns
+// in the path with another account's real link ID is a 404 at both person
+// doors, and the other link is untouched.
+func TestPersonUnlinkRefusesAnotherAccountsLink(t *testing.T) {
+ fx := newLinkFixture(t, "tunnel.example.com")
+ paul := signInPaul(t, fx)
+ paulToken := cliToken(t, fx, "paul@keymail.dev", "code-links-cross-paul")
+
+ fx.setUser("bob@keymail.dev")
+ bob := newBrowser(t)
+ signUp(t, fx, bob, "code-links-cross-bob")
+ accts, err := fx.st.AccountsFor("bob@keymail.dev")
+ if err != nil || len(accts) == 0 {
+ t.Fatal(accts, err)
+ }
+ bobSqid := accts[0].Sqid
+ poll := linkCeremony(t, fx, bob, "blog-home", bobSqid)
+ bobToken, bobLink := str(t, poll, "token"), str(t, poll, "link_id")
+ if status, out := publish(t, fx, bobToken, "blog"); status != http.StatusCreated {
+ t.Fatalf("bob's publish = %d %v", status, out)
+ }
+ fx.setUser("paul@keymail.dev")
+
+ if status, _, _ := unlinkForm(t, fx, paul, bobLink, true); status != http.StatusNotFound {
+ t.Fatalf("browser unlink of another account's link = %d, want 404", status)
+ }
+ if status, _, _ := unlinkForm(t, fx, paul, bobLink, false); status != http.StatusNotFound {
+ t.Fatalf("browser confirm card for another account's link = %d, want 404", status)
+ }
+ if status, _, out := rawReq(t, http.MethodDelete, fx.ts.URL+"/api/cli/links/"+fx.sqid+"/"+bobLink, paulToken, ""); status != http.StatusNotFound {
+ t.Fatalf("CLI unlink of another account's link = %d %s, want 404", status, out)
+ }
+ // Paul's own list does not show bob's link either.
+ _, body := getJSON(t, fx.ts.URL+"/api/cli/links/"+fx.sqid, paulToken)
+ if links, _ := body["links"].([]any); len(links) != 0 {
+ t.Fatalf("paul's list = %v, want none", body)
+ }
+
+ // Bob's link is unchanged: live, its credential resolves, its channel
+ // and its forward row are in the registry.
+ if l, err := fx.st.LinkByID(bobLink); err != nil || l == nil || !l.RevokedAt.IsZero() {
+ t.Fatalf("bob's link after the refused unlinks = %+v %v", l, err)
+ }
+ if _, ok := fx.st.CLIPrincipal(bobToken, time.Now()); !ok {
+ t.Fatal("bob's link token no longer resolves")
+ }
+ auth, err := linkRegistryOf(t, fx).LinkChannelAuth()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if auth[registry.LinkChannelName(bobLink)] != hashToken(bobToken) {
+ t.Fatal("bob's channel changed")
+ }
+ if hosts := linkForwardHosts(t, fx, bobLink); len(hosts) != 1 {
+ t.Fatalf("bob's forward rows = %v, want one", hosts)
+ }
+}
diff --git a/internal/console/links_copy.go b/internal/console/links_copy.go
index 422be64c3..86599bbeb 100644
--- a/internal/console/links_copy.go
+++ b/internal/console/links_copy.go
@@ -138,6 +138,10 @@ const (
// link's connection or an app's address (the revocation pending), in
// place of LD-C22, whose "already offline" is not yet true then.
copyLinkRemovingPending = "Removing. Carloku has not cut its connection yet, so its apps may still answer."
+ // A card in the removing state when the hub registry could not be read
+ // to say whether the connection is cut (neither LD-C22 nor the pending
+ // line is known to be true then).
+ copyLinkRemovingUnknown = "Removing. Carloku could not check just now whether its connection is cut."
// The Fleet tab's flash, and the person CLI list's 503, when the
// account's links or their state could not be read.
copyLinksReadFailed = "Your linked deployments could not be read just now."
diff --git a/internal/console/server.go b/internal/console/server.go
index 95e400941..5466405d4 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -1407,6 +1407,10 @@ type Server struct {
// (apilinks.go). Tests only: the barrier between the apps row and the
// forward row.
linkPublishHook func(linkID, stage string)
+ // linkedAppsRead, when non-nil, is the read the Linked deployments
+ // view (accountLinks) lists a link's apps with, in place of
+ // store.LinkedApps. Tests only: a read that fails.
+ linkedAppsRead func(linkID string) ([]linkedApp, error)
// delegationZone and lookupCNAME are the wildcard-capability door's two
// seams (apidomains.go). delegationZone is cfg.DelegationZone, shape-
// validated and normalized once here (normalizeDelegationZone);
diff --git a/internal/console/templates/account_fleet.html b/internal/console/templates/account_fleet.html
index 6c6c953a4..955222f0c 100644
--- a/internal/console/templates/account_fleet.html
+++ b/internal/console/templates/account_fleet.html
@@ -52,14 +52,14 @@
</div>
<p class="small">{{.LinkedText}}</p>
{{if .Removing}}<p><span class="chip chip-canary">{{.StateText}}</span></p>
-{{else}}{{if .SeenKnown}}<p>{{if .Reachable}}<span class="chip chip-health-ok">{{$.LinkSection.Reachable}}</span>{{else}}<span class="chip chip-stale">{{$.LinkSection.NotReachable}}</span>{{end}}
+{{else if .SeenKnown}}<p>{{if .Reachable}}<span class="chip chip-health-ok">{{$.LinkSection.Reachable}}</span>{{else}}<span class="chip chip-stale">{{$.LinkSection.NotReachable}}</span>{{end}}
{{if .StateText}}<span class="small">{{.StateText}}</span>{{end}}</p>{{end}}
-<h4>{{$.LinkSection.AppsHeading}}</h4>
+{{if or .Apps (not .Removing) (not .AppsKnown)}}<h4>{{$.LinkSection.AppsHeading}}</h4>
{{if .Apps}}<ul>
{{range .Apps}}<li><a href="{{$.Nav}}/apps/{{.Name}}">{{.Name}}</a>{{if .URL}} <a href="{{.URL}}">{{.URL}}</a>{{end}} <span class="chip chip-env">{{$.LinkSection.Kind}}</span></li>
{{end}}
-</ul>{{else}}<p class="small">{{$.LinkSection.NoApps}}</p>{{end}}
-{{end}}
+</ul>{{else if not .AppsKnown}}<p class="small">{{$.LinkSection.Unreadable}}</p>
+{{else}}<p class="small">{{$.LinkSection.NoApps}}</p>{{end}}{{end}}
{{end}}
{{else if .LinkedDeploymentsKnown}}<p class="small">{{.LinkSection.Empty}}</p>
{{else}}<p class="small">{{.LinkSection.Unreadable}}</p>{{end}}
diff --git a/parity/parity.tsv b/parity/parity.tsv
index 676c2ef87..1ee862c86 100644
--- a/parity/parity.tsv
+++ b/parity/parity.tsv
@@ -150,7 +150,7 @@ fleets-tag-box fleets both fleets tag-box POST /a/{sqid}/fleets/{fleet}/tags
fleets-detach-box fleets both fleets detach-box POST /a/{sqid}/fleets/{fleet}/detach
fleets-drain fleets gap fleets drain wp-fleets-relay
fleets-secrets-key fleets gap fleets secrets-key wp-fleets-relay The fleet page shows the fingerprint and prints the CLI command.
-links-unlink fleets console-only POST /a/{sqid}/links/{id}/unlink No carlos command unlinks from the account side yet. carlos link remove unlinks from the home.
+links-unlink fleets gap POST /a/{sqid}/links/{id}/unlink wp-cli-verbs
# team
team-list team gap GET /a/{sqid}/team wp-cli-verbs The CLI cannot list members.