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: 3 additions & 3 deletions src/commands/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5304,7 +5304,7 @@ async function handleRun({
composeProject: composeProjectName,
project,
profiles,
requestedEnvName: envName ?? null,
effectiveEnvName: envOverrides.effectiveEnvName,
service,
});
return await composeRuntimeBackend.run({
Expand All @@ -5326,14 +5326,14 @@ async function resolveCanSkipRunDependencies(opts: {
readonly composeProject: string | null;
readonly profiles: readonly string[];
readonly project: Awaited<ReturnType<typeof requireProjectContext>>;
readonly requestedEnvName: string | null;
readonly effectiveEnvName: string | null;
readonly service: string;
}): Promise<boolean> {
const runtimeState = await readProjectRuntimeStateEntry({
projectDir: opts.project.projectDir,
composeProject: opts.composeProjectKey,
});
if (runtimeState && runtimeState.envName !== opts.requestedEnvName) {
if (runtimeState && runtimeState.envName !== opts.effectiveEnvName) {
return false;
}

Expand Down
48 changes: 47 additions & 1 deletion tests/project-run-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,56 @@ test("run keeps dependency startup when the requested env differs from the live
expect(runCalls[0]?.noDeps).toBe(false);
});

test("run skips dependency startup when omitted env resolves to the live default overlay", async () => {
const projectRoot = await createProject({
config: {
env: {
defaultOverlay: "qa",
},
},
runtimeComposeProject: "project-run-env-test",
runtimeEnvName: "qa",
runningServices: ["api"],
});

const input = {
ctx: {
cwd: projectRoot,
cli: CLI_SPEC,
},
args: {
options: {
path: projectRoot,
project: undefined,
env: undefined,
branch: undefined,
workdir: undefined,
profile: undefined,
},
positionals: {
service: "api",
cmd: ["printenv"],
},
raw: {
argv: ["--path", projectRoot, "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(true);
});

async function createProject(input?: {
readonly services?: readonly string[];
readonly defaultYaml?: string;
readonly runtimeComposeProject?: string;
readonly runtimeEnvName?: string | null;
readonly runningServices?: readonly string[];
readonly config?: Record<string, unknown>;
}): Promise<string> {
const root = await mkdtemp(join(tmpdir(), "hack-project-run-env-"));
tempDirs.add(root);
Expand All @@ -327,6 +372,7 @@ async function createProject(input?: {
{
name: "project-run-env-test",
dev_host: "project-run-env.hack",
...(input?.config ?? {}),
},
null,
2
Expand All @@ -341,7 +387,7 @@ async function createProject(input?: {
entries: [
{
composeProject: input.runtimeComposeProject,
envName: null,
envName: input.runtimeEnvName ?? null,
updatedAt: "2026-03-31T00:00:00.000Z",
},
],
Expand Down
Loading