todo_service: новый сервис todo (надстройка над JobTread, REST, MCP, вебхуки, слежение Control), миграция 024, docs в proposed
All checks were successful
ci / test (push) Successful in 27s
ci / deploy (push) Successful in 2m10s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 11:08:54 +03:00
parent 816164902e
commit ad17e8364f
40 changed files with 2601 additions and 4 deletions

View File

@@ -0,0 +1,64 @@
import { afterAll, describe, expect, it } from "vitest";
import { createLogger, createTestDb, jobtreadSchema, readSettingsFile, testDatabaseUrl, type TestDb } from "khb_common";
import { ADMIN } from "./access.js";
import { TodoCore } from "./core.js";
import { PaveJt } from "./jt.js";
import { todoServiceSchema } from "./settings.js";
/**
* Живая проверка против JobTread: только тестовый проект 22PdjKPJvzbk, названия с префиксом llmtest-, созданное удаляется.
* Запуск: KHB_LIVE_JT=1 npx vitest run packages/todo_service/src/live.int.test.ts (нужны settings.json5 и туннель к БД).
*/
const TEST_JOB = "22PdjKPJvzbk";
const live = process.env.KHB_LIVE_JT === "1" && !!testDatabaseUrl();
const d = live ? describe : describe.skip;
d("todo_service: живой JobTread (тестовый проект)", () => {
const jtCfg = live ? jobtreadSchema.parse(readSettingsFile().jobtread) : { grantKey: "", organizationId: "" };
const jt = new PaveJt(jtCfg);
const created: string[] = [];
let db: TestDb | undefined;
afterAll(async () => {
for (const id of created) await jt.deleteTask(id).catch(() => undefined);
await db?.drop();
});
it("создать, прочитать, изменить, закрыть и удалить todo; startDate всегда равен endDate", async () => {
const t = await jt.createTask({ jobId: TEST_JOB, name: "llmtest-todo-service live", description: "live", endDate: "2026-12-01" });
created.push(t.id);
expect(t).toMatchObject({ jobId: TEST_JOB, isToDo: true, endDate: "2026-12-01", startDate: "2026-12-01", progress: null });
await jt.updateTask(t.id, { name: "llmtest-todo-service live 2", endDate: "2026-12-03", progress: 1 });
const g = await jt.getTask(t.id);
expect(g).toMatchObject({ name: "llmtest-todo-service live 2", endDate: "2026-12-03", startDate: "2026-12-03", progress: 1 });
await jt.deleteTask(t.id);
created.pop();
expect(await jt.getTask(t.id)).toBeNull();
});
it("ядро поверх JobTread: create / snooze / close, чтение через копию, события опроса", async () => {
db = await createTestDb(testDatabaseUrl()!);
const settings = todoServiceSchema.parse({ http: { token: "x" }, allowedJobIds: [TEST_JOB] });
const core = new TodoCore({ pool: db.pool, jt, settings, tz: "America/New_York", log: createLogger("t", "silent") });
const r = (await core.create(ADMIN, { jobId: TEST_JOB, name: "llmtest-todo-service core", kind: "reminder" }, "live-key")) as { id: string };
created.push(r.id);
const v = await core.get(ADMIN, r.id);
expect(v).toMatchObject({ kind: "reminder", status: "open", jobId: TEST_JOB });
await core.snooze(ADMIN, r.id, { until: "2026-12-10" });
expect((await core.get(ADMIN, r.id)).reviewDate).toBe("2026-12-10");
await core.close(ADMIN, r.id);
expect((await core.get(ADMIN, r.id)).status).toBe("done");
const ids = await jt.recentTaskEvents(new Date(Date.now() - 10 * 60_000).toISOString());
expect(ids.some((e) => e.taskId === r.id)).toBe(true);
expect(await core.pollEvents()).toBeGreaterThan(0);
await core.remove(ADMIN, r.id);
created.pop();
expect((await core.get(ADMIN, r.id).catch(() => ({ status: "deleted" }))).status).toBe("deleted");
});
it("открытые todo читаются постранично", async () => {
const open = await jt.listOpenTodos();
expect(open.length).toBeGreaterThan(10);
expect(open.every((t) => t.isToDo && (t.progress ?? 0) < 1)).toBe(true);
});
});