openreader/tests/unit/compute-worker-client-contract.vitest.spec.ts
Richard R a56aaa2be9 Refactor PDF parsing and rendering logic; migrate to compute-worker protocol
- Removed deprecated functions related to document parsing and blob storage in blobstore.ts.
- Introduced new PDF rendering logic in pdf-preview-renderer.ts and pdf-preview-pdfjs-runtime.ts.
- Updated previews-render.ts to utilize the new PDF rendering functions.
- Refactored user-whisper-align-job.ts to use the compute-worker client for alignment requests.
- Enhanced artifact.ts and operation.ts to validate parsed PDF artifacts and resolve current PDF parses.
- Updated snapshot.ts to align with new worker operation types.
- Adjusted runtime-config.ts to check for compute-worker availability.
- Modified types in parsed-pdf.ts and tts.ts to reflect changes in the compute-worker protocol.
- Added unit tests for PDF artifact validation and compute-worker client contract.
- Removed obsolete pdf-op-key.vitest.spec.ts test file.
2026-06-12 13:43:33 -06:00

58 lines
2 KiB
TypeScript

import { afterEach, describe, expect, test } from 'vitest';
import { createComputeWorkerApp, type ComputeWorkerApp } from '../../compute-worker/src/runtime';
import { FakeControlPlane } from '../../compute-worker/tests/fixtures/fake-control-plane';
import { ComputeWorkerClient } from '../../src/lib/server/compute-worker/client';
describe('ComputeWorkerClient contract', () => {
let runtime: ComputeWorkerApp | null = null;
afterEach(async () => {
await runtime?.close();
runtime = null;
});
test('exercises the real Fastify API through the app-owned HTTP client', async () => {
process.env.NATS_URL = 'nats://127.0.0.1:4222';
const fake = new FakeControlPlane();
runtime = await createComputeWorkerApp({
host: '127.0.0.1',
port: 0,
workerToken: 'contract-token',
disableWorkers: true,
routeDeps: fake.deps,
});
await runtime.start();
const address = runtime.app.server.address();
if (!address || typeof address === 'string') {
throw new Error('Compute worker did not bind a TCP port');
}
const client = new ComputeWorkerClient({
baseUrl: `http://127.0.0.1:${address.port}`,
token: 'contract-token',
});
const documentId = 'b'.repeat(64);
const request = {
documentId,
namespace: null,
documentObjectKey: `openreader/${documentId}.pdf`,
};
const created = await client.createPdfLayoutOperation(request);
expect(created).toMatchObject({
subject: { kind: 'pdf_layout', documentId, namespace: null },
status: 'queued',
});
expect(created).not.toHaveProperty('opKey');
expect(created).not.toHaveProperty('jobId');
await expect(client.getOperation(created.opId)).resolves.toMatchObject({
opId: created.opId,
subject: { kind: 'pdf_layout', documentId, namespace: null },
});
await expect(client.resolvePdfLayout(request)).resolves.toMatchObject({
artifact: null,
operation: { opId: created.opId },
});
});
});