Skip to content

Commit cdb2aaf

Browse files
authored
Merge pull request #13 from tstromberg/main
Upgrade to latest ds9 & prx libraries
2 parents 986931c + e71127d commit cdb2aaf

File tree

5 files changed

+40
-40
lines changed

5 files changed

+40
-40
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ jobs:
1414
contents: read
1515

1616
steps:
17-
- name: Check out code
18-
uses: actions/checkout@v4
19-
with:
20-
persist-credentials: false
17+
- name: Check out code
18+
uses: actions/checkout@v4
19+
with:
20+
persist-credentials: false
2121

22-
- name: Set up Go
23-
uses: actions/setup-go@v5
24-
with:
25-
go-version-file: 'go.mod'
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version-file: 'go.mod'
2626

27-
- name: Run tests
28-
run: make test
27+
- name: Run tests
28+
run: make test
2929

30-
- name: Upload coverage
31-
uses: codecov/codecov-action@v4
32-
if: success()
33-
with:
34-
fail_ci_if_error: false
30+
- name: Upload coverage
31+
uses: codecov/codecov-action@v4
32+
if: success()
33+
with:
34+
fail_ci_if_error: false

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module github.com/codeGROOVE-dev/prcost
33
go 1.25.3
44

55
require (
6-
github.com/codeGROOVE-dev/ds9 v0.0.0-20251028153329-0fbc86f835ed
6+
github.com/codeGROOVE-dev/ds9 v0.5.0
77
github.com/codeGROOVE-dev/gsm v0.0.0-20251019065141-833fe2363d22
8-
github.com/codeGROOVE-dev/prx v0.0.0-20251027204543-4e6165f046e5
8+
github.com/codeGROOVE-dev/prx v0.0.0-20251028202628-9f237ee71356
99
github.com/codeGROOVE-dev/turnclient v0.0.0-20251028130307-1f85c9aa43c4
1010
golang.org/x/time v0.14.0
1111
)

go.sum

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
github.com/codeGROOVE-dev/ds9 v0.0.0-20251028153329-0fbc86f835ed h1:PNvhCROSwAybWrJwYkTBUAaydQKJ8dWD8ml7gde5nkA=
2-
github.com/codeGROOVE-dev/ds9 v0.0.0-20251028153329-0fbc86f835ed/go.mod h1:/hZt40fp5FfuzVwiw9fgoOMBAa260rKPiWNJt8RU10Y=
1+
github.com/codeGROOVE-dev/ds9 v0.5.0 h1:J5IX1S1HtuJjGvj/gaMCXMY0HQb5Gzqz5c1a2uz14VM=
2+
github.com/codeGROOVE-dev/ds9 v0.5.0/go.mod h1:/hZt40fp5FfuzVwiw9fgoOMBAa260rKPiWNJt8RU10Y=
33
github.com/codeGROOVE-dev/gsm v0.0.0-20251019065141-833fe2363d22 h1:gtN3rOc6YspO646BkcOxBhPjEqKUz+jl175jIqglfDg=
44
github.com/codeGROOVE-dev/gsm v0.0.0-20251019065141-833fe2363d22/go.mod h1:KV+w19ubP32PxZPE1hOtlCpTaNpF0Bpb32w5djO8UTg=
5-
github.com/codeGROOVE-dev/prx v0.0.0-20251027012315-7b273aabfc7d h1:kUaCKFRxWFrWEyl4fVHi+eY/D5tKhBU29a8YbQyihEk=
6-
github.com/codeGROOVE-dev/prx v0.0.0-20251027012315-7b273aabfc7d/go.mod h1:7qLbi18baOyS8yO/6/64SBIqtyzSzLFdsDST15NPH3w=
7-
github.com/codeGROOVE-dev/prx v0.0.0-20251027204543-4e6165f046e5 h1:tjxTLJ5NXx1xhReL4M+J4LTl/JGNSZjPrznAoci06OA=
8-
github.com/codeGROOVE-dev/prx v0.0.0-20251027204543-4e6165f046e5/go.mod h1:FEy3gz9IYDXWnKWkoDSL+pWu6rujxbBSrF4w5A8QSK0=
9-
github.com/codeGROOVE-dev/retry v1.2.0 h1:xYpYPX2PQZmdHwuiQAGGzsBm392xIMl4nfMEFApQnu8=
10-
github.com/codeGROOVE-dev/retry v1.2.0/go.mod h1:8OgefgV1XP7lzX2PdKlCXILsYKuz6b4ZpHa/20iLi8E=
5+
github.com/codeGROOVE-dev/prx v0.0.0-20251028202628-9f237ee71356 h1:lHoHnylLAp7/7BMhdiTh9Z2+p4ATcQ7aFcgqxOFGzE4=
6+
github.com/codeGROOVE-dev/prx v0.0.0-20251028202628-9f237ee71356/go.mod h1:FEy3gz9IYDXWnKWkoDSL+pWu6rujxbBSrF4w5A8QSK0=
117
github.com/codeGROOVE-dev/retry v1.3.0 h1:/+ipAWRJLL6y1R1vprYo0FSjSBvH6fE5j9LKXjpD54g=
128
github.com/codeGROOVE-dev/retry v1.3.0/go.mod h1:8OgefgV1XP7lzX2PdKlCXILsYKuz6b4ZpHa/20iLi8E=
13-
github.com/codeGROOVE-dev/turnclient v0.0.0-20251022064427-5a712e1e10e6 h1:7FCmaftkl362oTZHVJyUg+xhxqfQFx+JisBf7RgklL8=
14-
github.com/codeGROOVE-dev/turnclient v0.0.0-20251022064427-5a712e1e10e6/go.mod h1:fYwtN9Ql6lY8t2WvCfENx+mP5FUwjlqwXCLx9CVLY20=
159
github.com/codeGROOVE-dev/turnclient v0.0.0-20251028130307-1f85c9aa43c4 h1:si9tMEo5SXpDuDXGkJ1zNnnpP8TbmakrkNujAbpKlqA=
1610
github.com/codeGROOVE-dev/turnclient v0.0.0-20251028130307-1f85c9aa43c4/go.mod h1:bFWMd0JeaJY0kSIO5AcRQdJLXF3Fo3eKclE49vmIZes=
1711
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=

internal/server/server.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"sync"
2121
"time"
2222

23-
"github.com/codeGROOVE-dev/ds9"
23+
"github.com/codeGROOVE-dev/ds9/pkg/datastore"
2424
"github.com/codeGROOVE-dev/gsm"
2525
"github.com/codeGROOVE-dev/prcost/pkg/cost"
2626
"github.com/codeGROOVE-dev/prcost/pkg/github"
@@ -117,7 +117,7 @@ type Server struct {
117117
prDataCacheMu sync.RWMutex
118118
calcResultCacheMu sync.RWMutex
119119
// DataStore client for persistent caching (nil if not enabled).
120-
dsClient *ds9.Client
120+
dsClient *datastore.Client
121121
}
122122

123123
// CalculateRequest represents a request to calculate PR costs.
@@ -236,7 +236,7 @@ func New() *Server {
236236

237237
// Initialize DataStore client if DATASTORE_DB is set (persistent caching across restarts).
238238
if dbID := os.Getenv("DATASTORE_DB"); dbID != "" {
239-
dsClient, err := ds9.NewClientWithDatabase(ctx, "", dbID)
239+
dsClient, err := datastore.NewClientWithDatabase(ctx, "", dbID)
240240
if err != nil {
241241
logger.WarnContext(ctx, "Failed to initialize DataStore client - persistent caching disabled",
242242
"database_id", dbID, "error", err)
@@ -374,11 +374,11 @@ func (s *Server) cachedPRQuery(ctx context.Context, key string) ([]github.PRSumm
374374
return nil, false
375375
}
376376

377-
dsKey := ds9.NameKey("PRQueryCache", key, nil)
377+
dsKey := datastore.NameKey("PRQueryCache", key, nil)
378378
var entity prQueryCacheEntity
379379
err := s.dsClient.Get(ctx, dsKey, &entity)
380380
if err != nil {
381-
if !errors.Is(err, ds9.ErrNoSuchEntity) {
381+
if !errors.Is(err, datastore.ErrNoSuchEntity) {
382382
s.logger.WarnContext(ctx, "DataStore cache read failed", "key", key, "error", err)
383383
}
384384
return nil, false
@@ -452,7 +452,7 @@ func (s *Server) cachePRQuery(ctx context.Context, key string, prs []github.PRSu
452452
QueryKey: key,
453453
}
454454

455-
dsKey := ds9.NameKey("PRQueryCache", key, nil)
455+
dsKey := datastore.NameKey("PRQueryCache", key, nil)
456456
if _, err := s.dsClient.Put(ctx, dsKey, &entity); err != nil {
457457
s.logger.WarnContext(ctx, "Failed to write PR query to DataStore", "key", key, "error", err)
458458
return
@@ -482,11 +482,11 @@ func (s *Server) cachedPRData(ctx context.Context, key string) (cost.PRData, boo
482482
return cost.PRData{}, false
483483
}
484484

485-
dsKey := ds9.NameKey("PRDataCache", key, nil)
485+
dsKey := datastore.NameKey("PRDataCache", key, nil)
486486
var entity prDataCacheEntity
487487
err := s.dsClient.Get(ctx, dsKey, &entity)
488488
if err != nil {
489-
if !errors.Is(err, ds9.ErrNoSuchEntity) {
489+
if !errors.Is(err, datastore.ErrNoSuchEntity) {
490490
s.logger.WarnContext(ctx, "DataStore cache read failed", "key", key, "error", err)
491491
}
492492
return cost.PRData{}, false
@@ -542,7 +542,7 @@ func (s *Server) cachePRData(ctx context.Context, key string, prData cost.PRData
542542
URL: key,
543543
}
544544

545-
dsKey := ds9.NameKey("PRDataCache", key, nil)
545+
dsKey := datastore.NameKey("PRDataCache", key, nil)
546546
if _, err := s.dsClient.Put(ctx, dsKey, &entity); err != nil {
547547
s.logger.WarnContext(ctx, "Failed to write PR data to DataStore", "key", key, "error", err)
548548
return
@@ -586,11 +586,11 @@ func (s *Server) cachedCalcResult(ctx context.Context, prURL string, cfg cost.Co
586586
return cost.Breakdown{}, false
587587
}
588588

589-
dsKey := ds9.NameKey("CalcResultCache", key, nil)
589+
dsKey := datastore.NameKey("CalcResultCache", key, nil)
590590
var entity calcResultCacheEntity
591591
err := s.dsClient.Get(ctx, dsKey, &entity)
592592
if err != nil {
593-
if !errors.Is(err, ds9.ErrNoSuchEntity) {
593+
if !errors.Is(err, datastore.ErrNoSuchEntity) {
594594
s.logger.WarnContext(ctx, "DataStore calc cache read failed", "key", key, "error", err)
595595
}
596596
return cost.Breakdown{}, false
@@ -646,7 +646,7 @@ func (s *Server) cacheCalcResult(ctx context.Context, prURL string, cfg cost.Con
646646
ConfigKey: configHash(cfg),
647647
}
648648

649-
dsKey := ds9.NameKey("CalcResultCache", key, nil)
649+
dsKey := datastore.NameKey("CalcResultCache", key, nil)
650650
if _, err := s.dsClient.Put(ctx, dsKey, &entity); err != nil {
651651
s.logger.WarnContext(ctx, "Failed to write calc result to DataStore", "key", key, "error", err)
652652
return

pkg/cost/cost_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log/slog"
88
"os"
99
"strings"
10+
"sync"
1011
"testing"
1112
"time"
1213
)
@@ -702,6 +703,7 @@ func TestCalculateFastTurnaroundNoDelay(t *testing.T) {
702703

703704
// Mock PRFetcher for testing AnalyzePRs
704705
type mockPRFetcher struct {
706+
mu sync.Mutex
705707
data map[string]PRData
706708
failURLs map[string]error
707709
callCount int
@@ -710,10 +712,14 @@ type mockPRFetcher struct {
710712
}
711713

712714
func (m *mockPRFetcher) FetchPRData(ctx context.Context, prURL string, updatedAt time.Time) (PRData, error) {
715+
m.mu.Lock()
713716
m.callCount++
717+
callCount := m.callCount
718+
maxCalls := m.maxCalls
719+
m.mu.Unlock()
714720

715721
// Fail after max calls if set
716-
if m.maxCalls > 0 && m.callCount > m.maxCalls {
722+
if maxCalls > 0 && callCount > maxCalls {
717723
return PRData{}, errors.New("max calls exceeded")
718724
}
719725

0 commit comments

Comments
 (0)