Files
crewAI/lib/cli/tests/test_trace_consent_session.py
João MouraandClaude Opus 5.5 4dcd19aa2e fix(tracing): turning tracing on is the answer, and an Evaluate button in the TUI (#7765)
* fix(tracing): turning tracing on is the answer; stop asking again

Two things a user who ran `crewai eval` sees today.

`crewai eval` offers to turn tracing on and run the crew. The run finishes —
and the ephemeral buffer asks "Share this execution trace with CrewAI?", which
is the same question again. Turning tracing on IS consent: `tracing_asked_for()`
is true when `CREWAI_TRACING_ENABLED` says so or when `tracing=True` was passed
in this context, and the buffer takes it as the answer. First-time
auto-collection still asks, because nobody asked for that one.

And the offer named the mechanism rather than the effect — "Turn tracing on
(CREWAI_TRACING_ENABLED=true stays in .env) and run the crew now?", then
"Tracing is on for this project (CREWAI_TRACING_ENABLED=true in .env)." The
variable is how it works, not what the user is agreeing to; both lines now say
what happens and leave the plumbing to the .env file it is written in.

491 telemetry tests and 62 eval-CLI tests green.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(tracing): the TUI's modal is a prompt too, and say where traces go

Two follow-ups from running it.

The terminal UI installs its own consent callback, so turning tracing on still
bought a modal at the end of the run — the callback is consulted before the
default prompt, and the check only guarded the prompt. A host's callback stays
authoritative, because an embedder may answer no for reasons of its own; what
changed is that the TUI's callback, which exists to ASK, now answers for itself
when tracing was asked for.

And having taken the variable out of the offer, the offer should say what saying
yes means: "Turn tracing on and run the crew now? The run's trace is sent to
CrewAI AMP", and afterwards "Tracing is on for this project — its runs are
traced to CrewAI AMP."

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* feat(tui): an Evaluate button beside View Traces and Deploy

A run finishes in the terminal UI and the next question is usually "was that
any good?" — which `crewai eval` answers, from the command line, about the run
that just happened. The button is there now, with `e` bound to it.

It behaves like Deploy rather than like View Traces: it leaves the UI and then
runs the command, because `crewai eval` talks — it prints the link to follow,
waits for the verdict and prints that — and none of it belongs inside a
full-screen app. It calls `eval_crew()` itself rather than reimplementing any
of it, so the button and the command can never say different things; a clean
SystemExit is the command deciding, and a failure is reported without failing
the run that already succeeded.

Declarative flows get it too — same button, same tail.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* feat(telemetry): count `crewai eval`, not only the button that runs it

The TUI's buttons each record a `cli_usage:` feature span, so the new Evaluate
button was counted — but the command it runs was not, and most people will type
`crewai eval` rather than press a button. Every evaluation now records
`cli_usage:eval`; the button keeps its own `cli_usage:evaluate`, so the
difference between the two is how many were started from the TUI.

It counts the command and nothing about the run: no id, no project, no verdict.
And it is wrapped like every other telemetry call here — a missing tracer or a
refused span never stops an evaluation.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* feat(telemetry): say which run was evaluated, and by whom

`project_id` already rides every span. What only this command knows is which
run is being graded, whether the caller was logged in, and — when they are —
which organization they are logged in to. A feature span can carry attributes
now, and `cli_usage:eval` carries those three.

What it does not carry is anything about the work: no inputs, no output, no
verdict, no criteria. The execution id is the join key; what was found lives in
AMP, where the evaluation itself is.

An anonymous caller reports `authenticated=false` and an empty organization, and
is not asked for one.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Address the review: a terminal, a thread, and the right run

Three findings worth acting on, one already fixed, and ruff.

**The security review is right.** `prompt_user_for_trace_viewing` fails closed
where no one can answer, so an anonymous run in CI has never uploaded. Treating
the switch as consent everywhere would have changed that: a project `.env`
copied into CI carries the variable, not the person. `tracing_asked_for()` now
answers only where a prompt could have been shown — the double-ask this PR is
for happens in a terminal, and nothing else moves.

**The ContextVar never crosses the worker.** `set_tracing_enabled` runs in the
crew's validator, on the thread the crew was BUILT on, and a flow never sets it
at all — so `tracing=True` without the env var still opened the modal. The TUI
reads the declaration off the object as well: the same yes, wherever written.

**The button now names the run it watched.** `_chain_eval()` called `crewai eval`
with no id, which looks up the last recorded run — a PREVIOUS run when this one
was not traced, and an offer to run the crew again when there is no record at
all. The TUI remembers what was recorded before the run, hands the new id to the
command, and says "this run was not traced" rather than grading someone else's.

**Already fixed**: telemetry is recorded after `get_or_create_project_id()`, not
before — that moved when the span gained its attributes.

492 telemetry tests, 187 CLI tests. Ruff format and check clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Close all three doors the prompt closes, not just the terminal

The security review named three places `prompt_user_for_trace_viewing` fails
closed — no terminal, a suite under test, and a host that suppressed tracing
messages — and the first pass only honoured the terminal. A run under test, or
inside a host that asked for silence, could still have uploaded on the strength
of a variable.

The three conditions are one function now, `_prompt_can_be_shown()`, used by the
prompt itself and by `tracing_asked_for`, so the rule and the prompt it answers
cannot drift apart. Where the question could not have been put to anybody, there
is nothing to answer and nothing leaves the machine.

The terminal UI decides for itself, and says why: it silences crewAI's console
to keep it out of its own layout, which is a reason a PROMPT cannot be shown,
not a reason to ask a second time — it has a screen and somebody in front of it.

494 telemetry tests, 88 TUI tests. Ruff clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Tests: a real session for the consent rule, and a laid-out screen for a click

The rule that a declared CREWAI_TRACING_ENABLED needs no modal only holds
where a prompt could have been shown, and a test suite is one of the places
it could not — so the three cases about a real session say a person is here.
The consent click waited for the screen, which is not the same as waiting for
its buttons to have a region; it now waits for the layout it clicks on.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* A run started for an evaluation closes itself, even in a child process

A project's crew and flow are run through `uv run …`, so the app lives in
another process and the ContextVar saying "an evaluation is waiting" never
reaches it: the screen stayed open and `crewai eval` waited behind it, which
is the trap the handshake was meant to remove. The environment is the one
thing that crosses into that process, so the command sets a variable there and
clears it after; the id travels back the way it already did, through the
project's last-run record. A run that FAILED leaves too — the command behind
the screen has its own way of saying there is nothing to grade, and it cannot
say it while somebody has to quit a screen first.

And the spans a run exports reach AMP a moment after the run ends, sometimes
later than that, so a command that just watched the run would ask for a trace
still in flight and be told, correctly and uselessly, that there is nothing
there. A run we know is fresh now waits up to two minutes and says it is
waiting; an id somebody typed fails at once, as it always has.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* The evaluation happens in the app, on the screen the reader is already on

Closing the app the moment the run ended and leaving somebody in a bare
terminal, waiting some seconds for a link to appear and a browser to open, is
worse than the screen it replaced. So the evaluation runs where the run does:
`Evaluating this run` under the run's own line, the report link beside it, the
browser opened from there, and `Goal gate PASSED · goal 5/5 · …` when it comes
back. Nothing closes; the reader leaves when they are done reading, and the
link is printed once more on the way out so it outlives the screen.

The Evaluate button does the same thing now instead of quitting the app and
chaining into the command, so there is one implementation of one experience —
`_chain_eval` and `_want_eval` are gone. Pressing it again opens the report it
already made rather than paying for a second evaluation.

Underneath, `crewai eval`'s two steps became callable as values: they raise
`EvaluationStoppedError` with the sentence to show instead of printing and
exiting, and `evaluate_run()` is the app's one door — the url as soon as AMP
gives it, every unfinished answer while it waits. The command keeps the
terminal wording it had; when it ran the crew itself, it now has nothing left
to say and steps aside for the app it opened.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* The button says which report it opens

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* The button works while it waits: it spins, and it stays pressable

A dimmed label that never moves reads as a screen that has stopped. The
Evaluate button now carries the same spinner the run's own line does, the
clock goes back up to eight frames a second while the evaluation runs, and the
button is no longer disabled — the report page is where the progress is, so
pressing it while it waits is the useful thing to do.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* View Traces opens the traces

The button never had a link. crewAI grants one for every exported run and
prints it after a run — but never under a TUI, where its console is kept out
of the layout — so the app had nothing to open and said so, which read as a
feature that had stopped working.

The link is now recorded beside the rest of what crewAI writes when a run's
spans reach AMP, and the button reads it off that record, matched to THIS
app's execution rather than to whatever ran last in the project. When there is
no link the notice says which of the two reasons it is: a run nobody traced,
or a traced run AMP granted no viewer for — only one of those is the reader's
to fix.

Verified against a real anonymous run: pressing `t` opens
app.crewai.com/crewai_plus/ephemeral_traces/<id> and shows it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* The review's five: a trust boundary, a fallback, a retry, an exit and a count

**A project's `.env` cannot lend itself the login.** `evaluate_run()` built its
AMP client after the project's `.env` had been loaded with override, so a
`CREWAI_PLUS_URL` a project put there landed in the set of origins trusted with
the saved `crewai login` bearer. The command reads that variable BEFORE the
`.env` — a shell export is this machine speaking — but inside the app there is
no such "before", so the variable is left out of the set entirely. The request
still follows it; the credential does not.

**A run no app evaluated is still evaluated.** The command returned as soon as
a trace existed, assuming the app had graded it — but a conversational session
never ends the way a crew does and a flow with human feedback takes the
terminal instead, so `crewai eval` could exit 0 having graded nothing. The app
now leaves a marker naming the run it started evaluating, and the command
grades anything that marker does not name.

**An evaluation that stopped can be tried again.** The button re-enabled itself
after a failure but the action still treated any existing evaluation as
finished, so a 502 could only be escaped by re-running the crew.

**A login that exits is shown on screen.** `saved_login()` fails by exiting,
which is not an `Exception` and so slipped past the worker's hands: the button
could sit on "Evaluating…" forever with the reason gone with the exit.

**An evaluation the app runs is counted.** `cli_usage:eval` is the count of
evaluations that begin, and the ones that begin in the app were missing from
it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* A stop is a sentence, and the app's own word settles what it graded

**"1" is not a reason.** A credential that exists but cannot be read stopped
the evaluation by printing its sentence and exiting — under the app the print
lands beneath the layout and the exit carries only a code, so the screen said
`1`. `saved_login()` now raises the stop like everything else that stops an
evaluation, the command catches it where it builds the client and prints it as
before, and the app shows it. The test that claimed to cover this raised a
`SystemExit` carrying a sentence, which is not what `_fail` raises; it now
breaks the credential store and reads what reaches the screen. The worker
still catches an exit, and says that the reason did not survive rather than
echoing its code.

**The record is the project's last finish, not this run.** Another run
finishing in the same project replaces it while the app is open, so "is the
marker about the id in the record" could send the command off to evaluate a
different execution. The marker is now the app's own word about the run it
watched — the id it evaluated, or null when it looked and found nothing to
grade — and the command trusts it over the record, matching on time rather
than on an id that may already have been overwritten. No marker still means no
app got here, which is the conversational session and the flow that takes the
terminal, and the command grades those itself.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* A project can say what good means, and `crewai eval` carries it

An evaluation grades a run against the crew's own `expected_output`s — which
is the prompt that produced the output, so it catches a crew that ignored its
own contract and nothing else. What discriminates lives in criteria somebody
writes, and there was nowhere to write them.

Now there is. After the first evaluation the criteria it used are written to
`eval.jsonc` in the project — once, never over a file that exists, because the
one thing worse than no criteria is criteria that vanish whenever somebody
evaluates — and the line that says so points at what to do with it. From then
on the file travels with every evaluation, as it was written, comments and
all: what a criterion means is the grader's to read, not this command's.

Both doors do it, since most evaluations now happen inside the run app: the
app writes the file and names it in the line that outlives its screen, and
`crewai eval` in a terminal says it there.

The file is bounded at the same 64KB AMP holds the field to, so one that would
be refused is never uploaded and the run is graded anyway.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* The review's asks: anonymous eval stats, a handshake a project cannot forge

Usage stats are anonymous, so the `crewai eval` count says whether the caller
was logged in and nothing else — no execution id, no organization (the product
decision on this PR). Which runs were evaluated, and by whom, is AMP's record.
A feature span now keeps only the keys its own feature lists, in both
telemetry classes; everything else — the dimensions every span carries
included — is dropped.

The run app's "an evaluation is waiting" handshake was an environment variable
any project's `.env` could set, which would start an evaluation with the
machine's login on a plain `crewai run`. Its value is now a random token that
counts only while the command's file of that name exists in the user's crewAI
data directory; a `.env` cannot create a file.

And three smaller ones: when no app evaluated the run, the command grades the
project's record only if it was written after this run began; the "Wrote
eval.jsonc" line after the app closes now appears (the key it read was never
set); an oversized eval.jsonc is said once, through the caller's note, rather
than printed under the TUI on every retry.

uv.lock is back to main's: the change was re-resolution drift, nothing this PR
needs.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* A report link is a web address, and an anonymous request names no organization

Two from the security review of 52fa5f3ae.

The report url comes from whichever AMP answered — which a project's `.env`
may choose — and is printed as a link and opened without a click. It is now
checked where it arrives, before anything shows or opens it: HTTPS, or plain
HTTP to this machine, no credentials in it, no control characters. Anything
else costs the link and nothing more. The host is not pinned: the report is
served by the evaluation service, not by AMP.

A request sent without the login — nobody logged in, or an AMP this machine is
not logged in to — no longer carries the saved organization id. AMP reads it
only beside a credential, so it said nothing to AMP and told an AMP the login
does not go to which organization was asking. Dropped, as anonymous trace
grants already drop it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
2026-09-28 11:28:52 -07:00

294 lines
11 KiB
Python

"""The terminal UI resolves local-session consent without the legacy uploader."""
import asyncio
import threading
from types import SimpleNamespace
from unittest.mock import Mock
from crewai_cli.crew_run_tui import CrewRunApp, TraceConsentScreen
import pytest
from textual.events import Mount
from textual.widgets import Button
class ConsentApp(CrewRunApp):
def on_mount(self, event: Mount | None = None) -> None:
"""Show the real UI without starting a crew or a refresh worker."""
if event is not None:
event.prevent_default()
def _say_a_person_is_here(monkeypatch):
"""The rule only holds where a prompt could have been shown, and a suite is
one of the places it could not. These cases are about a real session."""
utils = "crewai.events.listeners.tracing.utils"
monkeypatch.setattr(f"{utils}._is_test_environment", lambda: False)
monkeypatch.setattr(f"{utils}._is_interactive_terminal", lambda: True)
async def wait_for_consent(app, pilot):
for _ in range(50):
await pilot.pause(0.01)
# A pushed screen is not a laid-out one, and a click lands on the
# region the buttons have — zero-sized until the first layout pass.
if isinstance(app.screen, TraceConsentScreen) and all(
button.region for button in app.screen.query(Button)
):
return app.screen
raise AssertionError("The execution worker did not open the consent prompt")
@pytest.mark.asyncio
@pytest.mark.parametrize(
("action", "approved"),
[
("y", True),
("n", False),
("escape", False),
("click-yes", True),
("click-no", False),
],
)
async def test_session_consent_buttons_and_keys_resolve_execution_worker(
monkeypatch, action, approved
):
app = ConsentApp()
legacy = Mock(side_effect=AssertionError("Session consent invoked legacy upload"))
monkeypatch.setattr(app, "_send_traces_worker", legacy, raising=False)
async with app.run_test(size=(100, 40)) as pilot:
result = asyncio.create_task(asyncio.to_thread(app._request_trace_consent))
screen = await wait_for_consent(app, pilot)
assert str(screen.query_one("#btn-consent-yes", Button).label) == "Share Trace"
content = screen._build_content().plain
assert "stored locally" in content and "Sharing uploads it" in content
assert "prompts, inputs, outputs, and tool calls" in content
assert "20 seconds" in content
assert not result.done()
if action.startswith("click-"):
assert await pilot.click(f"#btn-consent-{action.removeprefix('click-')}")
else:
await pilot.press(action)
assert await asyncio.wait_for(result, timeout=5) is approved
await pilot.pause()
assert not isinstance(app.screen, TraceConsentScreen)
legacy.assert_not_called()
assert app._trace_consent_pending is None
@pytest.mark.asyncio
@pytest.mark.parametrize("value", ["true", "1"])
async def test_tracing_asked_for_needs_no_modal(monkeypatch, value):
"""The user turned tracing on for this project; the modal would be the same
question a second time."""
monkeypatch.setenv("CREWAI_TRACING_ENABLED", value)
_say_a_person_is_here(monkeypatch)
app = ConsentApp()
async with app.run_test(size=(100, 40)) as pilot:
assert await asyncio.to_thread(app._request_trace_consent) is True
await pilot.pause()
assert not isinstance(app.screen, TraceConsentScreen)
assert app._trace_consent_pending is None
@pytest.mark.asyncio
async def test_the_app_suppresses_messages_and_still_needs_no_modal(monkeypatch):
"""This app silences crewAI's console to keep it out of its own layout. That
is a reason a PROMPT cannot be shown, not a reason to ask again — the app
has a screen and somebody in front of it."""
monkeypatch.setenv("CREWAI_TRACING_ENABLED", "true")
_say_a_person_is_here(monkeypatch)
monkeypatch.setattr(
"crewai.events.listeners.tracing.utils.should_suppress_tracing_messages",
lambda: True,
)
app = ConsentApp()
async with app.run_test(size=(100, 40)) as pilot:
assert await asyncio.to_thread(app._request_trace_consent) is True
await pilot.pause()
assert not isinstance(app.screen, TraceConsentScreen)
@pytest.mark.asyncio
async def test_a_declaration_is_the_same_yes_as_the_variable(monkeypatch):
"""`tracing=True` never reaches this worker's context — the crew set it on
the thread it was built on — so the declaration itself is read."""
monkeypatch.delenv("CREWAI_TRACING_ENABLED", raising=False)
_say_a_person_is_here(monkeypatch)
app = ConsentApp()
app._crew = SimpleNamespace(tracing=True)
async with app.run_test(size=(100, 40)) as pilot:
assert await asyncio.to_thread(app._request_trace_consent) is True
await pilot.pause()
assert not isinstance(app.screen, TraceConsentScreen)
@pytest.mark.asyncio
async def test_consent_timeout_returns_false_and_dismisses_modal(monkeypatch):
app = ConsentApp()
waits = []
event = threading.Event()
class ExpiredEvent:
def set(self):
event.set()
def wait(self, *, timeout):
waits.append(timeout)
return False
# Replace only this module's event factory, leaving Textual's threads alone.
monkeypatch.setattr(
"crewai_cli.crew_run_tui.threading", SimpleNamespace(Event=ExpiredEvent)
)
legacy = Mock(side_effect=AssertionError("Timeout invoked legacy upload"))
monkeypatch.setattr(app, "_send_traces_worker", legacy, raising=False)
async with app.run_test(size=(100, 40)) as pilot:
result = await asyncio.wait_for(
asyncio.to_thread(app._request_trace_consent), timeout=5
)
assert result is False
await pilot.pause()
assert not isinstance(app.screen, TraceConsentScreen)
assert waits == [20]
assert app._trace_consent_pending is None
legacy.assert_not_called()
@pytest.mark.asyncio
async def test_quit_rejects_pending_consent_and_releases_worker(monkeypatch):
app = ConsentApp()
legacy = Mock(side_effect=AssertionError("Quit invoked legacy upload"))
monkeypatch.setattr(app, "_send_traces_worker", legacy, raising=False)
async with app.run_test(size=(100, 40)) as pilot:
result = asyncio.create_task(asyncio.to_thread(app._request_trace_consent))
await wait_for_consent(app, pilot)
await app.action_quit()
assert await asyncio.wait_for(result, timeout=5) is False
assert app._trace_consent_pending is None
legacy.assert_not_called()
def test_consent_callback_refuses_nonboolean_screen_results(monkeypatch):
app = CrewRunApp()
monkeypatch.setattr(app, "call_from_thread", lambda callback: callback())
monkeypatch.setattr(app, "push_screen", lambda screen, callback: callback("yes"))
monkeypatch.setattr(app, "_dismiss_consent_modal", lambda: None)
assert app._request_trace_consent() is False
@pytest.mark.asyncio
async def test_conversation_quit_can_ask_for_deferred_session_consent(monkeypatch):
app = ConsentApp(conversational=True)
decisions = []
class DeferredFlow:
defer_trace_finalization = True
def finalize_session_traces(self):
decisions.append(app._request_trace_consent())
app._flow = DeferredFlow()
app._conversation_previous_defer_trace_finalization = False
legacy = Mock(side_effect=AssertionError("Conversation quit invoked legacy upload"))
monkeypatch.setattr(app, "_send_traces_worker", legacy, raising=False)
async with app.run_test(size=(100, 40)) as pilot:
quit_task = asyncio.create_task(app.action_quit())
await wait_for_consent(app, pilot)
await pilot.press("n")
await asyncio.wait_for(quit_task, timeout=5)
assert decisions == [False]
assert app._flow.defer_trace_finalization is False
assert app._trace_consent_pending is None
legacy.assert_not_called()
@pytest.mark.asyncio
@pytest.mark.parametrize("prior_turn", [False, True])
async def test_quit_during_turn_discards_trace_after_worker_finishes(
monkeypatch, prior_turn
):
entered, release, finalized = (
threading.Event(),
threading.Event(),
threading.Event(),
)
app = ConsentApp(conversational=True)
completions = []
class RunningFlow:
defer_trace_finalization = True
trace = "prior turn" if prior_turn else None
def handle_turn(self, message):
entered.set()
release.wait(timeout=5)
# A first kickoff stores its deferred lifetime just before returning.
self.trace = "completed turn"
return "done"
def finalize_session_traces(self, *, discard=False):
completions.append(discard)
self.trace = None
finalized.set()
app._flow = RunningFlow()
app._conversation_previous_defer_trace_finalization = False
app._conversation_turn_in_progress = True
app._status = "working"
prompt = Mock(side_effect=AssertionError("Cancelled execution asked for consent"))
monkeypatch.setattr(app, "push_screen", prompt)
async with app.run_test(size=(100, 40)):
app._run_conversation_turn_worker("hello")
assert await asyncio.to_thread(entered.wait, 5)
try:
await app.action_quit()
assert completions == []
assert app._request_trace_consent() is False
finally:
release.set()
assert await asyncio.to_thread(finalized.wait, 5)
assert completions == [True]
assert app._flow.trace is None
assert app._flow.defer_trace_finalization is False
prompt.assert_not_called()
@pytest.mark.asyncio
@pytest.mark.parametrize("kind", ["crew", "flow"])
async def test_quit_during_execution_rejects_late_consent(monkeypatch, kind):
entered, release = threading.Event(), threading.Event()
app = ConsentApp()
decisions = []
class RunningExecution:
def kickoff(self, inputs=None):
entered.set()
release.wait(timeout=5)
decisions.append(app._request_trace_consent())
return "done"
setattr(app, f"_{kind}", RunningExecution())
app._status = "working"
prompt = Mock(side_effect=AssertionError("Cancelled execution asked for consent"))
completed = Mock()
failed = Mock()
monkeypatch.setattr(app, "push_screen", prompt)
monkeypatch.setattr(app, "_on_crew_done", completed)
monkeypatch.setattr(app, "_on_crew_failed", failed)
async with app.run_test(size=(100, 40)):
# Own the worker thread so the test awaits its body even after Textual
# cancels its worker wrappers on exit (running threads are not stopped).
run_worker = getattr(app, f"_run_{kind}_worker").__wrapped__
worker = asyncio.create_task(asyncio.to_thread(run_worker, app))
assert await asyncio.to_thread(entered.wait, 5)
try:
await app.action_quit()
finally:
release.set()
await asyncio.wait_for(worker, timeout=5)
assert decisions == [False]
assert app._trace_consent_pending is None
prompt.assert_not_called()
completed.assert_not_called()
failed.assert_not_called()