@tbox.cn/app-module-activity-play 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/INTEGRATION.md +59 -80
  2. package/README.md +10 -2
  3. package/dist/chunk-GDHTMID6.js +185 -0
  4. package/dist/chunk-XIDGKP5D.js +1154 -0
  5. package/dist/client/index.d.ts +2 -0
  6. package/dist/client/index.js +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +38 -10
  9. package/dist/server/index.d.ts +593 -85
  10. package/dist/server/index.js +37 -9
  11. package/package.json +5 -5
  12. package/skills/activity-play/SKILL.md +41 -15
  13. package/src/client/cards/activity-play/ActivityPlayCard.tsx +3 -3
  14. package/src/client/cards/activity-play-prize/ActivityPlayPrizeDetailCard.tsx +44 -0
  15. package/src/client/cards/activity-play-prize/ActivityPlayPrizeListCard.tsx +62 -0
  16. package/src/client/cards/activity-play-prize/index.ts +8 -0
  17. package/src/client/cards/view.ts +6 -3
  18. package/src/client/index.ts +6 -0
  19. package/src/server/cards/activity-play/meta.ts +5 -4
  20. package/src/server/cards/activity-play/samples.ts +43 -18
  21. package/src/server/cards/index.ts +5 -1
  22. package/src/server/errors.ts +9 -28
  23. package/src/server/index.ts +48 -11
  24. package/src/server/ports.ts +4 -25
  25. package/src/server/prizes/ports.ts +35 -0
  26. package/src/server/prizes/query.ts +11 -8
  27. package/src/server/prizes/routes.ts +139 -0
  28. package/src/server/prizes/tools.ts +180 -0
  29. package/src/server/query.ts +47 -28
  30. package/src/server/routes.ts +44 -230
  31. package/src/server/tools.ts +36 -31
  32. package/tbox.module.json +15 -8
  33. package/tests/cards-capture.test.ts +3 -4
  34. package/tests/ports.test.ts +57 -0
  35. package/tests/prizes-routes.test.ts +230 -0
  36. package/tests/prizes-tools.test.ts +216 -0
  37. package/tests/prizes.test.ts +33 -15
  38. package/tests/routes.test.ts +89 -16
  39. package/tests/samples.test.ts +2 -2
  40. package/tests/smoke.test.ts +8 -4
  41. package/tests/tools.test.ts +50 -31
  42. package/dist/chunk-CM4OEPC3.js +0 -689
  43. package/dist/chunk-HUBEOW44.js +0 -98
  44. package/tests/entry.test.ts +0 -458
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import { describe, expect, it, vi } from 'vitest';
17
17
  import type { RequestContext } from '@tbox.cn/app-contracts';
18
+ import type { ServerContext } from '@tbox.cn/app-agent-sdk-server';
18
19
  import { PROVIDER_ERROR_CODES } from '@tbox.cn/app-contracts';
19
20
  import type { ActivityPlayPrizeQueryPort } from '@tbox.cn/app-contracts-mall';
20
21
  import {
@@ -89,6 +90,12 @@ function makePort(opts: Partial<{
89
90
  } as never;
90
91
  }
91
92
 
93
+ /** 供给解析替身 ctx:resolveService 恒返回注入的 Port(记录调用——零解析断言锚点) */
94
+ function ctxOf(port: unknown): { ctx: ServerContext; resolveService: ReturnType<typeof vi.fn> } {
95
+ const resolveService = vi.fn(async () => port);
96
+ return { ctx: { integrations: { resolveService } } as unknown as ServerContext, resolveService };
97
+ }
98
+
92
99
  // ===== 主体纪律(任务06 约定) =====
93
100
 
94
101
  describe('requirePrizeSubjectId(严格主体检查)', () => {
@@ -125,7 +132,7 @@ describe('queryMyPrizeList / queryMyPrizeDetail', () => {
125
132
  it('缺商圈 → SCOPE_REQUIRED(400)', async () => {
126
133
  const port = makePort();
127
134
  const noMallCtx = reqCtxOf({ userId: '2088000000000001', source: 'local' });
128
- await expect(queryMyPrizeList(noMallCtx, port)).rejects.toMatchObject({
135
+ await expect(queryMyPrizeList(noMallCtx, ctxOf(port).ctx)).rejects.toMatchObject({
129
136
  code: 'SCOPE_REQUIRED',
130
137
  httpStatus: 400,
131
138
  });
@@ -137,27 +144,31 @@ describe('queryMyPrizeList / queryMyPrizeDetail', () => {
137
144
  reqCtxOf({ userId: 'u1', source: 'anonymous' }, 'mall-a'),
138
145
  ]) {
139
146
  const listPort = makePort();
140
- await expect(queryMyPrizeList(bad, listPort)).rejects.toMatchObject({
147
+ const listResolution = ctxOf(listPort);
148
+ await expect(queryMyPrizeList(bad, listResolution.ctx)).rejects.toMatchObject({
141
149
  code: 'LOGIN_REQUIRED',
142
150
  httpStatus: 401,
143
151
  });
144
152
  expect(listPort.listMyPrizes).not.toHaveBeenCalled();
153
+ expect(listResolution.resolveService).not.toHaveBeenCalled(); // 零供给解析接触(先于 registry)
145
154
 
146
155
  const detailPort = makePort();
147
- await expect(queryMyPrizeDetail(bad, detailPort, 'prize-demo-001')).rejects.toMatchObject({
156
+ const detailResolution = ctxOf(detailPort);
157
+ await expect(queryMyPrizeDetail(bad, detailResolution.ctx, 'prize-demo-001')).rejects.toMatchObject({
148
158
  code: 'LOGIN_REQUIRED',
149
159
  });
150
160
  expect(detailPort.getMyPrizeDetail).not.toHaveBeenCalled();
161
+ expect(detailResolution.resolveService).not.toHaveBeenCalled();
151
162
  }
152
163
  });
153
164
 
154
165
  it('连续与并发 A/B 用户不串主体:Port 收到的 subjectId 逐次对应', async () => {
155
166
  const port = makePort({ listResult: { total: 0, items: [] } });
156
- await queryMyPrizeList(localCtx('mall-a', 'user-A'), port);
157
- await queryMyPrizeList(localCtx('mall-a', 'user-B'), port);
167
+ await queryMyPrizeList(localCtx('mall-a', 'user-A'), ctxOf(port).ctx);
168
+ await queryMyPrizeList(localCtx('mall-a', 'user-B'), ctxOf(port).ctx);
158
169
  await Promise.all([
159
- queryMyPrizeList(localCtx('mall-a', 'user-A'), port),
160
- queryMyPrizeList(localCtx('mall-a', 'user-B'), port),
170
+ queryMyPrizeList(localCtx('mall-a', 'user-A'), ctxOf(port).ctx),
171
+ queryMyPrizeList(localCtx('mall-a', 'user-B'), ctxOf(port).ctx),
161
172
  ]);
162
173
  const subjects = port.listMyPrizes.mock.calls.map(([q]) => (q as { subjectId: string }).subjectId);
163
174
  expect(subjects).toEqual(['user-A', 'user-B', 'user-A', 'user-B']);
@@ -173,16 +184,23 @@ describe('queryMyPrizeList / queryMyPrizeDetail', () => {
173
184
  it('prizeRecordRef 原样定位:001 / 1.20 / 1e3 不数字化过 Port;首尾空白是标识原值不 trim 改写', async () => {
174
185
  for (const ref of ['001', '1.20', '1e3', ' record-001 ']) {
175
186
  const port = makePort({ detailResult: { ...DETAIL, prizeRecordRef: ref } });
176
- const detail = await queryMyPrizeDetail(localCtx(), port, ref);
187
+ const detail = await queryMyPrizeDetail(localCtx(), ctxOf(port).ctx, ref);
177
188
  expect(detail.prizeRecordRef).toBe(ref);
178
189
  expect(port.getMyPrizeDetail).toHaveBeenCalledWith(expect.anything(), ref);
179
190
  }
180
191
  });
181
192
 
193
+ it('『.』『..』整值原样达 Port(拒绝防线归 provider 纵深——模块不改判 400/404 混淆语义)', async () => {
194
+ const port = makePort({ detailResult: { ...DETAIL, prizeRecordRef: '.' } });
195
+ const detail = await queryMyPrizeDetail(localCtx(), ctxOf(port).ctx, '.');
196
+ expect(detail.prizeRecordRef).toBe('.');
197
+ expect(port.getMyPrizeDetail).toHaveBeenCalledWith(expect.anything(), '.');
198
+ });
199
+
182
200
  it('ref 非法(全空白/超长)→ INVALID_REQUEST 且零供给调用;非全空白原值直传(trim 只判空白不改写)', async () => {
183
201
  for (const bad of ['', ' ', '\t', 'x'.repeat(129)]) {
184
202
  const port = makePort();
185
- await expect(queryMyPrizeDetail(localCtx(), port, bad)).rejects.toMatchObject({
203
+ await expect(queryMyPrizeDetail(localCtx(), ctxOf(port).ctx, bad)).rejects.toMatchObject({
186
204
  code: 'INVALID_REQUEST',
187
205
  httpStatus: 400,
188
206
  });
@@ -201,7 +219,7 @@ describe('queryMyPrizeList / queryMyPrizeDetail', () => {
201
219
  { total: 1, items: [{ ...RECORD, prizeType: 7 }] },
202
220
  ]) {
203
221
  const port: unknown = makePort({ listResult: bad });
204
- await expect(queryMyPrizeList(localCtx(), port as ActivityPlayPrizeQueryPort)).rejects.toMatchObject({
222
+ await expect(queryMyPrizeList(localCtx(), ctxOf(port).ctx)).rejects.toMatchObject({
205
223
  code: 'PROVIDER_ERROR',
206
224
  httpStatus: 502,
207
225
  });
@@ -210,7 +228,7 @@ describe('queryMyPrizeList / queryMyPrizeDetail', () => {
210
228
 
211
229
  it('详情 null → PRIZE_NOT_FOUND(404)(不存在与不可见同文案)', async () => {
212
230
  const port = makePort({ detailResult: null });
213
- await expect(queryMyPrizeDetail(localCtx(), port, 'prize-demo-001')).rejects.toMatchObject({
231
+ await expect(queryMyPrizeDetail(localCtx(), ctxOf(port).ctx, 'prize-demo-001')).rejects.toMatchObject({
214
232
  code: 'PRIZE_NOT_FOUND',
215
233
  httpStatus: 404,
216
234
  });
@@ -218,7 +236,7 @@ describe('queryMyPrizeList / queryMyPrizeDetail', () => {
218
236
 
219
237
  it('供给返回另一记录标识 → PROVIDER_ERROR(不得以请求标识包装输出)', async () => {
220
238
  const port = makePort({ detailResult: { ...DETAIL, prizeRecordRef: 'prize-other-002' } });
221
- await expect(queryMyPrizeDetail(localCtx(), port, 'prize-demo-001')).rejects.toMatchObject({
239
+ await expect(queryMyPrizeDetail(localCtx(), ctxOf(port).ctx, 'prize-demo-001')).rejects.toMatchObject({
222
240
  code: 'PROVIDER_ERROR',
223
241
  });
224
242
  });
@@ -230,12 +248,12 @@ describe('queryMyPrizeList / queryMyPrizeDetail', () => {
230
248
  listMyPrizes: vi.fn(async () => ({ total: 1, items: [{ ...RECORD, prizeRecordRef: spacedRef }] })),
231
249
  getMyPrizeDetail: vi.fn(async (_q: unknown, ref: string) => ({ ...DETAIL, prizeRecordRef: ref })),
232
250
  };
233
- const list = await queryMyPrizeList(localCtx(), port);
251
+ const list = await queryMyPrizeList(localCtx(), ctxOf(port).ctx);
234
252
  const card = toPrizeListCardData({ mallId: 'mall-a', result: list });
235
253
  const refFromCard = card.items[0]!.prizeRecordRef;
236
254
  expect(refFromCard).toBe(spacedRef);
237
255
 
238
- const detail = await queryMyPrizeDetail(localCtx(), port, refFromCard);
256
+ const detail = await queryMyPrizeDetail(localCtx(), ctxOf(port).ctx, refFromCard);
239
257
  expect(detail.prizeRecordRef).toBe(spacedRef);
240
258
  expect(port.getMyPrizeDetail).toHaveBeenCalledWith(expect.anything(), spacedRef);
241
259
  });
@@ -243,7 +261,7 @@ describe('queryMyPrizeList / queryMyPrizeDetail', () => {
243
261
  it('供给结构非法(详情缺必填/未知键)→ PROVIDER_ERROR', async () => {
244
262
  for (const bad of [{ ...DETAIL, claimStatus: '' }, { ...DETAIL, extra: 1 }]) {
245
263
  const port = makePort({ detailResult: bad });
246
- await expect(queryMyPrizeDetail(localCtx(), port, 'prize-demo-001')).rejects.toMatchObject({
264
+ await expect(queryMyPrizeDetail(localCtx(), ctxOf(port).ctx, 'prize-demo-001')).rejects.toMatchObject({
247
265
  code: 'PROVIDER_ERROR',
248
266
  });
249
267
  }
@@ -16,6 +16,7 @@ import {
16
16
  type ActivityPlayQueryPort,
17
17
  } from '@tbox.cn/app-contracts-mall';
18
18
  import { createActivityPlayRouter } from '../src/server/routes';
19
+ import { normalizeActivityId } from '../src/server/query';
19
20
 
20
21
  /** 会话基础上下文(登录态 guest——等同浏览器轴 guest 登录产物) */
21
22
  const baseReqCtx = (): RequestContext => ({
@@ -25,22 +26,26 @@ const baseReqCtx = (): RequestContext => ({
25
26
  interface PortCall {
26
27
  q: ActivityPlayQueryContext;
27
28
  input?: { keyword?: string; limit?: number };
28
- activityRef?: string;
29
+ activityId?: string;
29
30
  }
30
31
 
31
- /** 可观测 Port 替身(记录调用 + 可配置返回/抛错) */
32
+ /** 可观测 Port 替身(记录调用 + 可配置返回/抛错)——自定义 handler 经包装后调用面
33
+ * 仍被捕获(「Port 收到什么入参」是原字符串语义回归的断言主体,不能因自定义而失明) */
32
34
  function makePort(overrides: Partial<ActivityPlayQueryPort> = {}) {
33
35
  const calls: PortCall[] = [];
36
+ const defaults: ActivityPlayQueryPort = {
37
+ async listActivities() { return { items: [] }; },
38
+ async getActivity() { return null; },
39
+ };
34
40
  const port: ActivityPlayQueryPort = {
35
41
  async listActivities(q, input) {
36
42
  calls.push({ q, input });
37
- return { items: [] };
43
+ return (overrides.listActivities ?? defaults.listActivities)(q, input);
38
44
  },
39
- async getActivity(q, activityRef) {
40
- calls.push({ q, activityRef });
41
- return null;
45
+ async getActivity(q, activityId) {
46
+ calls.push({ q, activityId });
47
+ return (overrides.getActivity ?? defaults.getActivity)(q, activityId);
42
48
  },
43
- ...overrides,
44
49
  };
45
50
  return { port, calls };
46
51
  }
@@ -52,7 +57,7 @@ interface Harness {
52
57
  }
53
58
 
54
59
  /** 装配被测 App:auth 形中间件写入 reqCtx → 挂模块 Router(stub ctx)。
55
- * 缺省 port = 可观测替身(空目录);自定义 port 时 calls 不记录(相应用例不校验调用面)。 */
60
+ * 缺省 port = 可观测替身(空目录);自定义 port 的调用面同样被 makePort 包装捕获。 */
56
61
  function makeApp(opts: {
57
62
  reqCtx: RequestContext | undefined;
58
63
  port?: ActivityPlayQueryPort;
@@ -77,10 +82,9 @@ function makeApp(opts: {
77
82
  }
78
83
 
79
84
  const ITEM = {
80
- activityRef: 'demo:wheel',
85
+ activityId: 'demo:wheel',
81
86
  title: '幸运转盘',
82
87
  status: 'active',
83
- loginRequired: false,
84
88
  } as const;
85
89
 
86
90
  describe('GET /api/m/activity-play/activities(列表)', () => {
@@ -216,19 +220,51 @@ describe('GET /api/m/activity-play/activities(列表)', () => {
216
220
  });
217
221
  });
218
222
 
219
- describe('GET /api/m/activity-play/activities/:activityRef(详情)', () => {
223
+ describe('GET /api/m/activity-play/activities/:activityId(详情)', () => {
220
224
  it('评审返修回归:数字/布尔形态合法字面量引用 200(原始字串——HTTP/工具同参同果)', async () => {
221
225
  const refs = ['1.2', 'true'];
222
- const { port } = makePort({ async getActivity(_q, ref) { return { ...ITEM, activityRef: ref }; } });
226
+ const { port } = makePort({ async getActivity(_q, ref) { return { ...ITEM, activityId: ref }; } });
223
227
  const h = makeApp({ reqCtx: baseReqCtx(), port });
224
228
  for (const ref of refs) {
225
229
  const res = await request(h.app).get(`/activities/${ref}?mallId=mall-a`);
226
230
  expect(res.status, ref).toBe(200);
227
- expect(res.body.data.activityRef).toBe(ref);
231
+ expect(res.body.data.activityId).toBe(ref);
228
232
  }
229
233
  });
230
234
 
231
- it('命中:返回 {"data":活动对象};activityRef 原样透传(含冒号)', async () => {
235
+ it('P2 返修回归:标识原值直传(列表返回 " record-001 " → 详情原样命中——trim 改写=404 串答)', async () => {
236
+ const SPACED = { activityId: ' record-001 ', title: '原值活动', status: 'active' } as const;
237
+ const { port, calls } = makePort({
238
+ async listActivities() { return { items: [SPACED] }; },
239
+ async getActivity(_q, id) { return id === ' record-001 ' ? SPACED : null; },
240
+ });
241
+ const h = makeApp({ reqCtx: baseReqCtx(), port });
242
+ const list = await request(h.app).get('/activities?mallId=mall-a');
243
+ expect(list.status).toBe(200);
244
+ expect(list.body.data.items[0].activityId).toBe(' record-001 ');
245
+ // %20 原样编码进路径;Port 收到原值(非 trim 后 'record-001')
246
+ const res = await request(h.app).get('/activities/%20record-001%20?mallId=mall-a');
247
+ expect(res.status).toBe(200);
248
+ expect(res.body.data.activityId).toBe(' record-001 ');
249
+ expect(calls.at(-1)?.activityId).toBe(' record-001 ');
250
+ });
251
+
252
+ it('P2 返修回归:『.』『..』路径标识防线(contract 拒 + handler 单元拒;HTTP 客户端边界如实记录)', async () => {
253
+ // dot 段防线三面:①契约 activityPlayIdSchema 拒(contracts-mall 域测试);②模块
254
+ // normalizeActivityId 直拒(handler 入口——若有形态抵达即 400);③provider adapter
255
+ // 构造请求前纵深拒(provider-hupo 测试:transport 零 dot 请求)。
256
+ // HTTP 用例侧如实:supertest/superagent 在客户端就把点段规范化(%2E 与 . 同样
257
+ // 落列表路由 200)——客户端边界不等价「dot 可送达 handler」;此处断言单元入口
258
+ // 行为(原字符串语义的回归主体在 handler/Port 层)。
259
+ for (const dot of ['.', '..']) {
260
+ expect(() => normalizeActivityId(dot), dot).toThrow();
261
+ }
262
+ const h = makeApp({ reqCtx: baseReqCtx() });
263
+ const res = await request(h.app).get('/activities/%2E?mallId=mall-a');
264
+ expect([200, 400]).toContain(res.status); // 客户端规范化或契约拒——不允许 5xx/404 串答
265
+ });
266
+
267
+ it('命中:返回 {"data":活动对象};activityId 原样透传(含冒号)', async () => {
232
268
  const { port } = makePort({ async getActivity() { return { ...ITEM }; } });
233
269
  const h = makeApp({ reqCtx: baseReqCtx(), port });
234
270
  const res = await request(h.app).get('/activities/demo:wheel?mallId=mall-a');
@@ -243,9 +279,10 @@ describe('GET /api/m/activity-play/activities/:activityRef(详情)', () => {
243
279
  expect(res.body.error.code).toBe('ACTIVITY_NOT_FOUND');
244
280
  });
245
281
 
246
- it('畸形 activityRef → 400 INVALID_REQUEST;商圈规则与列表一致', async () => {
282
+ it('畸形 activityId → 400 INVALID_REQUEST;商圈规则与列表一致', async () => {
247
283
  const h = makeApp({ reqCtx: baseReqCtx() });
248
- expect((await request(h.app).get('/activities/%20?mallId=mall-a')).status).toBe(400);
284
+ // %20 单空格标识:按原字符串语义合法(空间非路径段破坏符)——原值透传,上游不存在 → 404
285
+ expect((await request(h.app).get('/activities/%20?mallId=mall-a')).status).toBe(404);
249
286
  expect((await request(h.app).get('/activities/demo:wheel')).status).toBe(400);
250
287
  expect((await request(h.app).get('/activities/demo:wheel?mallId=')).status).toBe(400);
251
288
  });
@@ -253,6 +290,42 @@ describe('GET /api/m/activity-play/activities/:activityRef(详情)', () => {
253
290
  beforeEach(() => { vi.clearAllMocks(); });
254
291
  });
255
292
 
293
+ describe('远端活动改造回归(no-store × entry 退场)', () => {
294
+ it('成功响应恒 no-store(列表与详情——远端事实不落缓存)', async () => {
295
+ const { port } = makePort({ async listActivities() { return { items: [ITEM] }; }, async getActivity() { return ITEM; } });
296
+ const h = makeApp({ reqCtx: baseReqCtx(), port });
297
+ const list = await request(h.app).get('/activities?mallId=mall-a');
298
+ expect(list.status).toBe(200);
299
+ expect(list.headers['cache-control']).toBe('no-store');
300
+ const detail = await request(h.app).get('/activities/demo:wheel?mallId=mall-a');
301
+ expect(detail.status).toBe(200);
302
+ expect(detail.headers['cache-control']).toBe('no-store');
303
+ });
304
+
305
+ it('业务错误响应恒 no-store(404/502/400 抽查)', async () => {
306
+ const h = makeApp({ reqCtx: baseReqCtx() });
307
+ expect((await request(h.app).get('/activities/demo:none?mallId=mall-a')).headers['cache-control']).toBe('no-store');
308
+ expect((await request(h.app).get('/activities?mallId=mall-a&limit=0')).headers['cache-control']).toBe('no-store');
309
+ const h2 = makeApp({ reqCtx: baseReqCtx(), resolveError: new Error('boom') });
310
+ expect((await request(h2.app).get('/activities?mallId=mall-a')).headers['cache-control']).toBe('no-store');
311
+ });
312
+
313
+ it('供给对象带旧字段残留(loginRequired/activityRef)→ 502 PROVIDER_ERROR(出站契约同门拦截)', async () => {
314
+ const badItem = { ...ITEM, loginRequired: false };
315
+ const { port } = makePort({ async listActivities() { return { items: [badItem] }; } });
316
+ const h = makeApp({ reqCtx: baseReqCtx(), port });
317
+ const res = await request(h.app).get('/activities?mallId=mall-a');
318
+ expect(res.status).toBe(502);
319
+ expect(res.body.error.code).toBe('PROVIDER_ERROR');
320
+ });
321
+
322
+ it('POST entry 路由已退场(R3):参与前检查接口不存在——路由 miss 显性 404', async () => {
323
+ const h = makeApp({ reqCtx: baseReqCtx() });
324
+ const res = await request(h.app).post('/activities/demo:wheel/entry?mallId=mall-a').send({});
325
+ expect(res.status).toBe(404); // express 路由表无该 POST 路径(非业务信封)
326
+ });
327
+ });
328
+
256
329
  describe('错误信封与调用面', () => {
257
330
  it('统一错误信封 {"error":{"code","message"}}(三面抽查)', async () => {
258
331
  const h = makeApp({ reqCtx: baseReqCtx() });
@@ -23,7 +23,7 @@ describe('activity-play 样本即契约(T02-05)', () => {
23
23
  }
24
24
  });
25
25
 
26
- it('覆盖维度在场:list(含空态)+ detail;四种状态全覆盖', () => {
26
+ it('覆盖维度在场:list(含空态)+ detail;四种已知状态与 unknown 全覆盖(R-02)', () => {
27
27
  expect(sampledModes.has('list')).toBe(true);
28
28
  expect(sampledModes.has('detail')).toBe(true);
29
29
  const listEmpty = (meta.samples ?? []).some(
@@ -31,7 +31,7 @@ describe('activity-play 样本即契约(T02-05)', () => {
31
31
  && (s.data as { items: unknown[] }).items.length === 0,
32
32
  );
33
33
  expect(listEmpty).toBe(true);
34
- for (const status of ['not_started', 'active', 'ended', 'disabled']) {
34
+ for (const status of ['not_started', 'active', 'ended', 'disabled', 'unknown']) {
35
35
  expect(sampledStatuses.has(status), `样本缺状态 ${status}`).toBe(true);
36
36
  }
37
37
  });
@@ -6,8 +6,8 @@ describe('module-activity-play 模块形态(铁律冒烟)', () => {
6
6
  it('双端描述对象在场且自洽(satisfies ServerModule/ClientModule 编译期锁)', () => {
7
7
  expect(serverModule).toBeTruthy();
8
8
  expect(clientModule).toBeTruthy();
9
- // 2026-11-16 起含授权占位 renderer(单卡型与 server 侧对齐——铁律 cards key = meta.cardType)
10
- expect(Object.keys(clientModule.cards)).toEqual(['activity-play']);
9
+ // 2026-11-16 起含授权占位 renderer;2026-11-18 起含奖品两卡占位(与 server 侧对齐——铁律 cards key = meta.cardType)
10
+ expect(Object.keys(clientModule.cards)).toEqual(['activity-play', 'activity-play-prize-list', 'activity-play-prize-detail']);
11
11
  });
12
12
 
13
13
  it('cards key 约定 = meta.cardType(key 恒等于 meta.cardType——铁律位)', () => {
@@ -16,8 +16,12 @@ describe('module-activity-play 模块形态(铁律冒烟)', () => {
16
16
  }
17
17
  });
18
18
 
19
- it('出卡卡型唯一(activity-play——mode 承载列表/详情,不拆多卡型)', () => {
20
- expect(Object.keys(serverModule.cards)).toEqual(['activity-play']);
19
+ it('卡型面 = 活动单卡型 + 奖品两张独立卡型(activity-play mode 承载列表/详情;奖品按 api.md 独立卡型)', () => {
20
+ expect(Object.keys(serverModule.cards)).toEqual([
21
+ 'activity-play',
22
+ 'activity-play-prize-list',
23
+ 'activity-play-prize-detail',
24
+ ]);
21
25
  });
22
26
 
23
27
  it('本地技能声明接线(skills map 键 = skill 名,前置 name=activity-play)', () => {
@@ -29,18 +29,16 @@ const reqCtxOf = (mallId: string, userId = 'guest_1'): RequestContext => ({
29
29
  });
30
30
 
31
31
  const ITEM = {
32
- activityRef: 'demo:wheel',
32
+ activityId: 'demo:wheel',
33
33
  title: '幸运大转盘',
34
34
  description: '进入活动页面查看参与规则',
35
35
  status: 'active' as const,
36
- loginRequired: false,
37
36
  };
38
37
  const ITEM_B = {
39
- activityRef: 'demo:checkin',
38
+ activityId: 'demo:checkin',
40
39
  title: '签到有礼',
41
40
  startsAt: '2027-01-01T00:00:00+08:00',
42
41
  status: 'not_started' as const,
43
- loginRequired: true,
44
42
  };
45
43
 
46
44
  function makeTools(port: unknown) {
@@ -55,7 +53,7 @@ const listPort = (items: readonly unknown[]) => ({
55
53
  lastListCall = { q, input };
56
54
  return { items: (items as never[]) };
57
55
  }),
58
- getActivity: vi.fn(async (_q: unknown, ref: string) => (items as never[]).find((i: { activityRef?: string }) => i.activityRef === ref) ?? null),
56
+ getActivity: vi.fn(async (_q: unknown, ref: string) => (items as never[]).find((i: { activityId?: string }) => i.activityId === ref) ?? null),
59
57
  });
60
58
  let lastListCall: { q: unknown; input: { keyword?: string; limit?: number } } | undefined;
61
59
 
@@ -65,7 +63,7 @@ describe('listActivityPlays', () => {
65
63
  const result = await tools.listActivityPlays.execute!({}, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
66
64
  expect(result['found']).toBe(true);
67
65
  expect(result['count']).toBe(2);
68
- expect((result['items'] as Array<{ activityRef: string }>).map((i) => i.activityRef)).toEqual(['demo:wheel', 'demo:checkin']);
66
+ expect((result['items'] as Array<{ activityId: string }>).map((i) => i.activityId)).toEqual(['demo:wheel', 'demo:checkin']);
69
67
  const cards = result['cards'] as Array<{ cardType: string; data: unknown; note: string }>;
70
68
  expect(cards).toHaveLength(1);
71
69
  expect(cards[0]?.cardType).toBe(ACTIVITY_PLAY_CARD_TYPE);
@@ -118,7 +116,7 @@ describe('listActivityPlays', () => {
118
116
  const empty = await tools.listActivityPlays.execute!({}, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
119
117
  expect(empty['found']).toBe(false);
120
118
  expect(empty['count']).toBe(0);
121
- expect(empty['noResultsReason']).toContain('暂未登记');
119
+ expect(empty['noResultsReason']).toContain('暂无活动玩法');
122
120
  expect(empty['cards']).toBeUndefined();
123
121
 
124
122
  const kw = await tools.listActivityPlays.execute!({ keyword: '不存在的活动' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
@@ -172,9 +170,9 @@ describe('listActivityPlays', () => {
172
170
  describe('getActivityPlayDetail', () => {
173
171
  it('命中:一张 mode=detail 卡(items 恰一);facts 含状态/时间/说明', async () => {
174
172
  const tools = makeTools(listPort([ITEM, ITEM_B]));
175
- const result = await tools.getActivityPlayDetail.execute!({ activityRef: 'demo:checkin' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
173
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: 'demo:checkin' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
176
174
  expect(result['found']).toBe(true);
177
- expect(result['activityRef']).toBe('demo:checkin');
175
+ expect(result['activityId']).toBe('demo:checkin');
178
176
  expect(result['statusText']).toBe('未开始');
179
177
  expect((result['items'] as unknown[] | undefined)).toBeUndefined(); // detail = 扁平 facts(非列表嵌套)
180
178
  const cards = result['cards'] as Array<{ cardType: string; data: { mode: string; items: unknown[] } }>;
@@ -186,9 +184,9 @@ describe('getActivityPlayDetail', () => {
186
184
  });
187
185
 
188
186
  it('detail 允许返回 disabled(状态说明用),卡 data 不携带 enabled', async () => {
189
- const disabledItem = { activityRef: 'demo:hidden', title: '停用活动', status: 'disabled' as const, loginRequired: false };
187
+ const disabledItem = { activityId: 'demo:hidden', title: '停用活动', status: 'disabled' as const };
190
188
  const tools = makeTools(listPort([disabledItem]));
191
- const result = await tools.getActivityPlayDetail.execute!({ activityRef: 'demo:hidden' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
189
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: 'demo:hidden' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
192
190
  expect(result['found']).toBe(true);
193
191
  expect(result['statusText']).toBe('已停用');
194
192
  const card = (result['cards'] as Array<{ data: Record<string, unknown> }>)[0];
@@ -198,54 +196,75 @@ describe('getActivityPlayDetail', () => {
198
196
 
199
197
  it('未知引用 → ACTIVITY_NOT_FOUND 失败事实,无 cards(不猜首项/不造演示详情)', async () => {
200
198
  const tools = makeTools(listPort([ITEM]));
201
- const result = await tools.getActivityPlayDetail.execute!({ activityRef: 'demo:none' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
199
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: 'demo:none' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
202
200
  expect(result['found']).toBe(false);
203
201
  expect(result['errorCode']).toBe('ACTIVITY_NOT_FOUND');
204
202
  expect(result['cards']).toBeUndefined();
205
203
  });
206
204
 
207
- it('非法 activityRef → INVALID_REQUEST(契约引用形状单源)', async () => {
205
+ it('非法 activityId → INVALID_REQUEST(契约引用形状单源;纯空白合法原样透传→未命中)', async () => {
208
206
  const tools = makeTools(listPort([ITEM]));
209
- for (const bad of ['', ' ', 'bad ref!', 'x'.repeat(129)]) {
210
- const result = await tools.getActivityPlayDetail.execute!({ activityRef: bad }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
207
+ for (const bad of ['', 'a/b', 'a?b', 'a%b', 'a#b', 'x'.repeat(129), '.', '..']) {
208
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: bad }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
211
209
  expect(result['errorCode'], JSON.stringify(bad)).toBe('INVALID_REQUEST');
212
210
  expect(result['cards']).toBeUndefined();
213
211
  }
212
+ // ' '(纯空白)=原字符串语义合法字面量(空间非路径段破坏符)——原值透传上游,
213
+ // 不存在 → ACTIVITY_NOT_FOUND(与『不改写』回归同口径;其余控制/破坏符值就地 400)
214
+ const blank = await tools.getActivityPlayDetail.execute!({ activityId: ' ' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
215
+ expect(blank['errorCode']).toBe('ACTIVITY_NOT_FOUND');
214
216
  });
215
217
 
216
218
  it('评审返修回归:数字/布尔形态合法字面量引用(原始字串保留,数字串同型不撞车)', async () => {
217
219
  const weirdRefs = ['1.2', 'true', '0.12345', '42'];
218
- const items = weirdRefs.map((ref) => ({ ...ITEM, activityRef: ref }));
220
+ const items = weirdRefs.map((ref) => ({ ...ITEM, activityId: ref }));
219
221
  const tools = makeTools(listPort(items));
220
222
  for (const ref of weirdRefs) {
221
- const result = await tools.getActivityPlayDetail.execute!({ activityRef: ref }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
222
- expect(result['found'], `activityRef=${ref}`).toBe(true);
223
- expect(result['activityRef']).toBe(ref);
224
- const cards = result['cards'] as Array<{ data: { items: Array<{ activityRef: string }> } }>;
225
- expect(cards[0]?.data.items[0]?.activityRef).toBe(ref); // 卡 data 原样保留字面量
223
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: ref }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
224
+ expect(result['found'], `activityId=${ref}`).toBe(true);
225
+ expect(result['activityId']).toBe(ref);
226
+ const cards = result['cards'] as Array<{ data: { items: Array<{ activityId: string }> } }>;
227
+ expect(cards[0]?.data.items[0]?.activityId).toBe(ref); // 卡 data 原样保留字面量
226
228
  }
227
229
  });
228
230
 
229
231
  it('评审返修二轮:数字同型不同值引用不串答(JSON 转换已移除——1.20 不再折叠成 1.2、1e3 不再折叠成 1000)', async () => {
230
232
  // 目录同时含 1.2/1.20 与 1e3/1000 四个独立活动:每个引用必须精确命中自己
231
233
  const refs = ['1.2', '1.20', '1e3', '1000'];
232
- const items = refs.map((ref) => ({ ...ITEM, activityRef: ref, title: `活动${ref}` }));
234
+ const items = refs.map((ref) => ({ ...ITEM, activityId: ref, title: `活动${ref}` }));
233
235
  const tools = makeTools(listPort(items));
234
236
  for (const ref of refs) {
235
- const result = await tools.getActivityPlayDetail.execute!({ activityRef: ref }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
236
- expect(result['found'], `activityRef=${ref}`).toBe(true);
237
- expect(result['activityRef']).toBe(ref);
237
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: ref }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
238
+ expect(result['found'], `activityId=${ref}`).toBe(true);
239
+ expect(result['activityId']).toBe(ref);
238
240
  expect(result['title']).toBe(`活动${ref}`); // 撞车即串答——此处必须各自命中
239
241
  }
240
242
  });
241
243
 
242
- it('名称→引用不隐式回退:非 ref 形状 = INVALID_REQUEST;合法形状未知 = NOT_FOUND(无首项/演示回退)', async () => {
244
+ it('P2 返修回归:标识原值直传(含前后空格照原样命中供给记录——不 trim 不折叠)', async () => {
245
+ const spaced = { ...ITEM, activityId: ' record-001 ', title: '原值活动' };
246
+ const tools = makeTools(listPort([spaced]));
247
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: ' record-001 ' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
248
+ expect(result['found']).toBe(true);
249
+ expect(result['activityId']).toBe(' record-001 ');
250
+ expect(result['title']).toBe('原值活动');
251
+ });
252
+
253
+ it('P2 返修回归:『.』『..』整值 → INVALID_REQUEST(路径段漂移防线——工具与 HTTP 同门)', async () => {
254
+ const tools = makeTools(listPort([ITEM]));
255
+ for (const dot of ['.', '..']) {
256
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: dot }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
257
+ expect(result['errorCode'], dot).toBe('INVALID_REQUEST');
258
+ }
259
+ });
260
+
261
+ it('ID 边界:超长 = INVALID_REQUEST;空间内未知值 = NOT_FOUND(无首项/演示回退)', async () => {
243
262
  const tools = makeTools(listPort([ITEM]));
244
- // 标题字面量不是 activityRef(形状非法——技能引导模型先查列表拿引用,不猜)
245
- const byTitle = await tools.getActivityPlayDetail.execute!({ activityRef: '幸运大转盘' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
246
- expect(byTitle['errorCode']).toBe('INVALID_REQUEST');
247
- // 形状合法但目录中不存在
248
- const byUnknownRef = await tools.getActivityPlayDetail.execute!({ activityRef: 'demo:none' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
263
+ // 形态边界 = 控制字符/路径段破坏符/超长(含中文标题等一切非破坏符形态均属供应商标识空间)
264
+ const byTitle = await tools.getActivityPlayDetail.execute!({ activityId: '幸运大转盘' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
265
+ expect(byTitle['errorCode']).toBe('ACTIVITY_NOT_FOUND');
266
+ // 形态合法但供给查不到
267
+ const byUnknownRef = await tools.getActivityPlayDetail.execute!({ activityId: 'demo:none' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
249
268
  expect(byUnknownRef['errorCode']).toBe('ACTIVITY_NOT_FOUND');
250
269
  });
251
270
  });