reject checkpoint token self-comparison · Entire

reject checkpoint token self-comparison

66af1f9·

peyton-alt·3w ago·2 files·+33 added/-0 removed

Sessions

caff12e75277View transcript

Changes

2

116 unmodified lines

117
118
119
120
121
122
123
124
125
126

116 unmodified lines

if err != nil {
        return tokenCommandError(err)
    }
    if baselineReport.CheckpointID == report.CheckpointID {
        cmd.SilenceUsage = true
        return fmt.Errorf("cannot compare checkpoint %s to itself", report.CheckpointID)
    }
    report.Comparison = buildCheckpointTokensComparison(report, baselineReport)
    }

Mcmd/entire/cli/checkpoint_tokens.go+4

2315 unmodified lines

2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350

2315 unmodified lines

}
}

func TestCheckpointTokensCmd_RejectsSelfComparison(t *testing.T) {
    repo, _ := runExplainAutoTestRepo(t)
    ctx := context.Background()
    store := checkpoint.NewGitStore(repo, checkpoint.DefaultV1Refs())
    cpID := id.MustCheckpointID("abc222abc222")

writeCommittedTokenCheckpoint(ctx, t, store, cpID, "checkpoint-token-self-compare", &agent.TokenUsage{
        InputTokens:  100,
        OutputTokens: 50,
        APICallCount: 1,
    })

cmd := newCheckpointGroupCmd()
    var stdout bytes.Buffer
    cmd.SetOut(&stdout)
    cmd.SetArgs([]string{"tokens", "abc222", "--compare", "abc222abc222"})

err := cmd.ExecuteContext(ctx)
    if err == nil {
        t.Fatal("expected self-comparison error, got nil")
    }
    if !strings.Contains(err.Error(), "cannot compare checkpoint abc222abc222 to itself") {
        t.Fatalf("expected self-comparison error, got: %v", err)
    }
    if stdout.Len() != 0 {
        t.Fatalf("expected no report output for self-comparison, got:\n%s", stdout.String())
    }
}

func TestCheckpointTokensCmd_JSONOutputWithComparison(t *testing.T) {
    repo, _ := runExplainAutoTestRepo(t)
    ctx := context.Background()