Skip to content

Commit fd2d73b

Browse files
committed
feat(stats): add cost breakdown, forecast, and cache stats
1 parent 5f7cff0 commit fd2d73b

9 files changed

Lines changed: 297 additions & 24 deletions

File tree

internal/ai/gemini/pull_requests_summarizer_service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func TestGeneratePRSummary_HappyPath(t *testing.T) {
173173
summary, err := summarizer.GeneratePRSummary(ctx, "content with empty title")
174174

175175
assert.Error(t, err)
176-
assert.Contains(t, err.Error(), "no PR title")
176+
assert.Contains(t, err.Error(), "invalid AI output format")
177177
assert.Empty(t, summary.Title)
178178
})
179179
}

internal/ai/gemini/release_generator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,6 @@ func TestGenerateNotes(t *testing.T) {
324324

325325
// Assert
326326
assert.Error(t, err)
327-
assert.Contains(t, err.Error(), "empty response from AI")
327+
assert.Contains(t, err.Error(), "invalid AI output format")
328328
})
329329
}

internal/commands/stats/stats_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func TestShowMonthlyStats_NoActivity(t *testing.T) {
189189
os.Stdout = w
190190

191191
// Act
192-
err := cmd.showMonthlyStats(manager, trans)
192+
err := cmd.showMonthlyStats(manager, trans, false)
193193

194194
_ = w.Close()
195195
os.Stdout = oldStdout
@@ -243,7 +243,7 @@ func TestShowMonthlyStats_WithActivity(t *testing.T) {
243243
os.Stdout = w
244244

245245
// Act
246-
err := cmd.showMonthlyStats(manager, trans)
246+
err := cmd.showMonthlyStats(manager, trans, false)
247247

248248
_ = w.Close()
249249
os.Stdout = oldStdout
@@ -290,7 +290,7 @@ func TestShowMonthlyStats_GroupsByDay(t *testing.T) {
290290
os.Stdout = w
291291

292292
// Act
293-
err := cmd.showMonthlyStats(manager, trans)
293+
err := cmd.showMonthlyStats(manager, trans, false)
294294

295295
_ = w.Close()
296296
os.Stdout = oldStdout
@@ -436,7 +436,7 @@ func TestStatsCommand_Integration(t *testing.T) {
436436
r2, w2, _ := os.Pipe()
437437
os.Stdout = w2
438438

439-
errMonthly := cmd.showMonthlyStats(manager, trans)
439+
errMonthly := cmd.showMonthlyStats(manager, trans, false)
440440

441441
_ = w2.Close()
442442
os.Stdout = oldStdout
@@ -479,7 +479,7 @@ func TestShowMonthlyStats_HandlesManagerErrors(t *testing.T) {
479479
require.NoError(t, err)
480480

481481
// Act
482-
err = cmd.showMonthlyStats(manager, trans)
482+
err = cmd.showMonthlyStats(manager, trans, false)
483483

484484
// Assert
485485
assert.Error(t, err, "should return an error when the history is corrupt")

internal/commands/suggests_commits/suggests_commits_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ func (m *MockGitService) ValidateGitConfig(ctx context.Context) error {
4343
return args.Error(0)
4444
}
4545

46+
func (m *MockGitService) GetChangedFiles(ctx context.Context) ([]string, error) {
47+
args := m.Called(ctx)
48+
if args.Get(0) == nil {
49+
return nil, args.Error(1)
50+
}
51+
return args.Get(0).([]string), args.Error(1)
52+
}
53+
54+
func (m *MockGitService) GetDiff(ctx context.Context) (string, error) {
55+
args := m.Called(ctx)
56+
return args.String(0), args.Error(1)
57+
}
58+
4659
func setupTestEnv(t *testing.T) (*config.Config, *i18n.Translations, func()) {
4760
tmpDir, err := os.MkdirTemp("", "matecommit-test-*")
4861
if err != nil {

internal/errors/errors_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ func TestAppError_Error_Format(t *testing.T) {
4141
err: ErrNoChanges,
4242
contains: []string{
4343
"GIT",
44-
"no staged changes detected",
44+
"No staged changes detected",
4545
},
4646
},
4747
{
4848
name: "Error with underlying error",
4949
err: ErrGetBranch.WithError(errors.New("exit status 1")),
5050
contains: []string{
5151
"GIT",
52-
"failed to get current branch",
52+
"Failed to get current branch",
5353
"exit status 1",
5454
},
5555
},
@@ -60,7 +60,7 @@ func TestAppError_Error_Format(t *testing.T) {
6060
WithContext("stderr", "did not match any files"),
6161
contains: []string{
6262
"GIT",
63-
"failed to add file to staging",
63+
"Failed to add file to staging",
6464
"exit status 128",
6565
"did not match any files",
6666
},
@@ -72,7 +72,7 @@ func TestAppError_Error_Format(t *testing.T) {
7272
WithContext("stderr", "repository not found"),
7373
contains: []string{
7474
"GIT",
75-
"failed to get diff",
75+
"Failed to get diff",
7676
"command failed",
7777
"repository not found",
7878
},

internal/git/git_service_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ func TestGitService_ErrorHandling(t *testing.T) {
741741
var appErr *domainErrors.AppError
742742
assert.True(t, errors.As(err, &appErr))
743743
assert.Equal(t, domainErrors.TypeGit, appErr.Type)
744-
assert.Contains(t, err.Error(), "failed to get commit count")
744+
assert.Contains(t, err.Error(), "Failed to get commit count")
745745
})
746746
}
747747

@@ -970,7 +970,7 @@ func TestGitService_Push(t *testing.T) {
970970
var appErr *domainErrors.AppError
971971
assert.True(t, errors.As(err, &appErr))
972972
assert.Equal(t, domainErrors.TypeGit, appErr.Type)
973-
assert.Contains(t, err.Error(), "failed to push to remote")
973+
assert.Contains(t, err.Error(), "Failed to push to remote")
974974
})
975975
}
976976

internal/github/github_service_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ func TestGitHubClient_UpdatePR_ErrorCases(t *testing.T) {
275275

276276
assert.Error(t, err)
277277
assert.Contains(t, err.Error(), "insufficient permissions")
278-
assert.Contains(t, err.Error(), "required scopes")
279278
mockPR.AssertExpectations(t)
280279
})
281280
}
@@ -342,9 +341,10 @@ func TestGitHubClient_GetPR_ErrorCases(t *testing.T) {
342341
client := newTestClient(mockPR, mockIssues, mockRelease, mockUserService)
343342

344343
mockPR.On("Get", mock.Anything, "test-owner", "test-repo", 123).
345-
Return(&github.PullRequest{}, &github.Response{}, assert.AnError)
344+
Return(&github.PullRequest{}, &github.Response{Response: &http.Response{StatusCode: http.StatusInternalServerError}}, assert.AnError)
346345

347346
_, err := client.GetPR(context.Background(), 123)
347+
assert.Error(t, err)
348348
assert.Contains(t, err.Error(), "failed to get PR #123")
349349
})
350350

@@ -454,7 +454,7 @@ func TestGitHubClient_CreateRelease(t *testing.T) {
454454

455455
err := client.CreateRelease(context.Background(), release, notes, false, true)
456456
assert.Error(t, err)
457-
assert.Contains(t, err.Error(), "release already exists for version v1.0.0")
457+
assert.Contains(t, err.Error(), "failed to create release")
458458
})
459459

460460
t.Run("should return error if repo or tag not found", func(t *testing.T) {
@@ -473,7 +473,7 @@ func TestGitHubClient_CreateRelease(t *testing.T) {
473473

474474
err := client.CreateRelease(context.Background(), release, notes, false, true)
475475
assert.Error(t, err)
476-
assert.Contains(t, err.Error(), "repository or tag not found for version v1.0.0")
476+
assert.Contains(t, err.Error(), "repository not found")
477477
})
478478

479479
t.Run("should return generic error for other failures", func(t *testing.T) {
@@ -541,7 +541,7 @@ func TestGitHubClient_GetRelease(t *testing.T) {
541541

542542
assert.Error(t, err)
543543
assert.Nil(t, release)
544-
assert.Contains(t, err.Error(), "repository or tag not found for version v1.0.0")
544+
assert.Contains(t, err.Error(), "repository not found")
545545
mockRelease.AssertExpectations(t)
546546
})
547547

@@ -603,7 +603,7 @@ func TestGitHubClient_UpdateRelease(t *testing.T) {
603603
err := client.UpdateRelease(context.Background(), "v1.0.0", "Updated body")
604604

605605
assert.Error(t, err)
606-
assert.Contains(t, err.Error(), "repository or tag not found for version v1.0.0")
606+
assert.Contains(t, err.Error(), "repository not found")
607607
mockRelease.AssertExpectations(t)
608608
})
609609

@@ -1400,7 +1400,7 @@ func TestGitHubClient_CreateIssue(t *testing.T) {
14001400
client := newTestClient(mockPR, mockIssues, mockRelease, mockUserService)
14011401

14021402
mockIssues.On("Create", mock.Anything, "test-owner", "test-repo", mock.Anything).
1403-
Return((*github.Issue)(nil), &github.Response{}, assert.AnError)
1403+
Return((*github.Issue)(nil), &github.Response{Response: &http.Response{StatusCode: http.StatusInternalServerError}}, assert.AnError)
14041404

14051405
_, err := client.CreateIssue(context.Background(), "Title", "Body", nil, nil)
14061406

0 commit comments

Comments
 (0)