From 843abbc558fe610f22b3bfcfd8f799bf5cdde4f8 Mon Sep 17 00:00:00 2001 From: Type-Delta <121682210+Type-Delta@users.noreply.github.com> Date: Tue, 25 Aug 2026 13:34:41 +0700 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20fix(ci):=20Stabiliz?= =?UTF-8?q?e=20clean=20Windows=20test=20execution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Anchor test environments to the repository so commands that change cwd cannot create recursively nested paths. Make doctor tests self-contained on clean checkouts and harden Bun 1.3 runtime probing for shell-sensitive Windows paths. --- scripts/postinstall.cjs | 17 +++++++++++++++-- src/utils/testHelper.ts | 20 +++++++++----------- test/commands/doctor.spec.ts | 19 ++++++++++++++++++- test/utils/test-helper.spec.ts | 24 ++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 test/utils/test-helper.spec.ts diff --git a/scripts/postinstall.cjs b/scripts/postinstall.cjs index 01240b0..a7b5e75 100644 --- a/scripts/postinstall.cjs +++ b/scripts/postinstall.cjs @@ -313,6 +313,7 @@ function findRuntimeExecutable(name, platform = process.platform) { const located = spawnSync(locator, [name], { encoding: 'utf8', windowsHide: true, + env: process.env, }); if (located.error || located.status !== 0) return null; @@ -321,12 +322,24 @@ function findRuntimeExecutable(name, platform = process.platform) { const probe = needsShell ? spawnSync( process.env.ComSpec || 'cmd.exe', - ['/d', '/s', '/c', `""${executable}" -e "process.stdout.write(process.execPath)""`], - { encoding: 'utf8', windowsHide: true, windowsVerbatimArguments: true } + [ + '/d', + '/s', + '/c', + `""${path.basename(executable)}" -e "process.stdout.write(process.execPath)""`, + ], + { + encoding: 'utf8', + windowsHide: true, + windowsVerbatimArguments: true, + cwd: path.dirname(executable), + env: process.env, + } ) : spawnSync(executable, ['-e', 'process.stdout.write(process.execPath)'], { encoding: 'utf8', windowsHide: true, + env: process.env, }); const runtimeExecutable = String(probe.stdout || '').trim(); if (!probe.error && probe.status === 0 && fs.existsSync(runtimeExecutable)) { diff --git a/src/utils/testHelper.ts b/src/utils/testHelper.ts index 8bca5fc..52a50ba 100644 --- a/src/utils/testHelper.ts +++ b/src/utils/testHelper.ts @@ -29,6 +29,7 @@ let originalStdoutWrite: typeof process.stdout.write | null = null; let originalStderrWrite: typeof process.stderr.write | null = null; const USE_NATIVE_SUBMODULE_IN_TESTS = process.env.GDX_USE_INLINE_SUBMODULE === 'off'; const USE_NATIVE_GIT_CONFIG_IN_TESTS = process.env.GDX_USE_INLINE_GIT_CONFIG === 'off'; +const BASE_TEST_ENV_DIR = path.resolve(import.meta.dir, '../../test/env'); const __openInEditor = openInEditor; interface TestSystem { @@ -224,8 +225,6 @@ export async function createTestEnv( ...options.overwrites, }, }; - const baseTestEnvDir = path.join(process.cwd(), 'test/env'); - const clearedTestEnvs = clearTestEnvs(); if (clearedTestEnvs && process.platform === 'win32') { if (USE_NATIVE_SUBMODULE_IN_TESTS) { @@ -242,10 +241,10 @@ export async function createTestEnv( ncc() ); } - fs.mkdirSync(baseTestEnvDir, { recursive: true }); + fs.mkdirSync(BASE_TEST_ENV_DIR, { recursive: true }); const tmpDir = fs.mkdtempSync( - baseTestEnvDir + (resolvedOptions.suitName ? `/${resolvedOptions.suitName}-` : '/') + BASE_TEST_ENV_DIR + (resolvedOptions.suitName ? `/${resolvedOptions.suitName}-` : '/') ); const tmpDirName = path.basename(tmpDir); @@ -574,11 +573,10 @@ function getTestRunKey(): string { function clearTestEnvs(): boolean { if (testEnvCleared) return false; - const baseTestEnvDir = path.join(process.cwd(), 'test/env'); const markerName = `.gdx-test-run-${getTestRunKey()}`; - const markerPath = path.join(baseTestEnvDir, markerName); + const markerPath = path.join(BASE_TEST_ENV_DIR, markerName); - fs.mkdirSync(baseTestEnvDir, { recursive: true }); + fs.mkdirSync(BASE_TEST_ENV_DIR, { recursive: true }); if (fs.existsSync(markerPath)) { testEnvCleared = true; @@ -587,9 +585,9 @@ function clearTestEnvs(): boolean { let staleEntries: string[]; try { - staleEntries = fs.readdirSync(baseTestEnvDir); + staleEntries = fs.readdirSync(BASE_TEST_ENV_DIR); } catch { - console.error(`Failed to list test envs in: ${baseTestEnvDir}`); + console.error(`Failed to list test envs in: ${BASE_TEST_ENV_DIR}`); return false; } @@ -600,11 +598,11 @@ function clearTestEnvs(): boolean { return false; } - console.log(`Clearing stale test envs in: ${baseTestEnvDir}`); + console.log(`Clearing stale test envs in: ${BASE_TEST_ENV_DIR}`); for (const entry of staleEntries) { if (entry === markerName) continue; try { - fs.rmSync(path.join(baseTestEnvDir, entry), { recursive: true, force: true }); + fs.rmSync(path.join(BASE_TEST_ENV_DIR, entry), { recursive: true, force: true }); } catch { console.error(`Failed to remove stale test env: ${entry}`); } diff --git a/test/commands/doctor.spec.ts b/test/commands/doctor.spec.ts index 61bb60c..b052d35 100644 --- a/test/commands/doctor.spec.ts +++ b/test/commands/doctor.spec.ts @@ -1,5 +1,6 @@ import { describe, expect } from 'bun:test'; import path from 'node:path'; +import { pathToFileURL } from 'node:url'; import pkg from '../../package.json'; @@ -14,7 +15,23 @@ describe('gdx doctor', async () => { const writeInstallInfo = (version: string, shimInstalled = false) => { const nativeDir = path.join(tmpRootDir, 'native'); - fs.mkdirSync(nativeDir, { recursive: true }); + const scriptsDir = path.join(tmpRootDir, 'scripts'); + const workersDir = path.join(tmpRootDir, 'dist/workers'); + const diagnosticsDir = path.join(tmpRootDir, 'dist/diagnostics'); + for (const directory of [nativeDir, scriptsDir, workersDir, diagnosticsDir]) { + fs.mkdirSync(directory, { recursive: true }); + } + fs.writeFileSync(path.join(tmpRootDir, 'package.json'), JSON.stringify(pkg)); + fs.writeFileSync(path.join(scriptsDir, 'launcher.cjs'), ''); + fs.writeFileSync(path.join(scriptsDir, 'postinstall.cjs'), ''); + fs.writeFileSync(path.join(tmpRootDir, 'dist/index.js'), ''); + fs.writeFileSync(path.join(workersDir, 'generic.worker.min.js'), ''); + fs.writeFileSync( + path.join(diagnosticsDir, 'postinstall.validator.js'), + `export { runPostInstallDiagnostics } from ${JSON.stringify( + pathToFileURL(path.resolve(import.meta.dir, '../postinstall.validator.ts')).href + )};\n` + ); fs.writeFileSync( path.join(nativeDir, 'install.json'), JSON.stringify({ diff --git a/test/utils/test-helper.spec.ts b/test/utils/test-helper.spec.ts new file mode 100644 index 0000000..c443505 --- /dev/null +++ b/test/utils/test-helper.spec.ts @@ -0,0 +1,24 @@ +import { expect, it } from 'bun:test'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; + +import { createTestEnv } from '@/utils/testHelper'; + +it('anchors test environments to the repository when cwd changes', async () => { + const originalCwd = process.cwd(); + const outsideDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gdx-test-helper-cwd-')); + let cleanup = () => {}; + + try { + process.chdir(outsideDir); + const env = await createTestEnv(); + cleanup = env.cleanup; + + expect(path.dirname(env.tmpRootDir)).toBe(path.resolve(import.meta.dir, '../env')); + } finally { + process.chdir(originalCwd); + cleanup(); + fs.rmSync(outsideDir, { recursive: true, force: true }); + } +}); From 8484021fa3c5f986e51e2b272fe957020cff3eb0 Mon Sep 17 00:00:00 2001 From: Type-Delta <121682210+Type-Delta@users.noreply.github.com> Date: Tue, 25 Aug 2026 13:48:33 +0700 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20fix(parallel):=20Re?= =?UTF-8?q?move=20clean=20submodule=20worktrees?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use Git's required force flag only after gdx has verified the worktree and all submodules are clean, then deinitialized them. Tighten native-mode coverage to require successful removal. --- src/commands/parallel.ts | 8 +++++++- test/commands/parallel.spec.ts | 7 ++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/commands/parallel.ts b/src/commands/parallel.ts index 3d654ba..39bb44d 100644 --- a/src/commands/parallel.ts +++ b/src/commands/parallel.ts @@ -735,7 +735,13 @@ export async function removeParallelWorktree( try { Logger.debug(`Executing git worktree remove for '${alias}'...`, 'parallel'); - const result = await $`${operationGit$} worktree remove ${targetPath}`; + const removeArgs = [ + 'worktree', + 'remove', + ...(submodules.length > 0 ? ['--force'] : []), + targetPath, + ]; + const result = await $`${operationGit$} ${removeArgs}`; spinnerCtrl.stop(); quickPrint(result.stdout.trim()); diff --git a/test/commands/parallel.spec.ts b/test/commands/parallel.spec.ts index d418baf..d7eb892 100644 --- a/test/commands/parallel.spec.ts +++ b/test/commands/parallel.spec.ts @@ -946,11 +946,8 @@ describe('gdx parallel', async () => { const removeCtx = createGdxContext(tmpDir, ['parallel', 'remove', 'feature-deinit']); const removeResult = await parallel(removeCtx); - if (removeResult === 0) { - expect(buffer.stdout.toLowerCase()).toContain('removed worktree'); - } else { - expect(isSubmoduleRemovalBlockedError(buffer.stderr)).toBe(true); - } + expect(removeResult).toBe(0); + expect(buffer.stdout.toLowerCase()).toContain('removed worktree'); } finally { await forceRemoveWorktreePath(forkPath); await fs.rm(path.join(tmpDir, 'deps'), { recursive: true, force: true }); From 94b083fdccc23baf7eacdfb50e8aa116b543e248 Mon Sep 17 00:00:00 2001 From: Type-Delta <121682210+Type-Delta@users.noreply.github.com> Date: Tue, 25 Aug 2026 13:55:49 +0700 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A7=B9=20chore(ci):=20Verify=20with?= =?UTF-8?q?=20Bun=201.4.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit