peppa/packages/testkit/test/wait-reason.test.ts
peppa-bot 61e8368024
All checks were successful
peppa/lint lint: success за 2с
peppa/typecheck typecheck: success за 47с
peppa/build build: success за 32с
peppa/bundle bundle: success за 0с
peppa/test test: success за 1647с
peppa-ci / ci (pull_request) Successful in 29m28s
PEP-193: причина ожидания на странице задачи — лимит подписки со временем продолжения и сколько уже работает агент
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 11:07:55 +00:00

59 lines
4.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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");
});
});