@sprucelabs/spruce-agent-utils 0.0.1
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/.circleci/config.yml +80 -0
- package/.nvmrc +1 -0
- package/.vscode/launch.json +58 -0
- package/.vscode/settings.json +67 -0
- package/.vscode/tasks.json +112 -0
- package/eslint.config.mjs +3 -0
- package/package.json +77 -0
- package/src/.spruce/errors/errors.types.ts +29 -0
- package/src/.spruce/errors/options.types.ts +10 -0
- package/src/.spruce/errors/spruceAgentUtils/agentLoaderNotConfigured.schema.ts +16 -0
- package/src/.spruce/schemas/fields/fieldClassMap.ts +6 -0
- package/src/.spruce/schemas/fields/fields.types.ts +1 -0
- package/src/.spruce/settings.json +15 -0
- package/src/SpruceAgent.ts +40 -0
- package/src/__tests__/behavioral/AgentLoader.test.ts +53 -0
- package/src/__tests__/behavioral/TestingAgentLoader.test.ts +74 -0
- package/src/agentAssert.ts +35 -0
- package/src/errors/SpruceError.ts +23 -0
- package/src/errors/agentLoaderNotConfigured.builder.ts +7 -0
- package/src/index.ts +3 -0
- package/tsconfig.json +39 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
version: 2.1
|
|
2
|
+
orbs:
|
|
3
|
+
spruce: sprucelabsai/orb@1
|
|
4
|
+
jobs:
|
|
5
|
+
test:
|
|
6
|
+
docker:
|
|
7
|
+
- image: cimg/node:lts
|
|
8
|
+
working_directory: /mnt/ramdisk
|
|
9
|
+
steps:
|
|
10
|
+
- run:
|
|
11
|
+
name: Yolo perms
|
|
12
|
+
command: sudo chmod -R 777 /mnt/ramdisk
|
|
13
|
+
- add_ssh_keys:
|
|
14
|
+
fingerprints:
|
|
15
|
+
- "ec:9f:2e:aa:1f:c9:ab:49:57:8f:c0:cd:2e:5b:f3:b0"
|
|
16
|
+
- checkout
|
|
17
|
+
- spruce/check_and_skip_if_npm_publish
|
|
18
|
+
- spruce/create_env_from_base64_env
|
|
19
|
+
- spruce/install_rsync
|
|
20
|
+
- spruce/install_deps_build_ci_test
|
|
21
|
+
- spruce/exit_if_not_auto_upgrade
|
|
22
|
+
- spruce/merge_auto_upgrade
|
|
23
|
+
npm_publish:
|
|
24
|
+
docker:
|
|
25
|
+
- image: cimg/node:lts
|
|
26
|
+
working_directory: /mnt/ramdisk
|
|
27
|
+
steps:
|
|
28
|
+
- run:
|
|
29
|
+
name: Yolo perms
|
|
30
|
+
command: sudo chmod -R 777 /mnt/ramdisk
|
|
31
|
+
- add_ssh_keys:
|
|
32
|
+
fingerprints:
|
|
33
|
+
- "ec:9f:2e:aa:1f:c9:ab:49:57:8f:c0:cd:2e:5b:f3:b0"
|
|
34
|
+
- checkout
|
|
35
|
+
- spruce/check_and_skip_if_npm_publish
|
|
36
|
+
- spruce/install_rsync
|
|
37
|
+
- spruce/install_deps_build_dist_release
|
|
38
|
+
upgrade:
|
|
39
|
+
docker:
|
|
40
|
+
- image: cimg/node:lts
|
|
41
|
+
working_directory: /mnt/ramdisk
|
|
42
|
+
steps:
|
|
43
|
+
- run:
|
|
44
|
+
name: Yolo perms
|
|
45
|
+
command: sudo chmod -R 777 /mnt/ramdisk
|
|
46
|
+
- spruce/check_for_autoupgrade_dns
|
|
47
|
+
- add_ssh_keys:
|
|
48
|
+
fingerprints:
|
|
49
|
+
- "ec:9f:2e:aa:1f:c9:ab:49:57:8f:c0:cd:2e:5b:f3:b0"
|
|
50
|
+
- spruce/check_for_ssh_keys_env
|
|
51
|
+
- spruce/setup_ct_npm_cache
|
|
52
|
+
- checkout
|
|
53
|
+
- spruce/set_target_branch_env
|
|
54
|
+
- spruce/install_rsync
|
|
55
|
+
- spruce/install_cli
|
|
56
|
+
- spruce/upgrade_check_for_major
|
|
57
|
+
- spruce/check_for_newline_only_diff
|
|
58
|
+
- spruce/create_pr
|
|
59
|
+
workflows:
|
|
60
|
+
version: 2.1
|
|
61
|
+
do_build:
|
|
62
|
+
jobs:
|
|
63
|
+
- test:
|
|
64
|
+
context: public_package_publish
|
|
65
|
+
- npm_publish:
|
|
66
|
+
requires:
|
|
67
|
+
- test
|
|
68
|
+
context: public_package_publish
|
|
69
|
+
filters:
|
|
70
|
+
branches:
|
|
71
|
+
only:
|
|
72
|
+
- master
|
|
73
|
+
upgrade:
|
|
74
|
+
jobs:
|
|
75
|
+
- upgrade:
|
|
76
|
+
context: public_package_publish
|
|
77
|
+
filters:
|
|
78
|
+
branches:
|
|
79
|
+
only:
|
|
80
|
+
- never_run_only_for_cron
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lts/*
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.2.0",
|
|
3
|
+
"configurations": [
|
|
4
|
+
{
|
|
5
|
+
"type": "node",
|
|
6
|
+
"request": "attach",
|
|
7
|
+
"name": "attach.tests",
|
|
8
|
+
"port": 5200,
|
|
9
|
+
"restart": true,
|
|
10
|
+
"timeout": 10000
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"type": "node",
|
|
14
|
+
"request": "launch",
|
|
15
|
+
"name": "test.file",
|
|
16
|
+
"runtimeExecutable": "node",
|
|
17
|
+
"runtimeArgs": [
|
|
18
|
+
"--inspect-brk",
|
|
19
|
+
"--trace-warnings",
|
|
20
|
+
"${workspaceFolder}/node_modules/.bin/jest",
|
|
21
|
+
"${fileBasenameNoExtension}",
|
|
22
|
+
"--detectOpenHandles"
|
|
23
|
+
],
|
|
24
|
+
"cwd": "${workspaceFolder}",
|
|
25
|
+
"console": "integratedTerminal",
|
|
26
|
+
"internalConsoleOptions": "neverOpen"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"type": "node",
|
|
30
|
+
"request": "launch",
|
|
31
|
+
"name": "test.all",
|
|
32
|
+
"runtimeExecutable": "node",
|
|
33
|
+
"runtimeArgs": [
|
|
34
|
+
"--inspect-brk",
|
|
35
|
+
"--trace-warnings",
|
|
36
|
+
"${workspaceFolder}/node_modules/.bin/jest"
|
|
37
|
+
],
|
|
38
|
+
"cwd": "${workspaceFolder}",
|
|
39
|
+
"console": "integratedTerminal",
|
|
40
|
+
"internalConsoleOptions": "neverOpen"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"type": "node",
|
|
44
|
+
"request": "launch",
|
|
45
|
+
"name": "boot",
|
|
46
|
+
"runtimeExecutable": "yarn",
|
|
47
|
+
"runtimeArgs": [
|
|
48
|
+
"run",
|
|
49
|
+
"--inspect-brk",
|
|
50
|
+
"--trace-warnings",
|
|
51
|
+
"boot"
|
|
52
|
+
],
|
|
53
|
+
"cwd": "${workspaceFolder}",
|
|
54
|
+
"console": "integratedTerminal",
|
|
55
|
+
"internalConsoleOptions": "neverOpen"
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"debug.node.autoAttach": "on",
|
|
3
|
+
"git.ignoreLimitWarning": true,
|
|
4
|
+
"javascript.validate.enable": false,
|
|
5
|
+
"files.watcherExclude": {
|
|
6
|
+
"**/.git/objects/**": true,
|
|
7
|
+
"**/.git/subtree-cache/**": true,
|
|
8
|
+
"**/build/**": true,
|
|
9
|
+
"**/node_modules/**": true,
|
|
10
|
+
},
|
|
11
|
+
"search.exclude": {
|
|
12
|
+
"**/build/**": true,
|
|
13
|
+
"**/node_modules/**": true,
|
|
14
|
+
"**/.next/**": true
|
|
15
|
+
},
|
|
16
|
+
"editor.maxTokenizationLineLength": 20000000,
|
|
17
|
+
"[javascript]": {
|
|
18
|
+
"editor.formatOnSave": false
|
|
19
|
+
},
|
|
20
|
+
"[javascriptreact]": {
|
|
21
|
+
"editor.formatOnSave": false
|
|
22
|
+
},
|
|
23
|
+
"[typescript]": {
|
|
24
|
+
"editor.formatOnSave": false
|
|
25
|
+
},
|
|
26
|
+
"[typescriptreact]": {
|
|
27
|
+
"editor.formatOnSave": false
|
|
28
|
+
},
|
|
29
|
+
"[handlebars]": {
|
|
30
|
+
"editor.formatOnSave": false
|
|
31
|
+
},
|
|
32
|
+
"typescript.tsdk": "node_modules/typescript/lib",
|
|
33
|
+
"cSpell.ignorePaths": [
|
|
34
|
+
"**/package-lock.json",
|
|
35
|
+
"**/node_modules/**",
|
|
36
|
+
"**/build/**",
|
|
37
|
+
"**/vscode-extension/**",
|
|
38
|
+
"**/.git/objects/**",
|
|
39
|
+
".vscode",
|
|
40
|
+
".spruce"
|
|
41
|
+
],
|
|
42
|
+
"cSpell.words": [
|
|
43
|
+
"arkit",
|
|
44
|
+
"autogenerated",
|
|
45
|
+
"scrollable",
|
|
46
|
+
"serializable"
|
|
47
|
+
],
|
|
48
|
+
"debug.javascript.unmapMissingSources": true,
|
|
49
|
+
"javascript.preferences.importModuleSpecifier": "relative",
|
|
50
|
+
"typescript.preferences.importModuleSpecifier": "relative",
|
|
51
|
+
"eslint.useFlatConfig": true,
|
|
52
|
+
"eslint.enable": true,
|
|
53
|
+
"eslint.validate": [
|
|
54
|
+
"javascript",
|
|
55
|
+
"javascriptreact",
|
|
56
|
+
"typescript",
|
|
57
|
+
"typescriptreact"
|
|
58
|
+
],
|
|
59
|
+
"eslint.workingDirectories": [
|
|
60
|
+
"./"
|
|
61
|
+
],
|
|
62
|
+
"typescript.validate.enable": true,
|
|
63
|
+
"editor.formatOnSave": false,
|
|
64
|
+
"editor.codeActionsOnSave": {
|
|
65
|
+
"source.fixAll.eslint": "always"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "2.0.0",
|
|
3
|
+
"tasks": [
|
|
4
|
+
{
|
|
5
|
+
"type": "npm",
|
|
6
|
+
"script": "watch.build.dev",
|
|
7
|
+
"group": "build",
|
|
8
|
+
"label": "watch.build.dev & problem.watcher",
|
|
9
|
+
"isBackground": true,
|
|
10
|
+
"runOptions": {
|
|
11
|
+
"runOn": "folderOpen"
|
|
12
|
+
},
|
|
13
|
+
"promptOnClose": false,
|
|
14
|
+
"presentation": {
|
|
15
|
+
"focus": false,
|
|
16
|
+
"reveal": "never"
|
|
17
|
+
},
|
|
18
|
+
"problemMatcher": {
|
|
19
|
+
"base": "$tsc-watch",
|
|
20
|
+
"applyTo": "allDocuments"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"label": "test.file",
|
|
25
|
+
"command": "spruce",
|
|
26
|
+
"args": [
|
|
27
|
+
"test",
|
|
28
|
+
"--inspect",
|
|
29
|
+
"5200",
|
|
30
|
+
"--pattern",
|
|
31
|
+
"${fileBasenameNoExtension}",
|
|
32
|
+
"--watchMode",
|
|
33
|
+
"standard"
|
|
34
|
+
],
|
|
35
|
+
"promptOnClose": false,
|
|
36
|
+
"group": {
|
|
37
|
+
"kind": "test",
|
|
38
|
+
"isDefault": true
|
|
39
|
+
},
|
|
40
|
+
"presentation": {
|
|
41
|
+
"reveal": "always",
|
|
42
|
+
"panel": "dedicated",
|
|
43
|
+
},
|
|
44
|
+
"problemMatcher": []
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"label": "test.reporter",
|
|
48
|
+
"command": "spruce",
|
|
49
|
+
"args": [
|
|
50
|
+
"test",
|
|
51
|
+
"--shouldHoldAtStart",
|
|
52
|
+
"true",
|
|
53
|
+
"--watchMode",
|
|
54
|
+
"smart"
|
|
55
|
+
],
|
|
56
|
+
"promptOnClose": false,
|
|
57
|
+
"group": "test",
|
|
58
|
+
"runOptions": {
|
|
59
|
+
"runOn": "folderOpen"
|
|
60
|
+
},
|
|
61
|
+
"presentation": {
|
|
62
|
+
"panel": "shared",
|
|
63
|
+
"focus": true,
|
|
64
|
+
"reveal": "always"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"label": "spruce",
|
|
69
|
+
"type": "shell",
|
|
70
|
+
"command": "spruce ${input:spruceCommand}",
|
|
71
|
+
"problemMatcher": [],
|
|
72
|
+
"presentation": {
|
|
73
|
+
"reveal": "always",
|
|
74
|
+
"focus": true,
|
|
75
|
+
"panel": "new",
|
|
76
|
+
"clear": false
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"label": "shell",
|
|
81
|
+
"type": "shell",
|
|
82
|
+
"command": "${input:command} ${input:optionsCommand}",
|
|
83
|
+
"problemMatcher": [],
|
|
84
|
+
"presentation": {
|
|
85
|
+
"reveal": "always",
|
|
86
|
+
"focus": true,
|
|
87
|
+
"panel": "new",
|
|
88
|
+
"clear": false
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
"inputs": [
|
|
93
|
+
{
|
|
94
|
+
"id": "spruceCommand",
|
|
95
|
+
"description": "spruce command",
|
|
96
|
+
"default": "create.test",
|
|
97
|
+
"type": "promptString"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"id": "command",
|
|
101
|
+
"description": "command",
|
|
102
|
+
"default": "yarn",
|
|
103
|
+
"type": "promptString"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"id": "optionsCommand",
|
|
107
|
+
"description": "optionsCommand",
|
|
108
|
+
"default": "add",
|
|
109
|
+
"type": "promptString"
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sprucelabs/spruce-agent-utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build.ci": "yarn run build.tsc && yarn run build.resolve-paths && yarn run lint",
|
|
6
|
+
"build.dev": "yarn run build.tsc --sourceMap ; yarn run resolve-paths.lint",
|
|
7
|
+
"build.copy-files": "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/",
|
|
8
|
+
"build.resolve-paths": "resolve-path-aliases --target build --patterns '**/*.js,**/*.d.ts'",
|
|
9
|
+
"build.tsc": "yarn run build.copy-files && tsc",
|
|
10
|
+
"clean": "yarn run clean.build",
|
|
11
|
+
"clean.all": "yarn run clean.dependencies && yarn run clean.build",
|
|
12
|
+
"clean.build": "rm -rf build/",
|
|
13
|
+
"clean.dependencies": "rm -rf node_modules/ package-lock.json yarn.lock",
|
|
14
|
+
"fix.lint": "eslint --fix --cache '**/*.ts'",
|
|
15
|
+
"lint": "eslint --cache '**/*.ts'",
|
|
16
|
+
"lint.tsc": "tsc -p . --noEmit",
|
|
17
|
+
"post.watch.build": "yarn run build.copy-files && yarn run build.resolve-paths",
|
|
18
|
+
"rebuild": "yarn run clean.all && yarn install && yarn run build.dev",
|
|
19
|
+
"update.dependencies": "yarn run clean.dependencies && yarn",
|
|
20
|
+
"resolve-paths.lint": "yarn run build.resolve-paths ; yarn run lint",
|
|
21
|
+
"test": "jest",
|
|
22
|
+
"watch.build.dev": "tsc-watch --sourceMap --onCompilationComplete 'yarn run post.watch.build'",
|
|
23
|
+
"watch.rebuild": "yarn run clean.all && yarn install && yarn run watch.build.dev",
|
|
24
|
+
"watch.tsc": "tsc -w"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@sprucelabs/jest-json-reporter": "^10.0.12",
|
|
28
|
+
"@sprucelabs/resolve-path-aliases": "^4.0.9",
|
|
29
|
+
"@sprucelabs/spruce-test-fixtures": "^76.0.15",
|
|
30
|
+
"@sprucelabs/test": "^11.0.3",
|
|
31
|
+
"@sprucelabs/test-utils": "^7.0.16",
|
|
32
|
+
"@types/node": "^24.10.1",
|
|
33
|
+
"chokidar-cli": "^3.0.0",
|
|
34
|
+
"eslint": "^9.39.1",
|
|
35
|
+
"eslint-config-spruce": "^11.2.26",
|
|
36
|
+
"jest": "^30.2.0",
|
|
37
|
+
"jest-circus": "^30.2.0",
|
|
38
|
+
"prettier": "^3.7.3",
|
|
39
|
+
"ts-node": "^10.9.2",
|
|
40
|
+
"tsc-watch": "^7.2.0",
|
|
41
|
+
"typescript": "^5.9.3"
|
|
42
|
+
},
|
|
43
|
+
"description": "The utilities for getting the agent details on the utils",
|
|
44
|
+
"skill": {
|
|
45
|
+
"namespace": "spruce-agent-utils"
|
|
46
|
+
},
|
|
47
|
+
"jest": {
|
|
48
|
+
"testRunner": "jest-circus/runner",
|
|
49
|
+
"maxWorkers": 4,
|
|
50
|
+
"testTimeout": 120000,
|
|
51
|
+
"testEnvironment": "node",
|
|
52
|
+
"testPathIgnorePatterns": [
|
|
53
|
+
"<rootDir>/tmp/",
|
|
54
|
+
"<rootDir>/src/",
|
|
55
|
+
"<rootDir>/node_modules/",
|
|
56
|
+
"<rootDir>/build/__tests__/testDirsAndFiles/"
|
|
57
|
+
],
|
|
58
|
+
"testMatch": [
|
|
59
|
+
"**/__tests__/**/*.test.js?(x)"
|
|
60
|
+
],
|
|
61
|
+
"moduleNameMapper": {
|
|
62
|
+
"^#spruce/(.*)$": "<rootDir>/build/.spruce/$1"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"@sprucelabs/error": "^8.0.9",
|
|
67
|
+
"@sprucelabs/mercury-client": "^45.0.26",
|
|
68
|
+
"@sprucelabs/mercury-core-events": "^28.1.1",
|
|
69
|
+
"@sprucelabs/mercury-types": "^49.0.21",
|
|
70
|
+
"@sprucelabs/schema": "^33.0.17",
|
|
71
|
+
"@sprucelabs/spruce-core-schemas": "^42.0.21",
|
|
72
|
+
"@sprucelabs/spruce-event-plugin": "^76.0.15",
|
|
73
|
+
"@sprucelabs/spruce-event-utils": "^42.0.20",
|
|
74
|
+
"@sprucelabs/spruce-permission-plugin": "^48.0.16",
|
|
75
|
+
"@sprucelabs/spruce-skill-utils": "^33.0.20"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { default as SchemaEntity } from '@sprucelabs/schema'
|
|
2
|
+
import * as SpruceSchema from '@sprucelabs/schema'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export declare namespace SpruceErrors.SpruceAgentUtils {
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export interface AgentLoaderNotConfigured {
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface AgentLoaderNotConfiguredSchema extends SpruceSchema.Schema {
|
|
16
|
+
id: 'agentLoaderNotConfigured',
|
|
17
|
+
namespace: 'SpruceAgentUtils',
|
|
18
|
+
name: 'agent loader not configured',
|
|
19
|
+
fields: {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type AgentLoaderNotConfiguredEntity = SchemaEntity<SpruceErrors.SpruceAgentUtils.AgentLoaderNotConfiguredSchema>
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SpruceErrors } from "#spruce/errors/errors.types"
|
|
2
|
+
import { ErrorOptions as ISpruceErrorOptions} from "@sprucelabs/error"
|
|
3
|
+
|
|
4
|
+
export interface AgentLoaderNotConfiguredErrorOptions extends SpruceErrors.SpruceAgentUtils.AgentLoaderNotConfigured, ISpruceErrorOptions {
|
|
5
|
+
code: 'AGENT_LOADER_NOT_CONFIGURED'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type ErrorOptions = | AgentLoaderNotConfiguredErrorOptions
|
|
9
|
+
|
|
10
|
+
export default ErrorOptions
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SchemaRegistry } from '@sprucelabs/schema'
|
|
2
|
+
import { SpruceErrors } from '../errors.types'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const agentLoaderNotConfiguredSchema: SpruceErrors.SpruceAgentUtils.AgentLoaderNotConfiguredSchema = {
|
|
7
|
+
id: 'agentLoaderNotConfigured',
|
|
8
|
+
namespace: 'SpruceAgentUtils',
|
|
9
|
+
name: 'agent loader not configured',
|
|
10
|
+
fields: {
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
SchemaRegistry.getInstance().trackSchema(agentLoaderNotConfiguredSchema)
|
|
15
|
+
|
|
16
|
+
export default agentLoaderNotConfiguredSchema
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FieldDefinitions, FieldDefinitionMap, FieldValueTypeGeneratorMap, FieldMap } from '@sprucelabs/schema'
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MercuryClient } from '@sprucelabs/mercury-client'
|
|
2
|
+
import SpruceError from './errors/SpruceError'
|
|
3
|
+
|
|
4
|
+
export default class SpruceAgent implements AgentLoader {
|
|
5
|
+
private static instance?: SpruceAgent
|
|
6
|
+
private client: MercuryClient
|
|
7
|
+
|
|
8
|
+
private constructor(client: MercuryClient) {
|
|
9
|
+
this.client = client
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public static setup(client: MercuryClient) {
|
|
13
|
+
this.instance = new SpruceAgent(client)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public static reset() {
|
|
17
|
+
delete this.instance
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public static getInstance() {
|
|
21
|
+
if (this.instance) {
|
|
22
|
+
return this.instance
|
|
23
|
+
}
|
|
24
|
+
throw new SpruceError({
|
|
25
|
+
code: 'AGENT_LOADER_NOT_CONFIGURED',
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public async getName() {
|
|
30
|
+
const [{ name }] = await this.client.emitAndFlattenResponses(
|
|
31
|
+
'get-agent-name::v2020_12_25'
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
return name
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface AgentLoader {
|
|
39
|
+
getName(): Promise<string>
|
|
40
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AbstractSpruceFixtureTest,
|
|
3
|
+
eventFaker,
|
|
4
|
+
fake,
|
|
5
|
+
} from '@sprucelabs/spruce-test-fixtures'
|
|
6
|
+
import {
|
|
7
|
+
test,
|
|
8
|
+
suite,
|
|
9
|
+
assert,
|
|
10
|
+
errorAssert,
|
|
11
|
+
generateId,
|
|
12
|
+
} from '@sprucelabs/test-utils'
|
|
13
|
+
import SpruceAgent from '../../SpruceAgent'
|
|
14
|
+
|
|
15
|
+
@fake.login()
|
|
16
|
+
@suite()
|
|
17
|
+
export default class AgentLoaderTest extends AbstractSpruceFixtureTest {
|
|
18
|
+
private agents!: SpruceAgent
|
|
19
|
+
private agentName = generateId()
|
|
20
|
+
|
|
21
|
+
protected async beforeEach(): Promise<void> {
|
|
22
|
+
await super.beforeEach()
|
|
23
|
+
SpruceAgent.setup(this.fakedClient)
|
|
24
|
+
this.agents = SpruceAgent.getInstance()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@test()
|
|
28
|
+
protected async getInstanceThrowsWithoutConfiguring() {
|
|
29
|
+
SpruceAgent.reset()
|
|
30
|
+
const err = assert.doesThrow(() => SpruceAgent.getInstance())
|
|
31
|
+
errorAssert.assertError(err, 'AGENT_LOADER_NOT_CONFIGURED')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@test()
|
|
35
|
+
protected async getInstanceReturnsSameInstanceEachTime() {
|
|
36
|
+
assert.isEqual(
|
|
37
|
+
this.agents,
|
|
38
|
+
SpruceAgent.getInstance(),
|
|
39
|
+
'should be the same instance'
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@test()
|
|
44
|
+
protected async emitsGetAgentOnEmit() {
|
|
45
|
+
await eventFaker.on('get-agent-name::v2020_12_25', () => {
|
|
46
|
+
return { name: this.agentName }
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const name = await this.agents.getName()
|
|
50
|
+
|
|
51
|
+
assert.isEqual(name, this.agentName, 'agent name does not match')
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { fake } from '@sprucelabs/spruce-test-fixtures'
|
|
2
|
+
import { AbstractSpruceFixtureTest } from '@sprucelabs/spruce-test-fixtures'
|
|
3
|
+
import { test, suite, assert, errorAssert } from '@sprucelabs/test-utils'
|
|
4
|
+
import agentAssert from '../../agentAssert'
|
|
5
|
+
import SpruceAgent from '../../SpruceAgent'
|
|
6
|
+
|
|
7
|
+
@fake.login()
|
|
8
|
+
@suite()
|
|
9
|
+
export default class TestingAgentLoaderTest extends AbstractSpruceFixtureTest {
|
|
10
|
+
@test()
|
|
11
|
+
protected async throwsIfDidNotBeforeEach() {
|
|
12
|
+
assert.doesThrow(() => agentAssert.getName(), 'beforeEach')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@test()
|
|
16
|
+
protected async throwsAgentLoaderNotConfiguredIfGettingNameBeforeConfigured() {
|
|
17
|
+
await agentAssert.beforeEach(this.fakedClient)
|
|
18
|
+
const err = assert.doesThrow(() => agentAssert.getName())
|
|
19
|
+
|
|
20
|
+
errorAssert.assertError(err, 'AGENT_LOADER_NOT_CONFIGURED')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@test()
|
|
24
|
+
protected async nameMatchesNameFromAgent() {
|
|
25
|
+
await this.fullBeforeEach()
|
|
26
|
+
const actual = agentAssert.getName()
|
|
27
|
+
const expected = await SpruceAgent.getInstance().getName()
|
|
28
|
+
assert.isEqual(
|
|
29
|
+
actual,
|
|
30
|
+
expected,
|
|
31
|
+
'agentAssert should return the same name as SpruceAgent'
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@test()
|
|
36
|
+
protected async nameShouldDifferEachTest() {
|
|
37
|
+
await agentAssert.beforeEach(this.fakedClient)
|
|
38
|
+
const name1 = agentAssert.getName()
|
|
39
|
+
await agentAssert.beforeEach(this.fakedClient)
|
|
40
|
+
const name2 = agentAssert.getName()
|
|
41
|
+
|
|
42
|
+
assert.isNotEqual(name1, name2, 'names should differ between tests')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@test()
|
|
46
|
+
protected async assertIncludesAgentNameThrowsWithMissing() {
|
|
47
|
+
await this.fullBeforeEach()
|
|
48
|
+
|
|
49
|
+
//@ts-ignore
|
|
50
|
+
const err = assert.doesThrow(() => agentAssert.includesAgentName())
|
|
51
|
+
errorAssert.assertError(err, 'MISSING_PARAMETERS', {
|
|
52
|
+
parameters: ['text'],
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@test()
|
|
57
|
+
protected async canAssertIncludesName() {
|
|
58
|
+
await this.fullBeforeEach()
|
|
59
|
+
|
|
60
|
+
const includesName = `Hello, my agent name is ${await SpruceAgent.getInstance().getName()}!`
|
|
61
|
+
const doesNotIncludeName = `Hello, I have no agent name!`
|
|
62
|
+
|
|
63
|
+
agentAssert.includesAgentName(includesName)
|
|
64
|
+
|
|
65
|
+
assert.doesThrow(() =>
|
|
66
|
+
agentAssert.includesAgentName(doesNotIncludeName)
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private async fullBeforeEach() {
|
|
71
|
+
await agentAssert.beforeEach(this.fakedClient)
|
|
72
|
+
SpruceAgent.setup(this.fakedClient)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { MercuryClient } from '@sprucelabs/mercury-client'
|
|
2
|
+
import { assertOptions } from '@sprucelabs/schema'
|
|
3
|
+
import { eventFaker } from '@sprucelabs/spruce-test-fixtures'
|
|
4
|
+
import { assert, generateId } from '@sprucelabs/test-utils'
|
|
5
|
+
import SpruceAgent from './SpruceAgent'
|
|
6
|
+
|
|
7
|
+
let sharedClient: MercuryClient
|
|
8
|
+
let name: string = generateId()
|
|
9
|
+
|
|
10
|
+
const agentAssert = {
|
|
11
|
+
async beforeEach(client: MercuryClient) {
|
|
12
|
+
name = generateId()
|
|
13
|
+
sharedClient = client
|
|
14
|
+
await eventFaker.on('get-agent-name::v2020_12_25', () => {
|
|
15
|
+
return { name }
|
|
16
|
+
})
|
|
17
|
+
},
|
|
18
|
+
getName: () => {
|
|
19
|
+
assert.isTruthy(
|
|
20
|
+
sharedClient,
|
|
21
|
+
'You must call agentAssert.beforeEach(this.fakedClient) in your test to use agentAssert'
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
SpruceAgent.getInstance()
|
|
25
|
+
|
|
26
|
+
return name
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
includesAgentName: (text: string) => {
|
|
30
|
+
assertOptions({ text }, ['text'])
|
|
31
|
+
assert.doesInclude(text, name, `The tex must include agent name!`)
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default agentAssert
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import BaseSpruceError from '@sprucelabs/error'
|
|
2
|
+
import ErrorOptions from '#spruce/errors/options.types'
|
|
3
|
+
|
|
4
|
+
export default class SpruceError extends BaseSpruceError<ErrorOptions> {
|
|
5
|
+
/** an easy to understand version of the errors */
|
|
6
|
+
public friendlyMessage(): string {
|
|
7
|
+
const { options } = this
|
|
8
|
+
let message
|
|
9
|
+
switch (options?.code) {
|
|
10
|
+
case 'AGENT_LOADER_NOT_CONFIGURED':
|
|
11
|
+
message = `The agent loader has not been configured. Please call AgentLoader.setup(...) first. Best place is probably in the did-boot of your skill.`
|
|
12
|
+
break
|
|
13
|
+
default:
|
|
14
|
+
message = super.friendlyMessage()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const fullMessage = options.friendlyMessage
|
|
18
|
+
? options.friendlyMessage
|
|
19
|
+
: message
|
|
20
|
+
|
|
21
|
+
return fullMessage
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"skipLibCheck": true,
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"target": "ES2020",
|
|
7
|
+
"lib": [
|
|
8
|
+
"DOM",
|
|
9
|
+
"ES2022"
|
|
10
|
+
],
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"noImplicitAny": true,
|
|
13
|
+
"allowJs": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"noImplicitReturns": true,
|
|
16
|
+
"strict": true,
|
|
17
|
+
"noUnusedLocals": true,
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"moduleResolution": "node",
|
|
20
|
+
"sourceMap": false,
|
|
21
|
+
"outDir": "build",
|
|
22
|
+
"baseUrl": "src",
|
|
23
|
+
"experimentalDecorators": true,
|
|
24
|
+
"paths": {
|
|
25
|
+
"#spruce/*": [
|
|
26
|
+
".spruce/*"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"include": [
|
|
31
|
+
"./src/*.ts",
|
|
32
|
+
"./src/**/*.ts",
|
|
33
|
+
"./src/.spruce/**/*"
|
|
34
|
+
],
|
|
35
|
+
"exclude": [
|
|
36
|
+
"build",
|
|
37
|
+
"esm"
|
|
38
|
+
]
|
|
39
|
+
}
|