diff --git a/server/src/nest/storage/drivers/mirror.driver.ts b/server/src/nest/storage/drivers/mirror.driver.ts index b89cf91d1..bcdb26996 100644 --- a/server/src/nest/storage/drivers/mirror.driver.ts +++ b/server/src/nest/storage/drivers/mirror.driver.ts @@ -26,8 +26,10 @@ export interface ReplicaFailure { /** * Composite backend: one primary (source of truth) plus best-effort replicas. * Runs entirely over the driver interface — the second in-tree consumer of - * the contract suite. Only the `backups` category may be assigned a mirror - * (registry validation enforces it). + * the contract suite. Any category may be assigned a mirror (the v1 + * backups-only rule was lifted by the replicas-on-primary spec); replica + * writes are synchronous in the request path, which is why hot categories + * carry an advisory in the admin UI rather than a prohibition here. * * Writes hit the primary first and must succeed; replica failures are * reported through `onReplicaFailure` (surfaced as health status), never diff --git a/server/src/nest/storage/storage-registry.service.ts b/server/src/nest/storage/storage-registry.service.ts index 44f4e4e4a..cbae84a22 100644 --- a/server/src/nest/storage/storage-registry.service.ts +++ b/server/src/nest/storage/storage-registry.service.ts @@ -459,8 +459,5 @@ function validateConfig(backends: Map, categories: Map { expect(registry.resolve('files').backendName).toBe('uploads-local'); }); + it('a mirror may serve any category — the backups-only rule is lifted (replicas-on-primary spec)', () => { + const extraRoot = makeTmpDir(); + const { registry, uploadsRoot } = makeRegistry({ + backends: [ + { name: 'extra-local', type: 'local', options: { root: extraRoot } }, + { name: 'm', type: 'mirror', options: { primary: 'uploads-local', replicas: ['extra-local'] } }, + ], + categories: { covers: 'm' }, + }); + const covers = registry.resolve('covers'); + expect(covers.backendName).toBe('m'); + expect(covers.driver).toBeInstanceOf(MirrorDriver); + expect(covers.keyPrefix).toBe('covers/'); + // Hot-path reads stay free: getLocalPath delegates to the local primary. + expect(covers.driver.getLocalPath!('covers/x.jpg')).toBe( + path.join(fs.realpathSync(uploadsRoot), 'covers/x.jpg'), + ); + }); + it.each([ ['unknown backend name in categories', undefined, JSON.stringify({ files: 'nope' })], - [ - 'mirror assigned to a non-backups category', - JSON.stringify([ - { name: 'extra-local', type: 'local', options: { root: '/tmp/x' } }, - { name: 'm', type: 'mirror', options: { primary: 'uploads-local', replicas: ['extra-local'] } }, - ]), - JSON.stringify({ files: 'm' }), - ], [ 'nested mirror', JSON.stringify([