carlos / platform Public

console: DPA PDF review fixes (engine gate first, print leads on 502)

With no PDF engine, handleDPAPDF answers the plain 404 straight after
the membership gate, before any acceptance read, so a failing read can
no longer turn a disabled route into a 500
(TestDPAPDFNoEngineSkipsReads).

On the 502 record page, Print is the main button and Download PDF the
secondary one, since the banner tells the reader to print.

The claim fixture and the record-write census comment say what the
route writes precisely: no app records, sidecars or bucket objects;
the 502 path's page render updates the last-account pointer as the
record page does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 232a7b382bc67cf84fd575ff50c699064607c0ba parent e97e96f
6 files changed, +50 −12
  • internal/console/claim_invariant_fixtures_test.go +1 −1
  • internal/console/dpapdfroute.go +10 −4
  • internal/console/dpapdfroute_test.go +30 −2
  • internal/console/dparecord.go +2 −0
  • internal/console/templates/dpa_record.html +3 −2
  • internal/provision/dpa_pdf_census_test.go +4 −3

Intent

Human

<task-notification> <task-id>bv83be8ef</task-id> <tool-use-id>toolu_01LRhwoeXnwG6Hzhx1pyRvFJ</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/260ddc60-0dfc-4cf8-8857-7688d6275097/tasks/bv83be8ef.output</output-file> <status>completed</status> <summary>Background command "Run Astra whole-branch review of slice 2" completed (exit code 0)</summary> </task-notification>

diff --git a/internal/console/claim_invariant_fixtures_test.go b/internal/console/claim_invariant_fixtures_test.go
index 3836f339f..b9105f06b 100644
--- a/internal/console/claim_invariant_fixtures_test.go
+++ b/internal/console/claim_invariant_fixtures_test.go
@@ -861,7 +861,7 @@ var claimFixtures = map[string]claimFixture{
"route GET /a/{sqid}/index": claimRead("renders the account's sections as a phone index"),
"route GET /a/{sqid}/settings": claimRead("renders account settings"),
"route GET /a/{sqid}/settings/dpa": claimRead("renders the account's data processing agreement record; writes nothing"),
- "route GET /a/{sqid}/settings/dpa.pdf": claimRead("answers the account's executed data processing agreement as a PDF from the PDF engine; writes nothing"),
+ "route GET /a/{sqid}/settings/dpa.pdf": claimRead("answers the account's executed data processing agreement as a PDF from the PDF engine; writes no app records, sidecars or bucket objects; the 502 path's page render updates the last-account pointer as the record page does"),
"route GET /a/{sqid}/plan/keep": claimRead("renders the keep page (plans 4d) from the plan row, lapse items and an inventory read; writes nothing"),
"route GET /a/{sqid}/team": claimRead("renders members and invites"),
"route GET /a/{sqid}/trash": claimRead("lists trashed apps; purge is the trash/delete door"),
diff --git a/internal/console/dpapdfroute.go b/internal/console/dpapdfroute.go
index c093ac59c..4d96022e2 100644
--- a/internal/console/dpapdfroute.go
+++ b/internal/console/dpapdfroute.go
@@ -53,9 +53,9 @@ func (s *Server) dpaPDFConsoleName() string {
}
// handleDPAPDF answers the PDF. Gates, in order: membership (the
-// byte-identical 404 for anyone else); an acceptance in force (else the
-// 404 the record page gives a member); an engine configured (else the
-// plain 404); the write limit, as a cost bound. A render or engine failure
+// byte-identical 404 for anyone else); an engine configured (else the
+// plain 404, before any read); an acceptance in force (else the 404 the
+// record page gives a member); the write limit, as a cost bound. A render or engine failure
// is the record page at 502 with record.pdf_failed, logged with the
// account and the error's category only.
func (s *Server) handleDPAPDF(w http.ResponseWriter, r *http.Request) {
@@ -63,6 +63,12 @@ func (s *Server) handleDPAPDF(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
+ // The feature is off: the plain 404 before any read, so a failing
+ // read cannot answer 500 for a route that does not exist here.
+ if s.cfg.PDFEngine == "" {
+ http.NotFound(w, r)
+ return
+ }
ctx := r.Context()
live, doc, lh, err := s.dpaLiveRecord(ctx, acct.ID)
if err != nil {
@@ -70,7 +76,7 @@ func (s *Server) handleDPAPDF(w http.ResponseWriter, r *http.Request) {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
- if live == nil || s.cfg.PDFEngine == "" {
+ if live == nil {
http.NotFound(w, r)
return
}
diff --git a/internal/console/dpapdfroute_test.go b/internal/console/dpapdfroute_test.go
index 065b3341a..6c2e15950 100644
--- a/internal/console/dpapdfroute_test.go
+++ b/internal/console/dpapdfroute_test.go
@@ -246,6 +246,27 @@ func TestDPAPDFNoEngine(t *testing.T) {
}
}
+// With no engine the route is the plain 404 before any read: a failing
+// acceptance read is a 500 only once an engine is configured.
+func TestDPAPDFNoEngineSkipsReads(t *testing.T) {
+ fx := newConsoleFixture(t)
+ c := signInPaul(t, fx)
+ docID, lhID := dpaWorld(t, fx)
+ dpaAcceptFor(t, fx, docID, lhID)
+ if _, err := fx.st.db.Exec(`ALTER TABLE dpa_acceptances RENAME TO dpa_acceptances_gone`); err != nil {
+ t.Fatal(err)
+ }
+ status, _, body := get(t, c, fx.u("/settings/dpa.pdf"))
+ _, _, unrouted := get(t, c, fx.ts.URL+"/no/such/path")
+ if status != http.StatusNotFound || body != unrouted {
+ t.Errorf("no engine, failing read = %d, want the plain 404", status)
+ }
+ dpaPDFEngineFor(t, fx)
+ if s, _, _ := get(t, c, fx.u("/settings/dpa.pdf")); s != http.StatusInternalServerError {
+ t.Errorf("with an engine the failing read = %d, want 500 (the read must fail for this test to mean anything)", s)
+ }
+}
+
func TestDPAPDFEngineFailure(t *testing.T) {
fx := newConsoleFixture(t)
member := dpaMember(t, fx)
@@ -268,10 +289,17 @@ func TestDPAPDFEngineFailure(t *testing.T) {
if cd := h.Get("Content-Disposition"); cd != "" || strings.Contains(h.Get("Content-Type"), "pdf") {
t.Errorf("a failure answers as a download: %q %q", cd, h.Get("Content-Type"))
}
- // The page is the record, so "print this page" prints the record.
- if !strings.Contains(oplText(body), "Ada Lovelace, Director (paul@keymail.dev)") {
+ // The page is the record, so "print this page" prints the record, and
+ // print is the main button with the download beside it.
+ page := oplText(body)
+ if !strings.Contains(page, "Ada Lovelace, Director (paul@keymail.dev)") {
t.Errorf("the failure page is not the record:\n%s", body)
}
+ printBtn := `<button type="button" onclick="window.print()">` + oplDeck(t, "DPA-C39") + "</button>"
+ download := `<a class="btn btn-secondary" href="` + fx.path("/settings/dpa.pdf") + `">` + dpaPDFDeck(t, "PDF-C16") + "</a>"
+ if pi, di := strings.Index(page, printBtn), strings.Index(page, download); pi < 0 || di < 0 || pi > di {
+ t.Errorf("the failure page does not lead with print, then the download:\n%s", page)
+ }
line := logs.String()
if !strings.Contains(line, "dpa pdf "+fx.sqid) || !strings.Contains(line, "engine status 500") {
t.Errorf("log = %q, want the sqid and the category", line)
diff --git a/internal/console/dparecord.go b/internal/console/dparecord.go
index 99b4be8ea..86a82e676 100644
--- a/internal/console/dparecord.go
+++ b/internal/console/dparecord.go
@@ -32,6 +32,7 @@ type dpaRecordView struct {
Processor string
SettingsURL string
PDFURL string // the download, when an engine is configured
+ PDFFailed bool // the download just failed: print is the main button
}
// dpaRecordWhenLayout is dpa.record.row.when's value format.
@@ -152,6 +153,7 @@ func (s *Server) renderDPARecord(w http.ResponseWriter, r *http.Request, addr, r
p.DPARecord = v
if failed != "" {
p.FlashErr = failed
+ v.PDFFailed = true
}
s.render(w, status, "dpa_record", p)
}
diff --git a/internal/console/templates/dpa_record.html b/internal/console/templates/dpa_record.html
index 54129e173..ec9b895f6 100644
--- a/internal/console/templates/dpa_record.html
+++ b/internal/console/templates/dpa_record.html
@@ -18,8 +18,9 @@
</table>
</div>
<p class="small">The fingerprint changes if a single character of the agreement changes, so it proves which text was accepted.</p>
-<p class="no-print">{{if .PDFURL}}<a class="btn" href="{{.PDFURL}}">Download PDF</a>
-<button type="button" class="btn-secondary" onclick="window.print()">Print this record</button>{{else}}<button type="button" onclick="window.print()">Print this record</button>{{end}}
+<p class="no-print">{{if and .PDFURL (not .PDFFailed)}}<a class="btn" href="{{.PDFURL}}">Download PDF</a>
+<button type="button" class="btn-secondary" onclick="window.print()">Print this record</button>{{else}}<button type="button" onclick="window.print()">Print this record</button>{{with .PDFURL}}
+<a class="btn btn-secondary" href="{{.}}">Download PDF</a>{{end}}{{end}}
<a class="btn btn-secondary" href="{{.SettingsURL}}">Back to settings</a></p>
{{else}}<p>No agreement is in force yet. You can accept one in account settings.</p>
<p class="no-print"><a class="btn btn-secondary" href="{{.SettingsURL}}">Back to settings</a></p>
diff --git a/internal/provision/dpa_pdf_census_test.go b/internal/provision/dpa_pdf_census_test.go
index 26d4df232..1577b6d2b 100644
--- a/internal/provision/dpa_pdf_census_test.go
+++ b/internal/provision/dpa_pdf_census_test.go
@@ -10,9 +10,10 @@ package provision
// - var routeDecls (console): one new declaration, GET
// /a/{sqid}/settings/dpa.pdf (handleDPAPDF, dpapdfroute.go), for
// account members. It reads the console database's legal tables and
-// posts HTML to the PDF engine; it writes nothing, and reads or writes
-// no app record, sidecar or bucket object. The instances and sidecars
-// literals are unchanged: still key-site.
+// posts HTML to the PDF engine. It writes no app records, sidecars or
+// bucket objects; the 502 path's page render updates the last-account
+// pointer as the record page does. The instances and sidecars literals
+// are unchanged: still key-site.
func dpaPDFWriteCensusInventory() []censusEntry {
entries := append([]censusEntry(nil), certImport1429WriteCensusInventory()...)
repins := []censusEntry{