import { describe, expect, it, vi } from "vitest";

import { runStorageMaintenance } from "../../apps/worker/src/storage-maintenance.js";

describe("TDD-WP0-FILE-001 worker reconciliation", () => {
  it("reconciles startup before processing physical cleanup", async () => {
    const target = {
      processCleanupQueue: vi.fn(async () => ({ completed: 1, failed: 0 })),
      reconcileStartup: vi.fn(async () => ({ orphaned: 1, released_reservations: 1 })),
    };
    await expect(runStorageMaintenance(target)).resolves.toEqual({
      cleanup: { completed: 1, failed: 0 },
      reconciliation: { orphaned: 1, released_reservations: 1 },
    });
    expect(target.reconcileStartup).toHaveBeenCalledBefore(target.processCleanupQueue);
  });
});
