The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
import { describe, expect, it } from 'vitest'
import { en } from '@/i18n/en'
import { resolveVersionStatus } from './version-status'
const copy = en.shell.statusbar
const client = (over: Partial<Parameters<typeof resolveVersionStatus>[0]> = {}) =>
resolveVersionStatus({ applying: false, copy, remote: false, restarting: false, target: 'client', ...over })
const backend = (over: Partial<Parameters<typeof resolveVersionStatus>[0]> = {}) =>
resolveVersionStatus({ applying: false, copy, remote: true, restarting: false, target: 'backend', ...over })
describe('resolveVersionStatus', () => {
it('labels a current local client with its distance, keeping the commit for the tooltip', () => {
const status = client({ sha: 'abc1234', version: '0.4.2+1913.gabc1234' })
expect(status.label).toBe('v0.4.2+1913')
expect(status.tooltip).toContain('abc1234')
expect(status.hasUpdate).toBe(false)
expect(status.unknown).toBe(false)
})
it('appends the commit diff when the client is behind', () => {
const status = client({ behind: 12, branch: 'main', version: '0.4.2' })
expect(status.label).toBe('v0.4.2 (+12)')
expect(status.hasUpdate).toBe(true)
expect(status.tooltip).toContain('12 commits behind main')
})
// FAIL-BEFORE (#84591 class): a shallow install reports behind:null +
// updateAvailable. The client target ignored updateAvailable entirely, so
// the statusbar showed no update at all — and further back, the fabricated
// behind:1 rendered a frozen "(+1)" while the real distance grew to 61.
it('shows a count-free update hint when the client count is unknown', () => {
const status = client({ behind: 0, updateAvailable: true, version: '0.4.2' })
expect(status.label).toBe(`v0.4.2 (${copy.update})`)
expect(status.label).not.toContain('+1')
expect(status.hasUpdate).toBe(true)
})
it('falls back to the sha, then to unknown, when there is no version', () => {
expect(client({ sha: 'abc1234' }).label).toBe('abc1234')
expect(client({ sha: 'abc1234' }).unknown).toBe(false)
expect(client().label).toBe(copy.unknown)
expect(client().unknown).toBe(true)
})
it('treats the unknown sentinel as missing, without borrowing the client sha for a backend', () => {
expect(client({ version: 'unknown', sha: 'abc1234' }).label).toBe('abc1234')
expect(client({ version: 'unknown', sha: 'abc1234' }).unknown).toBe(false)
expect(client({ version: 'unknown' }).unknown).toBe(true)
expect(backend({ version: 'unknown', sha: 'abc1234' }).unknown).toBe(true)
expect(client({ version: 'git.abc1234' }).label).toBe('vgit.abc1234')
})
it('drops the diff while an apply is in flight', () => {
const applying = client({ applying: true, behind: 3, sha: 'abc1234', version: '0.4.2' })
expect(applying.label).toBe('v0.4.2 · update')
expect(applying.hasUpdate).toBe(false)
expect(client({ applying: true, restarting: true, version: '0.4.2' }).label).toBe('v0.4.2 · restart')
})
it('labels the backend target distinctly and never claims a client sha', () => {
const status = backend({ sha: 'abc1234', version: '0.4.2' })
expect(status.label).toBe('backend v0.4.2')
expect(status.tooltip).toBe('Backend v0.4.2')
})
it('falls back to (update) for a backend that cannot count commits', () => {
const status = backend({ updateAvailable: true, version: '0.4.2' })
expect(status.label).toBe('backend v0.4.2 (update)')
expect(status.hasUpdate).toBe(true)
})
it('prefers the exact commit diff over the generic (update) hint', () => {
expect(backend({ behind: 4, updateAvailable: true, version: '0.4.2' }).label).toBe('backend v0.4.2 (+4)')
})
it('hides a backend row that has no version at all', () => {
expect(backend().unknown).toBe(true)
})
it('stable channel: releases use the update word, never a commit count', () => {
const label = client({ behind: 4, updateAvailable: true, channel: 'stable', version: '0.4.2' }).label
expect(label).toBe('v0.4.2 (update)')
})
it('stable channel tooltip names the release tag', () => {
const tooltip = client({ behind: 1, channel: 'stable', latestTag: 'v0.18.0', version: '0.4.2' }).tooltip
expect(tooltip).toContain(`${copy.releaseAvailable('v0.18.0')}`)
})
it('stable channel never names a branch (a stable checkout sits on a tag)', () => {
const tooltip = client({
behind: 1,
branch: 'main',
channel: 'stable',
latestTag: 'v0.18.0',
version: '0.4.2'
}).tooltip
expect(tooltip).not.toContain('main')
expect(tooltip).toContain(`${copy.releaseAvailable('v0.18.0')}`)
})
})