@@ -46,6 +46,32 @@ fn cache_gc_verbose_shows_removed_entries() {
4646 home. child ( "hooks/hook-env-dead" )
4747 . create_dir_all ( )
4848 . expect ( "create hook env dir" ) ;
49+ home. child ( "hooks/hook-env-dead/.prek-hook.json" )
50+ . write_str (
51+ & serde_json:: to_string_pretty ( & json ! ( {
52+ "language" : "python" ,
53+ "language_version" : "3.12.0" ,
54+ "dependencies" : [
55+ "https://example.com/repo@v1.0.0" ,
56+ "dep1" ,
57+ "dep2" ,
58+ "dep3" ,
59+ "dep4" ,
60+ "dep5" ,
61+ "dep6" ,
62+ "dep7" ,
63+ ] ,
64+ "env_path" : home. child( "hooks/hook-env-dead" ) . path( ) ,
65+ "toolchain" : "/usr/bin/python3" ,
66+ "extra" : { } ,
67+ } ) )
68+ . expect ( "serialize hook marker" ) ,
69+ )
70+ . expect ( "write hook marker" ) ;
71+
72+ home. child ( "cache/go" )
73+ . create_dir_all ( )
74+ . expect ( "create cache dir" ) ;
4975
5076 // Have a tracked config that exists but references nothing (so everything above is unreferenced).
5177 let config_path = context. work_dir ( ) . child ( CONFIG_FILE ) ;
@@ -55,15 +81,22 @@ fn cache_gc_verbose_shows_removed_entries() {
5581 success: true
5682 exit_code: 0
5783 ----- stdout -----
58- Removed 1 repo, 1 hook env ([SIZE])
84+ Removed 1 repo, 1 hook env, 1 cache entry ([SIZE])
5985
6086 Removed 1 repo:
6187 - https://github.com/pre-commit/pre-commit-hooks@v1.0.0
6288 path: [HOME]/repos/deadbeef
6389
6490 Removed 1 hook env:
65- - hook- env-dead
91+ - python env
6692 path: [HOME]/hooks/hook-env-dead
93+ language: python (3.12.0)
94+ repo: https://example.com/repo@v1.0.0
95+ deps: dep1, dep2, dep3, dep4, dep5, dep6, … (+1 more)
96+
97+ Removed 1 cache entry:
98+ - go
99+ path: [HOME]/cache/go
67100
68101 ----- stderr -----
69102 " ) ;
@@ -220,10 +253,30 @@ fn cache_gc_prunes_unused_tool_versions() -> anyhow::Result<()> {
220253 repos:
221254 - repo: local
222255 hooks:
223- - id: local-python
224- name: Local Python Hook
225- entry: "python -c \"print(1)\""
226- language: python
256+ - id: local-python
257+ name: Local Python Hook
258+ entry: "python -c \"print(1)\""
259+ language: python
260+ - id: local-pygrep
261+ name: Local Pygrep Hook
262+ entry: "python -c \"print(1)\""
263+ language: pygrep
264+ - id: local-node
265+ name: Local Node Hook
266+ entry: "node -e \"console.log(1)\""
267+ language: node
268+ - id: local-go
269+ name: Local Go Hook
270+ entry: "go version"
271+ language: golang
272+ - id: local-ruby
273+ name: Local Ruby Hook
274+ entry: "ruby -e 'puts 1'"
275+ language: ruby
276+ - id: local-rust
277+ name: Local Rust Hook
278+ entry: "rustc --version"
279+ language: rust
227280 "# } ) ;
228281
229282 let home = context. home_dir ( ) ;
@@ -232,36 +285,88 @@ fn cache_gc_prunes_unused_tool_versions() -> anyhow::Result<()> {
232285 let config_path = context. work_dir ( ) . child ( CONFIG_FILE ) ;
233286 write_config_tracking_file ( home, & [ config_path. path ( ) ] ) ?;
234287
235- // Seed a "used" python hook env marker so GC can read `.prek-hook.json` and retain the
236- // corresponding Python tool version.
237- let env_dir = home. child ( "hooks/python-keep" ) ;
238- env_dir. create_dir_all ( ) ?;
239-
240- let py_312 = home. child ( "tools/python/3.12.0" ) ;
241- let py_311 = home. child ( "tools/python/3.11.0" ) ;
242- py_312. create_dir_all ( ) ?;
243- py_311. create_dir_all ( ) ?;
288+ // Seed "used" hook env markers so GC can read `.prek-hook.json` and retain the
289+ // corresponding tool versions per language.
290+ let env_py = home. child ( "hooks/python-keep" ) ;
291+ let env_node = home. child ( "hooks/node-keep" ) ;
292+ let env_go = home. child ( "hooks/go-keep" ) ;
293+ let env_ruby = home. child ( "hooks/ruby-remove" ) ;
294+ let env_rust = home. child ( "hooks/rust-remove" ) ;
295+ env_py. create_dir_all ( ) ?;
296+ env_node. create_dir_all ( ) ?;
297+ env_go. create_dir_all ( ) ?;
298+ env_ruby. create_dir_all ( ) ?;
299+ env_rust. create_dir_all ( ) ?;
300+
301+ let py_keep = home. child ( "tools/python/3.12.0" ) ;
302+ let py_remove = home. child ( "tools/python/3.11.0" ) ;
303+ py_keep. create_dir_all ( ) ?;
304+ py_remove. create_dir_all ( ) ?;
305+
306+ let node_keep = home. child ( "tools/node/22.0.0" ) ;
307+ let node_remove = home. child ( "tools/node/21.0.0" ) ;
308+ node_keep. create_dir_all ( ) ?;
309+ node_remove. create_dir_all ( ) ?;
310+
311+ let go_keep = home. child ( "tools/go/1.24.0" ) ;
312+ let go_remove = home. child ( "tools/go/1.23.0" ) ;
313+ go_keep. create_dir_all ( ) ?;
314+ go_remove. create_dir_all ( ) ?;
244315
245316 // Match logic for local hooks: empty deps + language request is `Any` by default.
246- let marker = json ! ( {
317+ let marker_py = json ! ( {
247318 "language" : "python" ,
248319 "language_version" : "3.12.0" ,
249320 "dependencies" : [ ] ,
250- "env_path" : env_dir . path( ) ,
251- "toolchain" : py_312 . child( "bin/python" ) . path( ) ,
321+ "env_path" : env_py . path( ) ,
322+ "toolchain" : py_keep . child( "bin/python" ) . path( ) ,
252323 "extra" : { } ,
253324 } ) ;
254- env_dir
325+ env_py
255326 . child ( ".prek-hook.json" )
256- . write_str ( & serde_json:: to_string_pretty ( & marker) ?) ?;
327+ . write_str ( & serde_json:: to_string_pretty ( & marker_py) ?) ?;
328+
329+ let marker_node = json ! ( {
330+ "language" : "node" ,
331+ "language_version" : "22.0.0" ,
332+ "dependencies" : [ ] ,
333+ "env_path" : env_node. path( ) ,
334+ "toolchain" : node_keep. child( "bin/node" ) . path( ) ,
335+ "extra" : { } ,
336+ } ) ;
337+ env_node
338+ . child ( ".prek-hook.json" )
339+ . write_str ( & serde_json:: to_string_pretty ( & marker_node) ?) ?;
340+
341+ let marker_go = json ! ( {
342+ "language" : "golang" ,
343+ "language_version" : "1.24.0" ,
344+ "dependencies" : [ ] ,
345+ "env_path" : env_go. path( ) ,
346+ "toolchain" : go_keep. child( "bin/go" ) . path( ) ,
347+ "extra" : { } ,
348+ } ) ;
349+ env_go
350+ . child ( ".prek-hook.json" )
351+ . write_str ( & serde_json:: to_string_pretty ( & marker_go) ?) ?;
257352
258353 cmd_snapshot ! ( context. filters( ) , context. command( ) . args( [ "cache" , "gc" , "--dry-run" , "-v" ] ) , @r"
259354 success: true
260355 exit_code: 0
261356 ----- stdout -----
262- Would remove 1 tool ([SIZE])
263-
264- Would remove 1 tool:
357+ Would remove 2 hook envs, 3 tools ([SIZE])
358+
359+ Would remove 2 hook envs:
360+ - ruby-remove
361+ path: [HOME]/hooks/ruby-remove
362+ - rust-remove
363+ path: [HOME]/hooks/rust-remove
364+
365+ Would remove 3 tools:
366+ - go/1.23.0
367+ path: [HOME]/tools/go/1.23.0
368+ - node/21.0.0
369+ path: [HOME]/tools/node/21.0.0
265370 - python/3.11.0
266371 path: [HOME]/tools/python/3.11.0
267372
0 commit comments