Skip to content

Commit bcd77ff

Browse files
committed
feat(session): add pipeline phase with tests
1 parent 9f2da98 commit bcd77ff

2 files changed

Lines changed: 75 additions & 0 deletions

File tree

cli/session/pipeline_phase.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package session
2+
3+
// PipelinePhase identifies the step of the Agentless-style pipeline
4+
// (localize → repair → validate) that a session turn belongs to.
5+
//
6+
// These string constants mirror hawk-core-contracts/sessions.Phase so that
7+
// cost records emitted by trace can be correlated with hawk's tok.Tracker
8+
// AggregateByPhase output without importing the contracts package
9+
// (trace is a standalone CLI, not part of the hawk Go module graph).
10+
type PipelinePhase string
11+
12+
const (
13+
// PipelinePhaseLocalize is the file/symbol identification phase.
14+
PipelinePhaseLocalize PipelinePhase = "localize"
15+
// PipelinePhaseRepair is the patch generation phase.
16+
PipelinePhaseRepair PipelinePhase = "repair"
17+
// PipelinePhaseValidate is the test/lint verification phase.
18+
PipelinePhaseValidate PipelinePhase = "validate"
19+
// PipelinePhaseReview is code review; the most token-intensive phase
20+
// at 59.4% of total spend (Tokenomics paper, arXiv 2601.14470).
21+
PipelinePhaseReview PipelinePhase = "review"
22+
// PipelinePhaseUnknown is the zero value for unattributed turns.
23+
PipelinePhaseUnknown PipelinePhase = ""
24+
)
25+
26+
// ParsePipelinePhase returns the PipelinePhase matching s, or
27+
// PipelinePhaseUnknown if unrecognised. Matching is case-sensitive to
28+
// stay consistent with the contracts package and JSON encoding.
29+
func ParsePipelinePhase(s string) PipelinePhase {
30+
switch PipelinePhase(s) {
31+
case PipelinePhaseLocalize, PipelinePhaseRepair,
32+
PipelinePhaseValidate, PipelinePhaseReview:
33+
return PipelinePhase(s)
34+
}
35+
return PipelinePhaseUnknown
36+
}

cli/session/pipeline_phase_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package session_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/GrayCodeAI/trace/cli/session"
7+
)
8+
9+
func TestParsePipelinePhase_Known(t *testing.T) {
10+
cases := []struct {
11+
input string
12+
want session.PipelinePhase
13+
}{
14+
{"localize", session.PipelinePhaseLocalize},
15+
{"repair", session.PipelinePhaseRepair},
16+
{"validate", session.PipelinePhaseValidate},
17+
{"review", session.PipelinePhaseReview},
18+
}
19+
for _, tc := range cases {
20+
got := session.ParsePipelinePhase(tc.input)
21+
if got != tc.want {
22+
t.Errorf("ParsePipelinePhase(%q) = %q, want %q", tc.input, got, tc.want)
23+
}
24+
}
25+
}
26+
27+
func TestParsePipelinePhase_Unknown(t *testing.T) {
28+
for _, s := range []string{"", "unknown", "LOCALIZE", "Repair"} {
29+
if got := session.ParsePipelinePhase(s); got != session.PipelinePhaseUnknown {
30+
t.Errorf("ParsePipelinePhase(%q) = %q, want PipelinePhaseUnknown", s, got)
31+
}
32+
}
33+
}
34+
35+
func TestPipelinePhaseString(t *testing.T) {
36+
if string(session.PipelinePhaseReview) != "review" {
37+
t.Errorf("PipelinePhaseReview string = %q, want %q", session.PipelinePhaseReview, "review")
38+
}
39+
}

0 commit comments

Comments
 (0)