The State Store, event capture and Gateway conversations already serve from PostgreSQL. This deletes internal/store and internal/infrastructure/edastore, the SQLite gateway session store and openProductionTaskStore, and the -db recovery path on a legacy task file; backup, restore, validate and rollback work on the database database_url names. - The binding-secret cipher moves to internal/infrastructure/bindingcipher and ToolCall to internal/infrastructure/postgres. - NewSessionStoreMemory is now a pure in-memory store that passes the shared SessionStore conformance suite. - Tests run against PostgreSQL through internal/infrastructure/postgres/pgstore; legacyimport/legacyfixture writes the legacy files the import and the boot gate read. - The cron dialect is owned in internal/domain/scheduling, so github.com/pocketbase/pocketbase and pocketbase/dbx leave go.mod. modernc.org/sqlite stays for the one-time import (legacyread). - The UI and Messaging architecture gates ban the Postgres and legacy readers in place of internal/store.
92 lines
3.3 KiB
Go
92 lines
3.3 KiB
Go
package staterpc
|
|
|
|
import (
|
|
"encoding/json"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
|
|
"github.com/samcharles93/archie-core/internal/logging"
|
|
)
|
|
|
|
// A decoded task-log page must never carry a nil slice for a collection field.
|
|
// Go marshals a nil slice to JSON null, and null is not an empty list: a
|
|
// client that reads the field as an array sees a different type than the same
|
|
// route serves when the collection is non-empty.
|
|
//
|
|
// This is the nil-slice class the contract-conformance audit deferred (its
|
|
// named revisit condition is a handler that can produce nil). The local reader
|
|
// already normalises both fields; the wire mapping did not, because protobuf
|
|
// decodes an empty `repeated` field to nil, so the grpc path regressed what the
|
|
// local path got right. Asserting the JSON shape rather than the slice catches
|
|
// it on both paths without depending on which one is under test.
|
|
func TestTaskLogPageCarriesNoNilCollectionFields(t *testing.T) {
|
|
// Both collections must be exercised empty. A log with entries but no
|
|
// structured "component" field leaves only Components empty; an attempt
|
|
// whose log file exists but holds no lines leaves only Entries empty, and
|
|
// that second shape is what catches an empty-slice mapping regressing on
|
|
// the entries side.
|
|
for _, tc := range []struct {
|
|
name string
|
|
write bool
|
|
}{
|
|
{name: "entries present, components empty", write: true},
|
|
{name: "entries empty, components empty", write: false},
|
|
} {
|
|
for _, mode := range []string{"local", "grpc"} {
|
|
t.Run(tc.name+"/"+mode, func(t *testing.T) {
|
|
ctx := t.Context()
|
|
baseDir := filepath.Join(t.TempDir(), "logs", "tasks")
|
|
reader := logging.NewTaskRegistry(baseDir, logging.NewFeed(10), logging.TaskSinkOptions{})
|
|
|
|
const taskID = 7
|
|
if err := reader.Open(taskID, 0); err != nil {
|
|
t.Fatalf("open sink: %v", err)
|
|
}
|
|
if tc.write {
|
|
// No "component" field at all: Components stays empty while
|
|
// Entries does not.
|
|
reader.Write(ctx, taskID, logging.Entry{Level: "INFO", Message: "starting"})
|
|
}
|
|
if err := reader.Close(taskID); err != nil {
|
|
t.Fatalf("close sink: %v", err)
|
|
}
|
|
|
|
var c taskLogContract = reader
|
|
if mode == "grpc" {
|
|
c = remoteTaskStore(t, pgstore.Open(t), reader, nil)
|
|
}
|
|
|
|
page, err := c.TaskLog(ctx, taskID, 0, logging.Query{})
|
|
if err != nil {
|
|
t.Fatalf("TaskLog: %v", err)
|
|
}
|
|
if !page.Found {
|
|
t.Fatal("Found = false for an attempt whose log file exists")
|
|
}
|
|
if tc.write && len(page.Entries) != 1 {
|
|
t.Fatalf("entries = %d, want the line the sink wrote", len(page.Entries))
|
|
}
|
|
if !tc.write && len(page.Entries) != 0 {
|
|
t.Fatalf("entries = %d, want none for a log with no lines", len(page.Entries))
|
|
}
|
|
|
|
raw, err := json.Marshal(page)
|
|
if err != nil {
|
|
t.Fatalf("marshal page: %v", err)
|
|
}
|
|
var decoded map[string]json.RawMessage
|
|
if err := json.Unmarshal(raw, &decoded); err != nil {
|
|
t.Fatalf("unmarshal page: %v", err)
|
|
}
|
|
for _, field := range []string{"entries", "components"} {
|
|
if got := string(decoded[field]); got == "null" {
|
|
t.Errorf("%s marshalled to null, want an empty list: the field's type must not depend on whether it has contents",
|
|
field)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|