carlos / platform Public

console: env form refuses up front when any bundle read fails

Paul's ruling on Astra R2: a post whose default bundle, listing or any
named bundle fails to read is refused with nothing written and nothing
drawn back; the carry path is removed. Envelope fields (env, newenv,
addenv) are validated once in envClassify, before any op.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 3eaf36e50c31fb0fb4a75f169573f1b4da030ba6 parent fcf3582
5 files changed, +233 −133
  • internal/console/appsettings.go +14 −15
  • internal/console/envcopy.go +12 −16
  • internal/console/envform.go +33 −49
  • internal/console/envformgate_test.go +162 −36
  • internal/console/templates/app_settings.html +12 −17

CI passed — run details

Intent

Human

<task-notification> <task-id>aaa8a054b8ad8a18f</task-id> <tool-use-id>toolu_01QDBMgtN8kNG5m7vsdTvwe9</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/abe35d56-e4c2-40df-9005-6e66b76b1f50/tasks/aaa8a054b8ad8a18f.output</output-file> <status>completed</status> <summary>Agent "Fix CI gate failures" 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>All five CI gate items are fixed and each failing test passes in a targeted run; full suites were not run, CI does that. Commits: 5010abb6, 441cc05a, 6b53c2a0, ceaaed99, fcf35828 (one per item). 1. CLI config door now uses local facts only; Save/Retry keep `reachFacts`. TestPerfWriteRoutesMeetTheBudget passes: config put 10 S3, median 340.9 ms (ceiling 750 ms, unchanged). The page Save test still lists record-only hosts. 2. Session S3 ceiling raised 416 to 418. Measured: removing the default-bundle read takes the page from 6 to 5 S3 and the session back to 416, so the delta is exactly 2. TestPerfSessionS3Requests passes. 3. Expected substrings updated to the new `envhead` / `envvar-name` markup. TestSettingsSectionReadsOnlyItsOwn passes. 4. Route added as a mutation door beside promote/restart, plus a line in testdata/claim-routes.txt. All five claim census tests pass. 5. The rejected site was `NewServer` in server.go, digest only: its one change is this branch's route line, and that route writes the config bundle, no instance or sidecar record. Re-pinned in a new `internal/provision/console_secrets_census_test.go`, class and kinds unchanged. TestPlan9B8RecordWriteCensus passes. Concerns: the CLI door no longer lists unseen or asleep hosts, the cost the ruling accepted; envform.go untouched. Report: `.superpowers/sdd/2026-11-08-console-secrets/ci-fix-report.md` (git-ignored, not committed).</result> <usage><subagent_tokens>140821</subagent_tokens><tool_uses>63</tool_uses><duration_ms>1069485</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>bfn28q087</task-id> <tool-use-id>toolu_01N5Uxdq9MsECPYDBeBeoCUk</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/abe35d56-e4c2-40df-9005-6e66b76b1f50/tasks/bfn28q087.output</output-file> <status>completed</status> <summary>Background command "sleep 120; for i in $(seq 1 90); do amadan ci status carlos/platform -branch design-console-secrets &gt;$HOME/.cache/console-secrets-copy/ci.txt 2&gt;&amp;1; rc=$?; grep -q fcf35828 $HOME/.cache/console-secrets-copy/ci.txt || { sleep 60; continue; }; [ $rc -eq 0 -o $rc -eq 1 ] &amp;&amp; break; sleep 60; done; echo rc=$rc; head -5 $HOME/.cache/console-secrets-copy/ci.txt" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 27.1 g CO₂e (3,389,699 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-console-secrets, 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/appsettings.go b/internal/console/appsettings.go
index 6a83ac90b..829ea82da 100644
--- a/internal/console/appsettings.go
+++ b/internal/console/appsettings.go
@@ -119,9 +119,11 @@ type SettingsView struct {
// Editable by any account member (EnvCanEdit, envform.go); ordinary
// values are shown, secrets by name only.
Envs []*EnvCard
- // EnvsUnavailable distinguishes a failed listing from an app that
- // genuinely has none, so the section does not claim "no environments"
- // during a transient bucket failure — StoreUnavailable's rule.
+ // EnvsUnavailable distinguishes a failed read (the default bundle, the
+ // listing or any named bundle) from an app that genuinely has none, so
+ // the section does not claim "no environments" during a transient
+ // bucket failure — StoreUnavailable's rule. The editable section draws
+ // no cards then, and its form refuses every post up front.
EnvsUnavailable bool
// EnvCanEdit: the section is a form (any account member, as with the
// CLI doors for a person). False keeps the read-only text.
@@ -142,9 +144,6 @@ type SettingsView struct {
// EnvOutcome is "After you save" (envsave.go): set after a Save that
// wrote, or a Retry; nil otherwise.
EnvOutcome *envOutcome
- // EnvCarry is a post's draft drawn back as it came, when the bundles
- // could not be read to draw it against (Save is off until they can).
- EnvCarry []envCarryField
// EnvCopy is the section's words; ConfigSealJS the sealing script the
// page inlines.
EnvCopy envPageCopy
@@ -560,15 +559,15 @@ func (s *Server) storeCard(ctx context.Context, acct *Account, app string) *Stor
// envCards is the default bundle's card, then one card per named config
// environment sorted by name, with the second return saying a read failed
-// (the default bundle or the listing): the difference between "this app
-// has no environments" and "I could not find out", which the section must
-// not collapse. Read budget (spec, codex 9): one GetBundle for the default
-// bundle, the listing, and one GetBundle per named bundle.
+// (the default bundle, the listing, or any named bundle): the difference
+// between "this app has no environments" and "I could not find out", which
+// the section must not collapse. Read budget (spec, codex 9): one GetBundle
+// for the default bundle, the listing, and one GetBundle per named bundle.
//
-// A single unreadable named bundle is skipped and logged rather than
-// blanking the list: the other environments are real, their instances are
-// really bound to them, and their stores are really billing. Same trade
-// storeEnvCards makes, for the same reason.
+// An unreadable named bundle makes the whole list unavailable, never a
+// card silently skipped: the editable form draws a post against every
+// card, and a missing one would drop its edits or let Save past the
+// one-bundle rule (Astra R2 P1-2). storeEnvCards, read-only, still skips.
func (s *Server) envCards(ctx context.Context, acct *Account, app string, routes []RouteView) ([]*EnvCard, bool) {
m, ver, err := appconfig.GetBundle(ctx, s.cfg.Releases, acct.Sqid, app, "")
if err != nil {
@@ -585,7 +584,7 @@ func (s *Server) envCards(ctx context.Context, acct *Account, app string, routes
m, ver, merr := appconfig.GetBundle(ctx, s.cfg.Releases, acct.Sqid, app, name)
if merr != nil {
log.Printf("console: settings environment %s/%s/%s: %v", acct.Sqid, app, name, merr)
- continue
+ return cards, true
}
card := envCardOf(name, m, ver, routes)
// The store is read through the same door the storage section uses,
diff --git a/internal/console/envcopy.go b/internal/console/envcopy.go
index 8333caf6d..e6dfb6c0b 100644
--- a/internal/console/envcopy.go
+++ b/internal/console/envcopy.go
@@ -58,13 +58,12 @@ type envPageCopy struct {
ChangeRemoved string // {name}
// Refusals while staging.
- OneBundle string // {env}
- Unsealed string
- AddNoName string
- AddNameTaken string // {name} {env}
- AddEmptySec string
- CouldNotRead string
- EnvelopeStale string // {name}
+ OneBundle string // {env}
+ Unsealed string
+ AddNoName string
+ AddNameTaken string // {name} {env}
+ AddEmptySec string
+ CouldNotRead string
// The browser sealing script's refusals (data-msg-* on the form).
MsgChars string
@@ -175,13 +174,12 @@ var envCopyDraft = envPageCopy{
ChangeSecret: "new value for secret {name}",
ChangeRemoved: "{name} removed",
- OneBundle: "You can change one environment at a time. Save or discard your changes to {env} first.",
- Unsealed: "A secret reached {console} without being sealed in your browser, so it was thrown away. If it was a real credential, treat it as exposed and replace it.",
- AddNoName: "Give the setting a name.",
- AddNameTaken: "{name} is already set in {env}. Use Edit to change it.",
- AddEmptySec: "A secret can't be empty.",
- CouldNotRead: "Couldn't read this app's settings just now. Try again in a moment.",
- EnvelopeStale: "The sealed value for {name} couldn't be read, so it was dropped. Enter it again.",
+ OneBundle: "You can change one environment at a time. Save or discard your changes to {env} first.",
+ Unsealed: "A secret reached {console} without being sealed in your browser, so it was thrown away. If it was a real credential, treat it as exposed and replace it.",
+ AddNoName: "Give the setting a name.",
+ AddNameTaken: "{name} is already set in {env}. Use Edit to change it.",
+ AddEmptySec: "A secret can't be empty.",
+ CouldNotRead: "Couldn't read this app's settings just now. Try again in a moment.",
MsgChars: "A value can't contain a backslash, a quote, a line break or a NUL character.",
MsgEmpty: "A secret can't be empty.",
@@ -321,8 +319,6 @@ func (c envPageCopy) staging(ref *envFormRefusal) string {
envRefuseTaken: c.AddNameTaken,
envRefuseEmptySec: c.AddEmptySec,
envRefuseVarValue: c.RefVarValue,
- envRefuseEnvelope: c.EnvelopeStale,
- envRefuseUnread: c.CouldNotRead,
envRefuseKeyChange: c.KeyChanged,
}[ref.Code]
return envFill(line, "name", ref.Var, "env", ref.Env)
diff --git a/internal/console/envform.go b/internal/console/envform.go
index 77061c0b9..64a1307f9 100644
--- a/internal/console/envform.go
+++ b/internal/console/envform.go
@@ -35,9 +35,15 @@
// <b> is "default" for the default bundle or the environment's name. Only
// rm.<b> and check_key repeat. Anything else posted twice, any field the
// protocol does not name, any secret plaintext (a non-empty sec.*, or an
-// add row ticked Secret that still carries its value, on ANY op), and two
+// add row ticked Secret that still carries its value, on ANY op), any
+// non-empty env.*, newenv.* or addenv.* that is not an envelope, and two
// fields staging one var two ways are refused with the Unsealed copy before
// any op runs: nothing is drawn back and nothing is written.
+//
+// A post is drawn against every card as read now. If any read fails (the
+// default bundle, the listing, or any named bundle), the section is
+// unavailable for that request: nothing is written and nothing posted is
+// drawn back; the page says so and offers Try again, a plain reload.
package console
import (
@@ -262,8 +268,6 @@ const (
envRefuseTaken = "taken"
envRefuseEmptySec = "empty-secret"
envRefuseVarValue = "var-value"
- envRefuseEnvelope = "envelope"
- envRefuseUnread = "unread"
envRefuseKeyChange = "key-changed"
)
@@ -325,10 +329,12 @@ const envFormMaxFields = 2000
// draft): a field the protocol does not name, a field that may appear once
// posted twice, a Secret flag other than "" or "1", secret plaintext (a
// non-empty sec.*, or any card's add row ticked Secret that still carries
-// its value), a val without the orig it was drawn with (or the reverse), a
-// carried envelope without its key (or the reverse), or one var staged two
-// ways at once. Every op passes through it: Save, Retry, Remove and
-// Discard as much as Add.
+// its value), a non-empty env.*, newenv.* or addenv.* that is not an
+// envelope (appconfig.CheckEnvelope: the one place envelope fields are
+// validated, whatever storage does next), a val without the orig it was
+// drawn with (or the reverse), a carried envelope without its key (or the
+// reverse), or one var staged two ways at once. Every op passes through it:
+// Save, Retry, Remove and Discard as much as Add.
func envClassify(form url.Values) bool {
type varKey struct{ b, n string }
ways := map[varKey]int{}
@@ -369,6 +375,9 @@ func envClassify(form url.Values) bool {
if _, ok := form["fp."+b+"."+n]; !ok {
return true
}
+ if appconfig.CheckEnvelope(v) != nil {
+ return true
+ }
ways[varKey{b, n}]++
case "fp":
if _, ok := form["newenv."+b+"."+n]; !ok {
@@ -378,8 +387,15 @@ func envClassify(form url.Values) bool {
ways[varKey{b, n}]++
case "env":
if v != "" {
+ if appconfig.CheckEnvelope(v) != nil {
+ return true
+ }
ways[varKey{b, n}]++
}
+ case "addenv":
+ if v != "" && appconfig.CheckEnvelope(v) != nil {
+ return true
+ }
case "rm":
for _, rn := range vs {
ways[varKey{b, rn}]++
@@ -463,13 +479,10 @@ func parseEnvForm(form url.Values, cards []*EnvCard) (*envDraft, *envFormRefusal
d.New[name] = vs[0]
}
case "env", "newenv":
+ // envClassify has checked the envelope.
if vs[0] == "" || !appconfig.ValidVarName(name) {
continue
}
- if appconfig.CheckEnvelope(vs[0]) != nil {
- refuse(&envFormRefusal{Code: envRefuseEnvelope, Var: name})
- continue
- }
fp := sealedTo
if kind == "newenv" {
fp = form.Get("fp." + b + "." + name)
@@ -558,7 +571,8 @@ func parseEnvForm(form url.Values, cards []*EnvCard) (*envDraft, *envFormRefusal
// envAdd stages the add row of card into d, or says why not. A secret row
// arrives sealed (addenv.<b>, sealed to sealedTo) with its value field gone
-// (envClassify has already refused one that still carries it).
+// (envClassify has already refused one that still carries it, and any
+// addenv that is not an envelope).
func envAdd(form url.Values, card *EnvCard, d *envDraft, sealedTo string) *envFormRefusal {
b := card.Bundle
name := strings.TrimSpace(form.Get("add." + b + ".name"))
@@ -593,9 +607,6 @@ func envAdd(form url.Values, card *EnvCard, d *envDraft, sealedTo string) *envFo
if envelope == "" {
return redraw(envRefuseEmptySec)
}
- if appconfig.CheckEnvelope(envelope) != nil {
- return redraw(envRefuseEnvelope)
- }
d.Secrets[name] = envSecret{Envelope: envelope, FP: sealedTo}
return nil
}
@@ -666,34 +677,6 @@ func applyEnvDraft(sv *SettingsView, d *envDraft, ref *envFormRefusal) {
}
}
-// envCarryField is one posted field drawn back as it came (EnvCarry).
-type envCarryField struct{ Name, Value string }
-
-// envCarry is a post's draft fields as they came, for a response that
-// could not read the bundles to draw them against: nothing the person
-// staged is lost to a read that failed, and nothing is written until the
-// bundles read again. The post has been through envClassify, so none of it
-// is plaintext.
-func envCarry(form url.Values) []envCarryField {
- var out []envCarryField
- for k, vs := range form {
- switch k {
- case "csrf", "op", "check_bundle", "check_key":
- continue
- }
- for _, v := range vs {
- out = append(out, envCarryField{k, v})
- }
- }
- sort.Slice(out, func(i, j int) bool {
- if out[i].Name != out[j].Name {
- return out[i].Name < out[j].Name
- }
- return out[i].Value < out[j].Value
- })
- return out
-}
-
// handleEnvForm is the Environments section's one form. Admission, the
// same for every op and in this order: the session; a total body cap; the
// URL-encoded content type only (no multipart, so no file parts and no
@@ -701,7 +684,8 @@ func envCarry(form url.Values) []envCarryField {
// membership and the app (accountApp: a non-member's 404 is an unknown
// app's); the write budget, one for every op; and only then the page and
// the bundle reads. Then the whole request is classified (envClassify)
-// before any op runs. Nothing here writes: Save goes to envFormSave
+// before any op runs, and a post whose bundles did not all read is refused
+// up front with nothing drawn back. Nothing here writes: Save goes to envFormSave
// (envsave.go), the one write, and Retry to envFormCheck, which only reads.
func (s *Server) handleEnvForm(w http.ResponseWriter, r *http.Request) {
_, raw, sok := s.session(r)
@@ -762,11 +746,11 @@ func (s *Server) handleEnvForm(w http.ResponseWriter, r *http.Request) {
return
}
if sv == nil || !sv.EnvCanEdit || sv.EnvsUnavailable {
- if sv != nil && sv.EnvCanEdit {
- sv.EnvError = sv.EnvCopy.staging(&envFormRefusal{Code: envRefuseUnread})
- // The draft rides along as posted, and Save is off until the
- // bundles read again.
- sv.Envs, sv.EnvCarry = nil, envCarry(r.PostForm)
+ // Refused up front: nothing is written and nothing posted is drawn
+ // back (no draft, no envelopes, no values, no fingerprints). The
+ // section says it could not read the settings and offers a reload.
+ if sv != nil {
+ sv.Envs, sv.EnvDraft, sv.EnvSummary, sv.EnvError = nil, nil, "", ""
}
s.render(w, http.StatusConflict, "app_settings", p)
return
diff --git a/internal/console/envformgate_test.go b/internal/console/envformgate_test.go
index e16c402c3..adf2a7675 100644
--- a/internal/console/envformgate_test.go
+++ b/internal/console/envformgate_test.go
@@ -351,51 +351,177 @@ func TestEnvFormBoundedInput(t *testing.T) {
}
}
-// A bundle that will not read keeps the posted draft (values, envelopes,
-// their keys, versions) with Save off; once it reads again, the carried
-// draft saves.
-func TestEnvSaveReadRefusalKeepsDraft(t *testing.T) {
- e := newEnvFx(t)
- e.saving()
- f := envFields(t, e.page(t))
- env := e.seal(t, "carried")
- f.Set("add.default.name", "WEBHOOK_SECRET")
- f.Set("add.default.secret", "1")
- f.Del("add.default.value")
- f.Set("addenv.default", env)
- status, body := e.post(t, f, "add:default")
- if status != http.StatusOK {
- t.Fatalf("add = %d", status)
- }
- f = envFields(t, body)
- f.Set("new.default.MODE", "fast")
- ver := f.Get("ver.default")
-
+// failRead makes key fail every read ("" heals it).
+func (e *envFx) failRead(key string) {
e.spy.mu.Lock()
- e.spy.failGet = appconfig.Key(e.fx.sqid, "shop")
+ e.spy.failGet = key
e.spy.mu.Unlock()
- status, body = e.post(t, f, "save")
+}
+
+// envUnreadLine is the section's line when a bundle did not read.
+const envUnreadLine = "Couldn&#39;t read this app&#39;s settings just now. Try again in a moment."
+
+// mustRefuseUnread: the post was refused up front because a bundle did not
+// read. Nothing was written (not the bundle, not the generation), no form
+// is drawn, nothing posted comes back, and Try again is a plain reload.
+func (e *envFx) mustRefuseUnread(t *testing.T, status int, body string, posted ...string) {
+ t.Helper()
if status != http.StatusConflict {
- t.Fatalf("save on an unreadable bundle = %d", status)
+ t.Fatalf("status = %d, want 409:\n%s", status, envBanner(body))
}
e.noWrites(t)
- mustContain(t, body, `name="new.default.MODE" value="fast"`, `name="newenv.default.WEBHOOK_SECRET" value="`,
- `name="fp.default.WEBHOOK_SECRET" value="`+f.Get("sealed_to")+`"`, `name="ver.default" value="`+ver+`"`,
- `name="op" value="stage" data-seal-skip>Try again</button>`)
- mustNotContain(t, body, `name="op" value="save"`)
- if got := envFields(t, body).Get("newenv.default.WEBHOOK_SECRET"); got != env {
- t.Fatalf("carried envelope = %q", got)
+ mustContain(t, body, envUnreadLine, `/apps/shop/settings/environments">Try again</a>`)
+ mustNotContain(t, body, "data-env-form", `name="newenv.`, `name="fp.`, `name="env.`, `name="new.`, `name="val.`,
+ `name="op" value="save"`, `class="env-outcome"`)
+ mustNotContain(t, body, posted...)
+}
+
+// Paul's ruling on R2: any bundle read failure on a post refuses it up
+// front. The default bundle failing, with plaintext in each envelope field
+// (Astra R2 P1-1's reproductions), is refused and nothing posted is echoed;
+// so is a well-formed draft, envelope and fingerprint included.
+func TestEnvFormUnreadDefaultRefusesAndEchoesNothing(t *testing.T) {
+ const plain = "review-r2-unsealed-credential"
+ cases := map[string]func(f url.Values){
+ "env": func(f url.Values) { f.Set("env.default.STRIPE_KEY", plain) },
+ "newenv": func(f url.Values) {
+ f.Set("newenv.default.NEW_SECRET", plain)
+ f.Set("fp.default.NEW_SECRET", f.Get("sealed_to"))
+ },
+ "addenv": func(f url.Values) {
+ f.Set("add.default.name", "API_TOKEN")
+ f.Set("add.default.secret", "1")
+ f.Del("add.default.value")
+ f.Set("addenv.default", plain)
+ },
+ }
+ for name, edit := range cases {
+ t.Run(name, func(t *testing.T) {
+ e := newEnvFx(t)
+ e.saving()
+ f := envFields(t, e.page(t))
+ edit(f)
+ e.failRead(appconfig.Key(e.fx.sqid, "shop"))
+ status, body := e.post(t, f, "save")
+ if status != http.StatusBadRequest && status != http.StatusConflict {
+ t.Fatalf("status = %d", status)
+ }
+ e.noWrites(t)
+ mustNotContain(t, body, plain, "API_TOKEN", "NEW_SECRET", `name="newenv.`, `name="fp.`, `class="env-outcome"`)
+ })
}
+ t.Run("valid draft", func(t *testing.T) {
+ e := newEnvFx(t)
+ e.saving()
+ f := envFields(t, e.page(t))
+ env := e.seal(t, "carried")
+ f.Set("new.default.MODE", "fast-r2")
+ f.Set("newenv.default.WEBHOOK_SECRET", env)
+ f.Set("fp.default.WEBHOOK_SECRET", f.Get("sealed_to"))
+ f.Set("bundle", "default")
+ e.failRead(appconfig.Key(e.fx.sqid, "shop"))
+ for _, op := range []string{"save", "stage", "add:default", "check"} {
+ status, body := e.post(t, f, op)
+ e.mustRefuseUnread(t, status, body, "fast-r2", "MODE", "WEBHOOK_SECRET", env, f.Get("sealed_to"))
+ }
+ // Healed, a fresh page saves as usual: nothing was kept to carry.
+ e.failRead("")
+ f = envFields(t, e.page(t))
+ f.Set("val.default.LOG_LEVEL", "warn")
+ if status, body := e.post(t, f, "save"); status != http.StatusOK {
+ t.Fatalf("save once it reads = %d: %s", status, envBanner(body))
+ }
+ if got := e.stored(t).Vars["LOG_LEVEL"].Value; got != "warn" {
+ t.Fatalf("stored LOG_LEVEL = %q", got)
+ }
+ })
+}
- e.spy.mu.Lock()
- e.spy.failGet = ""
- e.spy.mu.Unlock()
- if status, body = e.post(t, envFields(t, body), "save"); status != http.StatusOK {
- t.Fatalf("save once it reads = %d:\n%s", status, envBanner(body))
+// The same malformed envelope fields with storage healthy are refused by
+// classification, on every op, and nothing is written or echoed.
+func TestEnvFormMalformedEnvelopeRefused(t *testing.T) {
+ const plain = "review-r2-healthy-plaintext"
+ cases := map[string]func(f url.Values){
+ "env": func(f url.Values) { f.Set("env.default.STRIPE_KEY", plain) },
+ "newenv": func(f url.Values) {
+ f.Set("newenv.default.NEW_SECRET", plain)
+ f.Set("fp.default.NEW_SECRET", f.Get("sealed_to"))
+ },
+ "addenv": func(f url.Values) {
+ f.Set("add.default.name", "API_TOKEN")
+ f.Set("add.default.secret", "1")
+ f.Del("add.default.value")
+ f.Set("addenv.default", plain)
+ },
+ }
+ for name, edit := range cases {
+ for _, op := range []string{"save", "stage", "add:default", "discard"} {
+ t.Run(name+"/"+op, func(t *testing.T) {
+ e := newEnvFx(t)
+ e.saving()
+ f := envFields(t, e.page(t))
+ f.Set("val.default.LOG_LEVEL", "warn")
+ edit(f)
+ status, body := e.post(t, f, op)
+ if status != http.StatusBadRequest {
+ t.Fatalf("status = %d", status)
+ }
+ mustContain(t, body, envUnsealedLine)
+ mustNotContain(t, body, plain, "API_TOKEN", "NEW_SECRET", `value="warn"`, `class="env-outcome"`)
+ e.noWrites(t)
+ })
+ }
}
- if m := e.stored(t); m.Vars["MODE"].Value != "fast" || m.Vars["WEBHOOK_SECRET"].Envelope != env {
- t.Fatalf("stored = %+v", m.Vars)
+}
+
+// A named bundle that will not read makes the whole section unavailable
+// for a post, never a card silently skipped (Astra R2 P1-2): a named-only
+// edit is refused and not echoed, and edits in the default and named cards
+// together are refused with nothing written.
+func TestEnvFormUnreadNamedBundleRefused(t *testing.T) {
+ setup := func(t *testing.T) (*envFx, url.Values) {
+ e := newEnvFx(t)
+ 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))
+ if f.Get("orig.staging.LOG_LEVEL") != "debug" {
+ t.Fatalf("no staging card: %v", f)
+ }
+ return e, f
}
+ t.Run("named only", func(t *testing.T) {
+ e, f := setup(t)
+ f.Set("val.staging.LOG_LEVEL", "error-r2")
+ f.Set("bundle", "staging")
+ e.failRead(appconfig.EnvironmentKey(e.fx.sqid, "shop", "staging"))
+ status, body := e.post(t, f, "save")
+ e.mustRefuseUnread(t, status, body, "error-r2", "There's nothing to save")
+ })
+ t.Run("default and named", func(t *testing.T) {
+ e, f := setup(t)
+ f.Set("val.staging.LOG_LEVEL", "error-r2")
+ f.Set("val.default.LOG_LEVEL", "warn-r2")
+ f.Set("bundle", "default")
+ e.failRead(appconfig.EnvironmentKey(e.fx.sqid, "shop", "staging"))
+ status, body := e.post(t, f, "save")
+ e.mustRefuseUnread(t, status, body, "error-r2", "warn-r2")
+ if got := e.stored(t).Vars["LOG_LEVEL"].Value; got != "info" {
+ t.Fatalf("default LOG_LEVEL = %q, want untouched", got)
+ }
+ })
+ t.Run("get", func(t *testing.T) {
+ e, _ := setup(t)
+ e.failRead(appconfig.EnvironmentKey(e.fx.sqid, "shop", "staging"))
+ status, _, body := get(t, e.c, e.fx.u("/apps/shop/settings/environments"))
+ if status != http.StatusOK {
+ t.Fatalf("GET = %d", status)
+ }
+ mustContain(t, body, envUnreadLine)
+ mustNotContain(t, body, "data-env-form")
+ })
}
// CSRF comes before membership and the app (a bad token reads the same for
diff --git a/internal/console/templates/app_settings.html b/internal/console/templates/app_settings.html
index f288e814f..65a338c89 100644
--- a/internal/console/templates/app_settings.html
+++ b/internal/console/templates/app_settings.html
@@ -266,7 +266,7 @@ offers the final console-record step.</p>
{{end}}
{{if eq .SettingsSection "environments"}}
{{if .Settings.NoBucket}}<p class="banner error">no deployment bucket on this host — this console cannot read config</p>{{end}}
-{{if .Settings.EnvsUnavailable}}<p class="banner error">Could not read this app's environments. Please try again.</p>{{end}}
+{{if and .Settings.EnvsUnavailable (not .Settings.EnvCanEdit)}}<p class="banner error">Could not read this app's environments. Please try again.</p>{{end}}
{{if .Settings}}{{if .Settings.EnvCanEdit}}{{template "app_settings_envs" .}}{{else}}
<h2>Environments</h2>
<p class="small">A named environment is a config bundle that overlays this
@@ -635,14 +635,19 @@ 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}}
+{{- if $s.EnvsUnavailable}}
+{{/* A bundle, or the listing, did not read: no cards and no form, so no
+ post is drawn against a partial list and nothing posted is drawn
+ back. Try again is a plain reload. */}}
+<p class="banner error" role="alert">{{$c.CouldNotRead}} <a href="{{.Nav}}/apps/{{.Detail.App}}/settings/environments">{{$c.TryAgain}}</a></p>
+{{- else}}
{{/* #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>
- {{- if not $s.EnvCarry}}{{/* carried as posted otherwise, sealed_to naming the key the carried envelopes were sealed to */}}
<input type="hidden" name="bundle" value="{{if $d}}{{if not $d.Empty}}{{$d.Bundle}}{{end}}{{end}}">
- {{with $seal}}<input type="hidden" name="sealed_to" value="{{.SealedTo}}">{{end}}{{end}}
+ {{with $seal}}<input type="hidden" name="sealed_to" value="{{.SealedTo}}">{{end}}
{{range $s.Envs}}{{$b := .Bundle}}
<input type="hidden" name="ver.{{$b}}" value="{{.Version}}">
<h3 class="envhead">{{.Title}}</h3>
@@ -709,29 +714,18 @@ blocks deletion. Turn the safety delay off on the <a href="{{.Nav}}/apps/{{.AppN
un-hidden by the script below on the first edit in a panel (Save
diffs val.* against the bundle shown), and always shown with scripts
off. */}}
- {{- range $s.EnvCarry}}
- <input type="hidden" name="{{.Name}}" value="{{.Value}}">{{end}}
- {{- if $s.EnvCarry}}
- {{/* The bundles could not be read: the draft rides along as posted, and
- Save is off until they can be (Try again stages it against them). */}}
- <div class="savebar">
- <p class="small">{{$c.Unsaved}}</p>
- <div class="actions">
- <button type="submit" class="linkish" name="op" value="discard" data-seal-skip>{{$c.Discard}}</button>
- <button type="submit" class="btn-sm" name="op" value="stage" data-seal-skip>{{$c.TryAgain}}</button>
- </div>
- </div>
- {{- else}}
<div class="savebar"{{if or (not $d) $d.Empty}} hidden{{end}}>
<p class="small">{{if $s.EnvSummary}}{{$s.EnvSummary}}{{else}}{{$c.Unsaved}}{{end}}</p>
<div class="actions">
<button type="submit" class="linkish" name="op" value="discard" data-seal-skip>{{$c.Discard}}</button>
<button type="submit" class="btn-sm" name="op" value="save">{{$c.Save}}</button>
</div>
- </div>{{end}}
+ </div>
<noscript><style>.savebar[hidden] { display: flex; }</style></noscript>
</form>
+{{- end}}
{{with $s.EnvOutcome}}{{template "app_settings_env_outcome" $}}{{end}}
+{{- if not $s.EnvsUnavailable}}
<script>
(function () {
var form = document.querySelector("form[data-env-form]");
@@ -745,6 +739,7 @@ blocks deletion. Turn the safety delay off on the <a href="{{.Nav}}/apps/{{.AppN
})();
</script>
{{if $seal}}<script>{{$s.ConfigSealJS}}</script>{{end}}
+{{- end}}
{{end}}
{{/* "After you save" (envsave.go): where one write lands, from the shared