wishforge-ide/tests/backup-restore.test.ts
eust-w 0ef99b1e6d style: add Prettier and EditorConfig, format the codebase
Adds prettier 3.9.8 (exact) with a shared config (single quotes,
120 columns, trailing commas), .prettierignore, .editorconfig and the
`format` / `format:check` scripts, then formats all TypeScript,
JavaScript, CSS, JSON and YAML sources.

Purely mechanical: no behaviour change. Typecheck passes, the vitest
suite and the 74 IDE node tests produce the same results as before
(socket-binding tests still cannot run inside this sandbox).
Previously the longest source line was ~3000 characters; reviewing the
following semantic changes now produces readable diffs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:32:43 +08:00

38 lines
2.1 KiB
TypeScript

import { describe, expect, it } from 'vitest';
// JavaScript entrypoint is import-safe: no environment, Docker or database access occurs on import.
import { assertTestDatabase, parseArgs } from '../scripts/backup-restore.mjs';
describe('local backup and isolated restore safeguards', () => {
it('requires an explicit single mode and cannot accept an existing target database', () => {
expect(() => parseArgs([])).toThrow('explicitly');
expect(() => parseArgs(['--drill', '--backup-only'])).toThrow('exactly one');
expect(() => parseArgs(['--restore-verify', '--manifest', 'x', '--database', 'wishforge'])).toThrow(
'Unsupported flag',
);
expect(() => parseArgs(['--drill', '--clean'])).toThrow('Unsupported flag');
});
it('requires a manifest only for restore verification', () => {
expect(() => parseArgs(['--restore-verify'])).toThrow('requires');
expect(() => parseArgs(['--backup-only', '--manifest', 'x'])).toThrow('requires');
expect(parseArgs(['--restore-verify', '--manifest', '.wishforge/backups/a.manifest.json'])).toMatchObject({
mode: 'restore-verify',
context: 'colima',
container: 'wishforge-dev-postgres-1',
});
});
it('rejects database cleanup without an exact generated name and this drill ownership marker', () => {
const id = 'fe15d197-89ee-4928-8641-013520caec87',
name = `wf_restore_${id.replaceAll('-', '')}`,
marker = `wishforge-restore-drill:${id}`;
expect(() => assertTestDatabase(name, marker, marker)).not.toThrow();
expect(() => assertTestDatabase('wishforge', marker, marker)).toThrow('Refusing');
expect(() => assertTestDatabase(name, 'another-owner', marker)).toThrow('Refusing');
expect(() => assertTestDatabase(`wf_restore_${'a'.repeat(32)}`, marker, marker)).toThrow('Refusing');
});
it('rejects command-like context/container names before opening any resources', () => {
expect(() => parseArgs(['--drill', '--container', 'x;echo data'])).toThrow('Invalid');
expect(() => parseArgs(['--drill', '--context', '../../docker'])).toThrow('Invalid');
expect(parseArgs(['--help']).help).toBe(true);
});
});