carlos / platform Public

console: land Save on its outcome, refuse other-card edits, limit Retry

The outcome renders after the form, as in the mockup, under an
id="after-save" heading the form's action names, so the response opens
on it. A Save with edited or staged fields in another card is refused
with the one-at-a-time copy and writes nothing. Retry spends the same
write budget as Save.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 842f70b37034a3bc94d46c190cb656549163ece1 parent 80d3b78
6 files changed, +90 −17
  • internal/console/envcopy.go +2 −0
  • internal/console/envform.go +1 −6
  • internal/console/envform_test.go +3 −3
  • internal/console/envsave.go +8 −1
  • internal/console/envsave_test.go +70 −2
  • internal/console/templates/app_settings.html +6 −5

Intent

Human

<task-notification> <task-id>a8c12a371cf421417</task-id> <tool-use-id>toolu_011EvioLzAsagRwwe4aAN6Tb</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/abe35d56-e4c2-40df-9005-6e66b76b1f50/tasks/a8c12a371cf421417.output</output-file> <status>completed</status> <summary>Agent "Implement Task 8 Save" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE. Save writes once at the version the page showed, requests no restart, then shows "After you save". Retry (`op=check`) re-runs the check and writes nothing. Commits: 80d3b783 `console: save settings and say where they land` Tests: the targeted `-run` set (EnvSave, EnvOutcome, Task 7's Env and settings tests, ConfigPut, APIConfig, RestartWire, ReachFacts) passes, 43 s, `-count=1`. The new Chromium Save scene ran and passed: one POST, envelope only, outcome rendered. gofmt and vet are clean. Concerns: 1. The outcome is drawn at the top of the section, not after the form as in the mockup, because after Save the page loads at the top. Needs a design call. 2. A store or seal-key refusal keeps the draft, including its envelopes, so the person can retry. Value, key and sealing refusals drop what was refused. 3. If the staged card and another card both have edits, Save writes the staged one and ignores the other, per the ruling. Staging still refuses two cards at once. 4. Retry has no rate limit; each one costs a records listing and a box-report read. 5. App pages answer 500 when the console has no registry, so the no-registry test removes it mid-save through `configPutBeforeApply`. 6. All new copy is a draft for the copy pass, including blocked reasons, which are shown as the system's technical strings. Report: `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-console-secrets/.superpowers/sdd/2026-11-08-console-secrets/task-8-report.md`</result> <usage><subagent_tokens>220364</subagent_tokens><tool_uses>67</tool_uses><duration_ms>1151703</duration_ms></usage> </task-notification>

diff --git a/internal/console/envcopy.go b/internal/console/envcopy.go
index cc706c540..63a95db7e 100644
--- a/internal/console/envcopy.go
+++ b/internal/console/envcopy.go
@@ -126,6 +126,7 @@ type envPageCopy struct {
OutcomeCheckBad string
RateLimited string
NothingToSave string
+ CheckLimited string
}
// envCopyDraft is the section's copy before {console} is filled.
@@ -237,6 +238,7 @@ var envCopyDraft = envPageCopy{
OutcomeCheckBad: "Couldn't check that save again. Reload the page.",
RateLimited: "Too many changes at once. Nothing was saved. Try again in a minute.",
NothingToSave: "There's nothing to save.",
+ CheckLimited: "Too many checks at once. Try again in a minute.",
}
// envCopyFor is the section's copy for a console called consoleName.
diff --git a/internal/console/envform.go b/internal/console/envform.go
index c954e9d62..ba53e7ca3 100644
--- a/internal/console/envform.go
+++ b/internal/console/envform.go
@@ -582,16 +582,11 @@ func (s *Server) handleEnvForm(w http.ResponseWriter, r *http.Request) {
}
d, ref := parseEnvForm(r, sv.Envs)
op, _ := parseEnvOp(r.PostFormValue("op"))
- if op.verb == "save" && ref != nil && ref.Code == envRefuseOneBundle {
- // Save writes the one staged bundle (parseEnvForm's keep) and
- // ignores the other cards' fields; staging still refuses them.
- ref = nil
- }
if ref == nil && (op.verb == "save" || op.verb == "check") {
if op.verb == "save" {
s.envFormSave(w, r, p, acct, addr, d)
} else {
- s.envFormCheck(w, r, p, acct)
+ s.envFormCheck(w, r, p, acct, addr)
}
return
}
diff --git a/internal/console/envform_test.go b/internal/console/envform_test.go
index 4bcf8e6df..d8e41431a 100644
--- a/internal/console/envform_test.go
+++ b/internal/console/envform_test.go
@@ -152,7 +152,7 @@ func (e *envFx) post(t *testing.T, fields url.Values, op string) (int, string) {
}
var (
- envFormRe = regexp.MustCompile(`(?s)<form method="post" action="[^"]*/settings/environments".*?</form>`)
+ envFormRe = regexp.MustCompile(`(?s)<form method="post" action="[^"]*/settings/environments#after-save" data-env-form.*?</form>`)
envInputRe = regexp.MustCompile(`<input\b[^>]*>`)
envAttrRe = regexp.MustCompile(`([a-zA-Z_:][-a-zA-Z0-9_:.]*)(?:="([^"]*)")?`)
)
@@ -500,7 +500,7 @@ func TestEnvSecretControlsDisabledWithoutScript(t *testing.T) {
func TestEnvSealAttributes(t *testing.T) {
formTag := func(t *testing.T, body string) map[string]string {
t.Helper()
- tag := regexp.MustCompile(`<form method="post" action="[^"]*/settings/environments"[^>]*>`).FindString(body)
+ tag := regexp.MustCompile(`<form method="post" action="[^"]*/settings/environments#after-save"[^>]*>`).FindString(body)
if tag == "" {
t.Fatalf("no form:\n%s", body)
}
@@ -633,7 +633,7 @@ func TestEnvFormChromium(t *testing.T) {
t.Fatal(err)
}
page := e.page(t)
- action := html.UnescapeString(regexp.MustCompile(`<form method="post" action="([^"]*/settings/environments)"`).FindStringSubmatch(page)[1])
+ action := html.UnescapeString(regexp.MustCompile(`<form method="post" action="([^"]*/settings/environments)#after-save"`).FindStringSubmatch(page)[1])
var mu sync.Mutex
var posts []url.Values
diff --git a/internal/console/envsave.go b/internal/console/envsave.go
index 0ee590dd5..ba0129f19 100644
--- a/internal/console/envsave.go
+++ b/internal/console/envsave.go
@@ -198,9 +198,16 @@ func (s *Server) envFormSave(w http.ResponseWriter, r *http.Request, p page, acc
// Retry form carries, and no write. Only names are read from it, each
// checked; anything else is refused rather than classified as something
// it is not (fewer keys would hide a route the shadowing test should show).
-func (s *Server) envFormCheck(w http.ResponseWriter, r *http.Request, p page, acct *Account) {
+func (s *Server) envFormCheck(w http.ResponseWriter, r *http.Request, p page, acct *Account, addr string) {
sv := p.Settings
c := sv.EnvCopy
+ // The same budget as Save: each check reads the app's records and box
+ // reports.
+ if !s.allowWrite(Principal{Kind: PrincipalUser, Address: addr}, time.Now()) {
+ sv.EnvError = c.CheckLimited
+ s.render(w, http.StatusTooManyRequests, "app_settings", p)
+ return
+ }
bundle := r.PostFormValue("check_bundle")
card := envCardFor(sv.Envs, bundle)
keys := r.PostForm["check_key"]
diff --git a/internal/console/envsave_test.go b/internal/console/envsave_test.go
index fd02fe920..a933d7698 100644
--- a/internal/console/envsave_test.go
+++ b/internal/console/envsave_test.go
@@ -78,8 +78,6 @@ func TestEnvSaveWritesOnceNoRestart(t *testing.T) {
f.Set("val.default.LOG_LEVEL", "warn")
f.Set("env.default.STRIPE_KEY", replaced)
f.Set("bundle", "default")
- // An edit in another card is not this Save's: ignored, never written.
- f.Set("val.staging.LOG_LEVEL", "trace")
status, body := e.post(t, f, "save")
if status != http.StatusOK {
t.Fatalf("save = %d:\n%s", status, body)
@@ -122,6 +120,12 @@ func TestEnvSaveWritesOnceNoRestart(t *testing.T) {
"Nothing on this box uses these settings.", "Copies on other boxes may not all be listed here.",
`href="/a/`+e.fx.srv.mustAccountName(t)+`/apps/shop/instances">See what&#39;s running</a>`)
mustNotContain(t, out, "unused", "Unused", "<button")
+ // The browser lands on the outcome: the form's action names it, and it
+ // comes after the form, as in the mockup.
+ mustContain(t, body, `/apps/shop/settings/environments#after-save" data-env-form`, `<h2 id="after-save">After you save</h2>`)
+ if strings.Index(body, `id="after-save"`) < strings.Index(body, "data-env-form") {
+ t.Fatal("the outcome is drawn before the form")
+ }
// The audit row: counts and the bundle, naming this door; no content.
events, err := e.fx.st.Events(OpsAccountID, "shop", 20)
@@ -569,3 +573,67 @@ func TestEnvSaveRateLimited(t *testing.T) {
}
t.Fatalf("Save was never rate-limited in %d attempts", cliWriteBurst+3)
}
+
+// TestEnvSaveRefusesOtherBundleEdits: an edit or a staged field in a card
+// other than the one being saved is never dropped silently. The Save is
+// refused with the one-at-a-time copy, nothing is written, the draft stays.
+func TestEnvSaveRefusesOtherBundleEdits(t *testing.T) {
+ for name, edit := range map[string]func(url.Values){
+ "edited value": func(f url.Values) { f.Set("val.staging.LOG_LEVEL", "trace") },
+ "staged field": func(f url.Values) { f.Set("new.staging.OTHER", "x") },
+ } {
+ t.Run(name, func(t *testing.T) {
+ e := newEnvFx(t)
+ e.saving()
+ if _, err := appconfig.ApplyEnvironment(context.Background(), e.fx.rel, e.fx.sqid, "shop", "staging",
+ map[string]appconfig.Var{"LOG_LEVEL": {Kind: "env", Value: "debug"}}, nil); err != nil {
+ t.Fatal(err)
+ }
+ e.saving()
+ f := envFields(t, e.page(t))
+ f.Set("val.default.LOG_LEVEL", "warn")
+ f.Set("bundle", "default")
+ edit(f)
+ status, body := e.post(t, f, "save")
+ if status != http.StatusBadRequest {
+ t.Fatalf("save = %d, want 400", status)
+ }
+ mustContain(t, envBanner(body), "You can change one environment at a time. Save or discard your changes to All environments first.")
+ mustContain(t, body, `name="val.default.LOG_LEVEL" value="warn"`, `name="bundle" value="default"`)
+ mustNotContain(t, body, `class="env-outcome"`)
+ if w := e.written(); len(w) != 0 {
+ t.Fatalf("wrote %v", w)
+ }
+ if m := e.stored(t); m.Vars["LOG_LEVEL"].Value != "info" {
+ t.Fatalf("default moved: %+v", m.Vars)
+ }
+ })
+ }
+}
+
+// TestEnvSaveCheckRateLimited: Retry spends Save's budget.
+func TestEnvSaveCheckRateLimited(t *testing.T) {
+ e := newEnvFx(t)
+ csrf := envFields(t, e.page(t)).Get("csrf")
+ for i := 0; i < cliWriteBurst+3; i++ {
+ status, _, body := postForm(t, e.c, e.fx.u("/apps/shop/settings/environments"),
+ url.Values{"csrf": {csrf}, "op": {"check"}, "check_bundle": {"default"}, "check_key": {"LOG_LEVEL"}})
+ if status == http.StatusOK {
+ continue
+ }
+ if status != http.StatusTooManyRequests || i == 0 {
+ t.Fatalf("check %d = %d", i, status)
+ }
+ mustContain(t, envBanner(body), "Too many checks at once. Try again in a minute.")
+ mustNotContain(t, body, `class="env-outcome"`)
+ // The same budget: a Save now is refused too.
+ f := envFields(t, e.page(t))
+ f.Set("val.default.LOG_LEVEL", "warn")
+ if status, _ := e.post(t, f, "save"); status != http.StatusTooManyRequests {
+ t.Fatalf("save after the checks = %d, want 429", status)
+ }
+ e.spy.none(t)
+ return
+ }
+ t.Fatalf("check was never rate-limited in %d attempts", cliWriteBurst+3)
+}
diff --git a/internal/console/templates/app_settings.html b/internal/console/templates/app_settings.html
index 2da9130e2..d18f34742 100644
--- a/internal/console/templates/app_settings.html
+++ b/internal/console/templates/app_settings.html
@@ -635,8 +635,8 @@ blocks deletion. Turn the safety delay off on the <a href="{{.Nav}}/apps/{{.AppN
<h2>Environments</h2>
<p class="small">{{$c.Intro}}</p>
{{if $s.EnvError}}<p class="banner error" role="alert">{{$s.EnvError}}</p>{{end}}
-{{with $s.EnvOutcome}}{{template "app_settings_env_outcome" $}}{{end}}
-<form method="post" action="{{.Nav}}/apps/{{.Detail.App}}/settings/environments" data-env-form{{with $seal}} data-seal-pub="{{.Pub}}" data-seal-version="{{.Version}}"{{if .Account}} data-account="{{.Account}}" data-app="{{.App}}"{{end}} data-msg-chars="{{$c.MsgChars}}" data-msg-empty="{{$c.MsgEmpty}}" data-msg-seal="{{$c.MsgSeal}}" data-msg-changed="{{$c.MsgChanged}}"{{end}}>
+{{/* #after-save: the answer to a Save lands on its outcome, below the form. */}}
+<form method="post" action="{{.Nav}}/apps/{{.Detail.App}}/settings/environments#after-save" data-env-form{{with $seal}} data-seal-pub="{{.Pub}}" data-seal-version="{{.Version}}"{{if .Account}} data-account="{{.Account}}" data-app="{{.App}}"{{end}} data-msg-chars="{{$c.MsgChars}}" data-msg-empty="{{$c.MsgEmpty}}" data-msg-seal="{{$c.MsgSeal}}" data-msg-changed="{{$c.MsgChanged}}"{{end}}>
<input type="hidden" name="csrf" value="{{.CSRF}}">
{{/* The form's default button: Enter in any field stages (an add row with a name adds). */}}
<button type="submit" name="op" value="stage" class="visually-hidden" tabindex="-1" aria-hidden="true">{{$c.Stage}}</button>
@@ -715,6 +715,7 @@ blocks deletion. Turn the safety delay off on the <a href="{{.Nav}}/apps/{{.AppN
</div>
<noscript><style>.savebar[hidden] { display: flex; }</style></noscript>
</form>
+{{with $s.EnvOutcome}}{{template "app_settings_env_outcome" $}}{{end}}
<script>
(function () {
var form = document.querySelector("form[data-env-form]");
@@ -734,8 +735,8 @@ blocks deletion. Turn the safety delay off on the <a href="{{.Nav}}/apps/{{.AppN
classifier. Expectations only; observed state is the Running page's,
linked. No restart control anywhere in it: Save requests none. */}}
{{define "app_settings_env_outcome"}}{{$c := .Settings.EnvCopy}}{{$o := .Settings.EnvOutcome}}{{$run := printf "%s/apps/%s/instances" .Nav .Detail.App}}
-<section class="env-outcome" role="status" aria-labelledby="env-outcome-head">
-<h3 id="env-outcome-head">{{$c.OutcomeHead}}</h3>
+<section class="env-outcome" role="status" aria-labelledby="after-save">
+<h2 id="after-save">{{$c.OutcomeHead}}</h2>
{{if $o.Count}}<p class="banner">{{$c.SavedLine $o}}</p>{{end}}
{{if $o.Unknown}}<p class="small">{{$c.OutcomeUnknown}}</p>
{{else if $o.Empty}}<p class="small">{{$c.OutcomeNone}}</p>
@@ -778,7 +779,7 @@ blocks deletion. Turn the safety delay off on the <a href="{{.Nav}}/apps/{{.AppN
<li><strong>{{$c.OutcomeUndeliv}}:</strong> {{$c.UndelivLine $.Detail.App}}</li>{{end}}
</ul>
{{end}}
-{{if or $o.Unknown $o.Unresolved}}<form method="post" action="{{.Nav}}/apps/{{.Detail.App}}/settings/environments" class="inline">
+{{if or $o.Unknown $o.Unresolved}}<form method="post" action="{{.Nav}}/apps/{{.Detail.App}}/settings/environments#after-save" class="inline">
<input type="hidden" name="csrf" value="{{.CSRF}}">
<input type="hidden" name="check_bundle" value="{{$o.CheckBundle}}">
{{- range $o.CheckKeys}}