Skip to main content

max / alloy

Teach the spawn seal the sibling test-module form The seal cuts each module at its trailing `#[cfg(test)]` so test code, which spawns freely and does not ship, is not read as a production spawn. It asserted the tail opened `mod tests {` on purpose, so that code added below the tests could not be silently exempted. The sibling form declares `mod tests;` instead, which broke that assert on all eight moved files. Accept both, keep the no-code-below-the-tests guarantee for each, and skip `tests.rs` in the walk so a moved test's Command::new is not counted as a shipped spawn.
Co-Authored-By
Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session
https://claude.ai/code/session_01EEmeiSJnmyL98QzA5Dwsvz
Author: Max Johnson <me@maxj.phd> · 2026-09-03 22:53 UTC
Signed with PGP, not checked
Commit: 6e7fa8b3d82880dbc334ba6f9b09eb8265146c8f
Parent: f118b35
1 file changed, +24 insertions, -7 deletions
@@ -64,6 +64,12 @@
64 64 if path.extension().is_none_or(|ext| ext != "rs") {
65 65 continue;
66 66 }
67 + // A module's tests may live inline or in a `tests.rs` beside it. Both are
68 + // test code and neither ships, so the sibling form is skipped here for the
69 + // same reason `shipped` cuts the inline form off below.
70 + if path.file_name().is_some_and(|name| name == "tests.rs") {
71 + continue;
72 + }
67 73 let name = path
68 74 .strip_prefix(root)
69 75 .expect("walked from root")
@@ -83,7 +89,8 @@
83 89 /// user's session `PATH` decides.
84 90 ///
85 91 /// The cut is the first `#[cfg(test)]` in the first column, which every module
86 - /// here places on the file's last item. That shape is asserted rather than
92 + /// here places on the file's last item, whether that item opens the tests inline
93 + /// or declares them in a `tests.rs` sibling. That shape is asserted rather than
87 94 /// assumed: a module that grew code below its tests would otherwise have that
88 95 /// code silently exempted, which is the one way this check could go quiet
89 96 /// without failing.
@@ -100,14 +107,24 @@
100 107 "{name} has more than one `#[cfg(test)]` in the first column; \
101 108 the tail is no longer a single test module"
102 109 );
110 + let inline = tail.starts_with("#[cfg(test)]\nmod tests {\n");
111 + let sibling = tail.starts_with("#[cfg(test)]\nmod tests;");
103 112 assert!(
104 - tail.starts_with("#[cfg(test)]\nmod tests {\n"),
105 - "{name}'s `#[cfg(test)]` does not open a `mod tests`"
106 - );
107 - assert!(
108 - tail.trim_end().ends_with('}'),
109 - "{name} does not end with its test module"
113 + inline || sibling,
114 + "{name}'s `#[cfg(test)]` neither opens nor declares a `mod tests`"
110 115 );
116 + if inline {
117 + assert!(
118 + tail.trim_end().ends_with('}'),
119 + "{name} does not end with its test module"
120 + );
121 + } else {
122 + assert_eq!(
123 + tail.trim_end(),
124 + "#[cfg(test)]\nmod tests;",
125 + "{name} has code below its test module declaration"
126 + );
127 + }
111 128
112 129 text[..at].to_string()
113 130 }