trail: omit unset resume last_active · Entire
trail: omit unset resume last_active
7e4e9b6→main·
peyton-alt·2w ago·4 files·+65 added/-22 removed
Encode trail resume session last_active through a pointer-backed JSON shape so unset timestamps are omitted instead of serialized as year 0001.
Also remove the unused agentimport.Get helper that blocked the full lint check after merging main.
Sessions
c40acde9e205View transcript
Changes
4
cmd/entire/cli
agentimport
Magentimport.go-12
Magentimport_test.go+6/-9
Mtrail_resume_cmd.go+30/-1
Mtrail_resume_cmd_test.go+29
67 unmodified lines
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
71
72
73
67 unmodified lines
claudeImporter{},
}
// Get returns the importer registered under name.
//
//nolint:ireturn // Importer is the intended polymorphic seam returned to callers.
func Get(name string) (Importer, bool) {
for _, imp := range importers {
if imp.Name() == name {
return imp, true
}
}
return nil, false
}
// All returns every supported importer, sorted by name.
func All() []Importer {
out := append([]Importer(nil), importers...)
Mcmd/entire/cli/agentimport/agentimport.go-12
33 unmodified lines
34
35
36
37
38
39
37
38
39
40
41
42
41
42
43
44
45
46
43
44
45
46
33 unmodified lines
func TestRegistry_HasClaude(t *testing.T) {
t.Parallel()
imp, ok := Get("claude-code")
if !ok {
t.Fatal("claude-code importer not registered")
for _, imp := range All() {
if imp.Name() == "claude-code" {
return
}
}
if imp.Name() != "claude-code" {
t.Fatalf("unexpected name %q", imp.Name())
}
if len(All()) == 0 {
t.Fatal("All() returned no importers")
}
t.Fatal("claude-code importer not registered")
}
func initRepoWithCommit(t *testing.T) {
Mcmd/entire/cli/agentimport/agentimport_test.go+6/-9
72 unmodified lines
73
74
75
76
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
72 unmodified lines
SessionID string `json:"session_id"`
Agent string `json:"agent,omitempty"`
LastPrompt string `json:"last_prompt,omitempty"`
LastActive time.Time `json:"last_active,omitempty"`
LastActive time.Time `json:"-"`
CheckpointID string `json:"checkpoint_id"`
}
func (s trailResumeSessionContext) MarshalJSON() ([]byte, error) {
type trailResumeSessionContextJSON struct {
SessionID string `json:"session_id"`
Agent string `json:"agent,omitempty"`
LastPrompt string `json:"last_prompt,omitempty"`
LastActive *time.Time `json:"last_active,omitempty"`
CheckpointID string `json:"checkpoint_id"`
}
var lastActive *time.Time
if !s.LastActive.IsZero() {
active := s.LastActive
lastActive = &active
}
payload := trailResumeSessionContextJSON{
SessionID: s.SessionID,
Agent: s.Agent,
LastPrompt: s.LastPrompt,
LastActive: lastActive,
CheckpointID: s.CheckpointID,
}
data, err := json.Marshal(payload)
if err != nil {
return nil, fmt.Errorf("marshal trail resume session context: %w", err)
}
return data, nil
}
type trailResumeDefaultContext struct {
Branch string `json:"branch"`
SessionID string `json:"session_id,omitempty"`
}
Mcmd/entire/cli/trail_resume_cmd.go+30/-1
529 unmodified lines
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
529 unmodified lines
}
}
func TestEncodeTrailResumeContextJSONOmitsUnsetLastActive(t *testing.T) {
t.Parallel()
ctx := trailResumeContext{
Trail: trailResumeTrailContext{ID: "trl_1", Number: 575, Branch: "feature/trail-resume"},
Sessions: []trailResumeSessionContext{{
SessionID: "session-1",
CheckpointID: "aaaaaaaaaaaa",
}},
}
var out bytes.Buffer
if err := encodeTrailResumeContextJSON(&out, ctx); err != nil {
t.Fatalf("encodeTrailResumeContextJSON: %v", err)
}
var decoded struct {
Sessions []map[string]any `json:"sessions"`
}
if err := json.Unmarshal(out.Bytes(), &decoded); err != nil {
t.Fatalf("unmarshal output: %v\n%s", err, out.String())
}
if len(decoded.Sessions) != 1 {
t.Fatalf("decoded sessions len = %d, want 1", len(decoded.Sessions))
}
if _, ok := decoded.Sessions[0]["last_active"]; ok {
t.Fatalf("last_active should be omitted when unset:\n%s", out.String())
}
}
func TestEncodeTrailResumeContextJSONOmitsFindingsSummaryWhenUnavailable(t *testing.T) {
t.Parallel()