import { describe, expect, test } from 'bun:test'; import { compare, devVersion, guardProblem, nextPatch, pruneDev, utcStamp } from '../tools/desktop-dev'; describe('desktop dev channel', () => { test('stamps the next patch with the UTC commit time', () => { expect(nextPatch('0.8.47')).toBe('0.8.48'); expect(nextPatch('0.8.48-rc.1')).toBe('0.8.48'); expect(utcStamp(new Date('2026-10-23T09:05:07+03:00'))).toBe('20261023060507'); expect(devVersion('0.8.47', new Date('2026-10-23T06:05:07Z'))).toBe('0.8.48-dev.20261023060507'); }); test('dev builds sort above the current stable, below the next stable, monotonic in time', () => { const a = devVersion('0.8.47', new Date('2026-10-23T06:05:07Z')); const b = devVersion('0.8.47', new Date('2026-10-23T06:05:08Z')); expect(compare(a, '0.8.47')).toBe(1); expect(compare('0.8.48', a)).toBe(1); expect(compare(b, a)).toBe(1); expect(compare(a, a)).toBe(0); // after 0.8.48 ships, its successor's dev builds pass it expect(compare(devVersion('0.8.48', new Date('2026-10-24T00:00:00Z')), '0.8.48')).toBe(1); expect(compare('0.8.48-dev.10', '0.8.48-dev.9')).toBe(1); expect(compare('0.10.0', '0.9.9')).toBe(1); }); test('the publish guard refuses a version not above the live dev build', () => { expect(guardProblem('0.8.48-dev.20261023060507', null)).toBeNull(); expect(guardProblem('0.8.48-dev.20261023060508', '0.8.48-dev.20261023060507')).toBeNull(); expect(guardProblem('0.8.48-dev.20261023060507', '0.8.48-dev.20261023060507')).toContain('refused'); expect(guardProblem('0.8.48-dev.20261023060506', '0.8.48-dev.20261023060507')).toContain('refused'); expect(guardProblem('0.8.48', null)).toContain('not a dev version'); }); test('prunes dev drafts to the newest 5, never other releases', () => { const rel = (t: string) => ({ tag_name: t }); const dev = [1, 2, 3, 4, 5, 6, 7].map(i => rel(`dev-0.8.48-dev.2026102300000${i}`)); const out = pruneDev([rel('v0.8.47'), rel('rc-' + 'a'.repeat(40)), ...dev.reverse()]); expect(out.map(r => r.tag_name)).toEqual(['dev-0.8.48-dev.20261023000002', 'dev-0.8.48-dev.20261023000001']); }); });