fix(storage): reset reclaim state after any restore, re-check owners often, share release ticks

- A restore (admin panel or RESTORE_FROM_BACKUP) now leaves
  data/.trek-reclaim-reset before it swaps the database in. Boot reconcile
  resets the reclaim state when it finds the file, whatever install id the
  database names, and removes it afterwards; a successful reopen removes it
  too. A restart after a failed reopen, or a boot restore of this
  installation's own backup, no longer keeps the old switch, marks and
  confirmations. The id mismatch reset stays.
- The release job skips a tick (install_mismatch) while the database names
  another installation or a reset is still pending.
- An allowed owner verdict is cached for 15 minutes, a refusal for 26 hours.
  The local driver reads a list prefix as a folder, so the category root is
  still listed whole, at most once per category per window.
- Each tick reads every allowed category's due rows separately, an equal
  share of the 200 each, so a category whose deletes keep failing cannot
  starve the others.
- Rows dropped after 30 days overdue and releases refused by a full queue
  are logged at warn with their counts.
This commit is contained in:
Maurice
2026-11-01 18:31:41 +01:00
parent 9d2ffc91af
commit bef8fc20f1
17 changed files with 432 additions and 80 deletions
@@ -42,6 +42,7 @@ describe('resolveDataPaths', () => {
jwtSecretFile: path.join('/srv/trek', 'data', '.jwt_secret'),
encryptionKeyFile: path.join('/srv/trek', 'data', '.encryption_key'),
installIdFile: path.join('/srv/trek', 'data', '.trek-install-id'),
reclaimResetFile: path.join('/srv/trek', 'data', '.trek-reclaim-reset'),
dbFile: path.join('/srv/trek', 'data', 'travel.db'),
});
});
@@ -28,19 +28,24 @@ afterAll(async () => {
});
describe('StorageReleaseQueueRepository', () => {
it('RELQ-001: queues keys per category and answers the due ones, the longest waiting first, up to a limit', async () => {
it('RELQ-001: queues keys per category and answers the due ones of one category, the longest waiting first, up to a limit', async () => {
await queue.enqueue([{ category: 'covers', key: 'b.jpg' }], '2026-01-02 00:00:00');
await queue.enqueue([{ category: 'covers', key: 'a.jpg' }], '2026-01-01 00:00:00');
await queue.enqueue([{ category: 'places', key: 'a.jpg' }], '2026-01-01 00:00:00');
await queue.enqueue([{ category: 'covers', key: 'later.jpg' }], '2026-02-01 00:00:00');
expect(await queue.size()).toBe(4);
expect(await queue.dueIn(['covers'], '2026-01-15 00:00:00', 10)).toEqual([
expect(await queue.dueIn('covers', '2026-01-15 00:00:00', 10)).toEqual([
{ category: 'covers', key: 'a.jpg', due_at: '2026-01-01 00:00:00' },
{ category: 'covers', key: 'b.jpg', due_at: '2026-01-02 00:00:00' },
]);
expect(await queue.dueIn(['covers', 'places'], '2026-01-15 00:00:00', 1)).toHaveLength(1);
expect(await queue.dueIn([], '2026-01-15 00:00:00', 10)).toEqual([]);
expect(await queue.dueIn(['covers'], '2026-01-15 00:00:00', 0)).toEqual([]);
expect(await queue.dueIn('covers', '2026-01-15 00:00:00', 1)).toEqual([
{ category: 'covers', key: 'a.jpg', due_at: '2026-01-01 00:00:00' },
]);
expect(await queue.dueIn('places', '2026-01-15 00:00:00', 10)).toEqual([
{ category: 'places', key: 'a.jpg', due_at: '2026-01-01 00:00:00' },
]);
expect(await queue.dueIn('files', '2026-01-15 00:00:00', 10)).toEqual([]);
expect(await queue.dueIn('covers', '2026-01-15 00:00:00', 0)).toEqual([]);
});
it('RELQ-002: a key queued again waits from the later time, and an empty batch writes nothing', async () => {
@@ -48,8 +53,8 @@ describe('StorageReleaseQueueRepository', () => {
await queue.enqueue([{ category: 'covers', key: 'a.jpg' }], '2026-03-01 00:00:00');
await queue.enqueue([], '2026-04-01 00:00:00');
expect(await queue.size()).toBe(1);
expect(await queue.dueIn(['covers'], '2026-02-01 00:00:00', 10)).toEqual([]);
expect(await queue.dueIn(['covers'], '2026-03-01 00:00:00', 10)).toHaveLength(1);
expect(await queue.dueIn('covers', '2026-02-01 00:00:00', 10)).toEqual([]);
expect(await queue.dueIn('covers', '2026-03-01 00:00:00', 10)).toHaveLength(1);
});
it('RELQ-003: answers the categories holding a due row, each once', async () => {
@@ -77,7 +82,7 @@ describe('StorageReleaseQueueRepository', () => {
expect(await queue.deleteKeys('covers', ['a.jpg', 'nope.jpg'])).toBe(1);
expect(await queue.deleteKeys('covers', [])).toBe(0);
expect(await queue.deleteDueBefore('2026-02-01 00:00:00')).toBe(1);
expect(await queue.dueIn(['places'], '2026-03-01 00:00:00', 10)).toEqual([
expect(await queue.dueIn('places', '2026-03-01 00:00:00', 10)).toEqual([
{ category: 'places', key: 'a.jpg', due_at: '2026-03-01 00:00:00' },
]);
});
@@ -39,6 +39,7 @@ const fsMock = vi.hoisted(() => ({
createReadStream: vi.fn(),
rmSync: vi.fn(),
copyFileSync: vi.fn(),
writeFileSync: vi.fn(),
renameSync: vi.fn(),
cpSync: vi.fn(),
// Identity by default: when uploadsDir is a plain directory, realpathSync
@@ -1428,6 +1429,35 @@ describe('BACKUP-045 restoreFromZip — full success path (no uploads)', () => {
expect(logMock.logInfo).toHaveBeenCalledWith(expect.stringContaining('the replaced database was kept as'));
});
it('BACKUP-045j: leaves the reclaim reset file before it closes the database, and swaps nothing when it cannot', async () => {
setupSuccessfulExtraction();
setupAllTablesPresent();
const callOrder: string[] = [];
fsMock.writeFileSync.mockImplementation((target: string) => {
callOrder.push(`write:${path.basename(String(target))}`);
});
dbMock.closeDb.mockImplementation(() => {
callOrder.push('closeDb');
});
fsMock.unlinkSync.mockReturnValue(undefined);
fsMock.rmSync.mockReturnValue(undefined);
fsMock.existsSync.mockImplementation((p: string) => !String(p).includes('uploads'));
await restoreFromZip(deps(stubStorage()), '/data/tmp/upload.zip');
expect(callOrder.slice(0, 2)).toEqual(['write:.trek-reclaim-reset', 'closeDb']);
setupSuccessfulExtraction();
setupAllTablesPresent();
dbMock.closeDb.mockClear();
fsMock.writeFileSync.mockImplementation(() => {
throw new Error('read-only file system');
});
await expect(restoreFromZip(deps(stubStorage()), '/data/tmp/upload.zip')).rejects.toThrow('read-only file system');
expect(dbMock.closeDb).not.toHaveBeenCalled();
fsMock.writeFileSync.mockReset();
});
it('BACKUP-045i: swaps the archive into the database the connection runs on when TREK_DB_FILE moves it', async () => {
// The restore used to write data/travel.db whatever TREK_DB_FILE said: the
// live database was never replaced and the restore reported success.
+28 -11
View File
@@ -1,5 +1,5 @@
/**
* BOOT-RESTORE-001..008 — restoring a backup on a first start (#1089).
* BOOT-RESTORE-001..009 — restoring a backup on a first start (#1089).
*
* Real files, a real archive and a real SQLite file: what is being protected is
* the order of things on disk, and a mocked filesystem would only confirm the
@@ -21,12 +21,14 @@ vi.mock('../../../src/nest/plugins/plugin-backup', () => ({ stageExtractedPlugin
let root: string;
let dataDir: string;
let dbFile: string;
let reclaimResetFile: string;
beforeEach(() => {
root = fs.mkdtempSync(path.join(os.tmpdir(), 'trek-boot-restore-'));
dataDir = path.join(root, 'data');
fs.mkdirSync(dataDir);
dbFile = path.join(dataDir, 'travel.db');
reclaimResetFile = path.join(dataDir, '.trek-reclaim-reset');
stageMock.mockClear();
vi.spyOn(console, 'log').mockImplementation(() => {});
});
@@ -75,14 +77,17 @@ async function goodArchive(extra: Record<string, string> = {}) {
describe('restoreOnFirstBoot', () => {
it('BOOT-RESTORE-001: without the variable nothing happens', async () => {
expect(await restoreOnFirstBoot({ archive: null, dbFile, dataDir })).toEqual({ restored: false, reason: 'unset' });
expect(await restoreOnFirstBoot({ archive: null, dbFile, dataDir, reclaimResetFile })).toEqual({
restored: false,
reason: 'unset',
});
expect(fs.existsSync(dbFile)).toBe(false);
});
it("BOOT-RESTORE-002: on a first start the backup's database, key and uploads are put in place", async () => {
const zipPath = await goodArchive();
const out = await restoreOnFirstBoot({ archive: zipPath, dbFile, dataDir });
const out = await restoreOnFirstBoot({ archive: zipPath, dbFile, dataDir, reclaimResetFile });
expect(out.restored).toBe(true);
const db = new Database(dbFile, { readonly: true });
@@ -94,6 +99,8 @@ describe('restoreOnFirstBoot', () => {
expect(fs.readFileSync(path.join(out.uploads!, 'covers', 'c.jpg'), 'utf8')).toBe('jpeg');
expect(stageMock).toHaveBeenCalledWith(out.staging);
expect(fs.existsSync(`${dbFile}.restore-tmp`)).toBe(false);
// Storage reclaim drops the restored database's reclaim state on this start, whichever install it is from.
expect(fs.existsSync(reclaimResetFile)).toBe(true);
});
it('BOOT-RESTORE-003: with a database already there the backup is left alone, so a restart never rolls back', async () => {
@@ -102,35 +109,37 @@ describe('restoreOnFirstBoot', () => {
const before = fs.readFileSync(dbFile);
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
expect(await restoreOnFirstBoot({ archive: zipPath, dbFile, dataDir })).toEqual({
expect(await restoreOnFirstBoot({ archive: zipPath, dbFile, dataDir, reclaimResetFile })).toEqual({
restored: false,
reason: 'database-exists',
});
expect(fs.readFileSync(dbFile).equals(before)).toBe(true);
expect(warn).toHaveBeenCalledWith(expect.stringContaining('only restored on a first start'));
expect(fs.existsSync(reclaimResetFile)).toBe(false);
});
it('BOOT-RESTORE-004: a missing archive stops the start instead of coming up empty', async () => {
await expect(restoreOnFirstBoot({ archive: path.join(root, 'nope.zip'), dbFile, dataDir })).rejects.toBeInstanceOf(
BootRestoreError,
);
await expect(
restoreOnFirstBoot({ archive: path.join(root, 'nope.zip'), dbFile, dataDir, reclaimResetFile }),
).rejects.toBeInstanceOf(BootRestoreError);
expect(fs.existsSync(dbFile)).toBe(false);
});
it('BOOT-RESTORE-005: an archive without a database is refused and leaves no scratch behind', async () => {
const zipPath = await archive({ 'notes.txt': 'hello' });
await expect(restoreOnFirstBoot({ archive: zipPath, dbFile, dataDir })).rejects.toThrow(
await expect(restoreOnFirstBoot({ archive: zipPath, dbFile, dataDir, reclaimResetFile })).rejects.toThrow(
'RESTORE_FROM_BACKUP: Invalid backup: travel.db not found',
);
expect(fs.existsSync(dbFile)).toBe(false);
expect(fs.readdirSync(dataDir).filter((n) => n.startsWith('restore-boot-'))).toEqual([]);
expect(fs.existsSync(reclaimResetFile)).toBe(false);
});
it('BOOT-RESTORE-006: a database that is not a TREK one is refused', async () => {
const src = path.join(root, 'other.db');
trekDb(src, ['users']);
const zipPath = await archive({ 'travel.db': { file: src } });
await expect(restoreOnFirstBoot({ archive: zipPath, dbFile, dataDir })).rejects.toThrow(
await expect(restoreOnFirstBoot({ archive: zipPath, dbFile, dataDir, reclaimResetFile })).rejects.toThrow(
'missing required table: trips',
);
expect(fs.existsSync(dbFile)).toBe(false);
@@ -138,7 +147,7 @@ describe('restoreOnFirstBoot', () => {
it('BOOT-RESTORE-007: an entry escaping the archive is refused', async () => {
const zipPath = await archive({ '../escape.txt': 'x', 'travel.db': 'not a db' });
await expect(restoreOnFirstBoot({ archive: zipPath, dbFile, dataDir })).rejects.toThrow(
await expect(restoreOnFirstBoot({ archive: zipPath, dbFile, dataDir, reclaimResetFile })).rejects.toThrow(
/escapes the archive root|not a valid SQLite database/,
);
expect(fs.existsSync(dbFile)).toBe(false);
@@ -149,10 +158,18 @@ describe('restoreOnFirstBoot', () => {
trekDb(src);
const zipPath = await archive({ 'travel.db': { file: src } });
const out = await restoreOnFirstBoot({ archive: zipPath, dbFile, dataDir });
const out = await restoreOnFirstBoot({ archive: zipPath, dbFile, dataDir, reclaimResetFile });
expect(out).toEqual({ restored: true, uploads: null, staging: expect.stringContaining('restore-boot-') });
expect(fs.existsSync(dbFile)).toBe(true);
expect(fs.existsSync(path.join(dataDir, '.encryption_key'))).toBe(false);
});
it('BOOT-RESTORE-009: a reclaim reset file that cannot be written stops the start before the database is put in place', async () => {
const zipPath = await goodArchive();
// A directory where the file goes: writing it fails, as on a read-only data folder.
fs.mkdirSync(reclaimResetFile);
await expect(restoreOnFirstBoot({ archive: zipPath, dbFile, dataDir, reclaimResetFile })).rejects.toThrow();
expect(fs.existsSync(dbFile)).toBe(false);
});
});
@@ -9,7 +9,8 @@
* covers a margin for two weeks and is used up once the share is back under;
* an owner marker of another install keeps its hands off; a restore, or a
* database naming another install, resets the switch, the marks, the queue
* and the reports but keeps this install's id. RCLS-001 to RCLS-043.
* and the reports but keeps this install's id, and so does a restore's reset
* file whatever id the database names. RCLS-001 to RCLS-045.
*/
import { AppSettings } from '../../../../src/db/entities/AppSettings.entity';
import { AuditLog } from '../../../../src/db/entities/AuditLog.entity';
@@ -19,7 +20,7 @@ import { StorageReclaimMarksRepository } from '../../../../src/db/repositories/S
import { dbNow } from '../../../../src/db/types';
import { DataPathsService } from '../../../../src/nest/app-config/data-paths.service';
import { RuntimeEnvService } from '../../../../src/nest/app-config/runtime-env.service';
import { logError } from '../../../../src/nest/audit/audit-log.logger';
import { logError, logWarn } from '../../../../src/nest/audit/audit-log.logger';
import { DomainError } from '../../../../src/nest/common/domain-error';
import { DatabaseLifecycle } from '../../../../src/nest/database/database-lifecycle.service';
import { StorageAdminService } from '../../../../src/nest/storage/storage-admin.service';
@@ -167,7 +168,14 @@ beforeAll(async () => {
imports: [StorageModule],
init: true,
overrides: [
{ provide: DataPathsService, useValue: { ...new DataPathsService(), installIdFile: path.join(dataRoot, 'id') } },
{
provide: DataPathsService,
useValue: {
...new DataPathsService(),
installIdFile: path.join(dataRoot, 'id'),
reclaimResetFile: path.join(dataRoot, 'reclaim-reset'),
},
},
{
provide: DatabaseLifecycle,
useValue: {
@@ -189,6 +197,7 @@ beforeAll(async () => {
beforeEach(async () => {
vi.restoreAllMocks();
vi.mocked(logError).mockClear();
vi.mocked(logWarn).mockClear();
for (const entry of fs.readdirSync(uploadsRoot)) {
if (entry !== '.tmp') fs.rmSync(path.join(uploadsRoot, entry), { recursive: true, force: true });
}
@@ -854,6 +863,59 @@ describe('StorageReclaimService: a pass that stops, and a restore', () => {
expect(await countRows(orm, StorageReleaseQueue)).toBe(0);
});
it('RCLS-044: a restore left the reset file: a backup of this installation loses its state too, then it goes', async () => {
const install = t.get(StorageInstallService);
const sentinel = path.join(dataRoot, 'reclaim-reset');
await markedWeekOld(['orphan.jpg']);
await orm.repo(StorageReleaseQueue).enqueue([{ category: 'covers', key: 'queued.jpg' }], dbNow(new Date()));
// A restore at boot, or a restart after a restore whose reopen failed: the id is this installation's own.
fs.writeFileSync(sentinel, 'pending');
expect(await install.databaseIsThis(installId)).toBe(false);
expect(await install.reconcile()).toBe(true);
expect(fs.existsSync(sentinel)).toBe(false);
expect(await readAppSetting(orm, 'install_id')).toBe(installId);
expect(await readAppSetting(orm, 'storage.reclaim_delete')).toBeNull();
expect(await readAppSetting(orm, 'storage.reclaim_report')).toBeNull();
expect(await marksOf('covers')).toEqual([]);
expect(await countRows(orm, StorageReleaseQueue)).toBe(0);
expect(await install.databaseIsThis(installId)).toBe(true);
// Done once: the next start keeps what this installation does from then on.
await reclaim.setDeleteEnabled(true);
expect(await install.reconcile()).toBe(false);
expect((await reclaim.state()).deleteEnabled).toBe(true);
// A reopen that went through takes the file away with its reset.
fs.writeFileSync(sentinel, 'pending');
await reopen();
expect(fs.existsSync(sentinel)).toBe(false);
expect((await reclaim.state()).deleteEnabled).toBe(false);
});
it('RCLS-045: a reset file that cannot be removed is reset again on the next start, and the database is not this', async () => {
const install = t.get(StorageInstallService);
const sentinel = path.join(dataRoot, 'reclaim-reset');
fs.writeFileSync(sentinel, 'pending');
const realRm = fs.rmSync;
vi.spyOn(fs, 'rmSync').mockImplementation((target, options) => {
if (target === sentinel) throw Object.assign(new Error('read-only file system'), { code: 'EROFS' });
realRm(target, options);
});
try {
await reclaim.setDeleteEnabled(true);
expect(await install.reconcile()).toBe(true);
expect(fs.existsSync(sentinel)).toBe(true);
expect(await install.databaseIsThis(installId)).toBe(false);
expect(logWarn).toHaveBeenCalledWith(expect.stringContaining('the next start resets again'));
} finally {
vi.mocked(fs.rmSync).mockRestore();
fs.rmSync(sentinel, { force: true });
}
expect(await install.databaseIsThis(installId)).toBe(true);
// A database that names another installation is not this one either.
await setAppSetting(orm, 'install_id', '12345678-aaaa-4bbb-8ccc-1234567890ab');
expect(await install.databaseIsThis(installId)).toBe(false);
expect(await install.reconcile()).toBe(true);
});
it('RCLS-041: the install id file is made once, mode 0600; a garbled one keeps every delete off', async () => {
const file = path.join(dataRoot, 'id');
expect(fs.readFileSync(file, 'utf8').trim()).toBe(installId);
@@ -5,7 +5,9 @@
* StorageModule (a LocalDriver on a temp folder) with fake sources standing in
* for the owner domains. An object any row still names stays; the pass's
* guards hold, the owner marker included; a failure never reaches the caller
* and leaves its rows queued. RELS-001 to RELS-021.
* and leaves its rows queued; one failing category never holds up another, and
* a database that is not this installation's releases nothing. RELS-001 to
* RELS-026.
*/
import { AppSettings } from '../../../../src/db/entities/AppSettings.entity';
import { StorageReleaseQueue } from '../../../../src/db/entities/StorageReleaseQueue.entity';
@@ -121,7 +123,11 @@ beforeAll(async () => {
dataRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'trek-release-data-'));
orm = await createTestOrm(db);
await setBackends();
const paths = { ...new DataPathsService(), installIdFile: path.join(dataRoot, '.trek-install-id') };
const paths = {
...new DataPathsService(),
installIdFile: path.join(dataRoot, '.trek-install-id'),
reclaimResetFile: path.join(dataRoot, '.trek-reclaim-reset'),
};
t = await createTestModule({
db,
imports: [StorageModule],
@@ -441,3 +447,103 @@ describe('StorageReleaseService: the guards the nightly pass keeps', () => {
expect(await queued('covers')).toBe(0);
});
});
describe('StorageReleaseService: what a round-3 review found', () => {
it('RELS-022: a database naming another installation, or a restore whose reset is pending, releases nothing', async () => {
await put('covers', `${UUID}-x.jpg`);
await release.releaseValues([`/uploads/covers/${UUID}-x.jpg`]);
await setAppSetting(orm, 'install_id', '12345678-aaaa-4bbb-8ccc-1234567890ab');
try {
expect((await release.processDue(due())).skipped).toBe('install_mismatch');
} finally {
await setAppSetting(orm, 'install_id', installId);
}
const sentinel = path.join(dataRoot, '.trek-reclaim-reset');
fs.writeFileSync(sentinel, 'pending');
try {
expect((await release.processDue(due())).skipped).toBe('install_mismatch');
} finally {
fs.rmSync(sentinel, { force: true });
}
expect(exists('covers', `${UUID}-x.jpg`)).toBe(true);
expect(await queued('covers')).toBe(1);
expect(await release.processDue(due())).toEqual({ skipped: null, deleted: 1, kept: 0 });
});
it('RELS-023: a category whose deletes keep failing takes only its share of a tick, the others still go', async () => {
const older = Array.from({ length: 230 }, (_unused, i) => `${UUID}-c${i}.jpg`);
await orm.repo(StorageReleaseQueue).enqueue(
older.map((key) => ({ category: 'covers', key })),
dbNow(new Date(Date.now() - DAY)),
);
await put('places', `${UUID}-p.jpg`);
await release.releaseValues([`/uploads/places/${UUID}-p.jpg`]);
const realDelete = storage.delete.bind(storage);
vi.spyOn(storage, 'delete').mockImplementation(async (category, key) => {
if (category === 'covers') throw new Error('covers bucket refuses deletes');
await realDelete(category, key);
});
// The 230 older covers rows would fill a tick of 200 on their own, every tick.
expect((await release.processDue(due())).deleted).toBe(1);
expect(exists('places', `${UUID}-p.jpg`)).toBe(false);
expect(await queued('places')).toBe(0);
expect(await queued('covers')).toBe(230);
});
it('RELS-024: rows dropped after thirty days and a full queue are logged at warn with their counts', async () => {
await orm.repo(StorageReleaseQueue).enqueue(
[
{ category: 'covers', key: `${UUID}-old1.jpg` },
{ category: 'places', key: `${UUID}-old2.jpg` },
],
dbNow(new Date(Date.now() - 31 * DAY)),
);
await release.processDue(new Date());
expect(logWarn).toHaveBeenCalledWith(expect.stringMatching(/^\[storage\] 2 released object\(s\) waited 30 days/));
expect(logWarn).toHaveBeenCalledWith(expect.stringContaining('only once deletion is on'));
vi.mocked(logWarn).mockClear();
vi.spyOn(StorageReleaseQueueRepository.prototype, 'size').mockResolvedValueOnce(50_000);
expect(await release.releaseValues([`/uploads/covers/${UUID}-full.jpg`])).toBe(0);
expect(logWarn).toHaveBeenCalledWith(expect.stringContaining('(50000 of 50000 waiting): 1 released object(s)'));
expect(await countRows(orm, StorageReleaseQueue)).toBe(0);
});
it('RELS-025: an allowed owner verdict holds for one window only, a refusal until the next night', async () => {
const marker = storageOwnerMarkerKey('another-install-0002');
const lists = vi.spyOn(storage, 'list');
const start = due().getTime();
await put('covers', `${UUID}-w1.jpg`);
await release.releaseValues([`/uploads/covers/${UUID}-w1.jpg`]);
expect((await release.processDue(new Date(start))).deleted).toBe(1);
expect(lists).toHaveBeenCalledTimes(1);
// Another installation's marker shows up: within the window the verdict stands, without a second listing.
await put('covers', marker);
try {
await put('covers', `${UUID}-w2.jpg`);
await release.releaseValues([`/uploads/covers/${UUID}-w2.jpg`]);
expect((await release.processDue(new Date(start + 10 * 60_000))).deleted).toBe(1);
expect(lists).toHaveBeenCalledTimes(1);
// Past it the root is listed again and the category refused.
await put('covers', `${UUID}-w3.jpg`);
await release.releaseValues([`/uploads/covers/${UUID}-w3.jpg`]);
expect((await release.processDue(new Date(start + 16 * 60_000))).deleted).toBe(0);
expect(lists).toHaveBeenCalledTimes(2);
} finally {
await storage.delete('covers', marker);
}
// The refusal holds hours later, though the marker is gone, until the nightly pass judges again.
expect((await release.processDue(new Date(start + 6 * 60 * 60_000))).deleted).toBe(0);
expect(lists).toHaveBeenCalledTimes(2);
expect(exists('covers', `${UUID}-w3.jpg`)).toBe(true);
expect((await release.processDue(new Date(start + 27 * 60 * 60_000))).deleted).toBe(1);
expect(exists('covers', `${UUID}-w3.jpg`)).toBe(false);
});
it('RELS-026: the owner marker is looked for in the category root only, one shallow listing', async () => {
const lists = vi.spyOn(storage, 'list');
await put('covers', `${UUID}-root.jpg`);
await release.releaseValues([`/uploads/covers/${UUID}-root.jpg`]);
await release.processDue(due());
expect(lists.mock.calls).toEqual([['covers', '', { shallow: true }]]);
});
});