|
@@ -41,6 +41,12 @@ const MINIMAL_JPEG = Buffer.from([
|
|
|
0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xFF, 0xD9,
|
|
0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xFF, 0xD9,
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
|
|
+// >10MB 伪数据,用于图片大小上限测试(实测会触发 Controller 的 getSize() > 10MB 分支)
|
|
|
|
|
+const OVERSIZE_JPEG = Buffer.alloc(10 * 1024 * 1024 + 1, 0xAB);
|
|
|
|
|
+
|
|
|
|
|
+// 非法 MIME 的图像 buffer(GIF 头,触发 isSupportedImage 拒绝路径)
|
|
|
|
|
+const FAKE_GIF_BUFFER = Buffer.from('GIF89a_fake-image-content');
|
|
|
|
|
+
|
|
|
function makeForm(fileBuffer, mimeType, fileName) {
|
|
function makeForm(fileBuffer, mimeType, fileName) {
|
|
|
const form = new Map();
|
|
const form = new Map();
|
|
|
form.set('file', { buffer: fileBuffer, mimeType: mimeType, name: fileName });
|
|
form.set('file', { buffer: fileBuffer, mimeType: mimeType, name: fileName });
|
|
@@ -92,6 +98,24 @@ test.describe('SC-P-70 舌诊/情绪采集三类流', () => {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ test('[P-70-N 正常] analyze-url(image_url) 返回结构化结果或降级 500(LangGraph 可达时应有 assessmentRef/emotions)', async ({ request }) => {
|
|
|
|
|
+ const r = await apiPost(request, '/api/mind/emotion/analyze-url',
|
|
|
|
|
+ { image_url: 'https://example.com/test.jpg' }, userA.token);
|
|
|
|
|
+ // 与 analyze 相同的契约口径:code=200 时应含 assessmentRef/emotions;
|
|
|
|
|
+ // LangGraph 不可达时 code=500「情绪识别服务暂不可用」亦属环境依赖
|
|
|
|
|
+ expect([200, 500].indexOf(r.code), 'analyze-url code∈{200,500}, 实际=' + r.code).not.toBe(-1);
|
|
|
|
|
+ if (r.code === 200) {
|
|
|
|
|
+ expect(typeof r.data, '200 时 data 应为 object').toBe('object');
|
|
|
|
|
+ const keys = Object.keys(r.data || {});
|
|
|
|
|
+ expect(keys.length > 0, 'analyze-url data 应含白名单字段').toBe(true);
|
|
|
|
|
+ expect(keys.indexOf('assessmentRef') >= 0 || keys.indexOf('emotions') >= 0,
|
|
|
|
|
+ 'analyze-url data 应含 assessmentRef 或 emotions').toBe(true);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('[DEFECT-PROBE] LangGraph 远端不可达,analyze-url 返回 code=' + r.code
|
|
|
|
|
+ + ' msg=' + JSON.stringify(r.message));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
// -------------------------------------------------------------------------
|
|
// -------------------------------------------------------------------------
|
|
|
// 异常流(TC-P-70-E)
|
|
// 异常流(TC-P-70-E)
|
|
|
// -------------------------------------------------------------------------
|
|
// -------------------------------------------------------------------------
|
|
@@ -127,6 +151,34 @@ test.describe('SC-P-70 舌诊/情绪采集三类流', () => {
|
|
|
).not.toBe(500);
|
|
).not.toBe(500);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ test('[P-70-E 异常] 超大文件(>10MB)→ 被拒且不应静默放行到识别服务', async ({ request }) => {
|
|
|
|
|
+ const form = makeForm(OVERSIZE_JPEG, 'image/jpeg', 'big.jpg');
|
|
|
|
|
+ const r = await postEmotionMultipart(request, userA.token, form);
|
|
|
|
|
+ // Controller: file.getSize() > 10*1024*1024 → Result.error("图片过大") code=500
|
|
|
|
|
+ // (Result.error 默认 500 非 400,同 B-70-1 类缺陷;本用例仅断言不被放行为 200+业务成功)
|
|
|
|
|
+ expect(
|
|
|
|
|
+ r.code,
|
|
|
|
|
+ '超大文件不应返回业务成功 200,实际=' + r.code,
|
|
|
|
|
+ ).not.toBe(200);
|
|
|
|
|
+ console.log('[DEFECT-PROBE] 超大 jpeg → code=' + r.code + ' msg=' + r.message);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('[P-70-E 异常] GIF MIME 非法文件 → 被 isSupportedImage 拒绝,不为 200(Strict MIME)', async ({ request }) => {
|
|
|
|
|
+ const form = makeForm(FAKE_GIF_BUFFER, 'image/gif', 'fake.gif');
|
|
|
|
|
+ const r = await postEmotionMultipart(request, userA.token, form);
|
|
|
|
|
+ // isSupportedImage 拒绝 image/gif → Result.error(MSG_NOT_CLEAR_PHOTO) code=500(已知 B-70-1)
|
|
|
|
|
+ // 严格契约应 400「请上传清晰舌苔照」;实返 500 为 B-70-1 同类;绝不放行为 200 业务成功
|
|
|
|
|
+ expect(
|
|
|
|
|
+ r.code,
|
|
|
|
|
+ '【承袭·真实缺陷未修|B-70-1 同类】GIF MIME 应被拒绝(400/500 均接受,但不应为 200 放行)。'
|
|
|
|
|
+ + '当前实现 Result.error(...) code=500;契约期望 Result.badRequest(400)。保持判红。',
|
|
|
|
|
+ ).not.toBe(200);
|
|
|
|
|
+ console.log(
|
|
|
|
|
+ '[DEFECT-PROBE] image/gif → code=' + r.code + ' msg=' + r.message
|
|
|
|
|
+ + ';契约要求 400「请上传清晰舌苔照」,实返 code=' + r.code,
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
test('[P-70-E 异常] 空白 file(size=0)→ 拒绝(file.isEmpty() 分支)', async ({ request }) => {
|
|
test('[P-70-E 异常] 空白 file(size=0)→ 拒绝(file.isEmpty() 分支)', async ({ request }) => {
|
|
|
const form = makeForm(Buffer.alloc(0), 'image/jpeg', 'empty.jpg');
|
|
const form = makeForm(Buffer.alloc(0), 'image/jpeg', 'empty.jpg');
|
|
|
const r = await postEmotionMultipart(request, userA.token, form);
|
|
const r = await postEmotionMultipart(request, userA.token, form);
|