/** * Global-install planner tests — covers the pure decision function * that turns "what's installed globally" + "what we're publishing" + * --track-alpha into a list of GlobalUpdateItems for the executor. * * The disk-reading wrapper (`planGlobalUpdate`) is a thin shim on top * of `decideGlobalUpdates`; testing the pure layer exercises all the * policy. */ import { describe, expect, test } from 'bun:test'; import { decideGlobalUpdates } from './global-install'; /** Helper for tests: pretend everything in the map is installed at the listed version. */ function installedVersionFrom(versions: Record): (name: string) => string | null { return (name) => versions[name] ?? null; } describe('decideGlobalUpdates', () => { test('empty installed → empty plan', () => { expect( decideGlobalUpdates({ installed: [], justPublished: [], trackAlpha: false, installedVersion: () => null, }), ).toEqual([]); }); test('normal mode: force-pins just-published, update-pulls the rest', () => { const result = decideGlobalUpdates({ installed: ['@celilo/cli', '@celilo/e2e', '@celilo/event-bus'], justPublished: [ { name: '@celilo/cli', version: '0.4.0' }, { name: '@celilo/e2e', version: '0.8.0' }, ], trackAlpha: false, installedVersion: installedVersionFrom({ '@celilo/cli': '0.3.0', '@celilo/e2e': '0.7.0', '@celilo/event-bus': '0.1.0', }), }); expect(result).toEqual([ { name: '@celilo/cli', installed: '0.3.0', target: '0.4.0', forcePin: true, }, { name: '@celilo/e2e', installed: '0.7.0', target: '0.8.0', forcePin: true, }, { name: '@celilo/event-bus', installed: '0.1.0', target: '0.1.0', forcePin: false, }, ]); }); test('--track-alpha filters to just-published only', () => { const result = decideGlobalUpdates({ installed: ['@celilo/cli', '@celilo/e2e', '@celilo/event-bus'], justPublished: [{ name: '@celilo/e2e', version: '0.8.0-alpha.0' }], trackAlpha: true, installedVersion: installedVersionFrom({ '@celilo/cli': '0.3.0', '@celilo/e2e': '0.7.0', '@celilo/event-bus': '0.1.0', }), }); // Other globals (@celilo/cli, @celilo/event-bus) are left alone — // they may already be on their own alpha streams. expect(result).toHaveLength(1); expect(result[0]).toEqual({ name: '@celilo/e2e', installed: '0.7.0', target: '0.8.0-alpha.0', forcePin: true, }); }); test('--track-alpha + nothing-just-published → empty plan', () => { expect( decideGlobalUpdates({ installed: ['@celilo/cli', '@celilo/e2e'], justPublished: [], trackAlpha: true, installedVersion: installedVersionFrom({ '@celilo/cli': '0.3.0', '@celilo/e2e': '0.7.0', }), }), ).toEqual([]); }); test('handles missing installed version gracefully (target falls back to "?")', () => { const result = decideGlobalUpdates({ installed: ['@celilo/cli'], justPublished: [], trackAlpha: false, installedVersion: () => null, // bun symlink missing, malformed pkg, etc. }); expect(result).toEqual([ { name: '@celilo/cli', installed: null, target: '?', forcePin: false, }, ]); }); test('preserves installed order', () => { const result = decideGlobalUpdates({ installed: ['@celilo/event-bus', '@celilo/cli', '@celilo/e2e'], justPublished: [], trackAlpha: false, installedVersion: installedVersionFrom({ '@celilo/event-bus': '0.1.0', '@celilo/cli': '0.3.0', '@celilo/e2e': '0.7.0', }), }); expect(result.map((i) => i.name)).toEqual(['@celilo/event-bus', '@celilo/cli', '@celilo/e2e']); }); test('just-published packages NOT in installed are not added (only refreshes existing globals)', () => { // Operator hasn't installed @celilo/cli globally, but the publish // run shipped it. We don't auto-install — we only refresh what's // already there. So @celilo/cli should NOT appear in the plan. const result = decideGlobalUpdates({ installed: ['@celilo/e2e'], justPublished: [ { name: '@celilo/cli', version: '0.4.0' }, { name: '@celilo/e2e', version: '0.8.0' }, ], trackAlpha: false, installedVersion: installedVersionFrom({ '@celilo/e2e': '0.7.0' }), }); expect(result.map((i) => i.name)).toEqual(['@celilo/e2e']); }); });