@tbox.cn/app-module-shopping-guide 1.0.0-alpha.15 → 1.0.0-alpha.17
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.
- package/dist/{chunk-43AO3W7C.js → chunk-B3SVEGHZ.js} +102 -42
- package/dist/index.d.ts +3 -2
- package/dist/index.js +5 -1
- package/dist/server/index.d.ts +489 -450
- package/dist/server/index.js +5 -1
- package/package.json +9 -7
- package/skills/shopping-guide/SKILL.md +5 -0
- package/src/server/cards/shop-detail/samples.ts +8 -3
- package/src/server/index.ts +9 -40
- package/src/server/routes.ts +53 -0
- package/src/server/services/indoor-navigation.ts +60 -0
- package/src/server/tools/index.ts +39 -7
- package/tests/indoor-navigation.test.ts +301 -0
- package/tests/shopping-guide.test.ts +34 -2
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 室内导航接入双链路验收(get-shop 工具 + GET /shop-detail HTTP 共用 withIndoorNavigationTarget 单点)。
|
|
3
|
+
* 覆盖风险 ≡ 验收点(docs/plans/indoor-navigation/technical-design.md):
|
|
4
|
+
* - 同一商场/门店 → 两入口 indoorNavigation.url 完全一致,shopDetailCardDataSchema 校验通过;
|
|
5
|
+
* - 两商场各自配置(mallId 查配置隔离);
|
|
6
|
+
* - 降级族:缺商场范围 / 商场未配置 / 服务未注册 / 服务异常 → 省略字段、详情照常返回;
|
|
7
|
+
* - merchantId 原值透传('001' 不归一)。
|
|
8
|
+
* 服务本尊归任务 1(ctx.services 注册表)——本文件以测试实现并行开发;任务 1 交付后接线联跑补真实配置结果。
|
|
9
|
+
*/
|
|
10
|
+
import { describe, expect, it } from 'vitest';
|
|
11
|
+
import express from 'express';
|
|
12
|
+
import type { Express, Request, Response, NextFunction } from 'express';
|
|
13
|
+
import request from 'supertest';
|
|
14
|
+
import {
|
|
15
|
+
createIntegrationsRegistry,
|
|
16
|
+
createAuthStrategyRegistry,
|
|
17
|
+
createEnvironmentSecretProvider,
|
|
18
|
+
createInMemoryStateStore,
|
|
19
|
+
createServerContext,
|
|
20
|
+
createToolExecContext,
|
|
21
|
+
} from '@tbox.cn/app-agent-sdk-server';
|
|
22
|
+
import type { ServerContext } from '@tbox.cn/app-agent-sdk-server';
|
|
23
|
+
import { shopDetailCardDataSchema } from '@tbox.cn/app-contracts-mall';
|
|
24
|
+
import type { RequestContext } from '@tbox.cn/app-contracts';
|
|
25
|
+
import { createShoppingGuideTools } from '../src/server/tools';
|
|
26
|
+
import { createShoppingGuideRouter } from '../src/server/routes';
|
|
27
|
+
import { projectShopDetail } from '../src/server/projections';
|
|
28
|
+
import {
|
|
29
|
+
INDOOR_NAVIGATION_SERVICE,
|
|
30
|
+
type IndoorNavigationService,
|
|
31
|
+
withIndoorNavigationTarget,
|
|
32
|
+
} from '../src/server/services/indoor-navigation';
|
|
33
|
+
|
|
34
|
+
/** 会话上下文:mall scope 注入(attributes 契约键——与 shopping-guide.test.ts 同源) */
|
|
35
|
+
const reqCtxOf = (mallId?: string): RequestContext => ({
|
|
36
|
+
identity: { userId: 'local_u1', source: 'local' },
|
|
37
|
+
...(mallId ? { attributes: { mall: { miniAppId: 'app1', mallId } } } : {}),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
/** 商场范围 mallId='001' 门店——锁原值透传(禁任何归一) */
|
|
41
|
+
const SHOP = {
|
|
42
|
+
merchantId: '001',
|
|
43
|
+
name: '示例奶茶',
|
|
44
|
+
logoUrl: undefined,
|
|
45
|
+
coverUrls: [],
|
|
46
|
+
brand: undefined,
|
|
47
|
+
businessCategories: ['餐饮'],
|
|
48
|
+
location: { displayText: 'A 栋 1 楼 101', buildingName: 'A 栋', floorName: '1 楼', unitName: '101' },
|
|
49
|
+
status: { code: 'enabled' as const, label: '营业中', observedAt: '2026-11-18T00:00:00Z' },
|
|
50
|
+
description: '奶茶饮品店',
|
|
51
|
+
contactInfo: undefined,
|
|
52
|
+
services: [],
|
|
53
|
+
promotionFacts: [],
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const FIXTURE_PROVIDER = 'fixture';
|
|
57
|
+
const FIXTURE_PROVIDER_ID = 'fixture-shopping@1';
|
|
58
|
+
/** mall-1/mall-2 双实例注册(两商场配置隔离验证的解析基础);'*' 通配 = 缺范围请求也解析到
|
|
59
|
+
* 门店 stub(语义聚焦:缺范围时门店查询本身照常成功,仅导航省略——非 404/500 差错态) */
|
|
60
|
+
const SLOT_INSTANCES: Record<string, { enabled: boolean }> = {
|
|
61
|
+
'mall-1': { enabled: true },
|
|
62
|
+
'mall-2': { enabled: true },
|
|
63
|
+
'*': { enabled: true },
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
function buildServer(opts?: { indoor?: IndoorNavigationService }): ServerContext {
|
|
67
|
+
const registry = createIntegrationsRegistry({
|
|
68
|
+
integrations: {
|
|
69
|
+
services: Object.fromEntries(
|
|
70
|
+
['shopping-guide.catalog', 'shopping-guide.shops', 'shopping-guide.categories', 'shopping-guide.directory'].map((service) => [
|
|
71
|
+
service,
|
|
72
|
+
{ provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: SLOT_INSTANCES },
|
|
73
|
+
]),
|
|
74
|
+
),
|
|
75
|
+
},
|
|
76
|
+
catalog: {
|
|
77
|
+
providers: {
|
|
78
|
+
[FIXTURE_PROVIDER]: {
|
|
79
|
+
[FIXTURE_PROVIDER_ID]: {
|
|
80
|
+
provider: FIXTURE_PROVIDER,
|
|
81
|
+
implementation: FIXTURE_PROVIDER_ID,
|
|
82
|
+
credentialType: '-',
|
|
83
|
+
owner: 'fixture',
|
|
84
|
+
services: ['shopping-guide.catalog', 'shopping-guide.shops', 'shopping-guide.categories', 'shopping-guide.directory'],
|
|
85
|
+
local: true,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
services: {},
|
|
90
|
+
credentialTypes: {},
|
|
91
|
+
},
|
|
92
|
+
authStrategies: createAuthStrategyRegistry(),
|
|
93
|
+
secretProvider: createEnvironmentSecretProvider({ source: {}, production: false }),
|
|
94
|
+
instanceIdOf: (scope) => scope.mallId ?? '',
|
|
95
|
+
});
|
|
96
|
+
registry.registerAdapter(FIXTURE_PROVIDER, FIXTURE_PROVIDER_ID, (input) => {
|
|
97
|
+
const ports = {
|
|
98
|
+
catalog: { async searchProducts() { return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false }; }, async getProduct() { return null; }, async getFacets() { return { brands: [], categories: [], priceRanges: [], floors: [] }; } },
|
|
99
|
+
shop: { async searchShops() { return { items: [SHOP], page: 1, pageSize: 10, total: 1, hasMore: false }; }, async getShop() { return SHOP; } },
|
|
100
|
+
category: { async listCategories() { return []; } },
|
|
101
|
+
directory: { async getDirectory() { return null; } },
|
|
102
|
+
};
|
|
103
|
+
const SLOT_KEY_OF: Record<string, keyof typeof ports> = {
|
|
104
|
+
'shopping-guide.catalog': 'catalog',
|
|
105
|
+
'shopping-guide.shops': 'shop',
|
|
106
|
+
'shopping-guide.categories': 'category',
|
|
107
|
+
'shopping-guide.directory': 'directory',
|
|
108
|
+
};
|
|
109
|
+
return ports[SLOT_KEY_OF[input.service] ?? 'directory'];
|
|
110
|
+
});
|
|
111
|
+
const serverCtx = createServerContext({ state: createInMemoryStateStore(), integrations: registry });
|
|
112
|
+
if (opts?.indoor) serverCtx.services.register(INDOOR_NAVIGATION_SERVICE, opts.indoor);
|
|
113
|
+
return serverCtx;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
interface NavCall { mallId: string; merchantId: string }
|
|
117
|
+
|
|
118
|
+
/** 导航服务测试实现(并行开发替身——任务 1 交付后换其注册实现):
|
|
119
|
+
* mallId → 爱笔 H5 基址(未配置商场缺席);生成完整 URL 时追加 third_id=<merchantId>(编码一次)。 */
|
|
120
|
+
function makeIndoorStub(configs: Record<string, string>, overrides?: Partial<IndoorNavigationService>) {
|
|
121
|
+
const calls: NavCall[] = [];
|
|
122
|
+
const service: IndoorNavigationService = {
|
|
123
|
+
async resolveJumpUrl(mallId, merchantId) {
|
|
124
|
+
calls.push({ mallId, merchantId });
|
|
125
|
+
const base = configs[mallId];
|
|
126
|
+
if (!base) return undefined;
|
|
127
|
+
const joiner = base.includes('?') ? '&' : '?';
|
|
128
|
+
return `${base}${joiner}third_id=${encodeURIComponent(merchantId)}`;
|
|
129
|
+
},
|
|
130
|
+
...overrides,
|
|
131
|
+
};
|
|
132
|
+
return { service, calls };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const MALL_1_URL = 'https://indoor-nav.example.cn/mall-1/#/ar_v4?sdk_version=v4';
|
|
136
|
+
const MALL_2_URL = 'https://indoor-nav.example.cn/mall-2/#/ar_v4?sdk_version=v4';
|
|
137
|
+
|
|
138
|
+
/** 工具链 get-shop 结果(shop-detail 卡数据) */
|
|
139
|
+
async function runGetShopTool(serverCtx: ServerContext, mallId: string | undefined) {
|
|
140
|
+
const tools = createShoppingGuideTools({ getCtx: () => serverCtx });
|
|
141
|
+
return (await tools.getShop.execute!({ shopId: '001' }, createToolExecContext(reqCtxOf(mallId)) as never)) as {
|
|
142
|
+
summary: string;
|
|
143
|
+
cards?: { cardType: string; data: unknown }[];
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** HTTP 链 GET /shop-detail 结果 */
|
|
148
|
+
function makeHttpApp(serverCtx: ServerContext, reqCtx: RequestContext | undefined): Express {
|
|
149
|
+
const app = express();
|
|
150
|
+
app.use((req: Request, _res: Response, next: NextFunction) => {
|
|
151
|
+
if (reqCtx) (req as unknown as Record<string, unknown>)['tboxAuthContext'] = reqCtx;
|
|
152
|
+
next();
|
|
153
|
+
});
|
|
154
|
+
app.use(createShoppingGuideRouter(serverCtx));
|
|
155
|
+
return app;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
describe('双链路一致:同一商场/门店 HTTP 与对话出卡返回同一 indoorNavigation.url', () => {
|
|
159
|
+
it('契约三件具名可达(合流防线:运行时出口漏导出时本断言先红)', async () => {
|
|
160
|
+
// 背景:contracts-mall 运行时入口(runtime.ts/dist)是 NAMED 导出面——新常量漏挂时
|
|
161
|
+
// 消费侧 import 得 undefined、register/resolve 两端同键假绿(stage P4.6b 曾拦截)。
|
|
162
|
+
const contracts = await import('@tbox.cn/app-contracts-mall');
|
|
163
|
+
expect(contracts.INDOOR_NAVIGATION_SERVICE).toBe('indoor-navigation');
|
|
164
|
+
expect((await import('../src/server/services/indoor-navigation')).INDOOR_NAVIGATION_SERVICE).toBe('indoor-navigation');
|
|
165
|
+
expect(typeof contracts.indoorNavigationUrlSchema).toBe('object');
|
|
166
|
+
expect(contracts.indoorNavigationUrlSchema.safeParse('https://').success).toBe(false);
|
|
167
|
+
expect(contracts.indoorNavigationUrlSchema.safeParse('https://nav.example.cn/ar?third_id=001').success).toBe(true);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('get-shop 工具:卡数据携带 indoorNavigation.url 且 shopDetailCardDataSchema 通过', async () => {
|
|
171
|
+
const { service } = makeIndoorStub({ 'mall-1': MALL_1_URL });
|
|
172
|
+
const serverCtx = buildServer({ indoor: service });
|
|
173
|
+
const result = await runGetShopTool(serverCtx, 'mall-1');
|
|
174
|
+
expect(result.cards?.[0]?.cardType).toBe('shop-detail');
|
|
175
|
+
const data = result.cards![0]!.data;
|
|
176
|
+
expect(() => shopDetailCardDataSchema.parse(data)).not.toThrow();
|
|
177
|
+
const parsed = shopDetailCardDataSchema.parse(data);
|
|
178
|
+
expect(parsed.indoorNavigation?.url).toBe(`${MALL_1_URL}&third_id=001`);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('HTTP /shop-detail:data.indoorNavigation.url 与工具链完全一致(同一 URL 字符串)', async () => {
|
|
182
|
+
const { service, calls } = makeIndoorStub({ 'mall-1': MALL_1_URL });
|
|
183
|
+
const serverCtx = buildServer({ indoor: service });
|
|
184
|
+
const toolResult = await runGetShopTool(serverCtx, 'mall-1');
|
|
185
|
+
const toolData = shopDetailCardDataSchema.parse(toolResult.cards![0]!.data);
|
|
186
|
+
|
|
187
|
+
const app = makeHttpApp(serverCtx, reqCtxOf('mall-1'));
|
|
188
|
+
const res = await request(app).get('/shop-detail?shopId=001&mallId=mall-1');
|
|
189
|
+
expect(res.status).toBe(200);
|
|
190
|
+
const httpData = shopDetailCardDataSchema.parse(res.body.data);
|
|
191
|
+
expect(httpData.indoorNavigation?.url).toBe(toolData.indoorNavigation?.url);
|
|
192
|
+
expect(httpData.indoorNavigation).toEqual(toolData.indoorNavigation);
|
|
193
|
+
// 商场范围同源:工具经 scope、HTTP 经 query mallId 注入后同达 mall-1
|
|
194
|
+
expect(calls.every((c) => c.mallId === 'mall-1')).toBe(true);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('门店标识原值透传:merchantId "001" 原样达导航服务(无归一/无前缀)', async () => {
|
|
198
|
+
const { service, calls } = makeIndoorStub({ 'mall-1': MALL_1_URL });
|
|
199
|
+
const serverCtx = buildServer({ indoor: service });
|
|
200
|
+
await runGetShopTool(serverCtx, 'mall-1');
|
|
201
|
+
expect(calls).toEqual([{ mallId: 'mall-1', merchantId: '001' }]);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe('两商场各自配置:mallId 查配置隔离', () => {
|
|
206
|
+
it('mall-1/mall-2 → 各自基址生成的不同 URL', async () => {
|
|
207
|
+
const { service, calls } = makeIndoorStub({ 'mall-1': MALL_1_URL, 'mall-2': MALL_2_URL });
|
|
208
|
+
const serverCtx = buildServer({ indoor: service });
|
|
209
|
+
const r1 = shopDetailCardDataSchema.parse((await runGetShopTool(serverCtx, 'mall-1')).cards![0]!.data);
|
|
210
|
+
const r2 = shopDetailCardDataSchema.parse((await runGetShopTool(serverCtx, 'mall-2')).cards![0]!.data);
|
|
211
|
+
expect(r1.indoorNavigation?.url).toBe(`${MALL_1_URL}&third_id=001`);
|
|
212
|
+
expect(r2.indoorNavigation?.url).toBe(`${MALL_2_URL}&third_id=001`);
|
|
213
|
+
expect(calls.map((c) => c.mallId)).toEqual(['mall-1', 'mall-2']);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('未配置商场(任务 1 返回 undefined)→ 省略字段,详情照常返回且 schema 通过', async () => {
|
|
217
|
+
const { service } = makeIndoorStub({ 'mall-1': MALL_1_URL }); // mall-2 未配置
|
|
218
|
+
const serverCtx = buildServer({ indoor: service });
|
|
219
|
+
const result = await runGetShopTool(serverCtx, 'mall-2');
|
|
220
|
+
const parsed = shopDetailCardDataSchema.parse(result.cards![0]!.data);
|
|
221
|
+
expect(parsed.indoorNavigation).toBeUndefined();
|
|
222
|
+
expect(parsed.name).toBe('示例奶茶');
|
|
223
|
+
expect(parsed.merchantId).toBe('001');
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe('降级族:缺范围/未注册/异常 → 省略字段,详情照常', () => {
|
|
228
|
+
it('HTTP 缺商场范围(无 mallId query/属性)→ 200 + 无 indoorNavigation + 不触达导航服务', async () => {
|
|
229
|
+
const { service, calls } = makeIndoorStub({ 'mall-1': MALL_1_URL });
|
|
230
|
+
const serverCtx = buildServer({ indoor: service });
|
|
231
|
+
const app = makeHttpApp(serverCtx, reqCtxOf());
|
|
232
|
+
const res = await request(app).get('/shop-detail?shopId=001');
|
|
233
|
+
expect(res.status).toBe(200);
|
|
234
|
+
const parsed = shopDetailCardDataSchema.parse(res.body.data);
|
|
235
|
+
expect(parsed.indoorNavigation).toBeUndefined();
|
|
236
|
+
expect(parsed.name).toBe('示例奶茶');
|
|
237
|
+
expect(calls).toEqual([]); // 缺范围先于服务调用短路
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('get-shop 工具缺商场范围 → 降级返回门店详情(不再「暂时无法查询」)+ 省略导航字段', async () => {
|
|
241
|
+
const { service, calls } = makeIndoorStub({ 'mall-1': MALL_1_URL });
|
|
242
|
+
const serverCtx = buildServer({ indoor: service });
|
|
243
|
+
// 和 HTTP 缺范围用例同场景:attributes 无 mall scope(fixture '*' 通配让门店查询本身成功,
|
|
244
|
+
// 聚焦锁工具层降级语义——此前 toContext throw → exec 兜底「暂时无法查询」整链失败)
|
|
245
|
+
const result = await runGetShopTool(serverCtx, undefined);
|
|
246
|
+
expect(result.cards?.[0]?.cardType).toBe('shop-detail'); // 原行为:无 cards
|
|
247
|
+
const parsed = shopDetailCardDataSchema.parse(result.cards![0]!.data);
|
|
248
|
+
expect(parsed.indoorNavigation).toBeUndefined();
|
|
249
|
+
expect(parsed.name).toBe('示例奶茶');
|
|
250
|
+
expect(parsed.mallId).toBeUndefined(); // 无范围不透传 mallId
|
|
251
|
+
expect(calls).toEqual([]); // 装饰单点缺范围先短路,不触达服务
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('HTTP 服务未注册 → 200 + 无 indoorNavigation(两级缺席同形)', async () => {
|
|
255
|
+
const serverCtx = buildServer(); // 不注册 indoor-navigation
|
|
256
|
+
const app = makeHttpApp(serverCtx, reqCtxOf('mall-1'));
|
|
257
|
+
const res = await request(app).get('/shop-detail?shopId=001&mallId=mall-1');
|
|
258
|
+
expect(res.status).toBe(200);
|
|
259
|
+
expect(shopDetailCardDataSchema.parse(res.body.data).indoorNavigation).toBeUndefined();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('HTTP 服务异常 → 200 + 无 indoorNavigation(增强面 fail-soft,不 500)', async () => {
|
|
263
|
+
const { service } = makeIndoorStub({}, { resolveJumpUrl: async () => { throw new Error('down'); } });
|
|
264
|
+
const serverCtx = buildServer({ indoor: service });
|
|
265
|
+
const app = makeHttpApp(serverCtx, reqCtxOf('mall-1'));
|
|
266
|
+
const res = await request(app).get('/shop-detail?shopId=001&mallId=mall-1');
|
|
267
|
+
expect(res.status).toBe(200);
|
|
268
|
+
expect(shopDetailCardDataSchema.parse(res.body.data).indoorNavigation).toBeUndefined();
|
|
269
|
+
expect(res.body.data).toHaveProperty('name', '示例奶茶');
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('残缺/非法地址三层拦截:契约拒收 https:// → 消费侧同源 safeParse 省略 → 两条入口同形', async () => {
|
|
273
|
+
// ① 契约层:indoorNavigation.url 须为完整 HTTPS URL(indoorNavigationUrlSchema——url()+startsWith,
|
|
274
|
+
// 区别于仅前缀的 httpsUrlSchema;'https://' 残缺、非 https、裸文本均拒)
|
|
275
|
+
const base = projectShopDetail(SHOP as never);
|
|
276
|
+
expect(shopDetailCardDataSchema.safeParse({ ...base, indoorNavigation: { url: 'https://' } }).success).toBe(false);
|
|
277
|
+
expect(shopDetailCardDataSchema.safeParse({ ...base, indoorNavigation: { url: 'http://insecure.example.cn/nav' } }).success).toBe(false);
|
|
278
|
+
expect(shopDetailCardDataSchema.safeParse({ ...base, indoorNavigation: { url: 'not-a-url' } }).success).toBe(false);
|
|
279
|
+
expect(shopDetailCardDataSchema.safeParse({ ...base, indoorNavigation: { url: 'https://nav.example.cn/ar_v4?third_id=001' } }).success).toBe(true);
|
|
280
|
+
|
|
281
|
+
// ② 消费侧:服务返回残缺/非法地址 → 省略字段(复用契约同一 schema safeParse——防「服务下发了
|
|
282
|
+
// schema 过不去的地址」两侧判定漂移)
|
|
283
|
+
for (const url of ['https://', 'http://insecure.example.cn/nav', 'https:/single-slash.example.cn', 'not-a-url']) {
|
|
284
|
+
const serverCtx = buildServer();
|
|
285
|
+
serverCtx.services.register(INDOOR_NAVIGATION_SERVICE, { resolveJumpUrl: async () => url });
|
|
286
|
+
const data = await withIndoorNavigationTarget(projectShopDetail(SHOP as never), serverCtx, 'mall-1');
|
|
287
|
+
expect(data.indoorNavigation, `url=${url}`).toBeUndefined();
|
|
288
|
+
expect(data.name).toBe('示例奶茶');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ③ 按 R2 试接证词回归:服务被配置成返回 'https://' 时,此前两入口均接受并下发——现均省略字段
|
|
292
|
+
const serverCtx = buildServer();
|
|
293
|
+
serverCtx.services.register(INDOOR_NAVIGATION_SERVICE, { resolveJumpUrl: async () => 'https://' });
|
|
294
|
+
const tool = await runGetShopTool(serverCtx, 'mall-1');
|
|
295
|
+
expect(shopDetailCardDataSchema.parse(tool.cards![0]!.data).indoorNavigation).toBeUndefined();
|
|
296
|
+
const app = makeHttpApp(serverCtx, reqCtxOf('mall-1'));
|
|
297
|
+
const res = await request(app).get('/shop-detail?shopId=001&mallId=mall-1');
|
|
298
|
+
expect(res.status).toBe(200);
|
|
299
|
+
expect(shopDetailCardDataSchema.parse(res.body.data).indoorNavigation).toBeUndefined();
|
|
300
|
+
});
|
|
301
|
+
});
|
|
@@ -86,7 +86,7 @@ const portOf = (bag: Record<string, unknown>, service: string): unknown =>
|
|
|
86
86
|
const FIXTURE_PROVIDER = 'fixture';
|
|
87
87
|
const FIXTURE_PROVIDER_ID = 'fixture-shopping@1';
|
|
88
88
|
|
|
89
|
-
function buildFixtureServer(): ServerContext {
|
|
89
|
+
function buildFixtureServer(ports = stubShoppingPorts()): ServerContext {
|
|
90
90
|
const registry = createIntegrationsRegistry({
|
|
91
91
|
integrations: {
|
|
92
92
|
services: {
|
|
@@ -111,7 +111,7 @@ function buildFixtureServer(): ServerContext {
|
|
|
111
111
|
instanceIdOf: (scope) => scope.mallId ?? '',
|
|
112
112
|
});
|
|
113
113
|
registry.registerAdapter(FIXTURE_PROVIDER, FIXTURE_PROVIDER_ID, (input) =>
|
|
114
|
-
portOf(
|
|
114
|
+
portOf(ports as unknown as Record<string, unknown>, input.service));
|
|
115
115
|
|
|
116
116
|
const serverCtx = createServerContext({
|
|
117
117
|
state: createInMemoryStateStore(),
|
|
@@ -146,6 +146,38 @@ describe('S2 读链端到端(stub 槽位产物 → 投影 → 工具)', () =
|
|
|
146
146
|
expect(result.cards[0].note).toBe('示例运动店(3 楼)');
|
|
147
147
|
});
|
|
148
148
|
|
|
149
|
+
it('换一批排除已推荐门店,空批既不出卡也不向正文泄露旧店', async () => {
|
|
150
|
+
const server = buildFixtureServer();
|
|
151
|
+
const tools = createShoppingGuideTools({ getCtx: () => server });
|
|
152
|
+
const result = await tools.searchShops.execute!(
|
|
153
|
+
{ floorCode: 'F3', excludedMerchantIds: ['shop:1'] } as never,
|
|
154
|
+
createToolExecContext(ctx()) as never,
|
|
155
|
+
) as { summary: string; cards?: unknown[] };
|
|
156
|
+
expect(result.cards).toBeUndefined();
|
|
157
|
+
expect(JSON.parse(result.summary)).toMatchObject({ shops: [], total: 0 });
|
|
158
|
+
expect(result.summary).not.toContain('示例运动店');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('旧店占满一页时沿用筛选翻页,正文与卡片同批排除', async () => {
|
|
162
|
+
const ports = stubShoppingPorts();
|
|
163
|
+
const query = ports.shop.searchShops.bind(ports.shop);
|
|
164
|
+
ports.shop.searchShops = vi.fn(async (criteria) => {
|
|
165
|
+
const page = await query(criteria);
|
|
166
|
+
return criteria.page === 1 ? { ...page, total: 2, hasMore: true } : {
|
|
167
|
+
...page, page: 2, items: page.items.map((s) => ({ ...s, merchantId: 'shop:2', name: '另一家店' })),
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
const server = buildFixtureServer(ports);
|
|
171
|
+
const tools = createShoppingGuideTools({ getCtx: () => server });
|
|
172
|
+
const result = await tools.searchShops.execute!(
|
|
173
|
+
{ floorCode: 'F3', businessCategory: '运动', excludedMerchantIds: ['shop:1'] } as never,
|
|
174
|
+
createToolExecContext(ctx()) as never,
|
|
175
|
+
) as { summary: string; cards: { data: { items: { merchantId: string }[] } }[] };
|
|
176
|
+
expect(ports.shop.searchShops).toHaveBeenNthCalledWith(2, expect.objectContaining({ page: 2, floorCode: 'F3', businessCategory: '运动' }));
|
|
177
|
+
expect(result.cards[0].data.items.map((s) => s.merchantId)).toEqual(['shop:2']);
|
|
178
|
+
expect(JSON.parse(result.summary).shops.map((s: { merchantId: string }) => s.merchantId)).toEqual(['shop:2']);
|
|
179
|
+
});
|
|
180
|
+
|
|
149
181
|
it.skip('compare-products:暂停——provider 无商品接口', async () => {
|
|
150
182
|
// 工具已暂停注册,用例保留备用
|
|
151
183
|
});
|