import { expect, test } from 'bun:test'; import { parseRestoreMarkerPhase, RESTORE_MARKER_CONFIRMATION, SYNTHETIC_CHARACTER_ID_MIN, validateRestoreMarkerTarget, validateRestoreMarkerWrite, } from '../src/lib/server/restore-marker'; test('restore marker defaults to a non-writing verification phase', () => { expect(parseRestoreMarkerPhase(undefined)).toBe('verify'); expect(parseRestoreMarkerPhase('')).toBe('verify'); }); test('restore marker rejects non-loopback targets before any backend call', () => { expect(() => validateRestoreMarkerTarget(undefined)).toThrow('required'); expect(() => validateRestoreMarkerTarget('https://production.example.test')).toThrow('loopback'); expect(() => validateRestoreMarkerTarget('http://192.0.2.10:3210')).toThrow('loopback'); expect(validateRestoreMarkerTarget('http://127.0.0.1:3210').hostname).toBe('127.0.0.1'); expect(SYNTHETIC_CHARACTER_ID_MIN).toBeGreaterThan(2_000_000_000); }); test('restore marker requires explicit disposable confirmation for writes', () => { expect(() => validateRestoreMarkerWrite({ phase: 'write', allowWrite: undefined, confirmation: undefined })).toThrow('SMOKE_ALLOW_WRITE'); expect(() => validateRestoreMarkerWrite({ phase: 'write', allowWrite: '1', confirmation: 'wrong' })).toThrow('RESTORE_MARKER_CONFIRMATION'); expect(() => validateRestoreMarkerWrite({ phase: 'write', allowWrite: '1', confirmation: RESTORE_MARKER_CONFIRMATION })).not.toThrow(); expect(() => validateRestoreMarkerWrite({ phase: 'verify', allowWrite: undefined, confirmation: undefined })).not.toThrow(); });