| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- import { describe, expect, it } from "vitest";
- import * as f from "./botsService.fixtures.js";
- const actor = {
- provider: "webhook" as const,
- botId: "webhook-1",
- providerUserId: "user-1",
- chatType: "private" as const,
- };
- describe("botsService status", () => {
- it("reports bot counts and runtime contexts", async () => {
- const repo = f.createMemoryRepo(f.baseConfig);
- const service = f.createBotsService({
- credentialService: f.createCredentialService({ "secret-1": "secret" }),
- legacyTaskService: f.createLegacyTaskService(),
- repo: repo as never,
- });
- const code = await service.createBindCode({ botId: "webhook-1" });
- await service.handleInboundMessage({ botId: "webhook-1", text: `/bind ${code.code}`, actor });
- await service.handleInboundMessage({ botId: "webhook-1", text: "/new", actor });
- await expect(service.getStatus()).resolves.toMatchObject({
- botsCount: 1,
- enabledBotsCount: 1,
- contextsCount: 1,
- });
- await expect(service.getBotStates()).resolves.toMatchObject([
- {
- botId: "webhook-1",
- mode: "draft",
- activeTaskId: null,
- },
- ]);
- service.disposeAll();
- });
- it("returns user-facing /status for a bound bot", async () => {
- const repo = f.createMemoryRepo(f.baseConfig);
- const service = f.createBotsService({
- credentialService: f.createCredentialService({ "secret-1": "secret" }),
- legacyTaskService: f.createLegacyTaskService(),
- repo: repo as never,
- });
- const code = await service.createBindCode({ botId: "webhook-1" });
- await service.handleInboundMessage({ botId: "webhook-1", text: `/bind ${code.code}`, actor });
- const replies = await service.handleInboundMessage({
- botId: "webhook-1",
- text: "/status",
- actor,
- });
- expect(replies[0]?.text).toContain("工作区");
- expect(replies[0]?.text).not.toContain("Provider:");
- expect(replies[0]?.text).toContain("模型: default");
- service.disposeAll();
- });
- it("returns English /status when the app locale is en-US", async () => {
- const repo = f.createMemoryRepo(f.baseConfig);
- const service = f.createBotsService({
- credentialService: f.createCredentialService({ "secret-1": "secret" }),
- legacyTaskService: f.createLegacyTaskService(),
- settingService: f.createSettingService({
- locale: "en-US",
- lastWorkspaceSession: [
- {
- kind: "remote",
- workspacePath: "/tmp/workspace",
- workspaceIdentity: "ssh://host/tmp/workspace",
- },
- ],
- }),
- repo: repo as never,
- });
- const code = await service.createBindCode({ botId: "webhook-1" });
- await service.handleInboundMessage({ botId: "webhook-1", text: `/bind ${code.code}`, actor });
- const replies = await service.handleInboundMessage({
- botId: "webhook-1",
- text: "/status",
- actor,
- });
- expect(replies[0]?.text).toContain("Workspace: workspace");
- expect(replies[0]?.text).toContain("Model: default");
- expect(replies[0]?.text).toContain("Task: draft");
- service.disposeAll();
- });
- it("reports active task model from task/config options", async () => {
- const repo = f.createMemoryRepo(
- {
- ...f.baseConfig,
- bots: [
- {
- ...f.baseConfig.bots[0]!,
- providerUserId: "user-1",
- },
- ],
- },
- {
- version: 3,
- bots: {
- "webhook-1": {
- botId: "webhook-1",
- workspacePath: "/tmp/workspace",
- workspaceIdentity: "ssh://host/tmp/workspace",
- workspaceId: "ssh://host/tmp/workspace",
- mode: "task",
- activeTaskId: "task-1",
- updatedAt: Date.now(),
- },
- },
- },
- );
- const legacyTaskService = f.createLegacyTaskService();
- legacyTaskService.listTasks = async () => [
- {
- taskId: "task-1",
- title: "Active task",
- workspacePath: "/tmp/workspace",
- workspaceIdentity: "ssh://host/tmp/workspace",
- provider: "codex",
- model: "meta-model",
- status: "completed",
- traceId: "trace",
- createdAt: 1,
- updatedAt: 1,
- mode: "default",
- },
- ];
- legacyTaskService.getTaskConfigOptions = async () => [
- {
- id: "model",
- category: "model",
- type: "select",
- currentValue: "gpt-5.4",
- options: [{ value: "gpt-5.4", name: "GPT-5.4" }],
- },
- ];
- const service = f.createBotsService({
- credentialService: f.createCredentialService({ "secret-1": "secret" }),
- legacyTaskService,
- repo: repo as never,
- });
- const replies = await service.handleInboundMessage({
- botId: "webhook-1",
- text: "/status",
- actor,
- });
- expect(replies[0]?.text).not.toContain("Provider:");
- expect(replies[0]?.text).toContain("模型: gpt-5.4");
- service.disposeAll();
- });
- it("renders custom provider display name in status model", async () => {
- const providerId = "672a331d-423f-4c83-ab40-93288d9655a6";
- const repo = f.createMemoryRepo(
- {
- ...f.baseConfig,
- bots: [
- {
- ...f.baseConfig.bots[0]!,
- providerUserId: "user-1",
- },
- ],
- },
- {
- version: 3,
- bots: {
- "webhook-1": {
- botId: "webhook-1",
- workspacePath: "/tmp/workspace",
- workspaceIdentity: "ssh://host/tmp/workspace",
- workspaceId: "ssh://host/tmp/workspace",
- mode: "task",
- activeTaskId: "task-1",
- updatedAt: Date.now(),
- },
- },
- },
- );
- const legacyTaskService = f.createLegacyTaskService();
- legacyTaskService.listTasks = async () => [
- {
- taskId: "task-1",
- title: "Active task",
- workspacePath: "/tmp/workspace",
- workspaceIdentity: "ssh://host/tmp/workspace",
- provider: "glm",
- model: `${providerId}/deepseek-v4-flash`,
- status: "completed",
- traceId: "trace",
- createdAt: 1,
- updatedAt: 1,
- mode: "yolo",
- },
- ];
- const service = f.createBotsService({
- credentialService: f.createCredentialService({ "secret-1": "secret" }),
- legacyTaskService,
- modelSelectionService: f.createModelSelectionService([
- {
- id: providerId,
- name: "DeepSeek",
- endpoints: { baseURL: "https://example.com", paths: {} },
- apiKey: "sk-test",
- models: ["deepseek-v4-flash"],
- createdAt: 1,
- updatedAt: 1,
- },
- ]),
- repo: repo as never,
- });
- const replies = await service.handleInboundMessage({
- botId: "webhook-1",
- text: "/status",
- actor,
- });
- expect(replies[0]?.text).toContain("模型: DeepSeek/deepseek-v4-flash");
- expect(replies[0]?.text).not.toContain(`${providerId}/deepseek-v4-flash`);
- service.disposeAll();
- });
- });
|