fix(cli): add missing _log.debug call to session export/import/tell DatabaseError handlers
CI / lint (pull_request) Successful in 27s
CI / typecheck (pull_request) Successful in 1m1s
CI / security (pull_request) Successful in 53s
CI / quality (pull_request) Successful in 42s
CI / build (pull_request) Successful in 27s
CI / helm (pull_request) Successful in 24s
CI / unit_tests (pull_request) Successful in 6m58s
CI / e2e_tests (pull_request) Successful in 17m8s
CI / coverage (pull_request) Successful in 10m45s
CI / integration_tests (pull_request) Successful in 22m52s
CI / docker (pull_request) Successful in 1m23s
CI / status-check (pull_request) Successful in 1s
CI / benchmark-publish (pull_request) Has been skipped
CI / benchmark-regression (pull_request) Successful in 57m12s
CI / lint (pull_request) Successful in 27s
CI / typecheck (pull_request) Successful in 1m1s
CI / security (pull_request) Successful in 53s
CI / quality (pull_request) Successful in 42s
CI / build (pull_request) Successful in 27s
CI / helm (pull_request) Successful in 24s
CI / unit_tests (pull_request) Successful in 6m58s
CI / e2e_tests (pull_request) Successful in 17m8s
CI / coverage (pull_request) Successful in 10m45s
CI / integration_tests (pull_request) Successful in 22m52s
CI / docker (pull_request) Successful in 1m23s
CI / status-check (pull_request) Successful in 1s
CI / benchmark-publish (pull_request) Has been skipped
CI / benchmark-regression (pull_request) Successful in 57m12s
Add _log.debug("session export failed", exc_info=True),
_log.debug("session import failed", exc_info=True), and
_log.debug("session tell failed", exc_info=True) to the DatabaseError
handlers in export_session, import_session, and tell commands respectively.
This brings these handlers into consistency with the existing create, list,
show, and delete handlers which already include the _log.debug call for
diagnostic tracebacks when --log-level debug is used.
Also adds three new BDD scenarios and step implementations that verify
_log.debug is called in each of the three handlers, ensuring the pattern
is tested and cannot regress.
ISSUES CLOSED: #2788
This commit is contained in:
@@ -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