Skip to content

Commit 4da5c57

Browse files
dsarnoclaude
andauthored
Quiet plugin ring-buffer console echo during test runs (#496)
A clean, all-green `test_run` printed thousands of alarming lines — ~500 `MCP | filler N` from the log-ring bound test, plus per-test dispatcher `[recv]/[send]` chatter and `[error] ... malformed result` from negative-path suites that deliberately drive failures. It made a passing run look broken. `McpLogBuffer.log()` echoed every line to the Godot console unconditionally (the existing `enabled` field was never consulted). Gate the console `print` on `enabled and console_echo`; the ring buffer still records every line, so tests that assert on buffer contents are unaffected. The test runner flips the new static `console_echo` off for the duration of a run and restores it after, so live logging is unchanged outside tests. This does NOT touch engine-level C++ errors (JSON parse, get_node-from-outside- tree, etc.) that negative-path tests trigger — those aren't routed through our logger and still surface. The 33 raw `print("MCP | ...")` calls in the update/lifecycle paths are also left as-is (real diagnostics, not buffer-routed); trimming those is a possible follow-up. Verified live on Godot 4.6.3: `MCP | filler` lines during a run dropped from ~500 to 0, dispatcher `[error]` lines from 2 to 0, total editor log from thousands to ~400. GDScript suite: 0 failures (new `log_buffer` suite asserts the ring still records under a muted echo). 0 parse errors on 4.6.3 and 4.3. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 5f7ce91 commit 4da5c57

4 files changed

Lines changed: 68 additions & 1 deletion

File tree

plugin/addons/godot_ai/testing/test_runner.gd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ func run_suites(suites: Array, suite_filter: String = "", test_filter: String =
7575
_results.clear()
7676
var start := Time.get_ticks_msec()
7777

78+
## Silence the plugin's ring-buffer console echo while tests run. Negative-
79+
## path suites deliberately fill the ring with 500 lines and log malformed-
80+
## result errors; echoing all of that buries an all-green run in scary
81+
## console output. The ring contents tests assert on are untouched, and
82+
## the flag is restored after the run so live logging resumes.
83+
var _prev_console_echo := McpLogBuffer.console_echo
84+
McpLogBuffer.console_echo = false
85+
7886
for suite: McpTestSuite in suites:
7987
if not suite_filter.is_empty() and suite.suite_name() != suite_filter:
8088
continue
@@ -117,6 +125,7 @@ func run_suites(suites: Array, suite_filter: String = "", test_filter: String =
117125
_cleanup_leaked_nodes(scene_root, before_children)
118126

119127
_last_run_ms = Time.get_ticks_msec() - start
128+
McpLogBuffer.console_echo = _prev_console_echo
120129
return get_results(verbose)
121130

122131

plugin/addons/godot_ai/utils/log_buffer.gd

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ extends RefCounted
66

77
const MAX_LINES := 500
88

9+
## When false, `log()` still records into the ring buffer but does not echo the
10+
## line to the Godot console. The test runner flips this off for the duration
11+
## of a run so negative-path suites (which intentionally drive a 500-line ring
12+
## fill and malformed-result error logging) don't bury an all-green run in
13+
## console noise. Ring *contents* — what tests assert on via `get_recent()` /
14+
## `total_logged()` — are unaffected. Engine-level C++ errors raised by
15+
## negative-path tests are not routed through here and still surface.
16+
static var console_echo := true
17+
918
var _lines: Array[String] = []
1019
## Monotonic count of every line ever passed to `log()` since the last
1120
## `clear()`. Distinct from `_lines.size()`, which is bounded at MAX_LINES.
@@ -19,7 +28,8 @@ var enabled := true
1928

2029
func log(msg: String) -> void:
2130
var line := "MCP | %s" % msg
22-
print(line)
31+
if enabled and console_echo:
32+
print(line)
2333
_lines.append(line)
2434
if _lines.size() > MAX_LINES:
2535
_lines = _lines.slice(-MAX_LINES)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://6rrmdcq3mjsr

0 commit comments

Comments
 (0)