@dobby.ai/dobby 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +9 -0
- package/AGENTS.md +267 -0
- package/README.md +382 -0
- package/ROADMAP.md +34 -0
- package/config/cron.example.json +9 -0
- package/config/gateway.example.json +128 -0
- package/config/models.custom.example.json +27 -0
- package/dist/src/agent/event-forwarder.js +341 -0
- package/dist/src/agent/tests/event-forwarder.test.js +113 -0
- package/dist/src/cli/commands/config.js +243 -0
- package/dist/src/cli/commands/configure.js +61 -0
- package/dist/src/cli/commands/cron.js +288 -0
- package/dist/src/cli/commands/doctor.js +189 -0
- package/dist/src/cli/commands/extension.js +151 -0
- package/dist/src/cli/commands/init.js +286 -0
- package/dist/src/cli/commands/start.js +177 -0
- package/dist/src/cli/commands/topology.js +254 -0
- package/dist/src/cli/index.js +8 -0
- package/dist/src/cli/program.js +386 -0
- package/dist/src/cli/shared/config-io.js +223 -0
- package/dist/src/cli/shared/config-mutators.js +345 -0
- package/dist/src/cli/shared/config-path.js +207 -0
- package/dist/src/cli/shared/config-schema.js +159 -0
- package/dist/src/cli/shared/config-types.js +1 -0
- package/dist/src/cli/shared/configure-sections.js +429 -0
- package/dist/src/cli/shared/discord-config.js +12 -0
- package/dist/src/cli/shared/init-catalog.js +115 -0
- package/dist/src/cli/shared/init-models-file.js +65 -0
- package/dist/src/cli/shared/presets.js +86 -0
- package/dist/src/cli/shared/runtime.js +29 -0
- package/dist/src/cli/shared/schema-prompts.js +325 -0
- package/dist/src/cli/tests/config-command.test.js +42 -0
- package/dist/src/cli/tests/config-io.test.js +64 -0
- package/dist/src/cli/tests/config-mutators.test.js +47 -0
- package/dist/src/cli/tests/config-path.test.js +21 -0
- package/dist/src/cli/tests/discord-config.test.js +23 -0
- package/dist/src/cli/tests/doctor.test.js +107 -0
- package/dist/src/cli/tests/init-catalog.test.js +87 -0
- package/dist/src/cli/tests/presets.test.js +41 -0
- package/dist/src/cli/tests/program-options.test.js +92 -0
- package/dist/src/cli/tests/routing-config.test.js +199 -0
- package/dist/src/cli/tests/routing-legacy.test.js +191 -0
- package/dist/src/core/control-command.js +12 -0
- package/dist/src/core/dedup-store.js +92 -0
- package/dist/src/core/gateway.js +432 -0
- package/dist/src/core/routing.js +306 -0
- package/dist/src/core/runtime-registry.js +119 -0
- package/dist/src/core/tests/control-command.test.js +17 -0
- package/dist/src/core/tests/gateway-update-strategy.test.js +167 -0
- package/dist/src/core/tests/runtime-registry.test.js +116 -0
- package/dist/src/core/tests/typing-controller.test.js +103 -0
- package/dist/src/core/types.js +1 -0
- package/dist/src/core/typing-controller.js +88 -0
- package/dist/src/cron/config.js +114 -0
- package/dist/src/cron/schedule.js +49 -0
- package/dist/src/cron/service.js +196 -0
- package/dist/src/cron/store.js +142 -0
- package/dist/src/cron/types.js +1 -0
- package/dist/src/extension/loader.js +97 -0
- package/dist/src/extension/manager.js +269 -0
- package/dist/src/extension/manifest.js +21 -0
- package/dist/src/extension/registry.js +137 -0
- package/dist/src/main.js +6 -0
- package/dist/src/sandbox/executor.js +1 -0
- package/dist/src/sandbox/host-executor.js +111 -0
- package/docs/BOXLITE_SANDBOX_FEASIBILITY.md +175 -0
- package/docs/CRON_SCHEDULER_DESIGN.md +374 -0
- package/docs/DOCKER_SANDBOX_vs_BOXLITE.md +77 -0
- package/docs/EXTENSION_SYSTEM_ARCHITECTURE.md +119 -0
- package/docs/MVP.md +135 -0
- package/docs/RUNBOOK.md +242 -0
- package/docs/TEAMWORK_HANDOFF_DESIGN.md +440 -0
- package/package.json +43 -0
- package/plugins/connector-discord/dobby.manifest.json +18 -0
- package/plugins/connector-discord/index.js +1 -0
- package/plugins/connector-discord/package-lock.json +360 -0
- package/plugins/connector-discord/package.json +38 -0
- package/plugins/connector-discord/src/connector.ts +350 -0
- package/plugins/connector-discord/src/contribution.ts +21 -0
- package/plugins/connector-discord/src/mapper.ts +102 -0
- package/plugins/connector-discord/tsconfig.json +19 -0
- package/plugins/connector-feishu/dobby.manifest.json +18 -0
- package/plugins/connector-feishu/index.js +1 -0
- package/plugins/connector-feishu/package-lock.json +618 -0
- package/plugins/connector-feishu/package.json +38 -0
- package/plugins/connector-feishu/src/connector.ts +343 -0
- package/plugins/connector-feishu/src/contribution.ts +26 -0
- package/plugins/connector-feishu/src/mapper.ts +401 -0
- package/plugins/connector-feishu/tsconfig.json +19 -0
- package/plugins/plugin-sdk/index.d.ts +261 -0
- package/plugins/plugin-sdk/index.js +1 -0
- package/plugins/plugin-sdk/package-lock.json +12 -0
- package/plugins/plugin-sdk/package.json +22 -0
- package/plugins/provider-claude/dobby.manifest.json +17 -0
- package/plugins/provider-claude/index.js +1 -0
- package/plugins/provider-claude/package-lock.json +3398 -0
- package/plugins/provider-claude/package.json +39 -0
- package/plugins/provider-claude/src/contribution.ts +1018 -0
- package/plugins/provider-claude/tsconfig.json +19 -0
- package/plugins/provider-claude-cli/dobby.manifest.json +17 -0
- package/plugins/provider-claude-cli/index.js +1 -0
- package/plugins/provider-claude-cli/package-lock.json +2898 -0
- package/plugins/provider-claude-cli/package.json +38 -0
- package/plugins/provider-claude-cli/src/contribution.ts +1673 -0
- package/plugins/provider-claude-cli/tsconfig.json +19 -0
- package/plugins/provider-pi/dobby.manifest.json +17 -0
- package/plugins/provider-pi/index.js +1 -0
- package/plugins/provider-pi/package-lock.json +3877 -0
- package/plugins/provider-pi/package.json +40 -0
- package/plugins/provider-pi/src/contribution.ts +476 -0
- package/plugins/provider-pi/tsconfig.json +19 -0
- package/plugins/sandbox-core/boxlite.js +1 -0
- package/plugins/sandbox-core/dobby.manifest.json +17 -0
- package/plugins/sandbox-core/docker.js +1 -0
- package/plugins/sandbox-core/package-lock.json +136 -0
- package/plugins/sandbox-core/package.json +39 -0
- package/plugins/sandbox-core/src/boxlite-context.ts +2 -0
- package/plugins/sandbox-core/src/boxlite-contribution.ts +53 -0
- package/plugins/sandbox-core/src/boxlite-executor.ts +911 -0
- package/plugins/sandbox-core/src/docker-contribution.ts +43 -0
- package/plugins/sandbox-core/src/docker-executor.ts +217 -0
- package/plugins/sandbox-core/tsconfig.json +19 -0
- package/scripts/local-extensions.mjs +168 -0
- package/src/agent/event-forwarder.ts +414 -0
- package/src/cli/commands/config.ts +328 -0
- package/src/cli/commands/configure.ts +92 -0
- package/src/cli/commands/cron.ts +410 -0
- package/src/cli/commands/doctor.ts +230 -0
- package/src/cli/commands/extension.ts +205 -0
- package/src/cli/commands/init.ts +396 -0
- package/src/cli/commands/start.ts +223 -0
- package/src/cli/commands/topology.ts +383 -0
- package/src/cli/index.ts +9 -0
- package/src/cli/program.ts +465 -0
- package/src/cli/shared/config-io.ts +277 -0
- package/src/cli/shared/config-mutators.ts +440 -0
- package/src/cli/shared/config-schema.ts +228 -0
- package/src/cli/shared/config-types.ts +121 -0
- package/src/cli/shared/configure-sections.ts +551 -0
- package/src/cli/shared/discord-config.ts +14 -0
- package/src/cli/shared/init-catalog.ts +189 -0
- package/src/cli/shared/init-models-file.ts +77 -0
- package/src/cli/shared/runtime.ts +33 -0
- package/src/cli/shared/schema-prompts.ts +414 -0
- package/src/cli/tests/config-command.test.ts +56 -0
- package/src/cli/tests/config-io.test.ts +92 -0
- package/src/cli/tests/config-mutators.test.ts +59 -0
- package/src/cli/tests/doctor.test.ts +120 -0
- package/src/cli/tests/init-catalog.test.ts +96 -0
- package/src/cli/tests/program-options.test.ts +113 -0
- package/src/cli/tests/routing-config.test.ts +209 -0
- package/src/core/control-command.ts +12 -0
- package/src/core/dedup-store.ts +103 -0
- package/src/core/gateway.ts +607 -0
- package/src/core/routing.ts +379 -0
- package/src/core/runtime-registry.ts +141 -0
- package/src/core/tests/control-command.test.ts +20 -0
- package/src/core/tests/runtime-registry.test.ts +140 -0
- package/src/core/tests/typing-controller.test.ts +129 -0
- package/src/core/types.ts +318 -0
- package/src/core/typing-controller.ts +119 -0
- package/src/cron/config.ts +154 -0
- package/src/cron/schedule.ts +61 -0
- package/src/cron/service.ts +249 -0
- package/src/cron/store.ts +155 -0
- package/src/cron/types.ts +60 -0
- package/src/extension/loader.ts +145 -0
- package/src/extension/manager.ts +355 -0
- package/src/extension/manifest.ts +26 -0
- package/src/extension/registry.ts +229 -0
- package/src/main.ts +8 -0
- package/src/sandbox/executor.ts +44 -0
- package/src/sandbox/host-executor.ts +118 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
/**
|
|
8
|
+
* Writes a temporary default config under HOME/.dobby/gateway.json.
|
|
9
|
+
*/
|
|
10
|
+
async function writeTempHomeConfig(homeDir, payload) {
|
|
11
|
+
const dobbyDir = join(homeDir, ".dobby");
|
|
12
|
+
await mkdir(dobbyDir, { recursive: true });
|
|
13
|
+
const configPath = join(dobbyDir, "gateway.json");
|
|
14
|
+
await writeFile(configPath, `${JSON.stringify(payload, null, 2)}\n`, "utf-8");
|
|
15
|
+
return configPath;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Runs `dobby doctor` in a child process with an isolated HOME directory.
|
|
19
|
+
*/
|
|
20
|
+
async function runDoctorWithHome(homeDir, configPath) {
|
|
21
|
+
return await new Promise((resolve, reject) => {
|
|
22
|
+
const child = spawn(process.execPath, ["--import", "tsx", "src/main.ts", "doctor"], {
|
|
23
|
+
cwd: process.cwd(),
|
|
24
|
+
env: {
|
|
25
|
+
...process.env,
|
|
26
|
+
HOME: homeDir,
|
|
27
|
+
DOBBY_CONFIG_PATH: configPath,
|
|
28
|
+
},
|
|
29
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
30
|
+
});
|
|
31
|
+
let output = "";
|
|
32
|
+
child.stdout.on("data", (chunk) => {
|
|
33
|
+
output += String(chunk);
|
|
34
|
+
});
|
|
35
|
+
child.stderr.on("data", (chunk) => {
|
|
36
|
+
output += String(chunk);
|
|
37
|
+
});
|
|
38
|
+
child.once("error", (error) => reject(error));
|
|
39
|
+
child.once("close", (code) => {
|
|
40
|
+
resolve({ code, output });
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
test("doctor reports invalid binding route references", async () => {
|
|
45
|
+
const homeDir = await mkdtemp(join(tmpdir(), "dobby-doctor-home-"));
|
|
46
|
+
try {
|
|
47
|
+
const configPath = await writeTempHomeConfig(homeDir, {
|
|
48
|
+
extensions: { allowList: [] },
|
|
49
|
+
providers: {
|
|
50
|
+
default: "pi.main",
|
|
51
|
+
items: {
|
|
52
|
+
"pi.main": {
|
|
53
|
+
type: "provider.pi",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
connectors: {
|
|
58
|
+
items: {
|
|
59
|
+
"discord.main": {
|
|
60
|
+
type: "connector.discord",
|
|
61
|
+
botName: "dobby-main",
|
|
62
|
+
botToken: "token",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
sandboxes: {
|
|
67
|
+
default: "host.builtin",
|
|
68
|
+
items: {},
|
|
69
|
+
},
|
|
70
|
+
routes: {
|
|
71
|
+
defaults: {
|
|
72
|
+
provider: "pi.main",
|
|
73
|
+
sandbox: "host.builtin",
|
|
74
|
+
tools: "full",
|
|
75
|
+
mentions: "required",
|
|
76
|
+
},
|
|
77
|
+
items: {
|
|
78
|
+
main: {
|
|
79
|
+
projectRoot: process.cwd(),
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
bindings: {
|
|
84
|
+
items: {
|
|
85
|
+
"discord.main.123": {
|
|
86
|
+
connector: "discord.main",
|
|
87
|
+
source: {
|
|
88
|
+
type: "channel",
|
|
89
|
+
id: "123",
|
|
90
|
+
},
|
|
91
|
+
route: "missing-route",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
data: {
|
|
96
|
+
rootDir: "./data",
|
|
97
|
+
dedupTtlMs: 604800000,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
const result = await runDoctorWithHome(homeDir, configPath);
|
|
101
|
+
assert.equal(result.code, 1);
|
|
102
|
+
assert.equal(result.output.includes("bindings.items['discord.main.123'].route") && result.output.includes("missing-route"), true);
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
await rm(homeDir, { recursive: true, force: true });
|
|
106
|
+
}
|
|
107
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { createInitSelectionConfig } from "../shared/init-catalog.js";
|
|
4
|
+
test("createInitSelectionConfig wires explicit Discord bot config for provider.pi", () => {
|
|
5
|
+
const selected = createInitSelectionConfig(["provider.pi"], "connector.discord", {
|
|
6
|
+
routeId: "main",
|
|
7
|
+
projectRoot: "/tmp/project",
|
|
8
|
+
allowAllMessages: false,
|
|
9
|
+
botName: "dobby-main",
|
|
10
|
+
botToken: "token-abc",
|
|
11
|
+
channelId: "123",
|
|
12
|
+
routeProviderChoiceId: "provider.pi",
|
|
13
|
+
});
|
|
14
|
+
assert.deepEqual(selected.connectorConfig, {
|
|
15
|
+
botName: "dobby-main",
|
|
16
|
+
botToken: "token-abc",
|
|
17
|
+
reconnectStaleMs: 60_000,
|
|
18
|
+
reconnectCheckIntervalMs: 10_000,
|
|
19
|
+
});
|
|
20
|
+
assert.deepEqual(selected.providerChoiceIds, ["provider.pi"]);
|
|
21
|
+
assert.equal(selected.providerInstances.length, 1);
|
|
22
|
+
assert.equal(selected.providerInstanceId, "pi.main");
|
|
23
|
+
assert.equal(selected.providerContributionId, "provider.pi");
|
|
24
|
+
assert.equal(selected.routeProfile.provider, "pi.main");
|
|
25
|
+
assert.equal(selected.routeProfile.mentions, "required");
|
|
26
|
+
assert.equal(selected.bindingId, "discord.main.main");
|
|
27
|
+
assert.deepEqual(selected.bindingConfig, {
|
|
28
|
+
connector: "discord.main",
|
|
29
|
+
source: {
|
|
30
|
+
type: "channel",
|
|
31
|
+
id: "123",
|
|
32
|
+
},
|
|
33
|
+
route: "main",
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
test("createInitSelectionConfig wires explicit Discord bot config for provider.claude-cli", () => {
|
|
37
|
+
const selected = createInitSelectionConfig(["provider.claude-cli"], "connector.discord", {
|
|
38
|
+
routeId: "support",
|
|
39
|
+
projectRoot: "/tmp/project",
|
|
40
|
+
allowAllMessages: true,
|
|
41
|
+
botName: "ops-bot",
|
|
42
|
+
botToken: "token-xyz",
|
|
43
|
+
channelId: "999",
|
|
44
|
+
routeProviderChoiceId: "provider.claude-cli",
|
|
45
|
+
});
|
|
46
|
+
assert.deepEqual(selected.connectorConfig, {
|
|
47
|
+
botName: "ops-bot",
|
|
48
|
+
botToken: "token-xyz",
|
|
49
|
+
reconnectStaleMs: 60_000,
|
|
50
|
+
reconnectCheckIntervalMs: 10_000,
|
|
51
|
+
});
|
|
52
|
+
assert.deepEqual(selected.providerChoiceIds, ["provider.claude-cli"]);
|
|
53
|
+
assert.equal(selected.providerInstances.length, 1);
|
|
54
|
+
assert.equal(selected.providerInstanceId, "claude-cli.main");
|
|
55
|
+
assert.equal(selected.providerContributionId, "provider.claude-cli");
|
|
56
|
+
assert.equal(selected.routeProfile.provider, "claude-cli.main");
|
|
57
|
+
assert.equal(selected.routeProfile.mentions, "optional");
|
|
58
|
+
assert.deepEqual(selected.bindingConfig, {
|
|
59
|
+
connector: "discord.main",
|
|
60
|
+
source: {
|
|
61
|
+
type: "channel",
|
|
62
|
+
id: "999",
|
|
63
|
+
},
|
|
64
|
+
route: "support",
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
test("createInitSelectionConfig supports multiple providers and uses explicit route provider", () => {
|
|
68
|
+
const selected = createInitSelectionConfig(["provider.pi", "provider.claude-cli"], "connector.discord", {
|
|
69
|
+
routeId: "ops",
|
|
70
|
+
projectRoot: "/tmp/project",
|
|
71
|
+
allowAllMessages: false,
|
|
72
|
+
botName: "dobby-multi",
|
|
73
|
+
botToken: "token-multi",
|
|
74
|
+
channelId: "777",
|
|
75
|
+
routeProviderChoiceId: "provider.claude-cli",
|
|
76
|
+
});
|
|
77
|
+
assert.deepEqual(selected.providerChoiceIds, ["provider.pi", "provider.claude-cli"]);
|
|
78
|
+
assert.deepEqual(selected.providerInstances.map((item) => item.instanceId), ["pi.main", "claude-cli.main"]);
|
|
79
|
+
assert.deepEqual(selected.extensionPackages, [
|
|
80
|
+
"@dobby.ai/provider-pi",
|
|
81
|
+
"@dobby.ai/provider-claude-cli",
|
|
82
|
+
"@dobby.ai/connector-discord",
|
|
83
|
+
]);
|
|
84
|
+
assert.equal(selected.providerInstanceId, "claude-cli.main");
|
|
85
|
+
assert.equal(selected.routeProfile.provider, "claude-cli.main");
|
|
86
|
+
assert.equal(selected.routeProviderChoiceId, "provider.claude-cli");
|
|
87
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { createPresetConfig } from "../shared/presets.js";
|
|
4
|
+
test("createPresetConfig wires explicit Discord bot config for discord-pi", () => {
|
|
5
|
+
const preset = createPresetConfig("discord-pi", {
|
|
6
|
+
routeId: "main",
|
|
7
|
+
projectRoot: "/tmp/project",
|
|
8
|
+
allowAllMessages: false,
|
|
9
|
+
botName: "dobby-main",
|
|
10
|
+
botToken: "token-abc",
|
|
11
|
+
channelId: "123",
|
|
12
|
+
});
|
|
13
|
+
assert.deepEqual(preset.connectorConfig, {
|
|
14
|
+
botName: "dobby-main",
|
|
15
|
+
botToken: "token-abc",
|
|
16
|
+
botChannelMap: {
|
|
17
|
+
"123": "main",
|
|
18
|
+
},
|
|
19
|
+
reconnectStaleMs: 60_000,
|
|
20
|
+
reconnectCheckIntervalMs: 10_000,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
test("createPresetConfig wires explicit Discord bot config for discord-claude-cli", () => {
|
|
24
|
+
const preset = createPresetConfig("discord-claude-cli", {
|
|
25
|
+
routeId: "support",
|
|
26
|
+
projectRoot: "/tmp/project",
|
|
27
|
+
allowAllMessages: true,
|
|
28
|
+
botName: "ops-bot",
|
|
29
|
+
botToken: "token-xyz",
|
|
30
|
+
channelId: "999",
|
|
31
|
+
});
|
|
32
|
+
assert.deepEqual(preset.connectorConfig, {
|
|
33
|
+
botName: "ops-bot",
|
|
34
|
+
botToken: "token-xyz",
|
|
35
|
+
botChannelMap: {
|
|
36
|
+
"999": "support",
|
|
37
|
+
},
|
|
38
|
+
reconnectStaleMs: 60_000,
|
|
39
|
+
reconnectCheckIntervalMs: 10_000,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { CommanderError } from "commander";
|
|
4
|
+
import { buildProgram } from "../program.js";
|
|
5
|
+
test("CLI rejects --config option", async () => {
|
|
6
|
+
const program = buildProgram();
|
|
7
|
+
program.configureOutput({
|
|
8
|
+
writeErr: () => { },
|
|
9
|
+
writeOut: () => { },
|
|
10
|
+
});
|
|
11
|
+
program.exitOverride();
|
|
12
|
+
await assert.rejects(program.parseAsync(["node", "dobby", "--config", "./config/gateway.json"]), (error) => {
|
|
13
|
+
assert.equal(error instanceof CommanderError, true);
|
|
14
|
+
assert.equal(error.code, "commander.unknownOption");
|
|
15
|
+
assert.match(String(error.message), /unknown option '--config'/i);
|
|
16
|
+
return true;
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
test("init help has no merge/overwrite flags", () => {
|
|
20
|
+
const program = buildProgram();
|
|
21
|
+
const initCommand = program.commands.find((command) => command.name() === "init");
|
|
22
|
+
assert.ok(initCommand);
|
|
23
|
+
const help = initCommand.helpInformation();
|
|
24
|
+
assert.equal(help.includes("--merge"), false);
|
|
25
|
+
assert.equal(help.includes("--merge-strategy"), false);
|
|
26
|
+
assert.equal(help.includes("--overwrite"), false);
|
|
27
|
+
assert.equal(help.includes("--preset"), false);
|
|
28
|
+
assert.equal(help.includes("--non-interactive"), false);
|
|
29
|
+
assert.equal(help.includes("--yes"), false);
|
|
30
|
+
assert.equal(help.includes("--config"), false);
|
|
31
|
+
});
|
|
32
|
+
test("config help shows show/list/edit and schema", () => {
|
|
33
|
+
const program = buildProgram();
|
|
34
|
+
const configCommand = program.commands.find((command) => command.name() === "config");
|
|
35
|
+
assert.ok(configCommand);
|
|
36
|
+
const help = configCommand.helpInformation();
|
|
37
|
+
assert.match(help, /show \[options\] \[section\]/);
|
|
38
|
+
assert.match(help, /list \[options\] \[section\]/);
|
|
39
|
+
assert.match(help, /edit \[options\]/);
|
|
40
|
+
assert.match(help, /schema/);
|
|
41
|
+
assert.equal(help.includes("get"), false);
|
|
42
|
+
assert.equal(help.includes("set"), false);
|
|
43
|
+
assert.equal(help.includes("unset"), false);
|
|
44
|
+
});
|
|
45
|
+
test("config schema help shows list/show subcommands", () => {
|
|
46
|
+
const program = buildProgram();
|
|
47
|
+
const configCommand = program.commands.find((command) => command.name() === "config");
|
|
48
|
+
assert.ok(configCommand);
|
|
49
|
+
const schemaCommand = configCommand.commands.find((command) => command.name() === "schema");
|
|
50
|
+
assert.ok(schemaCommand);
|
|
51
|
+
const help = schemaCommand.helpInformation();
|
|
52
|
+
assert.match(help, /list \[options\]/);
|
|
53
|
+
assert.match(help, /show \[options\] <contributionId>/);
|
|
54
|
+
});
|
|
55
|
+
test("cron help shows core subcommands", () => {
|
|
56
|
+
const program = buildProgram();
|
|
57
|
+
const cronCommand = program.commands.find((command) => command.name() === "cron");
|
|
58
|
+
assert.ok(cronCommand);
|
|
59
|
+
const help = cronCommand.helpInformation();
|
|
60
|
+
assert.match(help, /add \[options\] <name>/);
|
|
61
|
+
assert.match(help, /list \[options\]/);
|
|
62
|
+
assert.match(help, /run \[options\] <jobId>/);
|
|
63
|
+
assert.match(help, /remove \[options\] <jobId>/);
|
|
64
|
+
});
|
|
65
|
+
test("binding help shows list, set, and remove subcommands", () => {
|
|
66
|
+
const program = buildProgram();
|
|
67
|
+
const bindingCommand = program.commands.find((command) => command.name() === "binding");
|
|
68
|
+
assert.ok(bindingCommand);
|
|
69
|
+
const help = bindingCommand.helpInformation();
|
|
70
|
+
assert.match(help, /list \[options\]/);
|
|
71
|
+
assert.match(help, /set \[options\] <bindingId>/);
|
|
72
|
+
assert.match(help, /remove <bindingId>/);
|
|
73
|
+
});
|
|
74
|
+
test("route help reflects provider, sandbox, mentions, and cascade-bindings options", () => {
|
|
75
|
+
const program = buildProgram();
|
|
76
|
+
const routeCommand = program.commands.find((command) => command.name() === "route");
|
|
77
|
+
assert.ok(routeCommand);
|
|
78
|
+
const setCommand = routeCommand.commands.find((command) => command.name() === "set");
|
|
79
|
+
const removeCommand = routeCommand.commands.find((command) => command.name() === "remove");
|
|
80
|
+
assert.ok(setCommand);
|
|
81
|
+
assert.ok(removeCommand);
|
|
82
|
+
const setHelp = setCommand.helpInformation();
|
|
83
|
+
const removeHelp = removeCommand.helpInformation();
|
|
84
|
+
assert.match(setHelp, /--provider <id>/);
|
|
85
|
+
assert.match(setHelp, /--sandbox <id>/);
|
|
86
|
+
assert.match(setHelp, /--mentions <policy>/);
|
|
87
|
+
assert.equal(setHelp.includes("--provider-id"), false);
|
|
88
|
+
assert.equal(setHelp.includes("--sandbox-id"), false);
|
|
89
|
+
assert.equal(setHelp.includes("--mentions-only"), false);
|
|
90
|
+
assert.equal(setHelp.includes("--default"), false);
|
|
91
|
+
assert.match(removeHelp, /--cascade-bindings/);
|
|
92
|
+
});
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
import { loadGatewayConfig } from "../../core/routing.js";
|
|
7
|
+
async function writeTempConfig(payload) {
|
|
8
|
+
const dir = await mkdtemp(join(tmpdir(), "dobby-routing-"));
|
|
9
|
+
const configPath = join(dir, "gateway.json");
|
|
10
|
+
await writeFile(configPath, `${JSON.stringify(payload, null, 2)}\n`, "utf-8");
|
|
11
|
+
return configPath;
|
|
12
|
+
}
|
|
13
|
+
async function writeRepoTempConfig(payload) {
|
|
14
|
+
const repoRoot = await mkdtemp(join(tmpdir(), "dobby-routing-repo-"));
|
|
15
|
+
const configDir = join(repoRoot, "config");
|
|
16
|
+
await mkdir(configDir, { recursive: true });
|
|
17
|
+
await mkdir(join(repoRoot, "scripts"), { recursive: true });
|
|
18
|
+
await writeFile(join(repoRoot, "package.json"), JSON.stringify({ name: "dobby" }), "utf-8");
|
|
19
|
+
await writeFile(join(repoRoot, "scripts", "local-extensions.mjs"), "#!/usr/bin/env node\n", "utf-8");
|
|
20
|
+
const configPath = join(configDir, "gateway.json");
|
|
21
|
+
await writeFile(configPath, `${JSON.stringify(payload, null, 2)}\n`, "utf-8");
|
|
22
|
+
return { repoRoot, configPath };
|
|
23
|
+
}
|
|
24
|
+
function validConfig() {
|
|
25
|
+
return {
|
|
26
|
+
extensions: { allowList: [] },
|
|
27
|
+
providers: {
|
|
28
|
+
default: "pi.main",
|
|
29
|
+
items: {
|
|
30
|
+
"pi.main": {
|
|
31
|
+
type: "provider.pi",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
connectors: {
|
|
36
|
+
items: {
|
|
37
|
+
"discord.main": {
|
|
38
|
+
type: "connector.discord",
|
|
39
|
+
botName: "dobby-main",
|
|
40
|
+
botToken: "token",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
sandboxes: {
|
|
45
|
+
default: "host.builtin",
|
|
46
|
+
items: {},
|
|
47
|
+
},
|
|
48
|
+
routes: {
|
|
49
|
+
defaults: {
|
|
50
|
+
provider: "pi.main",
|
|
51
|
+
sandbox: "host.builtin",
|
|
52
|
+
tools: "full",
|
|
53
|
+
mentions: "required",
|
|
54
|
+
},
|
|
55
|
+
items: {
|
|
56
|
+
main: {
|
|
57
|
+
projectRoot: "./workspace/project-a",
|
|
58
|
+
systemPromptFile: "./prompts/main.md",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
bindings: {
|
|
63
|
+
items: {
|
|
64
|
+
"discord.main.main": {
|
|
65
|
+
connector: "discord.main",
|
|
66
|
+
source: {
|
|
67
|
+
type: "channel",
|
|
68
|
+
id: "123",
|
|
69
|
+
},
|
|
70
|
+
route: "main",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
data: {
|
|
75
|
+
rootDir: "./data",
|
|
76
|
+
dedupTtlMs: 604800000,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
test("loadGatewayConfig applies route defaults and resolves relative paths", async () => {
|
|
81
|
+
const payload = validConfig();
|
|
82
|
+
const configPath = await writeTempConfig(payload);
|
|
83
|
+
try {
|
|
84
|
+
const loaded = await loadGatewayConfig(configPath);
|
|
85
|
+
const configDir = dirname(configPath);
|
|
86
|
+
assert.equal(loaded.providers.default, "pi.main");
|
|
87
|
+
assert.deepEqual(loaded.routes.defaults, {
|
|
88
|
+
provider: "pi.main",
|
|
89
|
+
sandbox: "host.builtin",
|
|
90
|
+
tools: "full",
|
|
91
|
+
mentions: "required",
|
|
92
|
+
});
|
|
93
|
+
assert.deepEqual(loaded.routes.items.main, {
|
|
94
|
+
projectRoot: join(configDir, "workspace/project-a"),
|
|
95
|
+
systemPromptFile: join(configDir, "prompts/main.md"),
|
|
96
|
+
provider: "pi.main",
|
|
97
|
+
sandbox: "host.builtin",
|
|
98
|
+
tools: "full",
|
|
99
|
+
mentions: "required",
|
|
100
|
+
});
|
|
101
|
+
assert.equal(loaded.data.rootDir, join(configDir, "data"));
|
|
102
|
+
assert.deepEqual(loaded.bindings.items["discord.main.main"], {
|
|
103
|
+
connector: "discord.main",
|
|
104
|
+
source: {
|
|
105
|
+
type: "channel",
|
|
106
|
+
id: "123",
|
|
107
|
+
},
|
|
108
|
+
route: "main",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
await rm(dirname(configPath), { recursive: true, force: true });
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
test("loadGatewayConfig resolves data.rootDir from repo root for repo-local config/gateway.json", async () => {
|
|
116
|
+
const payload = validConfig();
|
|
117
|
+
const { repoRoot, configPath } = await writeRepoTempConfig(payload);
|
|
118
|
+
try {
|
|
119
|
+
const loaded = await loadGatewayConfig(configPath);
|
|
120
|
+
const mainRoute = loaded.routes.items.main;
|
|
121
|
+
assert.ok(mainRoute);
|
|
122
|
+
assert.equal(loaded.data.rootDir, join(repoRoot, "data"));
|
|
123
|
+
assert.equal(mainRoute.projectRoot, join(repoRoot, "workspace/project-a"));
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
await rm(repoRoot, { recursive: true, force: true });
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
test("loadGatewayConfig rejects connector fields reserved by the host", async () => {
|
|
130
|
+
const payload = validConfig();
|
|
131
|
+
payload.connectors = {
|
|
132
|
+
items: {
|
|
133
|
+
"discord.main": {
|
|
134
|
+
type: "connector.discord",
|
|
135
|
+
botName: "dobby-main",
|
|
136
|
+
botToken: "token",
|
|
137
|
+
botChannelMap: {
|
|
138
|
+
"123": "main",
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
const configPath = await writeTempConfig(payload);
|
|
144
|
+
try {
|
|
145
|
+
await assert.rejects(loadGatewayConfig(configPath), /must not include 'botChannelMap'/);
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
await rm(dirname(configPath), { recursive: true, force: true });
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
test("loadGatewayConfig rejects connector env indirection fields reserved by the host", async () => {
|
|
152
|
+
const payload = validConfig();
|
|
153
|
+
payload.connectors = {
|
|
154
|
+
items: {
|
|
155
|
+
"discord.main": {
|
|
156
|
+
type: "connector.discord",
|
|
157
|
+
botName: "dobby-main",
|
|
158
|
+
botTokenEnv: "DISCORD_BOT_TOKEN",
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
const configPath = await writeTempConfig(payload);
|
|
163
|
+
try {
|
|
164
|
+
await assert.rejects(loadGatewayConfig(configPath), /must not include 'botTokenEnv'/);
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
await rm(dirname(configPath), { recursive: true, force: true });
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
test("loadGatewayConfig fails fast on duplicate binding sources", async () => {
|
|
171
|
+
const payload = validConfig();
|
|
172
|
+
payload.bindings = {
|
|
173
|
+
items: {
|
|
174
|
+
"discord.main.main": {
|
|
175
|
+
connector: "discord.main",
|
|
176
|
+
source: {
|
|
177
|
+
type: "channel",
|
|
178
|
+
id: "123",
|
|
179
|
+
},
|
|
180
|
+
route: "main",
|
|
181
|
+
},
|
|
182
|
+
"discord.main.duplicate": {
|
|
183
|
+
connector: "discord.main",
|
|
184
|
+
source: {
|
|
185
|
+
type: "channel",
|
|
186
|
+
id: "123",
|
|
187
|
+
},
|
|
188
|
+
route: "main",
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
const configPath = await writeTempConfig(payload);
|
|
193
|
+
try {
|
|
194
|
+
await assert.rejects(loadGatewayConfig(configPath), /duplicates source 'discord\.main:channel:123'/);
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
await rm(dirname(configPath), { recursive: true, force: true });
|
|
198
|
+
}
|
|
199
|
+
});
|