Repository navigation
wiring: read past #[cfg(test)] items and treat split-out test files as tests - #64
Merged
Merged
Conversation
…s tests
Two blind spots in the dead-capability scanner, both measured:
1. It stopped reading a file at the first column-zero #[cfg(test)], even
when that attribute guarded a single `use`. agent/claude_code.rs (now
claude_code/turn.rs:4) opens with `#[cfg(test)] use std::io::BufRead;`,
so ~1,600 production lines were never read. A #[cfg(test)] now hides
exactly the item it guards: the item is brace-matched with strings,
chars and comments skipped, and an inline `mod tests { ... }` hides only
its own body. cfg(all(test, ..)) is test-only; cfg(any(test, ..)) and
cfg(not(test)) are not.
2. Files declared by a parent as `#[cfg(test)] mod x;` carry no marker of
their own, so their calls counted as production callers and their items
as capabilities. Each such declaration is now resolved to its file
(x.rs, x/mod.rs, or #[path]) and that file and its module tree are
test code.
Seeing again raises the honest unwired count from 38 to 41:
Toolbox::set_permission_rules and ClaudeCodeBackend::{with_session,
with_models} are reached only by tests. MAX_UNWIRED is set to 41; the
items are reported, not removed or wired.
Pure move, so wiring.rs is under the 1,000-line threshold (1240 -> 886):
the inline `#[cfg(test)] mod tests { ... }` becomes
`#[cfg(test)] #[path = "wiring_tests.rs"] mod tests;`, the pattern
mcp_config.rs, mcp_oauth.rs and ansi_c.rs already use. No test is
changed, renamed or removed; the body is only dedented one level.
The scanner classifies the new file as test code: it calls `unwired_in`
and `Unwired::line_report`, both on the unwired list, so reading it as
production would drop the count to 39 and fail the ratchet. It stays 41.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two measured blind spots in the dead-capability scanner (
src/wiring.rs), found in the independent review of #63.Root causes and fixes
#[cfg(test)], even when that attribute guarded a singleuse.src/agent/claude_code.rs:8(nowsrc/agent/claude_code/turn.rs:4) opens with#[cfg(test)]\nuse std::io::BufRead;, so about 1,600 production lines were never read, in either direction: their callers didn't count and their functions were never declared.Fix:
scan_sourcetreats a#[cfg(test)]as a guard on the one item that follows it. The item is brace-matched, skipping strings, raw strings, chars and comments. An inlinemod tests { … }hides only its own body, and the code after its closing brace is production again.cfg(all(test, …))counts as test-only.cfg(any(test, …))andcfg(not(test))do not, because both ship.#[cfg(test)] mod x;has no marker of its own, so its calls counted as production callers and its helpers as capabilities.Fix:
test_module_filesresolves each such declaration the way rustc does:x.rsorx/mod.rsnext to the declaring file, or the#[path = "…"]target relative to the declaring file's directory. That file and every module file declared beneath it are test code. On this tree it resolves 36 files (all*_tests.rs,parser_pins.rs,permissions/rules/tests/*,tools/documents/fixtures.rs, …).Scanner tests, each with a control
a_test_only_use_does_not_hide_the_rest_of_the_file: a#[cfg(test)] usemid-file. A caller below it must be seen, and a dead fn below it must be declared.an_inline_test_module_hides_only_its_own_body: an inline test mod whose body contains'{',"}",r#"}}"#and// }. Production code after it must be read, and calls inside it must not count.a_split_out_test_file_is_neither_a_caller_nor_a_capability: covers a sibling#[cfg(test)] mod x;, a#[path]one,cfg(all(test, unix)), a module tree below a test file, and acfg(any(test, …))module that must stay production.Controls were run locally, then restored:
usewas not seen" and "production code after an inline test module was not read".Unwired count: 38 → 41
MAX_UNWIREDis set to the honest number, 41. All 38 previous items are still reported. The 3 newly visible items are listed below and were not deleted or wired up in this PR; that is the owner's decision.Toolbox::set_permission_rulessrc/toolbox/mod.rs:947src/toolbox/rule_tests.rs:41(split-out test file);src/agent/codex.rs:2109(inside codex's inlinemod tests, from line 1282)ClaudeCodeBackend::with_sessionsrc/agent/claude_code/mod.rs:297src/agent/claude_code/command_tests.rs:334;src/agent/claude_code/tests.rs:116,:126ClaudeCodeBackend::with_modelssrc/agent/claude_code/mod.rs:310src/agent/claude_code/command_tests.rs:333;src/agent/claude_code/tests.rs:127,:150,:159(plus a comment atmod.rs:509, which doesn't count)Local gate (Windows)
cargo fmt --all -- --checkpassed,cargo clippy --all-targets -q -- -D warningspassed, andcargo test -qpassed (2308 + 59, 0 failed).