@@ -5,6 +5,7 @@ import { join } from "node:path";
55import {
66 findProjectRoot ,
77 resolveFilePath ,
8+ applyWslPrefix ,
89 _resetProjectRootCache ,
910} from "../src/path.js" ;
1011
@@ -68,3 +69,50 @@ test("resolveFilePath", async (t) => {
6869 assert . strictEqual ( result , "/some/path/src/file.ts" ) ;
6970 } ) ;
7071} ) ;
72+
73+ test ( "applyWslPrefix" , async ( t ) => {
74+ const originalWslDistroName = process . env . WSL_DISTRO_NAME ;
75+
76+ t . afterEach ( ( ) => {
77+ if ( originalWslDistroName === undefined ) {
78+ delete process . env . WSL_DISTRO_NAME ;
79+ } else {
80+ process . env . WSL_DISTRO_NAME = originalWslDistroName ;
81+ }
82+ } ) ;
83+
84+ await t . test ( "prefixes path when WSL_DISTRO_NAME is set" , ( ) => {
85+ process . env . WSL_DISTRO_NAME = "Ubuntu-22.04" ;
86+ const path = "/home/user/project/src/file.ts:1:1" ;
87+ const result = applyWslPrefix ( path ) ;
88+ assert . strictEqual ( result , "//wsl.localhost/Ubuntu-22.04/home/user/project/src/file.ts:1:1" ) ;
89+ } ) ;
90+
91+ await t . test ( "returns path unchanged when WSL_DISTRO_NAME is not set" , ( ) => {
92+ delete process . env . WSL_DISTRO_NAME ;
93+ const path = "/home/user/project/src/file.ts:1:1" ;
94+ const result = applyWslPrefix ( path ) ;
95+ assert . strictEqual ( result , path ) ;
96+ } ) ;
97+ } ) ;
98+
99+ test ( "resolveFilePath with WSL" , async ( t ) => {
100+ const originalWslDistroName = process . env . WSL_DISTRO_NAME ;
101+
102+ t . afterEach ( ( ) => {
103+ _resetProjectRootCache ( ) ;
104+ if ( originalWslDistroName === undefined ) {
105+ delete process . env . WSL_DISTRO_NAME ;
106+ } else {
107+ process . env . WSL_DISTRO_NAME = originalWslDistroName ;
108+ }
109+ } ) ;
110+
111+ await t . test ( "applies WSL prefix to resolved src/ paths" , ( ) => {
112+ process . env . WSL_DISTRO_NAME = "Ubuntu-22.04" ;
113+ const projectRoot = findProjectRoot ( ) ;
114+ const rawPath = "/wrong/deploy/dir/src/routes/admin.ts:12:15" ;
115+ const result = resolveFilePath ( rawPath ) ;
116+ assert . strictEqual ( result , `//wsl.localhost/Ubuntu-22.04${ projectRoot } /src/routes/admin.ts:12:15` ) ;
117+ } ) ;
118+ } ) ;
0 commit comments