72 lines
3.9 KiB
TypeScript
72 lines
3.9 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { planNeedsInput, infoRequiredDetail, isPlatformEvalFailure, wrongStatusMessage, openApiTaskView } from "../src/openapi_task_view";
|
|
import type { Task } from "../src/types";
|
|
|
|
// 2026-11-09 ba39f8c8 的真实形状:第一轮 REPRODUCIBLE 留下 NEEDS_INPUT,第二轮因工作树残留崩溃落到 info_required。
|
|
const PLAN = [
|
|
"## 复现条件",
|
|
"- 账号/环境: <<<<<<< NEEDS_INPUT: TikTok Notes 包怎样切到 PPE `ppe_rest_bot` 泳道? >>>>>>>",
|
|
"- 触发问题: <<<<<<< NEEDS_INPUT: 要发什么问题\n才能稳定拿到餐厅卡 >>>>>>>",
|
|
"- 设备: <<<<<<< NEEDS_INPUT: 设备型号 @OPTION iPhone 15 | 工单原话 | iPhone 15 @OPTION 模拟器 | 代码 | macCatalyst >>>>>>>",
|
|
].join("\n");
|
|
const CRASH = "评估异常: Product worktree preparation failed: fatal: '/Users/x/eval-worktrees/ba39/TikTok' already exists";
|
|
|
|
describe("planNeedsInput", () => {
|
|
test("pulls one hint per sentinel, folds whitespace, drops @OPTION candidates", () => {
|
|
expect(planNeedsInput(PLAN)).toEqual([
|
|
"TikTok Notes 包怎样切到 PPE `ppe_rest_bot` 泳道?",
|
|
"要发什么问题 才能稳定拿到餐厅卡",
|
|
"设备型号",
|
|
]);
|
|
});
|
|
test("no plan / no sentinel → empty", () => {
|
|
expect(planNeedsInput(null)).toEqual([]);
|
|
expect(planNeedsInput("## 复现步骤\n1. 打开 App")).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("infoRequiredDetail", () => {
|
|
test("evaluator crash / usage limit → platform_error, raw node error is NOT echoed", () => {
|
|
const d = infoRequiredDetail({ status: "info_required", failureReason: CRASH });
|
|
expect(d?.kind).toBe("platform_error");
|
|
expect(JSON.stringify(d)).not.toContain("eval-worktrees");
|
|
expect(isPlatformEvalFailure("执行节点的 Claude 账号额度已用尽,多次重排仍未等到恢复")).toBe(true);
|
|
});
|
|
test("a real NEEDS_INFO verdict → needs_info with the evaluator's reason", () => {
|
|
expect(infoRequiredDetail({ status: "info_required", failureReason: "工单缺少复现入口" }))
|
|
.toEqual({ kind: "needs_info", reason: "工单缺少复现入口" });
|
|
});
|
|
test("other statuses → null", () => {
|
|
expect(infoRequiredDetail({ status: "pending_confirmation", failureReason: null })).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("openApiTaskView", () => {
|
|
const base = { id: "t1", title: "x", platform: "ios", createdAt: 1, finishedAt: null, mrUrl: null, mrState: null, baseRef: "notes/feature/restaurant-radar" } as unknown as Task;
|
|
test("pending_confirmation exposes needsInput and baseRef", () => {
|
|
const v = openApiTaskView({ ...base, status: "pending_confirmation", executionPlan: PLAN, failureReason: null } as Task);
|
|
expect(v.needsInput).toHaveLength(3);
|
|
expect(v.infoRequired).toBeNull();
|
|
expect(v.baseRef).toBe("notes/feature/restaurant-radar");
|
|
});
|
|
test("platform_error hides the stale plan's needsInput (it is not why this bounce happened)", () => {
|
|
const v = openApiTaskView({ ...base, status: "info_required", executionPlan: PLAN, failureReason: CRASH } as Task);
|
|
expect(v.infoRequired?.kind).toBe("platform_error");
|
|
expect(v.needsInput).toEqual([]);
|
|
});
|
|
test("needs_info exposes reason + needsInput", () => {
|
|
const v = openApiTaskView({ ...base, status: "info_required", executionPlan: PLAN, failureReason: "缺入口" } as Task);
|
|
expect(v.infoRequired).toEqual({ kind: "needs_info", reason: "缺入口" });
|
|
expect(v.needsInput).toHaveLength(3);
|
|
});
|
|
});
|
|
|
|
describe("wrongStatusMessage", () => {
|
|
test("info_required splits platform error from missing info", () => {
|
|
expect(wrongStatusMessage("info_required", CRASH)).toContain("与工单内容无关");
|
|
expect(wrongStatusMessage("info_required", CRASH)).not.toContain("重试不会好转");
|
|
expect(wrongStatusMessage("info_required", "缺入口")).toContain("重试不会好转");
|
|
expect(wrongStatusMessage("info_required")).toContain("重试不会好转");
|
|
});
|
|
});
|