Build checkpoint subtree paths via path.Join helper (no tree change) · Entire

Build checkpoint subtree paths via path.Join helper (no tree change)

a13bcc5·

Soph·2w ago·2 files·+117 added/-66 removed

A reviewer flagged fmt.Sprintf("%s%d/%s", basePath, idx, paths.MetadataFileName) as looking like a missing slash — it's correct only because basePath carries a trailing "/". Replace the string-concat path construction with a checkpointSubtreePath(base, segs...) helper over stdlib path.Join, so paths join correctly without relying on that invariant.

No behavior change: committed-tree assertions (checkpoint write/read, tripwire, update), integration (378), and both canary modes (git-branch 59/59, git-refs 58/59 +1 skip) are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Sessions

973f8248e820View transcript

Changes

2

package checkpoint

import "testing"

func TestCheckpointSubtreePath(t *testing.T) {
    t.Parallel()
    tests := []struct {
        name string
        base string
        segs []string
        want string
    }{
        // Per-checkpoint-ref root (basePath == ").
        {"ref root metadata", "", []string{"metadata.json"}, "metadata.json"},
        {"ref root session meta", "", []string{"0", "metadata.json"}, "0/metadata.json"},
        // v1 branch layout (basePath has a trailing slash — path.Join cleans it).
        {"v1 root metadata", "a3/b2c4d5e6f7/", []string{"metadata.json"}, "a3/b2c4d5e6f7/metadata.json"},
        {"v1 session meta", "a3/b2c4d5e6f7/", []string{"0", "metadata.json"}, "a3/b2c4d5e6f7/0/metadata.json"},
        {"v1 task file", "a3/b2c4d5e6f7/", []string{"tasks", "tool-1", "checkpoint.json"}, "a3/b2c4d5e6f7/tasks/tool-1/checkpoint.json"},
        // A clean dir base (no trailing slash) joins identically.
        {"clean session dir", "a3/b2c4d5e6f7/0", []string{"full.jsonl"}, "a3/b2c4d5e6f7/0/full.jsonl"},
        // No segments returns the cleaned base (trailing slash stripped).
        {"base only trailing slash", "a3/b2c4d5e6f7/", nil, "a3/b2c4d5e6f7"},
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            if got := checkpointSubtreePath(tt.base, tt.segs...); got != tt.want {
                t.Errorf("checkpointSubtreePath(%q, %v) = %q, want %q", tt.base, tt.segs, got, tt.want)
            }
        })
    }
}