Fallback JobTread (проверка при старте, повтор записи до 5 минут, повтор запуска в коде); требование: без ответа менеджера - только короткое напоминание (новая версия); тесты; docs
All checks were successful
ci / test (push) Successful in 25s
ci / deploy (push) Successful in 1m31s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 18:10:01 +03:00
parent ddbf3da93f
commit 059ece8578
16 changed files with 163 additions and 32 deletions

View File

@@ -53,7 +53,7 @@ d("консольные агенты (временная БД, фейковый
const it_messages: string[] = [];
const ctx = (): AgentContext => ({
pool: db.pool, log: createLogger("test", "silent"),
settings: { concurrency: 2, claudeBin: "claude", workRoot: tmpdir() + "/llmtest-agents", timeoutMs: 1000, maxFixRetries: 2, allowedJobIds: ["llmtest-job"] },
settings: { concurrency: 2, claudeBin: "claude", workRoot: tmpdir() + "/llmtest-agents", timeoutMs: 1000, maxFixRetries: 2, allowedJobIds: ["llmtest-job"], connectorRetry: { windowSeconds: 0, pauseSeconds: 0 } },
runner: async (c) => { calls.push(c); const fn = script.shift(); if (!fn) throw new Error("нет сценария"); return fn(c, calls.length); },
gate: new Semaphore(2), locks: new KeyedMutex(),
notifyIt: async (t) => { it_messages.push(t); },
@@ -191,7 +191,8 @@ d("консольные агенты (временная БД, фейковый
expect(calls).toHaveLength(0); // прежний раннер не использовался
expect(liveCalls).toHaveLength(2);
expect(liveCalls[0]!.prompt).toContain("# Память");
expect(liveCalls[0]!.prompt).toContain("ToolSearch с запросом select:mcp__claude_ai_JobTread__query");
expect(liveCalls[0]!.prompt).toContain("JobTread недоступен или запись не проходит");
expect(liveCalls[0]!.prompt).toMatch(/менеджер сегодня отвечал: (да|нет)/);
expect(liveCalls[0]!.prompt).toContain("Todo самого менеджера");
expect(liveCalls[0]!.prompt).toContain("его membership в JobTread: m1");
expect(liveCalls[1]!.prompt).toContain("# Продолжение диалога");
@@ -441,6 +442,33 @@ d("консольные агенты (временная БД, фейковый
const r = await db.pool.query("select claude_session_id from agent_manager_memory where manager_person_id = $1", [MGR]);
expect(r.rows[0].claude_session_id).toBeNull();
});
it("коннектор JobTread не поднялся: запуск повторяется в новой сессии, ответ неудачной попытки менеджеру не уходит", async () => {
calls = [];
const nl = String.fromCharCode(10);
const down = ["## Ответ менеджеру", "I can't write to JobTread right now", "## Память", "м-неудача", "## Изменения JobTread", "нет. Коннектор JobTread недоступен"].join(nl);
const good = ["## Ответ менеджеру", "Done: updated.", "## Память", "м-успех", "## Изменения JobTread", "записано"].join(nl);
script = [ok(down), ok(down), ok(good)];
const c = ctx();
const live = { ...c, settings: { ...c.settings, connectorRetry: { windowSeconds: 600, pauseSeconds: 0 } } };
const r = await runManagerAgent(live, { managerId: MGR, step: "step4", tools: "chat", prompt: "короткий промт", fullPrompt: "ПОЛНЫЙ промт", required: ["ответ менеджеру", "память"] });
expect(r.sections.get("ответ менеджеру")).toBe("Done: updated.");
expect(calls).toHaveLength(3);
expect(calls[1]!.prompt).toContain("ПОЛНЫЙ промт");
expect(calls[1]!.prompt).toContain("повтор запуска №1");
expect(calls[2]!.prompt).toContain("повтор запуска №2");
expect(calls[1]!.resume).toBe(false);
expect(calls[1]!.sessionId).not.toBe(calls[0]!.sessionId);
const runs = await db.pool.query("select status, error from agent_run where manager_person_id = $1 order by started_at desc limit 3", [MGR]);
expect(runs.rows.filter((x) => x.status === "failed" && /повтор запуска/.test(x.error ?? ""))).toHaveLength(2);
// окно исчерпано: отчёт о неудаче уходит как есть
calls = [];
script = [ok(down)];
const noRetry = { ...c, settings: { ...c.settings, connectorRetry: { windowSeconds: 0, pauseSeconds: 0 } } };
const r2 = await runManagerAgent(noRetry, { managerId: MGR, step: "step4", tools: "chat", prompt: "p", required: ["ответ менеджеру", "память"] });
expect(r2.sections.get("ответ менеджеру")).toContain("can't write");
expect(calls).toHaveLength(1);
});
it("API агентов: память читается и пишется с аудитом, сброс сессии, история", async () => {
const app = buildApi({ pool: db.pool, token: "t", run: async () => { throw new Error("не нужен"); } });
const h = { authorization: "Bearer t" };