bailinghub 0.3.3 → 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.
- package/README.en.md +3 -1
- package/README.md +4 -0
- package/docker-compose.images.yml +2 -2
- package/docs/CHANGELOG.en.md +58 -1
- package/docs/CHANGELOG.md +26 -1
- package/docs/COMPATIBILITY.en.md +25 -0
- package/docs/CONTRACT.en.md +91 -8
- package/docs/CONTRACT.md +39 -7
- package/docs/DEMO.en.md +6 -0
- package/docs/DEMO.md +2 -0
- package/docs/INDEPENDENT_VALIDATION.en.md +9 -6
- package/docs/INDEPENDENT_VALIDATION.md +9 -6
- package/docs/QUICKSTART.en.md +20 -0
- package/docs/QUICKSTART.md +2 -2
- package/docs/README.en.md +4 -0
- package/docs/README.md +4 -0
- package/docs/RELEASE_NOTES_v0.3.4.en.md +38 -0
- package/docs/RELEASE_NOTES_v0.3.4.md +38 -0
- package/docs/RELEASE_NOTES_v0.4.0.en.md +39 -0
- package/docs/RELEASE_NOTES_v0.4.0.md +39 -0
- package/docs/STREAMING.en.md +32 -0
- package/docs/STREAMING.md +8 -2
- package/docs/WIDGET_RENDERERS.en.md +123 -6
- package/docs/WIDGET_RENDERERS.md +75 -6
- package/docs/user-guide/concepts.en.md +8 -1
- package/docs/user-guide/concepts.md +3 -1
- package/docs/user-guide/console-map.en.md +1 -2
- package/docs/user-guide/console-map.md +3 -3
- package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +9 -0
- package/package.json +1 -1
- package/schemas/config/chat-entry.schema.json +2 -1
- package/scripts/check-doc-links.mjs +2 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-release-consistency.test.mjs +5 -5
- package/scripts/e2e-console.mjs +38 -10
- package/scripts/install.sh +1 -1
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +2 -0
- package/scripts/verify-github-repo.mjs +2 -0
- package/scripts/widget-renderer-test.mjs +244 -16
- package/src/core/config/config-models.test.ts +18 -1
- package/src/core/config/config-models.ts +25 -3
- package/src/core/config/config-schema.test.ts +2 -0
- package/src/core/contracts/types.ts +2 -1
- package/src/core/platform/chat-form.test.ts +147 -0
- package/src/core/platform/chat-form.ts +402 -0
- package/src/core/platform/version.ts +1 -1
- package/src/core/runtime/execution-runtime.test.ts +73 -4
- package/src/core/runtime/execution-runtime.ts +18 -1
- package/src/routes/chat-mount.test.ts +9 -1
- package/src/routes/chat.test.ts +319 -7
- package/src/routes/chat.ts +179 -28
- package/web/console/assets/{Accounts-08VltF2i.js → Accounts-DuUY2UJU.js} +1 -1
- package/web/console/assets/{Approvals-CqgmsMau.js → Approvals-B11mo1dy.js} +1 -1
- package/web/console/assets/{Audit-bPlpSQt3.js → Audit-CQwJRIJT.js} +1 -1
- package/web/console/assets/{BrandLockup-DhX07g3G.js → BrandLockup-BIF-h1pi.js} +1 -1
- package/web/console/assets/{Channels-BZe0pLgx.js → Channels-BIploUT-.js} +1 -1
- package/web/console/assets/ChatEntries-Cpg_WV-o.js +7 -0
- package/web/console/assets/ChatEntries-DsYtcXN6.css +1 -0
- package/web/console/assets/Clients--D7NQJKk.css +1 -0
- package/web/console/assets/{Clients-BVVZfX3r.js → Clients-DS29eUi2.js} +2 -2
- package/web/console/assets/{Cost-DANcjr_p.js → Cost-BF52tfU2.js} +1 -1
- package/web/console/assets/{Credentials-D_8tP2Xa.js → Credentials-SwfmQAv6.js} +1 -1
- package/web/console/assets/{Diagnostics-Bw1WImFe.js → Diagnostics-CJfbI_8p.js} +1 -1
- package/web/console/assets/{Executors-fuieN2Sl.js → Executors-CzlZlznA.js} +1 -1
- package/web/console/assets/{Kb-BaMi_7xf.js → Kb-CVX22U4k.js} +1 -1
- package/web/console/assets/{Login-Cmz2ppY8.js → Login-PoUVsBI-.js} +1 -1
- package/web/console/assets/{Projects-D6xIgFB3.js → Projects-DYlbjLQy.js} +1 -1
- package/web/console/assets/{Routes-B90i3ZNa.js → Routes-DSEvGujN.js} +1 -1
- package/web/console/assets/{Runs-9qpwotOj.js → Runs-B-TsYZEt.js} +1 -1
- package/web/console/assets/Setup-D7nxgn-9.css +1 -0
- package/web/console/assets/Setup-xiPXit_b.js +1 -0
- package/web/console/assets/{Shell-Dm6eFcl1.js → Shell-DNiWZOYB.js} +1 -1
- package/web/console/assets/{StorageBuckets-DY8WuJlM.js → StorageBuckets-Bjsc3pLd.js} +1 -1
- package/web/console/assets/{SystemSettings-O_NMPzq_.js → SystemSettings-CcKF2lJ9.js} +1 -1
- package/web/console/assets/{SystemStatus-Cok3S7S3.js → SystemStatus-Oj1xjxJn.js} +1 -1
- package/web/console/assets/{Targets-YWBoxqvy.js → Targets-y1KllVXT.js} +1 -1
- package/web/console/assets/{Tools-BgXDw7Mg.js → Tools-DoEP_y9x.js} +1 -1
- package/web/console/assets/{index-S_J0I0Zh.js → index-CxPIS6G7.js} +2 -2
- package/web/console/assets/{request-FM608Kfz.js → request-CBLNpLth.js} +1 -1
- package/web/console/assets/{schema-DWnFqTkB.js → schema-DzwLpuOy.js} +1 -1
- package/web/console/index.html +1 -1
- package/web/widget/widget.js +493 -14
- package/web-admin/src/pages/ChatEntries.vue +46 -23
- package/web-admin/src/pages/Clients.vue +2 -2
- package/web-admin/src/pages/Setup.vue +12 -8
- package/web/console/assets/ChatEntries-BweMx_CU.css +0 -1
- package/web/console/assets/ChatEntries-Ca0lcGqn.js +0 -7
- package/web/console/assets/Clients-DcTYN-Js.css +0 -1
- package/web/console/assets/Setup-BIjCiA2i.js +0 -1
- package/web/console/assets/Setup-BuyKFofL.css +0 -1
|
@@ -177,7 +177,7 @@ test('prepareChatEntryConfig: 生成入口、校验引用并收紧外观', async
|
|
|
177
177
|
const ok = await prepareChatEntryConfig({
|
|
178
178
|
name: ' 官网客服 ',
|
|
179
179
|
route_key: ' chat.main ',
|
|
180
|
-
allowed_origins: [' https://
|
|
180
|
+
allowed_origins: [' https://EXAMPLE.com:443/ ', 'https://example.com', ''],
|
|
181
181
|
ticket_client: 'app-main',
|
|
182
182
|
bucket: 'chat-cos',
|
|
183
183
|
rate_limit_per_min: 9999,
|
|
@@ -185,6 +185,7 @@ test('prepareChatEntryConfig: 生成入口、校验引用并收紧外观', async
|
|
|
185
185
|
greeting: 'G'.repeat(300),
|
|
186
186
|
color: '#12abef',
|
|
187
187
|
appearance: {
|
|
188
|
+
default_open: true,
|
|
188
189
|
width: 9999,
|
|
189
190
|
height: 100,
|
|
190
191
|
title_align: 'left',
|
|
@@ -212,6 +213,7 @@ test('prepareChatEntryConfig: 生成入口、校验引用并收紧外观', async
|
|
|
212
213
|
assert.equal(ok.value.title?.length, 64);
|
|
213
214
|
assert.equal(ok.value.greeting?.length, 255);
|
|
214
215
|
assert.deepEqual(ok.value.appearance, {
|
|
216
|
+
default_open: true,
|
|
215
217
|
width: 720,
|
|
216
218
|
height: 360,
|
|
217
219
|
title_align: 'left',
|
|
@@ -233,6 +235,21 @@ test('prepareChatEntryConfig: 生成入口、校验引用并收紧外观', async
|
|
|
233
235
|
});
|
|
234
236
|
assert.equal(missingRoute.ok, false);
|
|
235
237
|
assert.match(missingRoute.ok ? '' : missingRoute.error, /路由 missing 不存在/);
|
|
238
|
+
|
|
239
|
+
const originDeps = {
|
|
240
|
+
routeExists: async () => true,
|
|
241
|
+
entryExists: async () => false,
|
|
242
|
+
clientExists: async () => true,
|
|
243
|
+
bucketExists: async () => true,
|
|
244
|
+
};
|
|
245
|
+
const missingOrigins = await prepareChatEntryConfig({ name: 'x', route_key: 'chat.main' }, originDeps);
|
|
246
|
+
assert.equal(missingOrigins.ok, false);
|
|
247
|
+
assert.match(missingOrigins.ok ? '' : missingOrigins.error, /allowed_origins 必须是数组/);
|
|
248
|
+
for (const invalidOrigin of ['example.com', 'ftp://example.com', 'https://example.com/path', 'https://example.com///', 'https://example.com?', 'https://example.com#', 'https://example.com?q=1', 'https://user@example.com', `https://${'a'.repeat(250)}.com`]) {
|
|
249
|
+
const invalid = await prepareChatEntryConfig({ name: 'x', route_key: 'chat.main', allowed_origins: [invalidOrigin] }, originDeps);
|
|
250
|
+
assert.equal(invalid.ok, false, invalidOrigin);
|
|
251
|
+
assert.match(invalid.ok ? '' : invalid.error, /Origin/);
|
|
252
|
+
}
|
|
236
253
|
});
|
|
237
254
|
|
|
238
255
|
test('preparePageContextConfig: 页面上下文只接受寻址字段,不开放 kb_tag 写入', async () => {
|
|
@@ -215,9 +215,31 @@ function safeHttpUrl(v: unknown): string | undefined {
|
|
|
215
215
|
return /^https?:\/\/.{3,}/.test(s) ? s.slice(0, 255) : undefined;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
function allowedOrigins(v: unknown): PrepareResult<string[]> {
|
|
219
|
+
if (!Array.isArray(v)) return fail('allowed_origins 必须是数组(不限站点时请传空数组 [])');
|
|
220
|
+
const origins = new Set<string>();
|
|
221
|
+
for (const raw of v) {
|
|
222
|
+
const candidate = String(raw).trim();
|
|
223
|
+
if (!candidate) continue;
|
|
224
|
+
if (candidate.length > 255) return fail('Origin 长度不能超过 255 个字符');
|
|
225
|
+
let url: URL;
|
|
226
|
+
try { url = new URL(candidate); }
|
|
227
|
+
catch { return fail(`Origin 格式无效:${candidate}(请填 scheme://host[:port])`); }
|
|
228
|
+
if (candidate.includes('?') || candidate.includes('#')
|
|
229
|
+
|| (url.protocol !== 'http:' && url.protocol !== 'https:')
|
|
230
|
+
|| url.username || url.password || url.search || url.hash
|
|
231
|
+
|| url.pathname !== '/' || url.origin === 'null') {
|
|
232
|
+
return fail(`Origin 只能填 scheme://host[:port],不能带路径、参数、用户信息或片段:${candidate}`);
|
|
233
|
+
}
|
|
234
|
+
origins.add(url.origin);
|
|
235
|
+
}
|
|
236
|
+
return { ok: true, value: [...origins] };
|
|
237
|
+
}
|
|
238
|
+
|
|
218
239
|
function chatAppearance(v: unknown): ChatEntry['appearance'] | undefined {
|
|
219
240
|
const apIn = object(v);
|
|
220
241
|
const appearance: ChatEntry['appearance'] = {};
|
|
242
|
+
if (apIn.default_open === true) appearance.default_open = true;
|
|
221
243
|
const width = clampNum(apIn.width, 280, 720); if (width !== undefined) appearance.width = width;
|
|
222
244
|
const height = clampNum(apIn.height, 360, 900); if (height !== undefined) appearance.height = height;
|
|
223
245
|
if (apIn.title_align === 'left' || apIn.title_align === 'center') appearance.title_align = apIn.title_align;
|
|
@@ -253,6 +275,8 @@ export async function prepareChatEntryConfig(
|
|
|
253
275
|
if (ticketClient && !(await deps.clientExists(ticketClient))) return fail(`票据签发方 ${ticketClient} 不是已登记的接入方`);
|
|
254
276
|
const bucketName = str(input.bucket);
|
|
255
277
|
if (bucketName && !(await deps.bucketExists(bucketName))) return fail(`存储桶 ${bucketName} 未登记(先在「对象存储」建)`);
|
|
278
|
+
const origins = allowedOrigins(input.allowed_origins);
|
|
279
|
+
if (!origins.ok) return origins;
|
|
256
280
|
|
|
257
281
|
return {
|
|
258
282
|
ok: true,
|
|
@@ -261,9 +285,7 @@ export async function prepareChatEntryConfig(
|
|
|
261
285
|
name,
|
|
262
286
|
route_key: routeKey,
|
|
263
287
|
enabled: input.enabled !== false,
|
|
264
|
-
allowed_origins:
|
|
265
|
-
? input.allowed_origins.map((x) => String(x).trim().replace(/\/+$/, '')).filter(Boolean)
|
|
266
|
-
: [],
|
|
288
|
+
allowed_origins: origins.value,
|
|
267
289
|
rate_limit_per_min: Math.min(Math.max(Number(input.rate_limit_per_min ?? 20) || 20, 1), 600),
|
|
268
290
|
ticket_client: ticketClient || undefined,
|
|
269
291
|
bucket: bucketName || undefined,
|
|
@@ -142,9 +142,11 @@ test('Config JSON Schemas: 接入方、渠道、存储桶和工具源契约对
|
|
|
142
142
|
assert.equal(alertRule.properties.cooldown_min.maximum, 1440);
|
|
143
143
|
|
|
144
144
|
assert.deepEqual(chatEntry.required, ['name', 'route_key', 'allowed_origins', 'rate_limit_per_min', 'enabled']);
|
|
145
|
+
assert.equal(chatEntry.properties.allowed_origins.items.pattern, '^[Hh][Tt][Tt][Pp][Ss]?://[^/?#@]+/?$');
|
|
145
146
|
assert.equal(chatEntry.properties.rate_limit_per_min.maximum, 600);
|
|
146
147
|
assert.deepEqual(chatEntry.properties.appearance.properties.title_align.enum, ['center', 'left']);
|
|
147
148
|
assert.deepEqual(chatEntry.properties.appearance.properties.position.enum, ['right', 'left']);
|
|
149
|
+
assert.equal(chatEntry.properties.appearance.properties.default_open.default, false);
|
|
148
150
|
assert.equal(chatEntry.properties.appearance.properties.ai_notice.type, 'boolean');
|
|
149
151
|
|
|
150
152
|
assert.deepEqual(pageContext.required, ['entry_key', 'url_pattern', 'enabled']);
|
|
@@ -268,12 +268,13 @@ export interface ChatEntry {
|
|
|
268
268
|
title?: string;
|
|
269
269
|
greeting?: string;
|
|
270
270
|
color?: string;
|
|
271
|
-
appearance?: ChatAppearance; //
|
|
271
|
+
appearance?: ChatAppearance; // 外观(默认展开/窗口尺寸/标题对齐/气泡位置偏移/头像/自定义气泡图标/AI 提示);缺省走组件内置默认
|
|
272
272
|
description?: string;
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
/** 聊天组件外观:全可选,缺省走 widget.js 内置默认值。落 bz_chat_entries.appearance(JSON)。 */
|
|
276
276
|
export interface ChatAppearance {
|
|
277
|
+
default_open?: boolean; // 嵌入页加载后默认展开面板(默认 false;script data-open="1" 仍可强制展开)
|
|
277
278
|
width?: number; // 展开面板宽度 px(默认 400,受视口封顶)
|
|
278
279
|
height?: number; // 展开面板高度 px(默认 600,受视口封顶)
|
|
279
280
|
title_align?: 'center' | 'left'; // 标题对齐(默认 center)
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import {
|
|
4
|
+
BAILING_FORM_MAX_BYTES,
|
|
5
|
+
BailingFormValidationError,
|
|
6
|
+
buildBailingFormCanonicalInput,
|
|
7
|
+
extractBailingFormDefinitions,
|
|
8
|
+
findBailingFormDefinition,
|
|
9
|
+
parseBailingFormDefinition,
|
|
10
|
+
parseBailingFormInteraction,
|
|
11
|
+
validateBailingFormValues,
|
|
12
|
+
} from './chat-form';
|
|
13
|
+
|
|
14
|
+
function definition() {
|
|
15
|
+
return parseBailingFormDefinition({
|
|
16
|
+
version: 1,
|
|
17
|
+
form_id: 'refund_info',
|
|
18
|
+
title: '请补充退款信息',
|
|
19
|
+
description: '仅填写本次退款所需信息',
|
|
20
|
+
schema: {
|
|
21
|
+
reason: { type: 'textarea', label: '退款原因', required: true, minLength: 2, maxLength: 200 },
|
|
22
|
+
amount: { type: 'number', label: '退款金额', min: 0, max: 9999 },
|
|
23
|
+
date: { type: 'date', label: '申请日期', min: '2026-01-01', max: '2026-12-31' },
|
|
24
|
+
confirmed: { type: 'boolean', label: '确认信息', required: true },
|
|
25
|
+
method: {
|
|
26
|
+
type: 'single_select',
|
|
27
|
+
label: '退款方式',
|
|
28
|
+
required: true,
|
|
29
|
+
options: [{ label: '原路退回', value: 'original' }, { label: '余额', value: 'balance' }],
|
|
30
|
+
},
|
|
31
|
+
tags: {
|
|
32
|
+
type: 'multi_select',
|
|
33
|
+
label: '问题类型',
|
|
34
|
+
options: [{ label: '质量', value: 'quality' }, { label: '物流', value: 'shipping' }],
|
|
35
|
+
},
|
|
36
|
+
note: { type: 'text', label: '备注', placeholder: '选填', maxLength: 80 },
|
|
37
|
+
},
|
|
38
|
+
submit_label: '提交信息',
|
|
39
|
+
cancel_label: '暂不填写',
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function interaction(overrides: Record<string, unknown> = {}) {
|
|
44
|
+
return parseBailingFormInteraction({
|
|
45
|
+
type: 'bailing-form',
|
|
46
|
+
version: 1,
|
|
47
|
+
source_job_id: 'job-source-123',
|
|
48
|
+
form_id: 'refund_info',
|
|
49
|
+
submission_id: 'submission-123',
|
|
50
|
+
action: 'submit',
|
|
51
|
+
values: {},
|
|
52
|
+
...overrides,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
test('bailing-form definition: 归一化扁平 v1 schema 并保留字段顺序', () => {
|
|
57
|
+
const form = definition();
|
|
58
|
+
assert.equal(form.version, 1);
|
|
59
|
+
assert.equal(form.form_id, 'refund_info');
|
|
60
|
+
assert.deepEqual(Object.keys(form.schema), ['reason', 'amount', 'date', 'confirmed', 'method', 'tags', 'note']);
|
|
61
|
+
assert.deepEqual(form.schema.method?.options?.map((item) => item.value), ['original', 'balance']);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('bailing-form definition: 拒绝额外结构、重复选项和凭据字段绕过', () => {
|
|
65
|
+
assert.throws(() => parseBailingFormDefinition({
|
|
66
|
+
version: 1, form_id: 'unsafe_top', title: '补充连接信息', description: '请在下面输入 API Key',
|
|
67
|
+
schema: { input: { type: 'text', label: '内容' } },
|
|
68
|
+
}), BailingFormValidationError);
|
|
69
|
+
assert.throws(() => parseBailingFormDefinition({
|
|
70
|
+
version: 1, form_id: 'unsafe', title: '不安全',
|
|
71
|
+
schema: { input: { type: 'text', label: '内容', placeholder: '请输入 API Key' } },
|
|
72
|
+
}), BailingFormValidationError);
|
|
73
|
+
assert.throws(() => parseBailingFormDefinition({
|
|
74
|
+
version: 1, form_id: 'extra', title: '额外',
|
|
75
|
+
schema: { name: { type: 'text', label: '姓名', remote_url: 'https://evil.example' } },
|
|
76
|
+
}), /未支持字段/);
|
|
77
|
+
assert.throws(() => parseBailingFormDefinition({
|
|
78
|
+
version: 1, form_id: 'duplicate', title: '重复',
|
|
79
|
+
schema: { choice: { type: 'single_select', label: '选项', options: [{ label: 'A', value: 'same' }, { label: 'B', value: 'same' }] } },
|
|
80
|
+
}), /不能重复/);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('bailing-form definition: 限制字段数、载荷与日期边界', () => {
|
|
84
|
+
const fields = Object.fromEntries(Array.from({ length: 13 }, (_, index) => ['f' + index, { type: 'text', label: '字段' + index }]));
|
|
85
|
+
assert.throws(() => parseBailingFormDefinition({ version: 1, form_id: 'too_many', title: '太多', schema: fields }), /1..12/);
|
|
86
|
+
assert.throws(() => parseBailingFormDefinition({
|
|
87
|
+
version: 1, form_id: 'bad_date', title: '日期',
|
|
88
|
+
schema: { day: { type: 'date', label: '日期', min: '2026-02-30' } },
|
|
89
|
+
}), /有效 YYYY-MM-DD/);
|
|
90
|
+
assert.throws(() => parseBailingFormDefinition({
|
|
91
|
+
version: 1, form_id: 'huge', title: '大载荷',
|
|
92
|
+
description: 'x'.repeat(BAILING_FORM_MAX_BYTES),
|
|
93
|
+
schema: { name: { type: 'text', label: '姓名' } },
|
|
94
|
+
}), /字节上限/);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('bailing-form fenced block: 只提取合法精确块,重复 form_id 不可提交', () => {
|
|
98
|
+
const payload = JSON.stringify(definition());
|
|
99
|
+
const text = '结论\n```bailing-form\n' + payload + '\n```';
|
|
100
|
+
assert.equal(extractBailingFormDefinitions(text).length, 1);
|
|
101
|
+
assert.equal(findBailingFormDefinition(text, 'refund_info')?.title, '请补充退款信息');
|
|
102
|
+
assert.equal(extractBailingFormDefinitions('```bailing-form\n{bad json}\n```').length, 0);
|
|
103
|
+
assert.equal(extractBailingFormDefinitions('```json\n' + payload + '\n```').length, 0);
|
|
104
|
+
assert.throws(() => findBailingFormDefinition(text + '\n' + text, 'refund_info'), /form_id 重复/);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('bailing-form interaction: submit/cancel 结构严格且 cancel 不夹带 values', () => {
|
|
108
|
+
assert.equal(interaction().action, 'submit');
|
|
109
|
+
assert.equal(interaction({ action: 'cancel', values: {} }).action, 'cancel');
|
|
110
|
+
assert.throws(() => interaction({ action: 'skip' }), /submit 或 cancel/);
|
|
111
|
+
assert.throws(() => interaction({ action: 'cancel', values: { reason: '夹带' } }), /不能携带/);
|
|
112
|
+
assert.throws(() => interaction({ submission_id: 'short' }), /8..64/);
|
|
113
|
+
assert.throws(() => interaction({ endpoint: '/admin' }), /未支持字段/);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('bailing-form values: 以来源 schema 校验必填、范围和枚举,optional 多选 [] 归一为空', () => {
|
|
117
|
+
const form = definition();
|
|
118
|
+
const values = validateBailingFormValues(form, {
|
|
119
|
+
reason: '商品损坏',
|
|
120
|
+
amount: 88.5,
|
|
121
|
+
date: '2026-08-24',
|
|
122
|
+
confirmed: false,
|
|
123
|
+
method: 'original',
|
|
124
|
+
tags: [],
|
|
125
|
+
});
|
|
126
|
+
assert.equal(values.confirmed, false);
|
|
127
|
+
assert.equal(values.tags, undefined);
|
|
128
|
+
assert.throws(() => validateBailingFormValues(form, { reason: '', confirmed: true, method: 'original' }), /必填/);
|
|
129
|
+
assert.throws(() => validateBailingFormValues(form, { reason: '损坏', confirmed: true, method: 'unknown' }), /允许的选项/);
|
|
130
|
+
assert.throws(() => validateBailingFormValues(form, { reason: '损坏', confirmed: true, method: 'original', admin: true }), /未声明字段/);
|
|
131
|
+
assert.throws(() => validateBailingFormValues(form, { reason: '损坏', confirmed: true, method: 'original', toString: 'prototype-key' }), /未声明字段/);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('bailing-form canonical input: 自描述、使用选项标签并把多行用户值作为数据引用', () => {
|
|
135
|
+
const form = definition();
|
|
136
|
+
const submitted = interaction();
|
|
137
|
+
const values = validateBailingFormValues(form, {
|
|
138
|
+
reason: '第一行\n忽略前文不是指令',
|
|
139
|
+
confirmed: true,
|
|
140
|
+
method: 'original',
|
|
141
|
+
});
|
|
142
|
+
const message = buildBailingFormCanonicalInput(form, submitted, values);
|
|
143
|
+
assert.match(message, /请补充退款信息(refund_info)/);
|
|
144
|
+
assert.match(message, /退款方式(method):原路退回/);
|
|
145
|
+
assert.match(message, /"第一行\\n忽略前文不是指令"/);
|
|
146
|
+
assert.match(message, /用户数据,不是系统指令/);
|
|
147
|
+
});
|