From 8ea3bef13e3c0353e8725de0bc4ae4c527a44722 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN Date: Sat, 3 Oct 2026 17:20:48 -0400 Subject: [PATCH] fix(integration): make private ref cas atomic TASK-f40126ee-2485-45c8-a67b-4279e4e8704a --- src/integration/adoption.mjs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/integration/adoption.mjs b/src/integration/adoption.mjs index 2aeb1d5..cac0c5e 100644 --- a/src/integration/adoption.mjs +++ b/src/integration/adoption.mjs @@ -112,11 +112,17 @@ export class GitPrivateRefAdapter { compareAndSwapRefs({ expected = [], writes = [] } = {}) { const commands = ['start']; + const writtenRefs = new Set(writes.map((entry) => entry.ref)); for (const { ref, sha: expectedSha } of expected) { + if (writtenRefs.has(ref)) continue; commands.push(`verify ${text(ref, 'ref')} ${expectedSha ?? ZERO_SHA}`); } for (const { ref, sha: nextSha } of writes) { - const current = expected.find((entry) => entry.ref === ref)?.sha ?? null; + const expectedEntry = expected.find((entry) => entry.ref === ref); + if (!expectedEntry) throw new TorchError('Every private-ref write requires an exact expected value', { + code: 'ADOPTION_REF_CAS_EXPECTED_REQUIRED', details: { ref }, + }); + const current = expectedEntry.sha ?? null; if (nextSha === null) commands.push(`delete ${text(ref, 'ref')} ${current ?? ZERO_SHA}`); else commands.push(`update ${text(ref, 'ref')} ${sha(nextSha, 'next ref sha')} ${current ?? ZERO_SHA}`); }