Skip to content

Commit 584f720

Browse files
author
Bertan Ari
committed
fix: accept SHA-256 checkpoint hashes in restore validation
1 parent 86777f9 commit 584f720

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎src/core/checkpoints/__tests__/checkpoint.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,19 @@ describe("Checkpoint functionality", () => {
309309
},
310310
)
311311

312+
it("accepts a recorded SHA-256 checkpoint hash", async () => {
313+
const sha256Hash = "c".repeat(64)
314+
mockTask.clineMessages.push({ ts: 5, say: "checkpoint_saved", text: sha256Hash })
315+
316+
await checkpointRestore(mockTask, { ts: 2, commitHash: sha256Hash, mode: "preview" })
317+
318+
expect(mockCheckpointService.restoreCheckpoint).toHaveBeenCalledWith(sha256Hash)
319+
})
320+
312321
it.each([
313322
["a malformed hash", "HEAD~1"],
314323
["an abbreviated hash", "a".repeat(7)],
324+
["a hash between SHA-1 and SHA-256 length", "a".repeat(41)],
315325
["a well-formed but unrecorded hash", "b".repeat(40)],
316326
["a non-string", 42],
317327
])("rejects %s before any Git call", async (_label, commitHash) => {

‎src/core/checkpoints/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ export async function checkpointSave(task: Task, force = false, suppressMessage
227227
})
228228
}
229229

230-
// The shadow repo is created with `git init` defaults (SHA-1) and stores full hashes.
231-
const FULL_COMMIT_HASH = /^[0-9a-f]{40}$/
230+
// `git init` honours the user's init.defaultObjectFormat, so full hashes are SHA-1 or SHA-256.
231+
const FULL_COMMIT_HASH = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
232232

233233
// The hash arrives from the webview, so it must name a checkpoint this task recorded before reaching Git.
234234
function assertRecordedCheckpoint(task: Task, commitHash: unknown): asserts commitHash is string {

0 commit comments

Comments
 (0)