@@ -3,6 +3,7 @@ import * as NodeChildProcess from "node:child_process";
33import * as NodeFS from "node:fs" ;
44import * as NodeOS from "node:os" ;
55import * as NodePath from "node:path" ;
6+ import { expect } from "vite-plus/test" ;
67import * as NodeServices from "@effect/platform-node/NodeServices" ;
78import * as Option from "effect/Option" ;
89import { assert , describe , it } from "@effect/vitest" ;
@@ -264,3 +265,143 @@ it("compares against an explicit ref instead of the closest remote main", async
264265 assert . strictEqual ( result . base , project . commits . A ) ;
265266 assert . strictEqual ( result . ref , "origin/main" ) ;
266267} ) ;
268+
269+ function launcherFixture ( ) {
270+ const root = NodeFS . realpathSync (
271+ NodeFS . mkdtempSync ( NodePath . join ( NodeOS . tmpdir ( ) , "t3 checks & (fixture) " ) ) ,
272+ ) ;
273+ const write = ( file : string , content : string ) => {
274+ const path = NodePath . join ( root , file ) ;
275+ NodeFS . mkdirSync ( NodePath . dirname ( path ) , { recursive : true } ) ;
276+ NodeFS . writeFileSync ( path , content ) ;
277+ } ;
278+ for ( const file of [
279+ "scripts/check-changed.ts" ,
280+ "scripts/check-changed-command.ts" ,
281+ ".github/scripts/ci-changes.cjs" ,
282+ ] ) {
283+ write ( file , NodeFS . readFileSync ( NodePath . join ( import . meta. dirname , ".." , file ) , "utf8" ) ) ;
284+ }
285+ write ( ".gitignore" , "node_modules/\nrecords/\n" ) ;
286+ write ( "pnpm-workspace.yaml" , "packages:\n - packages/*\n" ) ;
287+ write (
288+ "package.json" ,
289+ JSON . stringify ( { type : "module" , scripts : { "knip:check" : "knip --include files" } } ) ,
290+ ) ;
291+ write ( "packages/example/package.json" , JSON . stringify ( { name : "example" } ) ) ;
292+ const source = "packages/example/space & (draft) %PATH% ! 研究.ts" ;
293+ write ( source , "export const value = 1;\n" ) ;
294+ write (
295+ "node_modules/vite-plus/package.json" ,
296+ JSON . stringify ( { type : "module" , exports : { "./bin" : "./cli.js" } } ) ,
297+ ) ;
298+ write (
299+ "node_modules/vite-plus/cli.js" ,
300+ `
301+ import fs from 'node:fs';
302+ import path from 'node:path';
303+ const args = process.argv.slice(2);
304+ fs.writeFileSync(path.join(process.env.RECORDS, process.pid + '.json'), JSON.stringify({ args, cwd: process.cwd() }));
305+ console.log('fixture stdout: ' + args[0]);
306+ console.error('fixture stderr: ' + args[0]);
307+ process.exit(args[0] === process.env.FAIL_STEP ? 23 : 0);
308+ ` ,
309+ ) ;
310+ // Select the Windows launcher without changing the Effect runtime's host platform.
311+ write (
312+ "scripts/check-changed.ts" ,
313+ NodeFS . readFileSync ( NodePath . join ( import . meta. dirname , "check-changed.ts" ) , "utf8" ) . replace (
314+ "vitePlusCommand(args, platform)" ,
315+ 'vitePlusCommand(args, "win32")' ,
316+ ) ,
317+ ) ;
318+ for ( const name of [ "effect" , "@effect/platform-node" , "@t3tools/shared" ] ) {
319+ const dest = NodePath . join ( root , "node_modules" , name ) ;
320+ NodeFS . mkdirSync ( NodePath . dirname ( dest ) , { recursive : true } ) ;
321+ NodeFS . symlinkSync (
322+ NodeFS . realpathSync ( NodePath . join ( import . meta. dirname , "node_modules" , name ) ) ,
323+ dest ,
324+ "junction" ,
325+ ) ;
326+ }
327+ const git = ( ...args : Array < string > ) =>
328+ NodeChildProcess . execFileSync ( "git" , args , { cwd : root , stdio : "pipe" , env } ) ;
329+ git ( "init" ) ;
330+ git ( "add" , "." ) ;
331+ git (
332+ "-c" ,
333+ "user.name=Fixture" ,
334+ "-c" ,
335+ 336+ "-c" ,
337+ "commit.gpgsign=false" ,
338+ "-c" ,
339+ "core.hooksPath=" ,
340+ "commit" ,
341+ "-m" ,
342+ "fixture" ,
343+ ) ;
344+ const records = NodePath . join ( root , "records" ) ;
345+ NodeFS . mkdirSync ( records ) ;
346+ return {
347+ root,
348+ source,
349+ write,
350+ run ( failStep = "" ) {
351+ return NodeChildProcess . spawnSync ( process . execPath , [ "scripts/check-changed.ts" , "HEAD" ] , {
352+ cwd : root ,
353+ encoding : "utf8" ,
354+ env : { ...env , TEMP : NodeOS . tmpdir ( ) , RECORDS : records , FAIL_STEP : failStep } ,
355+ } ) ;
356+ } ,
357+ calls : ( ) : Array < { args : Array < string > ; cwd : string } > =>
358+ NodeFS . readdirSync ( records ) . map ( ( file ) =>
359+ JSON . parse ( NodeFS . readFileSync ( NodePath . join ( records , file ) , "utf8" ) ) ,
360+ ) ,
361+ [ Symbol . dispose ] ( ) {
362+ NodeFS . rmSync ( root , { recursive : true , force : true } ) ;
363+ } ,
364+ } ;
365+ }
366+
367+ it ( "checks changed source paths through the Windows launcher" , ( ) => {
368+ using project = launcherFixture ( ) ;
369+ project . write ( project . source , "export const value = 2;\n" ) ;
370+ const result = project . run ( ) ;
371+ expect ( result . status , result . stdout + result . stderr ) . toBe ( 0 ) ;
372+ const calls = project . calls ( ) ;
373+ expect ( calls . find ( ( { args } ) => args [ 0 ] === "lint" ) ) . toEqual ( {
374+ args : [ "lint" , project . source ] ,
375+ cwd : project . root ,
376+ } ) ;
377+ expect ( calls . some ( ( { args } ) => args [ 0 ] === "fmt" && args . includes ( project . source ) ) ) . toBe ( true ) ;
378+ expect ( calls . some ( ( { args } ) => args [ 0 ] === "run" && args . includes ( "typecheck" ) ) ) . toBe ( true ) ;
379+ expect ( calls . some ( ( { args } ) => args [ 0 ] === "install" ) ) . toBe ( false ) ;
380+ expect ( result . stdout ) . toContain ( "fixture stdout: lint" ) ;
381+ expect ( result . stdout ) . toContain ( "fixture stderr: lint" ) ;
382+ } ) ;
383+
384+ it . each ( [ "install" , "lint" ] ) ( "reports a failing %s step with its output" , ( step ) => {
385+ using project = launcherFixture ( ) ;
386+ project . write ( project . source , "export const value = 2;\n" ) ;
387+ project . write (
388+ "packages/example/package.json" ,
389+ JSON . stringify ( { name : "example" , version : "1.0.1" } ) ,
390+ ) ;
391+ const result = project . run ( step ) ;
392+ expect ( result . status , result . stdout + result . stderr ) . toBe ( 1 ) ;
393+ const install = project . calls ( ) . find ( ( { args } ) => args [ 0 ] === "install" ) ;
394+ expect ( install ?. args , result . stdout + result . stderr ) . toEqual ( [
395+ "install" ,
396+ "--lockfile-only" ,
397+ "--ignore-scripts" ,
398+ ] ) ;
399+ expect ( install ?. cwd ) . not . toBe ( project . root ) ;
400+ expect ( result . stdout + result . stderr ) . toContain ( `fixture stdout: ${ step } ` ) ;
401+ expect ( result . stdout + result . stderr ) . toContain ( `fixture stderr: ${ step } ` ) ;
402+ expect ( result . stdout ) . toContain ( step === "install" ? "FAIL unused patches" : "FAIL lint" ) ;
403+ if ( step === "lint" ) expect ( result . stdout ) . toContain ( "pass unused patches" ) ;
404+ expect (
405+ NodeFS . existsSync ( NodePath . join ( project . root , "node_modules/.cache/check-changed.json" ) ) ,
406+ ) . toBe ( false ) ;
407+ } ) ;
0 commit comments