@coasys/ad4m 0.12.1-dev → 0.13.0-postmessage-ws-proxy.3
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/README.md +2 -25
- package/jest-setup.ts +1 -1
- package/lib/index.cjs +8677 -15318
- package/lib/index.js +14507 -21223
- package/lib/src/Ad4mClient.d.ts +9 -3
- package/lib/src/Ad4mClient.js +40 -13
- package/lib/src/Literal.js +6 -5
- package/lib/src/agent/Agent.js +26 -272
- package/lib/src/agent/AgentClient.d.ts +33 -21
- package/lib/src/agent/AgentClient.js +180 -374
- package/lib/src/agent/AgentStatus.js +2 -37
- package/lib/src/ai/AIClient.d.ts +12 -4
- package/lib/src/ai/AIClient.js +81 -285
- package/lib/src/ai/AITypes.d.ts +55 -0
- package/lib/src/ai/AITypes.js +18 -0
- package/lib/src/ai/Tasks.js +10 -133
- package/lib/src/apiClient.d.ts +53 -0
- package/lib/src/apiClient.js +234 -0
- package/lib/src/cache/PersistentCache.d.ts +40 -0
- package/lib/src/cache/PersistentCache.js +139 -0
- package/lib/src/expression/Expression.d.ts +1 -1
- package/lib/src/expression/Expression.js +13 -122
- package/lib/src/expression/ExpressionClient.d.ts +11 -3
- package/lib/src/expression/ExpressionClient.js +120 -75
- package/lib/src/expression/ExpressionRef.js +4 -27
- package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
- package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
- package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkRequest.js +1 -0
- package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
- package/lib/src/generated/api/AddSdnaRequest.js +2 -0
- package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
- package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
- package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
- package/lib/src/generated/api/AuthInfoInput.js +1 -0
- package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
- package/lib/src/generated/api/CapabilityInput.js +1 -0
- package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
- package/lib/src/generated/api/CommitBatchRequest.js +2 -0
- package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
- package/lib/src/generated/api/ComputeLogEntry.js +2 -0
- package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
- package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
- package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
- package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
- package/lib/src/generated/api/EmbedRequest.js +2 -0
- package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
- package/lib/src/generated/api/EntanglementProofInput.js +2 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
- package/lib/src/generated/api/ExportRequest.d.ts +5 -0
- package/lib/src/generated/api/ExportRequest.js +2 -0
- package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
- package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
- package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
- package/lib/src/generated/api/ExpressionProof.js +2 -0
- package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
- package/lib/src/generated/api/ExpressionProofInput.js +2 -0
- package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
- package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendsListRequest.js +2 -0
- package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
- package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
- package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
- package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
- package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
- package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
- package/lib/src/generated/api/ImportAgentRequest.js +2 -0
- package/lib/src/generated/api/ImportRequest.d.ts +4 -0
- package/lib/src/generated/api/ImportRequest.js +2 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
- package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
- package/lib/src/generated/api/LanguageMetaInput.js +2 -0
- package/lib/src/generated/api/Link.d.ts +5 -0
- package/lib/src/generated/api/Link.js +2 -0
- package/lib/src/generated/api/LinkExpression.d.ts +10 -0
- package/lib/src/generated/api/LinkExpression.js +1 -0
- package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
- package/lib/src/generated/api/LinkExpressionInput.js +1 -0
- package/lib/src/generated/api/LinkInput.d.ts +5 -0
- package/lib/src/generated/api/LinkInput.js +2 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
- package/lib/src/generated/api/LinkMutations.d.ts +6 -0
- package/lib/src/generated/api/LinkMutations.js +1 -0
- package/lib/src/generated/api/LinkStatus.d.ts +1 -0
- package/lib/src/generated/api/LinkStatus.js +2 -0
- package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/LockAgentRequest.js +2 -0
- package/lib/src/generated/api/ModelType.d.ts +1 -0
- package/lib/src/generated/api/ModelType.js +2 -0
- package/lib/src/generated/api/NotificationInput.d.ts +10 -0
- package/lib/src/generated/api/NotificationInput.js +2 -0
- package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
- package/lib/src/generated/api/OpenLinkRequest.js +2 -0
- package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
- package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
- package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
- package/lib/src/generated/api/PerspectiveInput.js +1 -0
- package/lib/src/generated/api/PromptRequest.d.ts +4 -0
- package/lib/src/generated/api/PromptRequest.js +2 -0
- package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
- package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
- package/lib/src/generated/api/QueryRequest.d.ts +7 -0
- package/lib/src/generated/api/QueryRequest.js +2 -0
- package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/ResourceInput.d.ts +4 -0
- package/lib/src/generated/api/ResourceInput.js +2 -0
- package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
- package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
- package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
- package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
- package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
- package/lib/src/generated/api/SetStatusRequest.js +2 -0
- package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/SignMessageRequest.js +2 -0
- package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
- package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
- package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
- package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
- package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
- package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/UserStatistics.d.ts +9 -0
- package/lib/src/generated/api/UserStatistics.js +2 -0
- package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
- package/lib/src/generated/api/VerificationRequestResult.js +2 -0
- package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
- package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
- package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
- package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
- package/lib/src/generated/api/index.d.ts +42 -0
- package/lib/src/generated/api/index.js +7 -0
- package/lib/src/index.d.ts +8 -2
- package/lib/src/index.js +8 -2
- package/lib/src/jestSetup.d.ts +0 -1
- package/lib/src/jestSetup.js +1 -1
- package/lib/src/language/Icon.js +2 -21
- package/lib/src/language/Language.d.ts +26 -176
- package/lib/src/language/Language.js +32 -72
- package/lib/src/language/LanguageClient.d.ts +2 -2
- package/lib/src/language/LanguageClient.js +15 -105
- package/lib/src/language/LanguageHandle.js +2 -41
- package/lib/src/language/LanguageMeta.js +4 -75
- package/lib/src/language/LanguageRef.js +2 -25
- package/lib/src/links/Links.js +14 -111
- package/lib/src/model/Ad4mModel.d.ts +143 -63
- package/lib/src/model/Ad4mModel.js +583 -425
- package/lib/src/model/Ad4mModel.test.js +1434 -688
- package/lib/src/model/ModelQueryBuilder.d.ts +61 -45
- package/lib/src/model/ModelQueryBuilder.js +315 -157
- package/lib/src/model/Subject.js +6 -6
- package/lib/src/model/decorators.d.ts +36 -8
- package/lib/src/model/decorators.js +41 -14
- package/lib/src/model/hydration-batch.d.ts +34 -0
- package/lib/src/model/hydration-batch.js +147 -0
- package/lib/src/model/hydration-batching.test.d.ts +7 -0
- package/lib/src/model/hydration-batching.test.js +456 -0
- package/lib/src/model/hydration.d.ts +3 -92
- package/lib/src/model/hydration.js +3 -691
- package/lib/src/model/index.d.ts +3 -4
- package/lib/src/model/index.js +3 -4
- package/lib/src/model/json-schema.js +2 -2
- package/lib/src/model/model-manifest.d.ts +41 -0
- package/lib/src/model/model-manifest.js +11 -0
- package/lib/src/model/query-cache.d.ts +30 -0
- package/lib/src/model/query-cache.js +66 -0
- package/lib/src/model/query-cache.test.d.ts +1 -0
- package/lib/src/model/query-cache.test.js +43 -0
- package/lib/src/model/query-common.d.ts +1 -1
- package/lib/src/model/query-common.js +1 -1
- package/lib/src/model/query-sparql-batch.d.ts +17 -0
- package/lib/src/model/query-sparql-batch.js +260 -0
- package/lib/src/model/query-sparql.d.ts +51 -0
- package/lib/src/model/query-sparql.js +466 -0
- package/lib/src/model/query-sparql.test.d.ts +1 -0
- package/lib/src/model/query-sparql.test.js +312 -0
- package/lib/src/model/{surreal-utils.d.ts → query-utils.d.ts} +13 -9
- package/lib/src/model/query-utils.js +189 -0
- package/lib/src/model/relation-filtering.test.js +15 -15
- package/lib/src/model/sdna.js +1 -1
- package/lib/src/model/shacl-gen.js +154 -57
- package/lib/src/model/subscription-delta.test.d.ts +24 -0
- package/lib/src/model/subscription-delta.test.js +180 -0
- package/lib/src/model/subscription-pool.d.ts +39 -0
- package/lib/src/model/subscription-pool.js +165 -0
- package/lib/src/model/types.d.ts +195 -5
- package/lib/src/model/types.js +5 -2
- package/lib/src/neighbourhood/Neighbourhood.js +4 -32
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
- package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
- package/lib/src/perspectives/LinkQuery.js +2 -42
- package/lib/src/perspectives/Perspective.d.ts +1 -1
- package/lib/src/perspectives/Perspective.js +10 -52
- package/lib/src/perspectives/PerspectiveClient.d.ts +22 -32
- package/lib/src/perspectives/PerspectiveClient.js +188 -454
- package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
- package/lib/src/perspectives/PerspectiveDiff.js +4 -31
- package/lib/src/perspectives/PerspectiveHandle.js +3 -43
- package/lib/src/perspectives/PerspectiveProxy.d.ts +157 -78
- package/lib/src/perspectives/PerspectiveProxy.js +475 -389
- package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
- package/lib/src/perspectives/PerspectiveResolver.js +0 -11
- package/lib/src/perspectives/SparqlBindings.d.ts +47 -0
- package/lib/src/perspectives/SparqlBindings.js +65 -0
- package/lib/src/perspectives/WakerSubscriptionManager.d.ts +3 -3
- package/lib/src/perspectives/WakerSubscriptionManager.js +12 -12
- package/lib/src/runtime/RuntimeClient.d.ts +8 -6
- package/lib/src/runtime/RuntimeClient.js +97 -454
- package/lib/src/runtime/RuntimeResolver.d.ts +14 -0
- package/lib/src/runtime/RuntimeResolver.js +84 -0
- package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
- package/lib/src/runtime/RuntimeTypes.js +45 -0
- package/lib/src/schema.gql +14 -1
- package/lib/src/shacl/SHACLFlow.d.ts +1 -1
- package/lib/src/shacl/SHACLFlow.js +9 -9
- package/lib/src/shacl/SHACLShape.d.ts +26 -1
- package/lib/src/shacl/SHACLShape.js +140 -38
- package/lib/src/shacl/SHACLShape.test.js +82 -0
- package/lib/src/typeDefs.js +3 -615
- package/lib/src/utils.d.ts +6 -6
- package/lib/src/utils.js +6 -6
- package/package.json +9 -24
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1192 -1288
- package/src/Ad4mClient.ts +46 -15
- package/src/Literal.test.ts +10 -5
- package/src/Literal.ts +6 -5
- package/src/agent/Agent.ts +0 -99
- package/src/agent/AgentClient.ts +238 -467
- package/src/agent/AgentStatus.ts +0 -12
- package/src/ai/AIClient.ts +96 -296
- package/src/ai/AITypes.ts +66 -0
- package/src/ai/Tasks.ts +0 -52
- package/src/apiClient.ts +287 -0
- package/src/cache/PersistentCache.ts +145 -0
- package/src/cache/cache.test.ts +713 -0
- package/src/expression/Expression.ts +3 -43
- package/src/expression/ExpressionClient.ts +148 -77
- package/src/expression/ExpressionRef.ts +2 -8
- package/src/generated/api/AIModelLoadingStatus.ts +3 -0
- package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
- package/src/generated/api/AddLinkRequest.ts +4 -0
- package/src/generated/api/AddLinksBulkRequest.ts +4 -0
- package/src/generated/api/AddSdnaRequest.ts +3 -0
- package/src/generated/api/ApplyTemplateRequest.ts +3 -0
- package/src/generated/api/AuthInfoInput.ts +4 -0
- package/src/generated/api/CapabilityInput.ts +4 -0
- package/src/generated/api/CommitBatchRequest.ts +3 -0
- package/src/generated/api/ComputeLogEntry.ts +3 -0
- package/src/generated/api/CreateExpressionRequest.ts +3 -0
- package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
- package/src/generated/api/CreateSubjectRequest.ts +3 -0
- package/src/generated/api/EmbedRequest.ts +3 -0
- package/src/generated/api/EntanglementProofInput.ts +3 -0
- package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
- package/src/generated/api/ExportRequest.ts +3 -0
- package/src/generated/api/ExpressionManyRequest.ts +3 -0
- package/src/generated/api/ExpressionProof.ts +3 -0
- package/src/generated/api/ExpressionProofInput.ts +3 -0
- package/src/generated/api/FriendSendMessageRequest.ts +3 -0
- package/src/generated/api/FriendsListRequest.ts +3 -0
- package/src/generated/api/GenerateAgentRequest.ts +3 -0
- package/src/generated/api/GenerateJwtRequest.ts +3 -0
- package/src/generated/api/GetSubjectDataRequest.ts +3 -0
- package/src/generated/api/ImportAgentRequest.ts +3 -0
- package/src/generated/api/ImportRequest.ts +3 -0
- package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
- package/src/generated/api/LanguageMetaInput.ts +3 -0
- package/src/generated/api/Link.ts +3 -0
- package/src/generated/api/LinkExpression.ts +6 -0
- package/src/generated/api/LinkExpressionInput.ts +6 -0
- package/src/generated/api/LinkInput.ts +3 -0
- package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
- package/src/generated/api/LinkMutations.ts +5 -0
- package/src/generated/api/LinkStatus.ts +3 -0
- package/src/generated/api/LockAgentRequest.ts +3 -0
- package/src/generated/api/ModelType.ts +3 -0
- package/src/generated/api/NotificationInput.ts +3 -0
- package/src/generated/api/OpenLinkRequest.ts +3 -0
- package/src/generated/api/PermitCapabilityRequest.ts +3 -0
- package/src/generated/api/PerspectiveInput.ts +4 -0
- package/src/generated/api/PromptRequest.ts +3 -0
- package/src/generated/api/PublishLanguageRequest.ts +4 -0
- package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
- package/src/generated/api/QueryRequest.ts +6 -0
- package/src/generated/api/RemoveLinkRequest.ts +4 -0
- package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
- package/src/generated/api/ResourceInput.ts +3 -0
- package/src/generated/api/SetDefaultModelRequest.ts +4 -0
- package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
- package/src/generated/api/SetMultiUserRequest.ts +3 -0
- package/src/generated/api/SetStatusRequest.ts +3 -0
- package/src/generated/api/SignMessageRequest.ts +3 -0
- package/src/generated/api/TrustedAgentsRequest.ts +3 -0
- package/src/generated/api/UnlockAgentRequest.ts +3 -0
- package/src/generated/api/UpdateLinkRequest.ts +5 -0
- package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
- package/src/generated/api/UserStatistics.ts +3 -0
- package/src/generated/api/VerificationRequestResult.ts +3 -0
- package/src/generated/api/VerifySignatureRequest.ts +3 -0
- package/src/generated/api/WriteSettingsRequest.ts +3 -0
- package/src/generated/api/index.ts +49 -0
- package/src/index.ts +8 -2
- package/src/jestSetup.ts +1 -1
- package/src/language/Icon.ts +0 -4
- package/src/language/Language.ts +51 -248
- package/src/language/LanguageClient.ts +21 -132
- package/src/language/LanguageHandle.ts +0 -14
- package/src/language/LanguageMeta.ts +0 -29
- package/src/language/LanguageRef.ts +0 -7
- package/src/links/Links.ts +0 -37
- package/src/model/Ad4mModel.test.ts +1664 -792
- package/src/model/Ad4mModel.ts +664 -499
- package/src/model/ModelQueryBuilder.ts +362 -183
- package/src/model/decorators.ts +71 -22
- package/src/model/hydration.ts +3 -772
- package/src/model/index.ts +3 -4
- package/src/model/json-schema.ts +2 -2
- package/src/model/query-cache.test.ts +54 -0
- package/src/model/query-cache.ts +79 -0
- package/src/model/query-common.ts +1 -1
- package/src/model/query-sparql.test.ts +376 -0
- package/src/model/query-sparql.ts +504 -0
- package/src/model/query-utils.ts +209 -0
- package/src/model/relation-filtering.test.ts +60 -53
- package/src/model/sdna.ts +1 -1
- package/src/model/shacl-gen.ts +163 -64
- package/src/model/shacl-roundtrip.test.ts +197 -0
- package/src/model/types-typed-query.test.ts +360 -0
- package/src/model/types.ts +256 -5
- package/src/neighbourhood/Neighbourhood.ts +0 -9
- package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
- package/src/perspectives/LinkQuery.ts +0 -15
- package/src/perspectives/Perspective.ts +1 -12
- package/src/perspectives/PerspectiveClient.test.ts +262 -0
- package/src/perspectives/PerspectiveClient.ts +252 -468
- package/src/perspectives/PerspectiveDiff.ts +0 -8
- package/src/perspectives/PerspectiveHandle.ts +1 -12
- package/src/perspectives/PerspectiveProxy.test.ts +125 -0
- package/src/perspectives/PerspectiveProxy.ts +522 -434
- package/src/perspectives/SparqlBindings.ts +79 -0
- package/src/perspectives/WakerSubscriptionManager.ts +13 -13
- package/src/runtime/RuntimeClient.ts +118 -461
- package/src/runtime/RuntimeTypes.ts +144 -0
- package/src/shacl/SHACLFlow.ts +9 -9
- package/src/shacl/SHACLShape.test.ts +204 -0
- package/src/shacl/SHACLShape.ts +191 -39
- package/src/typeDefs.ts +3 -5
- package/src/utils.ts +6 -6
- package/tsconfig.json +3 -7
- package/lib/src/model/query-surreal.d.ts +0 -44
- package/lib/src/model/query-surreal.js +0 -249
- package/lib/src/model/surreal-utils.js +0 -128
- package/shims/reflect-metadata.ts +0 -0
- package/shims/type-graphql.ts +0 -75
- package/src/PubSub.ts +0 -17
- package/src/agent/AgentResolver.ts +0 -263
- package/src/ai/AIResolver.ts +0 -372
- package/src/buildSchema.ts +0 -43
- package/src/expression/ExpressionResolver.ts +0 -64
- package/src/language/LanguageContext.ts +0 -37
- package/src/language/LanguageResolver.ts +0 -98
- package/src/model/Subject.ts +0 -159
- package/src/model/prolog-facts.ts +0 -145
- package/src/model/query-prolog.ts +0 -148
- package/src/model/query-surreal.ts +0 -280
- package/src/model/surreal-utils.ts +0 -147
- package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
- package/src/perspectives/PerspectiveResolver.ts +0 -372
- package/src/runtime/RuntimeResolver.ts +0 -691
- package/src/unwrapApolloResult.ts +0 -16
- package/tsconfig-browser.json +0 -82
package/src/Ad4mClient.test.ts
CHANGED
|
@@ -1,1344 +1,1248 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
1
|
+
import { Ad4mClient } from './Ad4mClient';
|
|
2
|
+
import { Perspective } from './perspectives/Perspective';
|
|
3
|
+
import { LinkQuery } from './perspectives/LinkQuery';
|
|
4
|
+
|
|
5
|
+
// Save original WebSocket so we can restore it after the suite
|
|
6
|
+
const originalWebSocket = (global as any).WebSocket;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Test architecture:
|
|
10
|
+
*
|
|
11
|
+
* The AD4M server exposes NO REST endpoints for authenticated operations.
|
|
12
|
+
* Everything goes through WebSocket RPC at /api/v1/ws.
|
|
13
|
+
*
|
|
14
|
+
* MockWebSocket intercepts all WS RPC messages and resolves them directly
|
|
15
|
+
* from a response map — no HTTP server, no Express, no REST translation.
|
|
16
|
+
*
|
|
17
|
+
* Server-side unauthenticated WS RPC types (empty token allowed):
|
|
18
|
+
* user.create, user.login, user.verifyEmail, user.requestVerification,
|
|
19
|
+
* user.multiUserEnabled, runtime.info, runtime.tlsDomain
|
|
20
|
+
*
|
|
21
|
+
* The only real HTTP endpoints on the server are:
|
|
22
|
+
* GET / — server info
|
|
23
|
+
* GET /health — health check
|
|
24
|
+
* POST /api/v1/ai/transcription/feed — binary PCM audio (not JSON)
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
// ===================== WS RPC MOCK RESPONSES =====================
|
|
28
|
+
// Each key is a WS RPC message type. The value is either a static response
|
|
29
|
+
// or a function (params) => response for dynamic behaviour.
|
|
30
|
+
|
|
31
|
+
type RpcHandler = unknown | ((params: Record<string, unknown>) => unknown);
|
|
32
|
+
|
|
33
|
+
const MOCK_RESPONSES: Record<string, RpcHandler> = {
|
|
34
|
+
// ── Agent ──
|
|
35
|
+
'agent.get': { did: 'did:test:123', perspective: new Perspective(), directMessageLanguage: 'lang://dm' },
|
|
36
|
+
'agent.status': { did: 'did:test:123', didDocument: 'doc', isInitialized: true, isUnlocked: true },
|
|
37
|
+
'agent.generate': { did: 'did:test:generated', didDocument: 'doc', isInitialized: true, isUnlocked: true },
|
|
38
|
+
'agent.lock': { did: 'did:test:123', isInitialized: true, isUnlocked: false },
|
|
39
|
+
'agent.unlock': { did: 'did:test:123', isInitialized: true, isUnlocked: true },
|
|
40
|
+
'agent.import': { did: 'did:test:imported', isInitialized: true, isUnlocked: true },
|
|
41
|
+
'agent.byDid': (p: Record<string, unknown>) => ({ did: p.did, perspective: new Perspective() }),
|
|
42
|
+
'agent.updateProfile': { did: 'did:test:123', perspective: new Perspective(), directMessageLanguage: 'lang://dm' },
|
|
43
|
+
'agent.sign': 'signed-message-data',
|
|
44
|
+
'agent.isLocked': false,
|
|
45
|
+
'agent.requestCapability': 'request-id-123',
|
|
46
|
+
'agent.permitCapability': 'permitted-token',
|
|
47
|
+
'agent.generateJwt': 'jwt-token-abc',
|
|
48
|
+
'agent.getApps': [{ requestId: 'app1', auth: {}, token: 'tok', revoked: false }],
|
|
49
|
+
'agent.removeApp': [],
|
|
50
|
+
'agent.revokeToken': [],
|
|
51
|
+
'agent.getTrustedAgents': ['did:trusted:1'],
|
|
52
|
+
'agent.addTrustedAgents': ['did:trusted:1', 'did:trusted:2'],
|
|
53
|
+
'agent.deleteTrustedAgents': ['did:trusted:1'],
|
|
54
|
+
'agent.getEntanglementProofs': ['proof1', 'proof2'],
|
|
55
|
+
'agent.addEntanglementProofs': [{ did: 'did:test:123', deviceKey: 'key1', deviceKeyType: 'type1' }],
|
|
56
|
+
'agent.deleteEntanglementProofs': [],
|
|
57
|
+
'agent.entanglementProofPreflight': { did: 'did:test:123', deviceKey: 'key1', deviceKeyType: 'type1' },
|
|
58
|
+
|
|
59
|
+
// ── Perspectives ──
|
|
60
|
+
'perspective.all': [{ uuid: 'uuid-1', name: 'test-perspective', sharedUrl: null, neighbourhood: null, state: 'Synced' }],
|
|
61
|
+
'perspective.get': (p: Record<string, unknown>) => ({
|
|
62
|
+
uuid: p.uuid, name: 'test-perspective', sharedUrl: null, neighbourhood: null, state: 'Synced',
|
|
63
|
+
}),
|
|
64
|
+
'perspective.create': (p: Record<string, unknown>) => ({
|
|
65
|
+
uuid: 'uuid-new', name: p.name, sharedUrl: null, neighbourhood: null, state: 'Synced',
|
|
66
|
+
}),
|
|
67
|
+
'perspective.update': (p: Record<string, unknown>) => ({
|
|
68
|
+
uuid: p.uuid, name: p.name, sharedUrl: null, neighbourhood: null, state: 'Synced',
|
|
69
|
+
}),
|
|
70
|
+
'perspective.remove': true,
|
|
71
|
+
'perspective.snapshot': {
|
|
72
|
+
links: [{ author: 'did:test:123', timestamp: '2024-01-01', data: { source: 's', predicate: 'p', target: 't' }, proof: { valid: true } }],
|
|
73
|
+
},
|
|
74
|
+
'perspective.publishSnapshot': 'Qm123',
|
|
75
|
+
'perspective.queryLinks': [
|
|
76
|
+
{ author: 'did:test:123', timestamp: '2024-01-01', data: { source: 's', predicate: 'p', target: 't' }, proof: { valid: true } },
|
|
77
|
+
],
|
|
78
|
+
'perspective.addLink': {
|
|
79
|
+
author: 'did:test:123', timestamp: '2024-01-01',
|
|
80
|
+
data: { source: 's', predicate: 'p', target: 't' }, proof: { valid: true },
|
|
81
|
+
},
|
|
82
|
+
'perspective.addLinkExpression': {
|
|
83
|
+
author: 'did:test:123', timestamp: '2024-01-01',
|
|
84
|
+
data: { source: 's', predicate: 'p', target: 't' }, proof: { valid: true },
|
|
85
|
+
},
|
|
86
|
+
'perspective.addLinks': [
|
|
87
|
+
{ author: 'did:test:123', timestamp: '2024-01-01', data: { source: 's', predicate: 'p', target: 't' }, proof: { valid: true } },
|
|
88
|
+
],
|
|
89
|
+
'perspective.removeLinks': [],
|
|
90
|
+
'perspective.linkMutations': {
|
|
91
|
+
additions: [{ author: 'did:test:123', timestamp: '2024-01-01', data: { source: 'a', predicate: 'p', target: 't' }, proof: { valid: true } }],
|
|
92
|
+
removals: [],
|
|
93
|
+
},
|
|
94
|
+
'perspective.updateLink': {
|
|
95
|
+
author: 'did:test:123', timestamp: '2024-01-01',
|
|
96
|
+
data: { source: 'new-s', predicate: 'p', target: 't' }, proof: { valid: true },
|
|
97
|
+
},
|
|
98
|
+
'perspective.removeLink': true,
|
|
99
|
+
'perspective.queryProlog': JSON.stringify([{ X: 'test' }]),
|
|
100
|
+
'perspective.querySparql': JSON.stringify([{ id: '1' }]),
|
|
101
|
+
'perspective.addSdna': true,
|
|
102
|
+
'perspective.executeCommands': true,
|
|
103
|
+
'perspective.createSubject': true,
|
|
104
|
+
'perspective.getSubjectData': '{"name":"test"}',
|
|
105
|
+
'perspective.createBatch': 'batch-id-1',
|
|
106
|
+
'perspective.commitBatch': { additions: [], removals: [] },
|
|
107
|
+
'perspective.subscribeQuery': true,
|
|
108
|
+
'perspective.keepAliveQuery': true,
|
|
109
|
+
'perspective.disposeQuery': true,
|
|
110
|
+
|
|
111
|
+
// ── Languages ──
|
|
112
|
+
'language.all': [{ name: 'test-lang', address: 'lang://test', settings: '{}', icon: null, constructorIcon: null }],
|
|
113
|
+
'language.get': (p: Record<string, unknown>) => ({
|
|
114
|
+
name: 'test-lang', address: p.address, settings: '{}', icon: null, constructorIcon: null,
|
|
115
|
+
}),
|
|
116
|
+
'language.meta': {
|
|
117
|
+
name: 'test-lang', address: 'lang://test', description: 'A test language',
|
|
118
|
+
author: 'did:test:123', templated: false, templateSourceLanguageAddress: null,
|
|
119
|
+
templateAppliedParams: null, possibleTemplateParams: null, sourceCodeLink: null,
|
|
120
|
+
},
|
|
121
|
+
'language.source': 'source-code-here',
|
|
122
|
+
'language.writeSettings': true,
|
|
123
|
+
'language.applyTemplate': { name: 'applied-lang', address: 'lang://applied' },
|
|
124
|
+
'language.publish': {
|
|
125
|
+
name: 'published-lang', address: 'lang://published', description: 'Published',
|
|
126
|
+
author: 'did:test:123', templated: false,
|
|
127
|
+
},
|
|
128
|
+
'language.remove': true,
|
|
129
|
+
|
|
130
|
+
// ── Neighbourhoods ──
|
|
131
|
+
'neighbourhood.publish': 'neighbourhood://published',
|
|
132
|
+
'neighbourhood.join': {
|
|
133
|
+
uuid: 'uuid-joined', name: 'joined-neighbourhood', sharedUrl: 'neighbourhood://url',
|
|
134
|
+
neighbourhood: {}, state: 'Synced',
|
|
135
|
+
},
|
|
136
|
+
'neighbourhood.otherAgents': ['did:other:1', 'did:other:2'],
|
|
137
|
+
'neighbourhood.hasTelepresence': true,
|
|
138
|
+
'neighbourhood.onlineAgents': [{ did: 'did:test:1', status: new Perspective() }],
|
|
139
|
+
'neighbourhood.setOnlineStatus': true,
|
|
140
|
+
'neighbourhood.sendSignal': true,
|
|
141
|
+
'neighbourhood.sendBroadcast': true,
|
|
142
|
+
|
|
143
|
+
// ── Expressions ──
|
|
144
|
+
'expression.get': (p: Record<string, unknown>) => {
|
|
145
|
+
if (p.raw === true) return 'raw-expression-data';
|
|
146
|
+
return {
|
|
147
|
+
author: 'did:test:123', timestamp: '2024-01-01', data: '{"content":"hello"}',
|
|
148
|
+
language: { address: 'lang://test' }, proof: { valid: true },
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
'expression.getMany': (p: Record<string, unknown>) => {
|
|
152
|
+
// Return one result per URL (aligned by index), matching real API behavior
|
|
153
|
+
const urls = (p.urls || []) as string[];
|
|
154
|
+
return urls.map((url: string) => ({
|
|
155
|
+
author: 'did:test:1', timestamp: '2023-01-01', data: { type: 'test' },
|
|
156
|
+
language: { address: 'lang://test' }, proof: { valid: true },
|
|
157
|
+
}));
|
|
158
|
+
},
|
|
159
|
+
'expression.create': 'Qm-expression-hash',
|
|
160
|
+
'expression.interactions': [{ label: 'interact1', name: 'doSomething', parameters: [] }],
|
|
161
|
+
'expression.interact': 'interaction-result',
|
|
162
|
+
|
|
163
|
+
// ── Runtime ──
|
|
164
|
+
'runtime.info': { ad4mExecutorVersion: '0.1.0', isUnlocked: true, isInitialized: true },
|
|
165
|
+
'runtime.tlsDomain': 'test.domain.com',
|
|
166
|
+
'runtime.quit': true,
|
|
167
|
+
'runtime.openLink': true,
|
|
168
|
+
'runtime.friends': ['did:friend:1', 'did:friend:2'],
|
|
169
|
+
'runtime.addFriends': ['did:friend:1', 'did:friend:2', 'did:friend:3'],
|
|
170
|
+
'runtime.removeFriends': ['did:friend:1'],
|
|
171
|
+
'runtime.friendStatus': (p: Record<string, unknown>) => ({
|
|
172
|
+
author: p.did, timestamp: '2023-01-01', data: JSON.stringify({ recipe_name: 'test' }), proof: { valid: true },
|
|
173
|
+
}),
|
|
174
|
+
'runtime.sendFriendMessage': true,
|
|
175
|
+
'runtime.inbox': [{ author: 'did:friend:1', timestamp: '2024-01-01', data: new Perspective() }],
|
|
176
|
+
'runtime.outbox': [],
|
|
177
|
+
'runtime.notifications': [],
|
|
178
|
+
'runtime.createNotification': true,
|
|
179
|
+
'runtime.updateNotification': true,
|
|
180
|
+
'runtime.grantNotification': true,
|
|
181
|
+
'runtime.deleteNotification': true,
|
|
182
|
+
'runtime.setStatus': true,
|
|
183
|
+
'runtime.linkLanguageTemplates': ['lang://template1'],
|
|
184
|
+
'runtime.addLinkLanguageTemplates': ['lang://template1', 'lang://template2'],
|
|
185
|
+
'runtime.removeLinkLanguageTemplates': ['lang://template1'],
|
|
186
|
+
'runtime.hcAgentInfos': ['hc-agent-info-1', 'hc-agent-info-2'],
|
|
187
|
+
'runtime.addHcAgentInfos': true,
|
|
188
|
+
'runtime.networkMetrics': 'metrics-data',
|
|
189
|
+
'runtime.restartHolochain': true,
|
|
190
|
+
'runtime.verifySignature': true,
|
|
191
|
+
'runtime.exportData': true,
|
|
192
|
+
'runtime.importData': { success: true, count: 5 },
|
|
193
|
+
'runtime.freeHostingEnabled': false,
|
|
194
|
+
'runtime.setFreeHostingEnabled': true,
|
|
195
|
+
'runtime.computeLog': [],
|
|
196
|
+
|
|
197
|
+
// ── AI ──
|
|
198
|
+
'ai.models': [{ id: 'model-1', name: 'GPT-Test', modelType: 'LLM', api: 'openai' }],
|
|
199
|
+
'ai.addModel': 'model-new-id',
|
|
200
|
+
'ai.updateModel': true,
|
|
201
|
+
'ai.removeModel': true,
|
|
202
|
+
'ai.setDefaultModel': true,
|
|
203
|
+
'ai.getDefaultModel': { id: 'model-1', name: 'GPT-Test', modelType: 'LLM' },
|
|
204
|
+
'ai.tasks': [{ taskId: 'task-1', name: 'summarize', modelId: 'model-1', systemPrompt: 'Summarize', promptExamples: [] }],
|
|
205
|
+
'ai.addTask': { taskId: 'task-new', name: 'new-task', modelId: 'model-1', systemPrompt: 'Do stuff', promptExamples: [] },
|
|
206
|
+
'ai.updateTask': { taskId: 'task-1', name: 'updated', modelId: 'model-1', systemPrompt: 'Updated', promptExamples: [] },
|
|
207
|
+
'ai.removeTask': { taskId: 'task-1', name: 'summarize', modelId: 'model-1', systemPrompt: 'Summarize', promptExamples: [] },
|
|
208
|
+
'ai.prompt': 'This is the AI response',
|
|
209
|
+
'ai.modelLoadingStatus': { model: 'model-1', progress: 100, status: 'loaded' },
|
|
210
|
+
|
|
211
|
+
// ── Users (unauthenticated on server — empty token allowed) ──
|
|
212
|
+
'user.create': { success: true, did: 'did:test:new-user' },
|
|
213
|
+
'user.login': 'login-jwt-token',
|
|
214
|
+
'user.verifyEmail': 'verified-token',
|
|
215
|
+
'user.requestVerification': { success: true, message: 'Verification email sent', requiresPassword: false, isExistingUser: true },
|
|
216
|
+
'user.list': [{ email: 'user@test.com', credits: 100, freeAccess: false }],
|
|
217
|
+
'user.multiUserEnabled': false,
|
|
218
|
+
'user.setMultiUserEnabled': true,
|
|
219
|
+
'user.credits': true,
|
|
220
|
+
'user.freeAccess': true,
|
|
221
|
+
'user.wallet': '0x1234567890abcdef',
|
|
222
|
+
'user.emailTest': (p: Record<string, unknown>) => {
|
|
223
|
+
if (p.action === 'get-code') return '123456';
|
|
224
|
+
return true;
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
// ── Hosting ──
|
|
228
|
+
'hosting.info': { email: 'test@test.com' },
|
|
229
|
+
'hosting.setHotWallet': true,
|
|
230
|
+
'hosting.requestPayment': { paymentUrl: 'https://pay.test' },
|
|
231
|
+
|
|
232
|
+
// ── Runtime: host rates & Unyt ──
|
|
233
|
+
'runtime.getHostRates': JSON.stringify([{ description: 'Link write', priceInHOT: 0.001 }]),
|
|
234
|
+
'runtime.setHostRates': true,
|
|
235
|
+
'runtime.unytAgentKey': 'unyt-agent-key-123',
|
|
236
|
+
'runtime.unytHotAgentPubkey': 'unyt-hot-pubkey-456',
|
|
237
|
+
'runtime.unytWalletBalance': '1000.50',
|
|
238
|
+
'runtime.unytWalletHistory': '[]',
|
|
239
|
+
'runtime.unytVersionInfo': '{"version":"0.1.0"}',
|
|
240
|
+
'runtime.unytSetMembraneProof': { success: true, message: 'ok' },
|
|
241
|
+
'runtime.unytReinstallDna': { success: true, message: 'reinstalled' },
|
|
242
|
+
'runtime.unytSendHot': { success: true, message: 'sent' },
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// ===================== MOCK WEBSOCKET =====================
|
|
246
|
+
|
|
247
|
+
/** Tracks the last RPC call for test assertions. */
|
|
248
|
+
let lastRpcCall: { type: string; params: Record<string, unknown> } | null = null;
|
|
249
|
+
|
|
250
|
+
class MockWebSocket {
|
|
251
|
+
static instances: MockWebSocket[] = [];
|
|
252
|
+
static CONNECTING = 0;
|
|
253
|
+
static OPEN = 1;
|
|
254
|
+
static CLOSING = 2;
|
|
255
|
+
static CLOSED = 3;
|
|
256
|
+
|
|
257
|
+
onopen: ((event: any) => void) | null = null;
|
|
258
|
+
onmessage: ((event: { data: string }) => void) | null = null;
|
|
259
|
+
onerror: ((event: any) => void) | null = null;
|
|
260
|
+
onclose: ((event: any) => void) | null = null;
|
|
261
|
+
readyState: number = MockWebSocket.CONNECTING;
|
|
262
|
+
closed = false;
|
|
263
|
+
url: string;
|
|
264
|
+
|
|
265
|
+
close() {
|
|
266
|
+
this.closed = true;
|
|
267
|
+
this.readyState = MockWebSocket.CLOSED;
|
|
268
|
+
this.onclose?.({});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
send(data: string) {
|
|
272
|
+
try {
|
|
273
|
+
const parsed = JSON.parse(data);
|
|
274
|
+
|
|
275
|
+
// Ping/pong keepalive
|
|
276
|
+
if (parsed.type === 'ping') {
|
|
277
|
+
setTimeout(() => {
|
|
278
|
+
this.onmessage?.({ data: JSON.stringify({ type: 'pong' }) });
|
|
279
|
+
}, 0);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// RPC call — resolve directly from MOCK_RESPONSES
|
|
284
|
+
const { id, type: msgType, params: rpcParams } = parsed;
|
|
285
|
+
const params = (rpcParams && typeof rpcParams === 'object')
|
|
286
|
+
? rpcParams as Record<string, unknown>
|
|
287
|
+
: {} as Record<string, unknown>;
|
|
288
|
+
|
|
289
|
+
// Track for assertions
|
|
290
|
+
lastRpcCall = { type: msgType, params };
|
|
291
|
+
|
|
292
|
+
const handler = MOCK_RESPONSES[msgType];
|
|
293
|
+
if (handler === undefined) {
|
|
294
|
+
setTimeout(() => {
|
|
295
|
+
this.onmessage?.({ data: JSON.stringify({ id, error: { code: 404, message: `Unknown RPC type: ${msgType}` } }) });
|
|
296
|
+
}, 0);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const result = typeof handler === 'function'
|
|
301
|
+
? (handler as (p: Record<string, unknown>) => unknown)(params)
|
|
302
|
+
: handler;
|
|
303
|
+
|
|
304
|
+
setTimeout(() => {
|
|
305
|
+
this.onmessage?.({ data: JSON.stringify({ id, result }) });
|
|
306
|
+
}, 0);
|
|
307
|
+
} catch { /* malformed JSON — ignore */ }
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** Simulate server pushing an event to the client. */
|
|
311
|
+
emit(payload: unknown) {
|
|
312
|
+
this.onmessage?.({ data: JSON.stringify(payload) });
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
constructor(url: string) {
|
|
316
|
+
this.url = url;
|
|
317
|
+
MockWebSocket.instances.push(this);
|
|
318
|
+
// Simulate async connection open
|
|
319
|
+
setTimeout(() => {
|
|
320
|
+
if (this.readyState === MockWebSocket.CONNECTING) {
|
|
321
|
+
this.readyState = MockWebSocket.OPEN;
|
|
322
|
+
this.onopen?.({});
|
|
323
|
+
}
|
|
324
|
+
}, 0);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Copy static constants to prototype (matches real WebSocket)
|
|
329
|
+
Object.defineProperty(MockWebSocket.prototype, 'CONNECTING', { value: 0 });
|
|
330
|
+
Object.defineProperty(MockWebSocket.prototype, 'OPEN', { value: 1 });
|
|
331
|
+
Object.defineProperty(MockWebSocket.prototype, 'CLOSING', { value: 2 });
|
|
332
|
+
Object.defineProperty(MockWebSocket.prototype, 'CLOSED', { value: 3 });
|
|
333
|
+
|
|
334
|
+
/** Return the last element of an array (avoids Array.prototype.at which needs ES2022 lib). */
|
|
335
|
+
function lastOf<T>(arr: T[]): T {
|
|
336
|
+
return arr[arr.length - 1];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ===================== TEST SETUP =====================
|
|
340
|
+
|
|
341
|
+
let ad4m: Ad4mClient;
|
|
342
|
+
|
|
343
|
+
beforeAll(() => {
|
|
344
|
+
(global as any).WebSocket = MockWebSocket as any;
|
|
345
|
+
// Ad4mClient takes an HTTP base URL; apiClient converts to ws:// internally
|
|
346
|
+
ad4m = new Ad4mClient('http://127.0.0.1:12000', 'test-token', false);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
afterAll(() => {
|
|
350
|
+
(global as any).WebSocket = originalWebSocket;
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
beforeEach(() => {
|
|
354
|
+
lastRpcCall = null;
|
|
355
|
+
MockWebSocket.instances = [];
|
|
356
|
+
// Clear caches to prevent cross-test interference
|
|
357
|
+
ad4m.agent.clearByDidCache();
|
|
358
|
+
ad4m.expression.clearCache();
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
// ===================== AGENT TESTS =====================
|
|
362
|
+
describe('AgentClient', () => {
|
|
363
|
+
test('me() returns agent with DID', async () => {
|
|
364
|
+
const agent = await ad4m.agent.me();
|
|
365
|
+
expect(agent.did).toBe('did:test:123');
|
|
366
|
+
expect(agent.directMessageLanguage).toBe('lang://dm');
|
|
66
367
|
});
|
|
67
368
|
|
|
369
|
+
test('status() returns agent status', async () => {
|
|
370
|
+
const status = await ad4m.agent.status();
|
|
371
|
+
expect(status.isInitialized).toBe(true);
|
|
372
|
+
expect(status.isUnlocked).toBe(true);
|
|
373
|
+
});
|
|
68
374
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// Pass a different path here if your ApolloServer serves at
|
|
74
|
-
// a different path.
|
|
75
|
-
path: '/subscriptions',
|
|
375
|
+
test('generate() sends passphrase and returns status', async () => {
|
|
376
|
+
const status = await ad4m.agent.generate('secret123');
|
|
377
|
+
expect(lastRpcCall!.params.passphrase).toBe('secret123');
|
|
378
|
+
expect(status.did).toBe('did:test:generated');
|
|
76
379
|
});
|
|
77
380
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
381
|
+
test('lock() locks the agent', async () => {
|
|
382
|
+
const status = await ad4m.agent.lock('secret123');
|
|
383
|
+
expect(lastRpcCall!.params.passphrase).toBe('secret123');
|
|
384
|
+
expect(status.isUnlocked).toBe(false);
|
|
385
|
+
});
|
|
81
386
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
387
|
+
test('unlock() unlocks the agent', async () => {
|
|
388
|
+
const status = await ad4m.agent.unlock('secret123');
|
|
389
|
+
expect(lastRpcCall!.params.passphrase).toBe('secret123');
|
|
390
|
+
expect(lastRpcCall!.params.holochain).toBe(true);
|
|
391
|
+
expect(status.isUnlocked).toBe(true);
|
|
392
|
+
});
|
|
88
393
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
394
|
+
test('import() imports a DID keystore', async () => {
|
|
395
|
+
const status = await ad4m.agent.import({
|
|
396
|
+
did: 'did:test:import', didDocument: 'doc', keystore: 'ks', passphrase: 'pass',
|
|
397
|
+
});
|
|
398
|
+
expect(lastRpcCall!.params.did).toBe('did:test:import');
|
|
399
|
+
expect(status.did).toBe('did:test:imported');
|
|
400
|
+
});
|
|
92
401
|
|
|
93
|
-
|
|
94
|
-
|
|
402
|
+
test('byDID() fetches agent by DID', async () => {
|
|
403
|
+
const agent = await ad4m.agent.byDID('did:test:other');
|
|
404
|
+
expect(agent.did).toBe('did:test:other');
|
|
405
|
+
});
|
|
95
406
|
|
|
96
|
-
|
|
407
|
+
test('signMessage() signs a message', async () => {
|
|
408
|
+
const signed = await ad4m.agent.signMessage('hello');
|
|
409
|
+
expect(lastRpcCall!.params.message).toBe('hello');
|
|
410
|
+
expect(signed).toBe('signed-message-data');
|
|
411
|
+
});
|
|
97
412
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
413
|
+
test('isLocked() returns lock status', async () => {
|
|
414
|
+
const locked = await ad4m.agent.isLocked();
|
|
415
|
+
expect(locked).toBe(false);
|
|
416
|
+
});
|
|
102
417
|
|
|
418
|
+
test('getEntanglementProofs() returns proofs', async () => {
|
|
419
|
+
const proofs = await ad4m.agent.getEntanglementProofs();
|
|
420
|
+
expect(proofs).toEqual(['proof1', 'proof2']);
|
|
421
|
+
});
|
|
103
422
|
|
|
423
|
+
test('addEntanglementProofs() sends proofs', async () => {
|
|
424
|
+
const result = await ad4m.agent.addEntanglementProofs([{ did: 'd', deviceKey: 'k', deviceKeyType: 't', didSigningKeyId: 'sk', deviceKeySignedByDid: 'sig1', didSignedByDeviceKey: 'sig2' }]);
|
|
425
|
+
expect(result).toHaveLength(1);
|
|
426
|
+
});
|
|
104
427
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
428
|
+
test('deleteEntanglementProofs() deletes proofs', async () => {
|
|
429
|
+
const result = await ad4m.agent.deleteEntanglementProofs([{ did: 'd', deviceKey: 'k', deviceKeyType: 't', didSigningKeyId: 'sk', deviceKeySignedByDid: 'sig1', didSignedByDeviceKey: 'sig2' }]);
|
|
430
|
+
expect(result).toEqual([]);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
test('requestCapability() returns request ID', async () => {
|
|
434
|
+
const id = await ad4m.agent.requestCapability({ appName: 'test', appDesc: 'test', appDomain: 'test', appUrl: 'test', capabilities: [] } as any);
|
|
435
|
+
expect(id).toBe('request-id-123');
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
test('permitCapability() returns token', async () => {
|
|
439
|
+
const token = await ad4m.agent.permitCapability('auth-string');
|
|
440
|
+
expect(token).toBe('permitted-token');
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
test('generateJwt() returns JWT', async () => {
|
|
444
|
+
const jwt = await ad4m.agent.generateJwt('req-1', 'rand-1');
|
|
445
|
+
expect(lastRpcCall!.params.requestId).toBe('req-1');
|
|
446
|
+
expect(jwt).toBe('jwt-token-abc');
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
test('getApps() returns apps list', async () => {
|
|
450
|
+
const apps = await ad4m.agent.getApps();
|
|
451
|
+
expect(apps).toHaveLength(1);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
test('removeApp() removes an app', async () => {
|
|
455
|
+
const result = await ad4m.agent.removeApp('app1');
|
|
456
|
+
expect(result).toEqual([]);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
test('revokeToken() revokes a token', async () => {
|
|
460
|
+
const result = await ad4m.agent.revokeToken('app1');
|
|
461
|
+
expect(result).toEqual([]);
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
test('agent-updated event unwraps nested agent payload', async () => {
|
|
465
|
+
const freshClient = new Ad4mClient('http://127.0.0.1:12000', 'test-token', false);
|
|
466
|
+
const callback = jest.fn();
|
|
467
|
+
freshClient.agent.addUpdatedListener(callback);
|
|
468
|
+
freshClient.agent.subscribeAgentUpdated();
|
|
469
|
+
|
|
470
|
+
const ws = lastOf(MockWebSocket.instances);
|
|
471
|
+
|
|
472
|
+
ws.emit({
|
|
473
|
+
type: 'agent-updated',
|
|
474
|
+
agent: { did: 'did:test:updated', directMessageLanguage: 'lang://dm2', perspective: null, isInitialized: true, isUnlocked: true },
|
|
114
475
|
});
|
|
115
476
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
describe('.agent', () => {
|
|
124
|
-
it('me() smoke test', async () => {
|
|
125
|
-
const agent = await ad4mClient.agent.me()
|
|
126
|
-
expect(agent.did).toBe('did:ad4m:test')
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
it('status() smoke test', async () => {
|
|
130
|
-
const agentStatus = await ad4mClient.agent.status()
|
|
131
|
-
expect(agentStatus.did).toBe('did:ad4m:test')
|
|
132
|
-
expect(agentStatus.isUnlocked).toBe(false)
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
it('import() smoke test', async () => {
|
|
136
|
-
const did = "did:test:test"
|
|
137
|
-
const didDocument = "did document test"
|
|
138
|
-
const keystore = "test"
|
|
139
|
-
const passphrase = "secret"
|
|
140
|
-
|
|
141
|
-
const agentStatus = await ad4mClient.agent.import({
|
|
142
|
-
did, didDocument, keystore, passphrase
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
expect(agentStatus.did).toBe(did)
|
|
146
|
-
expect(agentStatus.didDocument).toBe(didDocument)
|
|
147
|
-
expect(agentStatus.isInitialized).toBe(true)
|
|
148
|
-
expect(agentStatus.isUnlocked).toBe(true)
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
it('generate() smoke test', async () => {
|
|
152
|
-
const agentStatus = await ad4mClient.agent.generate("passphrase")
|
|
153
|
-
expect(agentStatus.did).toBeDefined()
|
|
154
|
-
expect(agentStatus.isInitialized).toBeTruthy()
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
it('lock() smoke test', async () => {
|
|
158
|
-
const agentStatus = await ad4mClient.agent.lock('secret')
|
|
159
|
-
expect(agentStatus.did).toBe("did:ad4m:test")
|
|
160
|
-
expect(agentStatus.isUnlocked).toBe(false)
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
it('unlock() smoke test', async () => {
|
|
164
|
-
const agentStatus = await ad4mClient.agent.unlock('secret', false)
|
|
165
|
-
expect(agentStatus.did).toBe("did:ad4m:test")
|
|
166
|
-
expect(agentStatus.isUnlocked).toBe(true)
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
it('byDID() smoke test', async () => {
|
|
170
|
-
const agent = await ad4mClient.agent.byDID('did:method:12345')
|
|
171
|
-
expect(agent.did).toBe('did:method:12345')
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
it('updatePublicPerspective() smoke test', async () => {
|
|
175
|
-
const perspective = new Perspective()
|
|
176
|
-
const link = new LinkExpression()
|
|
177
|
-
link.author = 'did:method:12345'
|
|
178
|
-
link.timestamp = new Date().toString()
|
|
179
|
-
link.data = new Link({source: 'root', target: 'perspective://Qm34589a3ccc0'})
|
|
180
|
-
link.proof = { signature: 'asdfasdf', key: 'asdfasdf' }
|
|
181
|
-
perspective.links.push(link)
|
|
182
|
-
|
|
183
|
-
const agent = await ad4mClient.agent.updatePublicPerspective(perspective)
|
|
184
|
-
expect(agent.did).toBe('did:ad4m:test')
|
|
185
|
-
expect(agent.perspective.links.length).toBe(1)
|
|
186
|
-
expect(agent.perspective.links[0].data.source).toBe('root')
|
|
187
|
-
expect(agent.perspective.links[0].data.target).toBe('perspective://Qm34589a3ccc0')
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
it('mutatePublicPerspective() smoke test', async () => {
|
|
191
|
-
let additionLink = new Link({source: 'root', target: 'perspective://Qm34589a3ccc0'})
|
|
192
|
-
const removalLink = new LinkExpression()
|
|
193
|
-
removalLink.author = "did:ad4m:test"
|
|
194
|
-
removalLink.timestamp = Date.now().toString()
|
|
195
|
-
removalLink.data = {
|
|
196
|
-
source: 'root2',
|
|
197
|
-
target: 'perspective://Qm34589a3ccc0'
|
|
198
|
-
}
|
|
199
|
-
removalLink.proof = {
|
|
200
|
-
signature: '',
|
|
201
|
-
key: '',
|
|
202
|
-
valid: true
|
|
203
|
-
}
|
|
477
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
478
|
+
const received = callback.mock.calls[0][0];
|
|
479
|
+
expect(received.did).toBe('did:test:updated');
|
|
480
|
+
expect(received.directMessageLanguage).toBe('lang://dm2');
|
|
481
|
+
expect(received).not.toHaveProperty('type');
|
|
482
|
+
});
|
|
204
483
|
|
|
484
|
+
test('agent-status-changed event unwraps nested agent payload', async () => {
|
|
485
|
+
const freshClient = new Ad4mClient('http://127.0.0.1:12000', 'test-token', false);
|
|
486
|
+
const callback = jest.fn();
|
|
487
|
+
freshClient.agent.addAgentStatusChangedListener(callback);
|
|
488
|
+
freshClient.agent.subscribeAgentStatusChanged();
|
|
205
489
|
|
|
206
|
-
|
|
207
|
-
const agent = await ad4mClient.agent.mutatePublicPerspective({additions: [additionLink], removals: [removalLink]} as LinkMutations)
|
|
208
|
-
expect(agent.did).toBe('did:ad4m:test')
|
|
209
|
-
expect(agent.perspective.links.length).toBe(1)
|
|
210
|
-
expect(agent.perspective.links[0].data.source).toBe('root')
|
|
211
|
-
expect(agent.perspective.links[0].data.target).toBe('neighbourhood://Qm12345')
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
it('updateDirectMessageLanguage() smoke test', async () => {
|
|
215
|
-
const agent = await ad4mClient.agent.updateDirectMessageLanguage("abcd")
|
|
216
|
-
expect(agent.directMessageLanguage).toBe('abcd')
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
it('entanglementProof() smoke tests', async () => {
|
|
220
|
-
const addProof = await ad4mClient.agent.addEntanglementProofs([new EntanglementProofInput("did:key:hash", "did-key-id", "ethereum", "ethAddr", "sig", "sig2")]);
|
|
221
|
-
expect(addProof[0].did).toBe("did:key:hash")
|
|
222
|
-
expect(addProof[0].didSigningKeyId).toBe("did-key-id")
|
|
223
|
-
expect(addProof[0].deviceKeyType).toBe("ethereum")
|
|
224
|
-
expect(addProof[0].deviceKey).toBe("ethAddr")
|
|
225
|
-
expect(addProof[0].deviceKeySignedByDid).toBe("sig")
|
|
226
|
-
expect(addProof[0].didSignedByDeviceKey).toBe("sig2")
|
|
227
|
-
|
|
228
|
-
const getProofs = await ad4mClient.agent.getEntanglementProofs();
|
|
229
|
-
expect(getProofs[0].did).toBe("did:key:hash")
|
|
230
|
-
expect(getProofs[0].didSigningKeyId).toBe("did-key-id")
|
|
231
|
-
expect(getProofs[0].deviceKeyType).toBe("ethereum")
|
|
232
|
-
expect(getProofs[0].deviceKey).toBe("ethAddr")
|
|
233
|
-
expect(getProofs[0].deviceKeySignedByDid).toBe("sig")
|
|
234
|
-
expect(getProofs[0].didSignedByDeviceKey).toBe("sig2")
|
|
235
|
-
|
|
236
|
-
const deleteProofs = await ad4mClient.agent.deleteEntanglementProofs([new EntanglementProofInput("did:key:hash", "did-key-id", "ethereum", "ethAddr", "sig", "sig2")]);
|
|
237
|
-
expect(deleteProofs[0].did).toBe("did:key:hash")
|
|
238
|
-
expect(deleteProofs[0].didSigningKeyId).toBe("did-key-id")
|
|
239
|
-
expect(deleteProofs[0].deviceKeyType).toBe("ethereum")
|
|
240
|
-
expect(deleteProofs[0].deviceKey).toBe("ethAddr")
|
|
241
|
-
expect(deleteProofs[0].deviceKeySignedByDid).toBe("sig")
|
|
242
|
-
expect(deleteProofs[0].didSignedByDeviceKey).toBe("sig2")
|
|
243
|
-
|
|
244
|
-
const preflight = await ad4mClient.agent.entanglementProofPreFlight("ethAddr", "ethereum");
|
|
245
|
-
expect(preflight.did).toBe("did:key:hash")
|
|
246
|
-
expect(preflight.didSigningKeyId).toBe("did-key-id")
|
|
247
|
-
expect(preflight.deviceKeyType).toBe("ethereum")
|
|
248
|
-
expect(preflight.deviceKey).toBe("ethAddr")
|
|
249
|
-
expect(preflight.deviceKeySignedByDid).toBe("sig")
|
|
250
|
-
expect(preflight.didSignedByDeviceKey).toBe(null)
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
it('requestCapability() smoke tests', async () => {
|
|
254
|
-
const requestId = await ad4mClient.agent.requestCapability({
|
|
255
|
-
appName: "demo-app",
|
|
256
|
-
appDesc: "demo-desc",
|
|
257
|
-
appDomain: "demo.test.org",
|
|
258
|
-
appUrl: "https://demo-link",
|
|
259
|
-
appIconPath: "/some/image/path",
|
|
260
|
-
capabilities: [
|
|
261
|
-
{
|
|
262
|
-
with: {
|
|
263
|
-
"domain":"agent",
|
|
264
|
-
"pointers":["*"]
|
|
265
|
-
} as ResourceInput,
|
|
266
|
-
can: ["QUERY"]
|
|
267
|
-
}] as CapabilityInput[]
|
|
268
|
-
} as AuthInfoInput)
|
|
269
|
-
expect(requestId).toBe("test-request-id")
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
it('agentGetApps() smoke tests', async () => {
|
|
274
|
-
const apps = await ad4mClient.agent.getApps()
|
|
275
|
-
expect(apps.length).toBe(0)
|
|
276
|
-
})
|
|
277
|
-
|
|
278
|
-
it('agentPermitCapability() smoke tests', async () => {
|
|
279
|
-
const rand = await ad4mClient.agent.permitCapability('{"requestId":"4f30e2e2-d307-4f2b-b0a0-6dac4ca4af26","auth":{"appName":"demo-app","appDesc":"demo-desc","appUrl":"demo-url","capabilities":[{"with":{"domain":"agent","pointers":["*"]},"can":["QUERY"]}]}}')
|
|
280
|
-
expect(rand).toBe("123")
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
it('agentGenerateJwt() smoke tests', async () => {
|
|
284
|
-
const jwt = await ad4mClient.agent.generateJwt("test-request-id", "123")
|
|
285
|
-
expect(jwt).toBe("test-jwt")
|
|
286
|
-
})
|
|
287
|
-
|
|
288
|
-
it('agentRevokeToken() smoke tests', async () => {
|
|
289
|
-
const newApps = await ad4mClient.agent.revokeToken('test-request-id')
|
|
290
|
-
expect(newApps.length).toBe(1)
|
|
291
|
-
expect(newApps[0].revoked).toBe(true)
|
|
292
|
-
})
|
|
293
|
-
|
|
294
|
-
it('agentRemoveToken() smoke tests', async () => {
|
|
295
|
-
const newApps = await ad4mClient.agent.removeApp('test-request-id')
|
|
296
|
-
expect(newApps.length).toBe(0)
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
it('agentIsLocked() smoke tests', async () => {
|
|
300
|
-
const status = await ad4mClient.agent.isLocked()
|
|
301
|
-
expect(status).toBe(false)
|
|
302
|
-
})
|
|
303
|
-
|
|
304
|
-
it('agentSignMessage() smoke tests', async () => {
|
|
305
|
-
const sig = await ad4mClient.agent.signMessage("test-message")
|
|
306
|
-
expect(sig.signature).toBe("test-message-signature")
|
|
307
|
-
expect(sig.publicKey).toBe("test-public-key")
|
|
308
|
-
})
|
|
309
|
-
})
|
|
310
|
-
|
|
311
|
-
describe('.expression', () => {
|
|
312
|
-
it('get() smoke test', async () => {
|
|
313
|
-
const nonExisting = await ad4mClient.expression.get("wrong address")
|
|
314
|
-
expect(nonExisting).toBeNull()
|
|
315
|
-
|
|
316
|
-
const expression = await ad4mClient.expression.get("neighbourhood://Qm123")
|
|
317
|
-
expect(expression).toBeDefined()
|
|
318
|
-
expect(expression.author).toBe('did:ad4m:test')
|
|
319
|
-
expect(expression.data).toBe("{\"type\":\"test expression\",\"content\":\"test\"}")
|
|
320
|
-
})
|
|
321
|
-
|
|
322
|
-
it('getMany() smoke test', async () => {
|
|
323
|
-
const getMany = await ad4mClient.expression.getMany(["hash1", "hash2"]);
|
|
324
|
-
expect(getMany.length).toBe(2);
|
|
325
|
-
expect(getMany[0].author).toBe('did:ad4m:test');
|
|
326
|
-
expect(getMany[0].data).toBe("{\"type\":\"test expression\",\"content\":\"test\"}");
|
|
327
|
-
expect(getMany[1]).toBeNull();
|
|
328
|
-
})
|
|
329
|
-
|
|
330
|
-
it('getRaw() smoke test', async () => {
|
|
331
|
-
const nonExisting = await ad4mClient.expression.getRaw("wrong address")
|
|
332
|
-
expect(nonExisting).toBeNull()
|
|
333
|
-
|
|
334
|
-
const expressionRaw = await ad4mClient.expression.getRaw("neighbourhood://Qm123")
|
|
335
|
-
expect(expressionRaw).toBeDefined()
|
|
336
|
-
const expression = JSON.parse(expressionRaw)
|
|
337
|
-
expect(expression.author).toBe('did:ad4m:test')
|
|
338
|
-
expect(expression.data).toBe("{\"type\":\"test expression\",\"content\":\"test\"}")
|
|
339
|
-
})
|
|
340
|
-
|
|
341
|
-
it('create() smoke test', async () => {
|
|
342
|
-
const address = await ad4mClient.expression.create('content', 'Qmabcdf')
|
|
343
|
-
expect(address.toString()).toBe("Qm1234")
|
|
344
|
-
|
|
345
|
-
const address2 = await ad4mClient.expression.create({content: 'json'}, 'Qmabcdf')
|
|
346
|
-
expect(address2.toString()).toBe("Qm1234")
|
|
347
|
-
})
|
|
348
|
-
|
|
349
|
-
it('interactions() smoke test', async () => {
|
|
350
|
-
const interactions = await ad4mClient.expression.interactions('Qmabcdf')
|
|
351
|
-
expect(interactions.length).toBe(1)
|
|
352
|
-
const i = interactions[0]
|
|
353
|
-
expect(i.label).toBe("Add a comment")
|
|
354
|
-
expect(i.name).toBe("add_comment")
|
|
355
|
-
expect(i.parameters.length).toBe(1)
|
|
356
|
-
const param = i.parameters[0]
|
|
357
|
-
expect(param.name).toBe('comment')
|
|
358
|
-
expect(param.type).toBe('string')
|
|
359
|
-
})
|
|
360
|
-
|
|
361
|
-
it('interact() smoke test', async () => {
|
|
362
|
-
const call = new InteractionCall('add_comment', { content: 'test'})
|
|
363
|
-
const result = await ad4mClient.expression.interact('Qmabcdf', call)
|
|
364
|
-
expect(result.toString()).toBe("test result")
|
|
365
|
-
})
|
|
366
|
-
})
|
|
367
|
-
|
|
368
|
-
describe('.langauges', () => {
|
|
369
|
-
it('byAddress() smoke test', async () => {
|
|
370
|
-
const language = await ad4mClient.languages.byAddress('test-language-address')
|
|
371
|
-
expect(language.address).toBe('test-language-address')
|
|
372
|
-
})
|
|
373
|
-
|
|
374
|
-
it('byFilter() smoke test', async () => {
|
|
375
|
-
const languages = await ad4mClient.languages.byFilter('linksAdapter')
|
|
376
|
-
expect(languages.length).toBe(1)
|
|
377
|
-
expect(languages[0].name).toBe('test-links-language')
|
|
378
|
-
})
|
|
379
|
-
|
|
380
|
-
it('all() smoke test', async () => {
|
|
381
|
-
const languages = await ad4mClient.languages.all()
|
|
382
|
-
expect(languages.length).toBe(1)
|
|
383
|
-
expect(languages[0].name).toBe('test-links-language')
|
|
384
|
-
})
|
|
385
|
-
|
|
386
|
-
it('writeSettings() smoke test', async () => {
|
|
387
|
-
const result = await ad4mClient.languages.writeSettings(
|
|
388
|
-
'test-language-address',
|
|
389
|
-
JSON.stringify({testSetting: true})
|
|
390
|
-
)
|
|
391
|
-
expect(result).toBe(true)
|
|
392
|
-
})
|
|
393
|
-
|
|
394
|
-
it('applyTemplateAndPublish() smoke test', async () => {
|
|
395
|
-
const language = await ad4mClient.languages.applyTemplateAndPublish(
|
|
396
|
-
'languageHash',
|
|
397
|
-
'{"name": "test-templating"}',
|
|
398
|
-
)
|
|
399
|
-
expect(language.name).toBe('languageHash-clone')
|
|
400
|
-
})
|
|
401
|
-
|
|
402
|
-
it('publish() smoke test', async () => {
|
|
403
|
-
let input = new LanguageMetaInput()
|
|
404
|
-
input.name = "test language 1"
|
|
405
|
-
input.description = "Language for smoke testing"
|
|
406
|
-
input.possibleTemplateParams = ['uuid', 'name', 'membrane']
|
|
407
|
-
input.sourceCodeLink = "https://github.com/perspect3vism/test-language"
|
|
408
|
-
|
|
409
|
-
const languageMeta = await ad4mClient.languages.publish(
|
|
410
|
-
'/some/language/path/',
|
|
411
|
-
input,
|
|
412
|
-
)
|
|
413
|
-
expect(languageMeta.name).toBe(input.name)
|
|
414
|
-
expect(languageMeta.description).toBe(input.description)
|
|
415
|
-
expect(languageMeta.possibleTemplateParams).toStrictEqual(input.possibleTemplateParams)
|
|
416
|
-
expect(languageMeta.sourceCodeLink).toBe(input.sourceCodeLink)
|
|
417
|
-
expect(languageMeta.address).toBe("Qm12345")
|
|
418
|
-
expect(languageMeta.author).toBe("did:test:me")
|
|
419
|
-
expect(languageMeta.templateSourceLanguageAddress).toBe("Qm12345")
|
|
420
|
-
expect(languageMeta.templateAppliedParams).toBe(JSON.stringify({uuid: 'asdfsdaf', name: 'test template'}))
|
|
421
|
-
})
|
|
422
|
-
|
|
423
|
-
it('meta() smoke test', async () => {
|
|
424
|
-
let input = new LanguageMetaInput()
|
|
425
|
-
input.name = "test language 1"
|
|
426
|
-
input.description = "Language for smoke testing"
|
|
427
|
-
input.possibleTemplateParams = ['uuid', 'name', 'membrane']
|
|
428
|
-
input.sourceCodeLink = "https://github.com/perspect3vism/test-language"
|
|
429
|
-
|
|
430
|
-
const languageMeta = await ad4mClient.languages.meta("Qm12345")
|
|
431
|
-
|
|
432
|
-
expect(languageMeta.name).toBe("test-language")
|
|
433
|
-
expect(languageMeta.address).toBe("Qm12345")
|
|
434
|
-
expect(languageMeta.description).toBe("Language meta for testing")
|
|
435
|
-
expect(languageMeta.author).toBe("did:test:me")
|
|
436
|
-
expect(languageMeta.templated).toBe(true)
|
|
437
|
-
expect(languageMeta.templateSourceLanguageAddress).toBe("Qm12345")
|
|
438
|
-
expect(languageMeta.templateAppliedParams).toBe(JSON.stringify({uuid: 'asdfsdaf', name: 'test template'}))
|
|
439
|
-
expect(languageMeta.possibleTemplateParams).toStrictEqual(['uuid', 'name'])
|
|
440
|
-
expect(languageMeta.sourceCodeLink).toBe("https://github.com/perspect3vism/ad4m")
|
|
441
|
-
})
|
|
442
|
-
|
|
443
|
-
it('source() smoke test', async () => {
|
|
444
|
-
const source = await ad4mClient.languages.source("Qm12345")
|
|
445
|
-
expect(source).toBe("var test = 'language source code'")
|
|
446
|
-
})
|
|
447
|
-
|
|
448
|
-
it('remove() smoke test', async () => {
|
|
449
|
-
const result = await ad4mClient.languages.remove("Qm12345");
|
|
450
|
-
expect(result).toBe(true);
|
|
451
|
-
})
|
|
452
|
-
})
|
|
453
|
-
|
|
454
|
-
describe('.neighbourhood', () => {
|
|
455
|
-
const testPerspective = new Perspective()
|
|
456
|
-
const linkExpr = new LinkExpression()
|
|
457
|
-
linkExpr.author = 'did:method:12345'
|
|
458
|
-
linkExpr.timestamp = new Date().toString()
|
|
459
|
-
linkExpr.data = new Link({source: 'root', target: 'perspective://Qm34589a3ccc0'})
|
|
460
|
-
linkExpr.proof = { signature: 'asdfasdf', key: 'asdfasdf' }
|
|
461
|
-
testPerspective.links.push(linkExpr)
|
|
462
|
-
|
|
463
|
-
const testUnsignedPerspective = new PerspectiveUnsignedInput()
|
|
464
|
-
const link = new Link({
|
|
465
|
-
source: 'root', target: 'perspective://Qm34589a3ccc0'
|
|
466
|
-
})
|
|
467
|
-
testUnsignedPerspective.links.push(link)
|
|
468
|
-
|
|
469
|
-
it('publishFromPerspective() smoke test', async () => {
|
|
470
|
-
const expressionRef = await ad4mClient.neighbourhood.publishFromPerspective('UUID', 'test-link-lang', new Perspective())
|
|
471
|
-
expect(expressionRef).toBe('neighbourhood://neighbourhoodAddress')
|
|
472
|
-
})
|
|
473
|
-
|
|
474
|
-
it('joinFromUrl() smoke test', async () => {
|
|
475
|
-
const perspective = await ad4mClient.neighbourhood.joinFromUrl('neighbourhood://Qm3sdf3dfwhsafd')
|
|
476
|
-
expect(perspective.sharedUrl).toBe('neighbourhood://Qm3sdf3dfwhsafd')
|
|
477
|
-
expect(perspective.uuid).toBeTruthy()
|
|
478
|
-
expect(perspective.name).toBeTruthy()
|
|
479
|
-
})
|
|
480
|
-
|
|
481
|
-
it('hasTelepresenceAdapter() smoke test', async () => {
|
|
482
|
-
const result = await ad4mClient.neighbourhood.hasTelepresenceAdapter('01234')
|
|
483
|
-
expect(result).toBe(true)
|
|
484
|
-
})
|
|
485
|
-
|
|
486
|
-
it('otherAgents() smoke test', async () => {
|
|
487
|
-
const agents = await ad4mClient.neighbourhood.otherAgents('01234')
|
|
488
|
-
expect(agents.length).toBe(1)
|
|
489
|
-
expect(agents[0]).toBe('did:test:other')
|
|
490
|
-
})
|
|
491
|
-
|
|
492
|
-
it('onlineAgents() smoke test', async () => {
|
|
493
|
-
const agents = await ad4mClient.neighbourhood.onlineAgents('01234')
|
|
494
|
-
expect(agents.length).toBe(1)
|
|
495
|
-
expect(agents[0].did).toBe('did:test:online')
|
|
496
|
-
const status = agents[0].status
|
|
497
|
-
expect(status.author).toBe('did:ad4m:test')
|
|
498
|
-
expect(status.data.links.length).toBe(1)
|
|
499
|
-
const link = status.data.links[0]
|
|
500
|
-
expect(link.author).toBe('did:ad4m:test')
|
|
501
|
-
expect(link.data.source).toBe('root')
|
|
502
|
-
})
|
|
503
|
-
|
|
504
|
-
it('setOnlineStatus() smoke test', async () => {
|
|
505
|
-
const result = await ad4mClient.neighbourhood.setOnlineStatus('01234', testPerspective)
|
|
506
|
-
expect(result).toBe(true)
|
|
507
|
-
})
|
|
508
|
-
|
|
509
|
-
it('setOnlineStatusU() smoke test', async () => {
|
|
510
|
-
const result = await ad4mClient.neighbourhood.setOnlineStatusU('01234', testUnsignedPerspective)
|
|
511
|
-
expect(result).toBe(true)
|
|
512
|
-
})
|
|
513
|
-
|
|
514
|
-
it('sendSignal() smoke test', async () => {
|
|
515
|
-
const result = await ad4mClient.neighbourhood.sendSignal('01234', "did:test:recipient", testPerspective)
|
|
516
|
-
expect(result).toBe(true)
|
|
517
|
-
})
|
|
518
|
-
|
|
519
|
-
it('sendSignaU() smoke test', async () => {
|
|
520
|
-
const result = await ad4mClient.neighbourhood.sendSignalU('01234', "did:test:recipient", testUnsignedPerspective)
|
|
521
|
-
expect(result).toBe(true)
|
|
522
|
-
})
|
|
523
|
-
|
|
524
|
-
it('sendBroadcast() smoke test', async () => {
|
|
525
|
-
const result = await ad4mClient.neighbourhood.sendBroadcast('01234', testPerspective)
|
|
526
|
-
expect(result).toBe(true)
|
|
527
|
-
})
|
|
528
|
-
|
|
529
|
-
it('sendBroadcastU() smoke test', async () => {
|
|
530
|
-
const result = await ad4mClient.neighbourhood.sendBroadcastU('01234', testUnsignedPerspective)
|
|
531
|
-
expect(result).toBe(true)
|
|
532
|
-
})
|
|
533
|
-
|
|
534
|
-
it('can be accessed via NeighbourhoodProxy', async () => {
|
|
535
|
-
const perspective = await ad4mClient.perspective.byUUID('00001')
|
|
536
|
-
const nh = await perspective.getNeighbourhoodProxy()
|
|
537
|
-
|
|
538
|
-
expect(await nh.hasTelepresenceAdapter()).toBe(true)
|
|
539
|
-
expect(await nh.otherAgents()).toStrictEqual(['did:test:other'])
|
|
540
|
-
expect((await nh.onlineAgents())[0].did).toStrictEqual('did:test:online')
|
|
541
|
-
expect(await nh.setOnlineStatus(testPerspective)).toBe(true)
|
|
542
|
-
expect(await nh.sendSignal('did:test:recipient', testPerspective)).toBe(true)
|
|
543
|
-
expect(await nh.sendBroadcast(testPerspective)).toBe(true)
|
|
544
|
-
|
|
545
|
-
nh.addSignalHandler((perspective) => {
|
|
546
|
-
//..
|
|
547
|
-
})
|
|
548
|
-
})
|
|
549
|
-
})
|
|
550
|
-
|
|
551
|
-
describe('.perspective', () => {
|
|
552
|
-
it('all() smoke test',async () => {
|
|
553
|
-
const perspectives = await ad4mClient.perspective.all()
|
|
554
|
-
expect(perspectives.length).toBe(2)
|
|
555
|
-
const p1 = perspectives[0]
|
|
556
|
-
const p2 = perspectives[1]
|
|
557
|
-
expect(p1.name).toBe('test-perspective-1')
|
|
558
|
-
expect(p2.name).toBe('test-perspective-2')
|
|
559
|
-
expect(p1.uuid).toBe('00001')
|
|
560
|
-
expect(p2.uuid).toBe('00002')
|
|
561
|
-
expect(p2.sharedUrl).toBe('neighbourhood://Qm12345')
|
|
562
|
-
expect(p2.neighbourhood.data.linkLanguage).toBe("language://Qm12345")
|
|
563
|
-
})
|
|
564
|
-
|
|
565
|
-
it('byUUID() smoke test', async () => {
|
|
566
|
-
const p = await ad4mClient.perspective.byUUID('00004')
|
|
567
|
-
expect(p.uuid).toBe('00004')
|
|
568
|
-
expect(p.name).toBe('test-perspective-1')
|
|
569
|
-
})
|
|
570
|
-
|
|
571
|
-
it('snapshotByUUID() smoke test', async () => {
|
|
572
|
-
const ps = await ad4mClient.perspective.snapshotByUUID('00004')
|
|
573
|
-
expect(ps.links.length).toBe(1)
|
|
574
|
-
expect(ps.links[0].author).toBe('did:ad4m:test')
|
|
575
|
-
expect(ps.links[0].data.source).toBe('root')
|
|
576
|
-
expect(ps.links[0].data.target).toBe('neighbourhood://Qm12345')
|
|
577
|
-
})
|
|
578
|
-
|
|
579
|
-
it('publishSnapshotByUUID() smoke test', async () => {
|
|
580
|
-
const snapshotUrl = await ad4mClient.perspective.publishSnapshotByUUID('00004')
|
|
581
|
-
expect(snapshotUrl).toBe('perspective://Qm12345')
|
|
582
|
-
|
|
583
|
-
})
|
|
584
|
-
|
|
585
|
-
it('queryLinks() smoke test', async () => {
|
|
586
|
-
const links = await ad4mClient.perspective.queryLinks('000001', {source: 'root'})
|
|
587
|
-
expect(links.length).toBe(1)
|
|
588
|
-
expect(links[0].data.source).toBe('root')
|
|
589
|
-
expect(links[0].data.target).toBe('neighbourhood://Qm12345')
|
|
590
|
-
})
|
|
591
|
-
|
|
592
|
-
it('queryProlog() smoke test', async () => {
|
|
593
|
-
let result = await ad4mClient.perspective.queryProlog('000001', "link(X, 2).")
|
|
594
|
-
expect(result.length).toBe(1)
|
|
595
|
-
expect(result[0].X).toBe(1)
|
|
596
|
-
|
|
597
|
-
const proxy = await ad4mClient.perspective.byUUID('000001')
|
|
598
|
-
result = await proxy.infer("link(X, 2).")
|
|
599
|
-
expect(result.length).toBe(1)
|
|
600
|
-
expect(result[0].X).toBe(1)
|
|
601
|
-
})
|
|
602
|
-
|
|
603
|
-
it('add() smoke test', async () => {
|
|
604
|
-
const p = await ad4mClient.perspective.add('p-name')
|
|
605
|
-
expect(p.uuid).toBe('00006')
|
|
606
|
-
expect(p.name).toBe('p-name')
|
|
607
|
-
})
|
|
608
|
-
|
|
609
|
-
it('update() smoke test', async () => {
|
|
610
|
-
const p = await ad4mClient.perspective.update('00001', 'new-name')
|
|
611
|
-
expect(p.uuid).toBe('00001')
|
|
612
|
-
expect(p.name).toBe('new-name')
|
|
613
|
-
})
|
|
614
|
-
|
|
615
|
-
it('remove() smoke test', async () => {
|
|
616
|
-
const r = await ad4mClient.perspective.remove('000001')
|
|
617
|
-
expect(r).toBeTruthy()
|
|
618
|
-
})
|
|
619
|
-
|
|
620
|
-
it('addLink() smoke test', async () => {
|
|
621
|
-
const link = await ad4mClient.perspective.addLink('00001', {source: 'root', target: 'lang://Qm123', predicate: 'p'})
|
|
622
|
-
expect(link.author).toBe('did:ad4m:test')
|
|
623
|
-
expect(link.data.source).toBe('root')
|
|
624
|
-
expect(link.data.predicate).toBe('p')
|
|
625
|
-
expect(link.data.target).toBe('lang://Qm123')
|
|
626
|
-
expect(link.status).toBe('shared')
|
|
627
|
-
})
|
|
628
|
-
|
|
629
|
-
it('addLocalLink() smoke test', async () => {
|
|
630
|
-
const link = await ad4mClient.perspective.addLink('00001', {source: 'root', target: 'lang://Qm123', predicate: 'p'}, 'local')
|
|
631
|
-
expect(link.author).toBe('did:ad4m:test')
|
|
632
|
-
expect(link.data.source).toBe('root')
|
|
633
|
-
expect(link.data.predicate).toBe('p')
|
|
634
|
-
expect(link.data.target).toBe('lang://Qm123')
|
|
635
|
-
expect(link.status).toBe('local')
|
|
636
|
-
})
|
|
637
|
-
|
|
638
|
-
it('addLinks() smoke test', async () => {
|
|
639
|
-
const links = await ad4mClient.perspective.addLinks('00001', [
|
|
640
|
-
{source: 'root', target: 'lang://Qm123', predicate: 'p'},
|
|
641
|
-
{source: 'root', target: 'lang://Qm123', predicate: 'p'}
|
|
642
|
-
])
|
|
643
|
-
expect(links.length).toBe(2)
|
|
644
|
-
expect(links[0].author).toBe('did:ad4m:test')
|
|
645
|
-
expect(links[0].data.source).toBe('root')
|
|
646
|
-
expect(links[0].data.predicate).toBe('p')
|
|
647
|
-
expect(links[0].data.target)
|
|
648
|
-
})
|
|
649
|
-
|
|
650
|
-
it('removeLinks() smoke test', async () => {
|
|
651
|
-
const links = await ad4mClient.perspective.removeLinks('00001', [
|
|
652
|
-
{author: '', timestamp: '', proof: {signature: '', key: ''}, data: {source: 'root', target: 'lang://Qm123', predicate: 'p'}},
|
|
653
|
-
{author: '', timestamp: '', proof: {signature: '', key: ''}, data: {source: 'root', target: 'lang://Qm123', predicate: 'p'}}
|
|
654
|
-
])
|
|
655
|
-
expect(links.length).toBe(2)
|
|
656
|
-
expect(links[0].author).toBe('did:ad4m:test')
|
|
657
|
-
expect(links[0].data.source).toBe('root')
|
|
658
|
-
expect(links[0].data.predicate).toBe('p')
|
|
659
|
-
expect(links[0].data.target)
|
|
660
|
-
})
|
|
661
|
-
|
|
662
|
-
it('linkMutations() smoke test', async () => {
|
|
663
|
-
const mutations = await ad4mClient.perspective.linkMutations('00001', {
|
|
664
|
-
additions: [
|
|
665
|
-
{source: 'root', target: 'lang://Qm123', predicate: 'p'},
|
|
666
|
-
{source: 'root', target: 'lang://Qm123', predicate: 'p'}
|
|
667
|
-
],
|
|
668
|
-
removals: [
|
|
669
|
-
{author: '', timestamp: '', proof: {signature: '', key: ''}, data: {source: 'root', target: 'lang://Qm123', predicate: 'p'}},
|
|
670
|
-
{author: '', timestamp: '', proof: {signature: '', key: ''}, data: {source: 'root', target: 'lang://Qm123', predicate: 'p'}}
|
|
671
|
-
]
|
|
672
|
-
});
|
|
673
|
-
expect(mutations.additions.length).toBe(2)
|
|
674
|
-
expect(mutations.removals.length).toBe(2)
|
|
675
|
-
|
|
676
|
-
expect(mutations.additions[0].author).toBe('did:ad4m:test')
|
|
677
|
-
expect(mutations.additions[0].data.source).toBe('root')
|
|
678
|
-
expect(mutations.additions[0].data.predicate).toBe('p')
|
|
679
|
-
expect(mutations.additions[0].data.target).toBe('lang://Qm123')
|
|
680
|
-
|
|
681
|
-
expect(mutations.removals[0].author).toBe('did:ad4m:test')
|
|
682
|
-
expect(mutations.removals[0].data.source).toBe('root')
|
|
683
|
-
expect(mutations.removals[0].data.predicate).toBe('p')
|
|
684
|
-
expect(mutations.removals[0].data.target).toBe('lang://Qm123')
|
|
685
|
-
})
|
|
686
|
-
|
|
687
|
-
it('addLinkExpression() smoke test', async () => {
|
|
688
|
-
const testLink = new LinkExpression()
|
|
689
|
-
testLink.author = "did:ad4m:test"
|
|
690
|
-
testLink.timestamp = Date.now().toString()
|
|
691
|
-
testLink.data = {
|
|
692
|
-
source: 'root',
|
|
693
|
-
target: 'lang://Qm123',
|
|
694
|
-
predicate: 'p'
|
|
695
|
-
}
|
|
696
|
-
testLink.proof = {
|
|
697
|
-
signature: '',
|
|
698
|
-
key: '',
|
|
699
|
-
valid: true
|
|
700
|
-
}
|
|
701
|
-
const link = await ad4mClient.perspective.addLinkExpression('00001', testLink);
|
|
702
|
-
expect(link.author).toBe('did:ad4m:test')
|
|
703
|
-
expect(link.data.source).toBe('root')
|
|
704
|
-
expect(link.data.predicate).toBe('p')
|
|
705
|
-
expect(link.data.target).toBe('lang://Qm123')
|
|
706
|
-
})
|
|
707
|
-
|
|
708
|
-
it('addListener() smoke test', async () => {
|
|
709
|
-
let perspective = await ad4mClient.perspective.byUUID('00004')
|
|
710
|
-
|
|
711
|
-
const testLink = new LinkExpression()
|
|
712
|
-
testLink.author = "did:ad4m:test"
|
|
713
|
-
testLink.timestamp = Date.now().toString()
|
|
714
|
-
testLink.data = {
|
|
715
|
-
source: 'root',
|
|
716
|
-
target: 'neighbourhood://Qm12345'
|
|
717
|
-
}
|
|
718
|
-
testLink.proof = {
|
|
719
|
-
signature: '',
|
|
720
|
-
key: '',
|
|
721
|
-
valid: true
|
|
722
|
-
}
|
|
490
|
+
const ws = lastOf(MockWebSocket.instances);
|
|
723
491
|
|
|
724
|
-
|
|
725
|
-
|
|
492
|
+
ws.emit({
|
|
493
|
+
type: 'agent-status-changed',
|
|
494
|
+
agent: { did: 'did:test:status', isInitialized: true, isUnlocked: false },
|
|
495
|
+
});
|
|
726
496
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
497
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
498
|
+
const received = callback.mock.calls[0][0];
|
|
499
|
+
expect(received.did).toBe('did:test:status');
|
|
500
|
+
expect(received.isUnlocked).toBe(false);
|
|
501
|
+
expect(received).not.toHaveProperty('type');
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
// ===================== PERSPECTIVE TESTS =====================
|
|
506
|
+
describe('PerspectiveClient', () => {
|
|
507
|
+
test('all() returns perspective proxies', async () => {
|
|
508
|
+
const perspectives = await ad4m.perspective.all();
|
|
509
|
+
expect(perspectives).toHaveLength(1);
|
|
510
|
+
expect(perspectives[0].uuid).toBe('uuid-1');
|
|
511
|
+
});
|
|
732
512
|
|
|
733
|
-
|
|
734
|
-
|
|
513
|
+
test('byUUID() returns a perspective proxy', async () => {
|
|
514
|
+
const p = await ad4m.perspective.byUUID('uuid-1');
|
|
515
|
+
expect(p).not.toBeNull();
|
|
516
|
+
expect(p!.uuid).toBe('uuid-1');
|
|
517
|
+
});
|
|
735
518
|
|
|
736
|
-
|
|
519
|
+
test('snapshotByUUID() returns snapshot', async () => {
|
|
520
|
+
const snapshot = await ad4m.perspective.snapshotByUUID('uuid-1');
|
|
521
|
+
expect(snapshot).not.toBeNull();
|
|
522
|
+
expect(snapshot!.links).toHaveLength(1);
|
|
523
|
+
});
|
|
737
524
|
|
|
738
|
-
|
|
739
|
-
|
|
525
|
+
test('add() creates a new perspective', async () => {
|
|
526
|
+
const p = await ad4m.perspective.add('new-perspective');
|
|
527
|
+
expect(lastRpcCall!.params.name).toBe('new-perspective');
|
|
528
|
+
expect(p.uuid).toBe('uuid-new');
|
|
529
|
+
});
|
|
740
530
|
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
531
|
+
test('update() updates a perspective name', async () => {
|
|
532
|
+
const p = await ad4m.perspective.update('uuid-1', 'renamed');
|
|
533
|
+
expect(lastRpcCall!.params.name).toBe('renamed');
|
|
534
|
+
expect(p.name).toBe('renamed');
|
|
535
|
+
});
|
|
744
536
|
|
|
745
|
-
|
|
746
|
-
|
|
537
|
+
test('remove() deletes a perspective', async () => {
|
|
538
|
+
const result = await ad4m.perspective.remove('uuid-1');
|
|
539
|
+
expect(result.perspectiveRemove).toBe(true);
|
|
540
|
+
});
|
|
747
541
|
|
|
748
|
-
|
|
542
|
+
test('queryLinks() queries links with parameters', async () => {
|
|
543
|
+
const links = await ad4m.perspective.queryLinks('uuid-1', new LinkQuery({ source: 'src', predicate: 'pred' }));
|
|
544
|
+
expect(links).toHaveLength(1);
|
|
545
|
+
expect(lastRpcCall!.params.source).toBe('src');
|
|
546
|
+
expect(lastRpcCall!.params.predicate).toBe('pred');
|
|
547
|
+
});
|
|
749
548
|
|
|
750
|
-
|
|
751
|
-
|
|
549
|
+
test('addLink() adds a link', async () => {
|
|
550
|
+
const link = await ad4m.perspective.addLink('uuid-1', { source: 's', predicate: 'p', target: 't' });
|
|
551
|
+
expect(link.data.source).toBe('s');
|
|
552
|
+
expect(lastRpcCall!.params.link).toEqual({ source: 's', predicate: 'p', target: 't' });
|
|
553
|
+
});
|
|
752
554
|
|
|
753
|
-
|
|
555
|
+
test('addLinks() adds multiple links', async () => {
|
|
556
|
+
const links = await ad4m.perspective.addLinks('uuid-1', [
|
|
557
|
+
{ source: 's1', predicate: 'p', target: 't1' },
|
|
558
|
+
{ source: 's2', predicate: 'p', target: 't2' },
|
|
559
|
+
]);
|
|
560
|
+
expect(links).toHaveLength(1);
|
|
561
|
+
expect(lastRpcCall!.params.links).toHaveLength(2);
|
|
562
|
+
});
|
|
754
563
|
|
|
755
|
-
|
|
564
|
+
test('removeLinks() forwards batchId in the bulk remove request', async () => {
|
|
565
|
+
const removed = await ad4m.perspective.removeLinks('uuid-1', [{
|
|
566
|
+
author: 'a', timestamp: 't',
|
|
567
|
+
data: { source: 's', predicate: 'p', target: 't' },
|
|
568
|
+
proof: { valid: true },
|
|
569
|
+
}] as any, 'batch-id-1');
|
|
570
|
+
expect(removed).toHaveLength(0);
|
|
571
|
+
expect(lastRpcCall!.type).toBe('perspective.removeLinks');
|
|
572
|
+
expect(lastRpcCall!.params.links).toHaveLength(1);
|
|
573
|
+
expect(lastRpcCall!.params.batchId).toBe('batch-id-1');
|
|
574
|
+
});
|
|
756
575
|
|
|
757
|
-
|
|
576
|
+
test('updateLink() updates a link', async () => {
|
|
577
|
+
const link = await ad4m.perspective.updateLink('uuid-1',
|
|
578
|
+
{ author: 'a', timestamp: 't', data: { source: 's', predicate: 'p', target: 't' }, proof: { valid: true } } as any,
|
|
579
|
+
{ source: 'new-s', predicate: 'p', target: 't' },
|
|
580
|
+
);
|
|
581
|
+
expect(link.data.source).toBe('new-s');
|
|
582
|
+
});
|
|
758
583
|
|
|
759
|
-
|
|
760
|
-
|
|
584
|
+
test('removeLink() removes a link', async () => {
|
|
585
|
+
const result = await ad4m.perspective.removeLink('uuid-1', {
|
|
586
|
+
author: 'a', timestamp: 't',
|
|
587
|
+
data: { source: 's', predicate: 'p', target: 't' },
|
|
588
|
+
proof: { valid: true },
|
|
589
|
+
} as any);
|
|
590
|
+
expect(result).toBe(true);
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
test('linkMutations() applies mutations', async () => {
|
|
594
|
+
const result = await ad4m.perspective.linkMutations('uuid-1', {
|
|
595
|
+
additions: [{ source: 'a', predicate: 'p', target: 't' }],
|
|
596
|
+
removals: [],
|
|
597
|
+
});
|
|
598
|
+
expect(result.additions).toHaveLength(1);
|
|
599
|
+
});
|
|
761
600
|
|
|
762
|
-
|
|
763
|
-
|
|
601
|
+
test('addSdna() adds SDNA', async () => {
|
|
602
|
+
const result = await ad4m.perspective.addSdna('uuid-1', 'TestClass', 'code', 'subject_class');
|
|
603
|
+
expect(result).toBe(true);
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
test('queryProlog() runs prolog query', async () => {
|
|
607
|
+
const result = await ad4m.perspective.queryProlog('uuid-1', 'test(X)');
|
|
608
|
+
expect(result).toEqual([{ X: 'test' }]);
|
|
609
|
+
});
|
|
764
610
|
|
|
765
|
-
|
|
766
|
-
|
|
611
|
+
test('subscribeToQueryUpdates() routes through the WebSocket endpoint', async () => {
|
|
612
|
+
const freshClient = new Ad4mClient('http://127.0.0.1:12000', 'test-token', false);
|
|
613
|
+
const callback = jest.fn();
|
|
614
|
+
const unsubscribe = freshClient.perspective.subscribeToQueryUpdates('sub-1', callback);
|
|
615
|
+
const ws = lastOf(MockWebSocket.instances);
|
|
767
616
|
|
|
768
|
-
|
|
617
|
+
expect(ws.url).toBe('ws://127.0.0.1:12000/api/v1/ws?token=test-token');
|
|
769
618
|
|
|
770
|
-
|
|
771
|
-
|
|
619
|
+
unsubscribe();
|
|
620
|
+
expect(ws.closed).toBe(true);
|
|
621
|
+
});
|
|
772
622
|
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
623
|
+
test('perspective lifecycle subscriptions use the WebSocket endpoint', async () => {
|
|
624
|
+
const freshClient = new Ad4mClient('http://127.0.0.1:12000', 'test-token', false);
|
|
625
|
+
freshClient.perspective.addPerspectiveAddedListener(jest.fn());
|
|
626
|
+
freshClient.perspective.subscribePerspectiveAdded();
|
|
776
627
|
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
{author: '', timestamp: '', proof: {signature: '', key: ''}, data:{source: 'root', target: 'none'}},
|
|
781
|
-
{source: 'root', target: 'lang://Qm123', predicate: 'p'})
|
|
782
|
-
expect(link.author).toBe('did:ad4m:test')
|
|
783
|
-
expect(link.data.source).toBe('root')
|
|
784
|
-
expect(link.data.predicate).toBe('p')
|
|
785
|
-
expect(link.data.target).toBe('lang://Qm123')
|
|
786
|
-
})
|
|
628
|
+
const ws = lastOf(MockWebSocket.instances);
|
|
629
|
+
expect(ws.url).toBe('ws://127.0.0.1:12000/api/v1/ws?token=test-token');
|
|
630
|
+
});
|
|
787
631
|
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
632
|
+
test('perspective-scoped link subscriptions ignore events for other perspectives', async () => {
|
|
633
|
+
const freshClient = new Ad4mClient('http://127.0.0.1:12000', 'test-token', false);
|
|
634
|
+
const linkAddedCallback = jest.fn();
|
|
635
|
+
const linkRemovedCallback = jest.fn();
|
|
636
|
+
const linkUpdatedCallback = jest.fn();
|
|
792
637
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
})
|
|
638
|
+
await freshClient.perspective.addPerspectiveLinkAddedListener('uuid-1', [linkAddedCallback]);
|
|
639
|
+
await freshClient.perspective.addPerspectiveLinkRemovedListener('uuid-1', [linkRemovedCallback]);
|
|
640
|
+
await freshClient.perspective.addPerspectiveLinkUpdatedListener('uuid-1', [linkUpdatedCallback]);
|
|
797
641
|
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
'00001',
|
|
801
|
-
'command1; command2',
|
|
802
|
-
'expression1',
|
|
803
|
-
'param1, param2'
|
|
804
|
-
);
|
|
805
|
-
expect(result).toBeTruthy();
|
|
806
|
-
})
|
|
642
|
+
const ws = lastOf(MockWebSocket.instances);
|
|
643
|
+
expect(ws.url).toBe('ws://127.0.0.1:12000/api/v1/ws?token=test-token');
|
|
807
644
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
645
|
+
// Events for a different perspective should be ignored
|
|
646
|
+
ws.emit({
|
|
647
|
+
type: 'link-added',
|
|
648
|
+
perspectiveUuid: 'uuid-2',
|
|
649
|
+
link: { author: 'did:test:123', timestamp: '2024-01-01T00:00:00.000Z', data: { source: 'test://other-added', predicate: 'test://has', target: 'test://value' }, proof: { valid: true } },
|
|
650
|
+
});
|
|
651
|
+
ws.emit({
|
|
652
|
+
type: 'link-removed',
|
|
653
|
+
perspectiveUuid: 'uuid-2',
|
|
654
|
+
link: { author: 'did:test:123', timestamp: '2024-01-01T00:00:00.000Z', data: { source: 'test://other-removed', predicate: 'test://has', target: 'test://value' }, proof: { valid: true } },
|
|
655
|
+
});
|
|
656
|
+
ws.emit({
|
|
657
|
+
type: 'link-updated',
|
|
658
|
+
perspectiveUuid: 'uuid-2',
|
|
659
|
+
oldLink: { author: 'did:test:123', timestamp: '2024-01-01T00:00:00.000Z', data: { source: 'test://other-old', predicate: 'test://has', target: 'test://value' }, proof: { valid: true } },
|
|
660
|
+
newLink: { author: 'did:test:123', timestamp: '2024-01-01T00:00:00.000Z', data: { source: 'test://other-new', predicate: 'test://has', target: 'test://value' }, proof: { valid: true } },
|
|
811
661
|
});
|
|
812
662
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
})
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
it('addTrustedAgents() smoke test', async () => {
|
|
835
|
-
const r = await ad4mClient.runtime.addTrustedAgents(["agentPubKey"]);
|
|
836
|
-
expect(r).toStrictEqual([ 'agentPubKey' ])
|
|
837
|
-
})
|
|
838
|
-
|
|
839
|
-
it('deleteTrustedAgents() smoke test', async () => {
|
|
840
|
-
const r = await ad4mClient.runtime.deleteTrustedAgents(["agentPubKey"]);
|
|
841
|
-
expect(r).toStrictEqual([])
|
|
842
|
-
})
|
|
843
|
-
|
|
844
|
-
it('getTrustedAgents() smoke test', async () => {
|
|
845
|
-
const r = await ad4mClient.runtime.getTrustedAgents();
|
|
846
|
-
expect(r).toStrictEqual([ 'agentPubKey' ])
|
|
847
|
-
})
|
|
848
|
-
|
|
849
|
-
it('addKnownLinkLanguageTemplates() smoke test', async () => {
|
|
850
|
-
const r = await ad4mClient.runtime.addKnownLinkLanguageTemplates(["Qm1337"]);
|
|
851
|
-
expect(r).toStrictEqual([ 'Qm1337' ])
|
|
852
|
-
})
|
|
853
|
-
|
|
854
|
-
it('removeKnownLinkLanguageTemplates() smoke test', async () => {
|
|
855
|
-
const r = await ad4mClient.runtime.removeKnownLinkLanguageTemplates(["Qm12345abcdef"]);
|
|
856
|
-
expect(r).toStrictEqual([])
|
|
857
|
-
})
|
|
858
|
-
|
|
859
|
-
it('knownLinkLanguageTemplates() smoke test', async () => {
|
|
860
|
-
const r = await ad4mClient.runtime.knownLinkLanguageTemplates();
|
|
861
|
-
expect(r).toStrictEqual([ 'Qm12345abcdef' ])
|
|
862
|
-
})
|
|
863
|
-
|
|
864
|
-
it('addFriends() smoke test', async () => {
|
|
865
|
-
const r = await ad4mClient.runtime.addFriends(["did:test:another_friend"]);
|
|
866
|
-
expect(r).toStrictEqual([ 'did:test:another_friend' ])
|
|
867
|
-
})
|
|
868
|
-
|
|
869
|
-
it('removeFriends() smoke test', async () => {
|
|
870
|
-
const r = await ad4mClient.runtime.removeFriends(["did:test:friend"]);
|
|
871
|
-
expect(r).toStrictEqual([])
|
|
872
|
-
})
|
|
873
|
-
|
|
874
|
-
it('friends() smoke test', async () => {
|
|
875
|
-
const r = await ad4mClient.runtime.friends();
|
|
876
|
-
expect(r).toStrictEqual([ 'did:test:friend' ])
|
|
877
|
-
})
|
|
878
|
-
|
|
879
|
-
it('hcAgentInfos smoke test', async () => {
|
|
880
|
-
const agentInfos = JSON.parse(await ad4mClient.runtime.hcAgentInfos())
|
|
881
|
-
expect(agentInfos.length).toBe(4)
|
|
882
|
-
expect(agentInfos[0].agent).toBeDefined()
|
|
883
|
-
expect(agentInfos[0].signature).toBeDefined()
|
|
884
|
-
expect(agentInfos[0].agent_info).toBeDefined()
|
|
885
|
-
})
|
|
886
|
-
|
|
887
|
-
it('hcAddAgentInfos smoke test', async () => {
|
|
888
|
-
await ad4mClient.runtime.hcAddAgentInfos("agent infos string")
|
|
889
|
-
})
|
|
890
|
-
|
|
891
|
-
it('ververifyStringSignedByDid() smoke test', async () => {
|
|
892
|
-
const verify = await ad4mClient.runtime.verifyStringSignedByDid("did", "didSigningKeyId", "data", "signedData")
|
|
893
|
-
expect(verify).toBe(true)
|
|
894
|
-
})
|
|
895
|
-
|
|
896
|
-
it('setStatus smoke test', async () => {
|
|
897
|
-
const link = new LinkExpression()
|
|
898
|
-
link.author = 'did:method:12345'
|
|
899
|
-
link.timestamp = new Date().toString()
|
|
900
|
-
link.data = new Link({source: 'root', target: 'perspective://Qm34589a3ccc0'})
|
|
901
|
-
link.proof = { signature: 'asdfasdf', key: 'asdfasdf' }
|
|
902
|
-
await ad4mClient.runtime.setStatus(new Perspective([link]))
|
|
903
|
-
})
|
|
904
|
-
|
|
905
|
-
it('friendStatus smoke test', async () => {
|
|
906
|
-
const statusExpr = await ad4mClient.runtime.friendStatus("did:ad4m:test")
|
|
907
|
-
expect(statusExpr.author).toBe("did:ad4m:test")
|
|
908
|
-
const statusPersp = statusExpr.data
|
|
909
|
-
expect(statusPersp.links.length).toBe(1)
|
|
910
|
-
expect(statusPersp.links[0].data.source).toBe('root')
|
|
911
|
-
expect(statusPersp.links[0].data.target).toBe('neighbourhood://Qm12345')
|
|
912
|
-
})
|
|
913
|
-
|
|
914
|
-
it('friendSendMessage smoke test', async () => {
|
|
915
|
-
const link = new LinkExpression()
|
|
916
|
-
link.author = 'did:method:12345'
|
|
917
|
-
link.timestamp = new Date().toString()
|
|
918
|
-
link.data = new Link({source: 'root', target: 'perspective://Qm34589a3ccc0'})
|
|
919
|
-
link.proof = { signature: 'asdfasdf', key: 'asdfasdf' }
|
|
920
|
-
await ad4mClient.runtime.friendSendMessage('did:ad4m:test', new Perspective([link]))
|
|
921
|
-
})
|
|
922
|
-
|
|
923
|
-
it('messageInbox smoke test', async () => {
|
|
924
|
-
const messages = await ad4mClient.runtime.messageInbox()
|
|
925
|
-
expect(messages.length).toBe(1)
|
|
926
|
-
const message = messages[0]
|
|
927
|
-
expect(message.author).toBe("did:ad4m:test")
|
|
928
|
-
const messagePersp = message.data
|
|
929
|
-
expect(messagePersp.links.length).toBe(1)
|
|
930
|
-
expect(messagePersp.links[0].data.source).toBe('root')
|
|
931
|
-
expect(messagePersp.links[0].data.target).toBe('neighbourhood://Qm12345')
|
|
932
|
-
})
|
|
933
|
-
|
|
934
|
-
it('messageOutbox smoke test', async () => {
|
|
935
|
-
const sentMessages = await ad4mClient.runtime.messageOutbox("did:ad4m:test")
|
|
936
|
-
expect(sentMessages.length).toBe(1)
|
|
937
|
-
const sentMessage = sentMessages[0]
|
|
938
|
-
expect(sentMessage.recipient).toBe("did:test:recipient")
|
|
939
|
-
const message = sentMessage.message
|
|
940
|
-
expect(message.author).toBe("did:ad4m:test")
|
|
941
|
-
const messagePersp = message.data
|
|
942
|
-
expect(messagePersp.links.length).toBe(1)
|
|
943
|
-
expect(messagePersp.links[0].data.source).toBe('root')
|
|
944
|
-
expect(messagePersp.links[0].data.target).toBe('neighbourhood://Qm12345')
|
|
945
|
-
})
|
|
946
|
-
|
|
947
|
-
it('runtimeInfo smoke test', async () => {
|
|
948
|
-
const runtimeInfo = await ad4mClient.runtime.info();
|
|
949
|
-
expect(runtimeInfo.ad4mExecutorVersion).toBe("x.x.x");
|
|
950
|
-
expect(runtimeInfo.isInitialized).toBe(true);
|
|
951
|
-
expect(runtimeInfo.isUnlocked).toBe(true);
|
|
952
|
-
})
|
|
953
|
-
|
|
954
|
-
it('requestInstallNotification smoke test', async () => {
|
|
955
|
-
await ad4mClient.runtime.requestInstallNotification({
|
|
956
|
-
description: "Test description",
|
|
957
|
-
appName: "Test app name",
|
|
958
|
-
appUrl: "https://example.com",
|
|
959
|
-
appIconPath: "https://example.com/icon",
|
|
960
|
-
trigger: "triple(X, ad4m://has_type, flux://message)",
|
|
961
|
-
perspectiveIds: ["u983ud-jdhh38d"],
|
|
962
|
-
webhookUrl: "https://example.com/webhook",
|
|
963
|
-
webhookAuth: "test-auth",
|
|
964
|
-
});
|
|
965
|
-
})
|
|
966
|
-
|
|
967
|
-
it('grantNotification smoke test', async () => {
|
|
968
|
-
await ad4mClient.runtime.grantNotification("test-notification");
|
|
969
|
-
})
|
|
970
|
-
|
|
971
|
-
it('notifications smoke test', async () => {
|
|
972
|
-
const notifications = await ad4mClient.runtime.notifications();
|
|
973
|
-
expect(notifications.length).toBe(1);
|
|
974
|
-
})
|
|
975
|
-
|
|
976
|
-
it('updateNotification smoke test', async () => {
|
|
977
|
-
await ad4mClient.runtime.updateNotification("test-notification", {
|
|
978
|
-
description: "Test description",
|
|
979
|
-
appName: "Test app name",
|
|
980
|
-
appUrl: "https://example.com",
|
|
981
|
-
appIconPath: "https://example.com/icon",
|
|
982
|
-
trigger: "triple(X, ad4m://has_type, flux://message)",
|
|
983
|
-
perspectiveIds: ["u983ud-jdhh38d"],
|
|
984
|
-
webhookUrl: "https://example.com/webhook",
|
|
985
|
-
webhookAuth: "test-auth",
|
|
986
|
-
});
|
|
987
|
-
})
|
|
988
|
-
|
|
989
|
-
it('removeNotification smoke test', async () => {
|
|
990
|
-
await ad4mClient.runtime.removeNotification("test-notification");
|
|
991
|
-
})
|
|
992
|
-
})
|
|
993
|
-
|
|
994
|
-
describe('Ad4mClient subscriptions', () => {
|
|
995
|
-
describe('ad4mClient without subscription', () => {
|
|
996
|
-
let ad4mClientWithoutSubscription: Ad4mClient
|
|
997
|
-
|
|
998
|
-
beforeEach(() => {
|
|
999
|
-
ad4mClientWithoutSubscription = new Ad4mClient(apolloClient, false)
|
|
1000
|
-
})
|
|
1001
|
-
|
|
1002
|
-
it('agent subscribeAgentUpdated smoke test', async () => {
|
|
1003
|
-
const agentUpdatedCallback = jest.fn()
|
|
1004
|
-
ad4mClientWithoutSubscription.agent.addUpdatedListener(agentUpdatedCallback)
|
|
1005
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1006
|
-
expect(agentUpdatedCallback).toBeCalledTimes(0)
|
|
1007
|
-
|
|
1008
|
-
ad4mClientWithoutSubscription.agent.subscribeAgentUpdated()
|
|
1009
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1010
|
-
await ad4mClientWithoutSubscription.agent.updateDirectMessageLanguage("lang://test");
|
|
1011
|
-
expect(agentUpdatedCallback).toBeCalledTimes(1)
|
|
1012
|
-
})
|
|
1013
|
-
|
|
1014
|
-
it('agent subscribeAgentStatusChanged smoke test', async () => {
|
|
1015
|
-
const agentStatusChangedCallback = jest.fn()
|
|
1016
|
-
ad4mClientWithoutSubscription.agent.addAgentStatusChangedListener(agentStatusChangedCallback)
|
|
1017
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1018
|
-
expect(agentStatusChangedCallback).toBeCalledTimes(0)
|
|
1019
|
-
|
|
1020
|
-
ad4mClientWithoutSubscription.agent.subscribeAgentStatusChanged()
|
|
1021
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1022
|
-
await ad4mClientWithoutSubscription.agent.unlock("test", false);
|
|
1023
|
-
expect(agentStatusChangedCallback).toBeCalledTimes(1)
|
|
1024
|
-
})
|
|
1025
|
-
|
|
1026
|
-
it('agent subscribeAppsChanged smoke test', async () => {
|
|
1027
|
-
const appsChangedCallback = jest.fn()
|
|
1028
|
-
ad4mClientWithoutSubscription.agent.addAppChangedListener(appsChangedCallback)
|
|
1029
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1030
|
-
expect(appsChangedCallback).toBeCalledTimes(0)
|
|
1031
|
-
|
|
1032
|
-
ad4mClientWithoutSubscription.agent.subscribeAppsChanged()
|
|
1033
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1034
|
-
await ad4mClientWithoutSubscription.agent.removeApp("test");
|
|
1035
|
-
expect(appsChangedCallback).toBeCalledTimes(1)
|
|
1036
|
-
})
|
|
1037
|
-
|
|
1038
|
-
it('perspective subscribePerspectiveAdded smoke test', async () => {
|
|
1039
|
-
const perspectiveAddedCallback = jest.fn()
|
|
1040
|
-
ad4mClientWithoutSubscription.perspective.addPerspectiveAddedListener(perspectiveAddedCallback)
|
|
1041
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1042
|
-
expect(perspectiveAddedCallback).toBeCalledTimes(0)
|
|
1043
|
-
|
|
1044
|
-
ad4mClientWithoutSubscription.perspective.subscribePerspectiveAdded()
|
|
1045
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1046
|
-
await ad4mClientWithoutSubscription.perspective.add('p-name-1');
|
|
1047
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1048
|
-
expect(perspectiveAddedCallback).toBeCalledTimes(1)
|
|
1049
|
-
})
|
|
1050
|
-
|
|
1051
|
-
it('perspective subscribePerspectiveUpdated smoke test', async () => {
|
|
1052
|
-
const perspectiveUpdatedCallback = jest.fn()
|
|
1053
|
-
ad4mClientWithoutSubscription.perspective.addPerspectiveUpdatedListener(perspectiveUpdatedCallback)
|
|
1054
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1055
|
-
expect(perspectiveUpdatedCallback).toBeCalledTimes(0)
|
|
1056
|
-
|
|
1057
|
-
ad4mClientWithoutSubscription.perspective.subscribePerspectiveUpdated()
|
|
1058
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1059
|
-
await ad4mClientWithoutSubscription.perspective.update('00006', 'p-test2');
|
|
1060
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1061
|
-
expect(perspectiveUpdatedCallback).toBeCalledTimes(1)
|
|
1062
|
-
})
|
|
1063
|
-
|
|
1064
|
-
it('perspective subscribePerspectiveRemoved smoke test', async () => {
|
|
1065
|
-
const perspectiveRemovedCallback = jest.fn()
|
|
1066
|
-
ad4mClientWithoutSubscription.perspective.addPerspectiveRemovedListener(perspectiveRemovedCallback)
|
|
1067
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1068
|
-
expect(perspectiveRemovedCallback).toBeCalledTimes(0)
|
|
1069
|
-
|
|
1070
|
-
ad4mClientWithoutSubscription.perspective.subscribePerspectiveRemoved()
|
|
1071
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1072
|
-
await ad4mClientWithoutSubscription.perspective.remove('00006');
|
|
1073
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1074
|
-
expect(perspectiveRemovedCallback).toBeCalledTimes(1)
|
|
1075
|
-
})
|
|
1076
|
-
})
|
|
1077
|
-
|
|
1078
|
-
describe('ad4mClient with subscription', () => {
|
|
1079
|
-
let ad4mClientWithSubscription
|
|
1080
|
-
|
|
1081
|
-
beforeEach(() => {
|
|
1082
|
-
ad4mClientWithSubscription = new Ad4mClient(apolloClient, true)
|
|
1083
|
-
})
|
|
1084
|
-
|
|
1085
|
-
it('agent subscribeAgentUpdated smoke test', async () => {
|
|
1086
|
-
const agentUpdatedCallback = jest.fn()
|
|
1087
|
-
ad4mClientWithSubscription.agent.addUpdatedListener(agentUpdatedCallback)
|
|
1088
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1089
|
-
expect(agentUpdatedCallback).toBeCalledTimes(0)
|
|
1090
|
-
|
|
1091
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1092
|
-
await ad4mClientWithSubscription.agent.updateDirectMessageLanguage("lang://test");
|
|
1093
|
-
expect(agentUpdatedCallback).toBeCalledTimes(1)
|
|
1094
|
-
})
|
|
1095
|
-
|
|
1096
|
-
it('agent subscribeAgentStatusChanged smoke test', async () => {
|
|
1097
|
-
const agentStatusChangedCallback = jest.fn()
|
|
1098
|
-
ad4mClientWithSubscription.agent.addAgentStatusChangedListener(agentStatusChangedCallback)
|
|
1099
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1100
|
-
expect(agentStatusChangedCallback).toBeCalledTimes(0)
|
|
1101
|
-
|
|
1102
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1103
|
-
await ad4mClientWithSubscription.agent.unlock("test", false);
|
|
1104
|
-
expect(agentStatusChangedCallback).toBeCalledTimes(1)
|
|
1105
|
-
})
|
|
1106
|
-
|
|
1107
|
-
it('agent subscribeAppsChanged smoke test', async () => {
|
|
1108
|
-
const appsChangedCallback = jest.fn()
|
|
1109
|
-
ad4mClientWithSubscription.agent.addAppChangedListener(appsChangedCallback)
|
|
1110
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1111
|
-
expect(appsChangedCallback).toBeCalledTimes(0)
|
|
1112
|
-
|
|
1113
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1114
|
-
await ad4mClientWithSubscription.agent.removeApp("test");
|
|
1115
|
-
expect(appsChangedCallback).toBeCalledTimes(1)
|
|
1116
|
-
})
|
|
1117
|
-
|
|
1118
|
-
it('perspective subscribePerspectiveAdded smoke test', async () => {
|
|
1119
|
-
const perspectiveAddedCallback = jest.fn()
|
|
1120
|
-
ad4mClientWithSubscription.perspective.addPerspectiveAddedListener(perspectiveAddedCallback)
|
|
1121
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1122
|
-
expect(perspectiveAddedCallback).toBeCalledTimes(0)
|
|
1123
|
-
|
|
1124
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1125
|
-
await ad4mClientWithSubscription.perspective.add('p-name-1');
|
|
1126
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1127
|
-
expect(perspectiveAddedCallback).toBeCalledTimes(1)
|
|
1128
|
-
})
|
|
1129
|
-
|
|
1130
|
-
it('perspective subscribePerspectiveUpdated smoke test', async () => {
|
|
1131
|
-
const perspectiveUpdatedCallback = jest.fn()
|
|
1132
|
-
ad4mClientWithSubscription.perspective.addPerspectiveUpdatedListener(perspectiveUpdatedCallback)
|
|
1133
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1134
|
-
expect(perspectiveUpdatedCallback).toBeCalledTimes(0)
|
|
1135
|
-
|
|
1136
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1137
|
-
await ad4mClientWithSubscription.perspective.update('00006', 'p-test2');
|
|
1138
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1139
|
-
expect(perspectiveUpdatedCallback).toBeCalledTimes(1)
|
|
1140
|
-
})
|
|
1141
|
-
|
|
1142
|
-
it('perspective subscribePerspectiveRemoved smoke test', async () => {
|
|
1143
|
-
const perspectiveRemovedCallback = jest.fn()
|
|
1144
|
-
ad4mClientWithSubscription.perspective.addPerspectiveRemovedListener(perspectiveRemovedCallback)
|
|
1145
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1146
|
-
expect(perspectiveRemovedCallback).toBeCalledTimes(0)
|
|
1147
|
-
|
|
1148
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1149
|
-
await ad4mClientWithSubscription.perspective.remove('00006');
|
|
1150
|
-
await new Promise<void>(resolve => setTimeout(resolve, 100))
|
|
1151
|
-
expect(perspectiveRemovedCallback).toBeCalledTimes(1)
|
|
1152
|
-
})
|
|
1153
|
-
})
|
|
1154
|
-
})
|
|
1155
|
-
describe('.ai', () => {
|
|
1156
|
-
it('getModels smoke test', async () => {
|
|
1157
|
-
const models = await ad4mClient.ai.getModels();
|
|
1158
|
-
expect(models).toBeDefined();
|
|
1159
|
-
expect(Array.isArray(models)).toBe(true);
|
|
1160
|
-
if (models.length > 0) {
|
|
1161
|
-
const model = models[0];
|
|
1162
|
-
expect(model).toHaveProperty('name');
|
|
1163
|
-
expect(model).toHaveProperty('id');
|
|
1164
|
-
expect(model).toHaveProperty('modelType');
|
|
1165
|
-
if (model.api) {
|
|
1166
|
-
expect(model.api).toHaveProperty('baseUrl');
|
|
1167
|
-
expect(model.api).toHaveProperty('apiKey');
|
|
1168
|
-
expect(model.api).toHaveProperty('model');
|
|
1169
|
-
expect(model.api).toHaveProperty('apiType');
|
|
1170
|
-
}
|
|
1171
|
-
if (model.local) {
|
|
1172
|
-
expect(model.local).toHaveProperty('fileName');
|
|
1173
|
-
if (model.local.tokenizerSource) {
|
|
1174
|
-
expect(model.local.tokenizerSource).toHaveProperty('repo');
|
|
1175
|
-
expect(model.local.tokenizerSource).toHaveProperty('revision');
|
|
1176
|
-
expect(model.local.tokenizerSource).toHaveProperty('fileName');
|
|
1177
|
-
}
|
|
1178
|
-
expect(model.local).toHaveProperty('huggingfaceRepo');
|
|
1179
|
-
expect(model.local).toHaveProperty('revision');
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
})
|
|
1183
|
-
|
|
1184
|
-
it('addModel smoke test', async () => {
|
|
1185
|
-
const newModel = {
|
|
1186
|
-
name: "New Test Model",
|
|
1187
|
-
api: {
|
|
1188
|
-
baseUrl: "https://api.newexample.com",
|
|
1189
|
-
apiKey: "new-test-api-key",
|
|
1190
|
-
apiType: "OpenAi",
|
|
1191
|
-
model: "gpt-4o"
|
|
1192
|
-
},
|
|
1193
|
-
local: {
|
|
1194
|
-
fileName: "new-test-model.bin",
|
|
1195
|
-
tokenizerSource: {
|
|
1196
|
-
repo: "test-repo",
|
|
1197
|
-
revision: "main",
|
|
1198
|
-
fileName: "tokenizer.json"
|
|
1199
|
-
},
|
|
1200
|
-
huggingfaceRepo: "test-repo",
|
|
1201
|
-
revision: "main"
|
|
1202
|
-
},
|
|
1203
|
-
modelType: "LLM"
|
|
1204
|
-
};
|
|
1205
|
-
const result = await ad4mClient.ai.addModel(newModel);
|
|
1206
|
-
expect(result).toBe("new-model-id");
|
|
1207
|
-
})
|
|
1208
|
-
|
|
1209
|
-
it('updateModel smoke test', async () => {
|
|
1210
|
-
const modelId = "test-model-id";
|
|
1211
|
-
const updatedModel = {
|
|
1212
|
-
name: "Updated Test Model",
|
|
1213
|
-
api: {
|
|
1214
|
-
baseUrl: "https://api.updatedexample.com",
|
|
1215
|
-
apiKey: "updated-test-api-key",
|
|
1216
|
-
apiType: "OpenAi",
|
|
1217
|
-
model: "gpt-4o"
|
|
1218
|
-
},
|
|
1219
|
-
local: {
|
|
1220
|
-
fileName: "updated-test-model.bin",
|
|
1221
|
-
tokenizerSource: {
|
|
1222
|
-
repo: "test-repo",
|
|
1223
|
-
revision: "main",
|
|
1224
|
-
fileName: "tokenizer.json"
|
|
1225
|
-
},
|
|
1226
|
-
huggingfaceRepo: "test-repo",
|
|
1227
|
-
revision: "main"
|
|
1228
|
-
},
|
|
1229
|
-
modelType: "LLM"
|
|
1230
|
-
};
|
|
1231
|
-
const result = await ad4mClient.ai.updateModel(modelId, updatedModel);
|
|
1232
|
-
expect(result).toBe(true);
|
|
1233
|
-
})
|
|
1234
|
-
|
|
1235
|
-
it('removeModel smoke test', async () => {
|
|
1236
|
-
const modelName = "Test Model to Remove";
|
|
1237
|
-
const result = await ad4mClient.ai.removeModel(modelName);
|
|
1238
|
-
expect(result).toBe(true);
|
|
1239
|
-
})
|
|
1240
|
-
|
|
1241
|
-
// skip this because ModelType is a string enum that can't be annotated for
|
|
1242
|
-
// TypeGraphQL without changing it to a real enum.
|
|
1243
|
-
// This all works with the Rust resolvers in AD4M,
|
|
1244
|
-
// as the intergration tests demonstrate.
|
|
1245
|
-
it.skip('setDefaultModel and getDefaultModel smoke test', async () => {
|
|
1246
|
-
const modelName = "Test Model";
|
|
1247
|
-
const modelType = "LLM";
|
|
1248
|
-
|
|
1249
|
-
const setResult = await ad4mClient.ai.setDefaultModel(modelType, modelName);
|
|
1250
|
-
expect(setResult).toBe(true);
|
|
1251
|
-
|
|
1252
|
-
const defaultModel = await ad4mClient.ai.getDefaultModel(modelType);
|
|
1253
|
-
expect(defaultModel).toBeDefined();
|
|
1254
|
-
expect(defaultModel.name).toBe("Default Test Model");
|
|
1255
|
-
expect(defaultModel.api).toBeDefined();
|
|
1256
|
-
expect(defaultModel.api.baseUrl).toBe("https://api.example.com");
|
|
1257
|
-
expect(defaultModel.api.apiKey).toBe("test-api-key");
|
|
1258
|
-
expect(defaultModel.api.apiType).toBe("OpenAi");
|
|
1259
|
-
expect(defaultModel.local).toBeDefined();
|
|
1260
|
-
expect(defaultModel.local.fileName).toBe("test-model.bin");
|
|
1261
|
-
if (defaultModel.local.tokenizerSource) {
|
|
1262
|
-
expect(defaultModel.local.tokenizerSource.repo).toBe("test-repo");
|
|
1263
|
-
expect(defaultModel.local.tokenizerSource.revision).toBe("main");
|
|
1264
|
-
expect(defaultModel.local.tokenizerSource.fileName).toBe("tokenizer.json");
|
|
1265
|
-
}
|
|
1266
|
-
expect(defaultModel.local.huggingfaceRepo).toBe("test-repo");
|
|
1267
|
-
expect(defaultModel.local.revision).toBe("main");
|
|
1268
|
-
expect(defaultModel.modelType).toBe(modelType);
|
|
1269
|
-
})
|
|
1270
|
-
|
|
1271
|
-
it('embed()', async () => {
|
|
1272
|
-
const vector = await ad4mClient.ai.embed("model", "test ets")
|
|
1273
|
-
expect(vector[0]).toEqual(0)
|
|
1274
|
-
expect(vector[1]).toEqual(10)
|
|
1275
|
-
expect(vector[2]).toEqual(20)
|
|
1276
|
-
expect(vector[3]).toEqual(30)
|
|
1277
|
-
})
|
|
1278
|
-
|
|
1279
|
-
it('tasks()', async () => {
|
|
1280
|
-
const tasks = await ad4mClient.ai.tasks()
|
|
1281
|
-
expect(tasks.length).toBe(2)
|
|
1282
|
-
expect(tasks[0].taskId).toBe("task_id")
|
|
1283
|
-
expect(tasks[0].modelId).toBe("modelId")
|
|
1284
|
-
})
|
|
1285
|
-
|
|
1286
|
-
it('addTask()', async () => {
|
|
1287
|
-
const task = await ad4mClient.ai.addTask("task_name", "model_id", "system prompt", []);
|
|
1288
|
-
expect(task.name).toBe("task_name")
|
|
1289
|
-
expect(task.taskId).toBe("task_id")
|
|
1290
|
-
expect(task.modelId).toBe("model_id")
|
|
1291
|
-
expect(task.systemPrompt).toBe("system prompt")
|
|
663
|
+
expect(linkAddedCallback).not.toHaveBeenCalled();
|
|
664
|
+
expect(linkRemovedCallback).not.toHaveBeenCalled();
|
|
665
|
+
expect(linkUpdatedCallback).not.toHaveBeenCalled();
|
|
666
|
+
|
|
667
|
+
// Events for the correct perspective should fire
|
|
668
|
+
const addedLink = {
|
|
669
|
+
author: 'did:test:123', timestamp: '2024-01-01T00:00:00.000Z',
|
|
670
|
+
data: { source: 'test://added', predicate: 'test://has', target: 'test://value' }, proof: { valid: true },
|
|
671
|
+
};
|
|
672
|
+
const removedLink = {
|
|
673
|
+
author: 'did:test:123', timestamp: '2024-01-01T00:00:00.000Z',
|
|
674
|
+
data: { source: 'test://removed', predicate: 'test://has', target: 'test://value' }, proof: { valid: true },
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
ws.emit({ type: 'link-added', perspectiveUuid: 'uuid-1', link: addedLink });
|
|
678
|
+
ws.emit({ type: 'link-removed', perspectiveUuid: 'uuid-1', link: removedLink });
|
|
679
|
+
ws.emit({
|
|
680
|
+
type: 'link-updated',
|
|
681
|
+
perspectiveUuid: 'uuid-1',
|
|
682
|
+
oldLink: { author: 'did:test:123', timestamp: '2024-01-01T00:00:00.000Z', data: { source: 'test://updated-old', predicate: 'test://has', target: 'test://value' }, proof: { valid: true } },
|
|
683
|
+
newLink: { author: 'did:test:123', timestamp: '2024-01-01T00:00:00.000Z', data: { source: 'test://updated-new', predicate: 'test://has', target: 'test://value' }, proof: { valid: true } },
|
|
1292
684
|
});
|
|
1293
685
|
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
686
|
+
expect(linkAddedCallback).toHaveBeenCalledWith(addedLink);
|
|
687
|
+
expect(linkRemovedCallback).toHaveBeenCalledWith(removedLink);
|
|
688
|
+
expect(linkUpdatedCallback).toHaveBeenCalledTimes(1);
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
test('runtime exception subscriptions normalize PascalCase exception types', async () => {
|
|
692
|
+
const freshClient = new Ad4mClient('http://127.0.0.1:12000', 'test-token', false);
|
|
693
|
+
const callback = jest.fn(() => null);
|
|
694
|
+
freshClient.runtime.addExceptionCallback(callback);
|
|
695
|
+
freshClient.runtime.subscribeExceptionOccurred();
|
|
696
|
+
|
|
697
|
+
const ws = lastOf(MockWebSocket.instances);
|
|
698
|
+
ws.emit({
|
|
699
|
+
type: 'exception-occurred',
|
|
700
|
+
exception: {
|
|
701
|
+
title: 'Request to authenticate application',
|
|
702
|
+
message: 'demo-app is waiting for authentication',
|
|
703
|
+
type: 'CapabilityRequested',
|
|
704
|
+
addon: '{}',
|
|
705
|
+
},
|
|
1299
706
|
});
|
|
1300
707
|
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
promptExamples: []
|
|
1307
|
-
});
|
|
1308
|
-
expect(task.name).toBe("task_name")
|
|
1309
|
-
expect(task.taskId).toBe("task_id")
|
|
1310
|
-
expect(task.modelId).toBe("model_id")
|
|
1311
|
-
expect(task.systemPrompt).toBe("system prompt")
|
|
708
|
+
expect(callback).toHaveBeenCalledWith({
|
|
709
|
+
title: 'Request to authenticate application',
|
|
710
|
+
message: 'demo-app is waiting for authentication',
|
|
711
|
+
type: 'CAPABILITY_REQUESTED',
|
|
712
|
+
addon: '{}',
|
|
1312
713
|
});
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
test('subscribeToQueryUpdates() ignores unrelated events and accepts object results', async () => {
|
|
717
|
+
const freshClient = new Ad4mClient('http://127.0.0.1:12000', 'test-token', false);
|
|
718
|
+
const callback = jest.fn();
|
|
719
|
+
const unsubscribe = freshClient.perspective.subscribeToQueryUpdates('sub-1', callback);
|
|
720
|
+
const ws = lastOf(MockWebSocket.instances);
|
|
721
|
+
|
|
722
|
+
ws.emit({ type: 'perspective-added', perspective: { uuid: 'uuid-ignored' } });
|
|
723
|
+
ws.emit({ type: 'query-subscription-update', subscriptionId: 'sub-2', result: { ignored: true } });
|
|
724
|
+
expect(callback).not.toHaveBeenCalled();
|
|
725
|
+
|
|
726
|
+
ws.emit({
|
|
727
|
+
type: 'query-subscription-update',
|
|
728
|
+
subscriptionId: 'sub-1',
|
|
729
|
+
result: [{ id: 'community://1', name: 'REST Smoke Community' }],
|
|
730
|
+
});
|
|
731
|
+
expect(callback).toHaveBeenCalledWith([{ id: 'community://1', name: 'REST Smoke Community' }]);
|
|
1313
732
|
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
733
|
+
unsubscribe();
|
|
734
|
+
ws.emit({
|
|
735
|
+
type: 'query-subscription-update',
|
|
736
|
+
subscriptionId: 'sub-1',
|
|
737
|
+
result: [{ id: 'community://2', name: 'Should not arrive' }],
|
|
1317
738
|
});
|
|
739
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
test('publishSnapshotByUUID() publishes a snapshot', async () => {
|
|
743
|
+
const hash = await ad4m.perspective.publishSnapshotByUUID('uuid-1');
|
|
744
|
+
expect(hash).toBe('Qm123');
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
test('createBatch() creates a batch', async () => {
|
|
748
|
+
const batchId = await ad4m.perspective.createBatch('uuid-1');
|
|
749
|
+
expect(batchId).toBe('batch-id-1');
|
|
750
|
+
});
|
|
751
|
+
|
|
752
|
+
test('commitBatch() commits a batch', async () => {
|
|
753
|
+
const result = await ad4m.perspective.commitBatch('uuid-1', 'batch-id-1');
|
|
754
|
+
expect(result.additions).toEqual([]);
|
|
755
|
+
});
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
// ===================== LANGUAGE TESTS =====================
|
|
759
|
+
describe('LanguageClient', () => {
|
|
760
|
+
test('all() returns all languages', async () => {
|
|
761
|
+
const langs = await ad4m.languages.all();
|
|
762
|
+
expect(langs).toHaveLength(1);
|
|
763
|
+
expect(langs[0].name).toBe('test-lang');
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
test('byFilter() filters languages', async () => {
|
|
767
|
+
await ad4m.languages.byFilter('test');
|
|
768
|
+
expect(lastRpcCall!.params.filter).toBe('test');
|
|
769
|
+
});
|
|
770
|
+
|
|
771
|
+
test('byAddress() returns a language handle', async () => {
|
|
772
|
+
const lang = await ad4m.languages.byAddress('lang://test');
|
|
773
|
+
expect(lang.name).toBe('test-lang');
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
test('meta() returns language meta', async () => {
|
|
777
|
+
const meta = await ad4m.languages.meta('lang://test');
|
|
778
|
+
expect(meta.name).toBe('test-lang');
|
|
779
|
+
expect(meta.author).toBe('did:test:123');
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
test('source() returns source code', async () => {
|
|
783
|
+
const source = await ad4m.languages.source('lang://test');
|
|
784
|
+
expect(source).toBe('source-code-here');
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
test('writeSettings() writes language settings', async () => {
|
|
788
|
+
const result = await ad4m.languages.writeSettings('lang://test', '{"key":"value"}');
|
|
789
|
+
expect(result).toBe(true);
|
|
790
|
+
expect(lastRpcCall!.params.settings).toBe('{"key":"value"}');
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
test('applyTemplateAndPublish() applies a template', async () => {
|
|
794
|
+
const ref = await ad4m.languages.applyTemplateAndPublish('lang://source', '{"param":"value"}');
|
|
795
|
+
expect(ref.name).toBe('applied-lang');
|
|
796
|
+
expect(ref.address).toBe('lang://applied');
|
|
797
|
+
});
|
|
798
|
+
|
|
799
|
+
test('publish() publishes a language', async () => {
|
|
800
|
+
const meta = await ad4m.languages.publish('/path/to/lang', { name: 'my-lang', description: 'desc' } as any);
|
|
801
|
+
expect(meta.name).toBe('published-lang');
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
test('remove() removes a language', async () => {
|
|
805
|
+
const result = await ad4m.languages.remove('lang://test');
|
|
806
|
+
expect(result).toBe(true);
|
|
807
|
+
});
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
// ===================== NEIGHBOURHOOD TESTS =====================
|
|
811
|
+
describe('NeighbourhoodClient', () => {
|
|
812
|
+
test('publishFromPerspective() publishes a neighbourhood', async () => {
|
|
813
|
+
const url = await ad4m.neighbourhood.publishFromPerspective(
|
|
814
|
+
'uuid-1', 'lang://link', new Perspective(),
|
|
815
|
+
);
|
|
816
|
+
expect(url).toBe('neighbourhood://published');
|
|
817
|
+
expect(lastRpcCall!.params.perspectiveUUID).toBe('uuid-1');
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
test('joinFromUrl() joins a neighbourhood', async () => {
|
|
821
|
+
const handle = await ad4m.neighbourhood.joinFromUrl('neighbourhood://test');
|
|
822
|
+
expect(handle.uuid).toBe('uuid-joined');
|
|
823
|
+
expect(lastRpcCall!.params.url).toBe('neighbourhood://test');
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
test('otherAgents() returns other agents', async () => {
|
|
827
|
+
const agents = await ad4m.neighbourhood.otherAgents('uuid-1');
|
|
828
|
+
expect(agents).toEqual(['did:other:1', 'did:other:2']);
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
test('hasTelepresenceAdapter() checks adapter', async () => {
|
|
832
|
+
const has = await ad4m.neighbourhood.hasTelepresenceAdapter('uuid-1');
|
|
833
|
+
expect(has).toBe(true);
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
test('onlineAgents() returns online agents', async () => {
|
|
837
|
+
const agents = await ad4m.neighbourhood.onlineAgents('uuid-1');
|
|
838
|
+
expect(agents).toHaveLength(1);
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
test('setOnlineStatus() sets status', async () => {
|
|
842
|
+
const result = await ad4m.neighbourhood.setOnlineStatus('uuid-1', new Perspective());
|
|
843
|
+
expect(result).toBe(true);
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
test('sendSignal() sends a signal', async () => {
|
|
847
|
+
const result = await ad4m.neighbourhood.sendSignal('uuid-1', 'did:other:1', new Perspective());
|
|
848
|
+
expect(result).toBe(true);
|
|
849
|
+
expect(lastRpcCall!.params.remoteAgentDid).toBe('did:other:1');
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
test('sendBroadcast() sends a broadcast', async () => {
|
|
853
|
+
const result = await ad4m.neighbourhood.sendBroadcast('uuid-1', new Perspective(), true);
|
|
854
|
+
expect(result).toBe(true);
|
|
855
|
+
expect(lastRpcCall!.params.loopback).toBe(true);
|
|
856
|
+
});
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
// ===================== EXPRESSION TESTS =====================
|
|
860
|
+
describe('ExpressionClient', () => {
|
|
861
|
+
test('get() returns an expression', async () => {
|
|
862
|
+
const expr = await ad4m.expression.get('lang://test/Qm123');
|
|
863
|
+
expect(expr.author).toBe('did:test:123');
|
|
864
|
+
});
|
|
865
|
+
|
|
866
|
+
test('getMany() returns multiple expressions', async () => {
|
|
867
|
+
const exprs = await ad4m.expression.getMany(['url1', 'url2']);
|
|
868
|
+
expect(exprs).toHaveLength(2);
|
|
869
|
+
expect(exprs[0].author).toBe('did:test:1');
|
|
870
|
+
expect(exprs[1].author).toBe('did:test:1');
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
test('getRaw() returns raw expression', async () => {
|
|
874
|
+
const raw = await ad4m.expression.getRaw('lang://test/Qm123');
|
|
875
|
+
expect(raw).toBe('raw-expression-data');
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
test('create() creates an expression', async () => {
|
|
879
|
+
const hash = await ad4m.expression.create({ content: 'hello' }, 'lang://test');
|
|
880
|
+
expect(hash).toBe('Qm-expression-hash');
|
|
881
|
+
expect(lastRpcCall!.params.languageAddress).toBe('lang://test');
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
test('interactions() returns interaction meta', async () => {
|
|
885
|
+
const interactions = await ad4m.expression.interactions('lang://test/Qm123');
|
|
886
|
+
expect(interactions).toHaveLength(1);
|
|
887
|
+
expect(interactions[0].label).toBe('interact1');
|
|
888
|
+
});
|
|
889
|
+
|
|
890
|
+
test('interact() calls an interaction', async () => {
|
|
891
|
+
const result = await ad4m.expression.interact('lang://test/Qm123', { name: 'doSomething', parameters: {} } as any);
|
|
892
|
+
expect(result).toBe('interaction-result');
|
|
893
|
+
});
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
// ===================== RUNTIME TESTS =====================
|
|
897
|
+
describe('RuntimeClient', () => {
|
|
898
|
+
test('info() returns runtime info', async () => {
|
|
899
|
+
const info = await ad4m.runtime.info();
|
|
900
|
+
expect(info.ad4mExecutorVersion).toBe('0.1.0');
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
test('tlsDomain() returns TLS domain', async () => {
|
|
904
|
+
const domain = await ad4m.runtime.tlsDomain();
|
|
905
|
+
expect(domain).toBe('test.domain.com');
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
test('quit() quits the runtime', async () => {
|
|
909
|
+
const result = await ad4m.runtime.quit();
|
|
910
|
+
expect(result).toBe(true);
|
|
911
|
+
});
|
|
912
|
+
|
|
913
|
+
test('friends() returns friends list', async () => {
|
|
914
|
+
const friends = await ad4m.runtime.friends();
|
|
915
|
+
expect(friends).toEqual(['did:friend:1', 'did:friend:2']);
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
test('addFriends() adds friends', async () => {
|
|
919
|
+
const result = await ad4m.runtime.addFriends(['did:friend:3']);
|
|
920
|
+
expect(result).toHaveLength(3);
|
|
921
|
+
expect(lastRpcCall!.params.dids).toEqual(['did:friend:3']);
|
|
922
|
+
});
|
|
923
|
+
|
|
924
|
+
test('removeFriends() removes friends', async () => {
|
|
925
|
+
const result = await ad4m.runtime.removeFriends(['did:friend:2']);
|
|
926
|
+
expect(result).toEqual(['did:friend:1']);
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
test('getTrustedAgents() returns trusted agents', async () => {
|
|
930
|
+
const agents = await ad4m.runtime.getTrustedAgents();
|
|
931
|
+
expect(agents).toEqual(['did:trusted:1']);
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
test('addTrustedAgents() adds trusted agents', async () => {
|
|
935
|
+
const result = await ad4m.runtime.addTrustedAgents(['did:trusted:2']);
|
|
936
|
+
expect(result).toHaveLength(2);
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
test('deleteTrustedAgents() removes trusted agents', async () => {
|
|
940
|
+
const result = await ad4m.runtime.deleteTrustedAgents(['did:trusted:2']);
|
|
941
|
+
expect(result).toEqual(['did:trusted:1']);
|
|
942
|
+
});
|
|
943
|
+
|
|
944
|
+
test('knownLinkLanguageTemplates() returns templates', async () => {
|
|
945
|
+
const templates = await ad4m.runtime.knownLinkLanguageTemplates();
|
|
946
|
+
expect(templates).toEqual(['lang://template1']);
|
|
947
|
+
});
|
|
1318
948
|
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
949
|
+
test('hcAgentInfos() returns agent infos list', async () => {
|
|
950
|
+
const infos = await ad4m.runtime.hcAgentInfos();
|
|
951
|
+
expect(infos).toEqual(['hc-agent-info-1', 'hc-agent-info-2']);
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
test('hcAddAgentInfos() sends array payload and returns boolean', async () => {
|
|
955
|
+
const result = await ad4m.runtime.hcAddAgentInfos(['hc-agent-info-1', 'hc-agent-info-2']);
|
|
956
|
+
expect(result).toBe(true);
|
|
957
|
+
expect(lastRpcCall!.params.agentInfos).toEqual(['hc-agent-info-1', 'hc-agent-info-2']);
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
test('verifyStringSignedByDid() verifies signature', async () => {
|
|
961
|
+
const result = await ad4m.runtime.verifyStringSignedByDid('did:test:1', 'key-1', 'data', 'signed');
|
|
962
|
+
expect(result).toBe(true);
|
|
963
|
+
expect(lastRpcCall!.params.did).toBe('did:test:1');
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
test('friendStatus() gets friend status', async () => {
|
|
967
|
+
const status = await ad4m.runtime.friendStatus('did:friend:1');
|
|
968
|
+
expect(status.author).toBe('did:friend:1');
|
|
969
|
+
});
|
|
970
|
+
|
|
971
|
+
test('friendSendMessage() sends a message', async () => {
|
|
972
|
+
const result = await ad4m.runtime.friendSendMessage('did:friend:1', new Perspective());
|
|
973
|
+
expect(result).toBe(true);
|
|
974
|
+
});
|
|
975
|
+
|
|
976
|
+
test('messageInbox() returns inbox messages', async () => {
|
|
977
|
+
const msgs = await ad4m.runtime.messageInbox();
|
|
978
|
+
expect(msgs).toHaveLength(1);
|
|
979
|
+
});
|
|
1324
980
|
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
expect(streamCallback).toBeCalledTimes(0)
|
|
981
|
+
test('openLink() opens a link', async () => {
|
|
982
|
+
const result = await ad4m.runtime.openLink('https://example.com');
|
|
983
|
+
expect(result).toBe(true);
|
|
984
|
+
expect(lastRpcCall!.params.url).toBe('https://example.com');
|
|
985
|
+
});
|
|
1331
986
|
|
|
1332
|
-
|
|
987
|
+
test('notifications() returns notifications', async () => {
|
|
988
|
+
const notifications = await ad4m.runtime.notifications();
|
|
989
|
+
expect(notifications).toEqual([]);
|
|
990
|
+
});
|
|
1333
991
|
|
|
1334
|
-
|
|
992
|
+
test('grantNotification() grants a notification', async () => {
|
|
993
|
+
const result = await ad4m.runtime.grantNotification('notif-1');
|
|
994
|
+
expect(result).toBe(true);
|
|
995
|
+
});
|
|
1335
996
|
|
|
1336
|
-
|
|
997
|
+
test('exportDb() exports the database', async () => {
|
|
998
|
+
const result = await ad4m.runtime.exportDb('/tmp/export');
|
|
999
|
+
expect(result).toBe(true);
|
|
1000
|
+
});
|
|
1337
1001
|
|
|
1338
|
-
|
|
1002
|
+
test('multiUserEnabled() checks multi-user status', async () => {
|
|
1003
|
+
const enabled = await ad4m.runtime.multiUserEnabled();
|
|
1004
|
+
expect(enabled).toBe(false);
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
test('setMultiUserEnabled() enables multi-user', async () => {
|
|
1008
|
+
const result = await ad4m.runtime.setMultiUserEnabled(true);
|
|
1009
|
+
expect(result).toBe(true);
|
|
1010
|
+
});
|
|
1011
|
+
|
|
1012
|
+
test('restartHolochain() restarts holochain', async () => {
|
|
1013
|
+
const result = await ad4m.runtime.restartHolochain();
|
|
1014
|
+
expect(result).toBe(true);
|
|
1015
|
+
});
|
|
1016
|
+
});
|
|
1017
|
+
|
|
1018
|
+
// ===================== AI TESTS =====================
|
|
1019
|
+
describe('AIClient', () => {
|
|
1020
|
+
test('getModels() returns models', async () => {
|
|
1021
|
+
const models = await ad4m.ai.getModels();
|
|
1022
|
+
expect(models).toHaveLength(1);
|
|
1023
|
+
expect(models[0].name).toBe('GPT-Test');
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
test('addModel() adds a model', async () => {
|
|
1027
|
+
const id = await ad4m.ai.addModel({ name: 'New Model', modelType: 'LLM' } as any);
|
|
1028
|
+
expect(id).toBe('model-new-id');
|
|
1029
|
+
expect(lastRpcCall!.params.model).toBeDefined();
|
|
1030
|
+
expect((lastRpcCall!.params.model as any).type).toBe('LLM');
|
|
1031
|
+
expect((lastRpcCall!.params.model as any).modelType).toBeUndefined();
|
|
1032
|
+
});
|
|
1033
|
+
|
|
1034
|
+
test('updateModel() updates a model', async () => {
|
|
1035
|
+
const result = await ad4m.ai.updateModel('model-1', { name: 'Updated', modelType: 'EMBEDDING' } as any);
|
|
1036
|
+
expect(result).toBe(true);
|
|
1037
|
+
expect((lastRpcCall!.params.model as any).type).toBe('EMBEDDING');
|
|
1038
|
+
expect((lastRpcCall!.params.model as any).modelType).toBeUndefined();
|
|
1039
|
+
});
|
|
1040
|
+
|
|
1041
|
+
test('removeModel() removes a model', async () => {
|
|
1042
|
+
const result = await ad4m.ai.removeModel('model-1');
|
|
1043
|
+
expect(result).toBe(true);
|
|
1044
|
+
});
|
|
1045
|
+
|
|
1046
|
+
test('tasks() returns tasks', async () => {
|
|
1047
|
+
const tasks = await ad4m.ai.tasks();
|
|
1048
|
+
expect(tasks).toHaveLength(1);
|
|
1049
|
+
});
|
|
1050
|
+
|
|
1051
|
+
test('addTask() adds a task', async () => {
|
|
1052
|
+
const task = await ad4m.ai.addTask('new-task', 'model-1', 'Do stuff', []);
|
|
1053
|
+
expect(task.name).toBe('new-task');
|
|
1054
|
+
});
|
|
1339
1055
|
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
})
|
|
1344
|
-
|
|
1056
|
+
test('removeTask() removes a task', async () => {
|
|
1057
|
+
const task = await ad4m.ai.removeTask('task-1');
|
|
1058
|
+
expect(task.name).toBe('summarize');
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1061
|
+
test('prompt() sends a prompt', async () => {
|
|
1062
|
+
const response = await ad4m.ai.prompt('task-1', 'Hello AI');
|
|
1063
|
+
expect(response).toBe('This is the AI response');
|
|
1064
|
+
expect(lastRpcCall!.params.taskId).toBe('task-1');
|
|
1065
|
+
expect(lastRpcCall!.params.prompt).toBe('Hello AI');
|
|
1066
|
+
});
|
|
1067
|
+
|
|
1068
|
+
test('modelLoadingStatus() returns status', async () => {
|
|
1069
|
+
const status = await ad4m.ai.modelLoadingStatus('model-1');
|
|
1070
|
+
expect(status.progress).toBe(100);
|
|
1071
|
+
});
|
|
1072
|
+
|
|
1073
|
+
test('setDefaultModel() sets default', async () => {
|
|
1074
|
+
const result = await ad4m.ai.setDefaultModel('LLM' as any, 'model-1');
|
|
1075
|
+
expect(result).toBe(true);
|
|
1076
|
+
});
|
|
1077
|
+
});
|
|
1078
|
+
|
|
1079
|
+
// ===================== USER/AUTH TESTS =====================
|
|
1080
|
+
describe('User and Auth', () => {
|
|
1081
|
+
test('createUser() creates a user', async () => {
|
|
1082
|
+
const result = await ad4m.agent.createUser('test@test.com', 'password');
|
|
1083
|
+
expect(result.success).toBe(true);
|
|
1084
|
+
});
|
|
1085
|
+
|
|
1086
|
+
test('loginUser() returns JWT', async () => {
|
|
1087
|
+
const jwt = await ad4m.agent.loginUser('test@test.com', 'password');
|
|
1088
|
+
expect(jwt).toBe('login-jwt-token');
|
|
1089
|
+
});
|
|
1090
|
+
|
|
1091
|
+
test('verifyEmailCode() returns token', async () => {
|
|
1092
|
+
const token = await ad4m.agent.verifyEmailCode('test@test.com', '123456', 'login');
|
|
1093
|
+
expect(token).toBe('verified-token');
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
test('hostingUserInfo() returns user info', async () => {
|
|
1097
|
+
const info = await ad4m.agent.hostingUserInfo();
|
|
1098
|
+
expect(info.email).toBe('test@test.com');
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1101
|
+
test('requestLoginVerification() sends email and returns result', async () => {
|
|
1102
|
+
const result = await ad4m.agent.requestLoginVerification('test@test.com');
|
|
1103
|
+
expect(result.success).toBe(true);
|
|
1104
|
+
expect(result.isExistingUser).toBe(true);
|
|
1105
|
+
expect(lastRpcCall!.params.email).toBe('test@test.com');
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
test('setHotWalletAddress() sends address', async () => {
|
|
1109
|
+
const result = await ad4m.agent.setHotWalletAddress('0xABC');
|
|
1110
|
+
expect(result).toBe(true);
|
|
1111
|
+
expect(lastRpcCall!.params.address).toBe('0xABC');
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
test('requestPayment() sends amount', async () => {
|
|
1115
|
+
const result = await ad4m.agent.requestPayment('100');
|
|
1116
|
+
expect(lastRpcCall!.params.amountHOT).toBe('100');
|
|
1117
|
+
});
|
|
1118
|
+
});
|
|
1119
|
+
|
|
1120
|
+
// ===================== MULTI-USER EXTENDED TESTS =====================
|
|
1121
|
+
describe('Multi-user and Hosting', () => {
|
|
1122
|
+
test('listUsers() returns user statistics', async () => {
|
|
1123
|
+
const users = await ad4m.runtime.listUsers();
|
|
1124
|
+
expect(users).toHaveLength(1);
|
|
1125
|
+
expect(users[0].email).toBe('user@test.com');
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
test('setUserCredits() sets credits for a user', async () => {
|
|
1129
|
+
const result = await ad4m.runtime.setUserCredits('user@test.com', 500);
|
|
1130
|
+
expect(result).toBe(true);
|
|
1131
|
+
expect(lastRpcCall!.params.email).toBe('user@test.com');
|
|
1132
|
+
expect(lastRpcCall!.params.amount).toBe(500);
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1135
|
+
test('setUserFreeAccess() toggles free access', async () => {
|
|
1136
|
+
const result = await ad4m.runtime.setUserFreeAccess('user@test.com', true);
|
|
1137
|
+
expect(result).toBe(true);
|
|
1138
|
+
expect(lastRpcCall!.params.email).toBe('user@test.com');
|
|
1139
|
+
expect(lastRpcCall!.params.enabled).toBe(true);
|
|
1140
|
+
});
|
|
1141
|
+
|
|
1142
|
+
test('userWalletAddress() returns wallet address', async () => {
|
|
1143
|
+
const addr = await ad4m.runtime.userWalletAddress('user@test.com');
|
|
1144
|
+
expect(addr).toBe('0x1234567890abcdef');
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1147
|
+
test('emailTestModeEnable() enables email test mode', async () => {
|
|
1148
|
+
const result = await ad4m.runtime.emailTestModeEnable();
|
|
1149
|
+
expect(result).toBe(true);
|
|
1150
|
+
expect(lastRpcCall!.params.action).toBe('enable');
|
|
1151
|
+
});
|
|
1152
|
+
|
|
1153
|
+
test('emailTestModeDisable() disables email test mode', async () => {
|
|
1154
|
+
const result = await ad4m.runtime.emailTestModeDisable();
|
|
1155
|
+
expect(result).toBe(true);
|
|
1156
|
+
expect(lastRpcCall!.params.action).toBe('disable');
|
|
1157
|
+
});
|
|
1158
|
+
|
|
1159
|
+
test('emailTestClearCodes() clears test codes', async () => {
|
|
1160
|
+
const result = await ad4m.runtime.emailTestClearCodes();
|
|
1161
|
+
expect(result).toBe(true);
|
|
1162
|
+
expect(lastRpcCall!.params.action).toBe('clear-codes');
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
test('getHostRates() returns parsed rates', async () => {
|
|
1166
|
+
const rates = await ad4m.runtime.getHostRates();
|
|
1167
|
+
expect(rates).toHaveLength(1);
|
|
1168
|
+
expect(rates[0].description).toBe('Link write');
|
|
1169
|
+
expect(rates[0].priceInHOT).toBe(0.001);
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
test('setHostRates() sends rates JSON', async () => {
|
|
1173
|
+
const result = await ad4m.runtime.setHostRates(JSON.stringify([{ description: 'test', priceInHOT: 1 }]));
|
|
1174
|
+
expect(result).toBe(true);
|
|
1175
|
+
});
|
|
1176
|
+
});
|
|
1177
|
+
|
|
1178
|
+
// ===================== UNYT / mHOT TESTS =====================
|
|
1179
|
+
describe('Unyt Integration', () => {
|
|
1180
|
+
test('unytAgentKey() returns agent key', async () => {
|
|
1181
|
+
const key = await ad4m.runtime.unytAgentKey();
|
|
1182
|
+
expect(key).toBe('unyt-agent-key-123');
|
|
1183
|
+
});
|
|
1184
|
+
|
|
1185
|
+
test('unytHotAgentPubkey() returns pubkey', async () => {
|
|
1186
|
+
const key = await ad4m.runtime.unytHotAgentPubkey();
|
|
1187
|
+
expect(key).toBe('unyt-hot-pubkey-456');
|
|
1188
|
+
});
|
|
1189
|
+
|
|
1190
|
+
test('unytWalletBalance() returns balance', async () => {
|
|
1191
|
+
const balance = await ad4m.runtime.unytWalletBalance();
|
|
1192
|
+
expect(balance).toBe('1000.50');
|
|
1193
|
+
});
|
|
1194
|
+
|
|
1195
|
+
test('unytWalletHistory() returns history', async () => {
|
|
1196
|
+
const history = await ad4m.runtime.unytWalletHistory();
|
|
1197
|
+
expect(history).toBe('[]');
|
|
1198
|
+
});
|
|
1199
|
+
|
|
1200
|
+
test('unytVersionInfo() returns version info', async () => {
|
|
1201
|
+
const info = await ad4m.runtime.unytVersionInfo();
|
|
1202
|
+
expect(info).toContain('version');
|
|
1203
|
+
});
|
|
1204
|
+
|
|
1205
|
+
test('unytSetMembraneProof() sets proof', async () => {
|
|
1206
|
+
const result = await ad4m.runtime.unytSetMembraneProof('proof-data');
|
|
1207
|
+
expect(result.success).toBe(true);
|
|
1208
|
+
expect(lastRpcCall!.params.proof).toBe('proof-data');
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1211
|
+
test('unytReinstallDna() reinstalls DNA', async () => {
|
|
1212
|
+
const result = await ad4m.runtime.unytReinstallDna();
|
|
1213
|
+
expect(result.success).toBe(true);
|
|
1214
|
+
});
|
|
1215
|
+
|
|
1216
|
+
test('unytSendHot() sends HOT tokens', async () => {
|
|
1217
|
+
const result = await ad4m.runtime.unytSendHot('recipient-123', '50');
|
|
1218
|
+
expect(result.success).toBe(true);
|
|
1219
|
+
expect(lastRpcCall!.params.recipient).toBe('recipient-123');
|
|
1220
|
+
expect(lastRpcCall!.params.amount).toBe('50');
|
|
1221
|
+
});
|
|
1222
|
+
});
|
|
1223
|
+
|
|
1224
|
+
// ===================== AD4M CLIENT INTEGRATION =====================
|
|
1225
|
+
describe('Ad4mClient', () => {
|
|
1226
|
+
test('all sub-clients are accessible', () => {
|
|
1227
|
+
expect(ad4m.agent).toBeDefined();
|
|
1228
|
+
expect(ad4m.expression).toBeDefined();
|
|
1229
|
+
expect(ad4m.languages).toBeDefined();
|
|
1230
|
+
expect(ad4m.neighbourhood).toBeDefined();
|
|
1231
|
+
expect(ad4m.perspective).toBeDefined();
|
|
1232
|
+
expect(ad4m.runtime).toBeDefined();
|
|
1233
|
+
expect(ad4m.ai).toBeDefined();
|
|
1234
|
+
});
|
|
1235
|
+
|
|
1236
|
+
test('token is passed via WebSocket URL query param', async () => {
|
|
1237
|
+
const freshClient = new Ad4mClient('http://127.0.0.1:12000', 'my-secret-token', false);
|
|
1238
|
+
await freshClient.agent.me();
|
|
1239
|
+
const ws = lastOf(MockWebSocket.instances);
|
|
1240
|
+
expect(ws.url).toBe('ws://127.0.0.1:12000/api/v1/ws?token=my-secret-token');
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
test('WS RPC message contains type and params', async () => {
|
|
1244
|
+
await ad4m.agent.generate('pass');
|
|
1245
|
+
expect(lastRpcCall!.type).toBe('agent.generate');
|
|
1246
|
+
expect(lastRpcCall!.params).toBeDefined();
|
|
1247
|
+
});
|
|
1248
|
+
});
|