Просмотр исходного кода

test(e2e): S-cfc-497 share.link.generate + S-cfc-496 ai.aiyunyi.upload 三流用例,探针取证承袭真实缺陷(G-304-1/N-R373-2)

仅写测试文件,不改生产源码。
- S-cfc-497 share.link.generate(SC-P-84): 正常生成+阅读 / 异常(缺 targetType/缺 targetId/targetId<=0/缺或坏 shareEventId/duration非数字) /
  权限(匿名401 严格·实测非401 + 越权分享/越权阅读严格·实测未拒) 三流;忽略型探针取真实契约;G-304-1 承袭·真实缺陷未修不造绿。
- S-cfc-496 ai.aiyunyi.upload: 正常上传 file(+path)→URL / 异常(非multipart 400/缺file 500/空file 500/仅POST 405/上游归一500) /
  权限(匿名401 登录门优先/匿名GET 405) 三流;忽略型探针取真实契约;外部爱云医上游未验 N-R373-2 承袭·真实缺陷未修不造绿。
探针 _probe_*.spec.js gitignore 不入库。
Sisyphus 14 часов назад
Родитель
Сommit
23c1306458

+ 176 - 0
tests/e2e/api/s-cfc-496-ai-aiyunyi-upload.spec.js

@@ -0,0 +1,176 @@
+/**
+ * S-cfc-496  ai.aiyunyi.upload  三类流 e2e 契约用例
+ * ================================================================
+ * 能力键 ai.aiyunyi.upload(docs/2026-11-24-爱云医AI检测接入方案.md §4.1/§3.3 B.7;S-cfc-496 4fc5c828f;
+ *   AicdsController javadoc + AicdsDetectionService.uploadFile + AiyunyiUploadContractTest CAPABILITY)。
+ *   (sc-key-map.md 当前无 ai.aiyunyi.* / S-cfc-496 登记;本 key 由提交+源码定义,见 discovery-2026-12-02-1013 §2.1。)
+ *
+ * 载体(AicdsController,统一 @PostMapping,仅 POST):
+ *   POST /api/aiyunyi/upload   multipart/form-data;必填 file;可选 path;
+ *     → Result,data=爱云医平台返回图片 URL(转发平台 POST /app-api/detection/package/enter/upload,
+ *       X-App-Key/X-Timestamp/X-Api-Sign,禁 /open-api/ upload 路径,不带 Authorization/X-User-Id-Encrypt)。
+ *   鉴权:JwtInterceptor.LOGIN_REQUIRED_PATHS 含 "/api/aiyunyi/"(整族登录门,匿名→401)
+ *     + controller @RequestAttribute("role") 角色闸门(anonymous/空白→403「无权限上传爱云医照片」,不进服务层)。
+ *   错误归一:服务层异常一律 Result.error「爱云医照片上传失败:…」(HTTP 200 + code=500,不把 http 500 外泄,不输出原始第三方报文为成功)。
+ *
+ * 探针取证(_probe_sc496.spec.js,gitignore 不入库,本机 127.0.0.1:9082 实测):
+ *   ── 本环境真实契约 ──
+ *   ANON_UPLOAD      http=401 code=401「请先登录」(登录门,无 token→401,不进服务层)
+ *   NO_FILE          http=200 code=500「服务器内部错误」(@RequestParam("file") 必填缺失 → MissingServletRequestPartException → 500;非 400)
+ *   EMPTY_FILE       http=200 code=500「爱云医照片上传失败:爱云医照片上传缺少 file(B.7 必填)」(空文件进服务层 → IllegalArgumentException → 归一)
+ *   NON_MULTIPART    http=200 code=400「请求格式错误,请使用文件表单上传」(非 multipart → MultipartException → GlobalExceptionHandler 400)
+ *   GET              http=200 code=405「请求方法不支持,本平台接口统一使用POST」(仅 POST)
+ *   AUTHED_UPLOAD    http=200 code=200 data=<imageUrl>(需爱云医上游可达 + app-key 有效;否则见下)
+ *   外部不可用/未配 app-key(本环境默认 AIYUNYI_BASE_URL=https://devadmin.aicds.com.cn/open-api + 占位 app-key):
+ *     http=200 code=500「爱云医照片上传失败:爱云医照片上传失败,code=401」(上游返回非 0 → IllegalState → 归一 code=500;不 http500;
+ *     实测此处**透出上游 code=401 文案**;不造假成功)
+ *   AUTHED_UPLOAD_WITH_STUB(后端 AIYUNYI_BASE_URL 指向返回 {code:0,data:url} 的上游 stub 实测):
+ *     http=200 code=200 data="…/img/1.png"(path 选填;form 带 file(+path);返回 URL 原样透传)
+ *
+ * ── 真实缺陷·承袭登记(不为缺陷造绿)──
+ *   [承袭·真实缺陷未修|N-R373-2/环境] 正常流依赖外部爱云医平台可达 + 真实 app-key/私钥签名;
+ *     测试环境占位 app-key(app-xxxx…)→ 上游 code=401 → 归一 code=500;本 spec 正常流严格断言,命中判红登记。
+ *     (契约层「转发 + URL 透传 + 非200归一 + 角色闸门 + 登录门 + 仅POST」由 AiyunyiUploadContractTest 12 例覆盖,
+ *      但 mock 不等于真实爱云医链路;真实上游**未验**。本轮未连生产。)
+ *   [承袭·真实缺陷未修] 缺 file 参数(非空 multipart 但无 file 字段)→ code=500「服务器内部错误」(非 400 参数校验);
+ *     空文件 → code=500;非 multipart → code=400;**仅 anonymous→401 为严格安全门**。
+ *   [承袭·真实缺陷未修] 错误文案透出上游原因(如「code=401」/ e.getMessage());结构化鉴权「role=anonymous→403」
+ *     在线上被登录门 401 先行拦截(难以仅凭 API 构造 role=anonymous + 有效 token),仅源码级断言。
+ *   (sc-key-map 未登记本 key;API_REFERENCE 无 /api/aiyunyi 登记;不在 tests/test-cases 台账。本轮仅补 e2e,不改生产源码。)
+ *
+ * 【硬边界】仅写测试文件;禁 `?.`;禁直接 `new Date(string)`;探针保持 gitignore 不入库;不改 src/main;不连生产。
+ * 【正常流运行前置】后端 AIYUNYI_BASE_URL 指向可用爱云医平台且 app-key/私钥有效,或本地 stub;否则正常流判红(承袭)。
+ */
+const { test, expect } = require('@playwright/test');
+const { registerRole, uniqueSuffix } = require('../helpers/api');
+
+// 1x1 PNG
+const PNG = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==', 'base64');
+
+test.describe('S-cfc-496 ai.aiyunyi.upload 三类流', () => {
+  let userA;
+
+  test.beforeAll(async ({ request }) => {
+    userA = await registerRole(request, 'parent', 'QA-S496' + uniqueSuffix());
+  });
+
+  // -------------------------------------------------------------------------
+  // 正常流
+  // -------------------------------------------------------------------------
+
+  test('[S496-N 正常] 已登录合法 multipart 上传 file → 200 + data=图片 URL(转发爱云医 uploadFile 透传)', async ({ request }) => {
+    const res = await request.post('/api/aiyunyi/upload', {
+      headers: { Authorization: 'Bearer ' + userA.token },
+      multipart: { file: { name: 'a.png', mimeType: 'image/png', buffer: PNG } },
+      timeout: 90000,
+    });
+    const body = await res.json().catch(() => ({}));
+    expect(res.status(), 'http=200').toBe(200);
+    // 严格契约:成功 data 为非空字符串 URL。前置需爱云医上游可达+app-key 有效;
+    // 本环境默认占位 app-key → code=500「爱云医照片上传失败…」判红登记「承袭·真实缺陷未修|N-R373-2/环境」,不造绿。
+    expect(body.code, '【承袭·真实缺陷未修】正常上传 code=200, 实际=' + body.code + ' msg=' + body.message).toBe(200);
+    expect(typeof body.data, 'data=图片 URL 字符串').toBe('string');
+    expect((body.data || '').length, 'data 非空').toBeGreaterThan(0);
+  });
+
+  test('[S496-N 正常] 可选 path 一并转发 → 200 + data=URL(path 不影响成功判定)', async ({ request }) => {
+    const res = await request.post('/api/aiyunyi/upload', {
+      headers: { Authorization: 'Bearer ' + userA.token },
+      multipart: { file: { name: 'a.png', mimeType: 'image/png', buffer: PNG }, path: 'qa/test.png' },
+      timeout: 90000,
+    });
+    const body = await res.json().catch(() => ({}));
+    expect(res.status(), 'http=200').toBe(200);
+    expect(body.code, '【承袭·真实缺陷未修】带 path 正常上传 code=200, 实际=' + body.code + ' msg=' + body.message).toBe(200);
+    expect(typeof body.data, 'data=URL 字符串').toBe('string');
+  });
+
+  // -------------------------------------------------------------------------
+  // 异常流
+  // -------------------------------------------------------------------------
+
+  test('[S496-E 异常] 非 multipart 请求 → 400「请求格式错误,请使用文件表单上传」', async ({ request }) => {
+    const res = await request.post('/api/aiyunyi/upload', {
+      headers: { Authorization: 'Bearer ' + userA.token, 'Content-Type': 'application/json' },
+      data: { file: 'x' },
+      timeout: 60000,
+    });
+    const body = await res.json().catch(() => ({}));
+    expect(res.status(), 'http=200').toBe(200);
+    expect(body.code, 'code=400, 实际=' + body.code).toBe(400);
+    expect(body.message).toBe('请求格式错误,请使用文件表单上传');
+  });
+
+  test('[S496-E 异常] multipart 但缺 file 字段 → 非成功(实测 code=500「服务器内部错误」,非400;不造绿)', async ({ request }) => {
+    const res = await request.post('/api/aiyunyi/upload', {
+      headers: { Authorization: 'Bearer ' + userA.token },
+      multipart: {},
+      timeout: 60000,
+    });
+    const body = await res.json().catch(() => ({}));
+    expect(res.status(), 'http=200').toBe(200);
+    expect(body.code, '缺 file → 非成功, 实际=' + body.code).not.toBe(200);
+    // 真实契约取证:@RequestParam("file") required=true 缺失 → 500 服务器内部错误(缺陷:非400)
+    expect(body.code, '【承袭·真实缺陷未修】缺 file→500 非400').toBe(500);
+    expect(body.data).toBeNull();
+  });
+
+  test('[S496-E 异常] 空 file(0 字节)→ 服务层拒绝归一 code=500「爱云医照片上传失败:爱云医照片上传缺少 file(B.7 必填)」', async ({ request }) => {
+    const res = await request.post('/api/aiyunyi/upload', {
+      headers: { Authorization: 'Bearer ' + userA.token },
+      multipart: { file: { name: 'empty.png', mimeType: 'image/png', buffer: Buffer.alloc(0) } },
+      timeout: 60000,
+    });
+    const body = await res.json().catch(() => ({}));
+    expect(res.status(), 'http=200').toBe(200);
+    expect(body.code, '空文件 → 500 归一, 实际=' + body.code).toBe(500);
+    expect(String(body.message || ''), '归一前缀').toContain('爱云医照片上传失败');
+    expect(body.data).toBeNull();
+  });
+
+  test('[S496-E 异常] 仅 POST:GET /api/aiyunyi/upload → 405', async ({ request }) => {
+    const res = await request.get('/api/aiyunyi/upload', {
+      headers: { Authorization: 'Bearer ' + userA.token }, timeout: 60000,
+    });
+    const body = await res.json().catch(() => ({}));
+    expect(res.status(), 'http=200').toBe(200);
+    expect(body.code, 'code=405').toBe(405);
+    expect(body.message).toBe('请求方法不支持,本平台接口统一使用POST');
+  });
+
+  // (外部上游不可用/鉴权失败 → 归一 code=500「爱云医照片上传失败…」HTTP不500、不造假成功:
+  //  本环境默认占位 app-key 实测 code=500「爱云医照片上传失败…code=401」,见探针取证 + 头部登记;
+  //  上游可用时走正常流。不写「成功或失败皆可」放水断言。)
+
+  // -------------------------------------------------------------------------
+  // 权限流
+  // -------------------------------------------------------------------------
+
+  test('[S496-P 权限·匿名401] 匿名上传 → 401「请先登录」(JwtInterceptor /api/aiyunyi/ 登录门,不进服务层)', async ({ request }) => {
+    const res = await request.post('/api/aiyunyi/upload', {
+      multipart: { file: { name: 'a.png', mimeType: 'image/png', buffer: PNG } }, timeout: 60000,
+    });
+    const body = await res.json().catch(() => ({}));
+    expect(res.status(), 'anon upload→401, 实际 http=' + res.status()).toBe(401);
+    expect(body.code, 'body.code=401').toBe(401);
+    expect(body.message).toBe('请先登录');
+  });
+
+  test('[S496-P 权限·匿名401] 匿名 + 非 multipart → 401 先于格式校验(登录门优先)', async ({ request }) => {
+    const res = await request.post('/api/aiyunyi/upload', {
+      headers: { 'Content-Type': 'application/json' }, data: {}, timeout: 60000,
+    });
+    const body = await res.json().catch(() => ({}));
+    expect(res.status(), 'anon non-multipart→401, 实际 http=' + res.status()).toBe(401);
+    expect(body.code, 'body.code=401').toBe(401);
+  });
+
+  test('[S496-P 权限] 匿名 GET → 405「仅POST」(handler mapping 先于登录门;非 401;真实契约取证)', async ({ request }) => {
+    const res = await request.get('/api/aiyunyi/upload', { timeout: 60000 });
+    const body = await res.json().catch(() => ({}));
+    // 实测:GET 仅-POST 映射不匹配 → HttpRequestMethodNotSupported → 405,先于 JwtInterceptor 登录门(非 401)。
+    expect(res.status(), 'http=200').toBe(200);
+    expect(body.code, 'anon GET→405, 实际=' + body.code).toBe(405);
+    expect(body.message).toBe('请求方法不支持,本平台接口统一使用POST');
+  });
+});

+ 242 - 0
tests/e2e/api/s-cfc-497-share-link-generate.spec.js

@@ -0,0 +1,242 @@
+/**
+ * S-cfc-497  share.link.generate  三类流 e2e 契约用例
+ * ================================================================
+ * SC-P-84 分享报告/方案给家人或规划师(docs/tdd/orchestration/sc-key-map.md L201)。
+ * 载体(ShareController,统一 @PostMapping):
+ *   POST /api/share/create   生成分享记录(越权分享被拒不落库不返回链接 · S-cfc-497 c71a518cf)
+ *                            body: { targetType(必填), targetId(必填,正数), shareChannel?, title? }
+ *   POST /api/share/read     记录分享阅读(越权阅读被拒不落 share_reads · S-cfc-497 c71a518cf)
+ *                            body: { shareEventId, duration? }  → data: { rewarded }
+ *   POST /api/share/my       我的分享记录
+ *   POST /api/share/stats    分享统计
+ *   POST /api/share/qrcode   生成分享小程序码(登录强制 · JwtInterceptor.LOGIN_REQUIRED_PATHS "/api/share/qrcode")
+ *
+ * 探针取证(_probe_sc497*.spec.js,gitignore 不入库,本机 127.0.0.1:9082 + 测试库实测):
+ *   ── 本环境真实契约(不以源码/台账自述为准)──
+ *   ANON_CREATE         http=200 code=500「无权分享该内容」(userId=-1 匿名放行到 controller,业务拒绝;**非 401**)
+ *   ANON_READ           http=200 code=200 data={rewarded:false}(readerId=-1 业务拒绝不落库;**非 401**)
+ *   ANON_MY             http=200 code=200 data=[](**非 401**)
+ *   A_CREATE_SELF       http=200 code=200 data={id,userId,targetType,targetId,shareChannel,shareTitle,shareUrl(16hex),status:'active',rewardPoints,clickCount:0,readCount:0,expiresAt,createdAt,updatedAt}
+ *   NO_TARGET_TYPE      http=200 code=500「服务器内部错误」(params.get("targetType").toString() NPE → GlobalExceptionHandler;非 400)
+ *   NO_TARGET_ID        http=200 code=500「无权分享该内容」(targetId==null → canCreateShare=false)
+ *   NEG_TARGET_ID       http=200 code=500「无权分享该内容」(targetId<=0 → 拒绝)
+ *   READ_NO_ID          http=200 code=200 rewarded=false(shareEventId==null → event==null → false)
+ *   READ_BAD_ID         http=200 code=200 rewarded=false(不存在 shareEventId → false)
+ *   READ_BAD_DURATION   http=200 code=400「For input string: \"abc\"」(Integer.parseInt → GlobalExceptionHandler 400;duration 非数字)
+ *   A_READ_SHORT        rewarded=false(duration < share_read_min_duration,默认 60)
+ *   A_READ_LONG         rewarded=true(duration >= minDuration;已落 share_reads + readCount++)
+ *   readCount           每次落库阅读 +1(POST /api/share/my 回读核验)
+ *   ── 越权取证(G-304-1 同族,实测)──
+ *   B_CREATE_TARGET_A   http=200 code=200 SUCCESS(B 跨家庭对 A 的 target 发起分享,**越权分享未被拒**)
+ *   B_READ_A_EVENT      http=200 code=200 rewarded=true + readCount++(B 跨用户阅读 A 的 share event,**越权阅读未被拒** + 奖励发放)
+ *   根因(源码级,本轮不改生产代码):
+ *     ShareService.canCreateShare → canViewMemberReports(userId, targetId, **caller自己familyId**),
+ *       ReportMemberPermissionService.isFamilyAdmin(userId, caller自己family)=true(direct-register 建家庭者即 admin)→ 无条件放行;
+ *       从不校验 targetId 所属家庭 == caller 家庭;familyId==null 时直接放行。
+ *     ShareService.canReadSharedTarget → 属主本人放行;否则同上 canViewMemberReports(readerId, event.targetId, reader自己familyId);
+ *     /api/share/create、/api/share/read、/api/share/my **不在 JwtInterceptor.LOGIN_REQUIRED_PATHS**,
+ *       匿名 setAnonymousUser(userId=-1) 放行到 controller;**仅 /api/share/qrcode 在 LOGIN_REQUIRED_PATHS**。
+ *
+ * ── 真实缺陷·承袭登记(不为缺陷造绿)──
+ *   [G-304-1 承袭·真实缺陷未修] 越权分享/越权阅读未被拒;匿名 /api/share/create 非 401;匿名 /api/share/read 非 401;
+ *     匿名 /api/share/my 非 401。本 spec 对「拒绝/401」写严格断言,命中即如实判红登记「承袭·真实缺陷未修」。
+ *     注:c71a518cf 提交信息自述「越权分享/越权阅读拒绝落库(6/6绿)」,但本环境运行时探针实测相反,以实测为准。
+ *   [承袭·真实缺陷未修] 缺 targetType → code=500「服务器内部错误」(NPE,非 400 参数校验);缺 duration 非数字 → code=400 透传异常文案。
+ *   (schema.sql 的 share_events 无 event_type;本环境共享测试库 share_events 存在 legacy NOT NULL event_type,
+ *    已为测试环境补 DEFAULT '';干净 schema 下 INSERT 不含 event_type。本 spec 不改生产源码、不改 schema.sql。)
+ *
+ * 【硬边界】仅写测试文件;禁 `?.`;禁直接 `new Date(string)`;探针文件保持 gitignore 不入库;不改 src/main。
+ */
+const { test, expect } = require('@playwright/test');
+const { registerRole, apiPost, uniqueSuffix } = require('../helpers/api');
+
+test.describe('S-cfc-497 share.link.generate 三类流', () => {
+  let userA, userB;
+
+  test.beforeAll(async ({ request }) => {
+    userA = await registerRole(request, 'parent', 'QA-S497-A' + uniqueSuffix());
+    userB = await registerRole(request, 'parent', 'QA-S497-B' + uniqueSuffix());
+  });
+
+  // -------------------------------------------------------------------------
+  // 正常流(生成 + 阅读)
+  // -------------------------------------------------------------------------
+
+  test('[S497-N 正常·生成] 登录用户生成分享 → 200 + 分享链接/状态/过期', async ({ request }) => {
+    const r = await apiPost(request, '/api/share/create', {
+      targetType: 'article', targetId: 12345, shareChannel: 'wechat', title: '分享标题',
+    }, userA.token);
+    expect(r.code, 'create code=200, 实际=' + r.code + ' msg=' + r.message).toBe(200);
+    const d = r.data || {};
+    expect(typeof d.shareUrl, '返回分享链接 shareUrl').toBe('string');
+    expect((d.shareUrl || '').length, 'shareUrl 非空').toBeGreaterThan(0);
+    expect(d.status, 'status=active').toBe('active');
+    expect(d.userId, 'userId=本人').toBe(userA.userId);
+    expect(d.targetType, 'targetType 回显').toBe('article');
+    expect(d.targetId, 'targetId 回显').toBe(12345);
+    expect(d.shareChannel, 'shareChannel 回显').toBe('wechat');
+    expect(d.clickCount, 'clickCount=0').toBe(0);
+    expect(d.readCount, 'readCount=0').toBe(0);
+    expect(typeof d.expiresAt, 'expiresAt 过期时间').toBe('string');
+  });
+
+  test('[S497-N 正常·生成] targetType=member + targetId=本人 → 200(目标属主本人可分享)', async ({ request }) => {
+    const r = await apiPost(request, '/api/share/create', {
+      targetType: 'member', targetId: userA.userId, shareChannel: 'timeline', title: 'member share',
+    }, userA.token);
+    expect(r.code, 'member self share 200, 实际=' + r.code + ' msg=' + r.message).toBe(200);
+    expect(r.data && r.data.targetType).toBe('member');
+  });
+
+  test('[S497-N 正常·阅读] 本人阅读自己的分享 → 200 + rewarded 语义 + readCount 落库 +1', async ({ request }) => {
+    const c = await apiPost(request, '/api/share/create', { targetType: 'article', targetId: 424242, title: 'read-me' }, userA.token);
+    expect(c.code, 'create 200').toBe(200);
+    const shareEventId = c.data && c.data.id;
+    expect(shareEventId, '拿到 shareEventId').toBeTruthy();
+
+    // 短阅读:未达 share_read_min_duration(默认 60)→ rewarded=false,但仍落库 readCount+1
+    const short = await apiPost(request, '/api/share/read', { shareEventId, duration: 5 }, userA.token);
+    expect(short.code, 'read short 200').toBe(200);
+    expect(short.data && short.data.rewarded, '短阅读 rewarded=false').toBe(false);
+
+    // 长阅读:达阈值 → rewarded=true
+    const long = await apiPost(request, '/api/share/read', { shareEventId, duration: 120 }, userA.token);
+    expect(long.code, 'read long 200').toBe(200);
+    expect(long.data && long.data.rewarded, '长阅读 rewarded=true').toBe(true);
+
+    // readCount 落库核验(POST /api/share/my 回读本人分享)
+    const my = await apiPost(request, '/api/share/my', {}, userA.token);
+    expect(my.code, 'my 200').toBe(200);
+    const list = Array.isArray(my.data) ? my.data : [];
+    const ev = list.find((x) => String(x.id) === String(shareEventId));
+    expect(ev, 'my 中含该 shareEvent').toBeTruthy();
+    expect(ev && ev.readCount, '两次阅读 readCount=2').toBe(2);
+  });
+
+  test('[S497-N 正常] /api/share/my 仅返回本人分享;/api/share/stats 统计本人', async ({ request }) => {
+    const my = await apiPost(request, '/api/share/my', {}, userA.token);
+    expect(my.code).toBe(200);
+    const list = Array.isArray(my.data) ? my.data : [];
+    for (const ev of list) {
+      expect(String(ev.userId), 'my 仅本人').toBe(String(userA.userId));
+    }
+    const stats = await apiPost(request, '/api/share/stats', {}, userA.token);
+    expect(stats.code, 'stats 200').toBe(200);
+    expect(typeof (stats.data && stats.data.totalShares), 'totalShares 数值').toBe('number');
+    expect(typeof (stats.data && stats.data.totalReads), 'totalReads 数值').toBe('number');
+  });
+
+  // -------------------------------------------------------------------------
+  // 异常流
+  // -------------------------------------------------------------------------
+
+  test('[S497-E 异常·生成] 缺 targetType → 拒绝(实测 code=500「服务器内部错误」,非 400;不造绿)', async ({ request }) => {
+    const r = await apiPost(request, '/api/share/create', { targetId: userA.userId }, userA.token);
+    expect(r.code, '缺 targetType → 非成功, 实际=' + r.code).not.toBe(200);
+    expect(r.data, '无分享链接返回').toBeNull();
+    // 真实契约取证:NPE → GlobalExceptionHandler code=500
+    expect(r.code, '实测 code=500 服务器内部错误(缺陷:非 400 参数校验)').toBe(500);
+    expect(r.message, '服务器内部错误').toBe('服务器内部错误');
+  });
+
+  test('[S497-E 异常·生成] 缺 targetId / targetId<=0 → code=500「无权分享该内容」不落库', async ({ request }) => {
+    // 缺 targetId
+    let r = await apiPost(request, '/api/share/create', { targetType: 'member' }, userA.token);
+    expect(r.code, '缺 targetId → 500, 实际=' + r.code).toBe(500);
+    expect(r.message).toBe('无权分享该内容');
+    expect(r.data).toBeNull();
+    // targetId=0
+    r = await apiPost(request, '/api/share/create', { targetType: 'member', targetId: 0 }, userA.token);
+    expect(r.code, 'targetId=0 → 500').toBe(500);
+    expect(r.message).toBe('无权分享该内容');
+    // targetId<0
+    r = await apiPost(request, '/api/share/create', { targetType: 'member', targetId: -5 }, userA.token);
+    expect(r.code, 'targetId<0 → 500').toBe(500);
+    expect(r.message).toBe('无权分享该内容');
+  });
+
+  test('[S497-E 异常·阅读] 缺 shareEventId / 不存在 shareEventId → 200 rewarded=false(不落库,不 500)', async ({ request }) => {
+    // 缺 shareEventId
+    let r = await apiPost(request, '/api/share/read', { duration: 1 }, userA.token);
+    expect(r.code, '缺 id → 200').toBe(200);
+    expect(r.data && r.data.rewarded, 'rewarded=false').toBe(false);
+    // 不存在 shareEventId
+    r = await apiPost(request, '/api/share/read', { shareEventId: 99999999, duration: 1 }, userA.token);
+    expect(r.code, 'bad id → 200').toBe(200);
+    expect(r.data && r.data.rewarded, 'rewarded=false').toBe(false);
+  });
+
+  test('[S497-E 异常·阅读] duration 非数字 → code=400 拒绝(不落库)', async ({ request }) => {
+    const c = await apiPost(request, '/api/share/create', { targetType: 'article', targetId: 555, title: 'x' }, userA.token);
+    expect(c.code).toBe(200);
+    const shareEventId = c.data && c.data.id;
+    const r = await apiPost(request, '/api/share/read', { shareEventId, duration: 'abc' }, userA.token);
+    expect(r.code, 'duration 非数字 → 400, 实际=' + r.code).toBe(400);
+    expect(r.data).toBeNull();
+  });
+
+  // -------------------------------------------------------------------------
+  // 权限流(严格契约 + 承袭·真实缺陷未修登记)
+  // -------------------------------------------------------------------------
+
+  test('[S497-P 权限·匿名401] 匿名 create → 401「请先登录」(严格契约;实测非401 → G-304-1 承袭判红)', async ({ request }) => {
+    const res = await request.post('/api/share/create', { data: { targetType: 'article', targetId: 1 }, timeout: 30000 });
+    const body = await res.json().catch(() => ({}));
+    // 任务要求匿名 401;实测 http=200 code=500「无权分享该内容」(userId=-1 放行到业务层)。
+    // /api/share/create 不在 JwtInterceptor.LOGIN_REQUIRED_PATHS。不造绿:保持严格断言,判红登记。
+    expect(res.status(), '【承袭·真实缺陷未修|G-304-1】anon create→401, 实际 http=' + res.status()).toBe(401);
+    expect(body.code, 'body.code=401').toBe(401);
+    expect(body.message, '请先登录').toBe('请先登录');
+  });
+
+  test('[S497-P 权限·匿名401] 匿名 read → 401「请先登录」(严格契约;实测非401 → G-304-1 承袭判红)', async ({ request }) => {
+    const res = await request.post('/api/share/read', { data: { shareEventId: 1, duration: 1 }, timeout: 30000 });
+    const body = await res.json().catch(() => ({}));
+    // 任务要求匿名 401;实测 http=200 code=200 rewarded=false。/api/share/read 不在 LOGIN_REQUIRED_PATHS。
+    expect(res.status(), '【承袭·真实缺陷未修|G-304-1】anon read→401, 实际 http=' + res.status()).toBe(401);
+    expect(body.code, 'body.code=401').toBe(401);
+    expect(body.message, '请先登录').toBe('请先登录');
+  });
+
+  test('[S497-P 权限·匿名401] 匿名 my → 401「请先登录」(严格契约;实测非401 → G-304-1 承袭判红)', async ({ request }) => {
+    const res = await request.post('/api/share/my', { data: {}, timeout: 30000 });
+    const body = await res.json().catch(() => ({}));
+    expect(res.status(), '【承袭·真实缺陷未修|G-304-1】anon my→401, 实际 http=' + res.status()).toBe(401);
+    expect(body.code, 'body.code=401').toBe(401);
+  });
+
+  test('[S497-P 权限·越权分享] 跨用户对他人 target 生成分享 → 被拒(严格契约;G-304-1 实测未拒 → 承袭判红)', async ({ request }) => {
+    // B(跨家庭、非 A 授权) 对 A 的 member target 发起分享
+    const r = await apiPost(request, '/api/share/create', {
+      targetType: 'member', targetId: userA.userId, shareChannel: 'wechat', title: 'B->A 越权',
+    }, userB.token);
+    // 严格契约:越权分享被拒、不落库、不返回分享链接(S-cfc-497 自述 + TC-P-84-P)。
+    // 实测:B 为自建家庭 admin → canViewMemberReports(B,...,B自己family)=true → code=200 SUCCESS。
+    // 不造绿:保持严格断言,判红登记「承袭·真实缺陷未修|G-304-1 跨家庭越权」。
+    expect(r.code, '【承袭·真实缺陷未修|G-304-1】越权分享应被拒, 实际 code=' + r.code + ' msg=' + r.message).not.toBe(200);
+    expect(r.data, '越权不返回分享链接').toBeNull();
+  });
+
+  test('[S497-P 权限·越权阅读] 跨用户阅读他人分享 → 拒绝不落 share_reads 不发放奖励(严格契约;G-304-1 实测未拒 → 承袭判红)', async ({ request }) => {
+    // A 创建分享
+    const c = await apiPost(request, '/api/share/create', { targetType: 'article', targetId: 909090, title: 'A only' }, userA.token);
+    expect(c.code).toBe(200);
+    const shareEventId = c.data && c.data.id;
+    expect(shareEventId).toBeTruthy();
+
+    // A 回读基线 readCount
+    const myBefore = await apiPost(request, '/api/share/my', {}, userA.token);
+    const before = ((myBefore.data || []).find((x) => String(x.id) === String(shareEventId)) || {}).readCount || 0;
+
+    // B 跨用户阅读 A 的 share event(长时长)
+    const r = await apiPost(request, '/api/share/read', { shareEventId, duration: 120 }, userB.token);
+    expect(r.code, 'read http code=200').toBe(200);
+    // 严格契约:越权阅读被拒不落 share_reads、不发放奖励。
+    // 实测:rewarded=true + readCount++。不造绿:保持严格断言,判红登记「承袭·真实缺陷未修|G-304-1 跨用户越权阅读」。
+    expect(r.data && r.data.rewarded, '【承袭·真实缺陷未修|G-304-1】越权阅读不应发放奖励 rewarded=true').toBe(false);
+
+    const myAfter = await apiPost(request, '/api/share/my', {}, userA.token);
+    const after = ((myAfter.data || []).find((x) => String(x.id) === String(shareEventId)) || {}).readCount || 0;
+    expect(after, '【承袭·真实缺陷未修|G-304-1】越权阅读不应 readCount++').toBe(before);
+  });
+});