Skip to content

Commit 3d75876

Browse files
committed
Adopt the sanctioned task-id discovery contract
The datasette-agent branch now substitutes __DATASETTE_TASK_ID__ into task HTML at render time and puts data-task-id on the HTML container itself. The harness switches from walking to the sibling status element to currentScript.closest("[data-task-id]"), and the Playwright runtime stub mirrors the new renderBrowserTask DOM. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ebf3ixoxYDoGkSTJgPcAc
1 parent a589de0 commit 3d75876

3 files changed

Lines changed: 12 additions & 18 deletions

File tree

‎datasette_apps/debug.py‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -315,23 +315,12 @@ def oversized():
315315
var currentScript = document.currentScript;
316316
317317
function findTaskId() {
318-
// The runtime renders task HTML inside .agent-browser-task-html,
319-
// immediately after the .agent-browser-task status element that
320-
// carries data-task-id.
318+
// Sanctioned contract: the runtime renders task HTML inside a
319+
// container carrying data-task-id.
321320
var container = currentScript
322-
? currentScript.closest(".agent-browser-task-html")
321+
? currentScript.closest("[data-task-id]")
323322
: null;
324-
var statusEl = container ? container.previousElementSibling : null;
325-
if (
326-
statusEl &&
327-
statusEl.classList &&
328-
statusEl.classList.contains("agent-browser-task") &&
329-
statusEl.dataset &&
330-
statusEl.dataset.taskId
331-
) {
332-
return statusEl.dataset.taskId;
333-
}
334-
return null;
323+
return container ? container.dataset.taskId : null;
335324
}
336325
337326
var agent = window.datasetteAgent;

‎tests/test_debug_jobs.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ async def test_complete_debug_job_normalizes_failure_envelopes():
293293
def test_debug_harness_html_is_a_generic_bootstrap():
294294
harness = build_debug_harness_html()
295295
assert "<script" in harness
296-
# Task identity comes from the runtime's rendered task element; the
296+
# Task identity comes from the runtime's data-task-id container; the
297297
# payload arrives through the one-shot claim - nothing job-specific
298298
# lives in the HTML
299-
assert "agent-browser-task" in harness
299+
assert "[data-task-id]" in harness
300300
assert "datasetteAgent" in harness
301301
assert "claimTask" in harness
302302
assert "completeTask" in harness

‎tests/test_playwright.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,12 @@ def test_csp_allowlisted_origin_can_receive_exfiltrated_data(tmp_path, monkeypat
894894
document.body.appendChild(statusEl);
895895
const htmlEl = document.createElement("div");
896896
htmlEl.className = "agent-browser-task-html";
897-
htmlEl.insertAdjacentHTML("beforeend", harnessHtml);
897+
// Matches renderBrowserTask: the container carries the task id, the
898+
// sanctioned discovery contract for task HTML
899+
htmlEl.dataset.taskId = taskId;
900+
htmlEl.insertAdjacentHTML(
901+
"beforeend", harnessHtml.replaceAll("__DATASETTE_TASK_ID__", taskId)
902+
);
898903
document.body.appendChild(htmlEl);
899904
htmlEl.querySelectorAll("script").forEach(oldScript => {
900905
const newScript = document.createElement("script");

0 commit comments

Comments
 (0)