@tbox.cn/app-toolkit 0.7.5 → 0.8.1
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/index.d.ts +1181 -1111
- package/dist/index.js +9 -9
- package/package.json +2 -2
- package/src/assembly/walk-manifests.ts +48 -10
- package/src/core/module-schema.ts +6 -0
- package/src/dto.ts +89 -68
- package/src/factory.ts +44 -57
- package/src/index.ts +10 -4
- package/src/integrations/predicate.ts +5 -9
- package/src/integrations/provider-binding.ts +83 -0
- package/src/views/app.ts +3 -1
- package/src/views/credential-types.ts +0 -1
- package/src/views/credentials.ts +3 -2
- package/src/views/integration-schemas.ts +17 -42
- package/src/views/modules.ts +14 -4
- package/src/views/provider-supply.ts +51 -0
- package/src/views/providers.ts +15 -49
- package/src/views/service-detail.ts +4 -5
- package/src/views/service-resolutions.ts +36 -13
- package/tests/credentials-view.test.ts +1 -3
- package/tests/demo-app.ts +31 -2
- package/tests/naming-alignment.test.ts +1 -1
- package/tests/provider-binding-supply.test.ts +508 -0
- package/tests/resolve-key.test.ts +4 -4
- package/tests/views.test.ts +83 -623
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { mkdirSync } from 'node:fs';
|
|
4
|
+
import { createAppToolkit, type AppToolkit } from '../src/factory.js';
|
|
5
|
+
import { invalidateContractsResolver } from '../src/core/contracts-resolver.js';
|
|
6
|
+
import {
|
|
7
|
+
createTempApp,
|
|
8
|
+
writeFakeContractsPackage,
|
|
9
|
+
linkContracts,
|
|
10
|
+
writeAppFile,
|
|
11
|
+
bumpMtime,
|
|
12
|
+
CASCADE_RESOLVE_BODY,
|
|
13
|
+
SUPPLY_AGGREGATE_BODY,
|
|
14
|
+
type TempApp,
|
|
15
|
+
} from './demo-app.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* v8 批测试:三轴同构绑定解析(ProviderBinding——「数据来源」状态服务端单源)+
|
|
19
|
+
* 供给判定端点(GET /providers/:p/supply——切换预览唯一判定源)+ 零槽自声明厂商
|
|
20
|
+
* (provider-custom 同构)+ 降级投影(N1——degrade binding 静态可算)。
|
|
21
|
+
*
|
|
22
|
+
* 协议形态钉子:
|
|
23
|
+
* module 视图 legacy 双写(provider/layer ≡ effective 投影——双写一致性断言锁定);
|
|
24
|
+
* App/Service 视图 binding 无 legacy 键(新字段无历史义务);
|
|
25
|
+
* Entry.binding 恒在场(未配置 = {null, null});
|
|
26
|
+
* supply module scope = ownedServices(跨模块 consumes 不入——绑定作用域诚实性)。
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
interface Harness {
|
|
30
|
+
app: TempApp;
|
|
31
|
+
tk: AppToolkit;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** binding 基座:root mock + module-parking(owns+consumes parking.query,模块级 wanda)+
|
|
35
|
+
* parking.query 内联 custom(弃用形态归一)+ auth.alipay-login 空槽(级联正例)。 */
|
|
36
|
+
function bindingHarness(): Harness {
|
|
37
|
+
const app = createTempApp('tbox-v8-bind-');
|
|
38
|
+
invalidateContractsResolver();
|
|
39
|
+
const store = join(app.appDir, 'contracts');
|
|
40
|
+
writeFakeContractsPackage(store, { version: '0.9.0', resolveBody: CASCADE_RESOLVE_BODY, supplyBody: SUPPLY_AGGREGATE_BODY });
|
|
41
|
+
linkContracts(app.appDir, store, { subdir: 'apps/server' });
|
|
42
|
+
mkdirSync(join(app.appDir, 'packages', 'module-parking'), { recursive: true });
|
|
43
|
+
writeAppFile(
|
|
44
|
+
app.appDir,
|
|
45
|
+
'packages/module-parking/tbox.module.json',
|
|
46
|
+
JSON.stringify({
|
|
47
|
+
schemaVersion: 1,
|
|
48
|
+
id: 'module-parking',
|
|
49
|
+
version: '0.1.0',
|
|
50
|
+
kind: 'business',
|
|
51
|
+
declare: {
|
|
52
|
+
owns: [{ service: 'parking.query' }],
|
|
53
|
+
consumes: [{ service: 'parking.query', optional: false }],
|
|
54
|
+
},
|
|
55
|
+
dependencies: { modules: [] },
|
|
56
|
+
env: [],
|
|
57
|
+
}),
|
|
58
|
+
);
|
|
59
|
+
writeAppFile(
|
|
60
|
+
app.appDir,
|
|
61
|
+
'config/integrations.json',
|
|
62
|
+
JSON.stringify({
|
|
63
|
+
provider: 'mock',
|
|
64
|
+
modules: { 'module-parking': { provider: 'wanda' } },
|
|
65
|
+
services: {
|
|
66
|
+
'parking.query': { provider: { provider: 'my-custom-api', credentialType: '-' }, implementation: 'my-custom-parking@1' },
|
|
67
|
+
'auth.alipay-login': {},
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
return { app, tk: createAppToolkit(app.appDir) };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** supply 基座:词汇 4 服务 + 三厂商供给矩阵(wanda: query+payment / joycity:
|
|
75
|
+
* query+payment+vehicle / partial: payment)+ module-parking(owns+consumes query+payment)+
|
|
76
|
+
* 跨域负例模块 module-extra(owns member.account——supply module scope 不受其 consumes 影响)。 */
|
|
77
|
+
function supplyHarness(): Harness {
|
|
78
|
+
const app = createTempApp('tbox-v8-sup-');
|
|
79
|
+
invalidateContractsResolver();
|
|
80
|
+
const store = join(app.appDir, 'contracts');
|
|
81
|
+
writeFakeContractsPackage(store, {
|
|
82
|
+
version: '0.9.0',
|
|
83
|
+
resolveBody: CASCADE_RESOLVE_BODY,
|
|
84
|
+
supplyBody: SUPPLY_AGGREGATE_BODY,
|
|
85
|
+
slots: ['parking.query', 'parking.payment', 'parking.vehicle', 'auth.alipay-login'],
|
|
86
|
+
meta: {
|
|
87
|
+
'parking.query': { name: '停车查询' },
|
|
88
|
+
'parking.payment': { name: '停车缴费' },
|
|
89
|
+
'parking.vehicle': { name: '车辆管理' },
|
|
90
|
+
'auth.alipay-login': { name: '支付宝登录' },
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
linkContracts(app.appDir, store, { subdir: 'apps/server' });
|
|
94
|
+
const providerManifest = (id: string, slots: Array<{ service: string; provider: string }>): string =>
|
|
95
|
+
JSON.stringify({
|
|
96
|
+
schemaVersion: 1,
|
|
97
|
+
id,
|
|
98
|
+
version: '0.1.0',
|
|
99
|
+
kind: 'business',
|
|
100
|
+
declare: {
|
|
101
|
+
providers: {
|
|
102
|
+
slots: slots.map((s) => ({ ...s, implementation: `${s.provider}@1`, credentialType: `${s.provider}-c` })),
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
dependencies: { modules: [] },
|
|
106
|
+
env: [],
|
|
107
|
+
});
|
|
108
|
+
mkdirSync(join(app.appDir, 'packages', 'provider-w'), { recursive: true });
|
|
109
|
+
writeAppFile(
|
|
110
|
+
app.appDir,
|
|
111
|
+
'packages/provider-w/tbox.module.json',
|
|
112
|
+
providerManifest('provider-w', [{ service: 'parking.query', provider: 'wanda' }, { service: 'parking.payment', provider: 'wanda' }]),
|
|
113
|
+
);
|
|
114
|
+
mkdirSync(join(app.appDir, 'packages', 'provider-j'), { recursive: true });
|
|
115
|
+
writeAppFile(
|
|
116
|
+
app.appDir,
|
|
117
|
+
'packages/provider-j/tbox.module.json',
|
|
118
|
+
providerManifest('provider-j', [
|
|
119
|
+
{ service: 'parking.query', provider: 'joycity' },
|
|
120
|
+
{ service: 'parking.payment', provider: 'joycity' },
|
|
121
|
+
{ service: 'parking.vehicle', provider: 'joycity' },
|
|
122
|
+
]),
|
|
123
|
+
);
|
|
124
|
+
mkdirSync(join(app.appDir, 'packages', 'provider-p'), { recursive: true });
|
|
125
|
+
writeAppFile(
|
|
126
|
+
app.appDir,
|
|
127
|
+
'packages/provider-p/tbox.module.json',
|
|
128
|
+
providerManifest('provider-p', [{ service: 'parking.payment', provider: 'partial' }]),
|
|
129
|
+
);
|
|
130
|
+
mkdirSync(join(app.appDir, 'packages', 'module-parking'), { recursive: true });
|
|
131
|
+
writeAppFile(
|
|
132
|
+
app.appDir,
|
|
133
|
+
'packages/module-parking/tbox.module.json',
|
|
134
|
+
JSON.stringify({
|
|
135
|
+
schemaVersion: 1,
|
|
136
|
+
id: 'module-parking',
|
|
137
|
+
version: '0.1.0',
|
|
138
|
+
kind: 'business',
|
|
139
|
+
declare: {
|
|
140
|
+
owns: [{ service: 'parking.query' }, { service: 'parking.payment' }],
|
|
141
|
+
consumes: [{ service: 'parking.query', optional: false }, { service: 'parking.payment', optional: true }],
|
|
142
|
+
},
|
|
143
|
+
dependencies: { modules: [] },
|
|
144
|
+
env: [],
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
147
|
+
writeAppFile(
|
|
148
|
+
app.appDir,
|
|
149
|
+
'config/integrations.json',
|
|
150
|
+
JSON.stringify({
|
|
151
|
+
provider: 'wanda',
|
|
152
|
+
modules: { 'module-parking': { provider: 'wanda' } },
|
|
153
|
+
services: { 'parking.query': { provider: 'wanda' } },
|
|
154
|
+
}),
|
|
155
|
+
);
|
|
156
|
+
return { app, tk: createAppToolkit(app.appDir) };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** 零槽自声明基座:provider-cx 包(declare.providers.id 自声明 + slots: [])——G1' 三消费点。 */
|
|
160
|
+
function zeroSlotHarness(): Harness {
|
|
161
|
+
const app = createTempApp('tbox-v8-zero-');
|
|
162
|
+
invalidateContractsResolver();
|
|
163
|
+
const store = join(app.appDir, 'contracts');
|
|
164
|
+
writeFakeContractsPackage(store, { version: '0.9.0', resolveBody: CASCADE_RESOLVE_BODY, supplyBody: SUPPLY_AGGREGATE_BODY, slots: ['parking.query'] });
|
|
165
|
+
linkContracts(app.appDir, store, { subdir: 'apps/server' });
|
|
166
|
+
mkdirSync(join(app.appDir, 'packages', 'provider-cx'), { recursive: true });
|
|
167
|
+
writeAppFile(
|
|
168
|
+
app.appDir,
|
|
169
|
+
'packages/provider-cx/tbox.module.json',
|
|
170
|
+
JSON.stringify({
|
|
171
|
+
schemaVersion: 1,
|
|
172
|
+
id: 'provider-cx',
|
|
173
|
+
name: '自定义 API',
|
|
174
|
+
version: '0.1.0',
|
|
175
|
+
kind: 'business',
|
|
176
|
+
declare: { providers: { id: 'provider-cx', slots: [] } },
|
|
177
|
+
dependencies: { modules: [] },
|
|
178
|
+
env: [],
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
181
|
+
writeAppFile(app.appDir, 'config/integrations.json', JSON.stringify({}));
|
|
182
|
+
return { app, tk: createAppToolkit(app.appDir) };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
describe('v8 ProviderBinding(三轴同构——「数据来源」状态单源)', () => {
|
|
186
|
+
it('app 轴:configured ≡ effective;inherited 恒空(无上级);无 legacy 键(新字段)', async () => {
|
|
187
|
+
const h = bindingHarness();
|
|
188
|
+
const v = await h.tk.loadApp();
|
|
189
|
+
expect(v.binding).toEqual({
|
|
190
|
+
configured: 'mock',
|
|
191
|
+
effective: { provider: 'mock', layer: 'app' },
|
|
192
|
+
inherited: { provider: null, layer: null },
|
|
193
|
+
});
|
|
194
|
+
h.app.dispose();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('module 轴:显式 configured + effective 本层 + inherited = root 回落 + legacy 双写(协议形态)', async () => {
|
|
198
|
+
const h = bindingHarness();
|
|
199
|
+
const v = await h.tk.loadModule('module-parking');
|
|
200
|
+
expect(v.binding).toEqual({
|
|
201
|
+
configured: 'wanda',
|
|
202
|
+
effective: { provider: 'wanda', layer: 'module' },
|
|
203
|
+
inherited: { provider: 'mock', layer: 'app' },
|
|
204
|
+
provider: 'wanda', // @deprecated 双写 ≡ effective.provider
|
|
205
|
+
layer: 'module', // @deprecated 双写 ≡ effective.layer
|
|
206
|
+
});
|
|
207
|
+
h.app.dispose();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('module 轴:provider 缺席(仅 config)→ effective = inherited = root 级联', async () => {
|
|
211
|
+
const h = bindingHarness();
|
|
212
|
+
writeAppFile(
|
|
213
|
+
h.app.appDir,
|
|
214
|
+
'config/integrations.json',
|
|
215
|
+
JSON.stringify({
|
|
216
|
+
provider: 'mock',
|
|
217
|
+
modules: { 'module-parking': { config: { baseUrl: 'https://x' } } },
|
|
218
|
+
services: { 'auth.alipay-login': {} },
|
|
219
|
+
}),
|
|
220
|
+
);
|
|
221
|
+
bumpMtime(join(h.app.appDir, 'config', 'integrations.json'));
|
|
222
|
+
const v = await h.tk.loadModule('module-parking');
|
|
223
|
+
expect(v.binding).toEqual({
|
|
224
|
+
configured: null,
|
|
225
|
+
effective: { provider: 'mock', layer: 'app' },
|
|
226
|
+
inherited: { provider: 'mock', layer: 'app' },
|
|
227
|
+
provider: 'mock', // legacy 双写 = effective 投影
|
|
228
|
+
layer: 'app',
|
|
229
|
+
});
|
|
230
|
+
h.app.dispose();
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('service 轴:内联声明(弃用形态)归一为 configured 名 + inherited = owner 模块绑定;无 legacy 键', async () => {
|
|
234
|
+
const h = bindingHarness();
|
|
235
|
+
const v = await h.tk.loadService('parking.query');
|
|
236
|
+
expect(v.binding).toEqual({
|
|
237
|
+
configured: 'my-custom-api',
|
|
238
|
+
effective: { provider: 'my-custom-api', layer: 'service' },
|
|
239
|
+
inherited: { provider: 'wanda', layer: 'module' },
|
|
240
|
+
});
|
|
241
|
+
h.app.dispose();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('service 轴:空槽({} 无 provider)→ 级联 owner 模块 ?? root(auth 无主 → root)', async () => {
|
|
245
|
+
const h = bindingHarness();
|
|
246
|
+
const v = await h.tk.loadService('auth.alipay-login');
|
|
247
|
+
expect(v.binding).toEqual({
|
|
248
|
+
configured: null,
|
|
249
|
+
effective: { provider: 'mock', layer: 'app' },
|
|
250
|
+
inherited: { provider: 'mock', layer: 'app' },
|
|
251
|
+
});
|
|
252
|
+
h.app.dispose();
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('service 轴:malformed(123)与空串归一 null + 级联(谓词 #5 诊断不在此吞)', async () => {
|
|
256
|
+
const h = bindingHarness();
|
|
257
|
+
writeAppFile(
|
|
258
|
+
h.app.appDir,
|
|
259
|
+
'config/integrations.json',
|
|
260
|
+
JSON.stringify({
|
|
261
|
+
provider: 'mock',
|
|
262
|
+
modules: { 'module-parking': { provider: 'wanda' } },
|
|
263
|
+
services: { 'parking.query': { provider: 123 } },
|
|
264
|
+
}),
|
|
265
|
+
);
|
|
266
|
+
bumpMtime(join(h.app.appDir, 'config', 'integrations.json'));
|
|
267
|
+
const malformed = await h.tk.loadService('parking.query');
|
|
268
|
+
expect(malformed.binding.configured).toBeNull();
|
|
269
|
+
expect(malformed.binding.effective).toEqual({ provider: 'wanda', layer: 'module' });
|
|
270
|
+
writeAppFile(
|
|
271
|
+
h.app.appDir,
|
|
272
|
+
'config/integrations.json',
|
|
273
|
+
JSON.stringify({
|
|
274
|
+
provider: 'mock',
|
|
275
|
+
modules: { 'module-parking': { provider: 'wanda' } },
|
|
276
|
+
services: { 'parking.query': { provider: '' } },
|
|
277
|
+
}),
|
|
278
|
+
);
|
|
279
|
+
bumpMtime(join(h.app.appDir, 'config', 'integrations.json'));
|
|
280
|
+
const empty = await h.tk.loadService('parking.query');
|
|
281
|
+
expect(empty.binding.configured).toBeNull();
|
|
282
|
+
expect(empty.binding.effective).toEqual({ provider: 'wanda', layer: 'module' });
|
|
283
|
+
h.app.dispose();
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe('v8 Entry.binding(求值轴双写——默认实例口径,layer 可 instance)', () => {
|
|
288
|
+
it('双写一致性:provider 有值 ⟹ provider/layer ≡ binding 投影;孤儿层(layer 在 provider 缺)= 既有口径', async () => {
|
|
289
|
+
const h = bindingHarness();
|
|
290
|
+
const batch = await h.tk.loadServiceResolutions();
|
|
291
|
+
for (const [service, entry] of Object.entries(batch.resolutions)) {
|
|
292
|
+
if (entry.provider !== undefined) {
|
|
293
|
+
// 双写一致性(P14 四等价面同源由 resolveServiceSummary 结构保证)
|
|
294
|
+
expect(entry.binding, service).toEqual({ provider: entry.provider, layer: entry.layer ?? null });
|
|
295
|
+
} else {
|
|
296
|
+
// 未配置/孤儿层:binding.provider = null;binding.layer = 派生层(含 root 孤儿 'app'——既有口径)
|
|
297
|
+
expect(entry.binding?.provider, service).toBeNull();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// 内联 custom:binding.provider = 归一名(≡ provider 字段)
|
|
301
|
+
expect(batch.resolutions['parking.query']).toMatchObject({
|
|
302
|
+
provider: 'my-custom-api',
|
|
303
|
+
binding: { provider: 'my-custom-api', layer: 'service' },
|
|
304
|
+
});
|
|
305
|
+
h.app.dispose();
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('instance 层覆盖:Entry.binding.layer = instance(求值口径独有——静态 binding 无此层)', async () => {
|
|
309
|
+
const h = bindingHarness();
|
|
310
|
+
writeAppFile(
|
|
311
|
+
h.app.appDir,
|
|
312
|
+
'config/integrations.json',
|
|
313
|
+
JSON.stringify({
|
|
314
|
+
provider: 'mock',
|
|
315
|
+
instances: [{ id: 'mall-bj-01' }],
|
|
316
|
+
defaultInstanceId: 'mall-bj-01',
|
|
317
|
+
services: { 'parking.query': { instances: { 'mall-bj-01': { provider: 'wanda' } } } },
|
|
318
|
+
}),
|
|
319
|
+
);
|
|
320
|
+
bumpMtime(join(h.app.appDir, 'config', 'integrations.json'));
|
|
321
|
+
const single = await h.tk.loadServiceResolution('parking.query');
|
|
322
|
+
// bindingHarness 无 wanda 供给 → binding-unresolved:provider 缺席(孤儿层口径),
|
|
323
|
+
// binding.layer 仍达 'instance'(deriveBindingLayer 与 layer 同源——求值口径独有层验证)
|
|
324
|
+
expect(single.resolution.status).toBe('binding-unresolved');
|
|
325
|
+
// binding.layer 恒在场且达 'instance'(求值口径独有);legacy layer 键孤儿层缺席(既有口径)
|
|
326
|
+
expect(single.resolution.binding).toEqual({ provider: null, layer: 'instance' });
|
|
327
|
+
expect(single.resolution.layer).toBeUndefined();
|
|
328
|
+
h.app.dispose();
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
describe('v8 GET /providers/:p/supply(供给判定——切换预览唯一判定源)', () => {
|
|
333
|
+
it('app scope:作用域 = resolutionKeys 单源(在册全集)+ 部分供给计数(客户端派生)', async () => {
|
|
334
|
+
const h = supplyHarness();
|
|
335
|
+
const v = await h.tk.loadProviderSupply('wanda', { kind: 'app' });
|
|
336
|
+
expect(v.scope).toEqual({ kind: 'app' });
|
|
337
|
+
expect(v.services).toEqual([
|
|
338
|
+
{ service: 'auth.alipay-login', name: '支付宝登录', supplied: false },
|
|
339
|
+
{ service: 'parking.payment', name: '停车缴费', supplied: true },
|
|
340
|
+
{ service: 'parking.query', name: '停车查询', supplied: true },
|
|
341
|
+
{ service: 'parking.vehicle', name: '车辆管理', supplied: false },
|
|
342
|
+
]);
|
|
343
|
+
h.app.dispose();
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it('app scope 防漂移:services 键集 ≡ 批量求值 resolutions 键集(resolutionKeys 单源)', async () => {
|
|
347
|
+
const h = supplyHarness();
|
|
348
|
+
const supply = await h.tk.loadProviderSupply('joycity', { kind: 'app' });
|
|
349
|
+
const resolutions = await h.tk.loadServiceResolutions();
|
|
350
|
+
expect(supply.services.map((s) => s.service)).toEqual(Object.keys(resolutions.resolutions));
|
|
351
|
+
h.app.dispose();
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('module scope:作用域 = 归属服务(declare.owns)——跨模块 consumes 不入(S1 作用域诚实性)', async () => {
|
|
355
|
+
const h = supplyHarness();
|
|
356
|
+
const v = await h.tk.loadProviderSupply('joycity', { kind: 'module', module: 'module-parking' });
|
|
357
|
+
expect(v.scope).toEqual({ kind: 'module', module: 'module-parking' });
|
|
358
|
+
expect(v.services).toEqual([
|
|
359
|
+
{ service: 'parking.payment', name: '停车缴费', supplied: true },
|
|
360
|
+
{ service: 'parking.query', name: '停车查询', supplied: true },
|
|
361
|
+
]);
|
|
362
|
+
h.app.dispose();
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('module scope 防漂移:services 键序 ≡ detail.ownedServices(moduleOwnershipWritable 单源)', async () => {
|
|
366
|
+
const h = supplyHarness();
|
|
367
|
+
const supply = await h.tk.loadProviderSupply('partial', { kind: 'module', module: 'module-parking' });
|
|
368
|
+
const detail = await h.tk.loadModule('module-parking');
|
|
369
|
+
expect(supply.services.map((s) => s.service)).toEqual(detail.ownedServices);
|
|
370
|
+
expect(supply.services.map((s) => s.supplied)).toEqual([true, false]); // 排序 payment 在前;partial 仅供 payment
|
|
371
|
+
h.app.dispose();
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it('service scope:单元素判定;任意 id 恒 200(判定非寻址——未供给 = false 非 404)', async () => {
|
|
375
|
+
const h = supplyHarness();
|
|
376
|
+
const hit = await h.tk.loadProviderSupply('joycity', { kind: 'service', service: 'parking.vehicle' });
|
|
377
|
+
expect(hit.services).toEqual([{ service: 'parking.vehicle', name: '车辆管理', supplied: true }]);
|
|
378
|
+
const miss = await h.tk.loadProviderSupply('wanda', { kind: 'service', service: 'parking.vehicle' });
|
|
379
|
+
expect(miss.services).toEqual([{ service: 'parking.vehicle', name: '车辆管理', supplied: false }]);
|
|
380
|
+
const unknown = await h.tk.loadProviderSupply('wanda', { kind: 'service', service: 'totally.unknown' });
|
|
381
|
+
expect(unknown.services).toEqual([{ service: 'totally.unknown', name: 'totally.unknown', supplied: false }]);
|
|
382
|
+
h.app.dispose();
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it('降级可用:contracts 不可用 → supply 仍 200(静态零 contracts——「数据来源」降级态存活)', async () => {
|
|
386
|
+
const app = createTempApp('tbox-v8-sup-dg-');
|
|
387
|
+
invalidateContractsResolver();
|
|
388
|
+
// 不装 contracts → resolveContractsForApp 走未安装分支(静态面照常)
|
|
389
|
+
mkdirSync(join(app.appDir, 'packages', 'provider-w'), { recursive: true });
|
|
390
|
+
writeAppFile(
|
|
391
|
+
app.appDir,
|
|
392
|
+
'packages/provider-w/tbox.module.json',
|
|
393
|
+
JSON.stringify({
|
|
394
|
+
schemaVersion: 1,
|
|
395
|
+
id: 'provider-w',
|
|
396
|
+
version: '0.1.0',
|
|
397
|
+
kind: 'business',
|
|
398
|
+
declare: { providers: { slots: [{ service: 'parking.query', provider: 'wanda', implementation: 'w@1', credentialType: '-' }] } },
|
|
399
|
+
dependencies: { modules: [] },
|
|
400
|
+
env: [],
|
|
401
|
+
}),
|
|
402
|
+
);
|
|
403
|
+
const tk = createAppToolkit(app.appDir);
|
|
404
|
+
const v = await tk.loadProviderSupply('wanda', { kind: 'service', service: 'parking.query' });
|
|
405
|
+
expect(v.services).toEqual([{ service: 'parking.query', name: 'parking.query', supplied: true }]);
|
|
406
|
+
app.dispose();
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it('边界:未知厂商 404 PROVIDER_NOT_FOUND;未知模块 404 MODULE_NOT_FOUND;scope 校验 400 先于 404', async () => {
|
|
410
|
+
const h = supplyHarness();
|
|
411
|
+
await expect(h.tk.loadProviderSupply('nope-vendor', { kind: 'app' })).rejects.toMatchObject({
|
|
412
|
+
code: 'PROVIDER_NOT_FOUND',
|
|
413
|
+
httpStatus: 404,
|
|
414
|
+
});
|
|
415
|
+
await expect(h.tk.loadProviderSupply('wanda', { kind: 'module', module: 'module-none' })).rejects.toMatchObject({
|
|
416
|
+
code: 'MODULE_NOT_FOUND',
|
|
417
|
+
httpStatus: 404,
|
|
418
|
+
});
|
|
419
|
+
await expect(h.tk.loadProviderSupply('nope-vendor', { kind: 'bogus' } as never)).rejects.toMatchObject({
|
|
420
|
+
code: 'VALIDATION_FAILED',
|
|
421
|
+
httpStatus: 400,
|
|
422
|
+
fields: ['scope'],
|
|
423
|
+
});
|
|
424
|
+
await expect(h.tk.loadProviderSupply('wanda', { kind: 'module' } as never)).rejects.toMatchObject({
|
|
425
|
+
code: 'VALIDATION_FAILED',
|
|
426
|
+
httpStatus: 400,
|
|
427
|
+
fields: ['module'],
|
|
428
|
+
});
|
|
429
|
+
await expect(h.tk.loadProviderSupply('wanda', { kind: 'service' } as never)).rejects.toMatchObject({
|
|
430
|
+
code: 'VALIDATION_FAILED',
|
|
431
|
+
httpStatus: 400,
|
|
432
|
+
fields: ['service'],
|
|
433
|
+
});
|
|
434
|
+
h.app.dispose();
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
describe('v8 零槽自声明厂商(provider-custom 同构——G1 三消费点)', () => {
|
|
439
|
+
it('清单:零槽厂商凭自声明 meta 入 /providers(local = false——空集无实现可聚合)', async () => {
|
|
440
|
+
const h = zeroSlotHarness();
|
|
441
|
+
const list = await h.tk.loadProviders();
|
|
442
|
+
const cx = list.providers.find((p) => p.provider === 'provider-cx');
|
|
443
|
+
expect(cx).toEqual({ provider: 'provider-cx', local: false, name: '自定义 API' });
|
|
444
|
+
h.app.dispose();
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('supply:厂商在、供给空 → 全 false(200 非 404);绑定后 resolution = binding-unresolved ⚠ 待接入', async () => {
|
|
448
|
+
const h = zeroSlotHarness();
|
|
449
|
+
const v = await h.tk.loadProviderSupply('provider-cx', { kind: 'service', service: 'parking.query' });
|
|
450
|
+
expect(v.services).toEqual([{ service: 'parking.query', name: 'parking.query', supplied: false }]);
|
|
451
|
+
// 绑定零槽厂商(显式中间态)→ 求值 binding-unresolved(待实施)
|
|
452
|
+
writeAppFile(h.app.appDir, 'config/integrations.json', JSON.stringify({ services: { 'parking.query': { provider: 'provider-cx' } } }));
|
|
453
|
+
bumpMtime(join(h.app.appDir, 'config', 'integrations.json'));
|
|
454
|
+
const single = await h.tk.loadServiceResolution('parking.query');
|
|
455
|
+
expect(single.resolution.status).toBe('binding-unresolved');
|
|
456
|
+
h.app.dispose();
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it('U6 守卫:零槽自声明包声明外来厂商槽 → 供给入账、meta 不污染(joycity 展示名归 joycity 包)', async () => {
|
|
460
|
+
const h = zeroSlotHarness();
|
|
461
|
+
// 真 joycity 包(meta 权威——name 大悦城)
|
|
462
|
+
mkdirSync(join(h.app.appDir, 'packages', 'provider-joycity'), { recursive: true });
|
|
463
|
+
writeAppFile(
|
|
464
|
+
h.app.appDir,
|
|
465
|
+
'packages/provider-joycity/tbox.module.json',
|
|
466
|
+
JSON.stringify({
|
|
467
|
+
schemaVersion: 1,
|
|
468
|
+
id: 'provider-joycity',
|
|
469
|
+
name: '大悦城',
|
|
470
|
+
version: '0.1.0',
|
|
471
|
+
kind: 'business',
|
|
472
|
+
declare: { providers: { slots: [{ service: 'parking.query', provider: 'joycity', implementation: 'joycity-parking@1', credentialType: 'joycity-c' }] } },
|
|
473
|
+
dependencies: { modules: [] },
|
|
474
|
+
env: [],
|
|
475
|
+
}),
|
|
476
|
+
);
|
|
477
|
+
// provider-cx 追加外来厂商槽(模拟 AI 统一落点实施真厂商缺口)
|
|
478
|
+
writeAppFile(
|
|
479
|
+
h.app.appDir,
|
|
480
|
+
'packages/provider-cx/tbox.module.json',
|
|
481
|
+
JSON.stringify({
|
|
482
|
+
schemaVersion: 1,
|
|
483
|
+
id: 'provider-cx',
|
|
484
|
+
name: '自定义 API',
|
|
485
|
+
version: '0.1.0',
|
|
486
|
+
kind: 'business',
|
|
487
|
+
declare: {
|
|
488
|
+
providers: {
|
|
489
|
+
id: 'provider-cx',
|
|
490
|
+
slots: [{ service: 'auth.alipay-login', provider: 'joycity', implementation: 'joycity-auth@1', credentialType: 'joycity-c' }],
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
dependencies: { modules: [] },
|
|
494
|
+
env: [],
|
|
495
|
+
}),
|
|
496
|
+
);
|
|
497
|
+
bumpMtime(join(h.app.appDir, 'packages/provider-cx/tbox.module.json'));
|
|
498
|
+
const list = await h.tk.loadProviders();
|
|
499
|
+
const cx = list.providers.find((p) => p.provider === 'provider-cx');
|
|
500
|
+
const joy = list.providers.find((p) => p.provider === 'joycity');
|
|
501
|
+
expect(cx).toBeDefined();
|
|
502
|
+
expect(joy).toBeDefined();
|
|
503
|
+
expect(joy?.name).toBe('大悦城'); // joycity 包 meta 首声明胜出——provider-cx 外来槽不污染
|
|
504
|
+
const v = await h.tk.loadProviderSupply('joycity', { kind: 'service', service: 'auth.alipay-login' });
|
|
505
|
+
expect(v.services[0]?.supplied).toBe(true);
|
|
506
|
+
h.app.dispose();
|
|
507
|
+
});
|
|
508
|
+
});
|
|
@@ -35,7 +35,7 @@ function mod(id: string, name?: string): WalkModuleInfo {
|
|
|
35
35
|
function walk(overrides: Partial<WalkManifestsResult> = {}): WalkManifestsResult {
|
|
36
36
|
return {
|
|
37
37
|
modules: [],
|
|
38
|
-
catalog: { providers: {}, services: {}, credentialTypes: {} },
|
|
38
|
+
catalog: { providers: {}, services: {}, credentialTypes: {}, vendorMeta: {} },
|
|
39
39
|
serviceSchemas: {},
|
|
40
40
|
vocabulary: [],
|
|
41
41
|
slotMeta: {},
|
|
@@ -91,7 +91,7 @@ describe('resolveServiceKey(服务双键)', () => {
|
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
it('demand 侧命中(catalog.services)', () => {
|
|
94
|
-
const w = walk({ catalog: { providers: {}, services: { 'auth.x': { optional: true, defaults: [], owners: [] } }, credentialTypes: {} } });
|
|
94
|
+
const w = walk({ catalog: { providers: {}, services: { 'auth.x': { optional: true, defaults: [], owners: [] } }, credentialTypes: {}, vendorMeta: {} } });
|
|
95
95
|
expect(resolveServiceKey(w, [], 'auth.x')).toBe('auth.x');
|
|
96
96
|
});
|
|
97
97
|
|
|
@@ -100,7 +100,7 @@ describe('resolveServiceKey(服务双键)', () => {
|
|
|
100
100
|
catalog: {
|
|
101
101
|
providers: { mock: { 'mock-p@1': { provider: 'mock', implementation: 'mock-p@1', credentialType: '-', owner: '@app/provider-mock', services: ['parking.query'] } } },
|
|
102
102
|
services: {},
|
|
103
|
-
credentialTypes: {},
|
|
103
|
+
credentialTypes: {}, vendorMeta: {},
|
|
104
104
|
},
|
|
105
105
|
});
|
|
106
106
|
expect(resolveServiceKey(w, [], 'parking.query')).toBe('parking.query');
|
|
@@ -121,7 +121,7 @@ describe('resolveServiceKey(服务双键)', () => {
|
|
|
121
121
|
it('展示名 demand meta 源命中(词汇缺席回落)', () => {
|
|
122
122
|
const w = walk({
|
|
123
123
|
vocabulary: ['auth.x'],
|
|
124
|
-
catalog: { providers: {}, services: { 'auth.x': { optional: true, defaults: [], name: '登录', owners: [] } }, credentialTypes: {} },
|
|
124
|
+
catalog: { providers: {}, services: { 'auth.x': { optional: true, defaults: [], name: '登录', owners: [] } }, credentialTypes: {}, vendorMeta: {} },
|
|
125
125
|
});
|
|
126
126
|
expect(resolveServiceKey(w, [], '登录')).toBe('auth.x');
|
|
127
127
|
});
|