@tbox.cn/app-toolkit 0.8.5 → 0.8.7
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 +42 -15
- package/dist/index.js +9 -9
- package/package.json +2 -2
- package/src/assembly/walk-manifests.ts +26 -11
- package/src/core/module-schema.ts +6 -0
- package/src/dto.ts +8 -5
- package/src/factory.ts +20 -3
- package/src/integrations/predicate-io.ts +7 -1
- package/src/integrations/predicate.ts +4 -2
- package/src/integrations/write.ts +3 -1
- package/src/views/modules.ts +4 -2
- package/src/views/providers.ts +29 -3
- package/tests/keyset-lockstep.test.ts +2 -1
- package/tests/module-resources.test.ts +2 -2
- package/tests/predicate-credential-refs.test.ts +96 -0
- package/tests/provider-selection-scope.test.ts +363 -0
- package/tests/vendor-schema-keywords.test.ts +20 -2
- package/tests/views.test.ts +19 -0
- package/tests/write-core.test.ts +29 -0
|
@@ -135,13 +135,16 @@ export interface WalkCatalog {
|
|
|
135
135
|
>;
|
|
136
136
|
credentialTypes: Record<string, { owner: string; packageDir: string; credentialSchema?: string }>;
|
|
137
137
|
/** 厂商展示元数据单源(v8——全厂商统一,slots 厂商 + `declare.providers.id` 零槽自声明同路径;
|
|
138
|
-
* 首声明胜出与 owner 同语义。U6 守卫:自声明包声明外来厂商槽 → 供给照常贡献、meta 不附着)。
|
|
139
|
-
|
|
138
|
+
* 首声明胜出与 owner 同语义。U6 守卫:自声明包声明外来厂商槽 → 供给照常贡献、meta 不附着)。
|
|
139
|
+
* selectionScope(任务12 可选协议):仅 'supplied-services' 受限时在场('all'/缺席同义恒
|
|
140
|
+
* 完整清单)——来源恒为厂商**自声明**(declare.providers 顶层字段,与 id 同块);槽贡献
|
|
141
|
+
* 不携带(防外来厂商策略附着),首有效声明胜出(??=)。 */
|
|
142
|
+
vendorMeta: Record<string, { owner: string; name?: string; description?: string; selectionScope?: 'supplied-services' }>;
|
|
140
143
|
}
|
|
141
144
|
|
|
142
145
|
/** loose 允许的 declare 局部结构(本地声明——解跨模块类型身份耦合,TS2719 防线) */
|
|
143
|
-
|
|
144
|
-
providers?: { id?: string; slots?: ProviderSlotContrib[] };
|
|
146
|
+
type LooseDeclare = {
|
|
147
|
+
providers?: { id?: string; selectionScope?: 'all' | 'supplied-services'; slots?: ProviderSlotContrib[] };
|
|
145
148
|
consumes?: Array<{
|
|
146
149
|
service: string;
|
|
147
150
|
optional?: boolean;
|
|
@@ -378,14 +381,26 @@ export function walkManifests(appDir: string, cache?: FileCache): WalkManifestsR
|
|
|
378
381
|
};
|
|
379
382
|
|
|
380
383
|
/** v8 零槽自声明:`declare.providers.id` 厂商入 catalog(空 impl map——供给判定
|
|
381
|
-
* 「厂商在、供给空」语义,绑定 → binding-unresolved 待实施 ⚠)+ vendorMeta 首声明登记。
|
|
382
|
-
|
|
384
|
+
* 「厂商在、供给空」语义,绑定 → binding-unresolved 待实施 ⚠)+ vendorMeta 首声明登记。
|
|
385
|
+
* selectionScope(任务12):**范围随厂商首声明一并确定——缺省 all 也是有效声明**
|
|
386
|
+
* (首包未写/写 all → 恒完整清单语义,后包 supplied-services 不得补入锁定;首包
|
|
387
|
+
* restricted → 后包 all 亦不覆盖——两方向后声明均无效)。仅 'supplied-
|
|
388
|
+
* services' 受限值落 meta;槽贡献永不携带(U6 同源隔离);slots 首建的 vendorMeta
|
|
389
|
+
* 对后到自声明同样构成首声明(visible 轴不因通道不同而重开)。 */
|
|
390
|
+
const ensureSelfVendor = (
|
|
391
|
+
id: string,
|
|
392
|
+
owner: string,
|
|
393
|
+
modMeta?: SlotMeta,
|
|
394
|
+
selectionScope?: 'all' | 'supplied-services',
|
|
395
|
+
): void => {
|
|
383
396
|
catalog.providers[id] ??= {};
|
|
384
|
-
catalog.vendorMeta[id]
|
|
397
|
+
const existed = catalog.vendorMeta[id] !== undefined; // 首声明(含 slots 通道先建)
|
|
398
|
+
const meta = (catalog.vendorMeta[id] ??= {
|
|
385
399
|
owner,
|
|
386
400
|
...(modMeta?.name ? { name: modMeta.name } : {}),
|
|
387
401
|
...(modMeta?.description ? { description: modMeta.description } : {}),
|
|
388
|
-
};
|
|
402
|
+
});
|
|
403
|
+
if (!existed && selectionScope === 'supplied-services') meta.selectionScope = 'supplied-services';
|
|
389
404
|
};
|
|
390
405
|
|
|
391
406
|
/** 厂商展示元数据(strict manifest descriptor 透传——loose 形态无 descriptor → undefined) */
|
|
@@ -480,7 +495,7 @@ export function walkManifests(appDir: string, cache?: FileCache): WalkManifestsR
|
|
|
480
495
|
}
|
|
481
496
|
const slots = declare?.providers?.slots ?? [];
|
|
482
497
|
const selfId = declare?.providers?.id;
|
|
483
|
-
if (selfId) ensureSelfVendor(selfId, entry.package, modMetaOf(manifest));
|
|
498
|
+
if (selfId) ensureSelfVendor(selfId, entry.package, modMetaOf(manifest), declare?.providers?.selectionScope);
|
|
484
499
|
if (slots.length) addSlots(slots, entry.package, dir, modMetaOf(manifest), selfId);
|
|
485
500
|
const consumes = declare?.consumes ?? [];
|
|
486
501
|
for (const need of consumes) addServiceConsume(need, entry.package);
|
|
@@ -503,7 +518,7 @@ export function walkManifests(appDir: string, cache?: FileCache): WalkManifestsR
|
|
|
503
518
|
const declare = declareOf(manifest);
|
|
504
519
|
const slots = declare?.providers?.slots ?? [];
|
|
505
520
|
const selfId = declare?.providers?.id;
|
|
506
|
-
if (selfId) ensureSelfVendor(selfId, pkg, modMetaOf(manifest));
|
|
521
|
+
if (selfId) ensureSelfVendor(selfId, pkg, modMetaOf(manifest), declare?.providers?.selectionScope);
|
|
507
522
|
if (slots.length) addSlots(slots, pkg, dir, modMetaOf(manifest), selfId);
|
|
508
523
|
const consumes = declare?.consumes ?? [];
|
|
509
524
|
for (const need of consumes) addServiceConsume(need, pkg);
|
|
@@ -539,7 +554,7 @@ export function walkManifests(appDir: string, cache?: FileCache): WalkManifestsR
|
|
|
539
554
|
}
|
|
540
555
|
const slots = declare?.providers?.slots ?? [];
|
|
541
556
|
const selfId = declare?.providers?.id;
|
|
542
|
-
if (selfId) ensureSelfVendor(selfId, `@app/${modId}`, modMetaOf(manifest));
|
|
557
|
+
if (selfId) ensureSelfVendor(selfId, `@app/${modId}`, modMetaOf(manifest), declare?.providers?.selectionScope);
|
|
543
558
|
if (slots.length) addSlots(slots, `@app/${modId}`, dir, modMetaOf(manifest), selfId);
|
|
544
559
|
const consumes = declare?.consumes ?? [];
|
|
545
560
|
for (const need of consumes) addServiceConsume(need, `@app/${modId}`);
|
|
@@ -139,6 +139,12 @@ export const moduleDescriptorSchema = z
|
|
|
139
139
|
.string()
|
|
140
140
|
.regex(SAFE_NAME_PATTERN, 'provider 名含非法字符(需 /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/)')
|
|
141
141
|
.optional(),
|
|
142
|
+
/** 厂商候选范围策略自声明(任务12 可选协议):缺席/='all' ——候选清单恒完整(
|
|
143
|
+
* 缺省语义由消费端解释——walk/vendorMeta 仅显式 'supplied-services' 生效);
|
|
144
|
+
* 'supplied-services' = 厂商仅在供给足迹与请求范围相交时进入限定候选清单。
|
|
145
|
+
* 策略只随**自声明厂商**(id === 本包厂商)进 vendorMeta——槽贡献
|
|
146
|
+
* (slot.provider 为外来厂商)不附着(U6 同源隔离,「跨厂商不得携带策略」)。 */
|
|
147
|
+
selectionScope: z.enum(['all', 'supplied-services']).optional(),
|
|
142
148
|
slots: z.array(providerSlotContribSchema).default([]),
|
|
143
149
|
})
|
|
144
150
|
.default({}),
|
package/src/dto.ts
CHANGED
|
@@ -100,7 +100,7 @@ export interface ModuleDetailView {
|
|
|
100
100
|
/** v6 所有权模型:模块归属服务(declare.owns 展平,排序;零归属 = [])——
|
|
101
101
|
* v5 domainKeys 退役(破坏性更名;面板 presence-detection 双读义务见 api.md §3) */
|
|
102
102
|
ownedServices: string[];
|
|
103
|
-
/** modules[install id] 集成位原值(provider/config
|
|
103
|
+
/** modules[install id] 集成位原值(provider/config/credentialRef——共享连接归属层三键;resources 不投影——见 resources 字段);未配置 = null */
|
|
104
104
|
integration: ModuleIntegrationNode | null;
|
|
105
105
|
/** 模块资源只读镜像(N2 读半边——写侧 resources 恒保全;含 ref 台账展开态 resolvedDatasetId);
|
|
106
106
|
* 无模块键/无资源节 = null */
|
|
@@ -293,16 +293,19 @@ export const APP_INTEGRATION_NODE_KEYS = [
|
|
|
293
293
|
'defaultInstanceId',
|
|
294
294
|
] as const;
|
|
295
295
|
|
|
296
|
-
/** 模块集成位节点(v6——provider 绑定默认 + config
|
|
297
|
-
*
|
|
296
|
+
/** 模块集成位节点(v6——provider 绑定默认 + config 级联层 + credentialRef 共享凭据归属层
|
|
297
|
+
* (contracts ModuleConfig.credentialRef——连接三件套整组共享,「连接只配一次」);
|
|
298
|
+
* resources 不投影不写——集成位编辑恒保全资源节,N2) */
|
|
298
299
|
export interface ModuleIntegrationNode {
|
|
299
300
|
provider?: string;
|
|
300
301
|
config?: Record<string, unknown>;
|
|
302
|
+
credentialRef?: string;
|
|
301
303
|
}
|
|
302
304
|
|
|
303
305
|
/** ModuleIntegrationNode 可写键集单源(v6——write applyModule 全量替换白名单
|
|
304
|
-
* (键集外 400;resources 恒随既有节点保全)+ views/modules 投影(GET ≡ PUT
|
|
305
|
-
|
|
306
|
+
* (键集外 400;resources 恒随既有节点保全)+ views/modules 投影(GET ≡ PUT,三同构;
|
|
307
|
+
* 锁步约束同 SERVICE_INTEGRATION_NODE_KEYS——须 ⊆ contracts zod 节点 schema)) */
|
|
308
|
+
export const MODULE_INTEGRATION_NODE_KEYS = ['provider', 'config', 'credentialRef'] as const;
|
|
306
309
|
|
|
307
310
|
/** ServiceIntegrationNode 可写键集单源(applyService 节点键纪律白名单——assertNodeKeys
|
|
308
311
|
* 无条件静态防线,zod 未知键拒绝语义前移,两态一致 400;0.8.2 降级写批新增。
|
package/src/factory.ts
CHANGED
|
@@ -115,6 +115,16 @@ function assertSupplyScope(scope: ProviderSupplyScope): void {
|
|
|
115
115
|
if (kind === 'module' && (typeof (scope as { module?: unknown }).module !== 'string' || (scope as { module: string }).module.length === 0)) {
|
|
116
116
|
throw new AppToolkitError('VALIDATION_FAILED', 400, 'scope=module 需携带非空 module 参数', ['module']);
|
|
117
117
|
}
|
|
118
|
+
const extra = (scope as { module?: unknown; service?: unknown });
|
|
119
|
+
if (kind === 'module' && extra.service !== undefined) {
|
|
120
|
+
throw new AppToolkitError('VALIDATION_FAILED', 400, 'scope=module 不得携带 service 伴随参数(组合互斥——参数与 scope 不匹配)', ['scope']);
|
|
121
|
+
}
|
|
122
|
+
if (kind === 'service' && extra.module !== undefined) {
|
|
123
|
+
throw new AppToolkitError('VALIDATION_FAILED', 400, 'scope=service 不得携带 module 伴随参数(组合互斥——参数与 scope 不匹配)', ['scope']);
|
|
124
|
+
}
|
|
125
|
+
if (kind === 'app' && (extra.module !== undefined || extra.service !== undefined)) {
|
|
126
|
+
throw new AppToolkitError('VALIDATION_FAILED', 400, 'scope=app 不接受 module/service 伴随参数', ['scope']);
|
|
127
|
+
}
|
|
118
128
|
if (kind === 'service' && (typeof (scope as { service?: unknown }).service !== 'string' || (scope as { service: string }).service.length === 0)) {
|
|
119
129
|
throw new AppToolkitError('VALIDATION_FAILED', 400, 'scope=service 需携带非空 service 参数', ['service']);
|
|
120
130
|
}
|
|
@@ -132,7 +142,13 @@ export interface AppToolkitRead {
|
|
|
132
142
|
loadService(service: string, o?: { include?: string[] }): Promise<ServiceDetail>;
|
|
133
143
|
loadServiceResolutions(services?: string[]): Promise<ServiceResolutionsView>;
|
|
134
144
|
loadServiceResolution(service: string): Promise<ServiceResolutionDetail>;
|
|
135
|
-
|
|
145
|
+
/** GET /providers(v8 完整清单;任务12 可选 scope 限定):缺省/`{}` = 完整在册清单
|
|
146
|
+
* (忽略候选范围策略——成员、字段和排序保持当前行为);`{scope}` = 限定候选清单
|
|
147
|
+
* (supplied-services 受限厂商按供给足迹与范围相交筛选;无策略厂商恒保留)。
|
|
148
|
+
* scope 显式请求参数(不从其他来源推断);错误矩阵沿 loadProviderSupply:
|
|
149
|
+
* 未知 kind/空值/伴随参数缺席 → 400 fields 指向出错参数;scope=module 未安装
|
|
150
|
+
* 模块 → 404 MODULE_NOT_FOUND(参数错误先于资源查询)。additive——原调用零变化。 */
|
|
151
|
+
loadProviders(o?: { scope?: ProviderSupplyScope }): Promise<ProvidersView>;
|
|
136
152
|
/** GET /providers/:p/supply?scope=…(v8——供给判定;切换预览唯一判定源,前端零关系计算)。
|
|
137
153
|
* scope 显式判别联合;provider ∉ catalog → 404;scope=module 未装 → 404;
|
|
138
154
|
* scope=service 任意 id 恒 200(判定非寻址)。 */
|
|
@@ -341,9 +357,10 @@ export function createAppToolkit(appDir: string, options: AppToolkitOptions = {}
|
|
|
341
357
|
const issues = await predicateIssues();
|
|
342
358
|
return loadServiceResolutionDetail(serviceId, snap, issues);
|
|
343
359
|
},
|
|
344
|
-
async loadProviders() {
|
|
360
|
+
async loadProviders(o?: { scope?: ProviderSupplyScope }) {
|
|
345
361
|
const contracts = await resolveContractsForApp(appDir);
|
|
346
|
-
|
|
362
|
+
if (o?.scope !== undefined) assertSupplyScope(o.scope);
|
|
363
|
+
return loadProvidersView(snapshot(contracts), o?.scope);
|
|
347
364
|
},
|
|
348
365
|
// v8 供给判定(静态零 contracts;scope 校验单点在本方法内——400 先于 404)
|
|
349
366
|
async loadProviderSupply(provider: string, scope: ProviderSupplyScope): Promise<ProviderSupplyView> {
|
|
@@ -150,12 +150,15 @@ export function buildPredicateAssembly(
|
|
|
150
150
|
|
|
151
151
|
const ig = integrations as {
|
|
152
152
|
services?: Record<string, { provider?: unknown; credentialRef?: unknown; instances?: Record<string, { provider?: unknown; credentialRef?: unknown }> }>;
|
|
153
|
+
modules?: Record<string, { credentialRef?: unknown }>;
|
|
153
154
|
credentialRefByInstance?: Record<string, unknown>;
|
|
154
155
|
credentialRef?: unknown;
|
|
155
156
|
instances?: unknown;
|
|
156
157
|
};
|
|
157
158
|
|
|
158
|
-
// ── #1 effective 候选 stem 收集(槽级 + 实例级 +
|
|
159
|
+
// ── #1 effective 候选 stem 收集(槽级 + 实例级 + modules[owner] 归属层 + root ByInstance +
|
|
160
|
+
// root 标量;env 通道兜底)——归属层 credentialRef 与绑定组/config 同层共担(contracts
|
|
161
|
+
// 归属链补全),文件/环境两通道探测同其余层(模块层放的不存在凭据同样 CREDENTIAL_FILE_MISSING) ──
|
|
159
162
|
const refs: string[] = [];
|
|
160
163
|
const pushRef = (v: unknown): void => {
|
|
161
164
|
if (typeof v === 'string' && v.startsWith('secret://')) refs.push(v);
|
|
@@ -168,6 +171,9 @@ export function buildPredicateAssembly(
|
|
|
168
171
|
}
|
|
169
172
|
}
|
|
170
173
|
}
|
|
174
|
+
for (const mod of Object.values(ig.modules ?? {})) {
|
|
175
|
+
if (mod && typeof mod === 'object') pushRef(mod.credentialRef);
|
|
176
|
+
}
|
|
171
177
|
for (const v of Object.values(ig.credentialRefByInstance ?? {})) pushRef(v);
|
|
172
178
|
pushRef(ig.credentialRef);
|
|
173
179
|
const credentialFileMissing: Record<string, boolean> = {};
|
|
@@ -111,7 +111,7 @@ export interface IntegrationServicePredicateInput {
|
|
|
111
111
|
/** v4 默认实例(normalizeInstances 解析语义:显式 ?? 单候选唯一解) */
|
|
112
112
|
defaultInstanceId?: string | null;
|
|
113
113
|
/** v6 模块集成位(modules 节三键——宽松透传;严格 zod 归模板 loader) */
|
|
114
|
-
modules?: Record<string, { provider?: string; config?: Record<string, unknown>; resources?: Record<string, { type?: unknown }> }>;
|
|
114
|
+
modules?: Record<string, { provider?: string; config?: Record<string, unknown>; credentialRef?: string; resources?: Record<string, { type?: unknown }> }>;
|
|
115
115
|
};
|
|
116
116
|
/** 已声明供给(`${vendor}\u0000${implementation}` → 槽集合;credentialType 供 #2/#6 绑定侧对齐) */
|
|
117
117
|
suppliedProviders: Record<string, { services: string[]; owner: string; credentialType?: string }>;
|
|
@@ -265,7 +265,9 @@ export function evaluateIntegrationServices(
|
|
|
265
265
|
for (const [serviceId, service] of Object.entries(integrations.services)) {
|
|
266
266
|
for (const [instanceId, instance] of Object.entries(service.instances ?? {})) {
|
|
267
267
|
if (instance.enabled === false) continue;
|
|
268
|
-
const
|
|
268
|
+
const owner = ownership?.[serviceId];
|
|
269
|
+
const moduleRef = owner != null ? integrations.modules?.[owner]?.credentialRef : undefined;
|
|
270
|
+
const ref = instance.credentialRef ?? service.credentialRef ?? moduleRef
|
|
269
271
|
?? integrations.credentialRefByInstance?.[instanceId] ?? integrations.credentialRef;
|
|
270
272
|
if (typeof ref !== 'string' || !ref.startsWith('secret://')) continue;
|
|
271
273
|
const stem = ref.slice('secret://'.length);
|
|
@@ -309,7 +309,9 @@ export function createWriteCore(appDir: string, opts: WriteCoreOptions = {}): Wr
|
|
|
309
309
|
const written = integrationsWritten || credentialsWritten;
|
|
310
310
|
// 孤儿凭据写后对账(api.md §4.13 承诺追平——「覆盖 DELETE 与 PUT 替换两类来源」;三 PUT 写路径
|
|
311
311
|
// finalize 单点收口,未来第四写方法自动继承)。dryRun(written 蕴含 !dryRun)与 no-diff
|
|
312
|
-
// (finalize 前短路 return)天然跳过;applyModule
|
|
312
|
+
// (finalize 前短路 return)天然跳过;applyModule 节点键为 provider/config/credentialRef
|
|
313
|
+
// ——credentialRef 是机密引用(引用落 integrations.json,真值恒走凭据旁路),无凭据文件
|
|
314
|
+
// 写动作,对账仍零新增比对项,无害捎带。
|
|
313
315
|
if (written) issues.push(...reconcileOrphanCredentials(appDir));
|
|
314
316
|
const restartScheduled = written && onApplied !== undefined;
|
|
315
317
|
if (restartScheduled) onApplied?.();
|
package/src/views/modules.ts
CHANGED
|
@@ -132,8 +132,9 @@ export function loadModuleDetailView(snapshot: ViewSnapshot, moduleId: string):
|
|
|
132
132
|
...[...new Set(w.ownedServices)].filter((service) => !consumed.has(service)).map((service) => toDemand(service, false)),
|
|
133
133
|
];
|
|
134
134
|
const modulesNode = (snapshot.integrations as { modules?: Record<string, unknown> } | null)?.modules ?? {};
|
|
135
|
-
// integration = modules[install id] 集成位投影(编辑预填源;provider/config
|
|
136
|
-
//
|
|
135
|
+
// integration = modules[install id] 集成位投影(编辑预填源;provider/config/credentialRef
|
|
136
|
+
// 三键 ≡ MODULE_INTEGRATION_NODE_KEYS(GET ≡ PUT 三同构——共享连接归属层凭据可经配置
|
|
137
|
+
// 面维护);resources 不投影不写,N2);未配置 = null
|
|
137
138
|
const rawNode = modulesNode[moduleId] as Record<string, unknown> | undefined;
|
|
138
139
|
const integration: ModuleDetailView['integration'] = rawNode
|
|
139
140
|
? {
|
|
@@ -141,6 +142,7 @@ export function loadModuleDetailView(snapshot: ViewSnapshot, moduleId: string):
|
|
|
141
142
|
...(rawNode.config && typeof rawNode.config === 'object' && !Array.isArray(rawNode.config)
|
|
142
143
|
? { config: rawNode.config as Record<string, unknown> }
|
|
143
144
|
: {}),
|
|
145
|
+
...(typeof rawNode.credentialRef === 'string' ? { credentialRef: rawNode.credentialRef } : {}),
|
|
144
146
|
}
|
|
145
147
|
: null;
|
|
146
148
|
// v8 三轴同构:configured/effective/inherited(moduleProviderBinding 单源);
|
package/src/views/providers.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { ProviderEntry, ProviderServiceDetail, ProvidersView } from '../dto.js';
|
|
1
|
+
import type { ProviderEntry, ProviderServiceDetail, ProviderSupplyScope, ProvidersView } from '../dto.js';
|
|
2
2
|
import { AppToolkitError } from '../core/errors.js';
|
|
3
3
|
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
4
4
|
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
5
|
+
import { moduleOwnershipWritable, providerFootprint } from '../integrations/module-binding.js';
|
|
5
6
|
import type { ViewSnapshot } from './context.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -11,14 +12,39 @@ import type { ViewSnapshot } from './context.js';
|
|
|
11
12
|
* 静态端点零求值(铁律 #3)。
|
|
12
13
|
*/
|
|
13
14
|
|
|
15
|
+
/** 受限候选供应商可见性(selectionScope='supplied-services';任务12——协议 api.md
|
|
16
|
+
* 「可选的候选范围扩展」):scope 缺席恒可见(无参调用=完整清单本行为);
|
|
17
|
+
* app=排除;module=供给足迹 ∩ 模块 owns 服务非空;service=供给足迹命中该服务。
|
|
18
|
+
* service 判定过滤而非寻址——未知 service id 恒可查(未受限供应商恒保留)。 */
|
|
19
|
+
function restrictedProviderVisible(snapshot: ViewSnapshot, provider: string, scope: ProviderSupplyScope): boolean {
|
|
20
|
+
const footprint = new Set(providerFootprint(snapshot.catalog, provider));
|
|
21
|
+
if (scope.kind === 'app') return false;
|
|
22
|
+
if (scope.kind === 'service') return footprint.has(scope.service);
|
|
23
|
+
const mod = snapshot.walk.modules.find((m) => m.id === scope.module);
|
|
24
|
+
if (!mod) throw new AppToolkitError('MODULE_NOT_FOUND', 404, `模块 ${scope.module} 非已装模块`);
|
|
25
|
+
const owned = moduleOwnershipWritable(snapshot.walk, mod).ownedServices;
|
|
26
|
+
return owned.some((service) => footprint.has(service));
|
|
27
|
+
}
|
|
28
|
+
|
|
14
29
|
/** GET /providers:厂商基本信息(vendorMeta 单源——slots 厂商 + 零槽自声明厂商同路径;
|
|
15
|
-
* 零槽厂商 = 空 impl map + 自声明 meta(supply
|
|
16
|
-
|
|
30
|
+
* 零槽厂商 = 空 impl map + 自声明 meta(supply 判定「厂商在、供给空」语义)。
|
|
31
|
+
* scope(任务12 可选):限定候选清单——仅 supplied-services 受限厂商参与筛选;
|
|
32
|
+
* 无策略厂商恒保留;成员/字段/排序与完整清单同构(响应不新增必填字段,相对排序保持)。 */
|
|
33
|
+
export function loadProvidersView(snapshot: ViewSnapshot, scope?: ProviderSupplyScope): ProvidersView {
|
|
34
|
+
// module scope 模块存在性校验先于清单遍历(&先于任何筛选判定)——全 all/空清单时
|
|
35
|
+
// 未知模块同样 404(协议矩阵「scope=module 未装 → 404;参数错误先于资源查询」的
|
|
36
|
+
// 完整语义,不依赖受限供应商在场才走到校验——模块校验先于遍历独立成立)。
|
|
37
|
+
if (scope?.kind === 'module' && !snapshot.walk.modules.some((m) => m.id === scope.module)) {
|
|
38
|
+
throw new AppToolkitError('MODULE_NOT_FOUND', 404, `模块 ${scope.module} 非已装模块`);
|
|
39
|
+
}
|
|
17
40
|
const providers: ProviderEntry[] = [];
|
|
18
41
|
for (const [provider, impls] of Object.entries(snapshot.catalog.providers)) {
|
|
19
42
|
const entries = Object.values(impls);
|
|
20
43
|
const meta = snapshot.catalog.vendorMeta[provider];
|
|
21
44
|
if (entries.length === 0 && !meta) continue;
|
|
45
|
+
if (scope && meta?.selectionScope === 'supplied-services' && !restrictedProviderVisible(snapshot, provider, scope)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
22
48
|
providers.push({
|
|
23
49
|
provider,
|
|
24
50
|
// 零槽厂商(空 entries)非 local(local 旗标语义 = 供给实现级聚合——空集无实现可聚合)
|
|
@@ -91,7 +91,8 @@ describe.skipIf(parseIntegrationsConfig === undefined)('键集-zod 锁步(asse
|
|
|
91
91
|
it('module 节点:MODULE_INTEGRATION_NODE_KEYS 全键过 zod;未知键被 zod 拒', () => {
|
|
92
92
|
const mod: Record<string, unknown> = {};
|
|
93
93
|
for (const k of MODULE_INTEGRATION_NODE_KEYS) {
|
|
94
|
-
|
|
94
|
+
// 标量键给标量形态(provider/credentialRef = string;config = record)
|
|
95
|
+
mod[k] = k === 'config' ? {} : (k === 'provider' || k === 'credentialRef') ? 'secret://x' : {};
|
|
95
96
|
}
|
|
96
97
|
expectZodPass({ services: {}, modules: { 'module-x': mod } });
|
|
97
98
|
expectZodReject({ services: {}, modules: { 'module-x': { ...mod, unknownKey: 1 } } });
|
|
@@ -142,7 +142,7 @@ describe('module resources 只读投影(N2 读半边)', () => {
|
|
|
142
142
|
noResourcesKey.app.dispose();
|
|
143
143
|
});
|
|
144
144
|
|
|
145
|
-
it('T5 写侧保全不变量:MODULE_INTEGRATION_NODE_KEYS 白名单恒不含 resources(N2
|
|
146
|
-
expect(MODULE_INTEGRATION_NODE_KEYS).toEqual(['provider', 'config']);
|
|
145
|
+
it('T5 写侧保全不变量:MODULE_INTEGRATION_NODE_KEYS 白名单恒不含 resources(N2 写半边不变;credentialRef 归属层凭据键入集——resources 仍恒保全)', () => {
|
|
146
|
+
expect(MODULE_INTEGRATION_NODE_KEYS).toEqual(['provider', 'config', 'credentialRef']);
|
|
147
147
|
});
|
|
148
148
|
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 归属层凭据引用扫描回归(P2 返修):modules[owner].credentialRef 与槽/实例层
|
|
3
|
+
* 同诊断面——「同一不存在的凭据,放模块层与放槽层同报 CREDENTIAL_FILE_MISSING」。
|
|
4
|
+
* 覆盖两通道:
|
|
5
|
+
* - 文件通道:config/credentials/<stem>.json 缺席 → missing(stem 收集含归属层);
|
|
6
|
+
* - 环境通道:env 键在场(stem kebab → UPPER_SNAKE)→ 不算缺失(wanda env 化语义);
|
|
7
|
+
* - 求值转折:evaluateIntegrationServices 消费归属层 ref → #1 CREDENTIAL_FILE_MISSING
|
|
8
|
+
* (service/instance 定位信息随 issue 携带——诊断可定位)。
|
|
9
|
+
*/
|
|
10
|
+
import { describe, expect, it } from 'vitest';
|
|
11
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { buildPredicateAssembly } from '../src/integrations/predicate-io.js';
|
|
14
|
+
import { evaluateIntegrationServices } from '../src/integrations/predicate.js';
|
|
15
|
+
import { walkManifests } from '../src/assembly/walk-manifests.js';
|
|
16
|
+
import { createTempApp, writeAppFile } from './demo-app.js';
|
|
17
|
+
|
|
18
|
+
const GHOST = 'secret://ghost-cred';
|
|
19
|
+
|
|
20
|
+
function appWithRef(modules: Record<string, unknown>, slotRef?: string) {
|
|
21
|
+
const app = createTempApp('tbox-credref-');
|
|
22
|
+
mkdirSync(join(app.appDir, 'packages', 'module-parking'), { recursive: true });
|
|
23
|
+
writeAppFile(app.appDir, 'packages/module-parking/tbox.module.json', JSON.stringify({
|
|
24
|
+
schemaVersion: 1, id: 'module-parking', version: '0.1.0', kind: 'business',
|
|
25
|
+
name: '停车缴费',
|
|
26
|
+
declare: { owns: [{ service: 'parking.query' }] },
|
|
27
|
+
}));
|
|
28
|
+
writeAppFile(app.appDir, 'config/integrations.json', JSON.stringify({
|
|
29
|
+
modules,
|
|
30
|
+
services: { 'parking.query': { instances: { '9001': {} }, ...(slotRef ? { credentialRef: slotRef } : {}) } },
|
|
31
|
+
}));
|
|
32
|
+
return app;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe('buildPredicateAssembly:#1 stem 收集含 modules[*].credentialRef', () => {
|
|
36
|
+
it('文件通道:模块层不存在凭据 → missing(与槽层同报);槽层对照同诊断', () => {
|
|
37
|
+
const appMod = appWithRef({ 'module-parking': { provider: 'mock', credentialRef: GHOST } });
|
|
38
|
+
const asmMod = buildPredicateAssembly(appMod.appDir, walkManifests(appMod.appDir), integrationsOf(appMod.appDir), {});
|
|
39
|
+
expect(asmMod.credentialFileMissing['ghost-cred']).toBe(true);
|
|
40
|
+
|
|
41
|
+
const appSlot = appWithRef({}, GHOST);
|
|
42
|
+
const asmSlot = buildPredicateAssembly(appSlot.appDir, walkManifests(appSlot.appDir), integrationsOf(appSlot.appDir), {});
|
|
43
|
+
expect(asmSlot.credentialFileMissing['ghost-cred']).toBe(true);
|
|
44
|
+
appMod.dispose();
|
|
45
|
+
appSlot.dispose();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('环境通道:env 键在场(kebab → UPPER_SNAKE) → 不算缺失(文件缺席免报)', () => {
|
|
49
|
+
const app = appWithRef({ 'module-parking': { provider: 'mock', credentialRef: GHOST } });
|
|
50
|
+
const asm = buildPredicateAssembly(app.appDir, walkManifests(app.appDir), integrationsOf(app.appDir), { GHOST_CRED: 'x' });
|
|
51
|
+
expect(asm.credentialFileMissing['ghost-cred']).toBeUndefined();
|
|
52
|
+
app.dispose();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('文件通道对照:credentials/<stem>.json 在场 → 不报', () => {
|
|
56
|
+
const app = appWithRef({ 'module-parking': { provider: 'mock', credentialRef: GHOST } });
|
|
57
|
+
mkdirSync(join(app.appDir, 'config', 'credentials'), { recursive: true });
|
|
58
|
+
writeFileSync(join(app.appDir, 'config', 'credentials', 'ghost-cred.json'), JSON.stringify({ type: 'bearer' }));
|
|
59
|
+
const asm = buildPredicateAssembly(app.appDir, walkManifests(app.appDir), integrationsOf(app.appDir), {});
|
|
60
|
+
expect(asm.credentialFileMissing['ghost-cred']).toBeUndefined();
|
|
61
|
+
app.dispose();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('evaluateIntegrationServices:归属层 ref 的 #1 转折(doctor 面终态)', () => {
|
|
66
|
+
it('模块层凭据缺文件 + ownership 绑定在 → CREDENTIAL_FILE_MISSING 带 service 定位', () => {
|
|
67
|
+
const issues = evaluateIntegrationServices({
|
|
68
|
+
integrations: {
|
|
69
|
+
modules: { 'module-parking': { provider: 'mock', credentialRef: GHOST } },
|
|
70
|
+
services: { 'parking.query': { instances: { '9001': {} } } },
|
|
71
|
+
} as never,
|
|
72
|
+
suppliedProviders: {},
|
|
73
|
+
demandedServices: {},
|
|
74
|
+
contracts: {
|
|
75
|
+
normalizeInstances: (cfg: { instances?: unknown[]; defaultInstanceId?: unknown }) => ({
|
|
76
|
+
instances: cfg.instances ?? [],
|
|
77
|
+
defaultInstanceId: cfg.defaultInstanceId ?? null,
|
|
78
|
+
}),
|
|
79
|
+
},
|
|
80
|
+
ownership: { 'parking.query': 'module-parking' },
|
|
81
|
+
credentialFileMissing: { 'ghost-cred': true },
|
|
82
|
+
credentialFileType: {},
|
|
83
|
+
} as never);
|
|
84
|
+
const hits = issues.filter((i) => i.code === 'CREDENTIAL_FILE_MISSING');
|
|
85
|
+
expect(hits).toHaveLength(1);
|
|
86
|
+
expect(hits[0]?.service).toBe('parking.query');
|
|
87
|
+
expect(hits[0]?.severity).toBe('error');
|
|
88
|
+
// issue 文案含归属层 ref 语义定位(模块层引用同样可诊断)
|
|
89
|
+
expect(hits[0]?.message).toContain('parking.query');
|
|
90
|
+
expect(hits[0]?.message).toContain('ghost-cred');
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
function integrationsOf(appDir: string): Record<string, unknown> {
|
|
95
|
+
return JSON.parse(readFileSync(join(appDir, 'config/integrations.json'), 'utf8')) as Record<string, unknown>;
|
|
96
|
+
}
|