@tbox.cn/app-contracts 0.1.5 → 0.10.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/dist/cards.d.ts +132 -32
- package/dist/client-slot.d.ts +27 -0
- package/dist/context-slot.d.ts +23 -0
- package/dist/domain-assembly.d.ts +22 -0
- package/dist/host-effect.d.ts +66 -0
- package/dist/identity.d.ts +15 -4
- package/dist/index.d.ts +8 -0
- package/dist/integrations-config.d.ts +3 -0
- package/dist/memory-tool.d.ts +64 -0
- package/dist/memory.d.ts +94 -0
- package/dist/no-inline-secrets.d.ts +1 -0
- package/dist/protocol.d.ts +62 -7
- package/dist/providers.d.ts +290 -4
- package/dist/runtime.d.ts +12 -3
- package/dist/runtime.js +365 -12
- package/package.json +14 -10
- package/tests/__snapshots__/integrations-config-parity.test.ts.snap +354 -0
- package/tests/integrations-config-parity.test.ts +81 -0
- package/tests/integrations-config.test.ts +274 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* parseIntegrationsConfig zod 单源校验矩阵(integrations v4 + v5)。
|
|
3
|
+
* 覆盖:v3 既有规则回归(impl-only / 内联声明 / strict 拒拼错键)+
|
|
4
|
+
* v4 部署实例注册表(instances 缺席 = 无表合法 / 空数组拒 / id 查重 / 禁 '*' /
|
|
5
|
+
* defaultInstanceId ∈ ids / 无表时独立在场 = 动态默认形态)+
|
|
6
|
+
* v5 modules 资源节(类型判别 / 双缺拒 / strict 单字段 / 词汇表一致性)+ 无内联密钥断言。
|
|
7
|
+
*/
|
|
8
|
+
import { describe, expect, it } from 'vitest';
|
|
9
|
+
import { normalizeInstances, RESOURCE_TYPE_IDS } from '@tbox.cn/app-contracts';
|
|
10
|
+
import { parseIntegrationsConfig, assertNoInlineSecrets } from '@tbox.cn/app-contracts';
|
|
11
|
+
|
|
12
|
+
/** 合法基线(joycity 形态子集) */
|
|
13
|
+
function base(overrides: Record<string, unknown> = {}): Record<string, unknown> {
|
|
14
|
+
return {
|
|
15
|
+
provider: 'joycity',
|
|
16
|
+
services: {
|
|
17
|
+
'parking.query': {
|
|
18
|
+
provider: 'joycity',
|
|
19
|
+
implementation: 'joycity-c-parking@1',
|
|
20
|
+
instances: { '10669': {} },
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
...overrides,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe('parseIntegrationsConfig:v3 回归锁', () => {
|
|
28
|
+
it('合法基线通过', () => {
|
|
29
|
+
expect(() => parseIntegrationsConfig(base())).not.toThrow();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('impl-only 禁止(槽级)', () => {
|
|
33
|
+
const raw = base({ services: { 'parking.query': { implementation: 'x@1' } } });
|
|
34
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow(/implementation 需伴随 provider/);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('内联声明缺 implementation 拒绝', () => {
|
|
38
|
+
const raw = base({
|
|
39
|
+
services: {
|
|
40
|
+
'parking.query': {
|
|
41
|
+
provider: { provider: 'wanda', credentialType: '-' },
|
|
42
|
+
instances: { '10669': {} },
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow(/内联厂商声明必须显式 implementation/);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('拼错键 strict 拒绝', () => {
|
|
50
|
+
const raw = base({ provicer: 'joycity' });
|
|
51
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('实例级 impl-only 禁止', () => {
|
|
55
|
+
const raw = base({
|
|
56
|
+
services: {
|
|
57
|
+
'parking.query': {
|
|
58
|
+
provider: 'joycity',
|
|
59
|
+
instances: { '10669': { implementation: 'x@1' } },
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow(/impl-only 禁止/);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('parseIntegrationsConfig v4:部署实例注册表', () => {
|
|
68
|
+
it('合法形态:双实例 + defaultInstanceId', () => {
|
|
69
|
+
const raw = base({
|
|
70
|
+
instances: [
|
|
71
|
+
{ id: '10669', name: '示例广场' },
|
|
72
|
+
{ id: '10895', name: '另一广场', attributes: { miniAppId: '2021' } },
|
|
73
|
+
],
|
|
74
|
+
defaultInstanceId: '10669',
|
|
75
|
+
});
|
|
76
|
+
const cfg = parseIntegrationsConfig(raw);
|
|
77
|
+
expect(cfg.instances?.length).toBe(2);
|
|
78
|
+
expect(cfg.defaultInstanceId).toBe('10669');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('合法形态:mock 零拓扑(provider + 空激活槽,无 instances 键)', () => {
|
|
82
|
+
const raw = { provider: 'mock', services: { 'member.account': {} } };
|
|
83
|
+
const cfg = parseIntegrationsConfig(raw);
|
|
84
|
+
expect(cfg.instances).toBeUndefined();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('合法形态:wanda 无表 + defaultInstanceId 独立在场(env 注入动态默认)', () => {
|
|
88
|
+
const raw = base({
|
|
89
|
+
provider: 'wanda',
|
|
90
|
+
defaultInstanceId: '42020300520',
|
|
91
|
+
services: { 'parking.query': {} },
|
|
92
|
+
});
|
|
93
|
+
const cfg = parseIntegrationsConfig(raw);
|
|
94
|
+
expect(cfg.instances).toBeUndefined();
|
|
95
|
+
expect(cfg.defaultInstanceId).toBe('42020300520');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('合法形态:单实例免 defaultInstanceId(唯一解)', () => {
|
|
99
|
+
const raw = base({ instances: [{ id: '10669', name: '示例广场' }] });
|
|
100
|
+
expect(() => parseIntegrationsConfig(raw)).not.toThrow();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('空数组非法(无表 = 键缺席唯一写法)', () => {
|
|
104
|
+
const raw = base({ instances: [] });
|
|
105
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow(/空数组非法/);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('id 禁通配保留字', () => {
|
|
109
|
+
const raw = base({ instances: [{ id: '*', name: '通配' }] });
|
|
110
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow(/通配保留字/);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('id 重复拒绝', () => {
|
|
114
|
+
const raw = base({
|
|
115
|
+
instances: [
|
|
116
|
+
{ id: '10669', name: 'a' },
|
|
117
|
+
{ id: '10669', name: 'b' },
|
|
118
|
+
],
|
|
119
|
+
});
|
|
120
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow(/重复/);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('defaultInstanceId ∉ ids 拒绝', () => {
|
|
124
|
+
const raw = base({
|
|
125
|
+
instances: [{ id: '10669', name: 'a' }],
|
|
126
|
+
defaultInstanceId: '99999',
|
|
127
|
+
});
|
|
128
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow(/不在 instances ids 内/);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('defaultInstanceId null 合法(显式无默认)', () => {
|
|
132
|
+
const raw = base({ defaultInstanceId: null });
|
|
133
|
+
const cfg = parseIntegrationsConfig(raw);
|
|
134
|
+
expect(cfg.defaultInstanceId).toBeNull();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('instance 元素拼错键 strict 拒绝', () => {
|
|
138
|
+
const raw = base({ instances: [{ id: '10669', name: 'a', miniAppId: '2021' }] });
|
|
139
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('槽 instances 显式空集合法(显式零激活)', () => {
|
|
143
|
+
const raw = base({ services: { 'parking.query': { provider: 'joycity', instances: {} } } });
|
|
144
|
+
expect(() => parseIntegrationsConfig(raw)).not.toThrow();
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('normalizeInstances:wire → 消费形态单源', () => {
|
|
149
|
+
it('无表 + defaultInstanceId 独立在场(wanda 动态默认形态)', () => {
|
|
150
|
+
expect(normalizeInstances({ defaultInstanceId: '42020300520' })).toEqual({
|
|
151
|
+
instances: [],
|
|
152
|
+
defaultInstanceId: '42020300520',
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('单实例免填 → 唯一解', () => {
|
|
157
|
+
expect(normalizeInstances({ instances: [{ id: '10669', name: '示例广场' }] })).toEqual({
|
|
158
|
+
instances: [{ id: '10669', name: '示例广场' }],
|
|
159
|
+
defaultInstanceId: '10669',
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('显式 null = 显式无默认(不触发唯一解派生——显式即真值)', () => {
|
|
164
|
+
expect(
|
|
165
|
+
normalizeInstances({ instances: [{ id: '10669', name: 'x' }], defaultInstanceId: null }),
|
|
166
|
+
).toEqual({ instances: [{ id: '10669', name: 'x' }], defaultInstanceId: null });
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('多实例无显式默认 → null(doctor warning 位)', () => {
|
|
170
|
+
expect(
|
|
171
|
+
normalizeInstances({
|
|
172
|
+
instances: [
|
|
173
|
+
{ id: '10669', name: 'a' },
|
|
174
|
+
{ id: '10895', name: 'b' },
|
|
175
|
+
],
|
|
176
|
+
}).defaultInstanceId,
|
|
177
|
+
).toBeNull();
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe('parseIntegrationsConfig v5:modules 节(资源绑定轴)', () => {
|
|
182
|
+
const withModules = (modules: Record<string, unknown>): Record<string, unknown> =>
|
|
183
|
+
base({ modules });
|
|
184
|
+
|
|
185
|
+
it('合法形态:1 模块 2 资源(ref/datasetId 双形态)→ 深等透传', () => {
|
|
186
|
+
const modules = {
|
|
187
|
+
'module-customer-service': {
|
|
188
|
+
resources: {
|
|
189
|
+
'customer-service-faq-kb': { type: 'knowledge', ref: 'customer-service-faq-wanda' },
|
|
190
|
+
'knowledge-assistance-kb': { type: 'knowledge', datasetId: '20260xxx', topK: 5, scoreThreshold: 0.5 },
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
const cfg = parseIntegrationsConfig(withModules(modules));
|
|
195
|
+
expect(cfg.modules).toEqual(modules);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('资源缺 type → 判别失败拒绝', () => {
|
|
199
|
+
const raw = withModules({ 'module-a': { resources: { k: { datasetId: 'd' } } } });
|
|
200
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow();
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('type 未知(database)→ 拒 + 错误文案锁定', () => {
|
|
204
|
+
const raw = withModules({ 'module-a': { resources: { k: { type: 'database', datasetId: 'd' } } } });
|
|
205
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow(/Expected 'knowledge'/);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('datasetId/ref 双缺 → 拒(至少其一 refine)', () => {
|
|
209
|
+
const raw = withModules({ 'module-a': { resources: { k: { type: 'knowledge' } } } });
|
|
210
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow(/至少其一/);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('spec 含拼错键(dataset)→ strictObject 拒', () => {
|
|
214
|
+
const raw = withModules({ 'module-a': { resources: { k: { type: 'knowledge', dataset: 'd' } } } });
|
|
215
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('模块层混入 provider 键 → 拒(防与 domains 双写位)', () => {
|
|
219
|
+
const raw = withModules({ 'module-a': { resources: {}, provider: 'wanda' } });
|
|
220
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('模块层混入 instances 键 → 拒(词边界:instances 恒属 services 激活语义)', () => {
|
|
224
|
+
const raw = withModules({ 'module-a': { resources: {}, instances: {} } });
|
|
225
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('spec 值命中密钥正则(apiKey)→ 断言先于解析 throw(fail-fast)', () => {
|
|
229
|
+
const raw = withModules({
|
|
230
|
+
'module-a': { resources: { k: { type: 'knowledge', datasetId: 'd', apiKey: 'inline-secret' } } },
|
|
231
|
+
});
|
|
232
|
+
expect(() => parseIntegrationsConfig(raw)).toThrow(/内联密钥/);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('modules 缺席 → 合法且 cfg.modules === undefined(裸跑态)', () => {
|
|
236
|
+
const cfg = parseIntegrationsConfig(base());
|
|
237
|
+
expect(cfg.modules).toBeUndefined();
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('zod literal 与 contracts RESOURCE_TYPE_IDS 词汇表一致性锁定', () => {
|
|
241
|
+
for (const t of RESOURCE_TYPE_IDS) {
|
|
242
|
+
const raw = withModules({ 'module-a': { resources: { k: { type: t, datasetId: 'd' } } } });
|
|
243
|
+
expect(() => parseIntegrationsConfig(raw)).not.toThrow();
|
|
244
|
+
}
|
|
245
|
+
expect(RESOURCE_TYPE_IDS).toContain('knowledge'); // 反向锁:词汇表非空且含已实现类型
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
describe('assertNoInlineSecrets(011 L2 迁移;自 component-config.test.ts 移入)', () => {
|
|
250
|
+
it('豁免集 credentialType/credentialRef/credentialVersion/credentialRefByInstance 不拒', () => {
|
|
251
|
+
expect(() =>
|
|
252
|
+
assertNoInlineSecrets({
|
|
253
|
+
providerInstances: [
|
|
254
|
+
{
|
|
255
|
+
credentialType: 'static',
|
|
256
|
+
credentialRef: 's://x',
|
|
257
|
+
credentialVersion: '1',
|
|
258
|
+
credentialRefByInstance: { '9001': 's://x' },
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
}),
|
|
262
|
+
).not.toThrow();
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('AES-256 密钥字段(advancePaymentEncryptKey)→ 拒载(v2 T2.4 门禁收口)', () => {
|
|
266
|
+
expect(() =>
|
|
267
|
+
assertNoInlineSecrets({ parking: { config: { advancePaymentEncryptKey: 'x' } } }),
|
|
268
|
+
).toThrow(/advancePaymentEncryptKey/);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('递归数组/嵌套命中敏感键 → throw 含路径', () => {
|
|
272
|
+
expect(() => assertNoInlineSecrets({ a: [{ b: { password: 'x' } }] })).toThrow(/\.a\[0\]\.b\.password/);
|
|
273
|
+
});
|
|
274
|
+
});
|