diff --git a/changelog.d/2213-stage-readonly.fixed.md b/changelog.d/2213-stage-readonly.fixed.md new file mode 100644 index 000000000..8d3685a88 --- /dev/null +++ b/changelog.d/2213-stage-readonly.fixed.md @@ -0,0 +1 @@ +A read-only window no longer offers the Stage write controls that core refuses: Hand a task to a Workflow, Re-match, Pause/Resume/Stop, Edit and the drag palette, plus Reset, are gone from the Stage a workflow row opens, and the Stage prints the host's own read-only sentence instead (#2213). diff --git a/docs/subsystems/workflow.md b/docs/subsystems/workflow.md index 9dbd43c8d..fa86f2189 100644 --- a/docs/subsystems/workflow.md +++ b/docs/subsystems/workflow.md @@ -54,7 +54,7 @@ Everything in `plugins/workflow/`: the graph rules, the run store, the matcher, 1. Friends' Bots are not nodes. A `remote` Bot is refused by create, define and the matcher. 2. The canvas and the run share one graph: nodes, edges and positions. A drag commits `workflow/graph`, but only while **Edit** is on — a factory preset is copied first (#1378). A wire or a reconnect that would list a pair the graph already carries commits nothing new, because `normalizeGraph` refuses a graph that lists one pair twice and then saves none of it: unguarded, the plane would show no edge, no change and only a save error (#2163). Status highlighting reads that same graph. Replacing edges does not recompute who is already running. The Settings canvas paints that graph on the same 960px design plane, scaled to the width the settings page gives it, so the canvas is not a second scroll container inside the page's own scroll; its pointer deltas are divided by the scale, and its wires keep a stronger stroke than a plain divider so an edge can be followed at that size (#1483). - While another dsh holds the Bot team the host is read-only (`roster.readOnly`): the page still reads through `workflow/state`, prints the host's own sentence under `role="status"`, and offers no **Edit**, **Add link** or wire port, so it cannot take a change that core would refuse with `bot/read-only` and then drop (#2187). The same window draws the sidebar's workflow list without **New**, the row's **Rename**/**Delete** or **Hand a task to a Workflow**: the list is read-only too, and an `roster.readOnly` that is not a string, or holds only whitespace, counts as writable — trimmed the way `core/src/client/workflows.js:570` trims it (#2200). + While another dsh holds the Bot team the host is read-only (`roster.readOnly`): the page still reads through `workflow/state`, prints the host's own sentence under `role="status"`, and offers no **Edit**, **Add link** or wire port, so it cannot take a change that core would refuse with `bot/read-only` and then drop (#2187). The same window draws the sidebar's workflow list without **New**, the row's **Rename**/**Delete** or **Hand a task to a Workflow**: the list is read-only too, and an `roster.readOnly` that is not a string, or holds only whitespace, counts as writable — trimmed the way `core/src/client/workflows.js:570` trims it (#2200). The Stage a row opens carries the same lock: it prints the host's sentence under `role="status"` and draws no **Hand a task to a Workflow**, no **Re-match**, no **Pause**/**Resume**/**Stop**, no **Edit**/drag palette and no **Reset**, while the row click, **Progress**, **Flow** and viewing a run still work; a writable roster draws every control exactly as before (#2213). 3. **A live run advances only when its ephemeral Bot replies, following the graph's edges in order.** That reply advances the run and may appear on the workflow stage log; it is not delivered into a persistent sidebar Bot conversation (for example Chief). The `workflow-step` send middleware denies those replies after `stepResult` runs. Nodes start only when their forward predecessors finish and edges reach them. **Early termination (#1537, #1538, #1546, #1570, #1571):** When a node completes **or fails**, the run ends immediately with status `done`, sets `run.earlyEnd` to the condition name, and does not advance to successors, take a success-path `loop`, or burn `onFail` recovery attempts. The two markers that report the task itself end it only on a structured signal (#1546): `needs-human` and `already-claimed` must be a declared OUTPUT whose value **equals** the marker, or a whole reply line that is exactly `EARLY-END ` in any case. A step that quotes an issue title, negates the label or reports it absent keeps running. `tip-unchanged` (#1570) and `open-pr` (#1571) accept that same structured signal — in a declared OUTPUT the value counts as a whole word, so a brief that names `data-open-project` is not `open-pr` (#1866) — and also honor their prose fallbacks (`tip unchanged` / `unchanged tip`, `open PR already` / `already has an open PR` / `has an open PR` / `found an open PR`), so a Bot that forgets the structured marker cannot soft-lock Claim↔Verify on the same tip. See `checkEarlyEnd` in Key files. Factory prompt guidance lives in `EARLY_END_GUIDANCE` (`plugins/workflow/src/template.js`) for Settings graphs that wire Triage / Claim / Verify: Verify must escalate once on an unchanged tip, not re-run the full suite. There is no scripted or seeded run path: `workflow/state` exposes only `live === true` runs — the running ones, plus the last run when it is still `live` and ended `failed` — a failed sibling stays on the stage beside whatever is running now, with `run.failure` (`{ code, at, nodeName?, text? }`) naming what ended it, so the room does not have to open Runs to learn that a run failed (#1493, #1494). The failed sibling is left out when a running run carries the same task id: that is a retry, and the live run keeps the row (#1507). History entries carry the run `id` and the same `failure`, so a Runs row shows when the run ended and why, and a row for a run already on the stage is not listed twice. A run does not create a schedule. `scheduleLabel` is display text. When the host can create Bots, starting a live run (`assign`, `run_workflow`, `ingest`) spawns one ephemeral Bot per node from that node's prompt, role, model and tools, sends it the step from the Main Bot, and removes every instance when the run finishes, fails for good, or is reset. A `failOnce` retry keeps them. They are hidden and left out of the sidebar. Loading the plugin does not spawn Bots for the default workflows. Plugin unload (`dispose`) and the load-time `reap` both end a live run still marked `running`: in-flight nodes are failed, the run is archived as `failed`, and any ephemeral Bot ids are released. A run already written as `running` with no ephemeral map (an older unload) is healed the same way on the next load (#1414). Loading is also the one moment a run the host left behind is noticed when its ephemeral map is still present: `reap` releases those instances and records the run as `failed`. Nothing resumes it. A run that already ended keeps its own status (#1388). `workflow/reset` stopping one live run ends it the same way before its Bots are released: nodes still `running` become `failed`, so the strip cannot keep painting a run that is over (#1424). A graph edit that drops a node that is still running ends that run the way Stop does: the node is failed, the run is archived `failed`, its node Bots are released, and the queue drains (#1549); an id whose release failed stays named on that archived run, and the next load's `reap` retries it, instead of the edit forgetting it (the #1616 contract). Every wait is bounded (#1530). A dispatch that does not land is not marked handed: the chat names the code and the attempt, and it is retried after a short backoff at most twice, never twice inside one hand-off, so a 429 is not hammered. When it still does not land, the step and the run fail with the reason written into the chat. Each running live step also holds a deadline — its workflow's `stepTimeoutMinutes`, `DEFAULT_STEP_TIMEOUT_MINUTES` (45 minutes) unless the record sets one, an integer from 1 to 120 given at create, through `define_workflow`, or through `workflow/step-timeout` (armed even when the host cannot spawn ephemeral Bots; #1530, #1580); when it expires the node and the run fail as `failed`, the run's ephemeral Bots are released, the chat and `run.failure` say the step's deadline was reached (`step deadline reached (45 min)`, the number its lane set), and `warn` names it once; the line never reads as a reply that did not arrive, because a step still working is killed by the same timer (#1868). The deadline is cleared as soon as the step moves, and by Pause, Stop, Reset, delete, `reap` and `dispose`; a paused run holds none, and Resume arms it again from that moment. A timer never outlives the run that started it. A reply that matches no running step — its run ended, or the node already moved — is reported through `warn` once per Bot and run instead of being dropped silently. A reply that says `could not answer your message` or `model call failed` fails that node and does not start its successor. A 429 or rate-limit mention in any other reply does not. Stop and Reset (`workflow/reset`) follow the same order as `dispose`: they release the run's Bots before the record forgets their ids, and an id whose release failed stays named on the still-live run, so the next Stop, Reset, dispose or load-time `reap` retries it (#1476). A run left that way is marked `paused` and `releasePending` and shows as Paused: it hands off no further node, `resume` is refused with an error, and Stop again is the retry. A whole-workflow Reset that could not release every Bot freezes every run it did not reset, because each of them has lost the ids whose release did go. The markers go away when the run ends: Stop again, `dispose`, `reap`, or its own completion. 4. Each workflow keeps a FIFO queue and up to `maxConcurrent` live runs (default 2, an integer from 1 to 8 on the record, via `workflow/concurrency`, or in Settings → Workflow graphs). A task that does not fit is enqueued. When a run finishes, every workflow with a free slot is drained, oldest enqueue first. A new assign on a workflow that already has a queue waits behind it. A task does not replace a running run or release that run's Bots. Migrating an old store keeps only runs that were still `running` with ephemeral Bot ids; other legacy scripted rows are dropped from active state (finished tasks may remain in lane history). History records a finished or failed live run. Lowering the cap does not stop a run that has already started. Assigning `{ botId }` claims the card for that local Bot and does not enqueue. A remote Bot is refused. `activeCount` is `runningOf(lane)` — live runs with `live === true` and `status === 'running'`. The stage aggregate chip and the Runs tab (运行记录) must agree: every such run appears as its own running row and progress card with its own `status` (never a hardcoded Running), the chip count does not exceed that list, and a failed sibling appears with its time and reason. On the Runs list, the clock stays in a non-shrinking column with a gap before the status chip, and a Failed row paints the Failed chip once — a generic Failed with no host detail does not also draw `wf-hist-reason` (#1618). 5. A node declares up to eight inputs and eight outputs. A required input is an output of the same name on an ancestor, or `task`, `title`, or `brief` on a root. A start with no provider is refused, and Bots spawned for that attempt are released. On a Bot-backed run a successor stays queued until its required inputs are present. If every forward predecessor is done, failed or skipped and an input is still missing, that node fails and the run stops. The dispatch text carries `Input : `. The Bot reports `OUTPUT : `; a single declared output may be the reply body. A declared output a gate reads is required (§3): when a `when`/`else` or `until` edge reads it and the step's reply does not produce it, the step fails with `failure.text` `Missing OUTPUT ` instead of settling, so the gate never reads silence as "not this branch" and the run cannot close `done` on it; a delivered value that does not equal `eq` still completes the step and skips the untaken branch (#1773). Nodes start in edge order. diff --git a/plugins/workflow/client.js b/plugins/workflow/client.js index 3a4eb97f6..d339255b1 100644 --- a/plugins/workflow/client.js +++ b/plugins/workflow/client.js @@ -510,7 +510,7 @@ window.__ModuleLoader__.load({ }))) } - function RunStrip({ workflow, run, focused, onFocus, onPause, onResume, onStop, onTab, onOpenDrawer }) { + function RunStrip({ workflow, run, focused, locked, onFocus, onPause, onResume, onStop, onTab, onOpenDrawer }) { const running = (run.running ?? []).map(id => nodeOf(workflow, id)).filter(Boolean) const chipClass = run.status === 'done' ? 'done' : (run.status === 'failed' ? 'failed' : (run.paused ? 'queued' : (running[0] ? 'running' : 'queued'))) const chipLabel = run.status === 'done' ? tr('Done') : (run.status === 'failed' ? tr('Failed') : (run.paused ? tr('Pause') : (running[0] ? tr('Running') : tr('Queued')))) @@ -539,16 +539,16 @@ window.__ModuleLoader__.load({ h('div', { className: 'wf-strip-progress', 'aria-label': tr('Progress'), title: tr('Progress') }, h('div', { className: 'wf-segs' }, (run.marks ?? []).map((mark, index) => h('span', { key: index, className: `wf-seg ${mark}` })))), h('div', { className: 'wf-strip-actions' }, - run.status === 'running' ? (run.paused + locked ? null : (run.status === 'running' ? (run.paused ? h('button', { type: 'button', className: 'wf-btn wf-sm wf-pri', onClick: (event) => { stopBubble(event); onResume?.(run.id) } }, tr('Resume')) - : h('button', { type: 'button', className: 'wf-btn wf-sm', onClick: (event) => { stopBubble(event); onPause?.(run.id) } }, tr('Pause'))) : null, - run.status === 'running' ? h('button', { type: 'button', className: 'wf-btn wf-sm wf-danger-outline', onClick: (event) => { stopBubble(event); onStop?.(run.id) } }, tr('Stop')) : null, + : h('button', { type: 'button', className: 'wf-btn wf-sm', onClick: (event) => { stopBubble(event); onPause?.(run.id) } }, tr('Pause'))) : null), + locked ? null : (run.status === 'running' ? h('button', { type: 'button', className: 'wf-btn wf-sm wf-danger-outline', onClick: (event) => { stopBubble(event); onStop?.(run.id) } }, tr('Stop')) : null), h('button', { type: 'button', className: 'wf-btn wf-sm', onClick: (event) => { stopBubble(event); focus(); onOpenDrawer?.(); onTab('runs') } }, tr('Progress')), h('button', { type: 'button', className: 'wf-btn wf-sm', onClick: (event) => { stopBubble(event); focus(); onOpenDrawer?.(); onTab('flow') } }, tr('Flow')))) } // Stage: view/control only — progress and flowchart; no message composer (#1459). - function Stage({ workflow, roster, stageLeft, drawer, tab, focusedRunId, onFocusRun, onCloseDrawer, onToggleDrawer, onOpenDrawer, onTab, onAssign, onTip, onReset, editing, onToggleEdit, onCommit, onPause, onResume, onStop, onRematch }) { + function Stage({ workflow, roster, locked, readOnlyReason, stageLeft, drawer, tab, focusedRunId, onFocusRun, onCloseDrawer, onToggleDrawer, onOpenDrawer, onTab, onAssign, onTip, onReset, editing, onToggleEdit, onCommit, onPause, onResume, onStop, onRematch }) { const chatRef = useRef(null) const chatFoot = useRef({ height: 0, shown: 0 }) const liveRuns = liveStageRuns(workflow) @@ -575,20 +575,21 @@ window.__ModuleLoader__.load({ h('span', { className: 'wf-pill-name' }, workflow.name), h('span', { className: 'wf-chev', 'aria-hidden': true }, '▾')), h('div', { className: 'wf-actions' }, - h('button', { type: 'button', className: 'wf-btn wf-pri', onClick: onAssign }, tr('Hand a task to a Workflow')))), + locked ? null : h('button', { type: 'button', className: 'wf-btn wf-pri', onClick: onAssign }, tr('Hand a task to a Workflow')))), + locked ? h('div', { className: 'wf-muted wf-read-only', role: 'status' }, readOnlyReason) : null, showSummary ? h('div', { className: 'wf-strip wf-strip-summary' }, h('span', { className: 'wf-chip queued' }, tr('{count} running · queue {depth}', { count: workflow.activeCount ?? liveRuns.length, depth: workflow.queueDepth ?? 0 }))) : null, held.length > 0 ? h('div', { className: 'wf-held' }, h('div', { className: 'wf-held-head' }, tr('Tasks this workflow holds')), held.map(taskId => h('div', { className: 'wf-held-row', key: taskId }, h('span', { className: 'wf-held-id', title: taskId }, taskId), - h('button', { type: 'button', className: 'wf-btn wf-sm', onClick: () => onRematch?.(taskId) }, tr('Re-match')))), + locked ? null : h('button', { type: 'button', className: 'wf-btn wf-sm', onClick: () => onRematch?.(taskId) }, tr('Re-match')))), (workflow.heldTaskCount ?? held.length) > held.length ? h('div', { className: 'wf-held-more' }, tr('{count} more held tasks', { count: (workflow.heldTaskCount ?? held.length) - held.length })) : null) : null, liveRuns.length > 0 ? h('div', { className: 'wf-strips' }, liveRuns.map(run => h(RunStrip, { - key: run.id, workflow, run, focused: viewRun?.id === run.id, + key: run.id, workflow, run, focused: viewRun?.id === run.id, locked, onFocus: onFocusRun, onPause, onResume, onStop, onTab, onOpenDrawer, }))) : null, visible.length > 0 ? h('div', { className: 'wf-chat', ref: chatRef }, @@ -597,7 +598,7 @@ window.__ModuleLoader__.load({ drawer ? h('aside', { className: 'wf-drawer' }, h('div', { className: 'wf-dr-head' }, h('button', { type: 'button', className: 'wf-icon', 'aria-label': tr('Close'), onClick: onCloseDrawer }, '×')), - h(DrawerBody, { workflow, roster, tab, onTab, onReset, onTip, editing, onToggleEdit, onCommit, viewRun })) : null) + h(DrawerBody, { workflow, roster, tab, locked, onTab, onReset, onTip, editing, onToggleEdit, onCommit, viewRun })) : null) } function Bubble({ message, workflow, roster }) { @@ -617,7 +618,7 @@ window.__ModuleLoader__.load({ message.attachments?.length ? h('div', { className: 'wf-att' }, message.attachments.map(name => h('span', { key: name }, name))) : null))) } - function DrawerBody({ workflow, roster, tab, onTab, onReset, onTip, editing, onToggleEdit, onCommit, viewRun }) { + function DrawerBody({ workflow, roster, tab, locked, onTab, onReset, onTip, editing, onToggleEdit, onCommit, viewRun }) { const run = viewRun?.live === true ? viewRun : null // The Flow tab paints the run the stage already has — the live run if there is // one, else the last one — so an idle workflow shows its last result, the same @@ -632,10 +633,10 @@ window.__ModuleLoader__.load({ ['flow', 'details', 'runs'].map(key => h('button', { key, type: 'button', role: 'tab', 'aria-selected': tab === key, className: tab === key ? 'on' : '', onClick: () => onTab(key), }, tr(key === 'flow' ? 'Flow' : key === 'details' ? 'Details' : 'Runs')))), - tab === 'flow' ? h(Flow, { workflow, run, nodeStatus, roster, onTip, editing, onCommit }) : null, + tab === 'flow' ? h(Flow, { workflow, run, nodeStatus, roster, onTip, editing: locked ? false : editing, onCommit }) : null, tab === 'details' ? h(Details, { workflow, roster }) : null, tab === 'runs' ? h(Runs, { workflow }) : null, - h('div', { className: 'wf-ctl' }, + locked ? null : h('div', { className: 'wf-ctl' }, h('button', { type: 'button', className: 'wf-btn', onClick: onReset }, `↺ ${tr('Reset')}`), h('button', { type: 'button', className: 'wf-btn', onClick: onToggleEdit }, editing ? tr('Finish editing') : tr('Edit')))) } @@ -2003,9 +2004,14 @@ window.__ModuleLoader__.load({ const prev = root.openWorkflowAssign // #1457: this path opened the dialog without ever loading the board, so it could only // ever show the frozen empty state. - root.openWorkflowAssign = () => { setAssignOpen(true); setOpenId(id => id); void loadTasks() } + // #2213: the Stage's Hand a task button is gone in a read-only window, and this second + // door must not open the dialog it no longer offers. + root.openWorkflowAssign = () => { + if (locked) return + setAssignOpen(true); setOpenId(id => id); void loadTasks() + } return () => { root.openWorkflowAssign = prev } - }, []) + }, [locked]) // One poll: while a run is live, for the Bot replies that advance nodes, and while a // read error is showing, so a refused read is retried. Two effects used to test the @@ -2209,7 +2215,7 @@ window.__ModuleLoader__.load({ error ? h('div', { className: 'wf-err', role: 'alert' }, error) : null, readError ? h('div', { className: 'wf-err', role: 'alert' }, readError) : null, open ? portal(h(Stage, { - workflow: open, roster, stageLeft, drawer, tab, focusedRunId, + workflow: open, roster, locked, readOnlyReason, stageLeft, drawer, tab, focusedRunId, onFocusRun: setFocusedRunId, editing, onToggleEdit: () => { setEditing(value => !value); setDrawer(true); setTab('flow') }, diff --git a/plugins/workflow/test/client.test.js b/plugins/workflow/test/client.test.js index a69b39dd1..13cb9bcb6 100644 --- a/plugins/workflow/test/client.test.js +++ b/plugins/workflow/test/client.test.js @@ -3558,3 +3558,121 @@ test('#2200: the host sentence #2187 put on the page is still there', async () = assert.ok(statuses.some(node => textOf(node).includes(READ_ONLY_REASON)), 'the page still says why in the host\'s own words') view.unmount() }) + +// #2213: the Stage a list row opens. #2200 took the write entries off the list and #2187 off +// the Settings graph page, but the Stage never received `locked`: Hand a task, Re-match, +// Pause/Stop, Edit and the drag palette all drew, and every press was refused behind the mask. +const STAGE_GRAPH = () => ({ + ...delivery(), id: 'lane-a', name: 'Lane A', + heldTasks: ['t-9'], heldTaskCount: 1, +}) + +async function mountStage(roster, graph = STAGE_GRAPH(), calls = []) { + const view = mount(client.Section, { roster, call: sidebarHost(graph, calls), actions: {} }) + await settle() + laneRow(view).props.onClick() + await settle() + return { view, calls } +} + +const buttonsOf = view => findAll(view.tree, node => node.type === 'button') +const countButton = (view, label) => buttonsOf(view).filter(node => (label === 'Reset' ? textOf(node).endsWith('Reset') : textOf(node) === label)).length +const WRITE_LABELS = ['Hand a task to a Workflow', 'Re-match', 'Pause', 'Resume', 'Stop', 'Edit', 'Finish editing', 'Reset'] + +async function openDrawerTabs(view, ...tabs) { + button(view.tree, 'Progress')?.props.onClick() + await settle() + for (const tab of tabs) { button(view.tree, tab)?.props.onClick(); await settle() } +} + +test('#2213: a read-only Stage draws no write entry and says why', async () => { + const { view, calls } = await mountStage({ bots: [], readOnly: READ_ONLY_REASON }) + assert.ok(findAll(view.tree, node => node.props?.className === 'wf-stage').length > 0, 'the row still opens the Stage') + const offered = [] + for (const label of WRITE_LABELS) { + const n = countButton(view, label) + if (n) offered.push(`${label} x${n}`) + } + await openDrawerTabs(view, 'Flow') + for (const label of WRITE_LABELS) { + const n = countButton(view, label) + if (n && !offered.some(item => item.startsWith(`${label} `))) offered.push(`${label} x${n}`) + } + // A reader in this window can still press what the page wrongly offers: take Edit if it is + // there, so the drag palette this bug also leaves open is exercised, not just inferred. + if (button(view.tree, 'Edit')) { button(view.tree, 'Edit').props.onClick(); await settle() } + if (findAll(view.tree, node => node.props?.className === 'wf-palette').length) offered.push('wf-palette') + assert.deepEqual(offered, [], 'a read-only Stage offers no write entry') + const why = findAll(view.tree, node => node.props?.role === 'status').map(textOf) + assert.ok(why.some(text => text.includes(READ_ONLY_REASON)), 'the Stage says why in the host\'s own words') + assert.deepEqual(calls.filter(item => item.name !== 'workflow/state'), [], 'nothing was written from the Stage') + view.unmount() +}) + +test('#2213: a read-only Stage still opens, reads and shows Progress / Flow', async () => { + const { view } = await mountStage({ bots: [], readOnly: READ_ONLY_REASON }) + assert.ok(button(view.tree, 'Progress'), 'Progress still opens the runs') + assert.ok(button(view.tree, 'Flow'), 'Flow still draws the run') + button(view.tree, 'Flow').props.onClick() + await settle() + assert.ok(findAll(view.tree, node => node.props?.['data-node'] === 'coder').length > 0, 'the flow still draws its nodes') + view.unmount() +}) + +test('#2213: a writable Stage keeps every write entry', async () => { + for (const roster of [{ bots: [] }, { bots: [], readOnly: '' }, { bots: [], readOnly: ' ' }]) { + const why = `roster.readOnly=${JSON.stringify(roster.readOnly)}` + const { view } = await mountStage(roster) + for (const label of ['Hand a task to a Workflow', 'Re-match', 'Pause', 'Stop']) { + assert.ok(countButton(view, label) > 0, `${label} stays (${why})`) + } + await openDrawerTabs(view, 'Flow') + assert.ok(countButton(view, 'Edit') > 0, `Edit stays (${why})`) + assert.ok(countButton(view, 'Reset') > 0, `Reset stays (${why})`) + button(view.tree, 'Edit').props.onClick() + await settle() + assert.ok(findAll(view.tree, node => node.props?.className === 'wf-palette').length > 0, `the drag palette opens (${why})`) + view.unmount() + } +}) + +test('#2213: a writable Stage keeps Resume on a paused run', async () => { + const graph = { ...STAGE_GRAPH(), run: { ...delivery().run, paused: true } } + const { view } = await mountStage({ bots: [] }, graph) + assert.ok(countButton(view, 'Resume') > 0, 'Resume stays on a paused run') + view.unmount() +}) + +// #2213: Hand a task had a second door. `__flybot__.openWorkflowAssign` opens the same +// dialog for the host's own callers, and it never read the window's lock: with the Stage +// button gone, a read-only window could still get the dialog (and its Assign) through it. +const withFlybotRoot = async (fn) => { + const prev = globalThis.__flybot__ + globalThis.__flybot__ = {} + try { return await fn() } finally { globalThis.__flybot__ = prev } +} + +test('#2213: a read-only window cannot open the assign dialog through __flybot__', async () => { + await withFlybotRoot(async () => { + const { view } = await mountStage({ bots: [], readOnly: READ_ONLY_REASON }) + const open = globalThis.__flybot__.openWorkflowAssign + assert.equal(typeof open, 'function', 'the host still finds the entry') + open() + await settle() + assert.equal(findAll(view.tree, node => node.props?.role === 'dialog').length, 0, 'no assign dialog in a read-only window') + view.unmount() + }) +}) + +test('#2213: a writable window still opens the assign dialog through __flybot__', async () => { + for (const roster of [{ bots: [] }, { bots: [], readOnly: '' }, { bots: [], readOnly: ' ' }]) { + const why = `roster.readOnly=${JSON.stringify(roster.readOnly)}` + await withFlybotRoot(async () => { + const { view } = await mountStage(roster) + globalThis.__flybot__.openWorkflowAssign() + await settle() + assert.equal(findAll(view.tree, node => node.props?.role === 'dialog').length, 1, `the assign dialog opens (${why})`) + view.unmount() + }) + } +})