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
6 changes: 1 addition & 5 deletions src/commands/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Compare runtime env against effective run env

The new mismatch check treats any stored non-null runtime env as incompatible when --env is omitted, because handleRun passes requestedEnvName as envName ?? null and resolveComposeEnvOverrides can still select a non-base default overlay. In that common env.defaultOverlay case, this condition makes hack run stop using --no-deps even when the live stack env actually matches the effective env, causing unnecessary dependency startup on every run.

Useful? React with 👍 / 👎.

return false;
}

Expand Down
37 changes: 37 additions & 0 deletions tests/project-run-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof runCommand.handler>[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;
Expand Down
Loading