fix(test): isolate integration tests from production hub via temp hub globalSetup (#734)

This commit is contained in:
SSU-WEI HUANG
2026-05-31 20:31:05 +08:00
committed by GitHub
parent 994a820e43
commit df35a8c523
6 changed files with 170 additions and 21 deletions
+8
View File
@@ -37,6 +37,7 @@ vi.mock('@/projectPath', () => ({
const originalPlatformDescriptor = Object.getOwnPropertyDescriptor(process, 'platform');
const originalInvokedCwd = process.env.HAPI_INVOKED_CWD;
const originalCliExecutable = process.env.HAPI_CLI_EXECUTABLE;
const originalBunExec = process.env.HAPI_BUN_EXEC;
function setPlatform(value: string) {
Object.defineProperty(process, 'platform', {
@@ -78,6 +79,11 @@ describe('spawnHappyCLI windowsHide behavior', () => {
} else {
process.env.HAPI_CLI_EXECUTABLE = originalCliExecutable;
}
if (originalBunExec === undefined) {
delete process.env.HAPI_BUN_EXEC;
} else {
process.env.HAPI_BUN_EXEC = originalBunExec;
}
});
afterAll(() => {
@@ -129,6 +135,8 @@ describe('spawnHappyCLI windowsHide behavior', () => {
});
it('forces Bun child processes to run with the cli project root as cwd', async () => {
// Clear the test-isolation override so we test the pure runtime behaviour
delete process.env.HAPI_BUN_EXEC;
const { getHappyCliCommand } = await import('./spawnHappyCLI');
const command = getHappyCliCommand(['mcp', '--url', 'http://127.0.0.1:1234/']);
+10
View File
@@ -116,6 +116,16 @@ export function getHappyCliCommand(args: string[]): HappyCliCommand {
};
}
// When vitest runs under Node.js, HAPI_BUN_EXEC can point to the bun binary so that
// spawned CLI child processes still run under bun (which is required for TypeScript entrypoints).
const bunExecOverride = process.env['HAPI_BUN_EXEC']?.trim();
if (bunExecOverride && isCrossPlatformAbsolutePath(bunExecOverride) && existsSync(bunExecOverride)) {
return {
command: bunExecOverride,
args: ['--cwd', projectRoot, entrypoint, ...args]
};
}
// Node.js fallback: preserve execArgv (for compatibility)
return {
command: process.execPath,