Skip to content

The agent that grows with you

3.5 KB
Raw Blame
import { describe, expect, it } from 'vitest'

import { resolveUpdateCopy } from './update-copy'

const copy = {
  availableTitle: 'New update available',
  availableBody: 'A new version of Hermes is ready to install.',
  availableTitleBackend: 'Backend update available',
  availableBodyBackend: 'A newer version of the connected Hermes backend is ready to install.',
  availableBodyNoChangelog: 'A newer version is ready. Release notes aren’t available for this install type.',
  availableBodyRelease: (tag: string) => `Hermes ${tag} is ready to install.`,
  availableBodyAppInstaller:
    'A new version of Hermes is ready. Hermes will close, Windows will finish the update, and Hermes will reopen on its own.'
}

describe('resolveUpdateCopy', () => {
  it('client target with commits: client title + client body', () => {
    const r = resolveUpdateCopy({ target: 'client', shownItems: 5, copy })
    expect(r.title).toBe('New update available')
    expect(r.body).toBe('A new version of Hermes is ready to install.')
  })

  it('backend target with commits: names the backend in title and body', () => {
    const r = resolveUpdateCopy({ target: 'backend', shownItems: 5, copy })
    expect(r.title).toBe('Backend update available')
    expect(r.body).toContain('backend')
  })

  it('no changelog (pip/non-git backend): degrades honestly, still names backend target in title', () => {
    const r = resolveUpdateCopy({ target: 'backend', shownItems: 0, copy })
    expect(r.title).toBe('Backend update available')
    // Body must NOT pretend there are notes — it states they're unavailable.
    expect(r.body).toBe(copy.availableBodyNoChangelog)
  })

  it('no changelog on client: same honest degrade', () => {
    const r = resolveUpdateCopy({ target: 'client', shownItems: 0, copy })
    expect(r.title).toBe('New update available')
    expect(r.body).toBe(copy.availableBodyNoChangelog)
  })

  it('stable channel with a known tag names the release, not the commit count', () => {
    const r = resolveUpdateCopy({
      target: 'client',
      shownItems: 0,
      channel: 'stable',
      latestTag: 'v0.18.0',
      copy
    })

    expect(r.body).toBe('Hermes v0.18.0 is ready to install.')
  })

  it('stable channel without a tag falls back to the generic release body', () => {
    const r = resolveUpdateCopy({ target: 'client', shownItems: 0, channel: 'stable', copy })
    expect(r.body).toBe(copy.availableBody)
  })

  it.each(['app-installer', 'microsoft-store'] as const)(
    '%s uses Windows update copy without commit vocabulary',
    mechanism => {
      const r = resolveUpdateCopy({ target: 'client', shownItems: 5, mechanism, copy })
      expect(r.body).toBe(copy.availableBodyAppInstaller)
    }
  )

  it('app-installer mechanism with a known tag names the release', () => {
    const r = resolveUpdateCopy({
      target: 'client',
      shownItems: 0,
      mechanism: 'app-installer',
      latestTag: 'v0.18.3',
      copy
    })

    expect(r.body).toBe('Hermes v0.18.3 is ready to install.')
  })

  it('other mechanisms keep the commit vocabulary', () => {
    const r = resolveUpdateCopy({ target: 'client', shownItems: 5, mechanism: 'windows-handoff', copy })
    expect(r.body).toBe(copy.availableBody)
  })

  it('macOS feed updates name the release without Windows or commit vocabulary', () => {
    expect(
      resolveUpdateCopy({
        target: 'client',
        shownItems: 0,
        mechanism: 'electron-updater',
        latestTag: 'v0.29.0+canary.20260906T000000Z',
        copy
      }).body
    ).toBe(copy.availableBodyRelease('v0.29.0+canary.20260906T000000Z'))
  })
})