|
| 1 | +@tool |
| 2 | +extends McpTestSuite |
| 3 | + |
| 4 | +## Coverage for McpLogBuffer's console-echo gating. The ring buffer must keep |
| 5 | +## recording lines (so content-asserting tests stay valid) whether or not the |
| 6 | +## console echo is muted — the test runner mutes it for the whole run. |
| 7 | + |
| 8 | +const McpLogBufferScript := preload("res://addons/godot_ai/utils/log_buffer.gd") |
| 9 | + |
| 10 | + |
| 11 | +func suite_name() -> String: |
| 12 | + return "log_buffer" |
| 13 | + |
| 14 | + |
| 15 | +## NOTE: there is intentionally no "console_echo defaults to true" test — the |
| 16 | +## test runner sets it false for the duration of every run, so the flag is |
| 17 | +## never true mid-run. The production default lives in the declaration |
| 18 | +## (`static var console_echo := true`) and the runner restores the prior value |
| 19 | +## on exit. |
| 20 | + |
| 21 | + |
| 22 | +func test_log_records_to_ring_when_echo_muted() -> void: |
| 23 | + var prev: bool = McpLogBufferScript.console_echo |
| 24 | + McpLogBufferScript.console_echo = false |
| 25 | + var buffer = McpLogBufferScript.new() |
| 26 | + buffer.log("quiet line a") |
| 27 | + buffer.log("quiet line b") |
| 28 | + McpLogBufferScript.console_echo = prev |
| 29 | + |
| 30 | + ## Muting the console must not drop ring entries — the contract that lets |
| 31 | + ## negative-path tests assert on buffer contents during a muted run. |
| 32 | + assert_eq(buffer.total_logged(), 2, "both lines recorded despite muted echo") |
| 33 | + var recent: Array = buffer.get_recent(10) |
| 34 | + assert_eq(recent.size(), 2, "ring holds both muted lines") |
| 35 | + assert_true(String(recent[-1]).ends_with("quiet line b"), "last line preserved verbatim") |
| 36 | + |
| 37 | + |
| 38 | +func test_per_instance_enabled_gates_recording_independently() -> void: |
| 39 | + ## `enabled` gates the console print per instance; recording still happens. |
| 40 | + var prev: bool = McpLogBufferScript.console_echo |
| 41 | + McpLogBufferScript.console_echo = false |
| 42 | + var buffer = McpLogBufferScript.new() |
| 43 | + buffer.enabled = false |
| 44 | + buffer.log("still recorded") |
| 45 | + McpLogBufferScript.console_echo = prev |
| 46 | + |
| 47 | + assert_eq(buffer.total_logged(), 1, "line recorded even with enabled=false") |
0 commit comments