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