fix(adobe-firefly): do not spawn Chrome for CDP warm under test runners (#13289)

The CDP session-warm path gated only on ADOBE_FIREFLY_BROWSER_REFRESH, so a unit
test exercising the image-edit route spawned a real headed Chrome. The browser
holds an OS handle on its profile directory under DATA_DIR, so teardown that
rmSync()s the temp DATA_DIR failed with EPERM on Windows, and the CDP socket kept
the runner alive for the full 75s warm timeout.

Gate the browser path on the same test-runner detection diskSessionsEnabled()
already uses. 8510-adobe-firefly-edits-route: 1 pass/4 fail in 63s -> 4 pass/0
fail in 2.5s.
This commit is contained in:
anhtahaylove
2026-09-17 12:32:10 +07:00
committed by GitHub
parent fde6241d41
commit cb9740b78d
2 changed files with 16 additions and 3 deletions

View File

@@ -0,0 +1 @@
- **fix(adobe-firefly):** never spawn a real Chrome for CDP session warm under a unit-test runner, so tests stop leaking a browser process that holds an OS handle on its DATA_DIR profile directory

View File

@@ -133,7 +133,7 @@ const FORTER_PROACTIVE_WARM_MS = 3 * 60_000;
* "1" still enables it; any other value (including unset) now also enables it.
*/
export function adobeFireflyBrowserEnabled(): boolean {
return process.env.ADOBE_FIREFLY_BROWSER_REFRESH !== "0";
return browserRefreshEnabled();
}
/** Persist sessions under DATA_DIR so restarts keep JWT + last cookie. */
const SESSION_DIR_NAME = "adobe-firefly-sessions";
@@ -430,6 +430,19 @@ export function estimateAdobeTokenExpiry(accessToken: string): number {
return Date.now() + 20 * 60 * 60_000;
}
/**
* Spawning a real Chrome is never valid under a unit-test runner. The browser holds
* an OS handle on its profile directory under DATA_DIR, so a test that rmSync()s its
* temp DATA_DIR in teardown fails with EPERM on Windows, and the CDP socket keeps the
* runner alive for the full 75s warm timeout.
*/
function browserRefreshEnabled(): boolean {
if (process.env.ADOBE_FIREFLY_BROWSER_REFRESH === "0") return false;
if (process.env.NODE_ENV === "test") return false;
if (process.env.VITEST || process.env.NODE_TEST_CONTEXT) return false;
return true;
}
function diskSessionsEnabled(): boolean {
// Unit tests and explicit opt-out skip durable disk cache (avoids sticky IMS skips).
if (process.env.ADOBE_FIREFLY_SESSION_DISK === "0") return false;
@@ -954,8 +967,7 @@ export async function rotateAdobeFireflySessionOnError(
clearAdobeFireflyWorkingArp(session.fingerprint);
noteAdobeFireflySubmitFailure();
const tryBrowser =
opts?.tryBrowser !== false && process.env.ADOBE_FIREFLY_BROWSER_REFRESH !== "0";
const tryBrowser = opts?.tryBrowser !== false && browserRefreshEnabled();
if (tryBrowser) {
opts?.log?.info?.(
"ADOBE-FIREFLY",