Папка приёма Google Drive <id чата>: опрос раз в 10 секунд, файлы = сообщения менеджера; swap 32 ГБ; docs
All checks were successful
ci / test (push) Successful in 15s
ci / deploy (push) Successful in 1m9s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 09:38:48 +03:00
parent d14bc02661
commit 5718f0c10b
38 changed files with 247 additions and 113 deletions

View File

@@ -1,3 +1,5 @@
import { writeFileSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { createLogger, createTestDb, testDatabaseUrl, type TestDb } from "khb_common";
@@ -7,6 +9,7 @@ import { parseSections } from "./agents/sections.js";
import { AgentFailure, runManagerAgent, type AgentContext } from "./agents/session.js";
import { runStep2 } from "./agents/step2.js";
import { handleManagerMessages } from "./slack/chat.js";
import { DriveInbox } from "./slack/drive-inbox.js";
import { SlackIntake } from "./slack/intake.js";
describe("разбор разделов ответа агента", () => {
@@ -203,4 +206,40 @@ d("консольные агенты (временная БД, фейковый
const log = await db.pool.query("select message_ts, status from slack_message_log where message_ts like '1.%' order by message_ts");
expect(log.rows).toEqual([{ message_ts: "1.5", status: "done" }, { message_ts: "1.6", status: "done" }]);
});
it("папка приёма Drive: файлы и текст из <folder>/<channel> становятся сообщениями чата", async () => {
calls = [];
const posted: string[] = [];
script = [ok("## Ответ менеджеру\nответ drive llmtest\n## Память\nм6")];
const deps = {
ctx: ctx(), timezone: "America/New_York",
slack: { postMessage: async (_c: string, t: string) => { posted.push(t); return true; }, fileInfo: async () => null, download: async () => 0 },
};
const intake = new SlackIntake(deps, { channelIds: [], debounceMs: 600_000 });
const moved: string[] = [];
let listed = [
{ Name: "note.txt", ID: "idnote0001xx", ModTime: "2026-01-01T10:00:00Z" },
{ Name: "voice.m4a", ID: "idvoice002xx", ModTime: "2026-01-01T10:00:05Z" },
{ Name: "_processed", ID: "x", IsDir: true },
];
const exec = async (_bin: string, args: string[]) => {
if (args[0] === "lsjson") return JSON.stringify(listed);
if (args[0] === "copyto") { writeFileSync(args[2]!, args[1]!.endsWith(".txt") ? "llmtest drive text message" : "audio"); return ""; }
if (args[0] === "moveto") { moved.push(args[1]!); listed = []; return ""; }
return "";
};
const inbox = new DriveInbox({
rcloneBin: "rclone", remote: "gd", folder: "ba", localRoot: join(tmpdir(), "llmtest-inbox"),
channels: async () => ["CLLMTEST"], accept: (f) => intake.onDriveFile(f), exec,
});
expect(await inbox.scan()).toBe(2);
expect(moved).toHaveLength(2);
expect(await inbox.scan()).toBe(0);
await intake.flush(MGR);
await intake.idle();
intake.stop();
expect(calls).toHaveLength(1);
expect(calls[0]!.prompt).toContain("llmtest drive text message");
expect(calls[0]!.prompt).toContain("voice.m4a");
expect(posted).toEqual(["ответ drive llmtest"]);
});
});