Handle empty base with no segments in checkpointSubtreePath · Entire

Handle empty base with no segments in checkpointSubtreePath

6afd87c·

Soph·2w ago·2 files·+11 added/-0 removed

path.Join with no trailing segments cleans a "" base to "." — an invalid git tree key. No current caller hits this (all pass at least one segment), but the helper's contract says it handles the ref root (base=="") safely, so make that true: return "" for the ref root and the cleaned base otherwise. Adds the ref-root-base-only test case to lock the behavior.

Addresses Copilot review on #1576.

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

Sessions

a0d229c313efView transcript

Changes

2

147 unmodified lines

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

147 unmodified lines

// and checkpointSubtreePath("a3/b2.../", "0", "metadata.json") == "a3/b2.../0/metadata.json".
// Callers therefore need not maintain the trailing-slash invariant by hand.
func checkpointSubtreePath(base string, segs ...string) string {
    if len(segs) == 0 {
        // path.Join with no segments would clean a "" base to "." — an invalid
        // git tree key. At the ref root the correct key is ""; for a non-empty
        // base, clean it to keep the trailing-slash-stripping behavior.
        if base == "" {
            return ""
        }
        return path.Clean(base)
    }
    return path.Join(append([]string{base}, segs...)...)
}

Mcmd/entire/cli/checkpoint/persistent.go+9

20 unmodified lines

21
22
23
24
25
26
27
28

20 unmodified lines

{"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"},
        // Ref root with no segments must stay "" (not path.Join's "." cleaning).
        {"ref root base only", "", nil, ""},
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {