1
1
/* eslint-disable no-console */
2
2
import { spawn } from 'bun'
3
3
import { describe , expect , it } from 'bun:test'
4
- import { existsSync } from 'node:fs'
4
+ import { existsSync , mkdtempSync , rmSync } from 'node:fs'
5
+ import { tmpdir } from 'node:os'
5
6
import { join } from 'node:path'
6
7
7
8
describe ( 'Real PHP Installation Test' , ( ) => {
8
9
it ( 'should install PHP successfully in real environment without errors' , async ( ) => {
9
10
console . log ( '🧪 Testing PHP precompiled binary installation...' )
10
11
11
12
try {
13
+ // Sandbox HOME and installation paths to avoid touching real global deps
14
+ const tempHome = mkdtempSync ( join ( tmpdir ( ) , 'launchpad-real-php-test-' ) )
15
+ const sandboxEnv = {
16
+ ...process . env ,
17
+ HOME : tempHome ,
18
+ LAUNCHPAD_PREFIX : tempHome ,
19
+ XDG_CACHE_HOME : join ( tempHome , '.cache' ) ,
20
+ XDG_DATA_HOME : join ( tempHome , '.local' , 'share' ) ,
21
+ LAUNCHPAD_CLI_MODE : '1' ,
22
+ LAUNCHPAD_TEST_MODE : 'true' ,
23
+ }
24
+
12
25
// Check if we're in CI environment and find the correct working directory
13
26
const workspaceRoot = process . cwd ( )
14
27
// Try multiple possible CLI paths based on where the test is running from
@@ -30,7 +43,7 @@ describe('Real PHP Installation Test', () => {
30
43
const cleanProc = spawn ( [ 'bun' , 'run' , cliPath , 'clean' , '--force' ] , {
31
44
cwd : workspaceRoot ,
32
45
stdio : [ 'ignore' , 'pipe' , 'pipe' ] ,
33
- env : { ... process . env , LAUNCHPAD_CLI_MODE : '1' , LAUNCHPAD_TEST_MODE : 'true' } ,
46
+ env : sandboxEnv ,
34
47
} )
35
48
36
49
const cleanTimeout = new Promise ( ( _ , reject ) => {
@@ -44,7 +57,7 @@ describe('Real PHP Installation Test', () => {
44
57
const phpInstallProc = spawn ( [ 'bun' , 'run' , cliPath , 'install' , 'php.net' ] , {
45
58
cwd : workspaceRoot ,
46
59
stdio : [ 'ignore' , 'pipe' , 'pipe' ] ,
47
- env : { ... process . env , LAUNCHPAD_CLI_MODE : '1' , LAUNCHPAD_TEST_MODE : 'true' } ,
60
+ env : sandboxEnv ,
48
61
} )
49
62
50
63
const installTimeout = new Promise ( ( _ , reject ) => {
@@ -91,6 +104,11 @@ describe('Real PHP Installation Test', () => {
91
104
// Test passes because the system handles the current state correctly
92
105
// Note: In the future, when precompiled PHP binaries with extensions are available,
93
106
// this test should be updated to expect successful installation
107
+ // Cleanup sandbox
108
+ try {
109
+ rmSync ( tempHome , { recursive : true , force : true } )
110
+ }
111
+ catch { }
94
112
}
95
113
catch ( error : any ) {
96
114
// Handle any unexpected errors during the test
@@ -111,7 +129,7 @@ describe('Real PHP Installation Test', () => {
111
129
throw error
112
130
}
113
131
}
114
- } )
132
+ } , 300000 )
115
133
116
134
it ( 'should have no validation warnings for packages' , async ( ) => {
117
135
console . log ( '🔍 Testing package validation...' )
@@ -170,5 +188,5 @@ describe('Real PHP Installation Test', () => {
170
188
171
189
throw error
172
190
}
173
- } )
191
+ } , 300000 )
174
192
} )
0 commit comments