Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test(backup): cover scheduled retention forwarding (#11991)

Adam Eivyf5d934911305
diff --git a/server/lib/backupConfig.test.js b/server/lib/backupConfig.test.js
new file mode 100644
index 0000000000..44e3219e95
--- /dev/null
+++ b/server/lib/backupConfig.test.js
@@ -0,0 +1,20 @@
+import { describe, expect, it } from 'vitest';
+import { MAX_RETENTION_COUNT, MIN_RETENTION_COUNT, resolveRetentionCount } from './backupConfig.js';
+
+describe('resolveRetentionCount', () => {
+ it.each([
+ ['zero', 0],
+ ['negative', -1],
+ ['above the maximum', MAX_RETENTION_COUNT + 1],
+ ['fractional', 2.5],
+ ['numeric string', '30'],
+ ['null', null],
+ ['missing', undefined]
+ ])('returns unlimited for %s retention', (_label, retentionCount) => {
+ expect(resolveRetentionCount({ retentionCount })).toBeNull();
+ });
+
+ it.each([MIN_RETENTION_COUNT, 30, MAX_RETENTION_COUNT])('accepts the valid count %s', retentionCount => {
+ expect(resolveRetentionCount({ retentionCount })).toBe(retentionCount);
+ });
+});
diff --git a/server/services/backupScheduler.test.js b/server/services/backupScheduler.test.js
index 3622a643d5..6f632760f9 100644
--- a/server/services/backupScheduler.test.js
+++ b/server/services/backupScheduler.test.js
@@ -112,7 +112,8 @@ describe('startBackupScheduler', () => {
enabled: true,
destPath: '/dest-fresh',
excludePaths: ['fresh/'],
- disabledDefaultExcludes: ['/loras/*.safetensors']
+ disabledDefaultExcludes: ['/loras/*.safetensors'],
+ retentionCount: 14
}
});
@@ -123,10 +124,28 @@ describe('startBackupScheduler', () => {
expect(runBackup).toHaveBeenCalledWith(
'/dest-fresh',
null,
- { excludePaths: ['fresh/'], disabledDefaultExcludes: ['/loras/*.safetensors'], retentionCount: null }
+ { excludePaths: ['fresh/'], disabledDefaultExcludes: ['/loras/*.safetensors'], retentionCount: 14 }
);
});
+ it('does not pass an invalid retention count to the backup run', async () => {
+ getSettings.mockResolvedValueOnce({
+ backup: { enabled: true, destPath: '/dest', retentionCount: 0 }
+ });
+ await startBackupScheduler();
+
+ getSettings.mockResolvedValueOnce({
+ backup: { enabled: true, destPath: '/dest', retentionCount: 0 }
+ });
+
+ const handler = schedule.mock.calls[0][0].handler;
+ await handler();
+
+ expect(runBackup).toHaveBeenCalledWith('/dest', null, {
+ excludePaths: [], disabledDefaultExcludes: [], retentionCount: null
+ });
+ });
+
it('rejects unreadable run-time settings and recovers on the next scheduled invocation', async () => {
const settings = { backup: { enabled: true, destPath: '/example-backups' } };
getSettings.mockResolvedValue(settings);