agentpaas.test.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import { expect, test } from "bun:test"
  2. import { paasCard } from "../../src/util/agentpaas"
  3. test("reviewed synthesis is distinguished from computation and scientific acceptance", () => {
  4. const card = paasCard({ status: "completed", research: { science: {
  5. status: "needs_evidence", synthesis: { status: "reviewed", answered: 1, total: 2 },
  6. study_schedule: { computed: 1, total: 2, units: [
  7. { study_id: "T1", status: "computed", interpretation_status: "reviewed", finding: "answered_within_scope", depends_on: [] },
  8. { study_id: "T2", status: "ready_to_plan", interpretation_status: "reviewed", finding: "inconclusive", depends_on: ["T1"] },
  9. ] },
  10. } } })
  11. const lines = card.lines.join("\n")
  12. expect(lines).toContain("T1 · 已形成限定范围回答")
  13. expect(lines).toContain("T2 · 结果尚不足以判断")
  14. expect(lines).toContain("1/2 项限定范围回答;不是独立科学验收")
  15. expect(lines).toContain("needs_evidence")
  16. expect(lines).not.toContain("待解释")
  17. })
  18. test("study schedule shows dependency readiness separately from scientific success", () => {
  19. const card = paasCard({ status: "completed", research: { science: {
  20. capabilities: { status: "per_round_selection" },
  21. study_schedule: { computed: 1, total: 3, units: [
  22. { study_id: "T1", status: "computed", depends_on: [] },
  23. { study_id: "T2", status: "ready_to_plan", depends_on: ["T1"] },
  24. { study_id: "T3", status: "waiting_prerequisite", depends_on: ["T2"] },
  25. ] },
  26. } } })
  27. expect(card.lines.join("\n")).toContain("1/3 项计算完成(不等于科学结论成立)")
  28. expect(card.lines.join("\n")).toContain("T2 · 待规划;依赖 T1")
  29. expect(card.lines.join("\n")).toContain("T3 · 等待前置计算;依赖 T2")
  30. expect(card.lines.join("\n")).toContain("逐轮选择已注册执行器")
  31. })
  32. test("stopped research recommendations are not displayed as automatically running", () => {
  33. const card = paasCard({ status: "completed", research: { science: {
  34. next_step: "补充定义后继续推导", control: { continue_automatically: false },
  35. capabilities: { status: "plans_only_no_registered_input" },
  36. } } })
  37. expect(card.lines.join("\n")).toContain("上述后续建议尚未自动执行")
  38. expect(card.lines.join("\n")).toContain("实际计算需先注册数据")
  39. })
  40. test("research card displays next research action and observation review separately", () => {
  41. const card = paasCard({ status: "completed", research: { science: {
  42. status: "needs_evidence", next_step: "补充模型适用性证据", observations: { recorded: 2, interpreted: 1, reviewed: 0 },
  43. } } })
  44. expect(card.lines.join("\n")).toContain("下一步研究:补充模型适用性证据")
  45. expect(card.lines.join("\n")).toContain("观察 2 份 · 已解释 1 份 · 模型审阅认可 0 份")
  46. })
  47. test("scientific card separates planned actions, executed kernels and reused observations", () => {
  48. for (const status of ["plans_only", "blocked", "reused_observations", "executed"]) {
  49. const card = paasCard({ status: "completed", research: { science: {
  50. status: "needs_evidence", research_ir: { status, planned_actions: 7,
  51. executed_kernels: status === "executed" ? 1 : 0, engine: status === "executed" ? "lambda_cek" : null },
  52. } } })
  53. expect(card.lines.join("\n")).toContain("needs_evidence")
  54. expect(card.lines.join("\n")).toContain("研究计划 7 项行动,不代表全部已执行")
  55. expect(card.lines.join("\n")).toContain(`本轮执行 ${status === "executed" ? 1 : 0} 个实验子程序`)
  56. }
  57. })
  58. test("a completed client tool can display a running backend task and unknown billing", () => {
  59. const card = paasCard({ status: "running", run_id: "run_long", agent_name: "Data67" })
  60. expect(card.title).toBe("Data67 · 运行中")
  61. expect(card.lines.join("\n")).toContain("watch")
  62. expect(card.lines.join("\n")).toContain("USD: 未报告")
  63. })
  64. test("pending ordinary confirmation overrides running and artifacts keep their IDs", () => {
  65. const card = paasCard({
  66. status: "running",
  67. pending_confirmation: { status: "pending" },
  68. artifacts: [{ artifact_id: "art_1", name: "结果.csv" }],
  69. })
  70. expect(card.title).toContain("等待工具确认")
  71. expect(card.lines.join("\n")).toContain("approve/reject")
  72. expect(card.lines.join("\n")).toContain("结果.csv · art_1")
  73. })
  74. test("research revision and scientific insufficiency remain separate from completed execution", () => {
  75. const card = paasCard({
  76. status: "completed",
  77. research: { revision: 2, science: { status: "needs_evidence" } },
  78. usage: { total_tokens: 12, cost_usd: 0 },
  79. })
  80. expect(card.lines.join("\n")).toContain("needs_evidence")
  81. expect(card.lines.join("\n")).toContain("研究版本:2")
  82. expect(card.lines.join("\n")).toContain("USD: 0")
  83. })
  84. test("unconfirmed cancellation does not turn a running task into cancelled", () => {
  85. const card = paasCard({ status: "running", cancellation_status: "unconfirmed" })
  86. expect(card.title).toContain("运行中")
  87. expect(card.lines.join("\n")).toContain("未确认,可能仍在运行")
  88. })
  89. test("approval deadline is visible and incomplete zero cost is not called free", () => {
  90. const card = paasCard({
  91. status: "running",
  92. pending_confirmation: { status: "pending", expires_at: "2026-10-23T10:00:00Z" },
  93. usage: { total_tokens: 12, cost_usd: 0 },
  94. })
  95. expect(card.lines.join("\n")).toContain("2026-10-23T10:00:00Z")
  96. expect(card.lines.join("\n")).toContain("0 不代表免费")
  97. })
  98. test("explicitly complete usage is distinguished from missing completeness", () => {
  99. const card = paasCard({
  100. status: "completed",
  101. usage: { total_tokens: 12, cost_usd: 0.1, usage_complete: true, cost_complete: true },
  102. })
  103. expect(card.lines.join("\n")).toContain("tokens 完整;费用 完整")
  104. })
  105. test("a stale confirmation cannot hide a terminal backend state", () => {
  106. expect(paasCard({ status: "cancelled", pending_confirmation: { status: "pending" } }).title).toContain("已取消")
  107. })
  108. test("resource gaps and missing independent evaluation stay visible after completion", () => {
  109. const card = paasCard({ status: "completed", research: { science: {
  110. resources: { methods: [{ method: "randomized_trial", status: "no_registered_operation", executors: [] }] },
  111. acceptance: { dimensions: { independent_scientific_evaluation: { status: "not_run" }, remote_or_instrument_acceptance: { status: "not_verified" } } },
  112. } } })
  113. expect(card.lines.join("\n")).toContain("缺少执行适配器")
  114. expect(card.lines.join("\n")).toContain("独立科学评价:未开展")
  115. expect(card.lines.join("\n")).toContain("不折算科学总分")
  116. })
  117. test("dataset inventory is not presented as completed scientific execution", () => {
  118. const card = paasCard({ status: "completed", research: { science: {
  119. resources: { datasets: [{ id: "water", profile: { kind: "table", row_count: 7, malformed_rows: 0 } },
  120. { id: "protocol", profile: { kind: "finite_graph", state_count: 4, transition_count: 4 } }] },
  121. research_ir: { status: "plans_only", planned_actions: 2, executed_kernels: 0 },
  122. } } })
  123. const lines = card.lines.join("\n")
  124. expect(lines).toContain("输入概况:water · 7 行")
  125. expect(lines).toContain("4 个状态 · 4 条转移;不是实验结果")
  126. expect(lines).toContain("本轮执行 0 个实验子程序")
  127. })
  128. test("numeric checks expose extracted scope without declaring complete verification", () => {
  129. for (const count of [0, 3]) {
  130. const card = paasCard({ status: "completed", research: { science: {
  131. synthesis: { status: "reviewed", answered: 1, total: 1, numeric_check: { status: "checked", quantity_claims: count } },
  132. } } })
  133. expect(card.lines.join("\n")).toContain(`提取 ${count} 条;不代表已覆盖全部表述`)
  134. }
  135. })
  136. test("numeric coverage reports unlinked occurrences separately from claim correctness", () => {
  137. const card = paasCard({ status: "completed", research: { science: {
  138. synthesis: { status: "reviewed", answered: 1, total: 1, numeric_check: {
  139. status: "checked", quantity_claims: 4, artifact: "study-synthesis-1-numbers-checks.json",
  140. coverage: { candidate_mentions: 7, linked_mentions: 4, unlinked_mentions: 3 },
  141. } },
  142. } } })
  143. expect(card.lines.join("\n")).toContain("4/7 已关联;3 未关联(可能包含计划值或标识)")
  144. expect(card.lines.join("\n")).toContain("study-synthesis-1-numbers-checks.json,不是语义核验覆盖率")
  145. })
  146. test("supplemental numeric extraction distinguishes recovered, excluded and unfinished checks", () => {
  147. const completed = paasCard({ status: "completed", research: { science: { synthesis: {
  148. numeric_check: { status: "checked", quantity_claims: 1, followup: { status: "completed",
  149. recovered_mentions: 1, not_result_mentions: 2, unresolved_mentions: 3, artifact: "numbers-unlinked.json" } },
  150. } } } })
  151. expect(completed.lines.join("\n")).toContain("恢复 1 处 · 模型判断非结果 2 处 · 暂无法对应 3 处")
  152. const pending = paasCard({ status: "completed", research: { science: { synthesis: {
  153. numeric_check: { status: "checked", quantity_claims: 0, followup: { status: "pending" } },
  154. } } } })
  155. expect(pending.lines.join("\n")).toContain("遗漏补查尚未完成;保留首次核对与未关联项,不表示全文通过")
  156. })
  157. test("result-only followups preserve plan issues and do not advertise a new execution IR", () => {
  158. for (const operation of ["review_results", "clarify"]) {
  159. const card = paasCard({status:"completed", research:{science:{
  160. operation: {operation}, research_ir: {status:"not_executed",executed_kernels:0,planned_actions:0},
  161. acceptance:{dimensions:{plan_review:{status:"not_reassessed"}}},
  162. }}})
  163. const text = card.lines.join("\n")
  164. expect(text).toContain(operation==="review_results" ? "复核已有结果" : "等待说明研究意图")
  165. expect(text).toContain("原有待修订项继续保留")
  166. expect(text).toContain("本轮执行 0 个实验子程序")
  167. expect(text).not.toContain("execution-ir.json 查看范围")
  168. }
  169. })
  170. test("candidate check counts do not imply completed studies", () => {
  171. const card = paasCard({ status: "completed", research: { science: {
  172. decision_support: { hypotheses: 2, candidate_checks: 1, independent_validation: false },
  173. study_schedule: { computed: 0, total: 2 },
  174. } } })
  175. expect(card.lines.join("\n")).toContain("2 个假设、1 项候选检查")
  176. expect(card.lines.join("\n")).toContain("0/2 项计算完成")
  177. expect(card.lines.join("\n")).toContain("research-decisions.json 查看依据与缺口")
  178. })
  179. test("shows research soft overrun and the explicit hard-limit extension separately", () => {
  180. const card = paasCard({
  181. status: "completed",
  182. research: { science: { budget: {
  183. actual_tokens: 210000, token_budget: 180000, budget_status: "exceeded",
  184. budget_message: "已超过计划预算 30000 tokens,流程已完成。",
  185. } } },
  186. })
  187. expect(card.lines.join("\n")).toContain("210000 / 计划 180000")
  188. expect(card.lines.join("\n")).toContain("超过计划预算 30000")
  189. const blocked = paasCard({
  190. status: "completed",
  191. research: { science: { budget: {
  192. actual_tokens: 210000, token_budget: 180000, budget_message: "下一步触及硬上限",
  193. extension_request: { suggested_limit: 300000 },
  194. } } },
  195. })
  196. expect(blocked.lines.join("\n")).toContain("300000 后继续;未自动增加上限")
  197. })
  198. test("research internal limits name their dimension rather than actual tokens", () => {
  199. const card = paasCard({ status: "completed", research: { science: { budget: {
  200. extension_request: { option: "max_total_input_chars", suggested_limit: 1200000 },
  201. } } } })
  202. expect(card.lines.join("\n")).toContain("将 max_total_input_chars 调整至 1200000")
  203. expect(card.lines.join("\n")).not.toContain("将 max_actual_tokens")
  204. const oversized = paasCard({ status: "completed", research: { science: { budget: {
  205. extension_request: { option: "max_input_chars_per_call", suggested_limit: null, next_action: "reduce_next_request" },
  206. } } } })
  207. expect(oversized.lines.join("\n")).toContain("压缩上下文或缩小任务")
  208. expect(oversized.lines.join("\n")).not.toContain("调整至")
  209. })
  210. test("server outcome distinguishes reused computation from interpretation revision", () => {
  211. const lines = ["计算:计算已完成;本次新增 0 次执行", "解释:解释待修订", "下一步:修订解释"]
  212. const card = paasCard({ status: "completed", research: { science: {
  213. status: "needs_revision", outcome: { schema_version: 1, headline: "计算已完成 · 解释待修订", lines },
  214. } } })
  215. expect(card.title).toContain("计算已完成 · 解释待修订")
  216. for (const line of lines) expect(card.lines).toContain(line)
  217. expect(card.lines.join("\n")).not.toContain("研究状态:needs_revision")
  218. })
  219. test("server progress sections replace the legacy flat summary without re-scoring", () => {
  220. const card = paasCard({status: "completed", research: {science: {outcome: {
  221. schema_version: 1, lines: ["legacy summary"], sections: [
  222. {id: "judgment", title: "当前研究判断", lines: ["条件内反证:示例假设"], omitted: 0},
  223. {id: "next", title: "下一步选项", lines: ["核对测量条件\n再决定"], omitted: 2},
  224. ],
  225. }}}})
  226. expect(card.lines).toContain("当前研究判断")
  227. expect(card.lines).toContain("条件内反证:示例假设")
  228. expect(card.lines).toContain("核对测量条件 再决定")
  229. expect(card.lines).not.toContain("legacy summary")
  230. })