前端(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>
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import fs from 'node:fs/promises';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
import { env } from '../src/config/env.js';
|
|
import {
|
|
withThumbnailTempDirectory,
|
|
writeThumbnailTempFile,
|
|
} from '../src/domain/thumbnailTempStorage.js';
|
|
|
|
const originalRoot = env.THUMBNAIL_TEMP_ROOT;
|
|
let testRoot: string | null = null;
|
|
|
|
afterEach(async () => {
|
|
env.THUMBNAIL_TEMP_ROOT = originalRoot;
|
|
if (testRoot) await fs.rm(testRoot, { recursive: true, force: true });
|
|
testRoot = null;
|
|
});
|
|
|
|
describe('thumbnailTempStorage', () => {
|
|
it('任务结束后无论成功与否都删除任务专属目录', async () => {
|
|
testRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'thumbnail-temp-test-'));
|
|
env.THUMBNAIL_TEMP_ROOT = testRoot;
|
|
const jobId = '00000000-0000-4000-8000-000000000001';
|
|
const leaseToken = '00000000-0000-4000-8000-000000000002';
|
|
let taskDirectory = '';
|
|
|
|
await expect(withThumbnailTempDirectory(jobId, leaseToken, async directory => {
|
|
taskDirectory = directory;
|
|
const file = await writeThumbnailTempFile(directory, 'thumbnail.webp', Buffer.from('test'));
|
|
const stats = await fs.stat(file);
|
|
expect(stats.mode & 0o777).toBe(0o600);
|
|
throw new Error('模拟处理失败');
|
|
})).rejects.toThrow('模拟处理失败');
|
|
|
|
await expect(fs.access(taskDirectory)).rejects.toMatchObject({ code: 'ENOENT' });
|
|
});
|
|
});
|