All checks were successful
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
4.0 KiB
TypeScript
59 lines
4.0 KiB
TypeScript
// PEP-193: the story page says why the work waits — a subscription limit with the time the agent
|
||
// goes on, and how long a working agent has been at it. Tests are named after the spec scenarios.
|
||
import { stripAsIs } from "@peppa/shared/i18n";
|
||
import assert from "node:assert/strict";
|
||
import { after, describe, test } from "node:test";
|
||
import type { StoryProductInput } from "@peppa/core";
|
||
import { core, db, project, teardown } from "./helpers.ts";
|
||
|
||
process.env.PEPPA_SECRET = "mock-secret-for-tests";
|
||
after(teardown);
|
||
|
||
const view = (i: Partial<StoryProductInput>) => core.storyProductView({ status: "in_progress", agentWorking: true, openQuestions: 0, ...i });
|
||
const TZ = "Asia/Almaty"; // UTC+5
|
||
const NOW = new Date("2026-11-30T09:00:00Z"); // 14:00 in Almaty
|
||
|
||
describe("PEP-193: причина ожидания на странице задачи", () => {
|
||
test("Лимит подписки со временем продолжения", () => {
|
||
const line = stripAsIs(core.limitWaitLine(new Date("2026-11-30T13:00:00Z"), { now: NOW, timeZone: TZ }));
|
||
assert.equal(line, "Лимит подписки — агент продолжит в 18:00");
|
||
const v = view({ agentName: "Квант", limitLine: line });
|
||
assert.equal(v.now, "Лимит подписки — агент продолжит в 18:00");
|
||
assert.equal(v.need, null, "nothing is needed from the owner");
|
||
assert.match(v.next, /сам/);
|
||
});
|
||
|
||
test("Лимит подписки: продолжение завтра", () => {
|
||
assert.equal(stripAsIs(core.limitWaitLine(new Date("2026-12-01T03:00:00Z"), { now: NOW, timeZone: TZ })), "Лимит подписки — агент продолжит завтра в 08:00");
|
||
});
|
||
|
||
test("Лимит без запланированного продолжения", () => {
|
||
assert.equal(stripAsIs(core.limitWaitLine(null, { now: NOW, timeZone: TZ })), "Лимит подписки — продолжим, когда он сбросится");
|
||
});
|
||
|
||
test("Агент работает уже N минут", () => {
|
||
assert.equal(stripAsIs(view({ agentName: "Квант", workingMin: 25.7 }).now), "Агент Квант работает над задачей уже 25 мин");
|
||
assert.equal(stripAsIs(view({ agentName: "Квант", workingMin: 130 }).now), "Агент Квант работает над задачей уже 2 ч 10 мин");
|
||
assert.equal(stripAsIs(view({ workingMin: 120 }).now), "Агент работает над задачей уже 2 ч");
|
||
assert.equal(stripAsIs(view({ workingMin: 3 * 24 * 60 + 5 }).now), "Агент работает над задачей уже 3 дн.");
|
||
});
|
||
|
||
test("Агент только что запущен", () => {
|
||
assert.equal(view({ agentName: "Квант", workingMin: 0.4 }).now, "Агент Квант работает над задачей");
|
||
assert.equal(view({ agentName: "Квант", workingMin: null }).now, "Агент Квант работает над задачей");
|
||
});
|
||
|
||
test("Вопрос важнее лимита", () => {
|
||
assert.equal(view({ openQuestions: 1, limitLine: "Лимит подписки — агент продолжит в 18:00" }).now, "Агент ждёт вашего ответа");
|
||
});
|
||
|
||
test("Строка задержки FORGE с причиной «лимит» называет время сброса лимита", async () => {
|
||
const p = await project({ turns: [] });
|
||
const task = await p.task();
|
||
const s = await core.createSession(db, { projectId: task.projectId, taskId: task.id });
|
||
await core.updateSession(db, s.id, { resumeAt: new Date("2026-11-30T13:00:00Z"), status: "rate_limited" });
|
||
await core.platformDelay(db, { projectId: task.projectId, taskId: task.id, sessionId: s.id }, { reason: "limit", details: "limit", state: "waiting", now: NOW });
|
||
assert.equal(stripAsIs((await core.taskDelayLine(db, task.id, { now: NOW, timeZone: TZ }))!), "Лимит подписки — агент продолжит в 18:00");
|
||
});
|
||
});
|