@@ -35,17 +35,28 @@ type Module = (String, String);
3535/// `core` and `bus` always load, since everything else depends on them.
3636/// Bisecting a crash otherwise means an edit and a rebuild per attempt, and
3737/// every attempt costs a game restart.
38- pub fn bundle ( dir : Option < & Path > , skip : & [ String ] , only : & [ String ] ,
39- ask : bool , no_hook : & [ String ] , trace : bool ) -> Result < String > {
38+ pub fn bundle (
39+ dir : Option < & Path > ,
40+ skip : & [ String ] ,
41+ only : & [ String ] ,
42+ ask : bool ,
43+ no_hook : & [ String ] ,
44+ trace : bool ,
45+ ) -> Result < String > {
4046 let ( mut out, sources) = read ( dir) ?;
4147
4248 // Individual sites the agent must not attach to, read by core's hook().
4349 let names: Vec < String > = no_hook. iter ( ) . map ( |n| format ! ( "\" {n}\" " ) ) . collect ( ) ;
44- out. push_str ( & format ! ( "
50+ out. push_str ( & format ! (
51+ "
4552var NO_HOOK = [{}];
46- " , names. join( ", " ) ) ) ;
47- out. push_str ( & format ! ( "var HOOK_TRACE = {trace};
48- " ) ) ;
53+ " ,
54+ names. join( ", " )
55+ ) ) ;
56+ out. push_str ( & format ! (
57+ "var HOOK_TRACE = {trace};
58+ "
59+ ) ) ;
4960
5061 for ( name, source) in sources {
5162 let module = module ( & name) ;
@@ -67,10 +78,12 @@ var NO_HOOK = [{}];
6778 if !ask {
6879 // Separates "the hook is installed" from "the hook stops the game
6980 // thread waiting for a verdict". One game restart answers which.
70- out. push_str ( "
81+ out. push_str (
82+ "
7183// --no-ask
7284askEnabled = false;
73- " ) ;
85+ " ,
86+ ) ;
7487 }
7588 Ok ( out)
7689}
@@ -127,7 +140,11 @@ fn read(dir: Option<&Path>) -> Result<(String, Vec<Module>)> {
127140
128141 let mut modules = Vec :: with_capacity ( paths. len ( ) ) ;
129142 for path in paths {
130- let name = path. file_name ( ) . unwrap_or_default ( ) . to_string_lossy ( ) . to_string ( ) ;
143+ let name = path
144+ . file_name ( )
145+ . unwrap_or_default ( )
146+ . to_string_lossy ( )
147+ . to_string ( ) ;
131148 modules. push ( ( name, std:: fs:: read_to_string ( & path) ?) ) ;
132149 }
133150 Ok ( ( addr, modules) )
@@ -155,20 +172,36 @@ mod tests {
155172
156173 #[ test]
157174 fn disabled_sites_reach_the_agent ( ) {
158- let bundle = super :: bundle ( Some ( & agent_dir ( ) ) , & [ ] , & [ ] , true ,
159- & [ "goldEpilogue" . to_string ( ) ] , false )
160- . expect ( "bundles" ) ;
161- assert ! ( bundle. contains( "var NO_HOOK = [\" goldEpilogue\" ];" ) ,
162- "the agent must be told which sites to leave alone" ) ;
163- assert ! ( bundle. find( "var NO_HOOK" ) . unwrap( )
164- < bundle. find( "function hook(" ) . unwrap( ) ,
165- "NO_HOOK has to be declared before core reads it" ) ;
175+ let bundle = super :: bundle (
176+ Some ( & agent_dir ( ) ) ,
177+ & [ ] ,
178+ & [ ] ,
179+ true ,
180+ & [ "goldEpilogue" . to_string ( ) ] ,
181+ false ,
182+ )
183+ . expect ( "bundles" ) ;
184+ assert ! (
185+ bundle. contains( "var NO_HOOK = [\" goldEpilogue\" ];" ) ,
186+ "the agent must be told which sites to leave alone"
187+ ) ;
188+ assert ! (
189+ bundle. find( "var NO_HOOK" ) . unwrap( ) < bundle. find( "function hook(" ) . unwrap( ) ,
190+ "NO_HOOK has to be declared before core reads it"
191+ ) ;
166192 }
167193
168194 #[ test]
169195 fn only_keeps_the_runtime_modules ( ) {
170- let bundle = super :: bundle ( Some ( & agent_dir ( ) ) , & [ ] , & [ "gold" . to_string ( ) ] ,
171- true , & [ ] , false ) . expect ( "bundles" ) ;
196+ let bundle = super :: bundle (
197+ Some ( & agent_dir ( ) ) ,
198+ & [ ] ,
199+ & [ "gold" . to_string ( ) ] ,
200+ true ,
201+ & [ ] ,
202+ false ,
203+ )
204+ . expect ( "bundles" ) ;
172205 assert ! ( bundle. contains( "60-gold.js" ) ) ;
173206 assert ! ( bundle. contains( "10-core.js" ) , "core is not optional" ) ;
174207 assert ! ( !bundle. contains( "50-health.js" ) ) ;
@@ -183,9 +216,10 @@ mod tests {
183216 let bundle = super :: bundle ( None , & [ ] , & [ ] , true , & [ ] , false ) . expect ( "bundles" ) ;
184217 assert ! ( bundle. contains( "var RVA" ) , "the address table comes first" ) ;
185218 assert ! ( bundle. find( "var RVA" ) . unwrap( ) < bundle. find( "var NO_HOOK" ) . unwrap( ) ) ;
186- assert ! ( bundle. find( "var NO_HOOK" ) . unwrap( )
187- < bundle. find( "// ---- 10-core.js ----" ) . unwrap( ) ,
188- "core reads NO_HOOK, so it is declared before core" ) ;
219+ assert ! (
220+ bundle. find( "var NO_HOOK" ) . unwrap( ) < bundle. find( "// ---- 10-core.js ----" ) . unwrap( ) ,
221+ "core reads NO_HOOK, so it is declared before core"
222+ ) ;
189223 }
190224
191225 /// Minification is comments and layout, and nothing else. Whole lines of
@@ -196,7 +230,10 @@ mod tests {
196230 . iter ( )
197231 . flat_map ( |( _, source) | source. lines ( ) )
198232 . any ( |line| line. starts_with ( "//" ) || line. starts_with ( " " ) ) ;
199- assert ! ( !commented, "the embedded modules keep comments or indentation" ) ;
233+ assert ! (
234+ !commented,
235+ "the embedded modules keep comments or indentation"
236+ ) ;
200237 }
201238
202239 /// Every module the real agent has is still a module, and the ones the
@@ -208,7 +245,10 @@ mod tests {
208245 . map ( |( name, _) | super :: module ( name) )
209246 . collect ( ) ;
210247 for required in [ "core" , "bus" , "names" ] {
211- assert ! ( names. contains( & required) , "{required} is missing from the bundle" ) ;
248+ assert ! (
249+ names. contains( & required) ,
250+ "{required} is missing from the bundle"
251+ ) ;
212252 }
213253 }
214254
@@ -218,11 +258,19 @@ mod tests {
218258 let manifest = super :: manifest ( None ) . expect ( "manifest" ) ;
219259 let groups: serde_json:: Value = serde_json:: from_str ( & manifest) . expect ( "json" ) ;
220260 let groups = groups. as_array ( ) . expect ( "an array of groups" ) ;
221- assert ! ( !groups. is_empty( ) , "no hook sites were read out of the agent" ) ;
261+ assert ! (
262+ !groups. is_empty( ) ,
263+ "no hook sites were read out of the agent"
264+ ) ;
222265 assert ! ( groups. iter( ) . any( |group| group[ "module" ] == "core" ) ) ;
223- assert ! ( groups. iter( ) . all( |group| {
224- group[ "hooks" ] . as_array( ) . is_some_and( |hooks| !hooks. is_empty( ) )
225- } ) , "a module with no sites has no row" ) ;
266+ assert ! (
267+ groups. iter( ) . all( |group| {
268+ group[ "hooks" ]
269+ . as_array( )
270+ . is_some_and( |hooks| !hooks. is_empty( ) )
271+ } ) ,
272+ "a module with no sites has no row"
273+ ) ;
226274 }
227275
228276 /// The same list, read out of a folder: what `--agent` gets.
0 commit comments