diff --git a/src/commands/project.ts b/src/commands/project.ts index ed420a65..2e7a7eb8 100644 --- a/src/commands/project.ts +++ b/src/commands/project.ts @@ -5333,11 +5333,7 @@ async function resolveCanSkipRunDependencies(opts: { projectDir: opts.project.projectDir, composeProject: opts.composeProjectKey, }); - if ( - opts.requestedEnvName !== null && - runtimeState?.envName !== null && - runtimeState?.envName !== opts.requestedEnvName - ) { + if (runtimeState && runtimeState.envName !== opts.requestedEnvName) { return false; } diff --git a/tests/project-run-command.test.ts b/tests/project-run-command.test.ts index a90f368b..c5b1143c 100644 --- a/tests/project-run-command.test.ts +++ b/tests/project-run-command.test.ts @@ -262,6 +262,43 @@ test("run keeps dependency startup when cached runtime state is stale", async () expect(runCalls[0]?.noDeps).toBe(false); }); +test("run keeps dependency startup when the requested env differs from the live stack env", async () => { + const projectRoot = await createProject({ + runtimeComposeProject: "project-run-env-test", + runningServices: ["api"], + }); + + const input = { + ctx: { + cwd: projectRoot, + cli: CLI_SPEC, + }, + args: { + options: { + path: projectRoot, + project: undefined, + env: "qa", + branch: undefined, + workdir: undefined, + profile: undefined, + }, + positionals: { + service: "api", + cmd: ["printenv"], + }, + raw: { + argv: ["--path", projectRoot, "--env", "qa", "api", "printenv"], + positionals: ["api", "printenv"], + }, + }, + } as unknown as Parameters[0]; + + const exitCode = await runCommand.handler(input); + + expect(exitCode).toBe(0); + expect(runCalls[0]?.noDeps).toBe(false); +}); + async function createProject(input?: { readonly services?: readonly string[]; readonly defaultYaml?: string;