Commit 901625e2423453e82ead89baab4dc1bf1914a8ed

Authored by graphlemon
1 parent 01173527

graphlemon: code_diff artifact for task 3605272e-fe33-48cc-b3f3-e0c0ba26f970

.graphlemon/runs/3605272e-fe33-48cc-b3f3-e0c0ba26f970/code_diff.patch 0 → 100644
  1 +diff --git a/frontend/app.js b/frontend/app.js
  2 +index 2f17236..da50ca9 100644
  3 +--- a/frontend/app.js
  4 ++++ b/frontend/app.js
  5 +@@ -104,6 +104,11 @@ const ARTIFACT_DETAIL_RE = /^#\/artifacts\/([^/]+)$/;
  6 + // reaching renderTaskDetail/mountTaskDetail with a bogus org_node that would
  7 + // otherwise need its own defensive checks further down.
  8 + const ORG_NODE_DETAIL_RE = /^#\/tasks\/([^/]+)\/org\/(planner|coder|validator)$/;
  9 ++// v_run_detail (U-046, 2026-08-06 SDD): "运行历史" (`#gc_runs_list`)
  10 ++// previously had nowhere real to send a click -- it just called
  11 ++// onSwitchToTask to switch v_graph_console's own task selector. This is the
  12 ++// actual run-detail page/route that closes that gap.
  13 ++const RUN_DETAIL_RE = /^#\/runs\/([^/]+)$/;
  14 +
  15 + let currentRouteCleanup = null;
  16 + function registerRouteCleanup(fn) {
  17 +@@ -124,6 +129,7 @@ function render() {
  18 + const orgNodeMatch = hash.match(ORG_NODE_DETAIL_RE);
  19 + const skillMatch = hash.match(SKILL_AUDIT_RE);
  20 + const artifactMatch = hash.match(ARTIFACT_DETAIL_RE);
  21 ++ const runMatch = hash.match(RUN_DETAIL_RE);
  22 + if (orgNodeMatch) {
  23 + // Reuses v_task_detail itself (same render/mount) with the org_node
  24 + // carried through as a second arg -- no separate view/route handler.
  25 +@@ -140,6 +146,9 @@ function render() {
  26 + // with the artifact_id pre-selected -- no separate detail view.
  27 + route = { render: renderArtifactBrowser, mount: mountArtifactBrowser };
  28 + routeArgs = [artifactMatch[1]];
  29 ++ } else if (runMatch) {
  30 ++ route = { render: renderRunDetail, mount: mountRunDetail };
  31 ++ routeArgs = [runMatch[1]];
  32 + }
  33 + }
  34 + if (!route) route = { render: () => "<h1>Not found</h1><p>" + hash + "</p>" };
  35 +@@ -1468,6 +1477,122 @@ function mountTaskDetail(taskId, initialOrgNode) {
  36 + });
  37 + }
  38 +
  39 ++// ---- v_run_detail (`#/runs/:run_id`, U-046 2026-08-06 SDD): single Work
  40 ++// Graph Run detail -- every work_node_execution the run contains, each with
  41 ++// its own log (live c_ws_log_tail while running, static c_execution_log_get
  42 ++// once terminal). Reuses renderGraphVisualizerPanel/mountLogViewer
  43 ++// unmodified, same as v_task_detail's todo tree above; the one DOM-id
  44 ++// contract mountLogViewer relies on (`#todo-detail-<node_exec_id>
  45 ++// .log-autoscroll`) is reproduced here via renderRunNodeListHtml so the
  46 ++// existing auto-scroll checkbox keeps working without touching
  47 ++// mountLogViewer itself.
  48 ++
  49 ++function renderRunNodeListHtml(run) {
  50 ++ if (!run.nodes.length) return '<div class="hint">该运行尚无节点</div>';
  51 ++ const items = run.nodes.map((wn) => {
  52 ++ const status = wn.status;
  53 ++ return (
  54 ++ '<li class="status-' + status + '">'
  55 ++ + '<div class="todo-row" data-node-exec-id="' + wn.node_exec_id + '">'
  56 ++ + '<span class="dot"></span>'
  57 ++ + '<span class="todo-id">' + escapeHtml(wn.node_id) + "</span>"
  58 ++ + '<span class="todo-status">' + escapeHtml(status) + " · " + escapeHtml(wn.subagent_type)
  59 ++ + " · retry_count=" + wn.retry_count + " · node_exec_id=" + wn.node_exec_id + "</span>"
  60 ++ + "</div>"
  61 ++ + '<div class="todo-detail" id="todo-detail-' + wn.node_exec_id + '" data-status="' + status + '">'
  62 ++ + (wn.reflection_notes ? "reflection_notes: " + escapeHtml(wn.reflection_notes) + "<br>" : "")
  63 ++ + '<div class="log-viewer-slot" id="log-slot-' + wn.node_exec_id + '"></div>'
  64 ++ + "</div>"
  65 ++ + "</li>"
  66 ++ );
  67 ++ }).join("");
  68 ++ return '<ul class="todo-tree">' + items + "</ul>";
  69 ++}
  70 ++
  71 ++function renderRunDetail(runId) {
  72 ++ if (!getCurrentProjectId()) return renderNoProjectSelected();
  73 ++ return `
  74 ++ <div class="page page-wide">
  75 ++ <div class="breadcrumb"><a href="#/graph">Graph 控制台</a> / run ${escapeHtml(runId)}</div>
  76 ++ <div id="rd_content"><div class="hint">加载中…</div></div>
  77 ++ </div>
  78 ++ `;
  79 ++}
  80 ++
  81 ++function mountRunDetail(runId) {
  82 ++ const projectId = getCurrentProjectId();
  83 ++ if (!projectId) return;
  84 ++ const content = document.getElementById("rd_content");
  85 ++
  86 ++ // Same "track open log viewers, close them on re-render/route-leave"
  87 ++ // pattern as mountTaskDetail/mountGraphConsole above.
  88 ++ const activeLogViewers = new Map();
  89 ++ function closeAllLogViewers() {
  90 ++ for (const close of activeLogViewers.values()) close();
  91 ++ activeLogViewers.clear();
  92 ++ }
  93 ++
  94 ++ // The event socket needs task_id, which we only learn from the run's own
  95 ++ // response -- opened lazily on the first successful render, not before.
  96 ++ let socket = null;
  97 ++
  98 ++ function renderDetail(run) {
  99 ++ closeAllLogViewers();
  100 ++ content.innerHTML = (
  101 ++ "<h1>" + escapeHtml(run.org_node) + " Work Graph Run</h1>"
  102 ++ + '<div class="meta-row">'
  103 ++ + "<div><b>RUN_ID</b>" + escapeHtml(run.run_id) + "</div>"
  104 ++ + "<div><b>STATUS</b>" + escapeHtml(run.status) + "</div>"
  105 ++ + "<div><b>STARTED_AT</b>" + escapeHtml(run.started_at || "") + "</div>"
  106 ++ + "<div><b>COMPLETED_AT</b>" + escapeHtml(run.completed_at || "") + "</div>"
  107 ++ + '<div><b>TASK</b><a href="#/tasks/' + encodeURIComponent(run.task_id) + '">' + escapeHtml(run.task_id) + "</a></div>"
  108 ++ + "</div>"
  109 ++ + renderGraphVisualizerPanel(run)
  110 ++ + '<div class="tooltip" id="graph-tooltip"></div>'
  111 ++ + '<div class="panel"><h2>节点列表</h2>' + renderRunNodeListHtml(run) + "</div>"
  112 ++ );
  113 ++
  114 ++ for (const row of content.querySelectorAll(".todo-row[data-node-exec-id]")) {
  115 ++ row.addEventListener("click", () => {
  116 ++ const nodeExecId = row.dataset.nodeExecId;
  117 ++ if (!nodeExecId) return;
  118 ++ const detail = document.getElementById("todo-detail-" + nodeExecId);
  119 ++ if (!detail) return;
  120 ++ detail.classList.toggle("open");
  121 ++ if (detail.classList.contains("open") && !activeLogViewers.has(nodeExecId)) {
  122 ++ const slot = document.getElementById("log-slot-" + nodeExecId);
  123 ++ slot.innerHTML = renderLogViewerHtml(nodeExecId);
  124 ++ activeLogViewers.set(nodeExecId, mountLogViewer(nodeExecId, detail.dataset.status));
  125 ++ }
  126 ++ });
  127 ++ }
  128 ++ mountGraphVisualizerTooltips(content);
  129 ++
  130 ++ if (!socket) {
  131 ++ socket = connectEventSocket(projectId, run.task_id, {
  132 ++ onEvent: () => refresh(),
  133 ++ onStatusChange: () => {},
  134 ++ });
  135 ++ }
  136 ++ }
  137 ++
  138 ++ async function refresh() {
  139 ++ const resp = await fetch("/api/work-graph-runs/" + encodeURIComponent(runId));
  140 ++ if (resp.status === 404) {
  141 ++ content.innerHTML = '<div class="error-banner" style="display:block;">运行不存在</div>';
  142 ++ return;
  143 ++ }
  144 ++ renderDetail(await resp.json());
  145 ++ }
  146 ++
  147 ++ refresh();
  148 ++
  149 ++ registerRouteCleanup(() => {
  150 ++ if (socket) socket.close();
  151 ++ closeAllLogViewers();
  152 ++ });
  153 ++}
  154 ++
  155 + // ---- v_graph_console (`#/graph`, 2026-08-03 SDD): Org/Work Graph
  156 + // visualization + Planner output overview. FR-1: independent Org Graph
  157 + // topology (not `org-strip`, see renderOrgGraphTopology below). FR-2/3:
  158 +@@ -1525,9 +1650,11 @@ function renderArtifactSummaryList(artifacts, types, emptyText) {
  159 + // #/artifacts / #/tasks with no filter pre-applied -- v_artifact_browser
  160 + // and v_task_board don't parse URL query params today, and adding that is
  161 + // out of scope for this page (SDD §2.5's explicit, recorded trade-off).
  162 +-// Graph run rows are the one exception: clicking a row switches this same
  163 +-// page's own task switcher, since there's no separate "run detail" route.
  164 +-async function mountArtifactsOverviewPanel(container, projectId, { onSwitchToTask }) {
  165 ++// Graph run rows: U-046 fixed the previous shortcut (switching this same
  166 ++// page's own task switcher via onSwitchToTask, because there was no
  167 ++// separate "run detail" route) to navigate to the real v_run_detail page
  168 ++// (#/runs/:run_id) instead.
  169 ++async function mountArtifactsOverviewPanel(container, projectId) {
  170 + container.innerHTML = '<div class="panel"><h2>Planner 产出总览</h2><div class="hint">加载中…</div></div>';
  171 + const [artifacts, runs, tasks] = await Promise.all([
  172 + fetch("/api/artifacts?project_id=" + encodeURIComponent(projectId)).then((r) => r.json()),
  173 +@@ -1540,7 +1667,7 @@ async function mountArtifactsOverviewPanel(container, projectId, { onSwitchToTas
  174 +
  175 + const runsHtml = runs.length === 0 ? '<div class="hint">暂无 Graph 运行记录</div>' : (
  176 + '<ul class="simple-list" id="gc_runs_list">' + runs.slice(0, 10).map((r) =>
  177 +- '<li data-run-task-id="' + r.task_id + '" style="cursor:pointer;"><span>' + escapeHtml(r.org_node) + " · run "
  178 ++ '<li data-run-id="' + r.run_id + '" style="cursor:pointer;"><span>' + escapeHtml(r.org_node) + " · run "
  179 + + r.run_id.slice(0, 8) + "</span><span>" + escapeHtml(r.status) + " · " + r.node_count + " 节点</span></li>"
  180 + ).join("") + "</ul>"
  181 + );
  182 +@@ -1564,8 +1691,10 @@ async function mountArtifactsOverviewPanel(container, projectId, { onSwitchToTas
  183 +
  184 + const runsListEl = document.getElementById("gc_runs_list");
  185 + if (runsListEl) {
  186 +- for (const li of runsListEl.querySelectorAll("li[data-run-task-id]")) {
  187 +- li.addEventListener("click", () => onSwitchToTask(li.dataset.runTaskId));
  188 ++ for (const li of runsListEl.querySelectorAll("li[data-run-id]")) {
  189 ++ li.addEventListener("click", () => {
  190 ++ window.location.hash = "#/runs/" + encodeURIComponent(li.dataset.runId);
  191 ++ });
  192 + }
  193 + }
  194 +
  195 +@@ -1639,12 +1768,7 @@ function mountGraphConsole() {
  196 + }
  197 +
  198 + function refreshArtifactsOverview() {
  199 +- mountArtifactsOverviewPanel(artifactsOverviewEl, projectId, {
  200 +- onSwitchToTask: (taskId) => {
  201 +- taskSelect.value = taskId;
  202 +- loadTaskAndRender(taskId);
  203 +- },
  204 +- });
  205 ++ mountArtifactsOverviewPanel(artifactsOverviewEl, projectId);
  206 + }
  207 +
  208 + async function loadTaskAndRender(taskId) {
  209 +diff --git a/frontend/test_run_detail_smoke.js b/frontend/test_run_detail_smoke.js
  210 +new file mode 100644
  211 +index 0000000..58befa9
  212 +--- /dev/null
  213 ++++ b/frontend/test_run_detail_smoke.js
  214 +@@ -0,0 +1,117 @@
  215 ++// v_run_detail (`#/runs/:run_id`, U-046 2026-08-06 SDD) smoke test. Same
  216 ++// no-framework/no-fixture convention as frontend/test_graph_console_smoke.js
  217 ++// and frontend/test_org_click_through_smoke.js (see
  218 ++// .claude/agent-memory/validator/feedback_no_js_test_framework.md) -- loads
  219 ++// app.js in a bare vm.Context and asserts on generated HTML strings / regex
  220 ++// matches for the new top-level pieces:
  221 ++// - RUN_DETAIL_RE: the new #/runs/:run_id route.
  222 ++// - renderRunNodeListHtml: the run-detail node list, including the
  223 ++// todo-detail-<node_exec_id> DOM-id contract mountLogViewer relies on
  224 ++// (`#todo-detail-<id> .log-autoscroll`) and the empty-run case.
  225 ++// - mountArtifactsOverviewPanel's now-fixed click target: `#gc_runs_list`
  226 ++// rows carry data-run-id (not the old data-run-task-id), so a real
  227 ++// click can build "#/runs/" + run_id instead of only ever switching
  228 ++// the task selector.
  229 ++//
  230 ++// Run: node frontend/test_run_detail_smoke.js
  231 ++
  232 ++"use strict";
  233 ++const fs = require("fs");
  234 ++const path = require("path");
  235 ++const vm = require("vm");
  236 ++const assert = require("assert");
  237 ++
  238 ++function makeFakeDiv() {
  239 ++ let text = "";
  240 ++ return {
  241 ++ set textContent(v) { text = v == null ? "" : String(v); },
  242 ++ get textContent() { return text; },
  243 ++ get innerHTML() {
  244 ++ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
  245 ++ },
  246 ++ };
  247 ++}
  248 ++
  249 ++const sandbox = {
  250 ++ document: {
  251 ++ createElement: () => makeFakeDiv(),
  252 ++ getElementById: () => null,
  253 ++ querySelectorAll: () => [],
  254 ++ addEventListener: () => {},
  255 ++ },
  256 ++ window: {
  257 ++ location: { protocol: "http:", host: "localhost", hash: "" },
  258 ++ addEventListener: () => {},
  259 ++ },
  260 ++ localStorage: { getItem: () => null, setItem: () => {} },
  261 ++ console,
  262 ++};
  263 ++vm.createContext(sandbox);
  264 ++
  265 ++const src = fs.readFileSync(path.join(__dirname, "app.js"), "utf8");
  266 ++// Top-level `const` regexes stay lexically scoped to the script and never
  267 ++// reach the sandbox object (same Annex B quirk the other smoke tests
  268 ++// already document) -- re-export what this test needs.
  269 ++const augmentedSrc = src + "\nglobalThis.RUN_DETAIL_RE = RUN_DETAIL_RE;\n";
  270 ++new vm.Script(augmentedSrc, { filename: "app.js" }).runInContext(sandbox);
  271 ++
  272 ++let assertionCount = 0;
  273 ++function check(condition, message) {
  274 ++ assertionCount++;
  275 ++ assert.ok(condition, message);
  276 ++}
  277 ++
  278 ++// ---- 1. RUN_DETAIL_RE: happy / boundary / failure ----
  279 ++{
  280 ++ const legal = "#/runs/run-abc-123".match(sandbox.RUN_DETAIL_RE);
  281 ++ check(legal, "legal run_id must match");
  282 ++ check(legal[1] === "run-abc-123", "captured group must be the run_id");
  283 ++
  284 ++ check(!"#/runs/".match(sandbox.RUN_DETAIL_RE), "missing run_id segment must not match");
  285 ++ check(!"#/runs/abc/extra".match(sandbox.RUN_DETAIL_RE), "extra path segments must not match");
  286 ++ check(!"#/tasks/abc".match(sandbox.RUN_DETAIL_RE), "an unrelated route must not match");
  287 ++}
  288 ++
  289 ++// ---- 2. renderRunNodeListHtml: node list + todo-detail-<id> DOM contract ----
  290 ++{
  291 ++ const run = {
  292 ++ run_id: "run-1", org_node: "coder", status: "running",
  293 ++ nodes: [
  294 ++ {
  295 ++ node_exec_id: "exec-1", node_id: "n1", subagent_type: "coder", status: "running",
  296 ++ retry_count: 0, reflection_notes: null,
  297 ++ },
  298 ++ {
  299 ++ node_exec_id: "exec-2", node_id: "n2", subagent_type: "coder", status: "done",
  300 ++ retry_count: 1, reflection_notes: "retried once after a transient error",
  301 ++ },
  302 ++ ],
  303 ++ };
  304 ++ const html = sandbox.renderRunNodeListHtml(run);
  305 ++ check(html.includes('data-node-exec-id="exec-1"'), "each row must carry its node_exec_id for the click handler");
  306 ++ check(html.includes('id="todo-detail-exec-1"'), "must reproduce the todo-detail-<id> id mountLogViewer's querySelector needs");
  307 ++ check(html.includes('data-status="running"'), "todo-detail wrapper must carry the node's live status");
  308 ++ check(html.includes('id="log-slot-exec-2"'), "must reserve a log-viewer-slot per node, same as v_task_detail's todo tree");
  309 ++ check(html.includes("retried once after a transient error"), "reflection_notes must be shown when present");
  310 ++ check(!html.includes("reflection_notes: <br>"), "no stray reflection_notes line when it's null (exec-1)");
  311 ++
  312 ++ const emptyHtml = sandbox.renderRunNodeListHtml({ nodes: [] });
  313 ++ check(emptyHtml.includes("该运行尚无节点"), "a run with zero nodes must render an explicit empty state, not blank/undefined");
  314 ++}
  315 ++
  316 ++// ---- 3. gc_runs_list rows: run-detail click target (2026-08-06 fix) ----
  317 ++{
  318 ++ // mountArtifactsOverviewPanel itself does an async fetch and can't run in
  319 ++ // this sandbox (no `fetch`), but the row-id contract it depends on is a
  320 ++ // pure string-building concern worth pinning directly: replicate the
  321 ++ // exact <li> markup mountArtifactsOverviewPanel emits for one run and
  322 ++ // confirm it carries data-run-id (not the removed data-run-task-id).
  323 ++ const escapeHtml = sandbox.escapeHtml;
  324 ++ const r = { org_node: "coder", run_id: "run-1234567890", status: "done", node_count: 3 };
  325 ++ const li = '<li data-run-id="' + r.run_id + '" style="cursor:pointer;"><span>' + escapeHtml(r.org_node) + " · run "
  326 ++ + r.run_id.slice(0, 8) + "</span><span>" + escapeHtml(r.status) + " · " + r.node_count + " 节点</span></li>";
  327 ++ check(li.includes('data-run-id="run-1234567890"'), "run row must carry the real run_id for #/runs/:run_id navigation");
  328 ++ check(!li.includes("data-run-task-id"), "the old task-switcher click target must be gone");
  329 ++}
  330 ++
  331 ++console.log("frontend/test_run_detail_smoke.js: all " + assertionCount + " assertions passed");
  332 +diff --git a/src/backend_server.py b/src/backend_server.py
  333 +index 470de0d..07b9551 100644
  334 +--- a/src/backend_server.py
  335 ++++ b/src/backend_server.py
  336 +@@ -130,6 +130,7 @@ _LOG_SUFFIX = "/log"
  337 + _ARTIFACTS_PREFIX = "/api/artifacts/"
  338 + _SKILLS_PREFIX = "/api/skills/"
  339 + _DEPLOYMENTS_PREFIX = "/api/deployments/"
  340 ++_WORK_GRAPH_RUNS_PREFIX = "/api/work-graph-runs/"
  341 +
  342 +
  343 + class _Handler(BaseHTTPRequestHandler):
  344 +@@ -180,6 +181,11 @@ class _Handler(BaseHTTPRequestHandler):
  345 + if parsed.path == "/api/work-graph-runs":
  346 + self._handle_work_graph_run_list(parsed.query)
  347 + return
  348 ++ if parsed.path.startswith(_WORK_GRAPH_RUNS_PREFIX):
  349 ++ run_id = parsed.path[len(_WORK_GRAPH_RUNS_PREFIX):]
  350 ++ if run_id and "/" not in run_id:
  351 ++ self._handle_work_graph_run_get(run_id)
  352 ++ return
  353 + if parsed.path.startswith(_ARTIFACTS_PREFIX):
  354 + artifact_id = parsed.path[len(_ARTIFACTS_PREFIX):]
  355 + if artifact_id and "/" not in artifact_id:
  356 +@@ -666,6 +672,20 @@ class _Handler(BaseHTTPRequestHandler):
  357 + else:
  358 + self._send_json(200, result)
  359 +
  360 ++ def _handle_work_graph_run_get(self, run_id):
  361 ++ """c_work_graph_run_get (U-046, GET /api/work-graph-runs/:run_id):
  362 ++ v_run_detail's single-run lookup -- the list endpoint above has no
  363 ++ per-run detail shape, and v_run_detail needs the full node list
  364 ++ (same shape as task_query.get_task's embedded work_graph_runs[i])
  365 ++ to reuse renderGraphVisualizerPanel/mountLogViewer unmodified."""
  366 ++ try:
  367 ++ with self.server.conn_lock:
  368 ++ result = work_graph_run_query.get_work_graph_run(self.server.conn, run_id)
  369 ++ except work_graph_run_query.WorkGraphRunNotFoundError:
  370 ++ self._send_json(404, {"error": "NOT_FOUND"})
  371 ++ else:
  372 ++ self._send_json(200, result)
  373 ++
  374 + def _handle_artifact_get(self, artifact_id):
  375 + try:
  376 + with self.server.conn_lock:
  377 +diff --git a/src/test_backend_server.py b/src/test_backend_server.py
  378 +index 5dc6071..8f58afe 100644
  379 +--- a/src/test_backend_server.py
  380 ++++ b/src/test_backend_server.py
  381 +@@ -1354,6 +1354,19 @@ class WorkGraphRunListRouteTest(unittest.TestCase):
  382 + self.assertEqual(status, 200)
  383 + self.assertEqual(body, [])
  384 +
  385 ++ def test_get_returns_run_with_nodes(self):
  386 ++ status, body = self._get("/api/work-graph-runs/run-1")
  387 ++ self.assertEqual(status, 200)
  388 ++ self.assertEqual(body["run_id"], "run-1")
  389 ++ self.assertEqual(body["task_id"], "task-1")
  390 ++ self.assertEqual(body["org_node"], "coder")
  391 ++ self.assertEqual(body["nodes"], [])
  392 ++
  393 ++ def test_get_nonexistent_run_returns_404(self):
  394 ++ status, body = self._get("/api/work-graph-runs/no-such-run")
  395 ++ self.assertEqual(status, 404)
  396 ++ self.assertEqual(body["error"], "NOT_FOUND")
  397 ++
  398 +
  399 + class DeploymentRouteTest(unittest.TestCase):
  400 + """U-043: c_deployment_list/c_deployment_current/c_deployment_get for
  401 +diff --git a/src/test_work_graph_run_query.py b/src/test_work_graph_run_query.py
  402 +index 152e2c8..cc32498 100644
  403 +--- a/src/test_work_graph_run_query.py
  404 ++++ b/src/test_work_graph_run_query.py
  405 +@@ -118,5 +118,33 @@ class ListWorkGraphRunsTest(WorkGraphRunQueryTestBase):
  406 + self.assertEqual(result, [])
  407 +
  408 +
  409 ++class GetWorkGraphRunTest(WorkGraphRunQueryTestBase):
  410 ++ """U-046: c_work_graph_run_get -- v_run_detail's single-run lookup."""
  411 ++
  412 ++ def test_returns_run_with_embedded_nodes(self):
  413 ++ self._insert_run("run-1", "coder", status="running", node_count=2)
  414 ++ result = work_graph_run_query.get_work_graph_run(self.conn, "run-1")
  415 ++ self.assertEqual(result["run_id"], "run-1")
  416 ++ self.assertEqual(result["task_id"], "task-1")
  417 ++ self.assertEqual(result["org_node"], "coder")
  418 ++ self.assertEqual(result["status"], "running")
  419 ++ self.assertEqual(result["graph_manifest"], {})
  420 ++ self.assertEqual(len(result["nodes"]), 2)
  421 ++ self.assertEqual(
  422 ++ {n["node_exec_id"] for n in result["nodes"]},
  423 ++ {"run-1-node-0", "run-1-node-1"},
  424 ++ )
  425 ++ self.assertEqual(result["nodes"][0]["status"], "done")
  426 ++
  427 ++ def test_nonexistent_run_raises(self):
  428 ++ with self.assertRaises(work_graph_run_query.WorkGraphRunNotFoundError):
  429 ++ work_graph_run_query.get_work_graph_run(self.conn, "no-such-run")
  430 ++
  431 ++ def test_run_with_no_nodes_returns_empty_list(self):
  432 ++ self._insert_run("run-1", "planner", node_count=0)
  433 ++ result = work_graph_run_query.get_work_graph_run(self.conn, "run-1")
  434 ++ self.assertEqual(result["nodes"], [])
  435 ++
  436 ++
  437 + if __name__ == "__main__":
  438 + unittest.main()
  439 +diff --git a/src/work_graph_run_query.py b/src/work_graph_run_query.py
  440 +index de08790..0e84758 100644
  441 +--- a/src/work_graph_run_query.py
  442 ++++ b/src/work_graph_run_query.py
  443 +@@ -7,8 +7,21 @@ codebase that lists `work_graph_run` rows across all tasks in a project
  444 + rather than for one `task_id` at a time, which is why it lives in its own
  445 + module instead of `task_query.py` (that module's own docstring frames it
  446 + as "built around a single task_id").
  447 ++
  448 ++U-046 (2026-08-06 SDD, "运行历史点击跳转错误 + 缺运行详情页"): adds
  449 ++`get_work_graph_run`, a single-`run_id` lookup for the new `v_run_detail`
  450 ++page (`#/runs/:run_id`). This deliberately mirrors the shape of
  451 ++`task_query.get_task`'s embedded `work_graph_runs[i]` entries (same keys,
  452 ++same per-node field list via `_nodes_for_run`) so the frontend can reuse
  453 ++`renderGraphVisualizerPanel`/`mountLogViewer` against this response without
  454 ++any remapping -- it's a separate query (by `run_id` instead of `task_id`)
  455 ++rather than a call into `task_query._work_nodes_for_run` because that
  456 ++helper is private to its own module and this module already owns
  457 ++`work_graph_run` reads.
  458 + """
  459 +
  460 ++import json
  461 ++
  462 + _VALID_ORG_NODES = ("planner", "coder", "validator")
  463 +
  464 +
  465 +@@ -51,3 +64,48 @@ def list_work_graph_runs(conn, project_id, org_node=None, limit=20):
  466 + }
  467 + for r in rows
  468 + ]
  469 ++
  470 ++
  471 ++class WorkGraphRunNotFoundError(Exception):
  472 ++ """NOT_FOUND -- c_work_graph_run_get on a nonexistent run_id."""
  473 ++
  474 ++
  475 ++def get_work_graph_run(conn, run_id):
  476 ++ row = conn.execute(
  477 ++ "SELECT run_id, task_id, org_node, graph_manifest, status, started_at, completed_at "
  478 ++ "FROM work_graph_run WHERE run_id = ?",
  479 ++ (run_id,),
  480 ++ ).fetchone()
  481 ++ if row is None:
  482 ++ raise WorkGraphRunNotFoundError(run_id)
  483 ++ return {
  484 ++ "run_id": row[0], "task_id": row[1], "org_node": row[2],
  485 ++ "graph_manifest": json.loads(row[3]) if row[3] else None,
  486 ++ "status": row[4], "started_at": row[5], "completed_at": row[6],
  487 ++ "nodes": _nodes_for_run(conn, row[0]),
  488 ++ }
  489 ++
  490 ++
  491 ++def _nodes_for_run(conn, run_id):
  492 ++ # Same column list as task_query._work_nodes_for_run -- kept in lockstep
  493 ++ # on purpose (see module docstring) so v_run_detail can reuse
  494 ++ # renderGraphVisualizerPanel/mountLogViewer unmodified.
  495 ++ rows = conn.execute(
  496 ++ "SELECT node_exec_id, node_id, subagent_type, status, retry_count, input_payload, "
  497 ++ "output_payload, reflection_notes, git_worktree_ref, input_schema_ref, output_schema_ref, "
  498 ++ "quota_limit_type, quota_wait_started_at "
  499 ++ "FROM work_node_execution WHERE run_id = ? ORDER BY node_exec_id",
  500 ++ (run_id,),
  501 ++ ).fetchall()
  502 ++ return [
  503 ++ {
  504 ++ "node_exec_id": n[0], "node_id": n[1], "subagent_type": n[2], "status": n[3],
  505 ++ "retry_count": n[4],
  506 ++ "input_payload": json.loads(n[5]) if n[5] else None,
  507 ++ "output_payload": json.loads(n[6]) if n[6] else None,
  508 ++ "reflection_notes": n[7], "git_worktree_ref": n[8],
  509 ++ "input_schema_ref": n[9], "output_schema_ref": n[10],
  510 ++ "quota_limit_type": n[11], "quota_wait_started_at": n[12],
  511 ++ }
  512 ++ for n in rows
  513 ++ ]