@tbox.cn/app-module-shopping-guide 0.2.1 → 0.8.2
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/AGENTS.md +16 -0
- package/README.md +96 -0
- package/dist/chunk-AYQZO2FV.js +1496 -0
- package/dist/chunk-QDTU2FRN.js +1682 -0
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -8
- package/dist/server/index.d.ts +2512 -608
- package/dist/server/index.js +1 -7
- package/dist/shop-guide-header-art-pea-v2-OME4MKBW.jpg +0 -0
- package/dist/shopping-guide-OQ2SSHXL.css +2593 -0
- package/package.json +25 -16
- package/skills/shopping-guide/SKILL.md +127 -24
- package/src/client/assets/shop-guide-header-art-pea-v2.jpg +0 -0
- package/src/client/assets/shop-guide-header-art.png +0 -0
- package/src/client/assets.d.ts +10 -0
- package/src/client/cards/category-list/index.tsx +113 -0
- package/src/client/cards/human-guide-list/index.tsx +72 -0
- package/src/client/cards/index.ts +14 -0
- package/src/client/cards/location-handoff/index.tsx +52 -0
- package/src/client/cards/mall-directory/index.tsx +77 -0
- package/src/client/cards/nearby-mall-list/index.tsx +40 -0
- package/src/client/cards/product-comparison/index.tsx +100 -0
- package/src/client/cards/product-detail/index.tsx +97 -0
- package/src/client/cards/product-list/index.tsx +223 -0
- package/src/client/cards/recommend-merchants/index.tsx +147 -0
- package/src/client/cards/shop-detail/index.tsx +133 -0
- package/src/client/cards/shop-list/index.tsx +216 -0
- package/src/client/cards/view.ts +147 -0
- package/src/client/categories.ts +38 -0
- package/src/client/components/ImageWithFallback.tsx +34 -0
- package/src/client/components/MerchantRow.tsx +78 -0
- package/src/client/components/ShopDetailSheet.tsx +383 -0
- package/src/client/components/ShopGuideHeader.tsx +24 -0
- package/src/client/components/ShopGuideSectionLabel.tsx +10 -0
- package/src/client/components/ShopListSheet.tsx +293 -0
- package/src/client/index.ts +8 -6
- package/src/client/styles/shopping-guide.css +2593 -0
- package/src/client/types/css.d.ts +2 -0
- package/src/server/cards/category-list/meta.ts +0 -2
- package/src/server/cards/human-guide-list/meta.ts +0 -2
- package/src/server/cards/index.ts +10 -10
- package/src/server/cards/location-handoff/meta.ts +0 -2
- package/src/server/cards/mall-directory/meta.ts +0 -2
- package/src/server/cards/nearby-mall-list/meta.ts +1 -3
- package/src/server/cards/product-comparison/meta.ts +0 -2
- package/src/server/cards/product-detail/meta.ts +0 -2
- package/src/server/cards/product-list/meta.ts +0 -2
- package/src/server/cards/recommend-merchants/meta.ts +37 -0
- package/src/server/cards/recommend-merchants/samples.ts +189 -0
- package/src/server/cards/{merchant-detail → shop-detail}/meta.ts +6 -6
- package/src/server/cards/shop-detail/samples.ts +72 -0
- package/src/server/cards/{merchant-list → shop-list}/meta.ts +9 -9
- package/src/server/cards/shop-list/samples.ts +154 -0
- package/src/server/domain/value-objects.ts +1 -2
- package/src/server/handler.ts +63 -0
- package/src/server/index.ts +161 -101
- package/src/server/ports/index.ts +120 -91
- package/src/server/ports/local-adapters.ts +5 -55
- package/src/server/projections/index.ts +159 -41
- package/src/server/tools/index.ts +590 -315
- package/tbox.module.json +137 -0
- package/tests/cards-render.test.tsx +830 -0
- package/tests/floor-pretool.test.ts +275 -0
- package/tests/handler.test.ts +259 -0
- package/tests/merchant-list-limit.test.ts +53 -0
- package/tests/ports-resolve.test.ts +112 -0
- package/tests/samples.test.ts +71 -0
- package/tests/shopping-guide.test.ts +402 -234
- package/tests/skill.test.ts +86 -0
- package/tests/view.test.ts +42 -0
- package/tsup.config.ts +9 -1
- package/dist/chunk-AGBLC6XI.js +0 -1294
- package/dist/chunk-U4WDS5PQ.js +0 -173
- package/skills/shopping-guide/references/comparison-format.md +0 -5
- package/skills/shopping-guide/references/faq-answers.md +0 -5
- package/skills/shopping-guide/references/floor-directory.md +0 -4
- package/skills/shopping-guide/references/intent-patterns.md +0 -5
- package/skills/shopping-guide/references/location-format.md +0 -5
- package/skills/shopping-guide/references/policy-lookup.md +0 -5
- package/skills/shopping-guide/references/product-search-tips.md +0 -6
- package/skills/shopping-guide/references/recommendation-style.md +0 -5
- package/src/client/cards/index.tsx +0 -267
- package/src/server/cards/customer-service-faq/meta.ts +0 -18
- package/src/server/integrations/joycity/adapter.ts +0 -226
- package/src/server/integrations/joycity/auth-strategy.ts +0 -38
- package/src/server/integrations/joycity/gateway.ts +0 -128
- package/tbox.component.json +0 -48
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 011 S7 shopping-guide 切片验收(
|
|
3
|
-
*
|
|
2
|
+
* 011 S7 shopping-guide 切片验收(F5 终态):
|
|
3
|
+
* 槽位轴 stub adapter(契约形状出参)→ 投影 → 工具 execute → 卡数据(schema 校验)。
|
|
4
|
+
* adapter/解码层行为归 provider 包测试覆盖;本文件锁定工具投影与本地知识库域。
|
|
4
5
|
*/
|
|
5
|
-
import { describe, expect, it } from 'vitest';
|
|
6
|
-
import { createInMemoryStateStore } from '@tbox.cn/app-sdk/server';
|
|
6
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
7
|
+
import { createInMemoryStateStore, createToolExecContext } from '@tbox.cn/app-sdk/server';
|
|
7
8
|
import { createServerContext } from '@tbox.cn/app-sdk/server';
|
|
8
9
|
import type { ServerContext } from '@tbox.cn/app-sdk/server';
|
|
9
|
-
import { createProviderRegistry } from '@tbox.cn/app-sdk/server';
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import { createShoppingGuideTools } from '../src/server/tools';
|
|
11
|
+
createIntegrationsRegistry,
|
|
12
|
+
createAuthStrategyRegistry,
|
|
13
|
+
createEnvironmentSecretProvider,
|
|
14
|
+
} from '@tbox.cn/app-sdk/server';
|
|
15
|
+
import { createShoppingGuideTools, shopListNote } from '../src/server/tools';
|
|
16
16
|
import { resolveShoppingGuidePorts } from '../src/server/ports';
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
merchantListCardDataSchema,
|
|
20
|
-
productComparisonCardDataSchema,
|
|
21
|
-
} from '@tbox.cn/app-contracts-mall';
|
|
17
|
+
import { shopListCardDataSchema } from '@tbox.cn/app-contracts-mall';
|
|
18
|
+
import type { ShoppingGuidePorts } from '../src/server/ports';
|
|
22
19
|
import type { RequestContext } from '@tbox.cn/app-contracts';
|
|
23
20
|
|
|
24
21
|
const ctx = (mallId = 'mall-1'): RequestContext => ({
|
|
@@ -26,265 +23,436 @@ const ctx = (mallId = 'mall-1'): RequestContext => ({
|
|
|
26
23
|
attributes: { mall: { miniAppId: 'app1', mallId } },
|
|
27
24
|
});
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
StockLabel: '有货',
|
|
45
|
-
Marketable: true,
|
|
46
|
-
MerchantID: 1,
|
|
47
|
-
MerchantName: '示例运动店',
|
|
48
|
-
BuildingName: 'A 栋',
|
|
49
|
-
FloorName: '3 楼',
|
|
50
|
-
UnitName: '301',
|
|
51
|
-
Labels: ['热卖'],
|
|
52
|
-
PromotionFacts: ['限时 8 折'],
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
if (req.path === JOYCITY_READ_OPERATIONS.listMerchants) {
|
|
58
|
-
return {
|
|
59
|
-
Code: 1,
|
|
60
|
-
Data: [
|
|
61
|
-
{
|
|
62
|
-
MerchantID: 1,
|
|
63
|
-
Name: '示例运动店',
|
|
64
|
-
CommercialTypeName: '运动',
|
|
65
|
-
BuildingName: 'A 栋',
|
|
66
|
-
FloorName: '3 楼',
|
|
67
|
-
UnitName: '301',
|
|
68
|
-
Status: 1,
|
|
69
|
-
Services: ['试穿'],
|
|
70
|
-
PromotionFacts: ['会员 9 折'],
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
if (req.path === JOYCITY_READ_OPERATIONS.getProduct) {
|
|
76
|
-
return {
|
|
77
|
-
Code: 1,
|
|
78
|
-
Data: {
|
|
79
|
-
ProductID: 101,
|
|
80
|
-
Name: '轻量跑鞋',
|
|
81
|
-
PriceYuan: 399,
|
|
82
|
-
StockLabel: '有货',
|
|
83
|
-
Marketable: true,
|
|
84
|
-
MerchantID: 1,
|
|
85
|
-
MerchantName: '示例运动店',
|
|
86
|
-
BuildingName: 'A 栋',
|
|
87
|
-
FloorName: '3 楼',
|
|
88
|
-
UnitName: '301',
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
return { Code: 0, Data: null };
|
|
93
|
-
},
|
|
26
|
+
/** 契约形状 stub(数据对齐原厂商 fixture;投影断言零改动迁移) */
|
|
27
|
+
function stubShoppingPorts(): ShoppingGuidePorts {
|
|
28
|
+
const shopRecord = {
|
|
29
|
+
merchantId: 'shop:1',
|
|
30
|
+
name: '示例运动店',
|
|
31
|
+
logoUrl: undefined,
|
|
32
|
+
coverUrls: [],
|
|
33
|
+
brand: undefined,
|
|
34
|
+
businessCategories: ['运动'],
|
|
35
|
+
location: { displayText: 'A 栋 3 楼 301', buildingName: 'A 栋', floorName: '3 楼', unitName: '301' },
|
|
36
|
+
status: { code: 'enabled' as const, label: '营业中', observedAt: '2026-08-14T00:00:00Z' },
|
|
37
|
+
description: '运动品牌旗舰店',
|
|
38
|
+
contactInfo: [{ channel: 'phone', value: '0571-88888888' }],
|
|
39
|
+
services: [],
|
|
40
|
+
promotionFacts: [],
|
|
94
41
|
};
|
|
42
|
+
return {
|
|
43
|
+
catalog: {
|
|
44
|
+
async searchProducts(criteria: { page: number; pageSize: number }) {
|
|
45
|
+
return { items: [], page: criteria.page, pageSize: criteria.pageSize, total: 0, hasMore: false };
|
|
46
|
+
},
|
|
47
|
+
async getProduct() {
|
|
48
|
+
return null;
|
|
49
|
+
},
|
|
50
|
+
async getFacets() {
|
|
51
|
+
return { brands: [], categories: [], priceRanges: [], floors: [] };
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
shop: {
|
|
55
|
+
async searchShops() {
|
|
56
|
+
return { items: [shopRecord], page: 1, pageSize: 10, total: 1, hasMore: false };
|
|
57
|
+
},
|
|
58
|
+
async getShop() {
|
|
59
|
+
return shopRecord;
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
category: {
|
|
63
|
+
async listCategories() {
|
|
64
|
+
return [];
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
directory: {
|
|
68
|
+
async getDirectory() {
|
|
69
|
+
return null;
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
} as never;
|
|
73
|
+
}
|
|
74
|
+
|
|
95
75
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
76
|
+
/** 槽 id → 四键 bag 的单 Port 分发(017 槽位原子化测试基建) */
|
|
77
|
+
const SLOT_KEY_OF: Record<string, string> = {
|
|
78
|
+
'shopping-guide.catalog': 'catalog',
|
|
79
|
+
'shopping-guide.shops': 'shop',
|
|
80
|
+
'shopping-guide.categories': 'category',
|
|
81
|
+
'shopping-guide.directory': 'directory',
|
|
82
|
+
};
|
|
83
|
+
const portOf = (bag: Record<string, unknown>, service: string): unknown =>
|
|
84
|
+
bag[SLOT_KEY_OF[service] ?? ''] ?? {};
|
|
85
|
+
|
|
86
|
+
const FIXTURE_PROVIDER = 'fixture';
|
|
87
|
+
const FIXTURE_PROVIDER_ID = 'fixture-shopping@1';
|
|
88
|
+
|
|
89
|
+
function buildFixtureServer(): ServerContext {
|
|
90
|
+
const registry = createIntegrationsRegistry({
|
|
91
|
+
integrations: {
|
|
92
|
+
services: {
|
|
93
|
+
'shopping-guide.catalog': { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: { 'mall-1': { enabled: true } } },
|
|
94
|
+
'shopping-guide.shops': { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: { 'mall-1': { enabled: true } } },
|
|
95
|
+
'shopping-guide.categories': { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: { 'mall-1': { enabled: true } } },
|
|
96
|
+
'shopping-guide.directory': { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: { 'mall-1': { enabled: true } } },
|
|
104
97
|
},
|
|
105
|
-
],
|
|
106
|
-
templates: [
|
|
107
|
-
{ providerTemplateId: 'joycity-commercial@1', credentialType: 'static-headers-v1' },
|
|
108
|
-
],
|
|
109
|
-
transportFactory: {
|
|
110
|
-
create: () => transport,
|
|
111
98
|
},
|
|
99
|
+
catalog: {
|
|
100
|
+
providers: {
|
|
101
|
+
// local: true → transport 短路(stub 不消费 transport)
|
|
102
|
+
[FIXTURE_PROVIDER]: {
|
|
103
|
+
[FIXTURE_PROVIDER_ID]: { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, credentialType: '-', owner: 'fixture', services: ['shopping-guide.catalog', 'shopping-guide.shops', 'shopping-guide.categories', 'shopping-guide.directory'], local: true },
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
services: {},
|
|
107
|
+
credentialTypes: {},
|
|
108
|
+
},
|
|
109
|
+
authStrategies: createAuthStrategyRegistry(),
|
|
110
|
+
secretProvider: createEnvironmentSecretProvider({ source: {}, production: false }),
|
|
111
|
+
instanceIdOf: (scope) => scope.mallId ?? '',
|
|
112
112
|
});
|
|
113
|
+
registry.registerAdapter(FIXTURE_PROVIDER, FIXTURE_PROVIDER_ID, (input) =>
|
|
114
|
+
portOf(stubShoppingPorts() as unknown as Record<string, unknown>, input.service));
|
|
113
115
|
|
|
114
116
|
const serverCtx = createServerContext({
|
|
115
117
|
state: createInMemoryStateStore(),
|
|
116
|
-
|
|
118
|
+
integrations: registry,
|
|
117
119
|
});
|
|
118
|
-
serverCtx.auth.setContext(ctx());
|
|
119
120
|
return serverCtx;
|
|
120
121
|
}
|
|
121
122
|
|
|
122
|
-
describe('S2 读链端到端(
|
|
123
|
-
it('search-products
|
|
124
|
-
|
|
125
|
-
await resolveShoppingGuidePorts(serverCtx);
|
|
126
|
-
const tools = createShoppingGuideTools({ getCtx: () => serverCtx });
|
|
127
|
-
|
|
128
|
-
const result = (await tools.searchProducts.execute!(
|
|
129
|
-
{
|
|
130
|
-
keywords: ['跑鞋'],
|
|
131
|
-
page: '1',
|
|
132
|
-
pageSize: '10',
|
|
133
|
-
} as never,
|
|
134
|
-
{} as never,
|
|
135
|
-
)) as { context: string; items: unknown[] };
|
|
136
|
-
|
|
137
|
-
expect(result.context).toBe('search');
|
|
138
|
-
expect(result.items).toHaveLength(1);
|
|
139
|
-
// 卡 schema 校验(TIER1 zod 单一来源)
|
|
140
|
-
expect(productListCardDataSchema.safeParse(result).success).toBe(true);
|
|
141
|
-
|
|
142
|
-
const item = result.items[0] as {
|
|
143
|
-
name: string;
|
|
144
|
-
price: { sale?: { display: string } };
|
|
145
|
-
merchant: { location?: { displayText: string } };
|
|
146
|
-
};
|
|
147
|
-
expect(item.name).toBe('轻量跑鞋');
|
|
148
|
-
expect(item.price.sale?.display).toBe('¥399.00');
|
|
149
|
-
expect(item.merchant.location?.displayText).toContain('A 栋');
|
|
123
|
+
describe('S2 读链端到端(stub 槽位产物 → 投影 → 工具)', () => {
|
|
124
|
+
it.skip('search-products:暂停——provider 无商品目录接口', async () => {
|
|
125
|
+
// 工具已暂停注册,用例保留备用
|
|
150
126
|
});
|
|
151
127
|
|
|
152
|
-
it('search-
|
|
128
|
+
it('search-shops:ShopRecord → shop-list 卡数据(schema 通过;v2 cards 出参)', async () => {
|
|
153
129
|
const serverCtx = buildFixtureServer();
|
|
154
|
-
await resolveShoppingGuidePorts(serverCtx);
|
|
130
|
+
await resolveShoppingGuidePorts(ctx(), serverCtx);
|
|
155
131
|
const tools = createShoppingGuideTools({ getCtx: () => serverCtx });
|
|
156
132
|
|
|
157
|
-
const result = (await tools.
|
|
158
|
-
{
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
))
|
|
165
|
-
|
|
166
|
-
expect(result.context).toBe('search');
|
|
167
|
-
expect(merchantListCardDataSchema.safeParse(result).success).toBe(true);
|
|
168
|
-
const item = result.items[0] as { name: string; location: { displayText: string } };
|
|
133
|
+
const result = (await tools.searchShops.execute!(
|
|
134
|
+
{ keywords: ['运动'], page: '1', pageSize: '10' } as never,
|
|
135
|
+
createToolExecContext(ctx()) as never,
|
|
136
|
+
)) as { summary: string; cards: { cardType: string; data: unknown; note?: string }[] };
|
|
137
|
+
|
|
138
|
+
expect(result.cards[0].cardType).toBe('shop-list');
|
|
139
|
+
const data = result.cards[0].data;
|
|
140
|
+
expect(shopListCardDataSchema.safeParse(data).success).toBe(true);
|
|
141
|
+
const item = (data as { items: { name: string; location: { displayText: string } }[] }).items[0];
|
|
169
142
|
expect(item.name).toBe('示例运动店');
|
|
170
143
|
expect(item.location.displayText).toContain('3 楼');
|
|
144
|
+
expect(result.summary).toContain('示例运动店');
|
|
145
|
+
// W7 note:主体+关键事实(店名+楼层)——模型凭 descriptor 可区分同型候选
|
|
146
|
+
expect(result.cards[0].note).toBe('示例运动店(3 楼)');
|
|
171
147
|
});
|
|
172
148
|
|
|
173
|
-
it('compare-products
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
149
|
+
it.skip('compare-products:暂停——provider 无商品接口', async () => {
|
|
150
|
+
// 工具已暂停注册,用例保留备用
|
|
151
|
+
});
|
|
152
|
+
});
|
|
177
153
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
154
|
+
// 014 评审修复(轻1):S3 门控块删除后,补正常路径 execute 回归(护栏退役 → 工具恒可执行)
|
|
155
|
+
describe('S4 工具正常执行回归(014:feature 门控退役后恒走业务路径)', () => {
|
|
156
|
+
it.skip('list-nearby-malls 正常执行:暂停——周边商场暂不涉及', async () => {
|
|
157
|
+
// 工具已暂停注册,用例保留备用
|
|
158
|
+
});
|
|
159
|
+
// customer-service-faq 正常执行用例随客服承接拆分迁至 module-customer-service(2026-08-31)
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe('itemActions 投影矩阵(015 S7/F1)', () => {
|
|
163
|
+
const merchant = {
|
|
164
|
+
merchantId: 'm_1',
|
|
165
|
+
name: '老凤祥',
|
|
166
|
+
logoUrl: undefined,
|
|
167
|
+
coverUrls: [],
|
|
168
|
+
brand: undefined,
|
|
169
|
+
businessCategories: ['珠宝'],
|
|
170
|
+
location: { displayText: 'A 栋 1 层 108', buildingName: 'A 栋', floorName: '1 层', unitName: '108', poiId: undefined },
|
|
171
|
+
status: { code: 'enabled' as const, label: '营业中', observedAt: '2026-08-14T00:00:00Z' },
|
|
172
|
+
description: undefined,
|
|
173
|
+
contactInfo: undefined,
|
|
174
|
+
services: [],
|
|
175
|
+
promotionFacts: [],
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
it('shop-list/detail:整行点击唤起详情(无查看详情按钮)+ link 导航(高德 search 模板)', async () => {
|
|
179
|
+
const { projectShopList, projectShopDetail } = await import('../src/server/projections');
|
|
180
|
+
const list = projectShopList('search', { items: [merchant as never], page: 1, pageSize: 10, total: 1, hasMore: false });
|
|
181
|
+
const item = list.items[0]!;
|
|
182
|
+
// 「查看详情」改为客户端整行点击发静默消息触发——itemActions 仅保留导航 link
|
|
183
|
+
expect(item.itemActions).toHaveLength(1);
|
|
184
|
+
expect(item.itemActions[0]).toMatchObject({ kind: 'link', label: '导航' });
|
|
185
|
+
expect((item.itemActions[0] as { url: string }).url).toContain('uri.amap.com/search');
|
|
186
|
+
expect(item.itemActions.some((a) => a.kind === 'send' && a.label === '查看详情')).toBe(false);
|
|
184
187
|
|
|
185
|
-
|
|
186
|
-
expect(
|
|
188
|
+
const detail = projectShopDetail(merchant as never);
|
|
189
|
+
expect(detail.itemActions.some((a) => a.kind === 'link' && a.label === '导航')).toBe(true);
|
|
187
190
|
});
|
|
188
191
|
|
|
189
|
-
it('
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
{
|
|
196
|
-
ProductID: 101,
|
|
197
|
-
Name: '轻量跑鞋',
|
|
198
|
-
PriceYuan: 199,
|
|
199
|
-
StockLabel: '有货',
|
|
200
|
-
Marketable: true,
|
|
201
|
-
MerchantID: 1,
|
|
202
|
-
MerchantName: '示例运动店',
|
|
203
|
-
},
|
|
204
|
-
],
|
|
205
|
-
};
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
const adapter = new JoyCityCatalogAdapter(gateway);
|
|
209
|
-
const page = await adapter.searchProducts({
|
|
210
|
-
ctx: { scope: { miniAppId: 'app1', mallId: 'mall-1' }, requestContext: ctx() as never },
|
|
211
|
-
page: 1,
|
|
212
|
-
pageSize: 10,
|
|
213
|
-
});
|
|
214
|
-
expect(page.items).toHaveLength(1);
|
|
215
|
-
expect(page.items[0].price.sale?.amountMinor).toBe(19900);
|
|
192
|
+
it('nearby-mall-list:send「{商场名}有什么店」(R6:无切商场动作)', async () => {
|
|
193
|
+
const { projectNearbyMalls } = await import('../src/server/projections');
|
|
194
|
+
const card = projectNearbyMalls([
|
|
195
|
+
{ mallId: 'mall-2', name: '示例广场', address: '北京市朝阳区', status: { code: 'open', label: '营业中' } },
|
|
196
|
+
]);
|
|
197
|
+
expect(card.malls[0]!.itemActions).toEqual([{ kind: 'send', label: '示例广场有什么店', value: '示例广场里有什么店' }]);
|
|
216
198
|
});
|
|
217
199
|
|
|
218
|
-
it('
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
BuildingName: 'A 栋',
|
|
229
|
-
FloorName: '3 楼',
|
|
230
|
-
Status: 1,
|
|
231
|
-
},
|
|
232
|
-
],
|
|
233
|
-
};
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
const adapter = new JoyCityMerchantAdapter(gateway);
|
|
237
|
-
const page = await adapter.searchMerchants({
|
|
238
|
-
ctx: { scope: { miniAppId: 'app1', mallId: 'mall-1' }, requestContext: ctx() as never },
|
|
239
|
-
page: 1,
|
|
240
|
-
pageSize: 10,
|
|
241
|
-
});
|
|
242
|
-
expect(page.items[0].status.code).toBe('enabled');
|
|
200
|
+
it('location-handoff:link 开始导航;human-guide:send 联系导购', async () => {
|
|
201
|
+
const { projectLocationHandoff, projectHumanGuideList } = await import('../src/server/projections');
|
|
202
|
+
const handoff = projectLocationHandoff(merchant as never);
|
|
203
|
+
expect(handoff.itemActions[0]).toMatchObject({ kind: 'link', label: '开始导航' });
|
|
204
|
+
expect(handoff.mapUrl).toContain('uri.amap.com');
|
|
205
|
+
|
|
206
|
+
const guides = projectHumanGuideList('m_1', '老凤祥', [
|
|
207
|
+
{ guideId: 'g_1', name: '王店长', available: true },
|
|
208
|
+
] as never);
|
|
209
|
+
expect(guides.guides[0]!.itemActions).toEqual([{ kind: 'send', label: '联系王店长', value: '我想联系老凤祥的导购王店长' }]);
|
|
243
210
|
});
|
|
244
211
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
212
|
+
// customer-service-faq 投影用例随客服承接拆分迁至 module-customer-service(2026-08-31)
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe('shopListNote:W7 note 主体组装(模型凭 descriptor 区分同型候选)', () => {
|
|
216
|
+
const data = (names: [string, string?][]): Parameters<typeof shopListNote>[0] =>
|
|
217
|
+
({
|
|
218
|
+
context: 'search',
|
|
219
|
+
items: names.map(([name, floorName]) => ({
|
|
220
|
+
merchantId: `m_${name}`,
|
|
221
|
+
name,
|
|
222
|
+
businessCategories: [],
|
|
223
|
+
location: { displayText: floorName ?? '', floorName, buildingName: '' },
|
|
224
|
+
status: { code: 'enabled', label: '营业中', observedAt: '2026-09-02T00:00:00Z' },
|
|
225
|
+
services: [],
|
|
226
|
+
promotionFacts: [],
|
|
227
|
+
itemActions: [],
|
|
228
|
+
})),
|
|
229
|
+
refinements: [],
|
|
230
|
+
}) as never;
|
|
231
|
+
|
|
232
|
+
it('店名(楼层)主体前置,2 家全列', () => {
|
|
233
|
+
expect(shopListNote(data([['特步儿童', '3F'], ['瑞幸咖啡', '1F']]))).toBe('特步儿童(3F)、瑞幸咖啡(1F)');
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('至多 3 个店名前置,超量收尾「等 N 家门店」', () => {
|
|
237
|
+
expect(shopListNote(data([['A', '1F'], ['B'], ['C', '3F'], ['D'], ['E']]))).toBe('A(1F)、B、C(3F) 等 5 家门店');
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('缺楼层名只列店名;空 items 回退纯计数', () => {
|
|
241
|
+
expect(shopListNote(data([['示例运动店']]))).toBe('示例运动店');
|
|
242
|
+
expect(shopListNote(data([]))).toBe('0 家门店');
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('total > visible(密度/分页截断)→ 尾缀显式声明 total 派生计数', () => {
|
|
246
|
+
expect(shopListNote(data([['A', '1F'], ['B'], ['C', '3F']]), 250)).toBe(
|
|
247
|
+
'A(1F)、B、C(3F)(共 250 家门店,当前展示前 3 家)',
|
|
251
248
|
);
|
|
252
249
|
});
|
|
253
250
|
});
|
|
254
251
|
|
|
255
|
-
describe('
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
252
|
+
describe('mall-overview:结构问句聚合承接(2026-09-02)', () => {
|
|
253
|
+
const overviewSample = {
|
|
254
|
+
mallId: 'mall-1',
|
|
255
|
+
floors: ['B1', '1F', '2F', '3F', '4F', '5F', '8F', '10F'],
|
|
256
|
+
categories: [
|
|
257
|
+
{ code: '餐饮', name: '餐饮', merchantCount: 6 },
|
|
258
|
+
{ code: '购物', name: '购物', merchantCount: 11 },
|
|
259
|
+
{ code: '生活', name: '生活', merchantCount: 1 },
|
|
260
|
+
],
|
|
261
|
+
stores: [
|
|
262
|
+
{ merchantId: '2000091010', name: '丰科2门店', coverUrls: [], businessCategories: ['百货'], location: { displayText: '1F-8811', floorName: '1F' }, status: { code: 'unknown', label: '营业状态以现场为准', observedAt: '2026-09-02T00:00:00Z' }, services: [], promotionFacts: [], observedAt: '2026-09-02T00:00:00Z' },
|
|
263
|
+
{ merchantId: '1000090324', name: '必胜客(北京丰科万达店)', coverUrls: [], businessCategories: ['洋快餐'], location: { displayText: '1F-1027', floorName: '1F' }, status: { code: 'unknown', label: '营业状态以现场为准', observedAt: '2026-09-02T00:00:00Z' }, services: [], promotionFacts: [], observedAt: '2026-09-02T00:00:00Z' }, // guard-vendor-neutrality: allow(真实厂商返回样例)
|
|
264
|
+
],
|
|
265
|
+
observedAt: '2026-09-02T00:00:00Z',
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
function buildOverviewServer(shopPort: Record<string, unknown>): ServerContext {
|
|
269
|
+
const registry = createIntegrationsRegistry({
|
|
270
|
+
integrations: { services: { 'shopping-guide.catalog': { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: { 'mall-1': { enabled: true } } }, 'shopping-guide.shops': { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: { 'mall-1': { enabled: true } } }, 'shopping-guide.categories': { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: { 'mall-1': { enabled: true } } }, 'shopping-guide.directory': { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: { 'mall-1': { enabled: true } } } } },
|
|
271
|
+
catalog: { providers: { [FIXTURE_PROVIDER]: { [FIXTURE_PROVIDER_ID]: { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, credentialType: '-', owner: 'fixture', services: ['shopping-guide.catalog', 'shopping-guide.shops', 'shopping-guide.categories', 'shopping-guide.directory'], local: true } } }, services: {}, credentialTypes: {} },
|
|
272
|
+
authStrategies: createAuthStrategyRegistry(),
|
|
273
|
+
secretProvider: createEnvironmentSecretProvider({ source: {}, production: false }),
|
|
274
|
+
instanceIdOf: (scope) => scope.mallId ?? '',
|
|
261
275
|
});
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
276
|
+
registry.registerAdapter(FIXTURE_PROVIDER, FIXTURE_PROVIDER_ID, (input) =>
|
|
277
|
+
portOf({
|
|
278
|
+
catalog: { async searchProducts() { return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false }; }, async getProduct() { return null; }, async getFacets() { return { brands: [], categories: [], priceRanges: [], floors: [] }; } },
|
|
279
|
+
...shopPort,
|
|
280
|
+
}, input.service));
|
|
281
|
+
return createServerContext({ state: createInMemoryStateStore(), integrations: registry });
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
it('fetchStoreOverview 可用 → agg 概览 shop-list 卡(note 携权威层数/业态计数)', async () => {
|
|
285
|
+
const searchShops = vi.fn(async () => ({ items: [], page: 1, pageSize: 50, total: 0, hasMore: false }));
|
|
286
|
+
const serverCtx = buildOverviewServer({
|
|
287
|
+
shop: { async searchShops() { return searchShops(); }, async getShop() { return null; }, async fetchStoreOverview() { return overviewSample; } },
|
|
288
|
+
category: { async listCategories() { return []; } },
|
|
289
|
+
directory: { async getDirectory() { return null; } },
|
|
266
290
|
});
|
|
267
|
-
|
|
291
|
+
const tools = createShoppingGuideTools({ getCtx: () => serverCtx });
|
|
292
|
+
const result = (await tools.mallOverview.execute!({ mallId: 'mall-1' }, createToolExecContext(ctx()) as never)) as {
|
|
293
|
+
cards: { cardType: string; note?: string; data: { summary?: string } }[];
|
|
294
|
+
};
|
|
295
|
+
expect(searchShops).not.toHaveBeenCalled(); // 概览不走全量口径
|
|
296
|
+
expect(result.cards[0]!.cardType).toBe('shop-list');
|
|
297
|
+
expect(result.cards[0]!.note).toContain('8 层');
|
|
298
|
+
expect(result.cards[0]!.note).toContain('餐饮 6 家');
|
|
299
|
+
expect(result.cards[0]!.note).toContain('当前展示其中 2 家门店');
|
|
300
|
+
expect(result.cards[0]!.data.summary).toBe('商场门店概览'); // 卡头无数字(概览数字只在回答)
|
|
268
301
|
});
|
|
269
302
|
|
|
270
|
-
it('
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
303
|
+
it('fetchStoreOverview 缺席 → 降级 searchShops 零参全量(口径不变)', async () => {
|
|
304
|
+
const searchShops = vi.fn(async () => ({
|
|
305
|
+
items: [{ merchantId: 'm1', name: '店', coverUrls: [], businessCategories: ['餐饮'], location: { displayText: '1F' }, status: { code: 'unknown', label: '', observedAt: 't' }, services: [], promotionFacts: [], observedAt: 't' }],
|
|
306
|
+
page: 1, pageSize: 50, total: 1, hasMore: false,
|
|
307
|
+
}));
|
|
308
|
+
const serverCtx = buildOverviewServer({
|
|
309
|
+
shop: { searchShops, async getShop() { return null; } },
|
|
310
|
+
category: { async listCategories() { return []; } },
|
|
311
|
+
directory: { async getDirectory() { return null; } },
|
|
274
312
|
});
|
|
275
|
-
const tools = createShoppingGuideTools({ getCtx: () =>
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
313
|
+
const tools = createShoppingGuideTools({ getCtx: () => serverCtx });
|
|
314
|
+
const result = (await tools.mallOverview.execute!({ mallId: 'mall-1' }, createToolExecContext(ctx()) as never)) as {
|
|
315
|
+
cards: { cardType: string }[];
|
|
316
|
+
};
|
|
317
|
+
expect(searchShops).toHaveBeenCalled();
|
|
318
|
+
expect(result.cards[0]!.cardType).toBe('shop-list');
|
|
279
319
|
});
|
|
320
|
+
});
|
|
280
321
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
322
|
+
describe('category-shops:类目问句确定性预执行(2026-09-03)', () => {
|
|
323
|
+
const categories = [
|
|
324
|
+
{ code: '餐饮', name: '餐饮', merchantCount: 6 },
|
|
325
|
+
{ code: '购物', name: '购物', merchantCount: 11 },
|
|
326
|
+
{ code: '生活', name: '生活', merchantCount: 1 },
|
|
327
|
+
];
|
|
328
|
+
|
|
329
|
+
function buildCategoryServer(shopPort: Record<string, unknown>, categoryPort: Record<string, unknown>): ServerContext {
|
|
330
|
+
const registry = createIntegrationsRegistry({
|
|
331
|
+
integrations: { services: { 'shopping-guide.catalog': { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: { 'mall-1': { enabled: true } } }, 'shopping-guide.shops': { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: { 'mall-1': { enabled: true } } }, 'shopping-guide.categories': { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: { 'mall-1': { enabled: true } } }, 'shopping-guide.directory': { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, instances: { 'mall-1': { enabled: true } } } } },
|
|
332
|
+
catalog: { providers: { [FIXTURE_PROVIDER]: { [FIXTURE_PROVIDER_ID]: { provider: FIXTURE_PROVIDER, implementation: FIXTURE_PROVIDER_ID, credentialType: '-', owner: 'fixture', services: ['shopping-guide.catalog', 'shopping-guide.shops', 'shopping-guide.categories', 'shopping-guide.directory'], local: true } } }, services: {}, credentialTypes: {} },
|
|
333
|
+
authStrategies: createAuthStrategyRegistry(),
|
|
334
|
+
secretProvider: createEnvironmentSecretProvider({ source: {}, production: false }),
|
|
335
|
+
instanceIdOf: (scope) => scope.mallId ?? '',
|
|
336
|
+
});
|
|
337
|
+
registry.registerAdapter(FIXTURE_PROVIDER, FIXTURE_PROVIDER_ID, (input) =>
|
|
338
|
+
portOf({
|
|
339
|
+
catalog: { async searchProducts() { return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false }; }, async getProduct() { return null; }, async getFacets() { return { brands: [], categories: [], priceRanges: [], floors: [] }; } },
|
|
340
|
+
shop: shopPort,
|
|
341
|
+
category: categoryPort,
|
|
342
|
+
directory: { async getDirectory() { return null; } },
|
|
343
|
+
}, input.service));
|
|
344
|
+
return createServerContext({ state: createInMemoryStateStore(), integrations: registry });
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function shopOf(cat: string, name: string) {
|
|
348
|
+
return {
|
|
349
|
+
merchantId: `shop:${cat}:${name}`,
|
|
350
|
+
name,
|
|
351
|
+
logoUrl: undefined,
|
|
352
|
+
coverUrls: [],
|
|
353
|
+
brand: undefined,
|
|
354
|
+
businessCategories: [cat],
|
|
355
|
+
location: { displayText: '1F-101', floorName: '1F' },
|
|
356
|
+
status: { code: 'unknown' as const, label: '营业状态以现场为准', observedAt: '2026-09-03T00:00:00Z' },
|
|
357
|
+
services: [],
|
|
358
|
+
promotionFacts: [],
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
it('精确归一命中:「餐饮」→ searchShops(businessCategory) → shop-list 卡(schema 校验)', async () => {
|
|
363
|
+
const searchShops = vi.fn(async (criteria: { businessCategory?: string }) => ({
|
|
364
|
+
items: criteria.businessCategory === '餐饮' ? [shopOf('餐饮', '烤鱼')] : [],
|
|
365
|
+
page: 1, pageSize: 200, total: criteria.businessCategory === '餐饮' ? 1 : 0, hasMore: false,
|
|
366
|
+
}));
|
|
367
|
+
const serverCtx = buildCategoryServer(
|
|
368
|
+
{ async searchShops(...a: unknown[]) { return searchShops(...(a as [{ businessCategory?: string }])); }, async getShop() { return null; } },
|
|
369
|
+
{ async listCategories() { return categories; } },
|
|
370
|
+
);
|
|
284
371
|
const tools = createShoppingGuideTools({ getCtx: () => serverCtx });
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
expect(
|
|
372
|
+
const result = (await tools.categoryShops.execute!({ categoryQuery: '餐饮' }, createToolExecContext(ctx()) as never)) as {
|
|
373
|
+
summary: string; cards: { cardType: string; data: unknown }[];
|
|
374
|
+
};
|
|
375
|
+
expect(searchShops).toHaveBeenCalledTimes(1);
|
|
376
|
+
expect(searchShops.mock.calls[0]![0].businessCategory).toBe('餐饮');
|
|
377
|
+
expect(result.cards[0]!.cardType).toBe('shop-list');
|
|
378
|
+
expect(() => shopListCardDataSchema.parse(result.cards[0]!.data)).not.toThrow();
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it('多词合并:「购物,餐饮」→ 两类目分查合并单卡(total 相加)', async () => {
|
|
382
|
+
const searchShops = vi.fn(async (criteria: { businessCategory?: string }) => {
|
|
383
|
+
if (criteria.businessCategory === '购物') return { items: [shopOf('购物', '运动店'), shopOf('购物', '服饰店')], page: 1, pageSize: 200, total: 2, hasMore: false };
|
|
384
|
+
if (criteria.businessCategory === '餐饮') return { items: [shopOf('餐饮', '烤鱼')], page: 1, pageSize: 200, total: 1, hasMore: false };
|
|
385
|
+
return { items: [], page: 1, pageSize: 200, total: 0, hasMore: false };
|
|
386
|
+
});
|
|
387
|
+
const serverCtx = buildCategoryServer(
|
|
388
|
+
{ async searchShops(...a: unknown[]) { return searchShops(...(a as [{ businessCategory?: string }])); }, async getShop() { return null; } },
|
|
389
|
+
{ async listCategories() { return categories; } },
|
|
390
|
+
);
|
|
391
|
+
const tools = createShoppingGuideTools({ getCtx: () => serverCtx });
|
|
392
|
+
const result = (await tools.categoryShops.execute!({ categoryQuery: '购物,餐饮' }, createToolExecContext(ctx()) as never)) as {
|
|
393
|
+
cards: { data: unknown; note?: string }[];
|
|
394
|
+
};
|
|
395
|
+
expect(searchShops).toHaveBeenCalledTimes(2);
|
|
396
|
+
const data = shopListCardDataSchema.parse(result.cards[0]!.data);
|
|
397
|
+
expect(data.items.length).toBe(3);
|
|
398
|
+
expect(result.cards[0]!.note).toContain('运动店');
|
|
399
|
+
expect(result.cards[0]!.note).toContain('烤鱼'); // 两类目门店合并同卡
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it('listTags 优先(与 mall-context 同口径):tags 即 code/name 同源', async () => {
|
|
403
|
+
const listTags = vi.fn(async () => ['餐饮', '购物'] as readonly string[]);
|
|
404
|
+
const listCategories = vi.fn(async () => categories);
|
|
405
|
+
const searchShops = vi.fn(async (_criteria: { businessCategory?: string }) => ({ items: [shopOf('餐饮', '烤鱼')], page: 1, pageSize: 200, total: 1, hasMore: false }));
|
|
406
|
+
const serverCtx = buildCategoryServer(
|
|
407
|
+
{ async searchShops(...a: unknown[]) { return searchShops(...(a as [{ businessCategory?: string }])); }, async getShop() { return null; } },
|
|
408
|
+
{ listTags, listCategories },
|
|
409
|
+
);
|
|
410
|
+
const tools = createShoppingGuideTools({ getCtx: () => serverCtx });
|
|
411
|
+
const result = (await tools.categoryShops.execute!({ categoryQuery: '美食' }, createToolExecContext(ctx()) as never)) as {
|
|
412
|
+
cards: { cardType: string }[];
|
|
413
|
+
};
|
|
414
|
+
expect(listTags).toHaveBeenCalled();
|
|
415
|
+
expect(listCategories).not.toHaveBeenCalled(); // listTags 可用不降级
|
|
416
|
+
expect(result.cards[0]!.cardType).toBe('shop-list');
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it('归一失败:类目表无命中词 → error summary(含 available 清单)+ 无卡', async () => {
|
|
420
|
+
const serverCtx = buildCategoryServer(
|
|
421
|
+
{ async searchShops() { return { items: [], page: 1, pageSize: 200, total: 0, hasMore: false }; }, async getShop() { return null; } },
|
|
422
|
+
{ async listCategories() { return categories; } },
|
|
423
|
+
);
|
|
424
|
+
const tools = createShoppingGuideTools({ getCtx: () => serverCtx });
|
|
425
|
+
const result = (await tools.categoryShops.execute!({ categoryQuery: '电器' }, createToolExecContext(ctx()) as never)) as {
|
|
426
|
+
summary: string; cards?: unknown[];
|
|
427
|
+
};
|
|
428
|
+
const parsed = JSON.parse(result.summary) as { error: string; available: string[] };
|
|
429
|
+
expect(parsed.error).toBe('category_unresolved');
|
|
430
|
+
expect(parsed.available).toContain('餐饮');
|
|
431
|
+
expect(result.cards).toBeUndefined();
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it('类目源不可用 → categories_unavailable 无卡 summary', async () => {
|
|
435
|
+
const serverCtx = buildCategoryServer(
|
|
436
|
+
{ async searchShops() { return { items: [], page: 1, pageSize: 200, total: 0, hasMore: false }; }, async getShop() { return null; } },
|
|
437
|
+
{ async listCategories() { throw new Error('down'); } },
|
|
438
|
+
);
|
|
439
|
+
const tools = createShoppingGuideTools({ getCtx: () => serverCtx });
|
|
440
|
+
const result = (await tools.categoryShops.execute!({ categoryQuery: '购物' }, createToolExecContext(ctx()) as never)) as {
|
|
441
|
+
summary: string; cards?: unknown[];
|
|
442
|
+
};
|
|
443
|
+
expect(JSON.parse(result.summary)).toMatchObject({ error: 'categories_unavailable' });
|
|
444
|
+
expect(result.cards).toBeUndefined();
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('空词 → category_query_empty 无卡 summary', async () => {
|
|
448
|
+
const serverCtx = buildCategoryServer(
|
|
449
|
+
{ async searchShops() { return { items: [], page: 1, pageSize: 200, total: 0, hasMore: false }; }, async getShop() { return null; } },
|
|
450
|
+
{ async listCategories() { return categories; } },
|
|
451
|
+
);
|
|
452
|
+
const tools = createShoppingGuideTools({ getCtx: () => serverCtx });
|
|
453
|
+
const result = (await tools.categoryShops.execute!({ categoryQuery: '' }, createToolExecContext(ctx()) as never)) as {
|
|
454
|
+
summary: string; cards?: unknown[];
|
|
455
|
+
};
|
|
456
|
+
expect(JSON.parse(result.summary)).toMatchObject({ error: 'category_query_empty' });
|
|
289
457
|
});
|
|
290
458
|
});
|