前端(Vite + React)、API/worker(Fastify + BullMQ)、api-contracts 契约包、 迁移脚本、测试与自托管 docker-compose 示例。 开源准备:运维脚本与机器信息已拆到私有仓库;公司名、备案号、隐私邮箱改读 publicCompliance.local.json(仓库只保留占位模板);站点地址与客服二维码改为 VITE_ 环境变量;fixtures 中的真实用户标识已匿名化;三个 package.json 标注 Apache-2.0。 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
const add = vi.hoisted(() => vi.fn());
|
|
vi.mock('../src/config/env.js', () => ({ env: { REDIS_URL: 'redis://localhost:6379' } }));
|
|
vi.mock('bullmq', () => ({
|
|
Queue: vi.fn(function Queue() {
|
|
return { add, close: vi.fn(), on: vi.fn() };
|
|
}),
|
|
}));
|
|
|
|
import { enqueueGenerationTask } from '../src/queues/generationQueue.js';
|
|
|
|
describe('generationQueue', () => {
|
|
it('同一业务 attempt 用 claim epoch 生成新 jobId,租约接管可真正恢复', async () => {
|
|
add.mockClear();
|
|
add.mockResolvedValue(undefined);
|
|
const taskId = '11111111-1111-4111-8111-111111111111';
|
|
await enqueueGenerationTask(taskId, 3, 7);
|
|
await enqueueGenerationTask(taskId, 3, 8);
|
|
|
|
expect(add).toHaveBeenNthCalledWith(
|
|
1,
|
|
'process-generation',
|
|
{ taskId, attempt: 3, claimEpoch: 7 },
|
|
{ jobId: `${taskId}-attempt-3-claim-7` },
|
|
);
|
|
expect(add).toHaveBeenNthCalledWith(
|
|
2,
|
|
'process-generation',
|
|
{ taskId, attempt: 3, claimEpoch: 8 },
|
|
{ jobId: `${taskId}-attempt-3-claim-8` },
|
|
);
|
|
});
|
|
});
|