fix(cli): add missing _log.debug call to session export/import/tell DatabaseError handlers #3184
@@ -166,6 +166,11 @@ Feature: Session CLI Coverage Boost
|
||||
Then session coverage boost the exit code is 1
|
||||
And session coverage boost the output contains "Database unavailable"
|
||||
|
||||
Scenario: export command DatabaseError handler emits debug log
|
||||
Given session coverage boost a mock service that raises DatabaseError on export
|
||||
When session coverage boost I invoke the export command to stdout with log capture
|
||||
Then session coverage boost the debug log "session export failed" was emitted
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# import command
|
||||
# ---------------------------------------------------------------
|
||||
@@ -202,6 +207,12 @@ Feature: Session CLI Coverage Boost
|
||||
Then session coverage boost the exit code is 1
|
||||
And session coverage boost the output contains "Database unavailable"
|
||||
|
||||
Scenario: import command DatabaseError handler emits debug log
|
||||
Given session coverage boost a mock service that raises DatabaseError on import
|
||||
And session coverage boost a temporary import file with valid JSON
|
||||
When session coverage boost I invoke the import command expecting database error with log capture
|
||||
Then session coverage boost the debug log "session import failed" was emitted
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# tell command
|
||||
# ---------------------------------------------------------------
|
||||
@@ -236,6 +247,11 @@ Feature: Session CLI Coverage Boost
|
||||
Then session coverage boost the exit code is 1
|
||||
And session coverage boost the output contains "Database unavailable"
|
||||
|
||||
Scenario: tell command DatabaseError handler emits debug log
|
||||
Given session coverage boost a mock service that raises DatabaseError on append
|
||||
When session coverage boost I invoke the tell command without stream with log capture
|
||||
Then session coverage boost the debug log "session tell failed" was emitted
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# show command with long message content truncation
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
@@ -643,6 +643,53 @@ def step_tell_db_error(context):
|
||||
_patch_service(context, svc)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Debug log verification steps (for _log.debug call consistency checks)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@when("session coverage boost I invoke the export command to stdout with log capture")
|
||||
def step_invoke_export_stdout_log_capture(context):
|
||||
|
||||
with patch("cleveragents.cli.commands.session._log") as mock_log:
|
||||
context.result = _runner.invoke(session_app, ["export", _ULID1])
|
||||
context.scvbst_mock_log = mock_log
|
||||
|
||||
|
||||
@when(
|
||||
"session coverage boost I invoke the import command expecting database error with log capture"
|
||||
)
|
||||
def step_invoke_import_db_error_log_capture(context):
|
||||
with patch("cleveragents.cli.commands.session._log") as mock_log:
|
||||
context.result = _runner.invoke(
|
||||
session_app,
|
||||
["import", "--input", str(context.scvbst_import_path)],
|
||||
)
|
||||
context.scvbst_mock_log = mock_log
|
||||
|
||||
|
||||
@when(
|
||||
"session coverage boost I invoke the tell command without stream with log capture"
|
||||
)
|
||||
def step_invoke_tell_no_stream_log_capture(context):
|
||||
with patch("cleveragents.cli.commands.session._log") as mock_log:
|
||||
context.result = _runner.invoke(
|
||||
session_app,
|
||||
["tell", "--session", _ULID1, "Hello world"],
|
||||
)
|
||||
context.scvbst_mock_log = mock_log
|
||||
|
||||
|
||||
@then('session coverage boost the debug log "{message}" was emitted')
|
||||
def step_assert_debug_log_emitted(context, message):
|
||||
mock_log = context.scvbst_mock_log
|
||||
calls = mock_log.debug.call_args_list
|
||||
messages = [str(c.args[0]) if c.args else "" for c in calls]
|
||||
assert any(message in m for m in messages), (
|
||||
f"Expected _log.debug called with '{message}'. Actual debug calls: {calls}"
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Shared assertions
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -622,6 +622,7 @@ def export_session(
|
||||
console.print(f"[red]Export error:[/red] {exc}")
|
||||
raise typer.Exit(1) from exc
|
||||
except DatabaseError as exc:
|
||||
_log.debug("session export failed", exc_info=True)
|
||||
console.print(
|
||||
f"[red]Error:[/red] Database unavailable: {exc}\n"
|
||||
"Hint: run 'agents init' to initialise the database."
|
||||
@@ -672,6 +673,7 @@ def import_session(
|
||||
console.print(f"[red]Import error:[/red] {exc}")
|
||||
raise typer.Exit(1) from exc
|
||||
except DatabaseError as exc:
|
||||
_log.debug("session import failed", exc_info=True)
|
||||
console.print(
|
||||
f"[red]Error:[/red] Database unavailable: {exc}\n"
|
||||
"Hint: run 'agents init' to initialise the database."
|
||||
@@ -746,6 +748,7 @@ def tell(
|
||||
console.print(f"[red]Session not found:[/red] {session_id}")
|
||||
raise typer.Exit(1) from exc
|
||||
except DatabaseError as exc:
|
||||
_log.debug("session tell failed", exc_info=True)
|
||||
console.print(
|
||||
f"[red]Error:[/red] Database unavailable: {exc}\n"
|
||||
"Hint: run 'agents init' to initialise the database."
|
||||
|
||||
Reference in New Issue
Block a user