reject checkpoint token self-comparison · Entire

reject checkpoint token self-comparison

3b91262·

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

2344 unmodified lines

2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379

2344 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()