| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import { createStore } from "solid-js/store"
- import { PaasRunPanel } from "../../src/pages/paas/run-panel"
- import type { PaasPlatform } from "../../src/paas"
- // Deliberately delayed snapshots exercise stale-response handling, not model quality.
- export function PanelFixture() {
- const [state, setState] = createStore({ runID: "run_1" })
- const runs: Record<string, Record<string, unknown>> = {
- run_1: {
- run_id: "run_1",
- agent_id: "research",
- status: "running",
- output: "第一项任务",
- usage: { duration_ms: 5000, cost_usd: 0.0012 },
- },
- run_2: { run_id: "run_2", agent_id: "research", status: "completed", output: "第二项任务" },
- }
- const control = {
- holdNext: false,
- held: false,
- failPause: false,
- failRead: false,
- readError: "HTTP 503",
- failFiles: false,
- files: [] as { name: string; path: string }[],
- cancelDownload: false,
- release: () => {},
- switchRun: () => setState("runID", "run_2"),
- update: (value: Record<string, unknown>) => {
- runs[state.runID] = { ...value, run_id: state.runID, agent_id: "research" }
- },
- }
- Object.assign(window, { paasPanelTest: control })
- const api: PaasPlatform = {
- connect: async () => ({ url: "https://example.test" }),
- disconnect: async () => {},
- request: async (request) => {
- if (request.action === "run") {
- if (control.failRead) throw new Error(control.readError)
- const snapshot = structuredClone(runs[request.runID])
- if (control.holdNext) {
- control.holdNext = false
- control.held = true
- await new Promise<void>((resolve) => {
- control.release = resolve
- })
- control.held = false
- }
- return snapshot
- }
- if (request.action === "run-files") {
- if (control.failFiles) throw new Error("HTTP 503:文件服务暂时不可用")
- return { files: control.files }
- }
- if (request.action === "run-events")
- return {
- run_id: request.runID,
- stages: [
- {
- stage_id: "collect",
- status: "completed",
- details: { round: 1 },
- started_at: "2026-11-30T10:00:00Z",
- completed_at: "2026-11-30T10:00:05Z",
- },
- ],
- events: [
- {
- sequence: 1,
- event_type: "tool_call",
- stage_id: "collect",
- data: { tool: "Bash", content: "pwd" },
- created_at: "2026-11-30T10:00:01Z",
- },
- ],
- }
- if (request.action === "download") return { saved: !control.cancelDownload }
- if (request.action === "pause") {
- if (control.failPause) throw new Error("暂时无法暂停,请稍后再试。")
- runs[request.runID] = { ...runs[request.runID], status: "paused", checkpoint_id: "checkpoint_1" }
- return runs[request.runID]
- }
- return {}
- },
- }
- return <PaasRunPanel api={api} agentID="research" runID={state.runID} />
- }
|