The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
package devincloud
import (
"crypto/sha256"
"encoding/hex"
"testing"
)
func TestMapSessionProducesLifecycleAndMessages(t *testing.T) {
s := Session{
SessionID: "sess1",
Status: "suspended",
UserID: "user-1",
CreatedAt: 1000,
UpdatedAt: 1600,
AcusConsumed: 2.5,
PullRequests: []PullRequest{{URL: "https://github.com/acme/widgets/pull/7", Number: 7}},
}
msgs := []Message{
{EventID: "e1", Source: "user", Message: "do the thing", CreatedAt: 1000},
{EventID: "e2", Source: "devin", Message: "done", CreatedAt: 1100},
}
mapped := MapSession(s, msgs)
if len(mapped) != 3 {
t.Fatalf("got %d events, want 3 (started, prompt, agent); ended is emitted by the orchestrator", len(mapped))
}
wantActions := []string{"session.started", "prompt.submitted", "agent.message"}
for i, want := range wantActions {
if mapped[i].Event.Event.Action != want {
t.Fatalf("event %d action = %q, want %q", i, mapped[i].Event.Event.Action, want)
}
}
// Dedup ids: lifecycle synthetic for started, event_id for messages.
wantIDs := []string{"sess1:started", "e1", "e2"}
for i, want := range wantIDs {
if mapped[i].DedupID != want {
t.Fatalf("event %d dedup id = %q, want %q", i, mapped[i].DedupID, want)
}
}
// Common fields.
for _, me := range mapped {
ev := me.Event
if ev.Origin != "cloud" {
t.Fatalf("origin = %q, want cloud", ev.Origin)
}
if ev.Harness.Name != "devin" {
t.Fatalf("harness = %q, want devin", ev.Harness.Name)
}
// Devin Cloud is polled after the run, neither a hook nor an OTLP stream: recording that
// on every event stops these from being read as endpoint-grade observation.
if ev.Harness.CollectionMethod != "poll" {
t.Fatalf("event %q collection_method = %q, want poll", ev.Event.Action, ev.Harness.CollectionMethod)
}
if ev.Run == nil || ev.Run.Provider != "devin_cloud" || ev.Run.RunID != "sess1" || ev.Run.Actor != "user-1" {
t.Fatalf("run = %+v", ev.Run)
}
if ev.Run.Repository != "acme/widgets" {
t.Fatalf("repository = %q, want acme/widgets", ev.Run.Repository)
}
if err := ev.Validate(); err != nil {
t.Fatalf("event %q failed Validate: %v", ev.Event.Action, err)
}
}
// Prompt text + devin message content.
if mapped[1].Event.Prompt == nil || mapped[1].Event.Prompt.Text != "do the thing" {
t.Fatalf("prompt text not mapped: %+v", mapped[1].Event.Prompt)
}
if mapped[2].Event.Message != "done" {
t.Fatalf("agent message = %q, want done", mapped[2].Event.Message)
}
// Timestamps come from the source unix times, rendered in the canonical event
// format. Devin reports whole seconds, so the sub-second digits are zeros -- the
// width is fixed so that every event in the stream sorts byte-wise as well as
// chronologically.
if mapped[0].Event.Timestamp != "1970-01-01T00:16:40.000000000Z" {
t.Fatalf("started ts = %q, want session created_at", mapped[0].Event.Timestamp)
}
}
func TestEndedEventCarriesMetadata(t *testing.T) {
s := Session{
SessionID: "sess1", Status: "suspended", UserID: "user-1",
CreatedAt: 1000, UpdatedAt: 1600, AcusConsumed: 2.5,
}
ended := EndedEvent(s)
if ended.Event.Action != "session.ended" {
t.Fatalf("action = %q, want session.ended", ended.Event.Action)
}
if err := ended.Validate(); err != nil {
t.Fatalf("ended failed Validate: %v", err)
}
devin, _ := ended.Raw["devin"].(map[string]interface{})
if devin == nil || devin["acus_consumed"] != 2.5 {
t.Fatalf("ended raw.devin = %+v", ended.Raw)
}
if devin["duration_seconds"] != int64(600) {
t.Fatalf("duration = %v, want 600", devin["duration_seconds"])
}
}
func TestMessageDedupIDHandlesEmptyAndDuplicate(t *testing.T) {
// Empty and duplicate event_ids must still yield unique dedup ids, or the
// dedup set would silently drop messages.
msgs := []Message{
{EventID: "", Source: "user", Message: "a", CreatedAt: 10},
{EventID: "", Source: "devin", Message: "b", CreatedAt: 11},
{EventID: "dup", Source: "user", Message: "c", CreatedAt: 12},
{EventID: "dup", Source: "devin", Message: "d", CreatedAt: 13},
}
mapped := MapSession(Session{SessionID: "s", Status: "working", CreatedAt: 5}, msgs)
if len(mapped) != 5 { // started + 4 messages
t.Fatalf("got %d events, want 5", len(mapped))
}
ids := map[string]bool{}
for _, me := range mapped {
if ids[me.DedupID] {
t.Fatalf("duplicate dedup id %q would drop a message", me.DedupID)
}
ids[me.DedupID] = true
}
}
func TestStatusClassification(t *testing.T) {
for _, st := range []string{"finished", "expired", "suspended"} {
if !IsTerminal(st) {
t.Fatalf("IsTerminal(%q) = false, want true", st)
}
}
for _, st := range []string{"working", "blocked"} {
if IsTerminal(st) {
t.Fatalf("IsTerminal(%q) = true, want false", st)
}
}
if IsFinal("suspended") {
t.Fatal("suspended should not be final (may resume)")
}
if !IsFinal("finished") {
t.Fatal("finished should be final")
}
}
func TestObjectNameLayout(t *testing.T) {
got := ObjectName("agent-traces/team=x", "devin_cloud", "user-1", "sess-9")
want := "agent-traces/team=x/provider=devin_cloud/user_id=user-1/run_id=sess-9/runtime.jsonl"
if got != want {
t.Fatalf("ObjectName = %q, want %q", got, want)
}
got2 := ObjectName("", "devin_cloud", "", "")
want2 := "provider=devin_cloud/user_id=unknown/run_id=unknown/runtime.jsonl"
if got2 != want2 {
t.Fatalf("ObjectName empties = %q, want %q", got2, want2)
}
got3 := ObjectName("tenant/logs", "devin_cloud", "user-1", "../../../../../../outside")
want3 := "tenant/logs/provider=devin_cloud/user_id=user-1/run_id=unknown/runtime.jsonl"
if got3 != want3 {
t.Fatalf("ObjectName traversal = %q, want %q", got3, want3)
}
}
func TestMapSessionRecordsRetainedMessageContent(t *testing.T) {
// Both markers used to claim full retention with no hash and no byte count,
// and the assistant's text reached the log only as the event message.
prompt := "fix the flaky test"
reply := "I disabled the retry and pinned the clock."
mapped := MapSession(
Session{SessionID: "devin-1", CreatedAt: 100},
[]Message{
{EventID: "m1", Source: "user", Message: prompt, CreatedAt: 101},
{EventID: "m2", Source: "devin", Message: reply, CreatedAt: 102},
},
)
if len(mapped) != 3 {
t.Fatalf("mapped = %d events, want 3", len(mapped))
}
promptEvent := mapped[1].Event
promptSum := sha256.Sum256([]byte(prompt))
if promptEvent.Content == nil || promptEvent.Content.Hash != hex.EncodeToString(promptSum[:]) {
t.Fatalf("prompt content marker = %#v, want the prompt hashed", promptEvent.Content)
}
if promptEvent.Content.Bytes != len(prompt) || !promptEvent.Content.Included {
t.Fatalf("prompt content marker = %#v, want the retained prompt described", promptEvent.Content)
}
if promptEvent.GenAI == nil || promptEvent.GenAI.Input == nil || promptEvent.GenAI.Input.Messages == nil {
t.Fatalf("prompt not mirrored into gen_ai.input.messages: %#v", promptEvent.GenAI)
}
agentEvent := mapped[2].Event
if agentEvent.GenAI == nil || agentEvent.GenAI.Output == nil || agentEvent.GenAI.Output.Messages == nil {
t.Fatalf("assistant text not promoted into gen_ai.output.messages: %#v", agentEvent.GenAI)
}
replySum := sha256.Sum256([]byte(reply))
if agentEvent.Content == nil || agentEvent.Content.Hash != hex.EncodeToString(replySum[:]) {
t.Fatalf("agent content marker = %#v, want the reply hashed", agentEvent.Content)
}
// The message keeps its existing role as the human-readable label.
if agentEvent.Message != reply {
t.Fatalf("agent message = %q, want the reply text preserved", agentEvent.Message)
}
}