@@ -9,10 +9,9 @@ import { describe, expect, it } from "vitest";
99import {
1010 checkKnipUnusedFileScanResult ,
1111 checkUnusedFiles ,
12- KNIP_MAX_BUFFER_BYTES ,
1312 parseKnipCompactUnusedFiles ,
14- runKnipUnusedFiles ,
1513} from "../../scripts/check-deadcode-unused-files.mts" ;
14+ import { KNIP_MAX_BUFFER_BYTES , runKnip } from "../../scripts/deadcode-knip-runner.mts" ;
1615import { killPidIfAlive } from "../../src/test-utils/process-tree.js" ;
1716import {
1817 isProcessAlive ,
@@ -22,6 +21,18 @@ import {
2221 waitForPidFile ,
2322} from "../helpers/process-wait.js" ;
2423
24+ const KNIP_UNUSED_FILE_ARGS = [
25+ "--config" ,
26+ "config/knip.config.ts" ,
27+ "--production" ,
28+ "--no-progress" ,
29+ "--reporter" ,
30+ "compact" ,
31+ "--files" ,
32+ "--no-config-hints" ,
33+ ] ;
34+ const KNIP_UNUSED_FILE_SCAN_NAME = "production unused-file scan" ;
35+
2536class FakeKnipProcess extends EventEmitter {
2637 readonly stderr = new EventEmitter ( ) ;
2738 readonly stdout = new EventEmitter ( ) ;
@@ -150,7 +161,7 @@ Delete the files or model their real entrypoints in Knip.`,
150161 writeFileSync ( pnpmExecPath , "console.log('pnpm');\n" , "utf8" ) ;
151162
152163 try {
153- const resultPromise = runKnipUnusedFiles ( {
164+ const resultPromise = runKnip ( KNIP_UNUSED_FILE_ARGS , {
154165 nodeExecPath : "/test-node" ,
155166 npmExecPath : pnpmExecPath ,
156167 spawnCommand ( command : string , args : string [ ] , options : unknown ) {
@@ -208,7 +219,7 @@ Delete the files or model their real entrypoints in Knip.`,
208219 it ( "falls back to bare pnpm when no managed pnpm runner is available" , async ( ) => {
209220 const calls : unknown [ ] = [ ] ;
210221
211- const resultPromise = runKnipUnusedFiles ( {
222+ const resultPromise = runKnip ( KNIP_UNUSED_FILE_ARGS , {
212223 env : { PATH : "" } ,
213224 npmExecPath : "" ,
214225 platform : "linux" ,
@@ -266,10 +277,11 @@ Delete the files or model their real entrypoints in Knip.`,
266277 return originalKill ( pid , signal as NodeJS . Signals ) ;
267278 } ) as typeof process . kill ;
268279 try {
269- const result = await runKnipUnusedFiles ( {
280+ const result = await runKnip ( KNIP_UNUSED_FILE_ARGS , {
270281 heartbeatMs : 1 ,
271282 killGraceMs : 50 ,
272283 maxBufferBytes : KNIP_MAX_BUFFER_BYTES ,
284+ scanName : KNIP_UNUSED_FILE_SCAN_NAME ,
273285 spawnCommand : ( ) => child ,
274286 timeoutMs : 5 ,
275287 writeStatus : ( message : string ) => statuses . push ( message ) ,
@@ -311,7 +323,7 @@ Delete the files or model their real entrypoints in Knip.`,
311323 "setInterval(() => {}, 1000);" ,
312324 ] . join ( "" ) ;
313325
314- const resultPromise = runKnipUnusedFiles ( {
326+ const resultPromise = runKnip ( KNIP_UNUSED_FILE_ARGS , {
315327 env : { ...process . env , OPENCLAW_TEST_CHILD_PID : childPidPath } ,
316328 killGraceMs : 50 ,
317329 spawnCommand ( _command : string , _args : string [ ] , options : unknown ) {
@@ -345,7 +357,7 @@ Delete the files or model their real entrypoints in Knip.`,
345357 const root = mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-knip-parent-signal-" ) ) ;
346358 const childPidPath = path . join ( root , "child.pid" ) ;
347359 const readyPath = path . join ( root , "child.ready" ) ;
348- const scriptUrl = pathToFileURL ( path . resolve ( "scripts/check- deadcode-unused-files .mts" ) ) . href ;
360+ const scriptUrl = pathToFileURL ( path . resolve ( "scripts/deadcode-knip-runner .mts" ) ) . href ;
349361 let childPid = 0 ;
350362 let runner : ReturnType < typeof spawn > | undefined ;
351363
@@ -365,8 +377,8 @@ Delete the files or model their real entrypoints in Knip.`,
365377 ] . join ( "" ) ;
366378 const runnerScript = [
367379 "import { spawn } from 'node:child_process';" ,
368- `import { runKnipUnusedFiles } from ${ JSON . stringify ( scriptUrl ) } ;` ,
369- " await runKnipUnusedFiles({" ,
380+ `import { runKnip } from ${ JSON . stringify ( scriptUrl ) } ;` ,
381+ ` await runKnip( ${ JSON . stringify ( KNIP_UNUSED_FILE_ARGS ) } , {` ,
370382 " spawnCommand(_command, _args, options) {" ,
371383 ` return spawn(process.execPath, ['-e', ${ JSON . stringify ( parentScript ) } ], options);` ,
372384 " }," ,
@@ -403,7 +415,7 @@ Delete the files or model their real entrypoints in Knip.`,
403415
404416 it ( "keeps output delivered after process exit but before stdio close" , async ( ) => {
405417 const child = new FakeKnipProcess ( ) ;
406- const resultPromise = runKnipUnusedFiles ( {
418+ const resultPromise = runKnip ( KNIP_UNUSED_FILE_ARGS , {
407419 spawnCommand : ( ) => child ,
408420 writeStatus : ( ) => { } ,
409421 } ) ;
@@ -436,9 +448,10 @@ Delete the files or model their real entrypoints in Knip.`,
436448 return originalKill ( pid , signal as NodeJS . Signals ) ;
437449 } ) as typeof process . kill ;
438450 try {
439- const resultPromise = runKnipUnusedFiles ( {
451+ const resultPromise = runKnip ( KNIP_UNUSED_FILE_ARGS , {
440452 killGraceMs : 50 ,
441453 maxBufferBytes : 4 ,
454+ scanName : KNIP_UNUSED_FILE_SCAN_NAME ,
442455 spawnCommand : ( ) => child ,
443456 timeoutMs : 1000 ,
444457 writeStatus : ( ) => { } ,
@@ -458,7 +471,7 @@ Delete the files or model their real entrypoints in Knip.`,
458471 } ) ;
459472
460473 it ( "reports spawn errors" , async ( ) => {
461- const resultPromise = runKnipUnusedFiles ( {
474+ const resultPromise = runKnip ( KNIP_UNUSED_FILE_ARGS , {
462475 spawnCommand : ( ) => {
463476 const child = new FakeKnipProcess ( ) ;
464477 queueMicrotask ( ( ) =>
0 commit comments