Simplify instance lifecycle commands

This commit is contained in:
zenord
2026-08-17 00:49:29 +08:00
parent f9fb4ef776
commit fe7bbd0631
13 changed files with 385 additions and 237 deletions
+69 -5
View File
@@ -70,16 +70,21 @@ function existingConfig(host = "0.0.0.0", port = 8787) {
id: "existing-bot",
workspace: os.tmpdir(),
persona: "existing persona",
agent: { id: readyAgent.id, command: readyAgent.command, args: readyAgent.args, env: {} },
skills: [],
permissions: { mode: "deny", allowedTools: [], allowedCommandPatterns: [] }
agent: {
id: "custom-kimi",
command: readyAgent.command,
args: ["-m", "gori-gpt/gpt-5.5", "acp"],
env: { TEST_AGENT_SETTING: "preserved" }
},
skills: [{ id: "test-skill", file: path.join(os.tmpdir(), "test-skill.md"), maxBytes: 1234 }],
permissions: { mode: "allowlist", allowedTools: ["Read"], allowedCommandPatterns: ["^true$"] }
},
gateway: {
server: { host, port, publicBaseUrl: "https://public.example.test" },
policy: { allowedUsers: [], allowedChats: [], requireMentionInGroup: true },
policy: { allowedUsers: ["allowed-user"], allowedChats: ["allowed-chat"], requireMentionInGroup: false },
platform: { type: "webhook", secret: testSecret }
},
runtime: {}
runtime: { acp: { promptTimeoutMs: 123456, maxProcesses: 3 } }
});
}
@@ -145,6 +150,17 @@ test("existing setup can change host and port while preserving public URL and se
assert.equal(config.gateway.server.publicBaseUrl, "https://public.example.test");
assert.equal(config.gateway.platform.type, "webhook");
assert.equal(config.gateway.platform.secret, testSecret);
assert.deepEqual(config.bot.agent, {
id: "custom-kimi",
command: readyAgent.command,
args: ["-m", "gori-gpt/gpt-5.5", "acp"],
env: { TEST_AGENT_SETTING: "preserved" }
});
assert.deepEqual(config.bot.skills, [{ id: "test-skill", file: path.join(os.tmpdir(), "test-skill.md"), maxBytes: 1234 }]);
assert.deepEqual(config.bot.permissions, { mode: "allowlist", allowedTools: ["Read"], allowedCommandPatterns: ["^true$"] });
assert.deepEqual(config.gateway.policy, { allowedUsers: ["allowed-user"], allowedChats: ["allowed-chat"], requireMentionInGroup: false });
assert.equal(config.runtime.acp.promptTimeoutMs, 123456);
assert.equal(config.runtime.acp.maxProcesses, 3);
assert.equal(prompt.closeCount, 1);
assert.ok(messages.some((message) => message.startsWith("ERROR: server host")));
assert.ok(messages.some((message) => message.startsWith("ERROR: server port")));
@@ -175,3 +191,51 @@ test("existing setup keeps host and port when defaults are accepted", async (t)
assert.equal(config.gateway.server.port, 9123);
assert.equal(prompt.closeCount, 1);
});
test("existing setup succeeds without a ready discovered agent and preserves its agent", async (t) => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "gori-setup-no-ready-"));
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
const target = path.join(root, "existing-bot", "config.json");
writeConfigFile(target, existingConfig());
await runSetup(target, {
botId: "existing-bot",
writeWithoutConfirmation: true,
prompt: new FakePrompt({}, ""),
discoverAgents: async () => [{ id: "kimi", command: "kimi", args: ["acp"], status: "not-found" }],
instancesDirectory: root,
log: () => undefined
});
assert.deepEqual(loadConfigFile(target).config.bot.agent, existingConfig().bot.agent);
});
test("new setup still fails when no ACP agent is ready", async (t) => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "gori-setup-new-no-ready-"));
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
const prompt = new FakePrompt();
await assert.rejects(runSetup(path.join(root, "new-bot", "config.json"), {
botId: "new-bot",
requireNew: true,
writeWithoutConfirmation: true,
prompt,
discoverAgents: async () => [],
instancesDirectory: root,
log: () => undefined
}), /No ACP agent is available/);
assert.equal(prompt.closeCount, 1);
});
test("existing setup rejects attempts to change bot identity", async (t) => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "gori-setup-identity-"));
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
const target = path.join(root, "existing-bot", "config.json");
writeConfigFile(target, existingConfig());
await assert.rejects(runSetup(target, {
botId: "different-bot",
prompt: new FakePrompt(),
discoverAgents: async () => []
}), /Cannot change existing bot\.id/);
});