Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions scripts/postinstall.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)) {
Expand Down
8 changes: 7 additions & 1 deletion src/commands/parallel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
20 changes: 9 additions & 11 deletions src/utils/testHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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}`);
}
Expand Down
19 changes: 18 additions & 1 deletion test/commands/doctor.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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({
Expand Down
7 changes: 2 additions & 5 deletions test/commands/parallel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
24 changes: 24 additions & 0 deletions test/utils/test-helper.spec.ts
Original file line number Diff line number Diff line change
@@ -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 });
}
});
Loading