oficina / memoria Public

Gate 3c's flip case: every surface follows VISIBLE → NOT_VISIBLE → UNKNOWN

TestGate3cEverySurfaceFollowsAFlip drives the results page and fragment,
the typeahead, the AI answer, the document page, the documents list and
Recently updated through a flip with nothing else changed. Writing it
found the typeahead hiding an unanswered app's documents silently; it
now carries §4.1's notice line (rst-suggest-notice). Mutations recorded
in the test, including an AI-answer cache keyed without the ruled
passages, which survived until the control document matched the
question too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev e1f68295df16a5d410f4dd2e3129a5581510e337 parent 43f0b0d
4 files changed, +177 −1
  • internal/memoria/flip_test.go +167 −0
  • internal/memoria/handlers.go +6 −1
  • internal/memoria/static/memoria.css +1 −0
  • internal/memoria/templates/results.html +3 −0

CI passed — run details

diff --git a/internal/memoria/flip_test.go b/internal/memoria/flip_test.go
new file mode 100644
index 0000000..3dab8a9
--- /dev/null
+++ b/internal/memoria/flip_test.go
@@ -0,0 +1,167 @@
+package memoria
+
+import (
+ "context"
+ "io"
+ "log/slog"
+ "net/http/httptest"
+ "path/filepath"
+ "strconv"
+ "strings"
+ "testing"
+
+ "amadan.net/oficina/suite"
+ "amadan.net/rastrillo/rastrillo/db"
+
+ "amadan.net/oficina/memoria/internal/memoria/provider"
+ "amadan.net/oficina/memoria/internal/memoria/seal"
+)
+
+// Gate 3c's flip case (suite doctrine §11, revision 11; Fable's review of
+// c38e3ad, H3): an authorization answer is never cached. One Docs
+// document; the app's answer for it goes VISIBLE → NOT_VISIBLE → UNKNOWN
+// with nothing else changed — no feed row, no restart, no cache cleared —
+// and the next request on every surface follows: shown, then hidden,
+// then withheld loudly and naming the app.
+//
+// Surfaces: the results page, the results fragment, the typeahead, the AI
+// answer (whose own cache is keyed on the ruled passages, so a flip
+// changes the key), the document page, the documents list and the front
+// page's Recently updated. TestEverySurfaceAsksTheAppOfRecord covers the
+// delete paths, which never show a sibling's document at all.
+//
+// Written, it found the typeahead hiding an unanswered app's documents
+// silently; it now carries §4.1's line like every other surface.
+//
+// MUTATION-TESTED 2026-11-02, each seen red and reverted: VisibleDocuments
+// memoised per document id → "the document page … after NOT_VISIBLE";
+// the AI answer cache keyed on asker and query only → "the AI answer …
+// after NOT_VISIBLE" (it survived until the control matched the question
+// too, so the answer still ran after the flip); the typeahead's notices
+// dropped → "the typeahead after UNKNOWN: hidden silently"; rule() memoised per (asker, item) → every surface
+// after the flip.
+func TestGate3cEverySurfaceFollowsAFlip(t *testing.T) {
+ logger := slog.New(slog.NewTextHandler(io.Discard, nil))
+ d, err := db.Open(filepath.Join(t.TempDir(), "app.db"), logger)
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { d.Close() })
+ dek := make([]byte, 32)
+ for i := range dek {
+ dek[i] = byte(i*7 + 1)
+ }
+ sealer, err := seal.New(dek)
+ if err != nil {
+ t.Fatal(err)
+ }
+ mux, a, err := AppForTest(d, "http://127.0.0.1:8899", sealer, logger)
+ if err != nil {
+ t.Fatal(err)
+ }
+ cus := &perItemCustody{apps: docsRoster(), give: map[string]suite.Authorization{}}
+ a.store.custody = cus
+ a.store.answerer = echoAnswerer{}
+ ctx := context.Background()
+ id, err := a.store.Ingest(ctx, IngestSpec{Source: "Docs", Key: "flip", Title: "Nebula launch plan",
+ Body: "## Plan\n\nThe nebula launch is planned for the spring.", ItemID: "flip", SiblingRevision: 4})
+ if err != nil {
+ t.Fatal(err)
+ }
+ // A control memoria owns, so a page that hides the Docs document still
+ // has something on it and an empty page is never mistaken for a pass.
+ // It matches the AI answer's question too, so after the flip the
+ // answer still runs — on the control alone — and an answer cached from
+ // before the flip has somewhere to be served from.
+ if _, err := a.store.Ingest(ctx, IngestSpec{Source: "upload", Key: "own", Title: "Kitchen rota", Body: "The nebula launch checklist is pinned by the kettle."}); err != nil {
+ t.Fatal(err)
+ }
+
+ get := func(path string) *httptest.ResponseRecorder {
+ req := httptest.NewRequest("GET", path, nil)
+ req.Header.Set("Accept", "text/html")
+ rec := httptest.NewRecorder()
+ mux.ServeHTTP(rec, req)
+ return rec
+ }
+ docPage := "/documents/" + strconv.FormatInt(id, 10)
+ const title, notice = "Nebula launch plan", "Docs did not answer"
+
+ type surface struct {
+ name, path string
+ // shows reports whether the response names the document.
+ shows func(*httptest.ResponseRecorder) bool
+ // loud reports whether an UNKNOWN response withholds out loud and
+ // names the app (or, for a route with no room for a sentence, is
+ // the retryable refusal).
+ loud func(*httptest.ResponseRecorder) bool
+ }
+ names := func(r *httptest.ResponseRecorder) bool { return strings.Contains(r.Body.String(), title) }
+ says := func(r *httptest.ResponseRecorder) bool { return strings.Contains(r.Body.String(), notice) }
+ surfaces := []surface{
+ {"the results page", "/?q=nebula", names, says},
+ {"the results fragment", "/search?q=nebula", names, says},
+ {"the typeahead", "/suggest?q=nebula", names, says},
+ {"the AI answer", "/answer?q=nebula+launch",
+ func(r *httptest.ResponseRecorder) bool {
+ return strings.Contains(r.Body.String(), "FROM THE SPRING PLAN") || names(r)
+ },
+ func(r *httptest.ResponseRecorder) bool {
+ return strings.Contains(r.Body.String(), "ONLY THE CHECKLIST")
+ }},
+ {"the document page", docPage,
+ func(r *httptest.ResponseRecorder) bool { return r.Code == 200 && names(r) },
+ func(r *httptest.ResponseRecorder) bool { return r.Code == 503 }},
+ {"the documents list", "/documents", names, says},
+ {"recently updated", "/", names, says},
+ }
+
+ for _, step := range []struct {
+ give suite.Authorization
+ want string
+ }{{suite.VISIBLE, "shown"}, {suite.NOT_VISIBLE, "hidden"}, {suite.UNKNOWN, "withheld"}, {suite.VISIBLE, "shown"}} {
+ cus.give["flip"] = step.give
+ for _, s := range surfaces {
+ r := get(s.path)
+ switch step.want {
+ case "shown":
+ if !s.shows(r) {
+ t.Errorf("%s after %v: not shown (%d)", s.name, step.give, r.Code)
+ }
+ case "hidden":
+ if s.shows(r) {
+ t.Errorf("%s after NOT_VISIBLE: still shown — an authorization answer was cached", s.name)
+ }
+ if s.name == "the document page" && r.Code != 404 {
+ t.Errorf("the document page after NOT_VISIBLE = %d, want 404", r.Code)
+ }
+ case "withheld":
+ if s.shows(r) {
+ t.Errorf("%s after UNKNOWN: still shown — an authorization answer was cached", s.name)
+ }
+ if !s.loud(r) {
+ t.Errorf("%s after UNKNOWN: hidden silently (%d), not withheld naming Docs", s.name, r.Code)
+ }
+ }
+ }
+ // The control stays on the list throughout.
+ if !strings.Contains(get("/documents").Body.String(), "Kitchen rota") {
+ t.Fatalf("after %v the control is gone, so an empty list proves nothing", step.give)
+ }
+ }
+}
+
+// echoAnswerer says which passages it was sent: a sentence from the Docs
+// document's text if that was among them, and another if only the
+// control was. A cached answer from before a flip is then visible by its
+// words.
+type echoAnswerer struct{}
+
+func (echoAnswerer) Answer(_ context.Context, _ string, ps []string) ([]provider.Sentence, error) {
+ for i, p := range ps {
+ if strings.Contains(p, "spring") {
+ return []provider.Sentence{{Text: "FROM THE SPRING PLAN.", Cite: []int{i}}}, nil
+ }
+ }
+ return []provider.Sentence{{Text: "ONLY THE CHECKLIST.", Cite: []int{0}}}, nil
+}
diff --git a/internal/memoria/handlers.go b/internal/memoria/handlers.go
index 91e2637..bd61a64 100644
--- a/internal/memoria/handlers.go
+++ b/internal/memoria/handlers.go
@@ -795,6 +795,10 @@ type suggestPage struct {
// model step, which a keystroke never runs).
Fact *Fact
Suggestions []Suggestion
+ // Notices are §4.1's lines for an app that did not answer: the
+ // typeahead withholds out loud like every other surface (gate 3c),
+ // rather than offering a shorter list that reads as complete.
+ Notices []string
}
// MaxSuggestions is how many documents the typeahead lists.
@@ -823,6 +827,7 @@ func (a *app) suggest(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
return
}
+ sp.Notices = found.Notices
if len(found.Facts) == 1 && found.Facts[0].Guess == nil && found.Facts[0].Model == "" {
f := found.Facts[0]
sp.Fact = &f
@@ -842,7 +847,7 @@ func (a *app) suggest(w http.ResponseWriter, r *http.Request) {
}
// Standing asked again after the search, as a list does: a
// typeahead built while it lapsed says nothing.
- if a.teamPartial(r) || (sp.Fact == nil && len(sp.Suggestions) == 0) {
+ if a.teamPartial(r) || (sp.Fact == nil && len(sp.Suggestions) == 0 && len(sp.Notices) == 0) {
w.WriteHeader(http.StatusNoContent)
return
}
diff --git a/internal/memoria/static/memoria.css b/internal/memoria/static/memoria.css
index 15d8069..b9a67d1 100644
--- a/internal/memoria/static/memoria.css
+++ b/internal/memoria/static/memoria.css
@@ -119,6 +119,7 @@ html { scrollbar-gutter: stable; }
[rst-suggest-fact] strong { font-size: 1.125rem; }
[rst-suggest-fact-label] { color: var(--rst-text-muted); font-size: 0.875rem; }
[rst-suggest-all] { color: var(--rst-text-muted); font-size: 0.875rem; justify-content: space-between; }
+[rst-suggest-notice] { color: var(--rst-text-muted); font-size: 0.8125rem; padding: 0.4rem 1rem; }
/* The box's middle on the screen's middle: the page's top padding is
half the screen less the bar, the main area's own padding and half the
diff --git a/internal/memoria/templates/results.html b/internal/memoria/templates/results.html
index 930cb3f..9fe5fb2 100644
--- a/internal/memoria/templates/results.html
+++ b/internal/memoria/templates/results.html
@@ -237,6 +237,9 @@
<span rst-suggest-title>{{.Title}}</span>{{if and .Trail (ne .Trail .Title)}} <span rst-muted>› {{.Trail}}</span>{{end}}
</a></li>
{{end}}
+ {{/* An app that did not answer, said in the list (gate 3c): not an
+ option, so the arrow keys pass over it. */}}
+ {{range .Notices}}<li role="presentation" rst-suggest-notice>{{.}}</li>{{end}}
<li role="option"><a href="/?q={{.Query}}" rst-suggest-item rst-suggest-all>Search for “{{.Query}}” <span rst-muted>Enter</span></a></li>
</ul>
{{end}}