Google Drive под ключами сервисных аккаунтов вместо rclone: клиент Drive API, папка приёма и выгрузка материалов; команда khb-drive для агентов (builder - строителям и проектным чатам, полный - руководителю); rclone удалён; промты; тесты
All checks were successful
ci / test (push) Successful in 25s
ci / deploy (push) Successful in 3m13s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-22 09:41:33 +03:00
parent c1f7c7b269
commit bfce62d66f
22 changed files with 805 additions and 103 deletions

View File

@@ -14,6 +14,7 @@ import { buildApi } from "./http-api.js";
import { listManagers } from "./managers.js";
import { pauseState } from "./pause.js";
import { handleManagerMessages } from "./slack/chat.js";
import type { DriveClient } from "./gdrive/client.js";
import { DriveInbox } from "./slack/drive-inbox.js";
import { SlackIntake } from "./slack/intake.js";
@@ -539,7 +540,7 @@ d("консольные агенты (временная БД, фейковый
expect(prompt).not.toContain("A huddle started");
expect(posted).toEqual(["ответ проект llmtest"]);
});
it("папка приёма Drive: файлы и текст из <folder>/<channel> становятся сообщениями чата", async () => {
it("папка приёма Drive: файлы и текст из builder_assistant/<channel> становятся сообщениями чата", async () => {
calls = [];
const posted: string[] = [];
script = [ok("## Ответ менеджеру\nответ drive llmtest\n## Память\nм6")];
@@ -550,20 +551,18 @@ d("консольные агенты (временная БД, фейковый
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 },
{ id: "idnote0001xx", name: "note.txt", mimeType: "text/plain", modifiedTime: "2026-01-01T10:00:00Z" },
{ id: "idvoice002xx", name: "voice.m4a", mimeType: "audio/mp4", modifiedTime: "2026-01-01T10:00:05Z" },
{ id: "x", name: "_processed", mimeType: "application/vnd.google-apps.folder" },
];
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,
});
const client = {
findChild: async (_p: string, name: string) => (name === "CLLMTEST" ? { id: "CHAN", name } : null),
children: async () => listed,
ensureFolder: async () => ({ id: "PROC", name: "_processed" }),
downloadTo: async (id: string, dest: string) => writeFileSync(dest, id.startsWith("idnote") ? "llmtest drive text message" : "audio"),
move: async (id: string) => { moved.push(id); listed = listed.filter((f) => f.id !== id); return {}; },
} as unknown as DriveClient;
const inbox = new DriveInbox({ client, rootFolderId: "ROOT", localRoot: join(tmpdir(), "llmtest-inbox"), channels: async () => ["CLLMTEST"], accept: (f) => intake.onDriveFile(f) });
expect(await inbox.scan()).toBe(2);
expect(moved).toHaveLength(2);
expect(await inbox.scan()).toBe(0);
@@ -575,4 +574,31 @@ d("консольные агенты (временная БД, фейковый
expect(calls[0]!.prompt).toContain("voice.m4a");
expect(posted).toEqual(["ответ drive llmtest"]);
});
it("Google Drive агентов: строителям (в том числе проектным чатам) - ключ builder, руководителю - полный; без ключей переменной нет", async () => {
const liveCalls: ClaudeCall[] = [];
const reply = (t: string) => ["## Ответ менеджеру", t, "## Ответ Arthur", t, "## Память", "м"].join(String.fromCharCode(10));
const liveRunner = {
run: async (c: ClaudeCall) => { liveCalls.push(c); return { text: reply("ок"), sessionId: c.sessionId }; },
isActive: () => false, activeSession: () => null, close: () => undefined, closeAll: () => undefined, activeCount: () => 0,
};
const base = ctx();
const slack = { postMessage: async () => true, fileInfo: async () => null, download: async () => 0 };
const driveKeys = { full: '{"k":"FULL"}', builder: '{"k":"BUILDER"}' };
const withLive = { ...base, liveRunner, settings: { ...base.settings, live: { managerIds: [MGR], idleMinutes: 10, warmupSeconds: 0 } } };
const mgr = { personId: MGR, name: "llmtest-Manager", slackUserId: "ULLMTEST", slackChannelId: "CLLMTEST" };
const msg = (ts: string) => [{ channel: "CLLMTEST", ts, text: "проверка ключа", fileIds: [] }];
await handleManagerMessages({ ctx: withLive, timezone: "America/New_York", slack, driveKeys, dryPublish: true }, mgr, msg("1791741500.000001"));
expect(liveCalls[0]!.env).toEqual({ KHB_DRIVE_KEY: '{"k":"BUILDER"}' });
// проектный канал (менеджер проекта - строитель) тоже builder
await handleManagerMessages({ ctx: withLive, timezone: "America/New_York", slack, driveKeys, dryPublish: true }, mgr, [{ channel: "CPROJ", ts: "1791741510.000001", text: "в проектном канале", fileIds: [], project: { jobId: "J1", jobName: "Проект", channel: "CPROJ", senderName: null, isHuddle: false } } as never]);
expect(liveCalls[1]!.env).toEqual({ KHB_DRIVE_KEY: '{"k":"BUILDER"}' });
// руководитель - полный ключ
await handleManagerMessages({ ctx: withLive, timezone: "America/New_York", slack, driveKeys, dryPublish: true }, { ...mgr, chatKind: "ceo" as const }, msg("1791741520.000001"));
expect(liveCalls[2]!.env).toEqual({ KHB_DRIVE_KEY: '{"k":"FULL"}' });
// ключ builder не задан - строителю доступ к Drive не выдаётся (полный ключ ему не отдаётся)
await handleManagerMessages({ ctx: withLive, timezone: "America/New_York", slack, driveKeys: { full: '{"k":"FULL"}' }, dryPublish: true }, mgr, msg("1791741530.000001"));
expect(liveCalls[3]!.env).toBeUndefined();
});
});