summaryrefslogtreecommitdiff
path: root/internal/event/event_test.go
diff options
context:
space:
mode:
authorClaude <noreply@anthropic.com>2026-05-22 09:08:52 +0000
committerClaude <noreply@anthropic.com>2026-05-22 09:08:52 +0000
commit39cc108b5f0bf3d0238a1707d657a77b7a3df184 (patch)
tree84ee8bcc039b058a308a542f1e1f4a4d11f9e144 /internal/event/event_test.go
parentc24fdaa9b6bce49f5c0a1c589fd064d46b62b88d (diff)
feat(event,storage): add events table substrate for OSS redesign
New internal/event package defines the Event type with canonical Kind and Actor constants. New events table is appended via additive migration (id, task_id, seq, ts, kind, actor, payload_json) with seq as per-task monotonic, assigned by the storage layer inside a transaction. CreateEvent + ListEvents support the future migration of question_json, interactions_json, summary, and elaboration_input off the tasks table into a unified, replayable event stream. No existing code paths are modified yet; this is pure substrate for Phase 1. https://claude.ai/code/session_01SESwn7kQ7oP62trWw6pc39
Diffstat (limited to 'internal/event/event_test.go')
-rw-r--r--internal/event/event_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/event/event_test.go b/internal/event/event_test.go
new file mode 100644
index 0000000..a2cd143
--- /dev/null
+++ b/internal/event/event_test.go
@@ -0,0 +1,42 @@
+package event
+
+import (
+ "encoding/json"
+ "testing"
+ "time"
+)
+
+func TestEvent_JSONRoundTrip(t *testing.T) {
+ original := Event{
+ ID: "evt-1",
+ TaskID: "task-1",
+ Seq: 42,
+ Timestamp: time.Date(2026, 5, 22, 12, 0, 0, 0, time.UTC),
+ Kind: KindClarificationRequest,
+ Actor: ActorAgent,
+ Payload: json.RawMessage(`{"question":"which env?"}`),
+ }
+
+ data, err := json.Marshal(original)
+ if err != nil {
+ t.Fatalf("marshal: %v", err)
+ }
+
+ var got Event
+ if err := json.Unmarshal(data, &got); err != nil {
+ t.Fatalf("unmarshal: %v", err)
+ }
+
+ if got.ID != original.ID || got.TaskID != original.TaskID || got.Seq != original.Seq {
+ t.Errorf("id/task/seq mismatch: got %+v want %+v", got, original)
+ }
+ if !got.Timestamp.Equal(original.Timestamp) {
+ t.Errorf("timestamp mismatch: got %v want %v", got.Timestamp, original.Timestamp)
+ }
+ if got.Kind != original.Kind || got.Actor != original.Actor {
+ t.Errorf("kind/actor mismatch: got %v/%v want %v/%v", got.Kind, got.Actor, original.Kind, original.Actor)
+ }
+ if string(got.Payload) != string(original.Payload) {
+ t.Errorf("payload mismatch: got %s want %s", got.Payload, original.Payload)
+ }
+}