From b9303ea907651d00d18afa05409224e833912cee Mon Sep 17 00:00:00 2001 From: Dakera Ops Date: Wed, 29 Jul 2026 10:48:28 +0000 Subject: [PATCH] test(client): add ValidFrom regression tests for StoreMemory (DAK-7424) Adds 2 unit tests (httptest-based) verifying that StoreMemory correctly forwards valid_from in the JSON request body when ValidFrom is set, and correctly omits it (omitempty) when ValidFrom is nil. These cover the field added in PR#145 which merged without dedicated test coverage. Co-Authored-By: Paperclip --- client_memory_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/client_memory_test.go b/client_memory_test.go index 86a9793..a489a89 100644 --- a/client_memory_test.go +++ b/client_memory_test.go @@ -917,6 +917,55 @@ func TestKeyUsage(t *testing.T) { } // =========================================================================== +// ValidFrom bi-temporal field tests (DAK-7424) +// =========================================================================== + +func TestStoreMemory_ValidFrom(t *testing.T) { + var capturedBody map[string]interface{} + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + json.NewDecoder(r.Body).Decode(&capturedBody) + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(map[string]interface{}{ + "memory": map[string]interface{}{ + "id": "mem-vf1", + "content": "past event", + "agent_id": "agent-1", + "memory_type": "episodic", + }, + }) + })) + defer server.Close() + client := NewClient(server.URL) + ts := int64(1700000000) + _, err := client.StoreMemory(context.Background(), "agent-1", StoreMemoryRequest{ + Content: "past event", + ValidFrom: &ts, + }) + require.NoError(t, err) + assert.Equal(t, float64(ts), capturedBody["valid_from"], "valid_from must be forwarded in request body") +} + +func TestStoreMemory_ValidFrom_Omitted(t *testing.T) { + var capturedBody map[string]interface{} + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + json.NewDecoder(r.Body).Decode(&capturedBody) + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(map[string]interface{}{ + "memory": map[string]interface{}{ + "id": "mem-vf2", "content": "now", "agent_id": "agent-1", "memory_type": "episodic", + }, + }) + })) + defer server.Close() + client := NewClient(server.URL) + _, err := client.StoreMemory(context.Background(), "agent-1", StoreMemoryRequest{ + Content: "now", + }) + require.NoError(t, err) + _, present := capturedBody["valid_from"] + assert.False(t, present, "valid_from must be omitted from request body when nil") +} + // Error Tests // ===========================================================================