Skip to content

The agent that grows with you

test: retry historical Desktop source check only on concurrent Git ref lock

ethernetd79e50e4f244
diff --git a/tests-js/update-ui.test.mjs b/tests-js/update-ui.test.mjs
index 2334c1bdd82..a55434c3855 100644
--- a/tests-js/update-ui.test.mjs
+++ b/tests-js/update-ui.test.mjs
@@ -76,6 +76,13 @@ test('checks the live Desktop bridge against the staged target before opening Ab
expect(f.log).toHaveBeenCalledWith(expect.stringContaining('"targetSha"'))
const current = fixture({ statusOverride: { supported: true, branch: 'main', currentSha: 'b'.repeat(40), targetSha: sha, behind: 1, updateAvailable: true } })
await updateUi.assertStagedBranch(current.page, sha, current.log)
+ const racing = fixture()
+ let checks = 0
+ racing.page.evaluate = fn => ++checks === 1
+ ? { supported: true, error: 'fetch-failed', message: "error: cannot lock ref 'refs/remotes/origin/main'" }
+ : current.page.evaluate(fn)
+ await updateUi.assertStagedBranch(racing.page, sha, racing.log)
+ expect(checks).toBe(2)
for (const statusOverride of [
{ supported: true, error: 'release-unavailable', branch: 'main' },
{ supported: true, branch: 'main', targetSha: 'b'.repeat(40), behind: 1, updateAvailable: true },
diff --git a/tests/install/e2e-assets/update-ui.cjs b/tests/install/e2e-assets/update-ui.cjs
index 17d56616641..62e2e5e8bbd 100644
--- a/tests/install/e2e-assets/update-ui.cjs
+++ b/tests/install/e2e-assets/update-ui.cjs
@@ -79,8 +79,16 @@ async function openAbout(page, { prepare, log, shot, confirmSettings = false, hi
}
async function assertStagedBranch(page, expectedSha, log) {
- const status = await page.evaluate(() => window.hermesDesktop.updates.check({ force: true }))
- log(`[source-branch-check] ${JSON.stringify(status)}`)
+ let status
+ for (let attempt = 0; attempt < 3; attempt++) {
+ status = await page.evaluate(() => window.hermesDesktop.updates.check({ force: true }))
+ log(`[source-branch-check] ${JSON.stringify(status)}`)
+ // The app's mount-time poller can fetch the same origin/main concurrently;
+ // Git rejects the losing ref update even though the winning fetch succeeded.
+ // Retry only that transient lock race, never a missing channel or other error.
+ if (status.error !== 'fetch-failed' || !/cannot lock ref 'refs\/remotes\/origin\/main'/.test(status.message || '')) break
+ await page.waitForTimeout(1_000)
+ }
// Historical Desktop status has no updateAvailable field: its About/overlay
// offers the button when behind > 0. Never accept an explicit false from a
// newer checker, a dirty source tree, or merely a matching remote tip.