@tbox.cn/app-toolkit 0.7.5 → 0.8.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.
@@ -5,9 +5,9 @@ import { fileURLToPath } from 'node:url';
5
5
  import { createAppToolkit, type AppToolkit } from '../src/factory.js';
6
6
  import { invalidateContractsResolver } from '../src/core/contracts-resolver.js';
7
7
  import { walkManifests, type WalkManifestsResult } from '../src/assembly/walk-manifests.js';
8
- import { buildIntegrationFieldRegistry, loadModuleFormViews, loadModuleIntegrationSchemas, loadServiceFieldRegistry, loadServiceIntegrationSchemas } from '../src/views/integration-schemas.js';
9
- import { resolveServiceDisplay } from '../src/views/context.js';
10
- import type { ViewSnapshot } from '../src/views/context.js';
8
+ import { buildIntegrationFieldRegistry, loadServiceIntegrationSchemas } from '../src/views/integration-schemas.js';
9
+ import { resolveServiceDisplay, loadViewSnapshotSync } from '../src/views/context.js';
10
+ import { resolveContractsForApp } from '../src/core/contracts-resolver.js';
11
11
  import { URL_METHOD_MAP } from './naming-alignment.test.js';
12
12
  import { createTempApp, writeFakeContractsPackage, linkContracts, writeAppFile, type TempApp } from './demo-app.js';
13
13
 
@@ -354,7 +354,7 @@ describe('views/工厂(O 矩阵核心族)', () => {
354
354
 
355
355
  it('O2 静态投影零求值键:/app、/modules/:m、/services/:s 结构性无 resolution/issues/contracts', async () => {
356
356
  const appView = await h.tk.loadApp();
357
- expect(Object.keys(appView)).toEqual(['services', 'integration']);
357
+ expect(Object.keys(appView)).toEqual(['services', 'integration', 'binding']);
358
358
  const mod = await h.tk.loadModule('module-parking');
359
359
  // v4.4 D34:domainKeys/providerBindings/configEditable 显式化(include 两键可选缺席——F4)
360
360
  // v7 词汇统一:模块展示名 name 前置(恒发——兜底 id)
@@ -622,7 +622,6 @@ describe('views/工厂(O 矩阵核心族)', () => {
622
622
  expect(credView.services['parking.query']?.credential).toEqual({
623
623
  type: 'wanda-c-signed-v1',
624
624
  ref: 'secret://wanda-parking.query',
625
- file: 'config/credentials/wanda-parking.query.json',
626
625
  masked: { appKey: 'SE****', appSecret: 'SE****' },
627
626
  });
628
627
  // O4 零真值:序列化后 grep 断言
@@ -662,13 +661,13 @@ describe('O6/O7/O10/O14(FX-3 补全)', () => {
662
661
  writeAppFile(app.appDir, 'packages/provider-multi/schemas/query.json', JSON.stringify({ type: 'object', properties: { baseUrl: { type: 'string' } } }));
663
662
  writeAppFile(app.appDir, 'packages/provider-multi/schemas/query2.json', JSON.stringify({ type: 'object', properties: { endpoint: { type: 'string' } } }));
664
663
  const tk = createAppToolkit(app.appDir);
665
- const detail = await tk.loadProvider('joycity');
666
- expect(detail.services['parking.query']?.implementations).toEqual([
664
+ // O7 组合单体:多 impl → implementations.length > 1 + schema 取默认 impl(声明序首个)
665
+ // v8:loadProvider(供给足迹转储)即删——多 impl 锁归组合单体 implementations[]
666
+ const combo = await tk.loadProviderService('joycity', 'parking.query');
667
+ expect(combo.implementations).toEqual([
667
668
  { implementation: 'joycity-parking@1', credentialType: 'joycity-c' },
668
669
  { implementation: 'joycity-parking@2', credentialType: 'joycity-c' },
669
670
  ]);
670
- // O7 组合单体:多 impl → implementations.length > 1 + schema 取默认 impl(声明序首个)
671
- const combo = await tk.loadProviderService('joycity', 'parking.query');
672
671
  expect(combo.implementations).toHaveLength(2);
673
672
  expect(combo.integrationSchemas.configSchema).toEqual({ type: 'object', properties: { baseUrl: { type: 'string' } } });
674
673
  // v4.4 D33:credentialSchema 删净(结构归 GET /credential-types——组合单体纯 config)
@@ -841,7 +840,7 @@ describe('v6 所有权族(D34 多域钉死退役 → ownedServices/binding 单
841
840
  const mod = await h2.tk.loadModule('module-parking');
842
841
  expect(mod.ownedServices).toEqual(['parking.query']);
843
842
  expect(mod.configEditable).toBe(true);
844
- expect(mod.binding).toEqual({ provider: 'wanda', layer: 'module' });
843
+ expect(mod.binding).toEqual({ configured: 'wanda', effective: { provider: 'wanda', layer: 'module' }, inherited: { provider: 'mock', layer: 'app' }, provider: 'wanda', layer: 'module' });
845
844
  expect(mod.integration).toEqual({ provider: 'wanda' });
846
845
  h2.app.dispose();
847
846
  });
@@ -870,13 +869,13 @@ describe('v6 所有权族(D34 多域钉死退役 → ownedServices/binding 单
870
869
  expect(mod.ownedServices).toEqual(['member.account', 'parking.query']);
871
870
  expect(mod.integration).toBeNull();
872
871
  expect(mod.configEditable).toBe(true);
873
- expect(mod.binding).toEqual({ provider: null, layer: null });
872
+ expect(mod.binding).toEqual({ configured: null, effective: { provider: null, layer: null }, inherited: { provider: null, layer: null }, provider: null, layer: null });
874
873
  // v6 写通道:多域归属合法——模块级 provider 单值落 modules[module-multi]
875
874
  const r = await tk.writeModuleIntegration('module-multi', { provider: 'wanda' });
876
875
  expect(r.written).toBe(true);
877
876
  const mod2 = await tk.loadModule('module-multi');
878
877
  expect(mod2.integration).toEqual({ provider: 'wanda' });
879
- expect(mod2.binding).toEqual({ provider: 'wanda', layer: 'module' });
878
+ expect(mod2.binding).toEqual({ configured: 'wanda', effective: { provider: 'wanda', layer: 'module' }, inherited: { provider: null, layer: null }, provider: 'wanda', layer: 'module' });
880
879
  app.dispose();
881
880
  });
882
881
 
@@ -902,7 +901,7 @@ describe('v6 所有权族(D34 多域钉死退役 → ownedServices/binding 单
902
901
  const tk = createAppToolkit(app.appDir);
903
902
  const mod = await tk.loadModule('module-zero');
904
903
  expect(mod.ownedServices).toEqual([]);
905
- expect(mod.binding).toEqual({ provider: null, layer: null });
904
+ expect(mod.binding).toEqual({ configured: null, effective: { provider: null, layer: null }, inherited: { provider: null, layer: null }, provider: null, layer: null });
906
905
  expect(mod.integration).toBeNull();
907
906
  await expect(tk.writeModuleIntegration('module-zero', { provider: 'x' })).rejects.toMatchObject({
908
907
  code: 'VALIDATION_FAILED',
@@ -1200,10 +1199,6 @@ describe('v4.4 include 协议 + Entry.layer + 层级 schema(F4/F5)', () => {
1200
1199
  await expect(h2.tk.loadApp({ include: ['bogus'] })).rejects.toMatchObject({
1201
1200
  code: 'VALIDATION_FAILED', httpStatus: 400, fields: ['include'],
1202
1201
  });
1203
- // 越权:provider 白名单仅 integrationSchemas——且 400 先于 PROVIDER_NOT_FOUND
1204
- await expect(h2.tk.loadProvider('wanda', { include: ['serviceResolutions'] })).rejects.toMatchObject({
1205
- code: 'VALIDATION_FAILED', httpStatus: 400, fields: ['include'],
1206
- });
1207
1202
  // 校验先于 MODULE_NOT_FOUND
1208
1203
  await expect(h2.tk.loadModule('ghost', { include: ['bogus'] })).rejects.toMatchObject({
1209
1204
  code: 'VALIDATION_FAILED', httpStatus: 400,
@@ -1309,16 +1304,6 @@ describe('v4.4 include 协议 + Entry.layer + 层级 schema(F4/F5)', () => {
1309
1304
  h3.app.dispose();
1310
1305
  });
1311
1306
 
1312
- it('S3 切换态批量:loadProvider include=integrationSchemas(供给轴逐服务)+ 未请求缺席', async () => {
1313
- const h2 = layerHarness();
1314
- const detail = await h2.tk.loadProvider('wanda', { include: ['integrationSchemas'] });
1315
- expect(detail.services['parking.query']?.integrationSchemas).toEqual({ configSchema: h2.schemas.query });
1316
- expect(detail.services['parking.payment']?.integrationSchemas).toEqual({ configSchema: h2.schemas.parking });
1317
- const plain = await h2.tk.loadProvider('wanda');
1318
- expect(plain.services['parking.query'] && 'integrationSchemas' in plain.services['parking.query']).toBe(false);
1319
- h2.app.dispose();
1320
- });
1321
-
1322
1307
  it('S4 多域模块 integrationSchemas → 整字段 null(D32——表单降级 ExtraFields)', async () => {
1323
1308
  const app = createTempApp('tbox-s4-');
1324
1309
  invalidateContractsResolver();
@@ -1589,237 +1574,17 @@ describe('v4.7 服务级 include(D38——生效绑定单体)', () => {
1589
1574
  });
1590
1575
 
1591
1576
  /**
1592
- * v5.1 D39 测试族(服务轴向假想绑定——?serviceProvider= 表单双投影重定向)。
1593
- * 供给矩阵(eHarness):wanda 供给 {parking.query, parking.payment};joycity 仅供给
1594
- * {parking.query}(provider-multi 双 impl 皆 query)——用例 (厂商 × 服务) 选型须对照本矩阵:
1595
- * catalog-miss 形态(D39-7)与豁免链正例(D39-6)不得混淆供给边界。每用例独立 eHarness
1596
- * (零 file-cache stat 指纹串扰);D39-8/D39-9 用 layerHarness(x-tbox-global 标记 fixture)。
1577
+ * v8 供给轴测试面(替代 v5.1 D39/S5b/S6/S7/S8 假想族——P18 轴参退场,切换预览归
1578
+ * /providers/:p/supply)。保留三块有长期价值的锁:
1579
+ * S5a 纯代数(buildIntegrationFieldRegistry 合并代数——零 fs 直调)
1580
+ * E5 实际态锁(module 轴 registry global 收窄 G 批负例——parkLotId 未标记不收)
1581
+ * 单源锁(loadServiceFieldRegistry ≡ buildRegistry over 链函数——无轴参形态)
1582
+ * binding 三态 / supply 判定 / 零槽自声明族 → provider-binding-supply.test.ts。
1597
1583
  */
1598
- describe('v5.1 D39(服务轴向假想绑定 serviceProvider)', () => {
1599
- it('D39-1 假想 happy + I1:双投影切 joycity 且 provider 一致 + 单键边界正例', async () => {
1600
- const h = eHarness();
1601
- writeIntegrations(h.app.appDir, { services: { 'parking.query': { provider: 'wanda' } } });
1602
- const both = ['integrationSchemas', 'integrationFieldRegistry'];
1603
- const v = await h.tk.loadService('parking.query', { include: both, serviceProvider: 'joycity' });
1604
- // I1:双投影同源同口径(fields = joycity schema 字段——catalog 复合键声明序首个 = @1 的 joycityUrl)
1605
- expect(v.integrationSchemas).toEqual({ provider: 'joycity', configSchema: h.schemas.joycity1 });
1606
- expect(v.integrationFieldRegistry?.provider).toBe('joycity');
1607
- expect(v.integrationFieldRegistry!.fields.map((f) => f.key)).toEqual(['joycityUrl']);
1608
- // 单键边界正例:仅 integrationSchemas + 轴参 → 200 假想计算;registry 未请求 = 缺席(S7-1 尾部先例)
1609
- const only = await h.tk.loadService('parking.query', { include: ['integrationSchemas'], serviceProvider: 'joycity' });
1610
- expect(only.integrationSchemas).toEqual({ provider: 'joycity', configSchema: h.schemas.joycity1 });
1611
- expect('integrationFieldRegistry' in only).toBe(false);
1612
- h.app.dispose();
1613
- });
1614
-
1615
- it('D39-2 I2 锁:integration/suppliedBy/defaults 恒实际态', async () => {
1616
- const h = eHarness();
1617
- writeIntegrations(h.app.appDir, { services: { 'parking.query': { provider: 'wanda', config: { baseUrl: 'https://w.example' } } } });
1618
- const base = await h.tk.loadService('parking.query');
1619
- const v = await h.tk.loadService('parking.query', { include: ['integrationSchemas', 'integrationFieldRegistry'], serviceProvider: 'joycity' });
1620
- expect(v.integration).toEqual(base.integration); // 文件逐字原值不被重定向(预览不产生「已保存」误导)
1621
- expect(v.suppliedBy).toEqual(base.suppliedBy); // catalog 静态切片恒实际
1622
- expect(v.defaults).toEqual(base.defaults); // manifest 预填恒实际
1623
- expect(v.integrationSchemas?.provider).toBe('joycity'); // 对照:表单层已重定向
1624
- h.app.dispose();
1625
- });
1626
-
1627
- it('D39-3 I3 锁 + 错轴静默忽略:空串 ≡ 缺席 ≡ 实际;appProvider/moduleProvider 被无视', async () => {
1628
- const h = eHarness();
1629
- writeIntegrations(h.app.appDir, { services: { 'parking.query': { provider: 'wanda' } } });
1630
- const empty = await h.tk.loadService('parking.query', { include: ['integrationFieldRegistry'], serviceProvider: '' });
1631
- const absent = await h.tk.loadService('parking.query', { include: ['integrationFieldRegistry'] });
1632
- expect(empty.integrationFieldRegistry).toEqual(absent.integrationFieldRegistry);
1633
- // 错轴参数(变量绕过多余属性检查——运行时按名读取,appProvider/moduleProvider 被无视;S7-4 先例镜像)
1634
- const opts = { include: ['integrationFieldRegistry'], serviceProvider: '', appProvider: 'joycity', moduleProvider: 'joycity' };
1635
- const wrongAxis = await h.tk.loadService('parking.query', opts);
1636
- expect(wrongAxis.integrationFieldRegistry).toEqual(absent.integrationFieldRegistry);
1637
- h.app.dispose();
1638
- });
1639
-
1640
- it('D39-4 轴参严检矩阵:400 先于 404(镜像 S7-1 形态)', async () => {
1641
- const h = eHarness();
1642
- await expect(h.tk.loadService('parking.query', { serviceProvider: 'x' })).rejects.toMatchObject({
1643
- code: 'VALIDATION_FAILED', httpStatus: 400, fields: ['serviceProvider'],
1644
- });
1645
- await expect(h.tk.loadService('parking.query', { include: [], serviceProvider: 'x' })).rejects.toMatchObject({
1646
- code: 'VALIDATION_FAILED', httpStatus: 400, fields: ['serviceProvider'],
1647
- });
1648
- // 先于 404:ghost 服务 + 无表单键轴参 → 400(非 SERVICE_NOT_FOUND);表单键在场 → 放行至 404
1649
- await expect(h.tk.loadService('ghost', { serviceProvider: 'x' })).rejects.toMatchObject({
1650
- code: 'VALIDATION_FAILED', httpStatus: 400, fields: ['serviceProvider'],
1651
- });
1652
- await expect(h.tk.loadService('ghost', { include: ['integrationSchemas'], serviceProvider: 'x' })).rejects.toMatchObject({
1653
- code: 'SERVICE_NOT_FOUND', httpStatus: 404,
1654
- });
1655
- h.app.dispose();
1656
- });
1657
-
1658
- it('D39-5 同构承诺锁:假想 ≡ PUT 改写 provider 后实读(双投影;S6 写通道先例)', async () => {
1659
- const h = eHarness();
1660
- const both = ['integrationSchemas', 'integrationFieldRegistry'];
1661
- writeIntegrations(h.app.appDir, { services: { 'parking.query': { provider: 'wanda' } } });
1662
- const hyp = await h.tk.loadService('parking.query', { include: both, serviceProvider: 'joycity' });
1663
- // 状态演进全经 toolkit 写通道——写后本实例缓存即刻失效,免外部写缓存关注
1664
- const cur = await h.tk.loadService('parking.query');
1665
- const w = await h.tk.writeServiceIntegration('parking.query', { ...cur.integration!, provider: 'joycity' });
1666
- expect(w.written).toBe(true);
1667
- const act = await h.tk.loadService('parking.query', { include: both });
1668
- expect(act.integrationSchemas).toEqual(hyp.integrationSchemas);
1669
- expect(act.integrationFieldRegistry).toEqual(hyp.integrationFieldRegistry);
1670
- h.app.dispose();
1671
- });
1672
-
1673
- it('D39-6 假想豁免链三分支:malformed 不污染 / 内联不读取无 H9 / 未绑定仍非 null', async () => {
1674
- // ① malformed 节点(E14 形态)+ 假想 → 非 null(短路在节点读取之前——坏形态只影响实际态投影)
1675
- const h = eHarness();
1676
- writeIntegrations(h.app.appDir, {
1677
- modules: { 'module-parking': { provider: 'wanda' } },
1678
- services: { 'parking.query': { provider: { provider: 'my-api' } } },
1679
- });
1680
- const bad = await h.tk.loadService('parking.query', { include: ['integrationFieldRegistry'], serviceProvider: 'joycity' });
1681
- expect(bad.integrationFieldRegistry).not.toBeNull();
1682
- expect(bad.integrationFieldRegistry!.provider).toBe('joycity');
1683
- // 实际态对照:同坏节点无轴参 → 整字段 null(E14 双态互证——预览与坏文件解耦)
1684
- const badActual = await h.tk.loadService('parking.query', { include: ['integrationSchemas'] });
1685
- expect(badActual.integrationSchemas).toBeNull();
1686
- h.app.dispose();
1687
- // ② 内联 ref 逃逸节点(E4 形态)+ 假想 → 无 H9 400(短路不读节点内联 ref——换厂商即离开内联)
1688
- const h2 = eHarness();
1689
- writeIntegrations(h2.app.appDir, {
1690
- services: { 'parking.query': { provider: { provider: 'my-api', credentialType: '-', configSchema: 'config/schemas-evil/x.json' } } },
1691
- });
1692
- const inline = await h2.tk.loadService('parking.query', { include: ['integrationSchemas'], serviceProvider: 'joycity' });
1693
- expect(inline.integrationSchemas).toEqual({ provider: 'joycity', configSchema: h2.schemas.joycity1 });
1694
- h2.app.dispose();
1695
- // ③ 全链未绑定(E8 形态)+ 假想 → 仍非 null(服务轴恒可写——无 module 轴零归属豁免形态);
1696
- // wanda 供给 payment(供给矩阵)→ mallId 字段在场
1697
- const h3 = eHarness();
1698
- writeIntegrations(h3.app.appDir, { services: { 'parking.payment': {} } });
1699
- const unbound = await h3.tk.loadService('parking.payment', { include: ['integrationFieldRegistry'], serviceProvider: 'wanda' });
1700
- // fields[].schema = 字段子 schema(非整文件 schema——G 批锁 :1777 同型)
1701
- expect(unbound.integrationFieldRegistry).toEqual({
1702
- provider: 'wanda', schemaless: [], unsupplied: [], additionalPropertiesAllowed: true,
1703
- fields: [{ key: 'mallId', schema: { type: 'string' }, sources: [{ service: 'parking.payment', required: false }], global: false }],
1704
- });
1705
- h3.app.dispose();
1706
- });
1707
-
1708
- it('D39-7 catalog miss:假想未知厂商 → 非 null 空集(schemaless=[service])', async () => {
1709
- const h = eHarness();
1710
- writeIntegrations(h.app.appDir, { services: { 'parking.query': { provider: 'wanda' } } });
1711
- const v = await h.tk.loadService('parking.query', { include: ['integrationSchemas', 'integrationFieldRegistry'], serviceProvider: 'ghost-vendor' });
1712
- expect(v.integrationSchemas).toEqual({ provider: 'ghost-vendor', configSchema: null });
1713
- expect(v.integrationFieldRegistry).toEqual({
1714
- provider: 'ghost-vendor', schemaless: ['parking.query'], unsupplied: [], additionalPropertiesAllowed: true, fields: [],
1715
- });
1716
- h.app.dispose();
1717
- });
1718
-
1719
- it('D39-8 global 旗标假想透传:标记位如实(layerHarness——true 正例 + 未标记 false 不过滤)', async () => {
1720
- const h = layerHarness();
1721
- // joycity 供给 parking.query → 假想后 fields = joycity query schema 字段(fixture 全标记 → global:true)
1722
- const joy = await h.tk.loadService('parking.query', { include: ['integrationFieldRegistry'], serviceProvider: 'joycity' });
1723
- expect(joy.integrationFieldRegistry!.provider).toBe('joycity');
1724
- expect(joy.integrationFieldRegistry!.fields.length).toBeGreaterThan(0);
1725
- expect(joy.integrationFieldRegistry!.fields.every((f) => f.global)).toBe(true);
1726
- // wanda 供给 parking.payment → mallId global:true / parkLotId global:false 在场(服务轴不过滤——G 批语义假想不变);
1727
- // payment 先配置入词汇(P9:契约包 ∪ 已配置——layerHarness 初始 integrations.json 未配置 payment;
1728
- // 覆盖写后 payment 节点 {} 实际态级联双缺 → null,假想 wanda 短路仍非 null——豁免链③同型,S7-7 外部写先例)
1729
- writeAppFile(h.app.appDir, 'config/integrations.json', JSON.stringify({ services: { 'parking.payment': {} } }));
1730
- const wan = await h.tk.loadService('parking.payment', { include: ['integrationFieldRegistry'], serviceProvider: 'wanda' });
1731
- expect(wan.integrationFieldRegistry!.fields.map((f) => f.key).sort()).toEqual(['mallId', 'parkLotId']);
1732
- expect(wan.integrationFieldRegistry!.fields.find((f) => f.key === 'mallId')!.global).toBe(true);
1733
- expect(wan.integrationFieldRegistry!.fields.find((f) => f.key === 'parkLotId')!.global).toBe(false);
1734
- h.app.dispose();
1735
- });
1736
-
1737
- it('D39-9 单源锁:loadServiceFieldRegistry(snap,s,X) ≡ buildIntegrationFieldRegistry over 链函数', async () => {
1738
- const h = layerHarness();
1739
- const { loadViewSnapshotSync } = await import('../src/views/context.js');
1740
- const snap = loadViewSnapshotSync({ appDir: h.app.appDir }, await h.tk.resolveContracts());
1741
- const X = 'joycity';
1742
- const reg = loadServiceFieldRegistry(snap, 'parking.query', X);
1743
- const schemas = loadServiceIntegrationSchemas(snap, 'parking.query', X);
1744
- expect(schemas).not.toBeNull();
1745
- // 结构性断言(依赖契约锁——registry 旁路重取 schema 破 I1 即刻红;S8 同族意图)
1746
- const manual = buildIntegrationFieldRegistry({
1747
- provider: schemas!.provider,
1748
- services: { 'parking.query': { configSchema: schemas!.configSchema } },
1749
- });
1750
- expect(reg).toEqual(manual);
1751
- h.app.dispose();
1752
- });
1753
- });
1754
-
1755
- /**
1756
- * v4.6 D36/D37 测试族(S5 接续 S1-S4):S5a 纯代数(直调合成 layer 字面量,零 fs)/
1757
- * S5b 接线序 + 等价锁 / S6 同构(假想 ≡ 写后实读)/ S7 边界(400·null 两态·I2·空集)/
1758
- * S8 双投影互证(依赖契约锁——旁路重取 serviceSchemas 破 S8-2/S8-3 即刻红)。
1759
- */
1760
- describe('v4.6 D36/D37(integrationFieldRegistry + 轴向假想绑定)', () => {
1761
- /** sources 单元 */
1762
- const src = (service: string, required: boolean): { service: string; required: boolean } => ({ service, required });
1763
-
1764
- /** E1:module 轴 moduleProvider=joycity(scope = demand 序 [query, payment]) */
1765
- const E1 = {
1766
- provider: 'joycity',
1767
- schemaless: [],
1768
- unsupplied: [],
1769
- additionalPropertiesAllowed: false,
1770
- fields: [
1771
- { key: 'baseUrl', schema: { type: 'string', format: 'uri', 'x-tbox-global': true }, global: true, sources: [src('parking.query', true), src('parking.payment', false)] },
1772
- { key: 'lotId', schema: null, global: true, sources: [src('parking.query', true), src('parking.payment', false)] },
1773
- { key: 'env', schema: { type: 'string', enum: ['dev', 'staging', 'prod'], 'x-tbox-global': true }, global: true, sources: [src('parking.query', false), src('parking.payment', false)] },
1774
- { key: 'envMixed', schema: null, global: true, sources: [src('parking.query', false), src('parking.payment', false)] },
1775
- { key: 'meta', schema: null, global: true, sources: [src('parking.query', false), src('parking.payment', false)] },
1776
- { key: 'options', schema: { type: 'object', properties: { x: { type: 'string', 'x-tbox-global': true } }, 'x-tbox-global': true }, global: true, sources: [src('parking.query', false), src('parking.payment', true)] },
1777
- { key: 'untyped', schema: null, global: true, sources: [src('parking.query', false), src('parking.payment', false)] },
1778
- { key: 'timeout', schema: null, global: true, sources: [src('parking.query', false), src('parking.payment', false)] },
1779
- { key: 'apiKey', schema: { type: 'string', 'x-tbox-global': true }, global: true, sources: [src('parking.payment', true)] },
1780
- ],
1781
- };
1782
-
1783
- /** E2:app 轴 appProvider=joycity(scope = 足迹字母序 [payment, query, vehicle]——序判别 + 首源漂移) */
1784
- const E2 = {
1785
- provider: 'joycity',
1786
- schemaless: ['parking.vehicle'],
1787
- unsupplied: [],
1788
- additionalPropertiesAllowed: false,
1789
- fields: [
1790
- { key: 'apiKey', schema: { type: 'string', 'x-tbox-global': true }, global: true, sources: [src('parking.payment', true)] },
1791
- { key: 'baseUrl', schema: { type: 'string', 'x-tbox-global': true }, global: true, sources: [src('parking.payment', false), src('parking.query', true)] },
1792
- { key: 'lotId', schema: null, global: true, sources: [src('parking.payment', false), src('parking.query', true)] },
1793
- { key: 'env', schema: { type: 'string', enum: ['prod', 'dev', 'staging'], 'x-tbox-global': true }, global: true, sources: [src('parking.payment', false), src('parking.query', false)] },
1794
- { key: 'envMixed', schema: null, global: true, sources: [src('parking.payment', false), src('parking.query', false)] },
1795
- { key: 'meta', schema: null, global: true, sources: [src('parking.payment', false), src('parking.query', false)] },
1796
- { key: 'options', schema: { type: 'object', properties: { x: { type: 'string', 'x-tbox-global': true } }, 'x-tbox-global': true }, global: true, sources: [src('parking.payment', true), src('parking.query', false)] },
1797
- { key: 'untyped', schema: null, global: true, sources: [src('parking.payment', false), src('parking.query', false)] },
1798
- { key: 'timeout', schema: null, global: true, sources: [src('parking.payment', false), src('parking.query', false)] },
1799
- ],
1800
- };
1801
-
1802
- /** E3:module 轴 moduleProvider=partial(scope=[payment],schemaless + 部分 unsupplied 四合一) */
1803
- const E3 = { provider: 'partial', schemaless: ['parking.payment'], unsupplied: ['parking.query'], additionalPropertiesAllowed: true, fields: [] };
1804
-
1805
- /** E4:module 轴 moduleProvider=ghost-x(未知厂商——非 null 空集 + 全 demand 回填,demand 序) */
1806
- const E4 = { provider: 'ghost-x', schemaless: [], unsupplied: ['parking.query', 'parking.payment'], additionalPropertiesAllowed: true, fields: [] };
1807
-
1808
- /** E5:实际态(无轴参,wanda;scope = [query, payment])——parkLotId 未标记 global 被表单收窄(G 批负例) */
1809
- const E5 = {
1810
- provider: 'wanda',
1811
- schemaless: [],
1812
- unsupplied: [],
1813
- additionalPropertiesAllowed: true,
1814
- fields: [
1815
- { key: 'baseUrl', schema: { type: 'string', format: 'uri', 'x-tbox-global': true }, global: true, sources: [src('parking.query', true)] },
1816
- { key: 'mallId', schema: { type: 'string', 'x-tbox-global': true }, global: true, sources: [src('parking.payment', false)] },
1817
- ],
1818
- };
1819
-
1820
- // ── S5a 纯代数(直调——合成 layer 字面量,零 fs)──
1821
- const reg = (services: Record<string, { configSchema: object | null }>, o?: { unsupplied?: string[] }) =>
1822
- buildIntegrationFieldRegistry({ provider: 'x', services }, o);
1584
+ describe('v8 供给轴(registry 单轨 + 单源锁)', () => {
1585
+ /** S5a 纯代数(直调——合成 layer 字面量,零 fs) */
1586
+ const reg = (services: Record<string, { configSchema: object | null }>) =>
1587
+ buildIntegrationFieldRegistry({ provider: 'x', services });
1823
1588
 
1824
1589
  it('S5a-1..4 R1 标量:双无 enum 首源保真 / enum 同集异序 / 异集 / 混布', () => {
1825
1590
  const both = reg({
@@ -1881,375 +1646,41 @@ describe('v4.6 D36/D37(integrationFieldRegistry + 轴向假想绑定)', () =
1881
1646
  untypedK: { type: 'string' },
1882
1647
  boolK: { type: 'string' },
1883
1648
  typeArr: { type: ['null', 'string'] },
1884
- objK: { type: 'object', properties: { q: { type: 'number' } } },
1649
+ objK: { type: 'object', properties: { p: { type: 'string' } } },
1885
1650
  },
1886
1651
  },
1887
1652
  },
1888
1653
  });
1889
- const byKey = Object.fromEntries(r3.fields.map((f) => [f.key, f]));
1890
- for (const k of ['mismatch', 'numeric', 'untypedK', 'boolK', 'typeArr', 'objK']) {
1891
- expect(byKey[k]?.schema, k).toBeNull();
1892
- }
1893
- expect(byKey.boolK?.sources).toHaveLength(2); // F1:布尔子 schema 照样入列(key 在、sources 在、schema null)
1894
- });
1895
-
1896
- it('S5a-8/9 单源直通 + required 聚合(some;conflict 照常聚合)', () => {
1897
- const single = reg({ 'a.one': { configSchema: { type: 'object', properties: { only: { type: 'string', enum: ['z'] } } } } });
1898
- expect(single.fields[0]).toEqual({ key: 'only', schema: { type: 'string', enum: ['z'] }, global: false, sources: [src('a.one', false)] });
1899
- const some = reg({
1900
- 'a.one': { configSchema: { type: 'object', properties: { k: { type: 'string' } }, required: ['k'] } },
1901
- 'a.two': { configSchema: { type: 'object', properties: { k: { type: 'string' } } } },
1902
- });
1903
- expect(some.fields[0].sources).toEqual([src('a.one', true), src('a.two', false)]);
1904
- const conflictReq = reg({
1905
- 'a.one': { configSchema: { type: 'object', properties: { k: { type: 'string' } }, required: ['k'] } },
1906
- 'a.two': { configSchema: { type: 'object', properties: { k: { type: 'integer' } } } },
1907
- });
1908
- expect(conflictReq.fields[0].schema).toBeNull();
1909
- expect(conflictReq.fields[0].sources.some((s) => s.required)).toBe(true);
1654
+ const get = (k: string) => r3.fields.find((f) => f.key === k)?.schema ?? null;
1655
+ expect(get('mismatch')).toBeNull(); // type 不等
1656
+ expect(get('numeric')).toBeNull(); // integer ≠ number(R3 已知保守点)
1657
+ expect(get('untypedK')).toBeNull(); // type 缺席
1658
+ expect(get('boolK')).toBeNull(); // 布尔子 schema 入列但不可调和
1659
+ expect(get('typeArr')).toBeNull(); // type 数组序敏感
1660
+ expect(get('objK')).toEqual({ type: 'object', properties: { p: { type: 'string' } } }); // R2 深相等
1910
1661
  });
1911
1662
 
1912
- it('S5a-10/11/12 聚合与装配:apAllowed 四态 / schemaless / unsupplied / 空 scope / 布尔整 schema 防御', () => {
1913
- expect(reg({ 'a.one': { configSchema: { type: 'object', properties: {} } } }).additionalPropertiesAllowed).toBe(true);
1914
- expect(reg({ 'a.one': { configSchema: { type: 'object', additionalProperties: false } } }).additionalPropertiesAllowed).toBe(false);
1915
- expect(reg({}).additionalPropertiesAllowed).toBe(true); // 空真
1916
- // N4:布尔整 schema 防御——不入 schemaless、零参与、fields 空
1917
- expect(reg({ 'a.one': { configSchema: true as unknown as object } })).toEqual({
1918
- provider: 'x', schemaless: [], unsupplied: [], additionalPropertiesAllowed: true, fields: [],
1919
- });
1920
- expect(reg({})).toEqual({ provider: 'x', schemaless: [], unsupplied: [], additionalPropertiesAllowed: true, fields: [] });
1921
- const asm = reg(
1922
- { 'a.one': { configSchema: null }, 'a.two': { configSchema: { type: 'object', properties: { k: { type: 'string' } } } } },
1923
- { unsupplied: ['b.x'] },
1924
- );
1925
- expect(asm.schemaless).toEqual(['a.one']);
1926
- expect(asm.unsupplied).toEqual(['b.x']);
1927
- });
1928
-
1929
- it('S5a-13 fields 序 = services 迭代序(首声明序 + 首源归序)', () => {
1930
- const order = reg({
1931
- 'b.second': { configSchema: { type: 'object', properties: { beta: { type: 'string' }, shared: { type: 'string', format: 'uri' } } } },
1932
- 'a.first': { configSchema: { type: 'object', properties: { alpha: { type: 'string' }, shared: { type: 'string' } } } },
1933
- });
1934
- expect(order.fields.map((f) => f.key)).toEqual(['beta', 'shared', 'alpha']);
1935
- expect(order.fields[1].sources.map((s) => s.service)).toEqual(['b.second', 'a.first']);
1936
- expect(order.fields[1].schema).toEqual({ type: 'string', format: 'uri' }); // 首源 = b.second
1937
- });
1938
-
1939
- // ── S5b 接线序 + 等价锁 ──
1940
- it('S5b-1/2/3 接线:假想双轴 registry 逐字(E1/E2/E3)+ 实际态(E5)+ fields 序判别', async () => {
1663
+ it('E5 实际态锁:module 轴 registry global 收窄(G 批负例——parkLotId 未标记不收)', async () => {
1941
1664
  const h2 = layerHarness();
1942
- const modInc = await h2.tk.loadModule('module-parking', {
1943
- include: ['integrationSchemas', 'integrationFieldRegistry'],
1944
- moduleProvider: 'joycity',
1945
- });
1946
- expect(modInc.integrationFieldRegistry).toEqual(E1);
1947
- expect(modInc.integrationSchemas).toEqual({
1948
- provider: 'joycity',
1949
- services: { 'parking.query': { configSchema: h2.joycity.query }, 'parking.payment': { configSchema: h2.joycity.payment } },
1950
- });
1951
- const appInc = await h2.tk.loadApp({ include: ['integrationFieldRegistry'], appProvider: 'joycity' });
1952
- expect(appInc.integrationFieldRegistry).toEqual(E2);
1953
- expect(appInc.integrationFieldRegistry?.fields[0].key).toBe('apiKey'); // 足迹字母序(vs E1 首键 baseUrl)
1954
- expect(appInc.integrationFieldRegistry?.fields[1].schema).toEqual({ type: 'string', 'x-tbox-global': true }); // 首源漂移(payment 先)
1955
- const partial = await h2.tk.loadModule('module-parking', { include: ['integrationFieldRegistry'], moduleProvider: 'partial' });
1956
- expect(partial.integrationFieldRegistry).toEqual(E3);
1957
- const actual = await h2.tk.loadModule('module-parking', { include: ['integrationFieldRegistry'] });
1958
- expect(actual.integrationFieldRegistry).toEqual(E5);
1665
+ const v = await h2.tk.loadModule('module-parking', { include: ['integrationFieldRegistry'] });
1666
+ expect(v.integrationFieldRegistry?.provider).toBe('wanda');
1667
+ const lot = v.integrationFieldRegistry!.fields.find((f) => f.key === 'parkLotId');
1668
+ expect(lot).toBeUndefined(); // 未标记 global → 收窄出局(layer.properties 仍全量)
1669
+ const mall = v.integrationFieldRegistry!.fields.find((f) => f.key === 'mallId');
1670
+ expect(mall?.global).toBe(true);
1959
1671
  h2.app.dispose();
1960
1672
  });
1961
1673
 
1962
- it('S5b-4 旧 loader 等价锁:loadModuleIntegrationSchemas ≡ loadModuleFormViews.integrationSchemas', async () => {
1963
- const h2 = layerHarness();
1964
- const walk = walkManifests(h2.app.appDir);
1965
- const snap: ViewSnapshot = {
1966
- appDir: h2.app.appDir,
1967
- walk,
1968
- catalog: walk.catalog,
1969
- integrations: await h2.tk.readIntegrationsConfig(),
1970
- contracts: await h2.tk.resolveContracts(),
1971
- };
1972
- const viaOld = loadModuleIntegrationSchemas(snap, 'module-parking');
1973
- expect(viaOld).toEqual(loadModuleFormViews(snap, 'module-parking').integrationSchemas);
1974
- expect(viaOld).toEqual({
1975
- provider: 'wanda',
1976
- services: { 'parking.query': { configSchema: h2.schemas.query }, 'parking.payment': { configSchema: h2.schemas.parking } },
1977
- });
1978
- h2.app.dispose();
1979
- });
1980
-
1981
- // ── S6 同构(状态演进全经 toolkit 写通道——免外部写缓存关注)──
1982
- it('S6 同构:假想预览 ≡ 真实写入后实读(含跟随应用级 + config 值无关)', async () => {
1983
- const h2 = layerHarness();
1984
- const both = ['integrationSchemas', 'integrationFieldRegistry'];
1985
- // ① 假想 joycity ≡ 写 {provider:'joycity'} 后实读(双投影)
1986
- const hypJoy = await h2.tk.loadModule('module-parking', { include: both, moduleProvider: 'joycity' });
1987
- const w1 = await h2.tk.writeModuleIntegration('module-parking', { provider: 'joycity' });
1988
- expect(w1.written).toBe(true);
1989
- const actJoy = await h2.tk.loadModule('module-parking', { include: both });
1990
- expect(actJoy.integrationFieldRegistry).toEqual(hypJoy.integrationFieldRegistry);
1991
- expect(actJoy.integrationSchemas).toEqual(hypJoy.integrationSchemas);
1992
- // ② 跟随应用级(root.provider=wanda)≡ 清模块位(N1 删 modules['module-parking'] → root 兜底)后实读——非平凡:清位前实际态 = E1
1993
- const hypFollow = await h2.tk.loadModule('module-parking', { include: both, moduleProvider: 'wanda' });
1994
- expect(hypFollow.integrationFieldRegistry).toEqual(E5);
1995
- await h2.tk.writeModuleIntegration('module-parking', {});
1996
- const actFollow = await h2.tk.loadModule('module-parking', { include: both });
1997
- expect(actFollow.integrationFieldRegistry).toEqual(hypFollow.integrationFieldRegistry);
1998
- // ③ PUT 任意 config 值不改 registry(schema 侧投影与值无关)
1999
- await h2.tk.writeModuleIntegration('module-parking', { provider: 'joycity', config: { baseUrl: 'https://example' } });
2000
- const actCfg = await h2.tk.loadModule('module-parking', { include: both });
2001
- expect(actCfg.integrationFieldRegistry).toEqual(E1);
2002
- h2.app.dispose();
2003
- });
2004
-
2005
- it('S6 app 轴同构:假想 ≡ 写 root {provider:joycity} 后实读(modules/services 不受扰)', async () => {
2006
- const h2 = layerHarness();
2007
- const hyp = await h2.tk.loadApp({ include: ['integrationFieldRegistry'], appProvider: 'joycity' });
2008
- const cur = await h2.tk.loadApp();
2009
- const w = await h2.tk.writeAppIntegration({ ...(cur.integration ?? {}), provider: 'joycity' });
2010
- expect(w.written).toBe(true);
2011
- const act = await h2.tk.loadApp({ include: ['integrationFieldRegistry'] });
2012
- expect(act.integrationFieldRegistry).toEqual(hyp.integrationFieldRegistry);
2013
- expect(act.integrationFieldRegistry).toEqual(E2);
2014
- // I2:域节点/mirror 不受 root 写入波及
2015
- expect((await h2.tk.loadModule('module-parking')).integration).toEqual({ provider: 'wanda' });
2016
- h2.app.dispose();
2017
- });
2018
-
2019
- // ── S7 边界 ──
2020
- it('S7-1/2/3/6 轴参严检:400 矩阵(fields 随参数名)+ 先于 404 + 边界正例 + 未请求缺席', async () => {
2021
- const h2 = layerHarness();
2022
- await expect(h2.tk.loadApp({ appProvider: 'wanda' })).rejects.toMatchObject({
2023
- code: 'VALIDATION_FAILED', httpStatus: 400, fields: ['appProvider'],
2024
- });
2025
- await expect(h2.tk.loadApp({ include: ['serviceResolutions'], appProvider: 'wanda' })).rejects.toMatchObject({
2026
- code: 'VALIDATION_FAILED', httpStatus: 400, fields: ['appProvider'],
2027
- });
2028
- await expect(h2.tk.loadApp({ include: [], appProvider: 'x' })).rejects.toMatchObject({ fields: ['appProvider'] });
2029
- await expect(h2.tk.loadModule('module-parking', { moduleProvider: 'x' })).rejects.toMatchObject({ fields: ['moduleProvider'] });
2030
- // 先于 404;表单键在场 → 放行至 404
2031
- await expect(h2.tk.loadModule('ghost', { moduleProvider: 'x' })).rejects.toMatchObject({
2032
- code: 'VALIDATION_FAILED', httpStatus: 400,
2033
- });
2034
- await expect(h2.tk.loadModule('ghost', { include: ['integrationSchemas'], moduleProvider: 'x' })).rejects.toMatchObject({
2035
- code: 'MODULE_NOT_FOUND', httpStatus: 404,
2036
- });
2037
- // 边界正例:仅 integrationSchemas + 轴参 → 200 假想计算;registry 未请求 = 缺席(内嵌三律)
2038
- const ok = await h2.tk.loadModule('module-parking', { include: ['integrationSchemas'], moduleProvider: 'joycity' });
2039
- expect(ok.integrationSchemas?.provider).toBe('joycity');
2040
- expect('integrationFieldRegistry' in ok).toBe(false);
2041
- h2.app.dispose();
2042
- });
2043
-
2044
- it('S7-4 空串 ≡ 缺席;错轴参数静默忽略', async () => {
2045
- const h2 = layerHarness();
2046
- const empty = await h2.tk.loadModule('module-parking', { include: ['integrationFieldRegistry'], moduleProvider: '' });
2047
- const absent = await h2.tk.loadModule('module-parking', { include: ['integrationFieldRegistry'] });
2048
- expect(empty.integrationFieldRegistry).toEqual(absent.integrationFieldRegistry);
2049
- expect(empty.integrationFieldRegistry).toEqual(E5);
2050
- // 错轴参数(变量绕过多余属性检查——运行时按名读取,appProvider 被无视)
2051
- const opts = { include: ['integrationFieldRegistry'], moduleProvider: 'joycity', appProvider: 'wanda' };
2052
- const wrongAxis = await h2.tk.loadModule('module-parking', opts);
2053
- expect(wrongAxis.integrationFieldRegistry).toEqual(E1);
2054
- h2.app.dispose();
2055
- });
2056
-
2057
- it('S7-5 I2:假想态下文件镜像与求值恒实际态', async () => {
2058
- const h2 = layerHarness();
2059
- const v = await h2.tk.loadModule('module-parking', {
2060
- include: ['serviceResolutions', 'integrationSchemas', 'integrationFieldRegistry'],
2061
- moduleProvider: 'joycity',
2062
- });
2063
- expect(v.integration).toEqual({ provider: 'wanda' });
2064
- expect(v.binding).toEqual({ provider: 'wanda', layer: 'module' });
2065
- expect(v.configEditable).toBe(true);
2066
- expect(v.integrationFieldRegistry?.provider).toBe('joycity'); // 表单层重定向
2067
- expect(v.integrationSchemas?.provider).toBe('joycity');
2068
- expect(v.serviceResolutions?.resolutions['parking.query']?.provider).toBe('wanda'); // 求值恒实际
2069
- h2.app.dispose();
2070
- });
2071
-
2072
- it('S7-7 null 两态:app 未绑定 / 可写未绑定 / D34 三形态(带 override 不豁免)', async () => {
2073
- // app 未绑定(root.provider 缺席——带空串轴参同此)
2074
- const h3 = layerHarness();
2075
- writeAppFile(
2076
- h3.app.appDir,
2077
- 'config/integrations.json',
2078
- JSON.stringify({
2079
- instances: [{ id: 'mall-bj-01', name: '北京店' }],
2080
- modules: { 'module-parking': { provider: 'joycity' } },
2081
- services: { 'parking.query': { provider: 'wanda', implementation: 'wanda-parking@1' } },
2082
- }),
2083
- );
2084
- expect((await h3.tk.loadApp({ include: ['integrationFieldRegistry'] })).integrationFieldRegistry).toBeNull();
2085
- expect(
2086
- (await h3.tk.loadApp({ include: ['integrationSchemas', 'integrationFieldRegistry'], appProvider: '' })).integrationSchemas,
2087
- ).toBeNull();
2088
- h3.app.dispose();
2089
-
2090
- // 可写未绑定(无 modules 位无 root.provider——无轴参 → null)
2091
- const h4 = layerHarness();
2092
- writeAppFile(
2093
- h4.app.appDir,
2094
- 'config/integrations.json',
2095
- JSON.stringify({
2096
- instances: [{ id: 'mall-bj-01', name: '北京店' }],
2097
- services: { 'parking.query': { provider: 'wanda', implementation: 'wanda-parking@1' } },
2098
- }),
2099
- );
2100
- const unbound = await h4.tk.loadModule('module-parking', { include: ['integrationFieldRegistry', 'integrationSchemas'] });
2101
- expect(unbound.integrationFieldRegistry).toBeNull();
2102
- expect(unbound.integrationSchemas).toBeNull();
2103
- expect(unbound.configEditable).toBe(true);
2104
- h4.app.dispose();
2105
-
2106
- // v6 形态(D34 三形态退役):零归属 → null(带 moduleProvider 仍 null——不豁免);
2107
- // 多域/跨域归属合法化 → 非 null(override 可计算;unsupplied 回填非供给归属槽)
2108
- const d34 = createTempApp('tbox-v46-d34-');
2109
- invalidateContractsResolver();
2110
- const store34 = joinStore(d34.appDir, 'contracts');
2111
- writeFakeContractsPackage(store34, { version: '0.9.0' });
2112
- linkContracts(d34.appDir, store34, { subdir: 'apps/server' });
2113
- const need = (service: string): { service: string; optional: boolean } => ({ service, optional: false });
2114
- const manifest34 = (id: string, services: Array<{ service: string; optional: boolean }>): string =>
2115
- JSON.stringify({ schemaVersion: 1, id, version: '0.1.0', kind: 'business', declare: { owns: services.map((x) => ({ service: x.service })), consumes: services }, dependencies: { modules: [] }, env: [] });
2116
- writeAppFile(d34.appDir, 'packages/module-multi/tbox.module.json', manifest34('module-multi', [need('parking.query'), need('member.account')]));
2117
- writeAppFile(
2118
- d34.appDir,
2119
- 'packages/module-zero/tbox.module.json',
2120
- JSON.stringify({ schemaVersion: 1, id: 'module-zero', version: '0.1.0', kind: 'business', declare: {}, dependencies: { modules: [] }, env: [] }),
2121
- );
2122
- writeAppFile(d34.appDir, 'packages/module-a/tbox.module.json', manifest34('module-a', [need('parking.alpha')]));
2123
- writeAppFile(d34.appDir, 'packages/module-b/tbox.module.json', manifest34('module-b', [need('parking.beta')]));
2124
- const tk34 = createAppToolkit(d34.appDir);
2125
- // 零归属:null(唯一 null 形态——override 不豁免)
2126
- const zero = await tk34.loadModule('module-zero', { include: ['integrationFieldRegistry', 'integrationSchemas'], moduleProvider: 'joycity' });
2127
- expect(zero.integrationFieldRegistry).toBeNull();
2128
- expect(zero.integrationSchemas).toBeNull();
2129
- expect(zero.configEditable).toBe(false);
2130
- // 多域归属:可写(owns>0)——override joycity 供给 parking.query(member.account → unsupplied)
2131
- const multi = await tk34.loadModule('module-multi', { include: ['integrationFieldRegistry', 'integrationSchemas'], moduleProvider: 'joycity' });
2132
- expect(multi.configEditable).toBe(true);
2133
- expect(multi.integrationSchemas?.provider).toBe('joycity');
2134
- // d34 fixture 无 provider 包 → joycity 零供给 → 双 owned 全回填(manifest owns 序)
2135
- expect(multi.integrationFieldRegistry?.unsupplied).toEqual(['parking.query', 'member.account']);
2136
- // 跨域归属:scope = owns ∩ 供给 = [](parking.alpha 非 joycity 供给)→ 非 null 空集 + unsupplied 全回填
2137
- const a = await tk34.loadModule('module-a', { include: ['integrationFieldRegistry'], moduleProvider: 'joycity' });
2138
- expect(a.integrationFieldRegistry).toEqual({ provider: 'joycity', schemaless: [], unsupplied: ['parking.alpha'], additionalPropertiesAllowed: true, fields: [] });
2139
- d34.dispose();
2140
- });
2141
-
2142
- it('S7-8 正例:未绑定 + override → 可计算(预览首次配置);未知厂商 → 非 null 空集 + unsupplied 回填', async () => {
2143
- const h5 = layerHarness();
2144
- writeAppFile(
2145
- h5.app.appDir,
2146
- 'config/integrations.json',
2147
- JSON.stringify({
2148
- instances: [{ id: 'mall-bj-01', name: '北京店' }],
2149
- services: { 'parking.query': { provider: 'wanda', implementation: 'wanda-parking@1' } },
2150
- }),
2151
- );
2152
- const preview = await h5.tk.loadModule('module-parking', { include: ['integrationFieldRegistry'], moduleProvider: 'joycity' });
2153
- expect(preview.integrationFieldRegistry).toEqual(E1); // 无绑定亦可预览(scope = demand ∩ joycity 供给)
2154
- const appPreview = await h5.tk.loadApp({ include: ['integrationFieldRegistry'], appProvider: 'joycity' });
2155
- expect(appPreview.integrationFieldRegistry).toEqual(E2);
2156
- const ghost = await h5.tk.loadModule('module-parking', {
2157
- include: ['integrationFieldRegistry', 'integrationSchemas'],
2158
- moduleProvider: 'ghost-x',
2159
- });
2160
- expect(ghost.integrationFieldRegistry).toEqual(E4);
2161
- expect(ghost.integrationSchemas).toEqual({ provider: 'ghost-x', services: {} });
2162
- const ghostApp = await h5.tk.loadApp({ include: ['integrationFieldRegistry'], appProvider: 'ghost-x' });
2163
- expect(ghostApp.integrationFieldRegistry).toEqual({
2164
- provider: 'ghost-x', schemaless: [], unsupplied: [], additionalPropertiesAllowed: true, fields: [],
2165
- });
2166
- h5.app.dispose();
2167
- });
2168
-
2169
- it('S7-9 最小正例:mock 零足迹 → 非 null 空集(factory→formViews→registry 全链)', async () => {
2170
- const h2 = harnessWithContracts();
2171
- const app = await h2.tk.loadApp({ include: ['integrationFieldRegistry'] });
2172
- expect(app.integrationFieldRegistry).toEqual({
2173
- provider: 'mock', schemaless: [], unsupplied: [], additionalPropertiesAllowed: true, fields: [],
2174
- });
2175
- h2.app.dispose();
2176
- });
2177
-
2178
- // ── S8 双投影互证(依赖契约锁——旁路重取 serviceSchemas 破等式即刻红)──
2179
- it('S8 双投影互证:properties 键集 ≡ sources 反查 + schemaless 等价 + unsupplied 等式', async () => {
2180
- const h2 = layerHarness();
2181
- const v = await h2.tk.loadModule('module-parking', {
2182
- include: ['integrationSchemas', 'integrationFieldRegistry'],
2183
- moduleProvider: 'joycity',
2184
- });
2185
- const layer = v.integrationSchemas!;
2186
- const registry = v.integrationFieldRegistry!;
2187
- expect(registry.provider).toBe(layer.provider); // I1:同源同口径
2188
- for (const [s, entry] of Object.entries(layer.services)) {
2189
- const cfg = entry.configSchema;
2190
- if (cfg === null) {
2191
- expect(registry.schemaless, s).toContain(s);
2192
- continue;
2193
- }
2194
- expect(registry.schemaless, s).not.toContain(s);
2195
- const c = cfg as Record<string, unknown>;
2196
- const props = c.properties;
2197
- const declared = props && typeof props === 'object' && !Array.isArray(props) ? Object.keys(props) : []; // 同款守卫
2198
- const rev = registry.fields.filter((f) => f.sources.some((x) => x.service === s)).map((f) => f.key);
2199
- // G 批收窄互证:表单键 ⊆ 声明键,且声明侧标记键 ≡ 表单键(未标记键落 ExtraFields——不进 fields)
2200
- const marked = declared.filter((k) => {
2201
- const sub = (props as Record<string, Record<string, unknown>>)[k];
2202
- return !!sub && sub['x-tbox-global'] === true;
2203
- });
2204
- expect(rev.every((k) => declared.includes(k)), s).toBe(true);
2205
- expect([...marked].sort(), s).toEqual([...rev].sort());
2206
- }
2207
- for (const s of registry.schemaless) expect(layer.services[s]?.configSchema).toBeNull();
2208
- // unsupplied ≡ demand − scope 键集
2209
- const demand = v.services.map((x) => x.service);
2210
- const scopeKeys = Object.keys(layer.services);
2211
- expect([...registry.unsupplied].sort()).toEqual(demand.filter((s) => !scopeKeys.includes(s)).sort());
2212
- h2.app.dispose();
2213
- });
2214
-
2215
- it('G 批收窄负例(P16 复合可见面):未标记键在 layer.properties 在场、registry.fields 不收(wanda 实际态 parkLotId)', async () => {
2216
- const h2 = layerHarness();
2217
- const v = await h2.tk.loadModule('module-parking', { include: ['integrationSchemas', 'integrationFieldRegistry'] });
2218
- const layer = v.integrationSchemas!;
2219
- const registry = v.integrationFieldRegistry!;
2220
- expect(layer.provider).toBe('wanda');
2221
- const parkingProps = (layer.services['parking.payment'].configSchema as Record<string, Record<string, unknown>>).properties as Record<string, Record<string, unknown>>;
2222
- expect(parkingProps.mallId['x-tbox-global']).toBe(true);
2223
- expect(parkingProps.parkLotId).toBeDefined(); // 原始投影在场
2224
- expect(parkingProps.parkLotId['x-tbox-global']).toBeUndefined();
2225
- expect(registry.fields.some((f) => f.key === 'parkLotId')).toBe(false); // 表单收窄不收
2226
- expect(registry.fields.some((f) => f.key === 'mallId')).toBe(true);
2227
- // app 轴同律(足迹含 query——baseUrl 标记在场)
2228
- const appV = await h2.tk.loadApp({ include: ['integrationSchemas', 'integrationFieldRegistry'] });
2229
- expect(appV.integrationFieldRegistry!.fields.some((f) => f.key === 'baseUrl')).toBe(true);
2230
- h2.app.dispose();
2231
- });
2232
-
2233
- it('G 批服务轴不过滤锁:loadServiceFieldRegistry 全字段带旗标(unmarked → global:false 在场)', async () => {
2234
- const h2 = layerHarness();
2235
- const snap = (await import('../src/views/context.js')).loadViewSnapshotSync({ appDir: h2.app.appDir }, await h2.tk.resolveContracts());
2236
- const reg = loadServiceFieldRegistry(snap, 'parking.payment');
2237
- expect(reg).not.toBeNull();
2238
- const keys = reg!.fields.map((f) => f.key).sort();
2239
- expect(keys).toEqual(['mallId', 'parkLotId']); // 服务轴全量(未标记也入列——旗标 false 如实)
2240
- const lot = reg!.fields.find((f) => f.key === 'parkLotId')!;
2241
- expect(lot.global).toBe(false);
2242
- expect(lot.schema).toEqual({ type: 'string', title: '车场组' }); // 无标记污染
2243
- const mall = reg!.fields.find((f) => f.key === 'mallId')!;
2244
- expect(mall.global).toBe(true);
2245
- h2.app.dispose();
2246
- });
2247
-
2248
- it('S8 app 轴:unsupplied ≡ [](结构性:足迹 ⊆ 供给)', async () => {
2249
- const h2 = layerHarness();
2250
- const v = await h2.tk.loadApp({ include: ['integrationFieldRegistry'], appProvider: 'joycity' });
2251
- expect(v.integrationFieldRegistry?.unsupplied).toEqual([]);
2252
- h2.app.dispose();
1674
+ it('单源锁:loadServiceFieldRegistry ≡ buildIntegrationFieldRegistry over 链函数(无轴参形态)', async () => {
1675
+ const h = eHarness();
1676
+ const view = await h.tk.loadService('parking.query', { include: ['integrationFieldRegistry'] });
1677
+ const snap = loadViewSnapshotSync({ appDir: h.app.appDir }, await resolveContractsForApp(h.app.appDir));
1678
+ const chain = loadServiceIntegrationSchemas(snap, 'parking.query');
1679
+ const expected = chain
1680
+ ? buildIntegrationFieldRegistry({ provider: chain.provider, services: { 'parking.query': { configSchema: chain.configSchema } } })
1681
+ : null;
1682
+ expect(view.integrationFieldRegistry).toEqual(expected);
1683
+ h.app.dispose();
2253
1684
  });
2254
1685
  });
2255
1686
 
@@ -2475,16 +1906,11 @@ describe('B1 展示名链', () => {
2475
1906
  h2.app.dispose();
2476
1907
  });
2477
1908
 
2478
- it('T6 厂商 title 传播(walk 层首声明)+ /providers/:p services[] 走链', async () => {
1909
+ it('T6 厂商展示名传播(vendorMeta 单源——walk 层首声明;description 字段 v8 删)', async () => {
2479
1910
  const h2 = displayHarness();
2480
1911
  const list = await h2.tk.loadProviders();
2481
1912
  const wanda = list.providers.find((p) => p.provider === 'wanda');
2482
1913
  expect(wanda?.name).toBe('万达');
2483
- expect(wanda?.description).toBe('万达厂商集成');
2484
- const detail = await h2.tk.loadProvider('wanda');
2485
- expect(detail.name).toBe('万达');
2486
- expect(detail.services['parking.query']?.name).toBe('停车查询');
2487
- expect(detail.services['parking.query']?.description).toBe('费用报价、车场信息、可享权益');
2488
1914
  h2.app.dispose();
2489
1915
  });
2490
1916
  });