fix: respect compose project name

This commit is contained in:
2026-08-30 19:11:50 +07:00 Unverified
parent 7f1d445981
commit e7efa9b44a
8 changed files with 58 additions and 7 deletions
+22 -1
View File
@@ -7,7 +7,7 @@ import {
resolveComposeArch,
withComposeArch,
} from "../../lib/arch";
import { createCachedGetter, ctx } from "../../lib/context";
import { createCachedGetter, ctx, resolveProjectName } from "../../lib/context";
import { toEnvVars, toTable } from "../../lib/format";
import { deepMerge, getPodContainerName, throwWhen } from "../../lib/shared";
@@ -131,6 +131,27 @@ describe("shared helpers", () => {
});
describe("context helpers", () => {
test("resolves project names using config, Compose, then directory precedence", () => {
expect(
resolveProjectName(
{ project: "directory", projectConfigured: false },
{ name: "compose" },
),
).toBe("compose");
expect(
resolveProjectName(
{ project: "config", projectConfigured: true },
{ name: "compose" },
),
).toBe("config");
expect(
resolveProjectName(
{ project: "directory", projectConfigured: false },
{},
),
).toBe("directory");
});
test("rejects access outside an application context", () => {
expect(() => ctx()).toThrow("Not in context");
});
+5 -1
View File
@@ -50,8 +50,12 @@ describe("Compose parsing", () => {
test("parses and validates a minimal Compose project", async () => {
const directory = await temporaryDirectory();
const path = join(directory, "compose.yml");
await writeFile(path, "services:\n app:\n image: nginx:latest\n");
await writeFile(
path,
"name: compose-project\nservices:\n app:\n image: nginx:latest\n",
);
expect(await readCompose(path)).toMatchObject({
name: "compose-project",
services: { app: { image: "nginx:latest" } },
});
});