"""The goalui bundle (moved verbatim from the pre-split web_stack_test.py; see test/harness.py for the shared machinery and the runner).""" from harness import * # noqa: F401,F403 — the shared wire helpers def run(ctx): """Plan 14 workstream B + plan 15 C1: the goal supervision surface. B1 — goal-run control parity (Retry supervision / Requeue-to-resume on the status head, the /tasks/ redirect, no notify-me toggle), B2 — the plan-review remarks queue, B4 — sessions.resume_notice + the terminal dropdown/resume panel, B5 — page order, effective rules and per-task capability badges, B6 — narrative footnote weights. C1 — the single-row block world: the goal's blocks ARE the run task's rows (answered from every surface through one path; no dual rows, no stragglers, at most one review-kind block per verdict path). C4 — the goal page batch: one muted head activity line, plan between attention and tasks, answered blocks behind an expander, footnote comments. C5 — the dashboard deep-link closure: goal pile cards link the goal page, every surface settles the single row, and no goal-side store exists to hold stragglers. """ auth, fake, fake_id, fake_token = ctx.auth, ctx.fake, ctx.fake_id, ctx.fake_token def run_task_of(goal_id): conn = db() try: return int(conn.execute( "select id from tasks where goal_id = ? and kind = 'goal_run'", (goal_id,)).fetchone()[0]) finally: conn.close() def wait_run(status, timeout=60, what="run status"): return wait_for(lambda: task_state(auth, run_task_of(goal))["status"] == status or False, timeout=timeout, what=what) def pile_questions(): return [b.get("question") for b in slot_public(auth, "/", "dashboard")["pinned"] if b.get("item_type") == "goal"] def open_session(task_id): """The task's newest session row (plan 16 D4: a parked round's row is closed 'parked' — still the record the CLI callbacks, the telemetry pushes and the page surfaces key on).""" conn = db() try: row = conn.execute( "select max(id) from sessions where task_id = ?", (task_id,)).fetchone() return int(row[0]) if row and row[0] else None finally: conn.close() print("== B1: the goal-run task page redirects to the goal ==") fake.goal_script = [("plan", "# Remarks plan\n\n## Steps\n\n1. First move")] act(auth, slot_public(auth, "/goals", "goals")["create"], { "project_id": "1", "title": "Goalui goal", "brief": "Drive the plan-14 goal surface end to end.", "branch_name": "goal/goalui"}) conn = db() goal = conn.execute("select id from goals where title = 'Goalui goal'" ).fetchone()[0] conn.close() act(auth, goal_state(goal)["start"], {}) wait_run("blocked", what="goalui goal agent parks on its plan") # plan review parks blocked run_task = run_task_of(goal) frames = directives("/tasks/%d" % run_task, auth) navigations = [d for d in frames if d.get("type") == "navigate"] check(any(d.get("uri") == "/goals/%d" % goal for d in navigations), "the goal-run task page redirects to /goals/ (navigate directive)") check(slot_public(auth, "/tasks/%d" % run_task, "task")["id"] == run_task, "the redirect still hydrates the task slot (sealed refresh + API readers)") status, page = http("GET", "/tasks/%d" % run_task, headers={ "X-Statum-Slot": "key=%s; as_at=%s" % (auth["key"], auth["as_at"])}, timeout=15) check(status == 200, "the compiled goal-run page serves") act(auth, slot_public(auth, "/tasks", "tasks")["create"], { "project_id": "1", "title": "Goalui worker", "priority": "4", "description": "A plain worker under no goal."}) conn = db() worker = conn.execute("select id from tasks where title = 'Goalui worker'" ).fetchone()[0] conn.close() check(not [d for d in directives("/tasks/%d" % worker, auth) if d.get("type") == "navigate"], "worker task pages render normally (no redirect)") state = goal_state(goal) check("toggle_notify" not in state and state.get("notify") is None, "no notify-me toggle on the goal (goals notify unconditionally)") goal_page = http_get_page(auth, "/goals/%d" % goal) check("Notify me" not in goal_page and "toggle-notify" not in goal_page, "the goal page template ships no notify control") check(state["branch_name"] == "goal/goalui" and state["base_branch"] == "main" and isinstance(state["push_branches"], list) and state["priority"] == 3 and len(state["started_display"]) > 0 and len(state["agent_saddle"]) > 0, "the status head carries the full field set (branch pair, chips list," " priority, timestamps, agent saddle)") check("Retry supervision" in goal_page and "Requeue to resume" in goal_page, "the status head ships the run-control parity buttons") check("status-corner" not in goal_page and "goal complete" not in goal_page and goal_page.count("badge-yeehaw") == 1, "yeehaw is rows-only (no goal-head corner badge; the row badge remains)") check(goal_state(goal)["current_activity"] == "parked awaiting the plan review", "the head line reads 'parked awaiting the plan review' while one is open") goal_page = http_get_page(auth, "/goals/%d" % goal) check(goal_page.index("Goal agent blocks") < goal_page.index("

Plan

") < goal_page.index("

Tasks

"), "the plan section sits between attention and tasks") check("data-plan-review" in goal_page and "Approved plan & revisions" in goal_page, "an open review renders expanded beside the collapsed approved-plan expander") print("== B2: the plan-review remarks queue ==") check(goal_state(goal)["status"] == "plan_review" and goal_state(goal)["plan_pending_block"] is not None, "the goal sits in plan review with a pending block") goal_page = http_get_page(auth, "/goals/%d" % goal) review_at = goal_page.index("data-plan-review") check(review_at > 0, "the plan review region is marked for the remarks queue") check(goal_page.index('data-block-id="goal.plan_pending_block.id"') > 0, "the queue keys on the pending goal block id") body_at = goal_page.index('data-plan-body') remarks_at = goal_page.index("data-plan-remarks") check(body_at < remarks_at, "the remarks queue renders at the bottom of the plan body") for marker in ("data-plan-accept", "data-plan-toggle", "data-plan-submit", "data-plan-remove", "plan-popover", "remarksByBlock"): check(marker in goal_page, "the remarks queue ships %s" % marker) check("(index + 1) + '. '" in goal_page, "the rejection payload numbers every queued remark") check("rejectOpenByBlock" in goal_page and "statum.afterEvaluate(syncPlanRemarks)" in goal_page, "the queue survives pulse refreshes (maps outside statum re-renders)") # The rejection payload exactly as the client composes it: the # stable verdict wording, then each remark NUMBERED in queue order # with its quote prefixed like a comment. payload = ("Plan feedback received:\n\n" "> ## Steps\n\n1. First move\n\n" "1. Add a rollback step\n\n" "2. Name the owner of the migration") act(auth, goal_state(goal)["plan_pending_block"]["answer_action"], {"answer": payload}) state = goal_state(goal) check(state["status"] == "planning", "the remarks rejection returns the agent to planning") rejected = [r for r in state["plan_revisions"] if r.get("answered")] check(any(r["answer"] == payload for r in rejected), "the rejection carries the remarks verbatim, in order") check(payload.index("1. Add a rollback step") < payload.index("2. Name the owner"), "the numbering is queue-ordered") print("== B4: resume_notice lands on the resumed session row ==") fake.goal_script = [("question", "Which datastore?", ["SQLite", "Redis"])] check(wait_for(lambda: goal_state(goal)["status"] == "planning" or False, timeout=30, what="rejection observed") is not None, "the agent revises") # The parked plan agent resumes with the verdict; the next round # raises the scripted question. check(wait_for(lambda: any(b["question"] == "Which datastore?" and not b.get("answered") for b in goal_state(goal)["blocks"]) or False, timeout=60, what="question raised") is not None, "the resumed agent raises its question") conn = db() notices = dict(conn.execute( "select id, resume_notice from sessions where task_id = ?", (run_task,) ).fetchall()) conn.close() resumed_ids = [i for i, text in notices.items() if text] fresh_ids = [i for i, text in notices.items() if not text] check(len(resumed_ids) >= 1 and any("Plan feedback received" in notices[i] for i in resumed_ids), "the resumed session stores the notice it was allocated") check(min(notices) in fresh_ids, "session 1 (the fresh opening round) carries no resume notice") print("== C1: the single run-task row IS the goal's block ==") check("Which datastore?" in pile_questions(), "the open goal question pins onto the dashboard pile") goal_rows = [b for b in goal_state(goal)["blocks"] if b["question"] == "Which datastore?"] run_rows = [b for b in task_state(auth, run_task)["blocks"] if b["question"] == "Which datastore?"] check(len(run_rows) == 1 and len(goal_rows) == 1 and int(run_rows[0]["id"]) == int(goal_rows[0]["id"]), "the goal page and the run task read the SAME single row") pile_card = [b for b in slot_public(auth, "/", "dashboard")["pinned"] if b.get("question") == "Which datastore?"][0] check(pile_card.get("item_type") == "goal" and int(pile_card.get("goal_id") or 0) == goal and int(pile_card.get("id") or 0) == int(run_rows[0]["id"]) and pile_card.get("goal_title") == "Goalui goal", "the pile card is the run-task row styled as a goal item") act(auth, [b for b in goal_state(goal)["blocks"] if b["question"] == "Which datastore?" and not b.get("answered")] [0]["answer_action"], {"option": "SQLite"}) conn = db() unanswered = conn.execute( "select count(*) from task_blocks where question = 'Which datastore?'" " and answer is null").fetchone()[0] conn.close() check(unanswered == 0, "answering from the goal page closes the single row") check("Which datastore?" not in pile_questions(), "the answered row no longer pins the dashboard pile") # The task-page deep link (the AnswerBlockAction API surface) # answers the SAME row through the one goal path — there is no # second row to sweep and no stale copy can survive. conn = db() conn.execute("insert into task_blocks (task_id, type, question, created_at)" " values (?, 'question', 'Deep link probe?'," " strftime('%s','now'))", (run_task,)) conn.commit() conn.close() check("Deep link probe?" in pile_questions(), "the fixture row pins like any goal question") deep_block = [b for b in task_state(auth, run_task)["blocks"] if b["question"] == "Deep link probe?" and not b.get("answered")][0] act(auth, deep_block["answer_action"], {"answer": "Answered via the deep link"}) conn = db() answered_row = conn.execute( "select answer from task_blocks where question = 'Deep link probe?'" ).fetchone()[0] tables = {r[0] for r in conn.execute( "select name from sqlite_master where type = 'table'").fetchall()} conn.close() check(answered_row == "Answered via the deep link", "the task-page deep link answers the same single row (the API path)") check("Deep link probe?" not in pile_questions(), "the deep-link answer closes the pile card too") check("goal_blocks" not in tables, "the goal_blocks table is gone (run-task blocks are canonical)") print("== C5: deep-link closure on the single-row world ==") # The pile card's goal item deep-links the goal page (the answer # surface); answering from either surface settled THE row above. home_markup = http_get_page(auth, "/") check("'/goals/' + blockview.goal_id" in home_markup, "the pile card deep-links the goal page for goal items") conn = db() dupes = conn.execute( "select count(*) from (select question from task_blocks where task_id = ?" " group by question having count(*) > 1)", (run_task,)).fetchone()[0] stragglers = conn.execute( "select count(*) from task_blocks where task_id = ? and answer is null", (run_task,)).fetchone()[0] goal_side_tables = [r[0] for r in conn.execute( "select name from sqlite_master where type = 'table'" " and name in ('goal_blocks','goal_comments','goal_events')").fetchall()] conn.close() check(dupes == 0 and stragglers == 0, "one row per question on the run task, none left unanswered") check(not goal_side_tables, "no goal-side store exists — historical stragglers are impossible") print("== B4: the terminal session dropdown + resume-info panel ==") fake.goal_script = [("suspend",)] check(wait_for(lambda: task_state(auth, run_task)["status"] == "suspended" or False, timeout=60, what="agent parks suspended") is not None, "the agent parks suspended for the requeue scenario") terminal = slot_public(auth, "/tasks/%d/terminal" % run_task, "terminal") ids = [int(s["id"]) for s in terminal["sessions"]] check(ids == sorted(ids, reverse=True), "the session dropdown lists newest-first") check(int(terminal["session_id"]) == ids[0], "the terminal still defaults to the latest session") labels = {int(s["id"]): s["label"] for s in terminal["sessions"]} check(all(label.startswith("Session #") for label in labels.values()), "dropdown labels read 'Session #N — started