// After a machine move the app folder list points at the old computer; relink finds each app here and keeps its id. import { describe, expect, test } from 'bun:test'; import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { configAppName, configFolders, relinkPlan } from '../cli/lib/registry'; function app(root: string, rel: string, name: string): string { const d = join(root, rel); mkdirSync(d, { recursive: true }); writeFileSync(join(d, 'storebound.config.ts'), `export default { app: { name: '${name}' } };\n`); return d; } describe('apps relink', () => { test('by the last path parts, else by the app name; ids stay; a taken folder is not reused', () => { const root = mkdtempSync(join(tmpdir(), 'sb-relink-')); const game = app(root, 'game-one', 'Game One'); const front = app(root, 'Studio/frontend', 'Studio'); const renamed = app(root, 'NewName/app', 'Old App'); mkdirSync(join(root, 'node_modules/x'), { recursive: true }); writeFileSync(join(root, 'node_modules/x/storebound.config.ts'), ''); const found = configFolders([root]); expect(found.sort()).toEqual([game, front, renamed].sort()); expect(configAppName(front)).toBe('Studio'); const r = { version: 1 as const, projects: [ { id: 'a', path: '/Users/name/Desktop/game-one', name: 'Game One', added: '' }, { id: 'b', path: '/Users/name/Work/Studio/frontend', name: 'frontend', added: '' }, { id: 'c', path: '/Users/name/Work/OldName/app', name: 'Old App', added: '' }, { id: 'd', path: '/Users/name/gone', name: 'Gone', added: '' }, ] }; const plan = relinkPlan(r, found, () => false, configAppName); expect(plan.map(p => [p.id, p.to])).toEqual([['a', game], ['b', front], ['c', renamed]]); }); });