carlos / platform Public

fix: claim page says has room or full, shows the new address

codex agent, operated by paul@keymail.dev pushed by paul@keymail.dev e240344c7e00459c623d7cd5c6aee583cf12c4c7 parent f20880a
7 files changed, +137 −35
  • internal/console/demo_claim_choice_test.go +63 −20
  • internal/console/demo_claim_copy.go +6 −4
  • internal/console/demo_claim_page.go +8 −4
  • internal/console/demo_claim_resume_browser_test.go +27 −1
  • internal/console/static/demo_claim.js +2 −0
  • internal/console/templates/demo_claim.html +5 −5
  • internal/console/testdata/demo_claim_resume_browser.mjs +26 −1

CI passed — run details

Intent

Human

<task-notification> <task-id>b1toc13us</task-id> <tool-use-id>toolu_01TYr57AFkaJozmvzpo32azX</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/b1toc13us.output</output-file> <status>completed</status> <summary>Background command "S=/home/paulca/.cache/tmp/dcau; until [ -f $S/done ]; do sleep 20; done; tail -1 $S/log; cat $S/final.md" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 48.3 g CO₂e (6,190,114 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on demo-claim-account-ui, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/internal/console/demo_claim_choice_test.go b/internal/console/demo_claim_choice_test.go
index ad80bcebf..7e9dbd6a6 100644
--- a/internal/console/demo_claim_choice_test.go
+++ b/internal/console/demo_claim_choice_test.go
@@ -172,17 +172,20 @@ func (s *claimRoomStore) List(ctx context.Context, prefix string) ([]string, err
func TestDemoClaimChoiceRoom(t *testing.T) {
for _, tc := range []struct {
- name string
- role string
- instances int
- plans, fail bool
- reason string
+ name string
+ role string
+ instances int
+ plans, fail bool
+ reason, room string
}{
- {"fits exactly", RoleOwner, 0, true, false, ""},
- {"needs two slots", RoleMember, 1, true, false, demoClaimAtLimit},
- {"role", "viewer", 0, true, false, demoClaimRoleDenied},
- {"plans off", RoleOwner, 1, false, false, ""},
- {"count failed", RoleOwner, 1, true, true, ""},
+ {"fits exactly", RoleOwner, 0, true, false, "", "Has room"},
+ {"needs two slots", RoleMember, 1, true, false, "Not enough room: 2 of 3 apps and instances in use. This demo needs room for 2.", ""},
+ {"full", RoleOwner, 2, true, false, "Full: 3 of 3 apps and instances in use", ""},
+ {"over limit", RoleOwner, 3, true, false, "Full: 4 of 3 apps and instances in use", ""},
+ {"role", "viewer", 0, true, false, demoClaimRoleDenied, ""},
+ {"role at limit", "viewer", 2, true, false, demoClaimRoleDenied, ""},
+ {"plans off", RoleOwner, 1, false, false, "", ""},
+ {"count failed", RoleOwner, 1, true, true, "", ""},
} {
t.Run(tc.name, func(t *testing.T) {
s, _, token := claimTestServer(t)
@@ -214,19 +217,30 @@ func TestDemoClaimChoiceRoom(t *testing.T) {
} else if !strings.Contains(body, `type="hidden" name="accountId" value="`+a.Sqid+`"`) {
t.Error("eligible account lost")
}
- if tc.plans && !tc.fail {
- want := fmt.Sprintf(demoClaimRoom, 1+tc.instances, 3)
- if !strings.Contains(body, want) || !strings.Contains(body, ">Free<") {
- t.Errorf("missing plan or room %q", want)
+ choice := s.demoClaimAccountView(t.Context(), *a, true)
+ if choice.Room != tc.room || choice.Reason != tc.reason {
+ t.Errorf("room/reason = %q / %q; want %q / %q", choice.Room, choice.Reason, tc.room, tc.reason)
+ }
+ if tc.room != "" && strings.Count(body, ">"+tc.room+"<") != 1 {
+ t.Errorf("single account must show exactly one %q line", tc.room)
+ }
+ if tc.reason == "" || tc.role == "viewer" {
+ if strings.Contains(body, "apps and instances") {
+ t.Error("eligible or role-disabled account shows counts")
+ }
+ } else if strings.Count(body, tc.reason) != 1 {
+ t.Error("capacity reason must appear once")
+ }
+ if (!tc.plans || tc.role == "viewer") && spy.calls.Load() != 0 {
+ t.Error("plans off or role-disabled account read store")
+ }
+ if tc.plans && !tc.fail && tc.role != "viewer" {
+ if !strings.Contains(body, ">Free<") {
+ t.Error("missing plan")
}
- if isPlanCap(s.checkRunningThings(t.Context(), a, 2)) != (tc.instances == 1) {
+ if isPlanCap(s.checkRunningThings(t.Context(), a, 2)) != (tc.instances >= 1) {
t.Error("hint differs from reservation")
}
- } else if strings.Contains(body, "apps and instances") {
- t.Error("unavailable count rendered")
- }
- if !tc.plans && spy.calls.Load() != 0 {
- t.Error("plans off read store")
}
// HEAD renders no capacity hint and does not count.
spy.calls.Store(0)
@@ -360,3 +374,32 @@ func claimChoiceAccount(t *testing.T, s *Server, id int64, person, role string)
a.Role = role
return a
}
+
+func TestDemoClaimProgressAndOutcome(t *testing.T) {
+ for _, state := range []string{"claiming", "claimed"} {
+ t.Run(state, func(t *testing.T) {
+ var rendered bytes.Buffer
+ address := "https://a-long-permanent-app-name.account.apps.example.com"
+ if err := demoClaimPageTemplate.ExecuteTemplate(&rendered, "demo_claim.html", demoClaimPageData{Copy: demoClaimBrowserCopy(), State: state, Step: 2, URL: address}); err != nil {
+ t.Fatal(err)
+ }
+ body := rendered.String()
+ if state == "claiming" {
+ if !strings.Contains(body, `id="claim-status" class="claim-sr-only" role="status" aria-live="polite"`) || !strings.Contains(body, "#claim .claim-sr-only") {
+ t.Error("live status must use the scoped screen-reader-only class")
+ }
+ if !strings.Contains(body, `data-step="2" aria-current="step">Starting your app</li>`) {
+ t.Error("current step is not marked")
+ }
+ } else {
+ if !strings.Contains(body, "<h1>"+demoClaimComplete+"</h1>") || strings.Count(body, demoClaimComplete) != 1 {
+ t.Error("outcome must appear once, as the heading")
+ }
+ link := regexp.MustCompile(`<a class="btn" href="([^"]+)" rel="noreferrer">([^<]+)</a>`).FindStringSubmatch(body)
+ if len(link) != 3 || link[1] != address || strings.TrimPrefix(link[2], "https://") != strings.TrimPrefix(address, "https://") {
+ t.Error("result link must display the permanent address")
+ }
+ }
+ })
+ }
+}
diff --git a/internal/console/demo_claim_copy.go b/internal/console/demo_claim_copy.go
index 6d2acf0ce..0e4518f26 100644
--- a/internal/console/demo_claim_copy.go
+++ b/internal/console/demo_claim_copy.go
@@ -96,12 +96,14 @@ const (
demoClaimDestination = "This goes into %s"
// CLAIM-KEEP-IN: action after choosing an account.
demoClaimKeepIn = "Keep in %s"
- // CLAIM-ROOM: the same unit as the catalog cap.
- demoClaimRoom = "%d of %d apps and instances in use"
+ // CLAIM-ROOM-AVAILABLE: the account has room for the app and its instance.
+ demoClaimHasRoom = "Has room"
+ // CLAIM-ROOM-FULL: current use is at or above the catalog cap.
+ demoClaimFull = "Full: %d of %d apps and instances in use"
+ // CLAIM-ROOM-INSUFFICIENT: one slot remains, but the claim needs two.
+ demoClaimNoRoom = "Not enough room: %d of %d apps and instances in use. This demo needs room for 2."
// CLAIM-ROLE-DENIED: membership cannot create apps.
demoClaimRoleDenied = "Your role cannot create apps in this account."
- // CLAIM-AT-LIMIT: a claim requires both an app and an instance.
- demoClaimAtLimit = "At its limit. This demo needs room for 2 apps and instances."
// CLAIM-STEP-COPYING: first progress step.
demoClaimCopying = "Copying your data"
// CLAIM-STEP-STARTING: second progress step.
diff --git a/internal/console/demo_claim_page.go b/internal/console/demo_claim_page.go
index ea40c871c..6b88cb47a 100644
--- a/internal/console/demo_claim_page.go
+++ b/internal/console/demo_claim_page.go
@@ -612,7 +612,7 @@ func (s *Server) demoClaimAccountView(ctx context.Context, a Account, count bool
c.Plan = planLabel(name)
}
}
- if !count {
+ if !count || c.Reason != "" {
return c
}
limits, err := s.EffectiveLimits(&a)
@@ -623,9 +623,13 @@ func (s *Server) demoClaimAccountView(ctx context.Context, a Account, count bool
if err != nil {
return c
}
- c.Room = fmt.Sprintf(demoClaimRoom, n, limits.RunningThings)
- if n+2 > limits.RunningThings && c.Reason == "" {
- c.Reason = demoClaimAtLimit
+ switch {
+ case n >= limits.RunningThings:
+ c.Reason = fmt.Sprintf(demoClaimFull, n, limits.RunningThings)
+ case n+2 > limits.RunningThings:
+ c.Reason = fmt.Sprintf(demoClaimNoRoom, n, limits.RunningThings)
+ default:
+ c.Room = demoClaimHasRoom
}
return c
}
diff --git a/internal/console/demo_claim_resume_browser_test.go b/internal/console/demo_claim_resume_browser_test.go
index 4c2c2b13e..b1452bee6 100644
--- a/internal/console/demo_claim_resume_browser_test.go
+++ b/internal/console/demo_claim_resume_browser_test.go
@@ -3,6 +3,7 @@ package console
import (
"context"
"encoding/json"
+ "fmt"
"net/http"
"net/http/httptest"
"os"
@@ -11,6 +12,8 @@ import (
"sync/atomic"
"testing"
"time"
+
+ "github.com/carlosframework/platform/internal/provision"
)
func TestDemoClaimSelectStepUpHeadless(t *testing.T) {
@@ -106,7 +109,30 @@ func TestDemoClaimSelectStepUpHeadless(t *testing.T) {
one.login("shop@example.com", MethodEmail, true)
claimAccount(t, single, 601, "shop@example.com", RoleOwner)
single.cfg.PlanCatalog = examplePlanCatalog(t)
- singleArgs, _ := json.Marshal(map[string]string{"target": singleServer.URL, "session": one.session, "cookie": one.cookie})
+ capacity, _, capacityToken := claimTestServer(t)
+ capacity.registerRoute("GET /static/{hash}/{file...}", capacity.handleStatic)
+ capacityServer := httptest.NewServer(capacity.mux)
+ defer capacityServer.Close()
+ capacity.cfg.Origin = capacityServer.URL
+ capacity.cfg.PlanCatalog = examplePlanCatalog(t)
+ room := newClaimBrowser(t, capacity, capacityToken)
+ room.login("shop@example.com", MethodEmail, true)
+ for i, name := range []string{"Full account", "Almost full account"} {
+ a := claimAccount(t, capacity, int64(701+i), "shop@example.com", RoleOwner)
+ if _, err := capacity.store.db.Exec(`UPDATE accounts SET name=? WHERE id=?`, name, a.ID); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := capacity.store.CreateAppIn(a.ID, "shop", "shop@example.com", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ for j := 0; j < 2-i; j++ {
+ if _, err := capacity.cfg.Releases.Put(t.Context(), provision.RecordKey(a.Sqid, "shop", fmt.Sprintf("shop%d.example.com", j)), []byte(`{}`), ""); err != nil {
+ t.Fatal(err)
+ }
+ }
+ }
+ singleArgs, _ := json.Marshal(map[string]string{"target": singleServer.URL, "session": one.session, "cookie": one.cookie,
+ "capacityTarget": capacityServer.URL, "capacitySession": room.session, "capacityCookie": room.cookie})
ctx, cancel := context.WithTimeout(t.Context(), 90*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, node, "testdata/demo_claim_resume_browser.mjs", chromium, t.TempDir(), ts.URL, b.session, b.cookie, a.Sqid, os.Getenv("CARLOS_DEMO_CLAIM_SCREENSHOTS"), string(singleArgs))
diff --git a/internal/console/static/demo_claim.js b/internal/console/static/demo_claim.js
index d0211ab72..2a48b76c1 100644
--- a/internal/console/static/demo_claim.js
+++ b/internal/console/static/demo_claim.js
@@ -40,6 +40,7 @@
const result = await response.json();
if (result.state === "aborted" && result.step === 0) {
for (const step of progress.querySelectorAll("[data-step]")) step.removeAttribute("aria-current");
+ status.classList.remove("claim-sr-only");
status.textContent = progress.dataset.aborted;
return;
}
@@ -57,6 +58,7 @@
failures = 0;
} catch (_) {
if (++failures >= 3) {
+ status.classList.remove("claim-sr-only");
status.textContent = progress.dataset.pollFailed;
reload.hidden = false;
return;
diff --git a/internal/console/templates/demo_claim.html b/internal/console/templates/demo_claim.html
index fc85359ac..dbe51a32f 100644
--- a/internal/console/templates/demo_claim.html
+++ b/internal/console/templates/demo_claim.html
@@ -29,14 +29,15 @@
#claim .claim-steps [aria-current=step] { color: var(--ink); font-weight: 600; }
#claim .claim-steps [aria-current=step]::marker { color: var(--accent); }
@media (prefers-reduced-motion: reduce) { #claim button, #claim .btn { transition: none; } }
+#claim .claim-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
#claim .claim-result { margin: 1.5rem 0; }
-#claim .claim-result .btn { display: inline-block; padding: 0.65rem 1.25rem; }
+#claim .claim-result .btn { display: inline-block; max-width: 100%; white-space: normal; overflow-wrap: anywhere; padding: 0.65rem 1.25rem; }
</style>
</head>
<body>
{{template "console_header" .Chrome}}
<main id="claim" data-failed="{{.Copy.failed}}">
-<h1>{{.Copy.title}}</h1>
+<h1>{{if eq .State "claimed"}}{{.Copy.complete}}{{else}}{{.Copy.title}}{{end}}</h1>
{{if .DemoName}}<div class="claim-summary">
<strong>{{.DemoName}}</strong><a href="https://{{.DemoHost}}" rel="noreferrer">{{.DemoHost}}</a>
<p>{{.Copy.saved}} {{.Permanent}}</p>
@@ -56,13 +57,12 @@
<li data-step="2"{{if eq .Step 2}} aria-current="step"{{end}}>{{.Copy.starting}}</li>
<li data-step="3"{{if eq .Step 3}} aria-current="step"{{end}}>{{.Copy.done}}</li>
</ol>
-<p id="claim-status" role="status" aria-live="polite">{{if eq .Step 2}}{{.Copy.starting}}{{else}}{{.Copy.copying}}{{end}}</p>
+<p id="claim-status" class="claim-sr-only" role="status" aria-live="polite">{{if eq .Step 2}}{{.Copy.starting}}{{else}}{{.Copy.copying}}{{end}}</p>
<a id="claim-reload" href="/demo/claim">{{.Copy.reload}}</a>
</div>{{end}}
{{if eq .State "aborted"}}<p>{{.Copy.aborted}}</p>{{end}}
{{if eq .State "claimed"}}
-<p role="status">{{.Copy.complete}}</p>
-<p class="claim-result"><a class="btn" href="{{.URL}}" rel="noreferrer">{{.Copy.url}}</a></p>
+<p class="claim-result"><a class="btn" href="{{.URL}}" rel="noreferrer">{{.URL}}</a></p>
<p><strong>{{.App}}</strong></p><p>{{.Copy.oldAddress}}</p><p>{{.Copy.next}}</p>
{{end}}
{{if and .HasIntent .CanClaim}}
diff --git a/internal/console/testdata/demo_claim_resume_browser.mjs b/internal/console/testdata/demo_claim_resume_browser.mjs
index 2102f2521..64264d637 100644
--- a/internal/console/testdata/demo_claim_resume_browser.mjs
+++ b/internal/console/testdata/demo_claim_resume_browser.mjs
@@ -57,6 +57,9 @@ async function capture(state) {
await call('Emulation.setEmulatedMedia',{features:[{name:'prefers-color-scheme',value:scheme},{name:'prefers-reduced-motion',value:'reduce'}]});
await new Promise(r=>setTimeout(r,150));
assert.equal(await evaluate('document.documentElement.scrollWidth <= innerWidth'),true,state+' overflows at '+width);
+ if (state === 'done') {
+ assert.equal(await evaluate('(() => { const link = document.querySelector(".claim-result a"); const rect = link.getBoundingClientRect(); return rect.left >= 0 && rect.right <= innerWidth && link.scrollWidth <= link.clientWidth; })()'),true,'result address overflows at '+width);
+ }
if (screenshots) {
const shot=await call('Page.captureScreenshot',{format:'png',captureBeyondViewport:true});
await writeFile(screenshots+'/'+state+'-'+scheme+'-'+width+'.png',Buffer.from(shot.data,'base64'));
@@ -94,7 +97,20 @@ try {
await until('document.readyState === "complete" && !!document.querySelector("#claim input[type=hidden][name=accountId]")');
assert.equal(await evaluate('document.querySelectorAll("#claim input[type=radio]").length'),0);
assert.equal(await evaluate('document.querySelector("#claim button[type=submit]").textContent'),'Keep in shop');
+ assert.equal(await evaluate('document.querySelector(".claim-single").innerText.includes("Has room")'),true);
+ assert.equal(await evaluate('document.querySelector(".claim-single").innerText.includes("apps and instances")'),false);
await capture('one');
+ await call('Network.setCookies', {cookies:[
+ {name:'carlos_console_session',value:single.capacitySession,url:single.capacityTarget,path:'/',httpOnly:true,sameSite:'Lax'},
+ {name:'carlos_demo_claim_flow',value:single.capacityCookie,url:single.capacityTarget,path:'/demo/claim',httpOnly:true,secure:true,sameSite:'Lax'}
+ ]});
+ await call('Page.navigate',{url:single.capacityTarget+'/demo/claim'});
+ await until('document.readyState === "complete" && document.querySelectorAll(".claim-card").length === 2');
+ const capacityCards = await evaluate('Array.from(document.querySelectorAll(".claim-card"), card => ({text:card.innerText,disabled:card.querySelector("input").disabled}))');
+ assert(capacityCards.every(card=>card.disabled));
+ assert(capacityCards.some(card=>card.text.includes('Full: 3 of 3 apps and instances in use')));
+ assert(capacityCards.some(card=>card.text.includes('Not enough room: 2 of 3 apps and instances in use. This demo needs room for 2.')));
+ await capture('capacity');
await call('Network.setCookies', {cookies:[
{name:'carlos_console_session',value:sessionToken,url:target,path:'/',httpOnly:true,sameSite:'Lax'},
{name:'carlos_demo_claim_flow',value:flowCookie,url:target,path:'/demo/claim',httpOnly:true,secure:true,sameSite:'Lax'}
@@ -131,6 +147,8 @@ try {
await evaluate(`document.querySelector('input[value='+${JSON.stringify(account)}+']').click()`);
assert.equal(await evaluate('document.querySelectorAll("script").length'),1);
assert.equal(await evaluate('document.querySelector("#claim button[type=submit]").textContent'), 'Keep in Personal projects');
+ assert.equal(await evaluate('Array.from(document.querySelectorAll(".claim-card:has(input:not(:disabled))")).every(card => card.innerText.includes("Has room") && !card.innerText.includes("apps and instances"))'),true);
+ assert.deepEqual(await evaluate('Array.from(document.querySelectorAll(".claim-card:has(input:disabled) .claim-detail")).map(el => el.textContent)'),['Free']);
await capture('many');
await evaluate(`const button = document.querySelector('form[action="/demo/claim/select"] button'); button.click(); button.click()`);
await until(`!!document.querySelector("p[role=status]") && !document.querySelector('form[action="/demo/claim/select"]')`);
@@ -144,10 +162,15 @@ try {
process.stdout.write('after: keyboard choice, redirect, callback, JS auto-submit; no CSP violations\n');
await until('document.querySelector("li[aria-current=step]")?.dataset.step === "2"');
assert.equal(await evaluate('document.getElementById("claim-status").textContent'),'Starting your app');
+ assert.equal(await evaluate('document.getElementById("claim-status").getAttribute("aria-live")'),'polite');
+ assert.equal(await evaluate('getComputedStyle(document.getElementById("claim-status")).clipPath'),'inset(50%)');
+ assert.equal(await evaluate('document.querySelector("li[aria-current=step]").getBoundingClientRect().height > 1'),true);
await capture('progress');
await until('!!document.querySelector(".claim-result a")');
await capture('done');
- assert.equal(await evaluate('document.querySelector(".claim-result a").textContent'),'Open app');
+ assert.equal(await evaluate('document.querySelector(".claim-result a").textContent.replace(/^https:\\/\\//, "")'),await evaluate('document.querySelector(".claim-result a").getAttribute("href").replace(/^https:\\/\\//, "")'));
+ assert.equal(await evaluate('document.querySelector("#claim h1").textContent'),'Your demo is now a permanent app.');
+ assert.equal(await evaluate('document.querySelector("#claim").innerText.split("Your demo is now a permanent app.").length-1'),1);
assert.equal(security.length,0,JSON.stringify(security));
process.stdout.write('progress: polled to step 2 and done automatically; no CSP violations\n');
const requestsAtDone=statusRequests;
@@ -159,6 +182,7 @@ try {
await until('document.getElementById("claim-reload")?.hidden === false');
assert.equal(statusRequests-beforeFailure,3,'did not stop after three failures');
assert.equal(await evaluate('document.getElementById("claim-status").textContent'),await evaluate('document.getElementById("claim-progress").dataset.pollFailed'));
+ assert.equal(await evaluate('getComputedStyle(document.getElementById("claim-status")).clipPath'),'none','failure message hidden');
assert.equal(await evaluate('document.querySelectorAll("#claim img").length'),0,'untrusted status rendered markup');
await new Promise(r=>setTimeout(r,3500));
assert.equal(statusRequests-beforeFailure,3,'failure fallback kept polling');
@@ -171,6 +195,7 @@ try {
await until('!!document.getElementById("claim-progress")');
const beforeAbort=statusRequests;
await until('document.getElementById("claim-status")?.textContent === document.getElementById("claim-progress")?.dataset.aborted');
+ assert.equal(await evaluate('getComputedStyle(document.getElementById("claim-status")).clipPath'),'none','abort message hidden');
assert.equal(await evaluate('document.querySelectorAll("[aria-current=step]").length'),0);
await new Promise(r=>setTimeout(r,3500));
assert.equal(statusRequests-beforeAbort,1,'aborted kept polling');