Skip to content

Commit cdf4e65

Browse files
committed
fix(cli): record the channel even when an update check fails
A failed check after a channel switch kept the old channel's dist-tag, so every command started another check. It now records the current channel and drops a version cached from the other one.
1 parent d6ca2ba commit cdf4e65

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎src/__tests__/update-check.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,22 @@ test('a cached version from the other channel is neither shown nor kept past a c
239239
assert.equal(stderr, '');
240240
assert.equal(vi.mocked(runCmdDetached).mock.calls.length, 1, 'the switch starts a fresh check');
241241
});
242+
243+
test('a failed check after a channel switch records the new channel and drops the old version', async () => {
244+
const stateDir = makeTempStateDir();
245+
cleanupPaths.push(stateDir);
246+
const cachePath = path.join(stateDir, 'update-check.json');
247+
writeCache(stateDir, {
248+
latestVersion: '0.12.0-nightly.20261011.8',
249+
distTag: 'nightly',
250+
checkedAt: '2026-03-30T10:00:00.000Z',
251+
});
252+
vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new Error('offline')));
253+
254+
await runUpdateCheckWorker({ cachePath, currentVersion: '0.11.3' });
255+
256+
const cache = readCache(stateDir);
257+
assert.equal(cache.distTag, 'latest');
258+
assert.equal(cache.latestVersion, undefined);
259+
assert.equal(cache.checkedAt, '2026-03-31T10:00:00.000Z');
260+
});

‎src/cli/update-check.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,13 @@ export async function runUpdateCheckWorker(options: UpdateCheckWorkerOptions): P
7676
prompted: cache.latestVersion === latestVersion ? cache.prompted === true : false,
7777
});
7878
} catch {
79+
// A failed check still records this channel, so a channel switch waits out the interval
80+
// instead of retrying on every command, and never keeps the other channel's version.
81+
const kept = cachedDistTag(cache) === distTag ? cache : {};
7982
writeUpdateCheckCache(options.cachePath, {
80-
...cache,
83+
...kept,
8184
checkedAt: new Date(now).toISOString(),
85+
distTag,
8286
});
8387
}
8488
}

0 commit comments

Comments
 (0)