Replace route-local restore writes with the core transaction and map preflight, rollback, and post-commit cleanup failures to precise HTTP responses. Treat only ENOENT as a missing export file and return transaction, restored, skipped, migrated, and restart facts. Update the settings panel to describe the full sensitive configuration group, avoid restart guidance for empty plans, and reload settings after both successful and failed imports so the UI reflects committed disk state. Add HTTP regression coverage for export and restore error semantics.
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import {
|
|
listPerUinOneBotConfigFiles,
|
|
readBackupConfigFile,
|
|
} from '../src/webui/server';
|
|
|
|
describe('backup filesystem adapter', () => {
|
|
let root: string;
|
|
|
|
beforeEach(() => {
|
|
root = fs.mkdtempSync(path.join(os.tmpdir(), 'snowluma-backup-http-'));
|
|
});
|
|
|
|
afterEach(() => {
|
|
fs.rmSync(root, { recursive: true, force: true });
|
|
});
|
|
|
|
it('treats only a missing file as absent', () => {
|
|
expect(readBackupConfigFile(root, 'missing.json')).toBeNull();
|
|
|
|
fs.mkdirSync(path.join(root, 'runtime.json'));
|
|
expect(() => readBackupConfigFile(root, 'runtime.json')).toThrow();
|
|
});
|
|
|
|
it('treats only a missing config directory as an empty OneBot list', () => {
|
|
expect(listPerUinOneBotConfigFiles(path.join(root, 'missing'))).toEqual([]);
|
|
|
|
const notDirectory = path.join(root, 'not-a-directory');
|
|
fs.writeFileSync(notDirectory, 'x');
|
|
expect(() => listPerUinOneBotConfigFiles(notDirectory)).toThrow();
|
|
});
|
|
});
|