import assert from 'node:assert/strict' import test from 'node:test' import { loadTestModule } from './load-test-module.mjs' const { describeRuntimeStatus, sameRuntimeId } = await loadTestModule(`export * from './lib/runtimeStatus'`) const rt = (commit, active = false) => ({ commit, active, path: `/runtimes/${commit}`, manifest: { qemu_version: 'QEMU 11.1.90' }, }) const remote = (commit) => ({ commit, channel: 'stable', archive_size: 100, }) test('sameRuntimeId matches full and short commits with matching revision suffix', () => { assert.equal(sameRuntimeId('6a1f03f', '6a1f03f862b4'), true) assert.equal(sameRuntimeId('3731afd-p3', '3731afd-p4'), false) assert.equal(sameRuntimeId('3731afd-p3', '3731afd9-p3'), true) }) test('active runtime matching remote latest is up to date', () => { const s = describeRuntimeStatus([rt('6a1f03f', true), rt('2df30ff', false)], remote('6a1f03f')) assert.equal(s.activeIsLatest, true) assert.equal(s.latestInstalled, true) assert.equal(s.updatable, false) assert.equal(s.switchRecommended, false) }) test('switching to an older runtime while latest is installed flags not-latest instead of up-to-date', () => { const s = describeRuntimeStatus([rt('2df30ff', true), rt('6a1f03f', false)], remote('6a1f03f')) assert.equal(s.activeIsLatest, false) assert.equal(s.latestInstalled, true) assert.equal(s.updatable, false) assert.equal(s.switchRecommended, true) }) test('missing remote latest marks runtime as updatable', () => { const s = describeRuntimeStatus([rt('2df30ff', true)], remote('6a1f03f')) assert.equal(s.activeIsLatest, false) assert.equal(s.latestInstalled, false) assert.equal(s.updatable, true) assert.equal(s.switchRecommended, false) })