cricinfo-cli-go 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/AGENTS.md +63 -0
  2. package/CONTRIBUTORS.md +75 -0
  3. package/LICENSE +21 -0
  4. package/Makefile +131 -0
  5. package/README.md +130 -0
  6. package/bin/cricinfo.js +44 -0
  7. package/cmd/cricinfo/main.go +15 -0
  8. package/go.mod +10 -0
  9. package/go.sum +10 -0
  10. package/internal/app/app.go +11 -0
  11. package/internal/app/app_test.go +122 -0
  12. package/internal/buildinfo/buildinfo.go +16 -0
  13. package/internal/cli/analysis.go +262 -0
  14. package/internal/cli/analysis_test.go +175 -0
  15. package/internal/cli/competitions.go +154 -0
  16. package/internal/cli/competitions_test.go +165 -0
  17. package/internal/cli/leagues.go +297 -0
  18. package/internal/cli/leagues_test.go +194 -0
  19. package/internal/cli/matches.go +403 -0
  20. package/internal/cli/matches_test.go +413 -0
  21. package/internal/cli/players.go +263 -0
  22. package/internal/cli/players_test.go +384 -0
  23. package/internal/cli/root.go +141 -0
  24. package/internal/cli/search.go +119 -0
  25. package/internal/cli/teams.go +214 -0
  26. package/internal/cli/teams_test.go +192 -0
  27. package/internal/cricinfo/analysis.go +1401 -0
  28. package/internal/cricinfo/analysis_phase15_test.go +267 -0
  29. package/internal/cricinfo/client.go +471 -0
  30. package/internal/cricinfo/client_test.go +280 -0
  31. package/internal/cricinfo/cmd/fixture-refresh/main.go +145 -0
  32. package/internal/cricinfo/competitions.go +405 -0
  33. package/internal/cricinfo/competitions_phase13_test.go +234 -0
  34. package/internal/cricinfo/coverage_ledger.go +122 -0
  35. package/internal/cricinfo/coverage_ledger_test.go +253 -0
  36. package/internal/cricinfo/decode.go +115 -0
  37. package/internal/cricinfo/decode_test.go +100 -0
  38. package/internal/cricinfo/entity_index.go +618 -0
  39. package/internal/cricinfo/entity_index_test.go +175 -0
  40. package/internal/cricinfo/fixture_matrix.go +243 -0
  41. package/internal/cricinfo/fixture_matrix_test.go +49 -0
  42. package/internal/cricinfo/fixtures_test.go +264 -0
  43. package/internal/cricinfo/historical_hydration.go +1641 -0
  44. package/internal/cricinfo/historical_phase14_test.go +542 -0
  45. package/internal/cricinfo/leagues.go +1210 -0
  46. package/internal/cricinfo/leagues_phase12_test.go +324 -0
  47. package/internal/cricinfo/live_leagues_test.go +169 -0
  48. package/internal/cricinfo/live_matches_test.go +203 -0
  49. package/internal/cricinfo/live_matrix_test.go +118 -0
  50. package/internal/cricinfo/live_players_test.go +122 -0
  51. package/internal/cricinfo/live_search_test.go +86 -0
  52. package/internal/cricinfo/live_smoke_test.go +213 -0
  53. package/internal/cricinfo/live_teams_test.go +104 -0
  54. package/internal/cricinfo/matches.go +1508 -0
  55. package/internal/cricinfo/matches_phase7_test.go +207 -0
  56. package/internal/cricinfo/matches_phase9_test.go +253 -0
  57. package/internal/cricinfo/normalize_entities.go +1727 -0
  58. package/internal/cricinfo/normalize_leagues.go +346 -0
  59. package/internal/cricinfo/players.go +1332 -0
  60. package/internal/cricinfo/players_phase10_test.go +174 -0
  61. package/internal/cricinfo/players_phase11_test.go +373 -0
  62. package/internal/cricinfo/render_contract.go +1088 -0
  63. package/internal/cricinfo/render_phase4_test.go +633 -0
  64. package/internal/cricinfo/renderer.go +1689 -0
  65. package/internal/cricinfo/resolver.go +813 -0
  66. package/internal/cricinfo/resolver_test.go +244 -0
  67. package/internal/cricinfo/teams.go +603 -0
  68. package/internal/cricinfo/teams_phase8_test.go +231 -0
  69. package/internal/cricinfo/testdata/fixtures/README.md +43 -0
  70. package/internal/cricinfo/testdata/fixtures/aux-competition-metadata/broadcasts.json +11 -0
  71. package/internal/cricinfo/testdata/fixtures/aux-competition-metadata/officials.json +150 -0
  72. package/internal/cricinfo/testdata/fixtures/details-plays/detail-110.json +157 -0
  73. package/internal/cricinfo/testdata/fixtures/details-plays/detail-52545007.json +145 -0
  74. package/internal/cricinfo/testdata/fixtures/details-plays/detail-52559021.json +143 -0
  75. package/internal/cricinfo/testdata/fixtures/details-plays/plays.json +15 -0
  76. package/internal/cricinfo/testdata/fixtures/endpoint-matrix.tsv +19 -0
  77. package/internal/cricinfo/testdata/fixtures/innings-fow-partnerships/fow-1.json +12 -0
  78. package/internal/cricinfo/testdata/fixtures/innings-fow-partnerships/fow.json +42 -0
  79. package/internal/cricinfo/testdata/fixtures/innings-fow-partnerships/innings-1-2.json +38 -0
  80. package/internal/cricinfo/testdata/fixtures/innings-fow-partnerships/partnership-1.json +31 -0
  81. package/internal/cricinfo/testdata/fixtures/innings-fow-partnerships/partnerships.json +42 -0
  82. package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/calendar-offdays.json +20 -0
  83. package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/calendar-ondays.json +21 -0
  84. package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/calendar.json +14 -0
  85. package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/season-2025.json +13 -0
  86. package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/season-group-1.json +13 -0
  87. package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/season-groups.json +11 -0
  88. package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/season-type-1.json +13 -0
  89. package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/season-types.json +11 -0
  90. package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/seasons.json +30 -0
  91. package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/standings-item-1.json +72 -0
  92. package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/standings-root.json +3 -0
  93. package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/standings.json +15 -0
  94. package/internal/cricinfo/testdata/fixtures/matches-competitions/competition.json +460 -0
  95. package/internal/cricinfo/testdata/fixtures/matches-competitions/event-1529474.json +86 -0
  96. package/internal/cricinfo/testdata/fixtures/matches-competitions/matchcards-1527966.json +368 -0
  97. package/internal/cricinfo/testdata/fixtures/matches-competitions/situation-1529474.json +10 -0
  98. package/internal/cricinfo/testdata/fixtures/players/athlete-1361257-statistics.json +126 -0
  99. package/internal/cricinfo/testdata/fixtures/players/athlete-1361257.json +113 -0
  100. package/internal/cricinfo/testdata/fixtures/players/roster-1361257-linescores-1-1-statistics-0.json +208 -0
  101. package/internal/cricinfo/testdata/fixtures/players/roster-1361257-linescores-1-2-statistics-0.json +252 -0
  102. package/internal/cricinfo/testdata/fixtures/players/roster-1361257-linescores.json +74 -0
  103. package/internal/cricinfo/testdata/fixtures/players/roster-1361257-statistics-0.json +1008 -0
  104. package/internal/cricinfo/testdata/fixtures/root-discovery/events.json +72 -0
  105. package/internal/cricinfo/testdata/fixtures/root-discovery/root.json +28 -0
  106. package/internal/cricinfo/testdata/fixtures/team-competitor/competitor-789643.json +40 -0
  107. package/internal/cricinfo/testdata/fixtures/team-competitor/leaders-789643.json +353 -0
  108. package/internal/cricinfo/testdata/fixtures/team-competitor/records-789643.json +91 -0
  109. package/internal/cricinfo/testdata/fixtures/team-competitor/roster-1147772-object.json +231 -0
  110. package/internal/cricinfo/testdata/fixtures/team-competitor/roster-1147772.json +235 -0
  111. package/internal/cricinfo/testdata/fixtures/team-competitor/roster-789643.json +322 -0
  112. package/internal/cricinfo/testdata/fixtures/team-competitor/scores-789643.json +19 -0
  113. package/internal/cricinfo/testdata/fixtures/team-competitor/statistics-789643.json +629 -0
  114. package/internal/cricinfo/testdata/fixtures/team-competitor/team-789643-athletes.json +7 -0
  115. package/internal/cricinfo/testdata/fixtures/team-competitor/team-789643.json +67 -0
  116. package/internal/cricinfo/testdata/golden/match-empty.golden +1 -0
  117. package/internal/cricinfo/testdata/golden/match-list.golden +2 -0
  118. package/internal/cricinfo/testdata/golden/match-partial.golden +3 -0
  119. package/internal/cricinfo/types.go +54 -0
  120. package/package.json +51 -0
  121. package/scripts/postinstall.js +153 -0
@@ -0,0 +1,267 @@
1
+ package cricinfo
2
+
3
+ import (
4
+ "context"
5
+ "strings"
6
+ "testing"
7
+ "time"
8
+ )
9
+
10
+ func TestPhase15FixtureDeterministicRankingAndGrouping(t *testing.T) {
11
+ t.Parallel()
12
+
13
+ players := []PlayerMatch{
14
+ {
15
+ PlayerID: "1001",
16
+ PlayerName: "Bowler A",
17
+ TeamID: "789643",
18
+ TeamName: "BOOST",
19
+ MatchID: "1529474",
20
+ LeagueID: "19138",
21
+ Bowling: []StatCategory{{
22
+ Name: "bowling",
23
+ Stats: []StatValue{
24
+ {Name: "dots", Value: 24, DisplayValue: "24"},
25
+ {Name: "sixesConceded", Value: 1, DisplayValue: "1"},
26
+ {Name: "balls", Value: 24, DisplayValue: "24"},
27
+ {Name: "conceded", Value: 14, DisplayValue: "14"},
28
+ },
29
+ }},
30
+ Batting: []StatCategory{{
31
+ Name: "batting",
32
+ Stats: []StatValue{
33
+ {Name: "runs", Value: 40, DisplayValue: "40"},
34
+ {Name: "ballsFaced", Value: 30, DisplayValue: "30"},
35
+ {Name: "fours", Value: 5, DisplayValue: "5"},
36
+ {Name: "sixes", Value: 1, DisplayValue: "1"},
37
+ },
38
+ }},
39
+ },
40
+ {
41
+ PlayerID: "1002",
42
+ PlayerName: "Bowler B",
43
+ TeamID: "789644",
44
+ TeamName: "SGH",
45
+ MatchID: "1529474",
46
+ LeagueID: "19138",
47
+ Bowling: []StatCategory{{
48
+ Name: "bowling",
49
+ Stats: []StatValue{
50
+ {Name: "dots", Value: 12, DisplayValue: "12"},
51
+ {Name: "sixesConceded", Value: 3, DisplayValue: "3"},
52
+ {Name: "balls", Value: 24, DisplayValue: "24"},
53
+ {Name: "conceded", Value: 28, DisplayValue: "28"},
54
+ },
55
+ }},
56
+ Batting: []StatCategory{{
57
+ Name: "batting",
58
+ Stats: []StatValue{
59
+ {Name: "runs", Value: 30, DisplayValue: "30"},
60
+ {Name: "ballsFaced", Value: 20, DisplayValue: "20"},
61
+ {Name: "fours", Value: 3, DisplayValue: "3"},
62
+ {Name: "sixes", Value: 2, DisplayValue: "2"},
63
+ },
64
+ }},
65
+ },
66
+ }
67
+
68
+ bowlingAgg := map[string]*analysisAggregate{}
69
+ for _, player := range players {
70
+ totals := extractBowlingTotals(player)
71
+ row := analysisSourceRow{
72
+ MatchID: player.MatchID,
73
+ LeagueID: player.LeagueID,
74
+ TeamID: player.TeamID,
75
+ TeamName: player.TeamName,
76
+ PlayerID: player.PlayerID,
77
+ PlayerName: player.PlayerName,
78
+ Dots: totals.dots,
79
+ SixesConceded: totals.sixesConceded,
80
+ Balls: totals.balls,
81
+ RunsConceded: totals.conceded,
82
+ }
83
+ key, dims := buildAnalysisGroup(row, []string{"player"})
84
+ entry := bowlingAgg[key]
85
+ if entry == nil {
86
+ entry = &analysisAggregate{row: dims, matchIDs: map[string]struct{}{}}
87
+ bowlingAgg[key] = entry
88
+ }
89
+ entry.matchIDs[row.MatchID] = struct{}{}
90
+ entry.dots += row.Dots
91
+ entry.sixesConceded += row.SixesConceded
92
+ entry.balls += row.Balls
93
+ entry.runsConceded += row.RunsConceded
94
+ }
95
+
96
+ economyRows := make([]AnalysisRow, 0, len(bowlingAgg))
97
+ dotRows := make([]AnalysisRow, 0, len(bowlingAgg))
98
+ sixRows := make([]AnalysisRow, 0, len(bowlingAgg))
99
+ for key, entry := range bowlingAgg {
100
+ economyRows = append(economyRows, AnalysisRow{Key: key, Value: economyFromAggregate(entry)})
101
+ dotRows = append(dotRows, AnalysisRow{Key: key, Value: float64(entry.dots), Count: entry.dots})
102
+ sixRows = append(sixRows, AnalysisRow{Key: key, Value: float64(entry.sixesConceded), Count: entry.sixesConceded})
103
+ }
104
+
105
+ economyRows = rankAnalysisRows(economyRows, true)
106
+ dotRows = rankAnalysisRows(dotRows, false)
107
+ sixRows = rankAnalysisRows(sixRows, false)
108
+
109
+ if !strings.Contains(economyRows[0].Key, "Bowler A") {
110
+ t.Fatalf("expected Bowler A to rank first by economy, rows=%+v", economyRows)
111
+ }
112
+ if !strings.Contains(dotRows[0].Key, "Bowler A") {
113
+ t.Fatalf("expected Bowler A to rank first by dots, rows=%+v", dotRows)
114
+ }
115
+ if !strings.Contains(sixRows[0].Key, "Bowler B") {
116
+ t.Fatalf("expected Bowler B to rank first by sixes conceded, rows=%+v", sixRows)
117
+ }
118
+
119
+ battingAgg := map[string]*analysisAggregate{}
120
+ for _, player := range players {
121
+ totals := extractBattingTotals(player)
122
+ row := analysisSourceRow{
123
+ MatchID: player.MatchID,
124
+ LeagueID: player.LeagueID,
125
+ TeamID: player.TeamID,
126
+ TeamName: player.TeamName,
127
+ PlayerID: player.PlayerID,
128
+ PlayerName: player.PlayerName,
129
+ Fours: totals.fours,
130
+ BattingSixes: totals.sixes,
131
+ RunsScored: totals.runs,
132
+ BallsFaced: totals.balls,
133
+ }
134
+ key, dims := buildAnalysisGroup(row, []string{"player"})
135
+ entry := battingAgg[key]
136
+ if entry == nil {
137
+ entry = &analysisAggregate{row: dims, matchIDs: map[string]struct{}{}}
138
+ battingAgg[key] = entry
139
+ }
140
+ entry.matchIDs[row.MatchID] = struct{}{}
141
+ entry.fours += row.Fours
142
+ entry.battingSixes += row.BattingSixes
143
+ entry.runsScored += row.RunsScored
144
+ entry.ballsFaced += row.BallsFaced
145
+ }
146
+
147
+ strikeRows := make([]AnalysisRow, 0, len(battingAgg))
148
+ for key, entry := range battingAgg {
149
+ strikeRows = append(strikeRows, AnalysisRow{Key: key, Value: strikeRateFromAggregate(entry)})
150
+ }
151
+ strikeRows = rankAnalysisRows(strikeRows, false)
152
+ if !strings.Contains(strikeRows[0].Key, "Bowler B") {
153
+ t.Fatalf("expected Bowler B to rank first by strike rate (30/20), rows=%+v", strikeRows)
154
+ }
155
+
156
+ dismissRows := []AnalysisRow{
157
+ {Key: "dismissal=bowled | team=BOOST", Value: 3, Count: 3},
158
+ {Key: "dismissal=caught | team=BOOST", Value: 3, Count: 3},
159
+ {Key: "dismissal=lbw | team=SGH", Value: 2, Count: 2},
160
+ }
161
+ dismissRows = rankAnalysisRows(dismissRows, false)
162
+ if dismissRows[0].Key > dismissRows[1].Key {
163
+ t.Fatalf("expected deterministic tie-break ordering by key, rows=%+v", dismissRows)
164
+ }
165
+ }
166
+
167
+ func TestPhase15BowlingActivityFilterSkipsNonBowlers(t *testing.T) {
168
+ t.Parallel()
169
+
170
+ nonBowler := &analysisAggregate{
171
+ row: AnalysisRow{
172
+ Key: "player=Pure Batter",
173
+ PlayerName: "Pure Batter",
174
+ },
175
+ matchIDs: map[string]struct{}{"1527689": {}},
176
+ }
177
+ bowler := &analysisAggregate{
178
+ row: AnalysisRow{
179
+ Key: "player=Bowler",
180
+ PlayerName: "Bowler",
181
+ },
182
+ matchIDs: map[string]struct{}{"1527689": {}},
183
+ balls: 24,
184
+ runsConceded: 18,
185
+ }
186
+
187
+ if hasBowlingActivity(nonBowler) {
188
+ t.Fatalf("expected non-bowling aggregate to be filtered out")
189
+ }
190
+ if !hasBowlingActivity(bowler) {
191
+ t.Fatalf("expected bowling aggregate to be retained")
192
+ }
193
+
194
+ rows := []AnalysisRow{
195
+ {
196
+ Key: bowler.row.Key,
197
+ Value: economyFromAggregate(bowler),
198
+ },
199
+ }
200
+ rows = rankAnalysisRows(rows, true)
201
+ if len(rows) != 1 || !strings.Contains(rows[0].Key, "Bowler") {
202
+ t.Fatalf("expected only active bowler to remain after filtering, rows=%+v", rows)
203
+ }
204
+ }
205
+
206
+ func TestLivePhase15SmallHistoricalScope(t *testing.T) {
207
+ t.Parallel()
208
+ requireLiveMatrix(t)
209
+
210
+ service, err := NewAnalysisService(AnalysisServiceConfig{})
211
+ if err != nil {
212
+ t.Fatalf("NewAnalysisService error: %v", err)
213
+ }
214
+ defer func() {
215
+ _ = service.Close()
216
+ }()
217
+
218
+ ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
219
+ defer cancel()
220
+
221
+ bowlingResult, err := service.Bowling(ctx, AnalysisMetricOptions{
222
+ Metric: "economy",
223
+ Scope: "season:2025",
224
+ LeagueQuery: "19138",
225
+ Top: 5,
226
+ })
227
+ if err != nil {
228
+ t.Fatalf("Bowling live error: %v", err)
229
+ }
230
+ if bowlingResult.Status == ResultStatusError {
231
+ if bowlingResult.Error != nil && bowlingResult.Error.StatusCode == 503 {
232
+ t.Skipf("skipping after transient 503: %+v", bowlingResult.Error)
233
+ }
234
+ t.Fatalf("unexpected bowling live status error: %+v", bowlingResult)
235
+ }
236
+
237
+ dismissResult, err := service.Dismissals(ctx, AnalysisDismissalOptions{
238
+ LeagueQuery: "19138",
239
+ Seasons: "2024-2025",
240
+ Top: 5,
241
+ })
242
+ if err != nil {
243
+ t.Fatalf("Dismissals live error: %v", err)
244
+ }
245
+ if dismissResult.Status == ResultStatusError {
246
+ if dismissResult.Error != nil && dismissResult.Error.StatusCode == 503 {
247
+ t.Skipf("skipping after transient 503: %+v", dismissResult.Error)
248
+ }
249
+ t.Fatalf("unexpected dismissals live status error: %+v", dismissResult)
250
+ }
251
+
252
+ dotsResult, err := service.Bowling(ctx, AnalysisMetricOptions{
253
+ Metric: "dots",
254
+ Scope: "match:1529474",
255
+ LeagueQuery: "19138",
256
+ Top: 5,
257
+ })
258
+ if err != nil {
259
+ t.Fatalf("Bowling dots live error: %v", err)
260
+ }
261
+ if dotsResult.Status == ResultStatusError {
262
+ if dotsResult.Error != nil && dotsResult.Error.StatusCode == 503 {
263
+ t.Skipf("skipping after transient 503: %+v", dotsResult.Error)
264
+ }
265
+ t.Fatalf("unexpected bowling dots status error: %+v", dotsResult)
266
+ }
267
+ }