@@ -94,15 +94,26 @@ describe('profile-query-cli session management', function () {
9494 } ) ;
9595
9696 describe ( 'path generation' , function ( ) {
97- it ( 'getSocketPath returns correct path' , function ( ) {
97+ it ( 'getSocketPath returns correct Unix path' , function ( ) {
98+ const originalPlatform = process . platform ;
99+ Object . defineProperty ( process , 'platform' , {
100+ value : 'linux' ,
101+ configurable : true ,
102+ } ) ;
98103 const sessionId = 'test123' ;
99104 const socketPath = getSocketPath ( testSessionDir , sessionId ) ;
100105 expect ( socketPath ) . toBe ( path . join ( testSessionDir , 'test123.sock' ) ) ;
106+ Object . defineProperty ( process , 'platform' , {
107+ value : originalPlatform ,
108+ configurable : true ,
109+ } ) ;
101110 } ) ;
102111
103112 it ( 'namespaces Windows pipe paths by session directory' , function ( ) {
113+ const originalPlatform = process . platform ;
104114 Object . defineProperty ( process , 'platform' , {
105115 value : 'win32' ,
116+ configurable : true ,
106117 } ) ;
107118
108119 const firstSocketPath = getSocketPath ( 'C:\\pq\\alpha' , 'test123' ) ;
@@ -117,6 +128,11 @@ describe('profile-query-cli session management', function () {
117128 ) ;
118129 expect ( firstSocketPath ) . not . toBe ( secondSocketPath ) ;
119130 expect ( firstSocketPath ) . toBe ( thirdSocketPath ) ;
131+
132+ Object . defineProperty ( process , 'platform' , {
133+ value : originalPlatform ,
134+ configurable : true ,
135+ } ) ;
120136 } ) ;
121137
122138 it ( 'generates a stable namespace from the session directory' , function ( ) {
@@ -177,9 +193,6 @@ describe('profile-query-cli session management', function () {
177193 describe ( 'current session tracking' , function ( ) {
178194 it ( 'sets and gets current session via symlink' , function ( ) {
179195 const sessionId = 'test123' ;
180- const socketPath = getSocketPath ( testSessionDir , sessionId ) ;
181- fs . writeFileSync ( socketPath , '' ) ;
182-
183196 setCurrentSession ( testSessionDir , sessionId ) ;
184197
185198 const currentId = getCurrentSessionId ( testSessionDir ) ;
@@ -193,23 +206,17 @@ describe('profile-query-cli session management', function () {
193206
194207 it ( 'replaces existing current session symlink' , function ( ) {
195208 // Create first session
196- const socket1 = getSocketPath ( testSessionDir , 'session1' ) ;
197- fs . writeFileSync ( socket1 , '' ) ;
198209 setCurrentSession ( testSessionDir , 'session1' ) ;
199210 expect ( getCurrentSessionId ( testSessionDir ) ) . toBe ( 'session1' ) ;
200211
201212 // Create second session
202- const socket2 = getSocketPath ( testSessionDir , 'session2' ) ;
203- fs . writeFileSync ( socket2 , '' ) ;
204213 setCurrentSession ( testSessionDir , 'session2' ) ;
205214 expect ( getCurrentSessionId ( testSessionDir ) ) . toBe ( 'session2' ) ;
206215 } ) ;
207216
208217 it ( 'getCurrentSocketPath resolves to correct path' , function ( ) {
209218 const sessionId = 'test123' ;
210219 const socketPath = getSocketPath ( testSessionDir , sessionId ) ;
211- fs . writeFileSync ( socketPath , '' ) ;
212-
213220 setCurrentSession ( testSessionDir , sessionId ) ;
214221
215222 const currentPath = getCurrentSocketPath ( testSessionDir ) ;
@@ -259,8 +266,10 @@ describe('profile-query-cli session management', function () {
259266 const socketPath = getSocketPath ( testSessionDir , sessionId ) ;
260267 const metadataPath = getMetadataPath ( testSessionDir , sessionId ) ;
261268
262- fs . writeFileSync ( socketPath , '' ) ;
263269 fs . writeFileSync ( metadataPath , '{}' ) ;
270+ if ( process . platform !== 'win32' ) {
271+ fs . writeFileSync ( socketPath , '' ) ;
272+ }
264273
265274 cleanupSession ( testSessionDir , sessionId ) ;
266275
@@ -280,8 +289,6 @@ describe('profile-query-cli session management', function () {
280289
281290 it ( 'removes current session symlink if it points to this session' , function ( ) {
282291 const sessionId = 'test123' ;
283- const socketPath = getSocketPath ( testSessionDir , sessionId ) ;
284- fs . writeFileSync ( socketPath , '' ) ;
285292 setCurrentSession ( testSessionDir , sessionId ) ;
286293
287294 cleanupSession ( testSessionDir , sessionId ) ;
@@ -291,8 +298,6 @@ describe('profile-query-cli session management', function () {
291298
292299 it ( 'does not remove current session symlink if it points to different session' , function ( ) {
293300 // Set current session to session1
294- const socket1 = getSocketPath ( testSessionDir , 'session1' ) ;
295- fs . writeFileSync ( socket1 , '' ) ;
296301 setCurrentSession ( testSessionDir , 'session1' ) ;
297302
298303 // Clean up session2
@@ -321,12 +326,18 @@ describe('profile-query-cli session management', function () {
321326 } ;
322327
323328 saveSessionMetadata ( testSessionDir , metadata ) ;
324- fs . writeFileSync ( metadata . socketPath , '' ) ;
325329
326330 expect ( validateSession ( testSessionDir , sessionId ) ) . toBe ( null ) ;
327331 } ) ;
328332
329333 it ( 'returns false for session with missing socket' , function ( ) {
334+ if ( process . platform === 'win32' ) {
335+ // Not applicable on Windows: named pipes are self-cleaning and disappear
336+ // automatically when the server stops, so a session can't have a live PID
337+ // but a missing socket. validateSession skips the socket check on Windows
338+ // for this reason.
339+ return ;
340+ }
330341 const sessionId = 'test123' ;
331342 const metadata : SessionMetadata = {
332343 id : sessionId ,
@@ -357,7 +368,9 @@ describe('profile-query-cli session management', function () {
357368 } ;
358369
359370 saveSessionMetadata ( testSessionDir , metadata ) ;
360- fs . writeFileSync ( metadata . socketPath , '' ) ;
371+ if ( process . platform !== 'win32' ) {
372+ fs . writeFileSync ( metadata . socketPath , '' ) ;
373+ }
361374
362375 expect ( validateSession ( testSessionDir , sessionId ) ) . not . toBe ( null ) ;
363376 } ) ;
0 commit comments