@peers-app/peers-sdk 0.27.2 → 0.27.4
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/contracts/contract-proxy.d.ts +7 -0
- package/dist/contracts/contract-proxy.js +19 -2
- package/dist/contracts/create-local-consumer.js +16 -1
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.js +2 -0
- package/dist/contracts/system/index.d.ts +2 -0
- package/dist/contracts/system/index.js +2 -0
- package/dist/contracts/system/invites-contract.js +2 -1
- package/dist/contracts/system/sync-check-contract.d.ts +97 -0
- package/dist/contracts/system/sync-check-contract.js +115 -0
- package/dist/contracts/tool-arguments.d.ts +15 -0
- package/dist/contracts/tool-arguments.js +41 -0
- package/dist/contracts/tool-catalog-service.js +2 -12
- package/dist/data/change-tracking.d.ts +40 -0
- package/dist/data/change-tracking.js +89 -0
- package/dist/data/orm/types.d.ts +24 -7
- package/dist/data/orm/types.js +97 -24
- package/dist/data/persistent-vars.d.ts +5 -0
- package/dist/data/persistent-vars.js +24 -6
- package/dist/define/manifest.js +6 -34
- package/dist/package-loader/package-loader.js +27 -22
- package/dist/system-ids.d.ts +5 -0
- package/dist/system-ids.js +6 -1
- package/package.json +4 -2
- package/dist/context/user-context-identity.test.d.ts +0 -1
- package/dist/context/user-context-identity.test.js +0 -220
- package/dist/contracts/__tests__/action-dispatch.test.d.ts +0 -1
- package/dist/contracts/__tests__/action-dispatch.test.js +0 -319
- package/dist/contracts/__tests__/also-implements.test.d.ts +0 -1
- package/dist/contracts/__tests__/also-implements.test.js +0 -110
- package/dist/contracts/__tests__/builder.test.d.ts +0 -1
- package/dist/contracts/__tests__/builder.test.js +0 -669
- package/dist/contracts/__tests__/contract-events.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-events.test.js +0 -199
- package/dist/contracts/__tests__/contract-observables.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-observables.test.js +0 -290
- package/dist/contracts/__tests__/contract-provider-router.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-provider-router.test.js +0 -315
- package/dist/contracts/__tests__/contract-proxy.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-proxy.test.js +0 -657
- package/dist/contracts/__tests__/contract-resolvers.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-resolvers.test.js +0 -758
- package/dist/contracts/__tests__/contract-subscription-lifecycle.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-subscription-lifecycle.test.js +0 -353
- package/dist/contracts/__tests__/contract-table-events.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-table-events.test.js +0 -209
- package/dist/contracts/__tests__/contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-transport.test.js +0 -163
- package/dist/contracts/__tests__/extract.test.d.ts +0 -1
- package/dist/contracts/__tests__/extract.test.js +0 -145
- package/dist/contracts/__tests__/frozen-contracts.test.d.ts +0 -1
- package/dist/contracts/__tests__/frozen-contracts.test.js +0 -191
- package/dist/contracts/__tests__/generic-tool-dispatch.test.d.ts +0 -1
- package/dist/contracts/__tests__/generic-tool-dispatch.test.js +0 -130
- package/dist/contracts/__tests__/host-contract-client.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-client.test.js +0 -793
- package/dist/contracts/__tests__/host-contract-consumer.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-consumer.test.js +0 -163
- package/dist/contracts/__tests__/host-contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-transport.test.js +0 -66
- package/dist/contracts/__tests__/integration.test.d.ts +0 -1
- package/dist/contracts/__tests__/integration.test.js +0 -348
- package/dist/contracts/__tests__/legacy-removal.test.d.ts +0 -1
- package/dist/contracts/__tests__/legacy-removal.test.js +0 -128
- package/dist/contracts/__tests__/persistent-registry.test.d.ts +0 -1
- package/dist/contracts/__tests__/persistent-registry.test.js +0 -109
- package/dist/contracts/__tests__/playground.test.d.ts +0 -1
- package/dist/contracts/__tests__/playground.test.js +0 -216
- package/dist/contracts/__tests__/registry.test.d.ts +0 -1
- package/dist/contracts/__tests__/registry.test.js +0 -238
- package/dist/contracts/__tests__/remote-contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/remote-contract-transport.test.js +0 -119
- package/dist/contracts/__tests__/system-contracts.test.d.ts +0 -1
- package/dist/contracts/__tests__/system-contracts.test.js +0 -247
- package/dist/contracts/__tests__/target-dispatch.d.ts +0 -11
- package/dist/contracts/__tests__/target-dispatch.js +0 -24
- package/dist/contracts/__tests__/tool-catalog-inventory.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog-inventory.test.js +0 -44
- package/dist/contracts/__tests__/tool-catalog-service.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog-service.test.js +0 -482
- package/dist/contracts/__tests__/tool-catalog.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog.test.js +0 -1199
- package/dist/contracts/__tests__/validate.test.d.ts +0 -1
- package/dist/contracts/__tests__/validate.test.js +0 -991
- package/dist/contracts/__tests__/workflow-context.test.d.ts +0 -1
- package/dist/contracts/__tests__/workflow-context.test.js +0 -50
- package/dist/data/access-level.test.d.ts +0 -1
- package/dist/data/access-level.test.js +0 -53
- package/dist/data/change-tracking.test.d.ts +0 -1
- package/dist/data/change-tracking.test.js +0 -62
- package/dist/data/files/files.test.d.ts +0 -1
- package/dist/data/files/files.test.js +0 -770
- package/dist/data/group-members.test.d.ts +0 -1
- package/dist/data/group-members.test.js +0 -336
- package/dist/data/group-share.test.d.ts +0 -1
- package/dist/data/group-share.test.js +0 -110
- package/dist/data/groups.test.d.ts +0 -1
- package/dist/data/groups.test.js +0 -153
- package/dist/data/orm/cursor.test.d.ts +0 -1
- package/dist/data/orm/cursor.test.js +0 -314
- package/dist/data/orm/data-query.mongo.test.d.ts +0 -1
- package/dist/data/orm/data-query.mongo.test.js +0 -367
- package/dist/data/orm/data-query.sqlite.test.d.ts +0 -1
- package/dist/data/orm/data-query.sqlite.test.js +0 -365
- package/dist/data/orm/data-query.test.d.ts +0 -1
- package/dist/data/orm/data-query.test.js +0 -545
- package/dist/data/orm/dependency-injection.test.d.ts +0 -1
- package/dist/data/orm/dependency-injection.test.js +0 -171
- package/dist/data/orm/event-registry.test.d.ts +0 -1
- package/dist/data/orm/event-registry.test.js +0 -44
- package/dist/data/orm/multi-cursors.test.d.ts +0 -1
- package/dist/data/orm/multi-cursors.test.js +0 -463
- package/dist/data/orm/sql.data-source.test.d.ts +0 -1
- package/dist/data/orm/sql.data-source.test.js +0 -731
- package/dist/data/orm/table-container-events.test.d.ts +0 -1
- package/dist/data/orm/table-container-events.test.js +0 -101
- package/dist/data/orm/table-container.test.d.ts +0 -1
- package/dist/data/orm/table-container.test.js +0 -273
- package/dist/data/orm/table.event-source.test.d.ts +0 -1
- package/dist/data/orm/table.event-source.test.js +0 -331
- package/dist/data/orm/types.test.d.ts +0 -1
- package/dist/data/orm/types.test.js +0 -409
- package/dist/data/package-table-identity.test.d.ts +0 -1
- package/dist/data/package-table-identity.test.js +0 -46
- package/dist/data/package-version-permissions.test.d.ts +0 -1
- package/dist/data/package-version-permissions.test.js +0 -107
- package/dist/data/package-version-resolver.test.d.ts +0 -4
- package/dist/data/package-version-resolver.test.js +0 -543
- package/dist/data/package-versions.test.d.ts +0 -1
- package/dist/data/package-versions.test.js +0 -227
- package/dist/data/persistent-vars.conflict.test.d.ts +0 -1
- package/dist/data/persistent-vars.conflict.test.js +0 -126
- package/dist/data/persistent-vars.migration.test.d.ts +0 -1
- package/dist/data/persistent-vars.migration.test.js +0 -133
- package/dist/data/persistent-vars.package-scope.test.d.ts +0 -1
- package/dist/data/persistent-vars.package-scope.test.js +0 -27
- package/dist/data/sync-recovery-queue.test.d.ts +0 -1
- package/dist/data/sync-recovery-queue.test.js +0 -215
- package/dist/data/table-signing.test.d.ts +0 -1
- package/dist/data/table-signing.test.js +0 -118
- package/dist/data/tool-access.test.d.ts +0 -1
- package/dist/data/tool-access.test.js +0 -166
- package/dist/data/user-permissions.test.d.ts +0 -1
- package/dist/data/user-permissions.test.js +0 -305
- package/dist/data/user-trust-levels.test.d.ts +0 -1
- package/dist/data/user-trust-levels.test.js +0 -37
- package/dist/define/also-implements.test.d.ts +0 -1
- package/dist/define/also-implements.test.js +0 -123
- package/dist/define/declare-contract.test.d.ts +0 -1
- package/dist/define/declare-contract.test.js +0 -573
- package/dist/define/define.test.d.ts +0 -1
- package/dist/define/define.test.js +0 -1010
- package/dist/define/empty-fields.test.d.ts +0 -1
- package/dist/define/empty-fields.test.js +0 -55
- package/dist/define/events-observables.test.d.ts +0 -1
- package/dist/define/events-observables.test.js +0 -1013
- package/dist/define/serve-members.test.d.ts +0 -1
- package/dist/define/serve-members.test.js +0 -630
- package/dist/define/vars.test.d.ts +0 -1
- package/dist/define/vars.test.js +0 -39
- package/dist/device/binary-peer-connection-v2.test.d.ts +0 -1
- package/dist/device/binary-peer-connection-v2.test.js +0 -730
- package/dist/device/binary-peer-connection.test.d.ts +0 -1
- package/dist/device/binary-peer-connection.test.js +0 -184
- package/dist/device/connection.test.d.ts +0 -1
- package/dist/device/connection.test.js +0 -613
- package/dist/device/device-election.test.d.ts +0 -1
- package/dist/device/device-election.test.js +0 -516
- package/dist/device/device.test.d.ts +0 -1
- package/dist/device/device.test.js +0 -243
- package/dist/device/frame-cipher.test.d.ts +0 -1
- package/dist/device/frame-cipher.test.js +0 -219
- package/dist/device/get-trust-level-fn.test.d.ts +0 -1
- package/dist/device/get-trust-level-fn.test.js +0 -685
- package/dist/device/streamed-socket.test.d.ts +0 -1
- package/dist/device/streamed-socket.test.js +0 -216
- package/dist/device/tx-encoding.test.d.ts +0 -1
- package/dist/device/tx-encoding.test.js +0 -295
- package/dist/device-pairing/cpace.test.d.ts +0 -1
- package/dist/device-pairing/cpace.test.js +0 -116
- package/dist/device-pairing/device-pairing.test.d.ts +0 -1
- package/dist/device-pairing/device-pairing.test.js +0 -211
- package/dist/hlc.test.d.ts +0 -1
- package/dist/hlc.test.js +0 -45
- package/dist/host-credentials.test.d.ts +0 -1
- package/dist/host-credentials.test.js +0 -88
- package/dist/identity/account-email.test.d.ts +0 -1
- package/dist/identity/account-email.test.js +0 -59
- package/dist/identity/anchor-document.test.d.ts +0 -1
- package/dist/identity/anchor-document.test.js +0 -16
- package/dist/identity/anchor-resolution.test.d.ts +0 -1
- package/dist/identity/anchor-resolution.test.js +0 -130
- package/dist/identity/key-change.test.d.ts +0 -1
- package/dist/identity/key-change.test.js +0 -811
- package/dist/invites/group-approval.test.d.ts +0 -1
- package/dist/invites/group-approval.test.js +0 -223
- package/dist/invites/invite-token.test.d.ts +0 -1
- package/dist/invites/invite-token.test.js +0 -123
- package/dist/keys.test.d.ts +0 -1
- package/dist/keys.test.js +0 -336
- package/dist/logging/console-logger.test.d.ts +0 -1
- package/dist/logging/console-logger.test.js +0 -300
- package/dist/logging/console-logs.table.test.d.ts +0 -1
- package/dist/logging/console-logs.table.test.js +0 -156
- package/dist/observable.test.d.ts +0 -1
- package/dist/observable.test.js +0 -309
- package/dist/package-build/build-package.test.d.ts +0 -1
- package/dist/package-build/build-package.test.js +0 -204
- package/dist/package-build/contract-add.test.d.ts +0 -1
- package/dist/package-build/contract-add.test.js +0 -467
- package/dist/package-build/freeze-contracts.test.d.ts +0 -1
- package/dist/package-build/freeze-contracts.test.js +0 -355
- package/dist/package-installer/package-author-signing.test.d.ts +0 -1
- package/dist/package-installer/package-author-signing.test.js +0 -200
- package/dist/package-installer/package-cloner.test.d.ts +0 -1
- package/dist/package-installer/package-cloner.test.js +0 -278
- package/dist/package-installer/package-creator.test.d.ts +0 -1
- package/dist/package-installer/package-creator.test.js +0 -908
- package/dist/package-installer/package-dev-tools.test.d.ts +0 -1
- package/dist/package-installer/package-dev-tools.test.js +0 -64
- package/dist/package-installer/package-installer.test.d.ts +0 -1
- package/dist/package-installer/package-installer.test.js +0 -882
- package/dist/package-installer/package-propagation.test.d.ts +0 -1
- package/dist/package-installer/package-propagation.test.js +0 -1269
- package/dist/package-installer/package-publisher.test.d.ts +0 -1
- package/dist/package-installer/package-publisher.test.js +0 -153
- package/dist/package-installer/package-remote-checker.test.d.ts +0 -1
- package/dist/package-installer/package-remote-checker.test.js +0 -334
- package/dist/package-installer/package-seed-installer.test.d.ts +0 -1
- package/dist/package-installer/package-seed-installer.test.js +0 -123
- package/dist/package-installer/package-tarball.test.d.ts +0 -1
- package/dist/package-installer/package-tarball.test.js +0 -75
- package/dist/package-installer/peers-core-installer.test.d.ts +0 -1
- package/dist/package-installer/peers-core-installer.test.js +0 -49
- package/dist/package-installer/peers-core-trust-anchor.test.d.ts +0 -1
- package/dist/package-installer/peers-core-trust-anchor.test.js +0 -155
- package/dist/package-loader/contract-package-loader.test.d.ts +0 -1
- package/dist/package-loader/contract-package-loader.test.js +0 -274
- package/dist/package-loader/host-authority-loading.test.d.ts +0 -1
- package/dist/package-loader/host-authority-loading.test.js +0 -104
- package/dist/package-loader/host-dispatch-policy.test.d.ts +0 -1
- package/dist/package-loader/host-dispatch-policy.test.js +0 -56
- package/dist/package-loader/isolated-artifact.test.d.ts +0 -1
- package/dist/package-loader/isolated-artifact.test.js +0 -688
- package/dist/package-loader/isolated-persistent-var-gateway.test.d.ts +0 -1
- package/dist/package-loader/isolated-persistent-var-gateway.test.js +0 -56
- package/dist/package-loader/isolated-table-gateway.test.d.ts +0 -1
- package/dist/package-loader/isolated-table-gateway.test.js +0 -633
- package/dist/package-loader/package-loader.test.d.ts +0 -1
- package/dist/package-loader/package-loader.test.js +0 -1764
- package/dist/package-loader/resolve-consumed-contracts.test.d.ts +0 -1
- package/dist/package-loader/resolve-consumed-contracts.test.js +0 -166
- package/dist/serial-json.compat.test.d.ts +0 -1
- package/dist/serial-json.compat.test.js +0 -369
- package/dist/serial-json.test.d.ts +0 -1
- package/dist/serial-json.test.js +0 -401
- package/dist/testing/mock-host-contract.test.d.ts +0 -1
- package/dist/testing/mock-host-contract.test.js +0 -782
- package/dist/utils.test.d.ts +0 -1
- package/dist/utils.test.js +0 -232
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("../../utils");
|
|
4
|
-
const registry_1 = require("../registry");
|
|
5
|
-
function makeDefinition(contractId, version, name = "Test Contract") {
|
|
6
|
-
return {
|
|
7
|
-
contractId,
|
|
8
|
-
version,
|
|
9
|
-
devTag: "dev",
|
|
10
|
-
name,
|
|
11
|
-
description: "test",
|
|
12
|
-
tables: [],
|
|
13
|
-
tools: [],
|
|
14
|
-
observables: [],
|
|
15
|
-
events: [],
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
describe("ContractRegistry.selectProvider", () => {
|
|
19
|
-
const contractId = (0, utils_1.newid)();
|
|
20
|
-
const packageA = (0, utils_1.newid)();
|
|
21
|
-
const packageB = (0, utils_1.newid)();
|
|
22
|
-
const packageC = (0, utils_1.newid)();
|
|
23
|
-
let registry;
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
registry = new registry_1.ContractRegistry();
|
|
26
|
-
registry.register(packageA, makeDefinition(contractId, 1, "A"));
|
|
27
|
-
registry.register(packageB, makeDefinition(contractId, 1, "B"));
|
|
28
|
-
});
|
|
29
|
-
it("returns registered provider ids in registration order", () => {
|
|
30
|
-
expect(registry.getRegisteredProviderIds(contractId, 1)).toEqual([packageA, packageB]);
|
|
31
|
-
});
|
|
32
|
-
it("selects the active provider when no preference is given", () => {
|
|
33
|
-
const selected = registry.selectProvider({ contractId, version: 1 });
|
|
34
|
-
expect(selected?.providerPackageId).toBe(packageA);
|
|
35
|
-
});
|
|
36
|
-
it("selects the first preferred provider that is registered", () => {
|
|
37
|
-
const dep = {
|
|
38
|
-
contractId,
|
|
39
|
-
version: 1,
|
|
40
|
-
providerPackageIds: [packageC, packageB, packageA],
|
|
41
|
-
};
|
|
42
|
-
expect(registry.selectProvider(dep)?.providerPackageId).toBe(packageB);
|
|
43
|
-
});
|
|
44
|
-
it("falls back to the active provider when preferred are missing and fallback is enabled", () => {
|
|
45
|
-
const dep = {
|
|
46
|
-
contractId,
|
|
47
|
-
version: 1,
|
|
48
|
-
providerPackageIds: [packageC],
|
|
49
|
-
fallbackToDefaultProvider: true,
|
|
50
|
-
};
|
|
51
|
-
expect(registry.selectProvider(dep)?.providerPackageId).toBe(packageA);
|
|
52
|
-
});
|
|
53
|
-
it("returns undefined when preferred are missing and fallback is disabled", () => {
|
|
54
|
-
const dep = {
|
|
55
|
-
contractId,
|
|
56
|
-
version: 1,
|
|
57
|
-
providerPackageIds: [packageC],
|
|
58
|
-
fallbackToDefaultProvider: false,
|
|
59
|
-
};
|
|
60
|
-
expect(registry.selectProvider(dep)).toBeUndefined();
|
|
61
|
-
});
|
|
62
|
-
it("returns undefined when no providers are registered", () => {
|
|
63
|
-
const empty = new registry_1.ContractRegistry();
|
|
64
|
-
expect(empty.selectProvider({ contractId, version: 1 })).toBeUndefined();
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
describe("ContractRegistry.registerBatch", () => {
|
|
68
|
-
it("registers same-batch alsoImplements targets atomically", () => {
|
|
69
|
-
const registry = new registry_1.ContractRegistry();
|
|
70
|
-
const providerPackageId = (0, utils_1.newid)();
|
|
71
|
-
const targetContractId = (0, utils_1.newid)();
|
|
72
|
-
const implementationContractId = (0, utils_1.newid)();
|
|
73
|
-
const result = registry.registerBatch(providerPackageId, [
|
|
74
|
-
{ definition: makeDefinition(targetContractId, 1, "Target") },
|
|
75
|
-
{
|
|
76
|
-
definition: makeDefinition(implementationContractId, 2, "Implementation"),
|
|
77
|
-
alsoImplements: [{ contractId: targetContractId, version: 1 }],
|
|
78
|
-
},
|
|
79
|
-
]);
|
|
80
|
-
expect(result.valid).toBe(true);
|
|
81
|
-
expect(registry.getProviderPackageId(targetContractId, 1)).toBe(providerPackageId);
|
|
82
|
-
expect(registry.getProviderPackageId(implementationContractId, 2)).toBe(providerPackageId);
|
|
83
|
-
});
|
|
84
|
-
it("registers alsoImplements as a routable provider alias", () => {
|
|
85
|
-
const registry = new registry_1.ContractRegistry();
|
|
86
|
-
const originalProvider = (0, utils_1.newid)();
|
|
87
|
-
const compatibleProvider = (0, utils_1.newid)();
|
|
88
|
-
const contractId = (0, utils_1.newid)();
|
|
89
|
-
registry.register(originalProvider, makeDefinition(contractId, 1, "Version 1"));
|
|
90
|
-
const result = registry.registerBatch(compatibleProvider, [
|
|
91
|
-
{
|
|
92
|
-
definition: makeDefinition(contractId, 2, "Version 2"),
|
|
93
|
-
alsoImplements: [{ contractId, version: 1 }],
|
|
94
|
-
},
|
|
95
|
-
]);
|
|
96
|
-
expect(result.valid).toBe(true);
|
|
97
|
-
expect(registry.getRegisteredProviderIds(contractId, 1)).toEqual([
|
|
98
|
-
originalProvider,
|
|
99
|
-
compatibleProvider,
|
|
100
|
-
]);
|
|
101
|
-
expect(registry.getProviderImplementation(contractId, 1, compatibleProvider)).toEqual({
|
|
102
|
-
contractId,
|
|
103
|
-
version: 2,
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
it("leaves registry state unchanged when any batch entry fails", () => {
|
|
107
|
-
const registry = new registry_1.ContractRegistry();
|
|
108
|
-
const existingProvider = (0, utils_1.newid)();
|
|
109
|
-
const rejectedProvider = (0, utils_1.newid)();
|
|
110
|
-
const existingContractId = (0, utils_1.newid)();
|
|
111
|
-
const newContractId = (0, utils_1.newid)();
|
|
112
|
-
const frozen = { ...makeDefinition(existingContractId, 1, "Frozen"), devTag: undefined };
|
|
113
|
-
expect(registry.register(existingProvider, frozen).valid).toBe(true);
|
|
114
|
-
const result = registry.registerBatch(rejectedProvider, [
|
|
115
|
-
{ definition: makeDefinition(newContractId, 1, "Would Be Partial") },
|
|
116
|
-
{ definition: makeDefinition(existingContractId, 1, "Frozen Changed") },
|
|
117
|
-
]);
|
|
118
|
-
expect(result.valid).toBe(false);
|
|
119
|
-
expect(registry.getDefinition(newContractId, 1)).toBeUndefined();
|
|
120
|
-
expect(registry.getRegisteredProviderIds(newContractId, 1)).toEqual([]);
|
|
121
|
-
expect(registry.getProviderPackageId(existingContractId, 1)).toBe(existingProvider);
|
|
122
|
-
expect(registry.getRegisteredProviderIds(existingContractId, 1)).toEqual([existingProvider]);
|
|
123
|
-
});
|
|
124
|
-
it("preserves the existing active provider when another package registers a batch", () => {
|
|
125
|
-
const registry = new registry_1.ContractRegistry();
|
|
126
|
-
const contractId = (0, utils_1.newid)();
|
|
127
|
-
const activeProvider = (0, utils_1.newid)();
|
|
128
|
-
const additionalProvider = (0, utils_1.newid)();
|
|
129
|
-
registry.register(activeProvider, makeDefinition(contractId, 1, "Active"));
|
|
130
|
-
expect(registry.registerBatch(additionalProvider, [
|
|
131
|
-
{ definition: makeDefinition(contractId, 1, "Additional") },
|
|
132
|
-
]).valid).toBe(true);
|
|
133
|
-
expect(registry.getProviderPackageId(contractId, 1)).toBe(activeProvider);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
describe("ContractRegistry.replaceBatch", () => {
|
|
137
|
-
it("replaces the provider's complete contract set and preserves its active selections", () => {
|
|
138
|
-
const registry = new registry_1.ContractRegistry();
|
|
139
|
-
const providerPackageId = (0, utils_1.newid)();
|
|
140
|
-
const retainedContractId = (0, utils_1.newid)();
|
|
141
|
-
const removedContractId = (0, utils_1.newid)();
|
|
142
|
-
const addedContractId = (0, utils_1.newid)();
|
|
143
|
-
registry.registerBatch(providerPackageId, [
|
|
144
|
-
{ definition: makeDefinition(retainedContractId, 1, "Retained") },
|
|
145
|
-
{ definition: makeDefinition(removedContractId, 1, "Removed") },
|
|
146
|
-
]);
|
|
147
|
-
const result = registry.replaceBatch(providerPackageId, [
|
|
148
|
-
{ definition: makeDefinition(retainedContractId, 1, "Retained replacement") },
|
|
149
|
-
{ definition: makeDefinition(addedContractId, 1, "Added") },
|
|
150
|
-
]);
|
|
151
|
-
expect(result.valid).toBe(true);
|
|
152
|
-
expect(registry.getProviderPackageId(retainedContractId, 1)).toBe(providerPackageId);
|
|
153
|
-
expect(registry.getRegisteredProviderIds(removedContractId, 1)).toEqual([]);
|
|
154
|
-
expect(registry.getProviderPackageId(addedContractId, 1)).toBe(providerPackageId);
|
|
155
|
-
});
|
|
156
|
-
it("leaves the previous provider set untouched when replacement validation fails", () => {
|
|
157
|
-
const registry = new registry_1.ContractRegistry();
|
|
158
|
-
const providerPackageId = (0, utils_1.newid)();
|
|
159
|
-
const existingContractId = (0, utils_1.newid)();
|
|
160
|
-
const rejectedContractId = (0, utils_1.newid)();
|
|
161
|
-
registry.register(providerPackageId, makeDefinition(existingContractId, 1, "Existing"));
|
|
162
|
-
const result = registry.replaceBatch(providerPackageId, [
|
|
163
|
-
{ definition: makeDefinition(rejectedContractId, 1, "Rejected") },
|
|
164
|
-
{ definition: makeDefinition(rejectedContractId, 1, "Duplicate") },
|
|
165
|
-
]);
|
|
166
|
-
expect(result.valid).toBe(false);
|
|
167
|
-
expect(registry.getProviderPackageId(existingContractId, 1)).toBe(providerPackageId);
|
|
168
|
-
expect(registry.getRegisteredProviderIds(rejectedContractId, 1)).toEqual([]);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
describe("ContractRegistry exposes", () => {
|
|
172
|
-
const hubId = (0, utils_1.newid)();
|
|
173
|
-
const newsId = (0, utils_1.newid)();
|
|
174
|
-
const provider = (0, utils_1.newid)();
|
|
175
|
-
const other = (0, utils_1.newid)();
|
|
176
|
-
it("keeps each provider's exposures, outside the contract's definition", () => {
|
|
177
|
-
const registry = new registry_1.ContractRegistry();
|
|
178
|
-
const result = registry.registerBatch(provider, [
|
|
179
|
-
{ definition: makeDefinition(newsId, 1, "News") },
|
|
180
|
-
{
|
|
181
|
-
definition: makeDefinition(hubId, 2, "Hub"),
|
|
182
|
-
exposes: [{ contractId: newsId, version: 1 }],
|
|
183
|
-
},
|
|
184
|
-
]);
|
|
185
|
-
expect(result.valid).toBe(true);
|
|
186
|
-
registry.registerBatch(other, [{ definition: makeDefinition(hubId, 2, "Hub") }]);
|
|
187
|
-
expect(registry.getExposedContracts(hubId, 2, provider)).toEqual([
|
|
188
|
-
{ contractId: newsId, version: 1 },
|
|
189
|
-
]);
|
|
190
|
-
expect(registry.getExposedContracts(hubId, 2, other)).toEqual([]);
|
|
191
|
-
expect(registry.getExposedContracts(newsId, 1, provider)).toEqual([]);
|
|
192
|
-
expect(registry.getExposedContracts(hubId, 2, (0, utils_1.newid)())).toEqual([]);
|
|
193
|
-
expect(registry.getDefinition(hubId, 2)).not.toHaveProperty("exposes");
|
|
194
|
-
expect(registry.getProviderDefinition(newsId, 1, provider)?.name).toBe("News");
|
|
195
|
-
expect(registry.getProviderDefinition(newsId, 1, other)).toBeUndefined();
|
|
196
|
-
// A caller can't change what the registry holds through the returned list.
|
|
197
|
-
registry.getExposedContracts(hubId, 2, provider).pop();
|
|
198
|
-
expect(registry.getExposedContracts(hubId, 2, provider)).toHaveLength(1);
|
|
199
|
-
});
|
|
200
|
-
it("carries exposures to an alsoImplements alias, and drops them on replacement", () => {
|
|
201
|
-
const registry = new registry_1.ContractRegistry();
|
|
202
|
-
registry.register(other, makeDefinition(hubId, 1, "Hub v1"));
|
|
203
|
-
registry.registerBatch(provider, [
|
|
204
|
-
{ definition: makeDefinition(newsId, 1, "News") },
|
|
205
|
-
{
|
|
206
|
-
definition: makeDefinition(hubId, 2, "Hub"),
|
|
207
|
-
alsoImplements: [{ contractId: hubId, version: 1 }],
|
|
208
|
-
exposes: [{ contractId: newsId, version: 1 }],
|
|
209
|
-
},
|
|
210
|
-
]);
|
|
211
|
-
expect(registry.getExposedContracts(hubId, 1, provider)).toEqual([
|
|
212
|
-
{ contractId: newsId, version: 1 },
|
|
213
|
-
]);
|
|
214
|
-
registry.replaceBatch(provider, [
|
|
215
|
-
{ definition: makeDefinition(newsId, 1, "News") },
|
|
216
|
-
{ definition: makeDefinition(hubId, 2, "Hub") },
|
|
217
|
-
]);
|
|
218
|
-
expect(registry.getExposedContracts(hubId, 2, provider)).toEqual([]);
|
|
219
|
-
});
|
|
220
|
-
it("refuses an exposure the batch doesn't provide, of itself, or twice", () => {
|
|
221
|
-
const registry = new registry_1.ContractRegistry();
|
|
222
|
-
const hub = (exposes) => [
|
|
223
|
-
{ definition: makeDefinition(newsId, 1, "News") },
|
|
224
|
-
{ definition: makeDefinition(hubId, 2, "Hub"), exposes },
|
|
225
|
-
];
|
|
226
|
-
expect(registry.validateBatch(provider, hub([{ contractId: (0, utils_1.newid)(), version: 1 }]))).toEqual(expect.objectContaining({
|
|
227
|
-
valid: false,
|
|
228
|
-
errors: [expect.objectContaining({ message: expect.stringMatching(/doesn't provide/) })],
|
|
229
|
-
}));
|
|
230
|
-
expect(registry.validateBatch(provider, hub([{ contractId: hubId, version: 2 }])).errors[0].message).toMatch(/can't expose itself/);
|
|
231
|
-
expect(registry.validateBatch(provider, hub([
|
|
232
|
-
{ contractId: newsId, version: 1 },
|
|
233
|
-
{ contractId: newsId, version: 1 },
|
|
234
|
-
])).errors[0].message).toMatch(/twice/);
|
|
235
|
-
expect(registry.registerBatch(provider, hub([{ contractId: newsId, version: 2 }])).valid).toBe(false);
|
|
236
|
-
expect(registry.getRegisteredProviderIds(newsId, 1)).toEqual([]);
|
|
237
|
-
});
|
|
238
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const system_ids_1 = require("../../system-ids");
|
|
4
|
-
const index_1 = require("../index");
|
|
5
|
-
const makeRequest = (overrides = {}) => ({
|
|
6
|
-
contractId: "contract-a",
|
|
7
|
-
version: 1,
|
|
8
|
-
dataContextId: "group-1",
|
|
9
|
-
targetDeviceId: "device-b",
|
|
10
|
-
context: {},
|
|
11
|
-
notify: async () => undefined,
|
|
12
|
-
...overrides,
|
|
13
|
-
});
|
|
14
|
-
const toolCall = {
|
|
15
|
-
contractId: "contract-a",
|
|
16
|
-
version: 1,
|
|
17
|
-
member: "tool",
|
|
18
|
-
name: "ping",
|
|
19
|
-
operation: "run",
|
|
20
|
-
args: [{ n: 1 }],
|
|
21
|
-
dataContextId: "group-1",
|
|
22
|
-
targetDeviceId: "device-b",
|
|
23
|
-
};
|
|
24
|
-
function makeTransport() {
|
|
25
|
-
const emit = jest.fn(async (_channel, ..._args) => "pong");
|
|
26
|
-
const transport = { emit, on: () => () => undefined };
|
|
27
|
-
return { transport, emit };
|
|
28
|
-
}
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
(0, index_1.setRemoteContractTransportFactory)(undefined);
|
|
31
|
-
});
|
|
32
|
-
describe("remote contract endpoint", () => {
|
|
33
|
-
it("selects the current transport for every call on a cached endpoint", async () => {
|
|
34
|
-
const first = makeTransport();
|
|
35
|
-
const second = makeTransport();
|
|
36
|
-
let current = first.transport;
|
|
37
|
-
const endpoint = (0, index_1.createRemoteContractEndpoint)(makeRequest(), () => current);
|
|
38
|
-
await endpoint.handleCall(toolCall, {});
|
|
39
|
-
current = second.transport;
|
|
40
|
-
await endpoint.handleCall(toolCall, {});
|
|
41
|
-
expect(first.emit).toHaveBeenCalledTimes(1);
|
|
42
|
-
expect(second.emit).toHaveBeenCalledTimes(1);
|
|
43
|
-
});
|
|
44
|
-
it("strips targetDeviceId and pins the authorized data context before emitting", async () => {
|
|
45
|
-
const { transport, emit } = makeTransport();
|
|
46
|
-
const factory = jest.fn(() => transport);
|
|
47
|
-
const endpoint = (0, index_1.createRemoteContractEndpoint)(makeRequest(), factory);
|
|
48
|
-
await expect(endpoint.handleCall(toolCall, {})).resolves.toBe("pong");
|
|
49
|
-
expect(factory).toHaveBeenCalledWith({ deviceId: "device-b", dataContextId: "group-1" });
|
|
50
|
-
expect(emit).toHaveBeenCalledTimes(1);
|
|
51
|
-
const [channel, sent] = emit.mock.calls[0];
|
|
52
|
-
expect(channel).toBe(index_1.CONTRACT_REQUEST_CHANNEL);
|
|
53
|
-
expect(sent).not.toHaveProperty("targetDeviceId");
|
|
54
|
-
expect(sent).toMatchObject({ name: "ping", dataContextId: "group-1", args: [{ n: 1 }] });
|
|
55
|
-
});
|
|
56
|
-
it("refuses to forward anything but tool runs and rejects after dispose", async () => {
|
|
57
|
-
const { transport, emit } = makeTransport();
|
|
58
|
-
const endpoint = (0, index_1.createRemoteContractEndpoint)(makeRequest(), () => transport);
|
|
59
|
-
await expect(endpoint.handleCall({ ...toolCall, member: "table", name: "Items", operation: "list" }, {})).rejects.toThrow("cannot be forwarded");
|
|
60
|
-
endpoint.dispose();
|
|
61
|
-
await expect(endpoint.handleCall(toolCall, {})).rejects.toThrow("disposed");
|
|
62
|
-
expect(emit).not.toHaveBeenCalled();
|
|
63
|
-
});
|
|
64
|
-
it.each([
|
|
65
|
-
["System App Updates", system_ids_1.appUpdatesContractId],
|
|
66
|
-
["System Packages", system_ids_1.packagesContractId],
|
|
67
|
-
["Device Operations", system_ids_1.deviceOperationsContractId],
|
|
68
|
-
])("refuses to forward a package's call to %s", async (_name, contractId) => {
|
|
69
|
-
const { transport, emit } = makeTransport();
|
|
70
|
-
const packageContext = { callerPackageId: "package-a" };
|
|
71
|
-
expect(() => (0, index_1.createRemoteContractEndpoint)(makeRequest({ contractId, context: packageContext }), () => transport)).toThrow("packages cannot call system contract");
|
|
72
|
-
// A package endpoint for its own contract cannot be steered at a system contract.
|
|
73
|
-
const packageTool = (0, index_1.createRemoteContractEndpoint)(makeRequest({ context: packageContext }), () => transport);
|
|
74
|
-
await expect(packageTool.handleCall({ ...toolCall, contractId }, packageContext)).rejects.toThrow("packages cannot call system contract");
|
|
75
|
-
expect(emit).not.toHaveBeenCalled();
|
|
76
|
-
// The user (no package) still reaches it, and the package still reaches its own contract.
|
|
77
|
-
const operator = (0, index_1.createRemoteContractEndpoint)(makeRequest({ contractId }), () => transport);
|
|
78
|
-
await expect(operator.handleCall({ ...toolCall, contractId }, {})).resolves.toBe("pong");
|
|
79
|
-
await expect(packageTool.handleCall(toolCall, packageContext)).resolves.toBe("pong");
|
|
80
|
-
expect(emit).toHaveBeenCalledTimes(2);
|
|
81
|
-
});
|
|
82
|
-
it("fails clearly when no transport factory is registered or the route is incomplete", () => {
|
|
83
|
-
expect(() => (0, index_1.createRemoteContractEndpoint)(makeRequest())).toThrow("no remote contract transport is registered");
|
|
84
|
-
expect(() => (0, index_1.createRemoteContractEndpoint)(makeRequest({ dataContextId: undefined }), () => makeTransport().transport)).toThrow("data context");
|
|
85
|
-
expect(() => (0, index_1.createRemoteContractEndpoint)(makeRequest({ targetDeviceId: undefined }), () => makeTransport().transport)).toThrow("target device");
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
describe("resolveRemoteTargetEndpoint", () => {
|
|
89
|
-
it("returns undefined for local routes and for the local device itself", () => {
|
|
90
|
-
(0, index_1.setRemoteContractTransportFactory)(() => makeTransport().transport);
|
|
91
|
-
expect((0, index_1.resolveRemoteTargetEndpoint)(makeRequest({ targetDeviceId: undefined }), {
|
|
92
|
-
localDeviceId: "device-a",
|
|
93
|
-
})).toBeUndefined();
|
|
94
|
-
expect((0, index_1.resolveRemoteTargetEndpoint)(makeRequest({ targetDeviceId: "device-a" }), {
|
|
95
|
-
localDeviceId: "device-a",
|
|
96
|
-
})).toBeUndefined();
|
|
97
|
-
});
|
|
98
|
-
it("prefers a factory scoped to the owning user context over the process default", async () => {
|
|
99
|
-
const scoped = makeTransport();
|
|
100
|
-
const fallback = makeTransport();
|
|
101
|
-
const userContext = {};
|
|
102
|
-
(0, index_1.setRemoteContractTransportFactory)(() => fallback.transport);
|
|
103
|
-
(0, index_1.setRemoteContractTransportFactory)(() => scoped.transport, { userContext });
|
|
104
|
-
const scopedEndpoint = (0, index_1.resolveRemoteTargetEndpoint)(makeRequest(), {
|
|
105
|
-
localDeviceId: "device-a",
|
|
106
|
-
userContext,
|
|
107
|
-
});
|
|
108
|
-
const fallbackEndpoint = (0, index_1.resolveRemoteTargetEndpoint)(makeRequest(), {
|
|
109
|
-
localDeviceId: "device-a",
|
|
110
|
-
});
|
|
111
|
-
await scopedEndpoint?.handleCall(toolCall, {});
|
|
112
|
-
await fallbackEndpoint?.handleCall(toolCall, {});
|
|
113
|
-
expect(scoped.emit).toHaveBeenCalledTimes(1);
|
|
114
|
-
expect(fallback.emit).toHaveBeenCalledTimes(1);
|
|
115
|
-
(0, index_1.setRemoteContractTransportFactory)(undefined, { userContext });
|
|
116
|
-
(0, index_1.setRemoteContractTransportFactory)(undefined);
|
|
117
|
-
expect(() => (0, index_1.resolveRemoteTargetEndpoint)(makeRequest(), { userContext })).toThrow("no remote contract transport is registered");
|
|
118
|
-
});
|
|
119
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "../system";
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const system_ids_1 = require("../../system-ids");
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const contract_resolvers_1 = require("../contract-resolvers");
|
|
6
|
-
const registry_1 = require("../registry");
|
|
7
|
-
const host_shell_contract_1 = require("../system/host-shell-contract");
|
|
8
|
-
const identity_contract_1 = require("../system/identity-contract");
|
|
9
|
-
const packages_contract_1 = require("../system/packages-contract");
|
|
10
|
-
const system_contracts_1 = require("../system-contracts");
|
|
11
|
-
const tool_catalog_1 = require("../tool-catalog");
|
|
12
|
-
const tool_catalog_service_1 = require("../tool-catalog-service");
|
|
13
|
-
// Populate the catalog with built-in system contracts.
|
|
14
|
-
require("../system");
|
|
15
|
-
describe("system contract catalog", () => {
|
|
16
|
-
it("self-registers the built-in system contracts", () => {
|
|
17
|
-
const ids = (0, system_contracts_1.listSystemContracts)()
|
|
18
|
-
.map((entry) => entry.contractId)
|
|
19
|
-
.filter(Boolean);
|
|
20
|
-
expect(ids).toEqual(expect.arrayContaining([
|
|
21
|
-
system_ids_1.appUpdatesContractId,
|
|
22
|
-
system_ids_1.logsContractId,
|
|
23
|
-
system_ids_1.deviceOperationsContractId,
|
|
24
|
-
system_ids_1.identityContractId,
|
|
25
|
-
system_ids_1.hostToolsContractId,
|
|
26
|
-
system_ids_1.desktopToolsContractId,
|
|
27
|
-
system_ids_1.networkDiagnosticsContractId,
|
|
28
|
-
system_ids_1.networkControlContractId,
|
|
29
|
-
system_ids_1.toolAccessControlContractId,
|
|
30
|
-
system_ids_1.toolCatalogContractId,
|
|
31
|
-
system_ids_1.packagesContractId,
|
|
32
|
-
]));
|
|
33
|
-
});
|
|
34
|
-
it("registers the Logs live resolver", async () => {
|
|
35
|
-
await new Promise((resolve) => queueMicrotask(resolve));
|
|
36
|
-
expect((0, contract_resolvers_1.getContractResolver)(system_ids_1.logsContractId, 1)).toEqual(expect.any(Function));
|
|
37
|
-
});
|
|
38
|
-
it("installSystemContracts seeds a registry with system providers", () => {
|
|
39
|
-
const registry = new registry_1.ContractRegistry();
|
|
40
|
-
(0, system_contracts_1.installSystemContracts)(registry);
|
|
41
|
-
expect(registry.resolve(system_ids_1.logsContractId, 1)?.name).toBe("System Logs");
|
|
42
|
-
expect(registry.getProviderPackageId(system_ids_1.logsContractId, 1)).toBe(system_ids_1.peersSystemPackageId);
|
|
43
|
-
expect(registry.resolve(system_ids_1.deviceOperationsContractId, 1)?.name).toBe("System Device Operations");
|
|
44
|
-
expect(registry.getProviderPackageId(system_ids_1.deviceOperationsContractId, 1)).toBe(system_ids_1.peersSystemPackageId);
|
|
45
|
-
expect(registry.resolve(system_ids_1.identityContractId, 1)?.name).toBe("System Identity");
|
|
46
|
-
expect(registry.getProviderPackageId(system_ids_1.identityContractId, 1)).toBe(system_ids_1.peersSystemPackageId);
|
|
47
|
-
expect(registry.resolve(system_ids_1.networkDiagnosticsContractId, 1)?.name).toBe("System Network Diagnostics");
|
|
48
|
-
expect(registry.getProviderPackageId(system_ids_1.networkDiagnosticsContractId, 1)).toBe(system_ids_1.peersSystemPackageId);
|
|
49
|
-
expect(registry.resolve(system_ids_1.networkControlContractId, 1)?.name).toBe("System Network Control");
|
|
50
|
-
expect(registry.getProviderPackageId(system_ids_1.networkControlContractId, 1)).toBe(system_ids_1.peersSystemPackageId);
|
|
51
|
-
expect(registry.resolve(system_ids_1.toolAccessControlContractId, 1)?.name).toBe("System Tool Access Control");
|
|
52
|
-
expect(registry.getProviderPackageId(system_ids_1.toolAccessControlContractId, 1)).toBe(system_ids_1.peersSystemPackageId);
|
|
53
|
-
});
|
|
54
|
-
it("declares DevicePairingState as the identity ceremony result", async () => {
|
|
55
|
-
// Loaded lazily. A top-level import cycles through device tables before they finish initializing.
|
|
56
|
-
const { devicePairingStateSchema } = await Promise.resolve().then(() => require("../../device-pairing/types"));
|
|
57
|
-
const stateFields = Object.keys(devicePairingStateSchema.shape).sort();
|
|
58
|
-
const definition = (0, identity_contract_1.getIdentityContractDefinition)();
|
|
59
|
-
for (const name of ["startSource", "startDestination", "approve", "reject", "cancel"]) {
|
|
60
|
-
const tool = definition.tools.find((entry) => entry.name === name);
|
|
61
|
-
expect(tool?.outputFields.map((entry) => entry.name).sort()).toEqual(stateFields);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
it("registerSystemContract makes new contracts installable without loader changes", () => {
|
|
65
|
-
const fakeContractId = (0, utils_1.newid)();
|
|
66
|
-
const providerPackageId = (0, utils_1.newid)();
|
|
67
|
-
(0, system_contracts_1.registerSystemContract)({
|
|
68
|
-
providerPackageId,
|
|
69
|
-
contractId: fakeContractId,
|
|
70
|
-
version: 1,
|
|
71
|
-
getDefinition: () => ({
|
|
72
|
-
contractId: fakeContractId,
|
|
73
|
-
version: 1,
|
|
74
|
-
devTag: "dev",
|
|
75
|
-
name: "Fake System Contract",
|
|
76
|
-
description: "test",
|
|
77
|
-
tables: [],
|
|
78
|
-
tools: [],
|
|
79
|
-
observables: [],
|
|
80
|
-
events: [],
|
|
81
|
-
}),
|
|
82
|
-
});
|
|
83
|
-
const registry = new registry_1.ContractRegistry();
|
|
84
|
-
(0, system_contracts_1.installSystemContracts)(registry);
|
|
85
|
-
expect(registry.getProviderPackageId(fakeContractId, 1)).toBe(providerPackageId);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
test("system catalog initialization retries without publishing on failed persistence", async () => {
|
|
89
|
-
const rows = new Map();
|
|
90
|
-
let fail = true;
|
|
91
|
-
const context = {
|
|
92
|
-
tableContainer: {
|
|
93
|
-
getTable: () => ({
|
|
94
|
-
list: async () => [...rows.values()],
|
|
95
|
-
get: async (toolId) => rows.get(toolId),
|
|
96
|
-
save: async (row) => {
|
|
97
|
-
if (fail)
|
|
98
|
-
throw new Error("storage unavailable");
|
|
99
|
-
rows.set(row.toolId, row);
|
|
100
|
-
return row;
|
|
101
|
-
},
|
|
102
|
-
dataChanged: { subscribe: () => ({ unsubscribe: () => true }) },
|
|
103
|
-
}),
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
const registry = new registry_1.ContractRegistry();
|
|
107
|
-
const catalog = new tool_catalog_1.ToolCatalog(context, registry);
|
|
108
|
-
await expect((0, system_contracts_1.installSystemContracts)(registry)).rejects.toThrow("storage unavailable");
|
|
109
|
-
expect(registry.getProviderPackageId(system_ids_1.deviceOperationsContractId, 1)).toBeUndefined();
|
|
110
|
-
fail = false;
|
|
111
|
-
await (0, system_contracts_1.installSystemContracts)(registry);
|
|
112
|
-
expect(registry.getProviderPackageId(system_ids_1.deviceOperationsContractId, 1)).toBe(system_ids_1.peersSystemPackageId);
|
|
113
|
-
expect(registry.getProviderPackageId(system_ids_1.identityContractId, 1)).toBe(system_ids_1.peersSystemPackageId);
|
|
114
|
-
expect([...rows.values()].some((row) => row.contractId === system_ids_1.toolAccessControlContractId)).toBe(true);
|
|
115
|
-
await catalog.dispose();
|
|
116
|
-
});
|
|
117
|
-
test("a later system provider's persistence failure does not publish an earlier provider", async () => {
|
|
118
|
-
const contractId = (0, utils_1.newid)();
|
|
119
|
-
const providerPackageId = (0, utils_1.newid)();
|
|
120
|
-
(0, system_contracts_1.registerSystemContract)({
|
|
121
|
-
contractId,
|
|
122
|
-
version: 1,
|
|
123
|
-
providerPackageId,
|
|
124
|
-
getDefinition: () => ({
|
|
125
|
-
contractId,
|
|
126
|
-
version: 1,
|
|
127
|
-
name: "Later system provider",
|
|
128
|
-
description: "",
|
|
129
|
-
tables: [],
|
|
130
|
-
observables: [],
|
|
131
|
-
tools: [{ name: "read", usageDescription: "", inputFields: [], outputFields: [] }],
|
|
132
|
-
}),
|
|
133
|
-
});
|
|
134
|
-
const rows = new Map();
|
|
135
|
-
const registry = new registry_1.ContractRegistry();
|
|
136
|
-
const context = {
|
|
137
|
-
tableContainer: {
|
|
138
|
-
getTable: () => ({
|
|
139
|
-
list: async () => [...rows.values()],
|
|
140
|
-
save: async (row) => {
|
|
141
|
-
if (row.contractId === contractId)
|
|
142
|
-
throw new Error("late persistence failure");
|
|
143
|
-
rows.set(row.toolId, row);
|
|
144
|
-
return row;
|
|
145
|
-
},
|
|
146
|
-
}),
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
const catalog = new tool_catalog_1.ToolCatalog(context, registry);
|
|
150
|
-
try {
|
|
151
|
-
await expect(catalog.ready()).rejects.toThrow(/late persistence failure/);
|
|
152
|
-
expect(rows.size).toBeGreaterThan(0);
|
|
153
|
-
expect(registry.getProviderPackageId(system_ids_1.deviceOperationsContractId, 1)).toBeUndefined();
|
|
154
|
-
expect(registry.getProviderPackageId(contractId, 1)).toBeUndefined();
|
|
155
|
-
}
|
|
156
|
-
finally {
|
|
157
|
-
await catalog.dispose();
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
test("host and desktop workflow members are present with workflow-only policy", () => {
|
|
161
|
-
const registry = new registry_1.ContractRegistry();
|
|
162
|
-
(0, system_contracts_1.installSystemContracts)(registry);
|
|
163
|
-
for (const [id, names] of [
|
|
164
|
-
[system_ids_1.hostToolsContractId, ["default_assistant_runner", "tool-search"]],
|
|
165
|
-
[system_ids_1.desktopToolsContractId, ["cd", "send-notification"]],
|
|
166
|
-
]) {
|
|
167
|
-
const definition = registry.resolve(id, 1);
|
|
168
|
-
for (const name of names)
|
|
169
|
-
expect(definition?.tools.find((tool) => tool.name === name)?.requiresWorkflowRun).toBe(true);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
test("System Packages is remote only for Self and never workflow-invocable", () => {
|
|
173
|
-
const registry = new registry_1.ContractRegistry();
|
|
174
|
-
(0, system_contracts_1.installSystemContracts)(registry);
|
|
175
|
-
const definition = registry.resolve(system_ids_1.packagesContractId, 1);
|
|
176
|
-
expect(definition?.name).toBe("System Packages");
|
|
177
|
-
expect(registry.getProviderPackageId(system_ids_1.packagesContractId, 1)).toBe(system_ids_1.peersSystemPackageId);
|
|
178
|
-
expect((0, contract_resolvers_1.isLocalOnlyContractId)(system_ids_1.packagesContractId)).toBe(false);
|
|
179
|
-
for (const tool of definition?.tools ?? []) {
|
|
180
|
-
expect(tool.remoteAccessLevel).toBeUndefined();
|
|
181
|
-
expect((0, tool_catalog_service_1.isWorkflowInvocableTarget)({
|
|
182
|
-
contractId: system_ids_1.packagesContractId,
|
|
183
|
-
version: 1,
|
|
184
|
-
toolName: tool.name,
|
|
185
|
-
})).toBe(false);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
test("System Host Shell is remote only for Self and never workflow-invocable", () => {
|
|
189
|
-
const registry = new registry_1.ContractRegistry();
|
|
190
|
-
(0, system_contracts_1.installSystemContracts)(registry);
|
|
191
|
-
const definition = registry.resolve(system_ids_1.hostShellContractId, 1);
|
|
192
|
-
expect(definition?.name).toBe("System Host Shell");
|
|
193
|
-
expect(registry.getProviderPackageId(system_ids_1.hostShellContractId, 1)).toBe(system_ids_1.peersSystemPackageId);
|
|
194
|
-
expect((0, contract_resolvers_1.isLocalOnlyContractId)(system_ids_1.hostShellContractId)).toBe(false);
|
|
195
|
-
expect(definition?.tools.map((tool) => tool.name)).toContain("screenshot");
|
|
196
|
-
for (const tool of definition?.tools ?? []) {
|
|
197
|
-
expect(tool.remoteAccessLevel).toBeUndefined();
|
|
198
|
-
expect((0, tool_catalog_service_1.isWorkflowInvocableTarget)({
|
|
199
|
-
contractId: system_ids_1.hostShellContractId,
|
|
200
|
-
version: 1,
|
|
201
|
-
toolName: tool.name,
|
|
202
|
-
})).toBe(false);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
it.each([
|
|
206
|
-
["https://peers.app/docs", { kind: "browser", url: "https://peers.app/docs" }],
|
|
207
|
-
[" http://localhost:3000 ", { kind: "browser", url: "http://localhost:3000" }],
|
|
208
|
-
["mailto:someone@example.com", { kind: "browser", url: "mailto:someone@example.com" }],
|
|
209
|
-
["~/peers/packages", { kind: "path", path: "~/peers/packages" }],
|
|
210
|
-
["/tmp/a b", { kind: "path", path: "/tmp/a b" }],
|
|
211
|
-
["C:\\Users\\me", { kind: "path", path: "C:\\Users\\me" }],
|
|
212
|
-
["relative/dir", { kind: "path", path: "relative/dir" }],
|
|
213
|
-
])("open routes %p", (target, expected) => {
|
|
214
|
-
expect((0, host_shell_contract_1.classifyHostOpenTarget)(target)).toEqual(expected);
|
|
215
|
-
});
|
|
216
|
-
it.each([
|
|
217
|
-
"file:///etc/passwd",
|
|
218
|
-
"javascript:alert(1)",
|
|
219
|
-
"vscode://file/x",
|
|
220
|
-
"smb://host/share",
|
|
221
|
-
"",
|
|
222
|
-
])("open refuses %p", (target) => {
|
|
223
|
-
expect(() => (0, host_shell_contract_1.classifyHostOpenTarget)(target)).toThrow(/open (refuses|requires)/);
|
|
224
|
-
});
|
|
225
|
-
it.each([
|
|
226
|
-
[undefined, ["beta", "stable"]],
|
|
227
|
-
["", ["beta", "stable"]],
|
|
228
|
-
["dev", ["beta", "stable"]],
|
|
229
|
-
["beta", ["stable"]],
|
|
230
|
-
["stable", []],
|
|
231
|
-
["nightly", []],
|
|
232
|
-
])("promotion targets for %p are %p", (tag, targets) => {
|
|
233
|
-
expect((0, packages_contract_1.packageVersionPromotionTargets)(tag)).toEqual(targets);
|
|
234
|
-
});
|
|
235
|
-
it.each([
|
|
236
|
-
["https://github.com/peers-app/x.git", true],
|
|
237
|
-
["http://host/x", true],
|
|
238
|
-
["git@github.com:peers-app/x", true],
|
|
239
|
-
[" git@github.com:peers-app/x.git", true],
|
|
240
|
-
["git@notes", false],
|
|
241
|
-
["../x.git", false],
|
|
242
|
-
["/abs/x.git", false],
|
|
243
|
-
["My Package", false],
|
|
244
|
-
["00mvdhk66tdqrj3hy0bacmj32", false],
|
|
245
|
-
])("routes %p to clonePackage: %p", (target, expected) => {
|
|
246
|
-
expect((0, packages_contract_1.isPackageRepositoryUrl)(target)).toBe(expected);
|
|
247
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { IToolInstance } from "../../data/tools";
|
|
2
|
-
import { type ContractToolDispatch } from "../contract-proxy";
|
|
3
|
-
/**
|
|
4
|
-
* The host's `dispatchTool`, for tests: runs `tools` as the provider of `contractId` v1 with the
|
|
5
|
-
* frame the calling tool's provider bound, so each target is admitted as the host would admit
|
|
6
|
-
* it. Targets can dispatch further through the same bridge.
|
|
7
|
-
*
|
|
8
|
-
* @param contractId - The contract the targets are provided under.
|
|
9
|
-
* @param tools - The target tools, by name.
|
|
10
|
-
*/
|
|
11
|
-
export declare function targetDispatch(contractId: string, tools: Record<string, IToolInstance>): ContractToolDispatch;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.targetDispatch = targetDispatch;
|
|
4
|
-
const contract_proxy_1 = require("../contract-proxy");
|
|
5
|
-
/**
|
|
6
|
-
* The host's `dispatchTool`, for tests: runs `tools` as the provider of `contractId` v1 with the
|
|
7
|
-
* frame the calling tool's provider bound, so each target is admitted as the host would admit
|
|
8
|
-
* it. Targets can dispatch further through the same bridge.
|
|
9
|
-
*
|
|
10
|
-
* @param contractId - The contract the targets are provided under.
|
|
11
|
-
* @param tools - The target tools, by name.
|
|
12
|
-
*/
|
|
13
|
-
function targetDispatch(contractId, tools) {
|
|
14
|
-
const dispatch = (target, args, context) => provider({
|
|
15
|
-
contractId: target.contractId,
|
|
16
|
-
version: target.version,
|
|
17
|
-
member: "tool",
|
|
18
|
-
name: target.toolName,
|
|
19
|
-
operation: "run",
|
|
20
|
-
args: [args],
|
|
21
|
-
}, context);
|
|
22
|
-
const provider = (0, contract_proxy_1.createContractProvider)({ contractId, version: 1, tools, forwardCallContext: true }, { dispatchTool: dispatch });
|
|
23
|
-
return dispatch;
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "../../index";
|