reject checkpoint token self-comparison · Entire

reject checkpoint token self-comparison

dee0162·

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

Sessions

caff12e75277View transcript

Changes

2

111 unmodified lines

112
113
114
115
116
117
118
119
120
121

111 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

2288 unmodified lines

2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323

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