diff --git a/scripts/crabbox-wrapper.mjs b/scripts/crabbox-wrapper.mjs index 66ef52300656..a2a221084cb3 100755 --- a/scripts/crabbox-wrapper.mjs +++ b/scripts/crabbox-wrapper.mjs @@ -2940,16 +2940,7 @@ function isWorktreeClean() { return gitOutput(["status", "--porcelain=v1"]).stdout === ""; } -function hasAgentsBranchChanges() { - const base = gitOutput(["merge-base", "HEAD", "refs/remotes/origin/main"]); - if (base.status !== 0) { - return false; - } - const changed = gitOutput(["diff", "--name-only", `${base.stdout}..HEAD`, "--", ".agents"]); - return changed.status === 0 && changed.stdout.length > 0; -} - -function shouldUseFullCheckoutForCleanRemoteSync(commandArgs, providerName) { +function shouldUseFullCheckoutForCleanRemoteSync(commandArgs, _providerName) { if (commandArgs[0] !== "run") { return false; } @@ -2960,11 +2951,7 @@ function shouldUseFullCheckoutForCleanRemoteSync(commandArgs, providerName) { return false; } - return ( - isSparseCheckout() || - isChangedGateCommand(runCommandArgs(commandArgs)) || - (canonicalProviderName(providerName) === "blacksmith-testbox" && hasAgentsBranchChanges()) - ); + return isSparseCheckout() || isChangedGateCommand(runCommandArgs(commandArgs)); } function defaultFullCheckoutSyncRoot() { @@ -3194,6 +3181,23 @@ function injectFullCheckoutLeaseReclaim(commandArgs) { return normalizedArgs; } +function injectRemoteTestboxCi(commandArgs, providerName) { + if (commandArgs[0] !== "run" || canonicalProviderName(providerName) !== "blacksmith-testbox") { + return commandArgs; + } + const normalizedArgs = [...commandArgs]; + const { start } = runCommandBounds(normalizedArgs); + if (start < 0) { + return normalizedArgs; + } + if (hasOption(normalizedArgs, "--shell")) { + normalizedArgs[start] = `env CI=true ${normalizedArgs[start]}`; + } else { + normalizedArgs.splice(start, 0, "env", "CI=true"); + } + return normalizedArgs; +} + const version = probeCrabboxMetadata(binary, ["--version"]); const help = probeCrabboxMetadata(binary, ["run", "--help"]); const providers = parseProvidersFromHelp(help.text); @@ -3388,7 +3392,7 @@ try { cleanupOnce(); throw error; } -const childArgs = +const childArgs = injectRemoteTestboxCi( childCwd === repoRoot ? injectRemoteWindowsHydratedNodeModulesBootstrap( injectRemoteAwsMacosSwiftBootstrap( @@ -3408,7 +3412,9 @@ const childArgs = provider, ), remoteChangedGateBase, - ); + ), + provider, +); let testboxLeaseFreshness; try { testboxLeaseFreshness = prepareTestboxLeaseFreshness({ diff --git a/test/scripts/crabbox-wrapper.test.ts b/test/scripts/crabbox-wrapper.test.ts index 9efd78f7f9b5..92dc04d1b243 100644 --- a/test/scripts/crabbox-wrapper.test.ts +++ b/test/scripts/crabbox-wrapper.test.ts @@ -760,6 +760,8 @@ describe("scripts/crabbox-wrapper", () => { "--id", "tbx_owned", "--", + "env", + "CI=true", "echo ok", ]); }); @@ -782,6 +784,8 @@ describe("scripts/crabbox-wrapper", () => { "--id", "blue-hermit", "--", + "env", + "CI=true", "echo ok", ]); }); @@ -3166,7 +3170,9 @@ describe("scripts/crabbox-wrapper", () => { expect(result.error).toBeUndefined(); expect(result.status).toBe(0); expect(result.stderr).not.toContain("could not parse provider list"); - expect(result.stderr).not.toContain("selected binary failed basic --version/--help sanity checks"); + expect(result.stderr).not.toContain( + "selected binary failed basic --version/--help sanity checks", + ); expect(result.stderr).toContain( "providers=hetzner,aws,local-container,blacksmith-testbox,cloudflare", );