MCPcopy Create free account
hub / github.com/compozy/agh / TestMemoryHandlersReadAndNotFound

Function TestMemoryHandlersReadAndNotFound

internal/api/httpapi/memory_test.go:159–223  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

157}
158
159func TestMemoryHandlersReadAndNotFound(t *testing.T) {
160 t.Parallel()
161
162 store, _ := newTestMemoryStore(t)
163 mustWriteMemory(t, store, memcontract.ScopeGlobal, "", "readme.md", memcontract.TypeUser, "hello world")
164 mustWriteMemory(
165 t,
166 store,
167 memcontract.ScopeGlobal,
168 "",
169 "_system-hidden.md",
170 memcontract.TypeReference,
171 "system body",
172 )
173
174 handlers := newTestMemoryHandlers(t, stubSessionManager{}, stubObserver{}, store, &stubDreamTrigger{})
175 engine := newTestRouter(t, handlers)
176
177 resp := performRequest(t, engine, http.MethodGet, "/api/memory/readme.md?scope=global", nil)
178 if resp.Code != http.StatusOK {
179 t.Fatalf("status = %d, want %d; body=%s", resp.Code, http.StatusOK, resp.Body.String())
180 }
181
182 var payload memoryEntryResponse
183 decodeJSONResponse(t, resp, &payload)
184 if !strings.Contains(payload.Memory.Content, "hello world") {
185 t.Fatalf("content = %q, want stored body", payload.Memory.Content)
186 }
187
188 missing := performRequest(t, engine, http.MethodGet, "/api/memory/missing.md?scope=global", nil)
189 if missing.Code != http.StatusNotFound {
190 t.Fatalf("status = %d, want %d; body=%s", missing.Code, http.StatusNotFound, missing.Body.String())
191 }
192
193 systemHidden := performRequest(t, engine, http.MethodGet, "/api/memory/_system-hidden.md?scope=global", nil)
194 if systemHidden.Code != http.StatusNotFound {
195 t.Fatalf(
196 "status = %d, want %d for hidden system memory; body=%s",
197 systemHidden.Code,
198 http.StatusNotFound,
199 systemHidden.Body.String(),
200 )
201 }
202
203 systemVisible := performRequest(
204 t,
205 engine,
206 http.MethodGet,
207 "/api/memory/_system-hidden.md?scope=global&include_system=true",
208 nil,
209 )
210 if systemVisible.Code != http.StatusOK {
211 t.Fatalf(
212 "status = %d, want %d for include_system read; body=%s",
213 systemVisible.Code,
214 http.StatusOK,
215 systemVisible.Body.String(),
216 )

Callers

nothing calls this directly

Calls 8

ContainsMethod · 0.80
newTestMemoryStoreFunction · 0.70
mustWriteMemoryFunction · 0.70
newTestMemoryHandlersFunction · 0.70
newTestRouterFunction · 0.70
performRequestFunction · 0.70
decodeJSONResponseFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected