11import { existsSync , mkdtempSync , rmSync } from "node:fs" ;
2- import { homedir , tmpdir } from "node:os" ;
2+ import { tmpdir } from "node:os" ;
33import { join } from "node:path" ;
44import { getRuntimePath , readRuntimeConfig } from "@coder-studio/core/runtime" ;
55import { afterEach , beforeEach , describe , expect , it } from "vitest" ;
@@ -9,7 +9,10 @@ import { createServer, type Server, type ServerRuntimeOptions } from "../server.
99describe ( "server runtime config" , ( ) => {
1010 const originalHome = process . env . HOME ;
1111 const originalUserProfile = process . env . USERPROFILE ;
12+ const originalRuntimeDir = process . env . CODER_STUDIO_RUNTIME_DIR ;
13+ const originalRuntimePath = process . env . CODER_STUDIO_RUNTIME_JSON_PATH ;
1214 let testHomeDir : string ;
15+ let runtimePath : string ;
1316 let server : Server | undefined ;
1417
1518 const createRuntimeServer = async (
@@ -20,6 +23,9 @@ describe("server runtime config", () => {
2023 testHomeDir = mkdtempSync ( join ( tmpdir ( ) , "cs-server-runtime-home-" ) ) ;
2124 process . env . HOME = testHomeDir ;
2225 process . env . USERPROFILE = testHomeDir ;
26+ runtimePath = join ( testHomeDir , ".coder-studio" , "runtime.json" ) ;
27+ delete process . env . CODER_STUDIO_RUNTIME_DIR ;
28+ process . env . CODER_STUDIO_RUNTIME_JSON_PATH = runtimePath ;
2329 } ) ;
2430
2531 afterEach ( async ( ) => {
@@ -28,7 +34,6 @@ describe("server runtime config", () => {
2834 server = undefined ;
2935 }
3036
31- const runtimePath = join ( homedir ( ) , ".coder-studio" , "runtime.json" ) ;
3237 if ( existsSync ( runtimePath ) ) {
3338 rmSync ( runtimePath ) ;
3439 }
@@ -46,6 +51,18 @@ describe("server runtime config", () => {
4651 } else {
4752 process . env . USERPROFILE = originalUserProfile ;
4853 }
54+
55+ if ( originalRuntimeDir === undefined ) {
56+ delete process . env . CODER_STUDIO_RUNTIME_DIR ;
57+ } else {
58+ process . env . CODER_STUDIO_RUNTIME_DIR = originalRuntimeDir ;
59+ }
60+
61+ if ( originalRuntimePath === undefined ) {
62+ delete process . env . CODER_STUDIO_RUNTIME_JSON_PATH ;
63+ } else {
64+ process . env . CODER_STUDIO_RUNTIME_JSON_PATH = originalRuntimePath ;
65+ }
4966 } ) ;
5067
5168 it ( "writes runtime config on startup and clears it on stop" , async ( ) => {
@@ -62,9 +79,7 @@ describe("server runtime config", () => {
6279 pid : process . pid ,
6380 } )
6481 ) ;
65- expect ( getRuntimePath ( ) ) . toBe (
66- process . env . CODER_STUDIO_RUNTIME_JSON_PATH ?? join ( homedir ( ) , ".coder-studio" , "runtime.json" )
67- ) ;
82+ expect ( getRuntimePath ( ) ) . toBe ( runtimePath ) ;
6883
6984 await server . stop ( ) ;
7085 server = undefined ;
0 commit comments