11//go:build ignore
22
3- // score.go: Crane migration scoring script.
4- // Usage: cd cmd/apm && go test -json ./... | go run ../../.crane/scripts/score.go
3+ // score.go -- migration scoring script for the APM CLI Python-to-Go migration.
4+ // Usage: go test -json ./... | go run .crane/scripts/score.go
5+ // Outputs JSON with migration_score and progress metrics.
56//
6- // Reads go test JSON output from stdin and emits a migration score JSON object.
7- // migration_score = (parity_passing / parity_total) * correctness_gate
8- // where correctness_gate = 1.0 if all target tests pass, 0.0 otherwise.
7+ // Scoring formula:
8+ // migration_score = (parity_passing / parity_total) * correctness_gate
9+ // correctness_gate = 1.0 if all target tests pass, 0.0 otherwise
10+ //
11+ // NOTE: This script must NOT be modified after milestone 1 is accepted.
912
1013package main
1114
@@ -14,17 +17,17 @@ import (
1417 "encoding/json"
1518 "fmt"
1619 "os"
20+ "strings"
1721)
1822
1923type TestEvent struct {
20- Action string `json:"Action"`
21- Test string `json:"Test"`
22- Package string `json:"Package"`
23- Elapsed float64 `json:"Elapsed"`
24- Output string `json:"Output"`
24+ Action string `json:"Action"`
25+ Package string `json:"Package"`
26+ Test string `json:"Test"`
27+ Output string `json:"Output"`
2528}
2629
27- type ScoreOutput struct {
30+ type Score struct {
2831 MigrationScore float64 `json:"migration_score"`
2932 Progress float64 `json:"progress"`
3033 ParityPassing int `json:"parity_passing"`
@@ -35,68 +38,69 @@ type ScoreOutput struct {
3538}
3639
3740func main () {
38- var passed , failed int
3941 scanner := bufio .NewScanner (os .Stdin )
4042
43+ var parityPassing , parityTotal , targetPassing , targetTotal int
44+
4145 for scanner .Scan () {
42- line := scanner .Bytes ()
43- if len (line ) == 0 {
46+ line := scanner .Text ()
47+ if ! strings . HasPrefix (line , "{" ) {
4448 continue
4549 }
4650 var ev TestEvent
47- if err := json .Unmarshal (line , & ev ); err != nil {
51+ if err := json .Unmarshal ([] byte ( line ) , & ev ); err != nil {
4852 continue
4953 }
5054 if ev .Test == "" {
51- // package-level event
5255 continue
5356 }
54- switch ev .Action {
55- case "pass" :
56- passed ++
57- case "fail" :
58- failed ++
57+
58+ isParity := strings .Contains (ev .Test , "Parity" ) || strings .Contains (ev .Package , "parity" )
59+ isTarget := strings .HasPrefix (ev .Package , "github.com/githubnext/apm/" )
60+
61+ if isParity {
62+ if ev .Action == "run" {
63+ parityTotal ++
64+ } else if ev .Action == "pass" {
65+ parityPassing ++
66+ }
67+ }
68+ if isTarget {
69+ if ev .Action == "run" {
70+ targetTotal ++
71+ } else if ev .Action == "pass" {
72+ targetPassing ++
73+ }
5974 }
6075 }
6176
62- total := passed + failed
63- // parity_total is the number of Python source modules (302).
64- // Until parity tests are wired, this reflects Go test count.
65- const parityTotal = 302
66- parityPassing := 0
67- if total > 0 {
68- parityPassing = passed
77+ correctnessGate := 1.0
78+ if targetTotal > 0 && targetPassing < targetTotal {
79+ correctnessGate = 0.0
6980 }
7081
71- correctnessGate := 0.0
72- if total > 0 && failed == 0 {
73- correctnessGate = 1.0
74- } else if total == 0 {
75- // No tests yet -- score is 0 but not a failure.
76- correctnessGate = 0.0
82+ total := 302 // fixed: total Python modules/functions to port
83+ if parityTotal > total {
84+ total = parityTotal
7785 }
7886
79- progress := 0.0
80- if parityTotal > 0 {
81- progress = float64 (parityPassing ) / float64 (parityTotal )
87+ var migrationScore float64
88+ if total > 0 {
89+ migrationScore = ( float64 (parityPassing ) / float64 (total )) * correctnessGate
8290 }
8391
84- migrationScore := progress * correctnessGate
92+ progress := float64 ( parityPassing ) / float64 ( total )
8593
86- out := ScoreOutput {
94+ score := Score {
8795 MigrationScore : migrationScore ,
8896 Progress : progress ,
8997 ParityPassing : parityPassing ,
90- ParityTotal : parityTotal ,
91- SourceTestsPassing : 247 ,
92- TargetTestsPassing : passed ,
98+ ParityTotal : total ,
99+ SourceTestsPassing : 247 , // stable Python baseline
100+ TargetTestsPassing : targetPassing ,
93101 PerfRatio : 1.0 ,
94102 }
95103
96- enc := json .NewEncoder (os .Stdout )
97- enc .SetIndent ("" , " " )
98- if err := enc .Encode (out ); err != nil {
99- fmt .Fprintf (os .Stderr , "score.go: encode error: %v\n " , err )
100- os .Exit (1 )
101- }
104+ out , _ := json .MarshalIndent (score , "" , " " )
105+ fmt .Println (string (out ))
102106}
0 commit comments