@solid-stack/builder 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +6 -7
  2. package/dist/bin.js +370 -339
  3. package/dist/bin.js.map +1 -1
  4. package/dist/commands/mesh/commands/down/handler.d.ts.map +1 -1
  5. package/dist/commands/mesh/commands/up/command.d.ts.map +1 -1
  6. package/dist/commands/mesh/commands/up/handler.d.ts.map +1 -1
  7. package/dist/core/composition/compileServiceComposition.d.ts.map +1 -1
  8. package/dist/core/composition/composeDependsOn.d.ts +3 -1
  9. package/dist/core/composition/composeDependsOn.d.ts.map +1 -1
  10. package/dist/core/composition/composePaths.d.ts +1 -0
  11. package/dist/core/composition/composePaths.d.ts.map +1 -1
  12. package/dist/core/composition/dependencyLifecycle.d.ts.map +1 -1
  13. package/dist/core/composition/validateMaterializedComposeBuildInputs.d.ts +4 -0
  14. package/dist/core/composition/validateMaterializedComposeBuildInputs.d.ts.map +1 -0
  15. package/dist/core/composition/validateMaterializedComposeFiles.d.ts +8 -0
  16. package/dist/core/composition/validateMaterializedComposeFiles.d.ts.map +1 -0
  17. package/dist/core/config/meshStageContract.d.ts +6 -0
  18. package/dist/core/config/meshStageContract.d.ts.map +1 -0
  19. package/dist/core/config/resolveMeshStage.d.ts.map +1 -1
  20. package/dist/core/config/types.d.ts +1 -1
  21. package/dist/core/config/types.d.ts.map +1 -1
  22. package/dist/core/mesh/checkers/checkMesh.d.ts +0 -1
  23. package/dist/core/mesh/checkers/checkMesh.d.ts.map +1 -1
  24. package/dist/core/mesh/checkers/checkMeshServices.d.ts +2 -5
  25. package/dist/core/mesh/checkers/checkMeshServices.d.ts.map +1 -1
  26. package/dist/core/mesh/getMeshJson.d.ts.map +1 -1
  27. package/dist/core/mesh/meshSchema.d.ts +0 -55
  28. package/dist/core/mesh/meshSchema.d.ts.map +1 -1
  29. package/dist/core/mesh/runners/runMeshTestE2e.d.ts.map +1 -1
  30. package/dist/core/mesh/types.d.ts +4 -4
  31. package/dist/core/mesh/types.d.ts.map +1 -1
  32. package/dist/core/mesh/v2/compileMeshComposition.d.ts.map +1 -1
  33. package/dist/core/mesh/v2/compileMeshTester.d.ts.map +1 -1
  34. package/dist/core/runners/runFiniteTester.d.ts +3 -0
  35. package/dist/core/runners/runFiniteTester.d.ts.map +1 -0
  36. package/dist/core/runners/runTestE2e.d.ts.map +1 -1
  37. package/dist/index.js +371 -340
  38. package/dist/index.js.map +1 -1
  39. package/dist/utils/runState.d.ts.map +1 -1
  40. package/package.json +1 -1
  41. package/schemas/mesh-schema.json +0 -106
  42. package/dist/core/mesh/runners/runMeshTestUnit.d.ts +0 -3
  43. package/dist/core/mesh/runners/runMeshTestUnit.d.ts.map +0 -1
  44. package/dist/core/mesh/v2/validateMeshTestStage.d.ts +0 -22
  45. package/dist/core/mesh/v2/validateMeshTestStage.d.ts.map +0 -1
package/dist/bin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command, Argument } from 'commander';
3
- import pc14 from 'picocolors';
3
+ import pc15 from 'picocolors';
4
4
  import fs, { existsSync, readFileSync, mkdirSync, writeFileSync, statSync, unlinkSync, realpathSync, lstatSync, readlinkSync, renameSync } from 'fs';
5
5
  import path from 'path';
6
6
  import { z } from 'zod';
@@ -172,7 +172,7 @@ function runStep(executable, args, projectDir, ctx) {
172
172
  if (stderr) process.stderr.write(stderr);
173
173
  if (result.error || result.status !== 0) {
174
174
  console.error("\n" + "=".repeat(60));
175
- console.error(pc14.red(`\u{1F6A8} INFRASTRUCTURE CHECK FAILED \u{1F6A8}`));
175
+ console.error(pc15.red(`\u{1F6A8} INFRASTRUCTURE CHECK FAILED \u{1F6A8}`));
176
176
  console.error("=".repeat(60));
177
177
  console.error(`Failed Step : ${ctx.stepName}`);
178
178
  if (ctx.targetFile) {
@@ -199,7 +199,7 @@ function checkDockerfile(buildJson, projectDir) {
199
199
  const dockerfileRel = buildJson.dockerfile || "Dockerfile";
200
200
  const dockerfilePath = resolveApplicationDockerfile(projectDir, dockerfileRel);
201
201
  const content = readFileSync(dockerfilePath, "utf-8");
202
- console.log(pc14.cyan(`
202
+ console.log(pc15.cyan(`
203
203
  \u{1F50D} Linting Dockerfile (${dockerfileRel})...`));
204
204
  runStep(
205
205
  "docker",
@@ -269,7 +269,7 @@ function checkDockerfileContract(build, projectDir) {
269
269
  const relative = build.dockerfile ?? "Dockerfile";
270
270
  resolveApplicationDockerfile(root, relative);
271
271
  const policyDir = getDockerfilePolicyDir();
272
- console.log(pc14.cyan(`
272
+ console.log(pc15.cyan(`
273
273
  \u{1F50D} Validating Builder Dockerfile contract (${relative})...`));
274
274
  runStep("docker", ["run", "--rm", "--network", "none", "--mount", `type=bind,src=${root},dst=/project,readonly`, "--mount", `type=bind,src=${policyDir},dst=/builder-policy,readonly`, "-w", "/project", CONFTEST_IMAGE, "test", relative, "-p", "/builder-policy"], root, { stepName: "Dockerfile Contract", targetFile: relative });
275
275
  }
@@ -324,7 +324,7 @@ function getDeclaredYamlFiles(build, projectDir) {
324
324
  function checkYamlFiles(build, projectDir) {
325
325
  const root = resolveProjectDir(projectDir);
326
326
  const files = getDeclaredYamlFiles(build, root);
327
- if (files.length) console.log(pc14.cyan(`
327
+ if (files.length) console.log(pc15.cyan(`
328
328
  \u{1F50D} Validating ${files.length} declared V2 Compose file(s)...`));
329
329
  for (const file of files) {
330
330
  const absolutePath = resolveInsideProject(root, file.relativePath, { sourceFile: `${root}/build.json`, configPath: file.source, ...file.stage ? { stage: file.stage } : {} });
@@ -970,9 +970,9 @@ function validateComposeResourceReferences(document, context, onlyServices) {
970
970
  const definitions = document[kind === "volume" ? "volumes" : kind === "network" ? "networks" : kind === "config" ? "configs" : "secrets"];
971
971
  return Boolean(definitions && Object.hasOwn(definitions, name));
972
972
  };
973
- const check = (path22, kind, name) => {
973
+ const check = (path24, kind, name) => {
974
974
  if (kind === "network" && name === "default") return;
975
- if (!exists(kind, name)) fail(path22, kind, name);
975
+ if (!exists(kind, name)) fail(path24, kind, name);
976
976
  };
977
977
  for (const [serviceName, service] of Object.entries(document.services ?? {})) {
978
978
  validateServiceResources(serviceName, service, check);
@@ -1084,6 +1084,87 @@ function validateDependencyCompose(dependencyKey, dependency, document, context)
1084
1084
  if (!isEnabledValidComposeHealthcheck(services[owner].healthcheck)) fail(`services.${owner}.healthcheck`, "endpoint owner requires a valid enabled Compose healthcheck");
1085
1085
  }
1086
1086
  }
1087
+ function validateMaterializedComposeFiles(document, sourceFile, stage, options = {}) {
1088
+ const baseDir = options.baseDir ?? path.dirname(sourceFile);
1089
+ for (const kind of ["configs", "secrets"]) {
1090
+ for (const [name, raw] of Object.entries(document[kind] ?? {})) {
1091
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
1092
+ const file = raw.file;
1093
+ if (typeof file !== "string") continue;
1094
+ const absolute = path.resolve(baseDir, file);
1095
+ let regular = false;
1096
+ try {
1097
+ regular = fs.statSync(absolute).isFile();
1098
+ } catch {
1099
+ }
1100
+ if (!regular) {
1101
+ throw new ConfigError({
1102
+ sourceFile,
1103
+ configPath: `${kind}.${name}.file`,
1104
+ stage,
1105
+ composition: options.composition ?? "service",
1106
+ value: file,
1107
+ reason: "Materialized Compose file resource is missing or not a regular file"
1108
+ });
1109
+ }
1110
+ }
1111
+ }
1112
+ }
1113
+ function validateMaterializedComposeBuildInputs(document, sourceFile, stage, composition) {
1114
+ const baseDir = path.dirname(sourceFile);
1115
+ for (const [name, service] of Object.entries(document.services ?? {})) {
1116
+ const build = service.build;
1117
+ if (build === void 0) continue;
1118
+ const objectBuild = build && typeof build === "object" && !Array.isArray(build) ? build : void 0;
1119
+ const context = typeof build === "string" ? build : objectBuild?.context ?? ".";
1120
+ const configPath = `services.${name}.build`;
1121
+ const fail = (field, value, reason) => {
1122
+ throw new ConfigError({
1123
+ sourceFile,
1124
+ configPath: `${configPath}.${field}`,
1125
+ stage,
1126
+ composition,
1127
+ value,
1128
+ reason
1129
+ });
1130
+ };
1131
+ if (typeof context !== "string" || context.trim() === "") {
1132
+ return fail("context", context, "Local build context must be a non-empty path");
1133
+ }
1134
+ if (isRemoteBuildContext(context)) continue;
1135
+ const absoluteContext = path.resolve(baseDir, context);
1136
+ let directory = false;
1137
+ try {
1138
+ directory = fs.statSync(absoluteContext).isDirectory();
1139
+ } catch {
1140
+ }
1141
+ if (!directory) {
1142
+ fail(
1143
+ "context",
1144
+ context,
1145
+ "Materialized local build context is missing or not a directory"
1146
+ );
1147
+ }
1148
+ if (objectBuild?.dockerfile_inline !== void 0) continue;
1149
+ const dockerfile = objectBuild?.dockerfile ?? "Dockerfile";
1150
+ if (typeof dockerfile !== "string" || dockerfile.trim() === "") {
1151
+ return fail("dockerfile", dockerfile, "Dockerfile path must be a non-empty string");
1152
+ }
1153
+ const absoluteDockerfile = path.resolve(absoluteContext, dockerfile);
1154
+ let regular = false;
1155
+ try {
1156
+ regular = fs.statSync(absoluteDockerfile).isFile();
1157
+ } catch {
1158
+ }
1159
+ if (!regular) {
1160
+ fail(
1161
+ "dockerfile",
1162
+ dockerfile,
1163
+ "Materialized local Dockerfile is missing or not a regular file"
1164
+ );
1165
+ }
1166
+ }
1167
+ }
1087
1168
  function canonicalBuildContext(value, baseDir) {
1088
1169
  return canonicalPath(path.resolve(baseDir, value));
1089
1170
  }
@@ -1091,8 +1172,8 @@ function isSameBuildContext(actual, expected, baseDir) {
1091
1172
  return canonicalBuildContext(actual, baseDir) === canonicalBuildContext(expected, baseDir);
1092
1173
  }
1093
1174
  function validateAndPrepareAppOverride(document, context) {
1094
- const fail = (path22, reason, value) => {
1095
- throw new ConfigError({ sourceFile: context.file, configPath: path22, stage: context.stage, composition: "service", ...value === void 0 ? {} : { value }, reason });
1175
+ const fail = (path24, reason, value) => {
1176
+ throw new ConfigError({ sourceFile: context.file, configPath: path24, stage: context.stage, composition: "service", ...value === void 0 ? {} : { value }, reason });
1096
1177
  };
1097
1178
  const allowedRootKeys = /* @__PURE__ */ new Set(["services", "volumes", "networks", "configs", "secrets"]);
1098
1179
  for (const key of Object.keys(document)) if (!key.startsWith("x-") && !allowedRootKeys.has(key)) fail(key, "unsupported override Compose top-level field");
@@ -1196,18 +1277,30 @@ function mergeAppOverride(inherited, overlay) {
1196
1277
  return mergeValue(inherited, overlay);
1197
1278
  }
1198
1279
 
1199
- // src/core/composition/dependencyLifecycle.ts
1200
- function asMap(value) {
1201
- if (Array.isArray(value)) return Object.fromEntries(value.filter((v) => typeof v === "string").map((v) => [v, {}]));
1202
- if (value && typeof value === "object") return value;
1203
- return {};
1280
+ // src/core/composition/composeDependsOn.ts
1281
+ function normalizeComposeDependsOn(value) {
1282
+ const entries2 = Array.isArray(value) ? value.filter((item) => typeof item === "string").map((name) => [name, {}]) : value && typeof value === "object" ? Object.entries(value) : [];
1283
+ return Object.fromEntries(entries2.map(([name, options]) => [
1284
+ name,
1285
+ {
1286
+ ...options && typeof options === "object" && !Array.isArray(options) ? options : {},
1287
+ condition: "service_healthy"
1288
+ }
1289
+ ]));
1204
1290
  }
1291
+ function enforceHealthyDependsOn(document) {
1292
+ for (const service of Object.values(document.services ?? {})) {
1293
+ if (service.depends_on === void 0) continue;
1294
+ service.depends_on = normalizeComposeDependsOn(service.depends_on);
1295
+ }
1296
+ }
1297
+
1298
+ // src/core/composition/dependencyLifecycle.ts
1205
1299
  function healthyMerge(target, owners) {
1206
- const current = asMap(target.depends_on);
1300
+ const current = normalizeComposeDependsOn(target.depends_on);
1207
1301
  for (const owner of owners) {
1208
1302
  const old = current[owner];
1209
- const cond = old && typeof old === "object" ? old.condition : void 0;
1210
- current[owner] = { ...old && typeof old === "object" ? old : {}, condition: cond === "service_healthy" ? cond : "service_healthy" };
1303
+ current[owner] = { ...old && typeof old === "object" ? old : {}, condition: "service_healthy" };
1211
1304
  }
1212
1305
  target.depends_on = current;
1213
1306
  }
@@ -1309,11 +1402,12 @@ function compileServiceComposition(stage, projectDir, options = {}) {
1309
1402
  const namespaced = {};
1310
1403
  for (const [key, dep] of Object.entries(effective.dependencies).sort(([a], [b]) => a.localeCompare(b))) {
1311
1404
  const sourcePath = resolveInsideProject(root, dep.compose, { sourceFile: buildPath, configPath: `dependencies.${key}.compose`, stage });
1312
- const document = rebaseComposePaths(loadComposeDocument(sourcePath, { sourceFile: buildPath, configPath: `dependencies.${key}.compose`, stage, composition: "service" }), sourcePath, options.composeOutputDir ?? root);
1405
+ const rawDocument = loadComposeDocument(sourcePath, { sourceFile: buildPath, configPath: `dependencies.${key}.compose`, stage, composition: "service" });
1406
+ const document = rebaseComposePaths(rawDocument, sourcePath, options.composeOutputDir ?? root);
1313
1407
  validateDependencyCompose(key, dep, document, { composePath: sourcePath, stage });
1314
1408
  if (Object.keys(dep.endpoints).length) {
1315
1409
  const ns = namespaceDependencyCompose({ dependencyKey: key, namespacePrefix: options.namespacePrefix ? `${options.namespacePrefix}${key}` : `dep--${key}`, document, allocator: nameAllocator, identityPrefix: JSON.stringify(["service", options.appServiceName ?? "app", "dependency", key]) });
1316
- namespaced[key] = { doc: ns.document, map: ns.serviceNameMap, source: sourcePath };
1410
+ namespaced[key] = { doc: ns.document, raw: rawDocument, map: ns.serviceNameMap, source: sourcePath };
1317
1411
  }
1318
1412
  }
1319
1413
  const materialized = {};
@@ -1321,6 +1415,8 @@ function compileServiceComposition(stage, projectDir, options = {}) {
1321
1415
  let app = compose.services.app ?? (compose.services.app = { build: { context: "." } });
1322
1416
  if (profile.infraMode === "integrated") for (const [key, entry] of Object.entries(namespaced)) {
1323
1417
  if (options.suppressDependencies?.has(key)) continue;
1418
+ validateMaterializedComposeFiles(entry.raw, entry.source, stage);
1419
+ validateMaterializedComposeBuildInputs(entry.raw, entry.source, stage, "service");
1324
1420
  const dep = effective.dependencies[key];
1325
1421
  const item = structuredClone(entry.doc);
1326
1422
  mergeDocument(compose, item, { sourceFile: entry.source, configPath: `dependencies.${key}.compose`, stage, composition: "service" });
@@ -1455,6 +1551,10 @@ function compileServiceComposition(stage, projectDir, options = {}) {
1455
1551
  allocator: nameAllocator,
1456
1552
  resourceNamespace: options.meshMode ? options.appServiceName ?? "app" : "app"
1457
1553
  });
1554
+ validateMaterializedComposeFiles(loadedOverride, overridePath, stage, {
1555
+ baseDir: root,
1556
+ composition: "service"
1557
+ });
1458
1558
  for (const section of ["volumes", "networks", "configs", "secrets"]) if (prepared.resources[section]) mergeDocument(compose, { services: {}, [section]: prepared.resources[section] }, { sourceFile: overridePath, configPath: `${layer.stage}.override-compose`, stage, composition: "service" });
1459
1559
  const rawOverrideEnv = normalizeComposeEnvironment(prepared.app.environment, `${layer.stage}.override-compose.services.app.environment`);
1460
1560
  const overrideEnv = rawOverrideEnv;
@@ -1500,6 +1600,7 @@ function compileServiceComposition(stage, projectDir, options = {}) {
1500
1600
  const testerEnv = options.deferReferenceResolution ? testerEnvRaw : resolveEnv(testerEnvRaw, registry, testerContext);
1501
1601
  compose.services.tester = { build: { context: ".", ...raw.dockerfile ? { dockerfile: raw.dockerfile } : {}, target: profile.testerTarget ?? "test-e2e" }, network_mode: "host", env_file: [{ path: ".env.e2e-tester", required: false }], environment: { ...testerEnv, EXEC_MODE: "e2e" }, depends_on: { app: { condition: "service_healthy" } } };
1502
1602
  }
1603
+ enforceHealthyDependsOn(compose);
1503
1604
  nameAllocator.assertUnique();
1504
1605
  return { compose, effectiveBuild: effective, endpoints: { app: appEndpoints, dependencies: depEndpoints }, projectName, ...profile.attachTester && !options.meshMode ? { testerServiceName: "tester" } : {}, appEnvironmentLayers, builderInternalEnvironment: { ...internal }, externalAppEnvironment: { ...options.externalAppEnv ?? {} }, dependencyServiceNames: Object.fromEntries(Object.entries(materialized).map(([key, dep]) => [key, [...dep.serviceNames]])), dependencyEnvironments: Object.fromEntries(Object.entries(effective.dependencies).map(([key, dep]) => [key, dep.env])) };
1505
1606
  }
@@ -1521,7 +1622,7 @@ function checkInfra(projectDir = process.cwd()) {
1521
1622
  checkDockerfileContract(buildJson, absProjectDir);
1522
1623
  checkYamlFiles(buildJson, absProjectDir);
1523
1624
  checkAllEffectiveServiceStages(absProjectDir);
1524
- console.log(pc14.green("\n\u2705 All V2 service infrastructure and contract checks passed.\n"));
1625
+ console.log(pc15.green("\n\u2705 All V2 service infrastructure and contract checks passed.\n"));
1525
1626
  }
1526
1627
  function checkComposeAvailability() {
1527
1628
  const composeCheck = spawnSync(
@@ -1566,7 +1667,7 @@ function checkDependencies() {
1566
1667
  const count = (networkCheck.stdout || "").trim().split("\n").filter(Boolean).length;
1567
1668
  if (count > 25) {
1568
1669
  console.warn(
1569
- pc14.yellow(
1670
+ pc15.yellow(
1570
1671
  `
1571
1672
  \u26A0\uFE0F High Docker Network Count Warning: Detected ${count} networks. Docker's default address pool can become exhausted, resulting in "could not find an available, non-overlapping IPv4 address pool" errors.
1572
1673
  To resolve, run "builder prune" or "docker network prune -f", or configure default-address-pools in /etc/docker/daemon.json.
@@ -1605,6 +1706,36 @@ Examples:
1605
1706
  }
1606
1707
  });
1607
1708
  };
1709
+
1710
+ // src/core/mesh/types.ts
1711
+ var MESH_CONFIG_STAGES = ["dev", "prod", "e2e"];
1712
+ var MESH_COMMAND_STAGES = ["dev", "prod", "test", "test-e2e"];
1713
+
1714
+ // src/core/config/meshStageContract.ts
1715
+ var REMOVED_MESH_TEST_MESSAGE = "mesh.json.test is no longer supported. A mesh has no test topology. Put service-owned isolated test settings in build.json.test; put global E2E topology settings in mesh.json.e2e. The mesh test command runs independent service tests, then global E2E.";
1716
+ function assertNoLegacyMeshTest(input, sourceFile) {
1717
+ if (input !== null && typeof input === "object" && !Array.isArray(input) && Object.prototype.hasOwnProperty.call(input, "test")) {
1718
+ throw new ConfigError({
1719
+ sourceFile,
1720
+ configPath: "test",
1721
+ composition: "mesh",
1722
+ reason: REMOVED_MESH_TEST_MESSAGE
1723
+ });
1724
+ }
1725
+ }
1726
+ function assertMeshConfigStage(stage, sourceFile) {
1727
+ if (typeof stage !== "string" || !MESH_CONFIG_STAGES.includes(stage)) {
1728
+ throw new ConfigError({
1729
+ sourceFile,
1730
+ configPath: "<stage>",
1731
+ composition: "mesh",
1732
+ reason: "Unsupported mesh configuration stage. Supported stages: dev, prod, e2e. test is a pipeline command, not a mesh configuration stage."
1733
+ });
1734
+ }
1735
+ }
1736
+ function meshStageOverlayChain(stage) {
1737
+ return stage === "e2e" ? ["prod", "e2e"] : [stage];
1738
+ }
1608
1739
  var identifierSchema2 = z.string().regex(BUILDER_IDENTIFIER_PATTERN, "must match ^[a-z][a-z0-9-]*$");
1609
1740
  var serviceNameSchema = identifierSchema2.refine((name) => !RESERVED_MESH_SERVICE_NAMES.has(name), { message: "is reserved and cannot be used as a mesh service name" });
1610
1741
  var envSchema2 = z.record(z.string(), z.string());
@@ -1612,7 +1743,7 @@ var meshServiceSchema = z.object({ path: z.string().min(1), env: envSchema2.opti
1612
1743
  var meshServiceStageOverlaySchema = z.object({ path: z.string().min(1).optional(), env: envSchema2.optional(), dependencies: z.record(identifierSchema2, serviceNameSchema).optional(), dependsOn: z.array(serviceNameSchema).optional(), publish: z.array(z.string()).optional() }).strict();
1613
1744
  var meshStageSchema = z.object({ services: z.record(serviceNameSchema, meshServiceStageOverlaySchema).optional() }).strict();
1614
1745
  var rootServicesSchema = z.record(serviceNameSchema, meshServiceSchema).refine((services) => Object.keys(services).length >= 1, { message: "must contain at least one root service" });
1615
- var meshSchema = z.object({ $schema: z.string().optional(), name: z.string().optional(), tester: z.object({ compose: z.string().min(1), service: z.string().min(1), env: envSchema2.optional() }).strict().optional(), services: rootServicesSchema, dev: meshStageSchema.optional(), prod: meshStageSchema.optional(), test: meshStageSchema.optional(), e2e: meshStageSchema.optional() }).strict();
1746
+ var meshSchema = z.object({ $schema: z.string().optional(), name: z.string().optional(), tester: z.object({ compose: z.string().min(1), service: z.string().min(1), env: envSchema2.optional() }).strict().optional(), services: rootServicesSchema, dev: meshStageSchema.optional(), prod: meshStageSchema.optional(), e2e: meshStageSchema.optional() }).strict();
1616
1747
 
1617
1748
  // src/core/mesh/getMeshJson.ts
1618
1749
  function getMeshJson(projectDir = process.cwd()) {
@@ -1630,6 +1761,7 @@ function getMeshJson(projectDir = process.cwd()) {
1630
1761
  } catch (err) {
1631
1762
  throw new ScriptError(`Failed to parse mesh.json at ${meshPath}: ${errorMessage(err)}`);
1632
1763
  }
1764
+ assertNoLegacyMeshTest(parsed, meshPath);
1633
1765
  const result = meshSchema.safeParse(parsed);
1634
1766
  if (!result.success) {
1635
1767
  const reason = result.error.issues.map((issue) => `${issue.path.join(".") || "<root>"}: ${issue.message}`).join("; ");
@@ -1640,10 +1772,12 @@ function getMeshJson(projectDir = process.cwd()) {
1640
1772
 
1641
1773
  // src/core/config/resolveMeshStage.ts
1642
1774
  function resolveMeshStage(mesh, stage, sourceFile) {
1775
+ assertNoLegacyMeshTest(mesh, sourceFile);
1776
+ assertMeshConfigStage(stage, sourceFile);
1643
1777
  if (Object.keys(mesh.services).length === 0) throw new ConfigError({ sourceFile, configPath: "services", stage, composition: "mesh", reason: "mesh.json must declare at least one root service" });
1644
1778
  const services = {};
1645
1779
  for (const [name, service] of Object.entries(mesh.services)) services[name] = { path: service.path, env: { ...service.env ?? {} }, dependencies: { ...service.dependencies ?? {} }, dependsOn: [...service.dependsOn ?? []], publish: [...service.publish ?? []] };
1646
- for (const overlayStage of stageOverlayChain(stage)) for (const [name, patch] of Object.entries(mesh[overlayStage]?.services ?? {})) {
1780
+ for (const overlayStage of meshStageOverlayChain(stage)) for (const [name, patch] of Object.entries(mesh[overlayStage]?.services ?? {})) {
1647
1781
  const prior = services[name] ?? { path: void 0, env: {}, dependencies: {}, dependsOn: [], publish: [] };
1648
1782
  services[name] = { path: patch.path ?? prior.path, env: mergeStringMap(prior.env, patch.env), dependencies: { ...prior.dependencies, ...patch.dependencies ?? {} }, dependsOn: unionStable(prior.dependsOn, patch.dependsOn), publish: unionStable(prior.publish, patch.publish) };
1649
1783
  }
@@ -1660,12 +1794,8 @@ function resolveMeshStage(mesh, stage, sourceFile) {
1660
1794
  }
1661
1795
  }
1662
1796
  assertAcyclicGraph(graph, { sourceFile, stage, composition: "mesh" });
1663
- const result = { ...mesh, services };
1664
- delete result.dev;
1665
- delete result.prod;
1666
- delete result.test;
1667
- delete result.e2e;
1668
- return result;
1797
+ const { dev: _dev, prod: _prod, e2e: _e2e, ...base } = mesh;
1798
+ return { ...base, services };
1669
1799
  }
1670
1800
  function loadEffectiveMeshServices(meshDir, effectiveMesh, stage) {
1671
1801
  const out = {};
@@ -1804,16 +1934,6 @@ function applyMeshLifecycleEdges(services, edges) {
1804
1934
  consumer.depends_on = old;
1805
1935
  }
1806
1936
  }
1807
-
1808
- // src/core/composition/composeDependsOn.ts
1809
- function normalizeComposeDependsOn(value) {
1810
- if (Array.isArray(value)) {
1811
- return Object.fromEntries(value.filter((item) => typeof item === "string").map((name) => [name, {}]));
1812
- }
1813
- return value && typeof value === "object" ? { ...value } : {};
1814
- }
1815
-
1816
- // src/core/mesh/v2/compileMeshTester.ts
1817
1937
  function appendEnvFile(existing, next) {
1818
1938
  if (existing === void 0) return [next];
1819
1939
  return Array.isArray(existing) ? [...existing, next] : [existing, next];
@@ -1848,7 +1968,9 @@ function applyTesterBuildTarget(service) {
1848
1968
  if (service.build && typeof service.build === "object" && !Array.isArray(service.build)) service.build = { ...service.build, target: "test-e2e" };
1849
1969
  }
1850
1970
  function compileMeshTester(meshDir, tester, endpointRegistry, effectiveTopLevelApps, stage, referenceContext, nameAllocator = new GeneratedComposeNameAllocator(effectiveTopLevelApps)) {
1851
- const meshPath = path.join(meshDir, "mesh.json"), file = resolveInsideProject(meshDir, tester.compose, { sourceFile: meshPath, configPath: "tester.compose", stage }), raw = rebaseComposePaths(loadComposeDocument(file, { sourceFile: meshPath, configPath: "tester.compose", stage, composition: "mesh" }), file, meshDir);
1971
+ const meshPath = path.join(meshDir, "mesh.json"), file = resolveInsideProject(meshDir, tester.compose, { sourceFile: meshPath, configPath: "tester.compose", stage });
1972
+ const sourceDocument = loadComposeDocument(file, { sourceFile: meshPath, configPath: "tester.compose", stage, composition: "mesh" });
1973
+ const raw = rebaseComposePaths(sourceDocument, file, meshDir);
1852
1974
  if (!raw.services || !raw.services[tester.service]) throw new ConfigError({ sourceFile: meshPath, configPath: "tester.service", stage, composition: "mesh", value: tester.service, reason: "Selected tester service does not exist in tester Compose" });
1853
1975
  validateComposeResourceReferences(raw, { sourceFile: file, stage, composition: "mesh" });
1854
1976
  validateServiceReferences(raw, file, stage);
@@ -1865,6 +1987,8 @@ function compileMeshTester(meshDir, tester, endpointRegistry, effectiveTopLevelA
1865
1987
  if (selectedRaw.network_mode !== void 0 && selectedRaw.network_mode !== "host") throw new ConfigError({ sourceFile: file, configPath: `services.${tester.service}.network_mode`, stage, composition: "mesh", reason: "Selected tester runner must be compatible with host networking" });
1866
1988
  if (selectedRaw.networks !== void 0) throw new ConfigError({ sourceFile: file, configPath: `services.${tester.service}.networks`, stage, composition: "mesh", reason: "Selected host-network tester runner cannot declare Compose networks" });
1867
1989
  if (selectedRaw.ports !== void 0) throw new ConfigError({ sourceFile: file, configPath: `services.${tester.service}.ports`, stage, composition: "mesh", reason: "Selected host-network tester runner cannot define ports" });
1990
+ validateMaterializedComposeFiles(sourceDocument, file, stage, { composition: "mesh" });
1991
+ validateMaterializedComposeBuildInputs(sourceDocument, file, stage, "mesh");
1868
1992
  const meshCtx = referenceContext ?? { services: {}, bindings: /* @__PURE__ */ new Map(), endpoints: endpointRegistry, stage, meshJsonPath: meshPath };
1869
1993
  const testerBuilderKeys = [EXEC_MODE_KEY, INFRA_MODE_KEY], rawRunnerEnvironment = normalizeComposeEnvironment(selectedRaw.environment, "tester runner environment");
1870
1994
  assertNoBuilderOwnedEnvKeys(rawRunnerEnvironment, testerBuilderKeys, { sourceFile: file, configPath: `services.${tester.service}.environment`, stage, composition: "mesh" });
@@ -2130,113 +2254,33 @@ function compileMeshComposition(stage, meshDir, options = {}) {
2130
2254
  testerServiceName = built.runnerServiceName;
2131
2255
  }
2132
2256
  }
2257
+ enforceHealthyDependsOn(compose);
2133
2258
  nameAllocator.assertUnique();
2134
2259
  const yaml = stringify(compose);
2135
2260
  assertUniqueHostPortMappings(yaml);
2136
2261
  return { compose, effectiveMesh: effective, loadedServices: services, endpoints, projectName, ...testerServiceName ? { testerServiceName } : {} };
2137
2262
  }
2138
2263
 
2139
- // src/core/mesh/v2/validateMeshTestStage.ts
2140
- function validateMeshTestStage(services, meshDir, meshPath, validationMode = false) {
2141
- const bindings = bindingsMap(buildDependencyBindings(services, "test", meshPath));
2142
- const publication = resolveMeshPublication(
2143
- services,
2144
- bindings,
2145
- "test",
2146
- meshPath
2147
- );
2148
- for (const pub of publication) {
2149
- if (pub.target === "dependency") {
2150
- throw new ConfigError({
2151
- sourceFile: meshPath,
2152
- configPath: `services.${pub.ownerMeshService}.publish`,
2153
- stage: "test",
2154
- composition: "mesh",
2155
- value: pub.logicalPath,
2156
- reason: "mesh.test is isolated; dependency endpoints are not materialized and cannot be published"
2157
- });
2158
- }
2159
- }
2160
- const appPublications = publication.filter((pub) => pub.target === "app").sort(
2161
- (a, b) => a.ownerMeshService.localeCompare(b.ownerMeshService) || a.endpoint.localeCompare(b.endpoint)
2162
- ).map((pub) => {
2163
- const endpoint = services[pub.ownerMeshService].effectiveBuild.app.endpoints[pub.endpoint];
2164
- return {
2165
- meshService: pub.ownerMeshService,
2166
- endpoint: pub.endpoint,
2167
- logicalPath: pub.logicalPath,
2168
- containerPort: endpoint.port,
2169
- requested: endpoint.publicPort
2170
- };
2171
- });
2172
- const allocatedPorts = /* @__PURE__ */ new Map();
2173
- for (const name of Object.keys(services).sort((a, b) => a.localeCompare(b))) {
2174
- const intents = appPublications.filter((pub) => pub.meshService === name).map((pub) => ({
2175
- logicalPath: pub.logicalPath,
2176
- requested: pub.requested
2177
- }));
2178
- const ownPorts = allocateHostPorts(
2179
- meshDir,
2180
- "test",
2181
- intents,
2182
- validationMode,
2183
- { sourceFile: meshPath, composition: "mesh" }
2184
- );
2185
- for (const [logicalPath, port] of ownPorts) allocatedPorts.set(logicalPath, port);
2186
- }
2187
- return { bindings, appPublications, allocatedPorts };
2188
- }
2189
- function applyTestAppPublications(validated, meshService, app, endpointRegistry) {
2190
- for (const publication of validated.appPublications) {
2191
- if (publication.meshService !== meshService) continue;
2192
- const published = validated.allocatedPorts.get(publication.logicalPath);
2193
- const ports = Array.isArray(app.ports) ? app.ports : [];
2194
- ports.push({
2195
- target: publication.containerPort,
2196
- published,
2197
- host_ip: PUBLIC_HOST,
2198
- protocol: "tcp"
2199
- });
2200
- app.ports = ports;
2201
- const endpoint = endpointRegistry[publication.endpoint];
2202
- if (endpoint) {
2203
- endpoint.publicHost = PUBLIC_HOST;
2204
- endpoint.publicPort = published;
2205
- endpoint.effectivelyPublished = true;
2206
- }
2207
- }
2208
- }
2209
-
2210
2264
  // src/core/mesh/checkers/checkMeshServices.ts
2211
- function checkMeshServices(mesh, meshDir, options = {}) {
2212
- const root = resolveProjectDir(meshDir), meshPath = path.join(root, "mesh.json");
2265
+ function checkMeshServices(mesh, meshDir) {
2266
+ const root = resolveProjectDir(meshDir);
2267
+ const meshPath = path.join(root, "mesh.json");
2213
2268
  const checked = /* @__PURE__ */ new Set();
2214
- const stages = options.includeTestStage ? ["dev", "prod", "test", "e2e"] : ["dev", "prod", "e2e"];
2215
- for (const stage of stages) {
2269
+ for (const stage of MESH_CONFIG_STAGES) {
2216
2270
  const effective = resolveMeshStage(mesh, stage, meshPath);
2217
2271
  const services = loadEffectiveMeshServices(root, effective, stage);
2218
- const testValidation = stage === "test" ? validateMeshTestStage(services, root, meshPath, true) : void 0;
2219
2272
  for (const [name, svc] of Object.entries(services)) {
2220
2273
  if (!checked.has(svc.absolutePath)) {
2221
- console.log(pc14.cyan(`
2274
+ console.log(pc15.cyan(`
2222
2275
  \u{1F50D} Checking mesh service ${name}...`));
2223
2276
  checkInfra(svc.absolutePath);
2224
2277
  checked.add(svc.absolutePath);
2225
2278
  }
2226
- if (stage === "test") {
2227
- const fragment = compileServiceComposition("test", svc.absolutePath, { validationMode: true, meshMode: true, deferReferenceResolution: true });
2228
- applyTestAppPublications(testValidation, name, fragment.compose.services.app, fragment.endpoints.app);
2229
- const endpoints = { app: { [name]: fragment.endpoints.app }, dependencies: { [name]: fragment.endpoints.dependencies } };
2230
- const ctx = { services: { [name]: svc }, bindings: /* @__PURE__ */ new Map(), endpoints, stage: "test", meshJsonPath: meshPath };
2231
- for (const key of ["EXEC_MODE", "INFRA_MODE", ...Object.values(svc.effectiveBuild.app.endpoints).some((ep) => ep.primary) ? ["PORT"] : []]) {
2232
- if (key in svc.meshEnv) throw new ConfigError({ sourceFile: meshPath, configPath: `services.${name}.env.${key}`, stage: "test", composition: "mesh", reason: "Mesh service env cannot set Builder-owned environment" });
2233
- }
2234
- resolveMeshAppEnvironmentLayers(name, fragment.appEnvironmentLayers, ctx, new Set(Object.keys(svc.meshEnv)));
2235
- for (const [depName, depEnv] of Object.entries(fragment.dependencyEnvironments ?? {})) resolveServiceBuildEnvThroughMesh(name, depEnv, ctx, `services.${name}.dependencies.${depName}.env`);
2236
- resolveMeshEnvMap(svc.meshEnv, ctx, `services.${name}.env`);
2237
- }
2238
2279
  }
2239
- if (stage !== "test") compileMeshComposition(stage, root, { validationMode: true, allowMissingTester: true });
2280
+ compileMeshComposition(stage, root, {
2281
+ validationMode: true,
2282
+ allowMissingTester: true
2283
+ });
2240
2284
  }
2241
2285
  }
2242
2286
  function checkMeshTester(mesh, meshDir, options = {}) {
@@ -2254,13 +2298,11 @@ function checkMeshTester(mesh, meshDir, options = {}) {
2254
2298
  function checkMesh(meshDir = process.cwd(), options = {}) {
2255
2299
  const absMeshDir = resolveProjectDir(meshDir);
2256
2300
  const mesh = getMeshJson(absMeshDir);
2257
- checkMeshServices(mesh, absMeshDir, {
2258
- includeTestStage: Boolean(options.includeTestStage)
2259
- });
2301
+ checkMeshServices(mesh, absMeshDir);
2260
2302
  checkMeshTester(mesh, absMeshDir, { required: Boolean(options.requireTester) });
2261
2303
  console.log(
2262
- pc14.bold(
2263
- pc14.green("\n\u{1F389} All V2 mesh infrastructure, services, and contract checks passed!\n")
2304
+ pc15.bold(
2305
+ pc15.green("\n\u{1F389} All V2 mesh infrastructure, services, and contract checks passed!\n")
2264
2306
  )
2265
2307
  );
2266
2308
  }
@@ -2299,14 +2341,7 @@ Examples:
2299
2341
  }
2300
2342
  });
2301
2343
  };
2302
- function compileMeshEnvironment(stage, rawMeshDir = process.cwd(), options = {}) {
2303
- const meshDir = resolveProjectDir(rawMeshDir), compiled = compileMeshComposition(stage, meshDir), yaml = stringify(compiled.compose);
2304
- if (options.validateWithDocker !== false) {
2305
- const result = spawnSync("docker", ["compose", "--project-directory", meshDir, "-f", "-", "config", "--quiet"], { cwd: meshDir, encoding: "utf-8", input: yaml });
2306
- if (result.error || result.status !== 0) throw new ScriptError(`Generated mesh Compose configuration is invalid: ${result.error?.message ?? result.stderr ?? result.stdout}`, { cause: result.error });
2307
- }
2308
- return { yaml, ...compiled.testerServiceName ? { testerServiceName: compiled.testerServiceName } : {} };
2309
- }
2344
+ var compileEnvironment = (stage, projectDir = process.cwd(), options = {}) => stringify(compileServiceComposition(stage, projectDir, { full: Boolean(options.full), silenceWarnings: options.silenceWarnings }).compose);
2310
2345
  var activeComposeSet = /* @__PURE__ */ new Set();
2311
2346
  var signalHandlersRegistered = false;
2312
2347
  var activeChildProcess = null;
@@ -2585,59 +2620,126 @@ function projectNamesForServiceStage(projectDir, stage) {
2585
2620
  }
2586
2621
  function projectNamesForMeshStage(meshDir, stage) {
2587
2622
  const absDir = resolveProjectDir(meshDir);
2588
- let rawMeshName;
2589
- let serviceNames = [];
2623
+ let rawMeshName = path.basename(absDir);
2590
2624
  try {
2591
- const mesh = getMeshJson(absDir);
2592
- rawMeshName = mesh.name || path.basename(absDir);
2593
- serviceNames = Object.keys(resolveMeshStage(mesh, "test", path.join(absDir, "mesh.json")).services);
2625
+ rawMeshName = getMeshJson(absDir).name || rawMeshName;
2594
2626
  } catch {
2595
- rawMeshName = path.basename(absDir);
2596
2627
  }
2597
2628
  const s = stage.toLowerCase();
2598
- if (s === "dev") {
2599
- return [deriveProjectName(rawMeshName, "dev")];
2629
+ if (s === "test" || s === "test-e2e") {
2630
+ return [deriveProjectName(rawMeshName, "e2e")];
2600
2631
  }
2601
- if (s === "prod") {
2602
- return [deriveProjectName(rawMeshName, "prod")];
2632
+ return [deriveProjectName(rawMeshName, s)];
2633
+ }
2634
+
2635
+ // src/commands/service/commands/down/handler.ts
2636
+ async function handleServiceDown(rawStage = "dev", options = {}) {
2637
+ const projectDir = resolveProjectDir(options.projectDir);
2638
+ const stage = (rawStage || "dev").toLowerCase();
2639
+ const validStages = ["dev", "prod", "test", "test-unit", "test-e2e"];
2640
+ if (!validStages.includes(stage)) {
2641
+ throw new ScriptError(
2642
+ `Unknown environment stage: "${rawStage}". Supported stages: dev, prod, test, test-unit, test-e2e`
2643
+ );
2603
2644
  }
2604
- if (s === "test-e2e") {
2605
- return [deriveProjectName(rawMeshName, "e2e")];
2645
+ console.log(
2646
+ pc15.cyan(`
2647
+ \u{1F9F9} Stopping and tearing down service environment [${stage}]...`)
2648
+ );
2649
+ if (options.debug) {
2650
+ try {
2651
+ let env = "dev";
2652
+ if (stage === "prod") env = "prod";
2653
+ else if (stage === "test" || stage === "test-unit") env = "test";
2654
+ else if (stage === "test-e2e") env = "e2e";
2655
+ const finalYamlConfig = compileEnvironment(env, projectDir);
2656
+ console.log(
2657
+ pc15.yellow("Final merged YAML configuration:\n"),
2658
+ redactYamlSecrets(finalYamlConfig)
2659
+ );
2660
+ } catch {
2661
+ }
2606
2662
  }
2607
- if (s === "test-unit") {
2608
- return serviceNames.map((name) => `${deriveProjectName(rawMeshName, "dev")}-${name}-test`);
2663
+ const runState = readRunState(projectDir);
2664
+ const candidateProjects = projectNamesForServiceStage(projectDir, stage);
2665
+ if (runState?.projectName) {
2666
+ candidateProjects.unshift(runState.projectName);
2609
2667
  }
2610
- if (s === "test") {
2611
- return [...serviceNames.map((name) => `${deriveProjectName(rawMeshName, "dev")}-${name}-test`), deriveProjectName(rawMeshName, "e2e")];
2668
+ const uniqueProjects = Array.from(new Set(candidateProjects));
2669
+ for (const proj of uniqueProjects) {
2670
+ await teardownCompose("", projectDir, {
2671
+ projectName: proj,
2672
+ ...runState?.projectName === proj && runState.anonymousVolumeServices ? { anonymousVolumeServices: runState.anonymousVolumeServices } : {},
2673
+ removeVolumes: Boolean(options.volumes)
2674
+ });
2612
2675
  }
2613
- return [deriveProjectName(rawMeshName, s)];
2676
+ clearRunState(projectDir);
2677
+ console.log(
2678
+ pc15.green(`\u2705 Service environment [${stage}] stopped and removed.
2679
+ `)
2680
+ );
2681
+ return 0;
2682
+ }
2683
+ function compileMeshEnvironment(stage, rawMeshDir = process.cwd(), options = {}) {
2684
+ const meshDir = resolveProjectDir(rawMeshDir), compiled = compileMeshComposition(stage, meshDir), yaml = stringify(compiled.compose);
2685
+ if (options.validateWithDocker !== false) {
2686
+ const result = spawnSync("docker", ["compose", "--project-directory", meshDir, "-f", "-", "config", "--quiet"], { cwd: meshDir, encoding: "utf-8", input: yaml });
2687
+ if (result.error || result.status !== 0) throw new ScriptError(`Generated mesh Compose configuration is invalid: ${result.error?.message ?? result.stderr ?? result.stdout}`, { cause: result.error });
2688
+ }
2689
+ return { yaml, ...compiled.testerServiceName ? { testerServiceName: compiled.testerServiceName } : {} };
2614
2690
  }
2615
2691
 
2616
2692
  // src/commands/mesh/commands/down/handler.ts
2693
+ function rootServiceDirsForCleanup(meshDir) {
2694
+ try {
2695
+ const mesh = getMeshJson(meshDir);
2696
+ const dirs = Object.entries(mesh.services).sort(([a], [b]) => a.localeCompare(b)).map(([name, service]) => resolveInsideProject(meshDir, service.path, {
2697
+ sourceFile: path.join(meshDir, "mesh.json"),
2698
+ configPath: `services.${name}.path`
2699
+ }));
2700
+ return [...new Set(dirs)];
2701
+ } catch {
2702
+ return [];
2703
+ }
2704
+ }
2617
2705
  async function handleMeshDown(rawStage = "dev", options = {}) {
2618
2706
  const stage = (rawStage || "dev").toLowerCase();
2619
2707
  const meshDir = resolveProjectDir(options.projectDir);
2620
- const validStages = ["dev", "prod", "test", "test-unit", "test-e2e"];
2621
- if (!validStages.includes(stage)) {
2708
+ if (stage === "test-unit") {
2709
+ throw new ScriptError(
2710
+ "mesh down test-unit is no longer supported because meshes have no test topology. Use builder service down test-unit -C <service> for service recovery, or builder mesh down test for the complete test pipeline."
2711
+ );
2712
+ }
2713
+ if (!MESH_COMMAND_STAGES.includes(stage)) {
2622
2714
  throw new ScriptError(
2623
- `Unknown mesh stage: "${rawStage}". Supported stages: dev, prod, test, test-unit, test-e2e`
2715
+ `Unknown mesh stage: "${rawStage}". Supported stages: ${MESH_COMMAND_STAGES.join(", ")}`
2624
2716
  );
2625
2717
  }
2626
2718
  console.log(
2627
- pc14.cyan(`
2719
+ pc15.cyan(`
2628
2720
  \u{1F9F9} Stopping and tearing down global mesh environment [${stage}]...`)
2629
2721
  );
2630
2722
  if (options.debug) {
2631
2723
  try {
2632
- const mode = stage === "dev" ? "dev" : stage === "test-e2e" ? "e2e" : "prod";
2724
+ const mode = stage === "dev" ? "dev" : stage === "test" || stage === "test-e2e" ? "e2e" : "prod";
2633
2725
  const { yaml } = compileMeshEnvironment(mode, meshDir, { validateWithDocker: false });
2634
2726
  console.log(
2635
- pc14.yellow("\nFinal merged Mesh YAML configuration:\n"),
2727
+ pc15.yellow("\nFinal merged Mesh YAML configuration:\n"),
2636
2728
  redactYamlSecrets(yaml)
2637
2729
  );
2638
2730
  } catch {
2639
2731
  }
2640
2732
  }
2733
+ if (stage === "test") {
2734
+ for (const serviceDir of rootServiceDirsForCleanup(meshDir)) {
2735
+ const status = await handleServiceDown("test", {
2736
+ projectDir: serviceDir,
2737
+ volumes: Boolean(options.volumes),
2738
+ debug: Boolean(options.debug)
2739
+ });
2740
+ if (status !== 0) return status;
2741
+ }
2742
+ }
2641
2743
  const runState = readRunState(meshDir);
2642
2744
  const candidateProjects = projectNamesForMeshStage(meshDir, stage);
2643
2745
  if (runState?.projectName) {
@@ -2653,7 +2755,7 @@ async function handleMeshDown(rawStage = "dev", options = {}) {
2653
2755
  }
2654
2756
  clearRunState(meshDir);
2655
2757
  console.log(
2656
- pc14.green(`\u2705 Global mesh environment [${stage}] stopped and removed.
2758
+ pc15.green(`\u2705 Global mesh environment [${stage}] stopped and removed.
2657
2759
  `)
2658
2760
  );
2659
2761
  return 0;
@@ -2820,19 +2922,19 @@ async function runCompose(args, yamlConfig, projectDir, options = {}) {
2820
2922
  // src/core/mesh/runners/runMeshDev.ts
2821
2923
  async function runMeshDev(options = {}) {
2822
2924
  const meshDir = resolveProjectDir(options.projectDir);
2823
- console.log(pc14.cyan(`
2925
+ console.log(pc15.cyan(`
2824
2926
  \u{1F680} Starting Global DEV Mesh Environment...`));
2825
2927
  const { yaml } = compileMeshEnvironment("dev", meshDir);
2826
2928
  const parsed = parse(yaml);
2827
2929
  const projectName = parsed?.name || "mesh-dev";
2828
2930
  if (options.debug) {
2829
2931
  console.log(
2830
- pc14.yellow("\nFinal merged Mesh Dev YAML configuration:\n"),
2932
+ pc15.yellow("\nFinal merged Mesh Dev YAML configuration:\n"),
2831
2933
  redactYamlSecrets(yaml)
2832
2934
  );
2833
2935
  }
2834
2936
  if (options.dryRun) {
2835
- console.log(pc14.green("Dry run complete. Compose was not started."));
2937
+ console.log(pc15.green("Dry run complete. Compose was not started."));
2836
2938
  return 0;
2837
2939
  }
2838
2940
  const hostPorts = extractHostPorts(yaml);
@@ -2862,19 +2964,19 @@ async function runMeshDev(options = {}) {
2862
2964
  }
2863
2965
  async function runMeshProd(options = {}) {
2864
2966
  const meshDir = resolveProjectDir(options.projectDir);
2865
- console.log(pc14.cyan(`
2967
+ console.log(pc15.cyan(`
2866
2968
  \u{1F3ED} Starting Global PROD Mesh Environment...`));
2867
2969
  const { yaml } = compileMeshEnvironment("prod", meshDir);
2868
2970
  const parsed = parse(yaml);
2869
2971
  const projectName = parsed?.name || "mesh-prod";
2870
2972
  if (options.debug) {
2871
2973
  console.log(
2872
- pc14.yellow("\nFinal merged Mesh Prod YAML configuration:\n"),
2974
+ pc15.yellow("\nFinal merged Mesh Prod YAML configuration:\n"),
2873
2975
  redactYamlSecrets(yaml)
2874
2976
  );
2875
2977
  }
2876
2978
  if (options.dryRun) {
2877
- console.log(pc14.green("Dry run complete. Compose was not started."));
2979
+ console.log(pc15.green("Dry run complete. Compose was not started."));
2878
2980
  return 0;
2879
2981
  }
2880
2982
  const hostPorts = extractHostPorts(yaml);
@@ -2902,15 +3004,12 @@ async function runMeshProd(options = {}) {
2902
3004
  );
2903
3005
  return status;
2904
3006
  }
2905
- var compileEnvironment = (stage, projectDir = process.cwd(), options = {}) => stringify(compileServiceComposition(stage, projectDir, { full: Boolean(options.full), silenceWarnings: options.silenceWarnings }).compose);
2906
-
2907
- // src/core/runners/runTestUnit.ts
2908
3007
  var runTestUnit = async (options) => {
2909
3008
  if (!options.skipBanner) {
2910
- console.log(pc14.bold(pc14.blue(`
3009
+ console.log(pc15.bold(pc15.blue(`
2911
3010
  ========================================`)));
2912
- console.log(pc14.bold(pc14.blue(`\u{1F9EA} STAGE: UNIT & ISOLATED TESTS`)));
2913
- console.log(pc14.bold(pc14.blue(`========================================
3011
+ console.log(pc15.bold(pc15.blue(`\u{1F9EA} STAGE: UNIT & ISOLATED TESTS`)));
3012
+ console.log(pc15.bold(pc15.blue(`========================================
2914
3013
  `)));
2915
3014
  }
2916
3015
  const finalYamlConfig = compileEnvironment("test", options.projectDir, {
@@ -2920,12 +3019,12 @@ var runTestUnit = async (options) => {
2920
3019
  const projectName = parsed?.name || "test";
2921
3020
  if (options.debug) {
2922
3021
  console.log(
2923
- pc14.yellow("Final merged YAML configuration:\n"),
3022
+ pc15.yellow("Final merged YAML configuration:\n"),
2924
3023
  redactYamlSecrets(finalYamlConfig)
2925
3024
  );
2926
3025
  }
2927
3026
  if (options.dryRun) {
2928
- console.log(pc14.green("[DRY-RUN] Unit tests simulated. Compose was not started."));
3027
+ console.log(pc15.green("[DRY-RUN] Unit tests simulated. Compose was not started."));
2929
3028
  return 0;
2930
3029
  }
2931
3030
  await checkHostPortCollisions(extractHostPorts(finalYamlConfig));
@@ -2951,22 +3050,45 @@ var runTestUnit = async (options) => {
2951
3050
  }
2952
3051
  );
2953
3052
  if (status === 0) {
2954
- console.log(pc14.bold(pc14.green(`
3053
+ console.log(pc15.bold(pc15.green(`
2955
3054
  \u2705 Unit tests passed successfully.
2956
3055
  `)));
2957
3056
  } else {
2958
- console.error(pc14.red(`
3057
+ console.error(pc15.red(`
2959
3058
  \u274C Unit tests failed with exit code ${status}.
2960
3059
  `));
2961
3060
  }
2962
3061
  return status;
2963
3062
  };
3063
+
3064
+ // src/core/runners/runFiniteTester.ts
3065
+ async function runFiniteTester(yaml, projectDir, testerServiceName) {
3066
+ const startStatus = await runCompose(
3067
+ ["up", "--build", "--detach"],
3068
+ yaml,
3069
+ projectDir,
3070
+ { removeVolumes: true }
3071
+ );
3072
+ if (startStatus !== 0) return startStatus;
3073
+ const testerStatus = await runCompose(
3074
+ ["wait", testerServiceName],
3075
+ yaml,
3076
+ projectDir,
3077
+ { removeVolumes: true }
3078
+ );
3079
+ await runCompose(["logs", "--no-color"], yaml, projectDir, {
3080
+ removeVolumes: true
3081
+ });
3082
+ return testerStatus;
3083
+ }
3084
+
3085
+ // src/core/runners/runTestE2e.ts
2964
3086
  var runTestE2e = async (options) => {
2965
3087
  if (!options.skipBanner) {
2966
- console.log(pc14.bold(pc14.blue(`
3088
+ console.log(pc15.bold(pc15.blue(`
2967
3089
  ========================================`)));
2968
- console.log(pc14.bold(pc14.blue(`\u{1F6A6} STAGE: INTEGRATED E2E TESTS`)));
2969
- console.log(pc14.bold(pc14.blue(`========================================
3090
+ console.log(pc15.bold(pc15.blue(`\u{1F6A6} STAGE: INTEGRATED E2E TESTS`)));
3091
+ console.log(pc15.bold(pc15.blue(`========================================
2970
3092
  `)));
2971
3093
  }
2972
3094
  const finalYamlConfig = compileEnvironment("e2e", options.projectDir, {
@@ -2976,12 +3098,12 @@ var runTestE2e = async (options) => {
2976
3098
  const projectName = parsed?.name || "e2e";
2977
3099
  if (options.debug) {
2978
3100
  console.log(
2979
- pc14.yellow("Final merged YAML configuration:\n"),
3101
+ pc15.yellow("Final merged YAML configuration:\n"),
2980
3102
  redactYamlSecrets(finalYamlConfig)
2981
3103
  );
2982
3104
  }
2983
3105
  if (options.dryRun) {
2984
- console.log(pc14.green("[DRY-RUN] E2E tests simulated. Compose was not started."));
3106
+ console.log(pc15.green("[DRY-RUN] E2E tests simulated. Compose was not started."));
2985
3107
  return 0;
2986
3108
  }
2987
3109
  await checkHostPortCollisions(extractHostPorts(finalYamlConfig));
@@ -2995,29 +3117,18 @@ var runTestE2e = async (options) => {
2995
3117
  projectDir: options.projectDir
2996
3118
  });
2997
3119
  const status = await runWithCleanup(
2998
- () => runCompose(
2999
- [
3000
- "up",
3001
- "--build",
3002
- "--abort-on-container-exit",
3003
- "--exit-code-from",
3004
- "tester"
3005
- ],
3006
- finalYamlConfig,
3007
- options.projectDir,
3008
- { removeVolumes: true }
3009
- ),
3120
+ () => runFiniteTester(finalYamlConfig, options.projectDir, "tester"),
3010
3121
  async () => {
3011
3122
  await teardownCompose(finalYamlConfig, options.projectDir, { removeVolumes: true });
3012
3123
  clearRunState(options.projectDir);
3013
3124
  }
3014
3125
  );
3015
3126
  if (status === 0) {
3016
- console.log(pc14.bold(pc14.green(`
3127
+ console.log(pc15.bold(pc15.green(`
3017
3128
  \u2705 E2E tests passed successfully.
3018
3129
  `)));
3019
3130
  } else {
3020
- console.error(pc14.red(`
3131
+ console.error(pc15.red(`
3021
3132
  \u274C E2E tests failed with exit code ${status}.
3022
3133
  `));
3023
3134
  }
@@ -3026,15 +3137,15 @@ var runTestE2e = async (options) => {
3026
3137
 
3027
3138
  // src/core/runners/runTest.ts
3028
3139
  var runTest = async (options) => {
3029
- console.log(pc14.bold(pc14.blue(`
3140
+ console.log(pc15.bold(pc15.blue(`
3030
3141
  ========================================`)));
3031
- console.log(pc14.bold(pc14.blue(`\u{1F9EA} [1/2] STAGE: UNIT & ISOLATED TESTS`)));
3032
- console.log(pc14.bold(pc14.blue(`========================================
3142
+ console.log(pc15.bold(pc15.blue(`\u{1F9EA} [1/2] STAGE: UNIT & ISOLATED TESTS`)));
3143
+ console.log(pc15.bold(pc15.blue(`========================================
3033
3144
  `)));
3034
3145
  const unitStatus = await runTestUnit({ ...options, skipBanner: true });
3035
3146
  if (unitStatus !== 0) {
3036
3147
  console.error(
3037
- pc14.red(
3148
+ pc15.red(
3038
3149
  `
3039
3150
  \u274C [1/2] Unit tests failed with exit code ${unitStatus}. Aborting E2E tests.
3040
3151
  `
@@ -3043,29 +3154,29 @@ var runTest = async (options) => {
3043
3154
  return unitStatus;
3044
3155
  }
3045
3156
  console.log(
3046
- pc14.bold(pc14.green(`
3157
+ pc15.bold(pc15.green(`
3047
3158
  \u2705 [1/2] Unit tests passed successfully.
3048
3159
  `))
3049
3160
  );
3050
- console.log(pc14.bold(pc14.blue(`========================================`)));
3051
- console.log(pc14.bold(pc14.blue(`\u{1F6A6} [2/2] STAGE: INTEGRATED E2E TESTS`)));
3052
- console.log(pc14.bold(pc14.blue(`========================================
3161
+ console.log(pc15.bold(pc15.blue(`========================================`)));
3162
+ console.log(pc15.bold(pc15.blue(`\u{1F6A6} [2/2] STAGE: INTEGRATED E2E TESTS`)));
3163
+ console.log(pc15.bold(pc15.blue(`========================================
3053
3164
  `)));
3054
3165
  const e2eStatus = await runTestE2e({ ...options, skipBanner: true });
3055
3166
  if (e2eStatus !== 0) {
3056
3167
  console.error(
3057
- pc14.red(`
3168
+ pc15.red(`
3058
3169
  \u274C [2/2] E2E tests failed with exit code ${e2eStatus}.
3059
3170
  `)
3060
3171
  );
3061
3172
  return e2eStatus;
3062
3173
  }
3063
- console.log(pc14.bold(pc14.green(`
3174
+ console.log(pc15.bold(pc15.green(`
3064
3175
  \u2705 [2/2] E2E tests passed successfully.
3065
3176
  `)));
3066
3177
  console.log(
3067
- pc14.bold(
3068
- pc14.green(`\u{1F389} All test stages (unit + e2e) completed successfully!
3178
+ pc15.bold(
3179
+ pc15.green(`\u{1F389} All test stages (unit + e2e) completed successfully!
3069
3180
  `)
3070
3181
  )
3071
3182
  );
@@ -3078,7 +3189,7 @@ async function runMeshServiceTests(options = {}) {
3078
3189
  const rootServices = Object.entries(mesh.services).sort(([left], [right]) => left.localeCompare(right));
3079
3190
  for (const [serviceName, service] of rootServices) {
3080
3191
  const serviceDir = resolveInsideProject(meshDir, service.path, { sourceFile: meshPath, configPath: `services.${serviceName}.path`, stage: "test" });
3081
- console.log(pc14.bold(pc14.cyan(`
3192
+ console.log(pc15.bold(pc15.cyan(`
3082
3193
  -> Running full standalone test lifecycle for [${serviceName}]
3083
3194
  `)));
3084
3195
  const status = await runTest({ projectDir: serviceDir, debug: Boolean(options.debug), detach: false, skipBanner: true, silenceWarnings: false, ...options.dryRun !== void 0 ? { dryRun: options.dryRun } : {} });
@@ -3091,16 +3202,16 @@ async function runMeshTestE2e(options = {}) {
3091
3202
  if (!mesh.tester) throw new ScriptError("Global mesh E2E requires root mesh.json.tester { compose, service, env? }");
3092
3203
  const { yaml, testerServiceName } = compileMeshEnvironment("e2e", meshDir);
3093
3204
  if (!testerServiceName) throw new ScriptError("Global mesh E2E tester runner could not be compiled.");
3094
- if (options.debug) console.log(pc14.yellow("\nFinal global mesh E2E YAML configuration:\n"), redactYamlSecrets(yaml));
3205
+ if (options.debug) console.log(pc15.yellow("\nFinal global mesh E2E YAML configuration:\n"), redactYamlSecrets(yaml));
3095
3206
  if (options.dryRun) {
3096
- console.log(pc14.green("[DRY-RUN] Global mesh E2E compiled; Compose was not started."));
3207
+ console.log(pc15.green("[DRY-RUN] Global mesh E2E compiled; Compose was not started."));
3097
3208
  return 0;
3098
3209
  }
3099
3210
  await checkHostPortCollisions(extractHostPorts(yaml));
3100
3211
  const projectName = parse(yaml)?.name || "mesh-e2e";
3101
3212
  await teardownCompose(yaml, meshDir, { removeVolumes: true, silent: true });
3102
3213
  writeRunState(meshDir, { projectName, stage: "test-e2e", projectDir: meshDir });
3103
- const status = await runWithCleanup(() => runCompose(["up", "--build", "--abort-on-container-exit", "--exit-code-from", testerServiceName], yaml, meshDir, { removeVolumes: true }), async () => {
3214
+ const status = await runWithCleanup(() => runFiniteTester(yaml, meshDir, testerServiceName), async () => {
3104
3215
  await teardownCompose(yaml, meshDir, { removeVolumes: true });
3105
3216
  clearRunState(meshDir);
3106
3217
  });
@@ -3109,84 +3220,52 @@ async function runMeshTestE2e(options = {}) {
3109
3220
 
3110
3221
  // src/core/mesh/runners/runMeshTest.ts
3111
3222
  async function runMeshTest(options = {}) {
3112
- console.log(pc14.bold(pc14.blue("\n========================================\nMESH TEST PIPELINE\n========================================\n")));
3113
- console.log(pc14.bold(pc14.blue("[1/2] ROOT SERVICE TEST LIFECYCLES")));
3223
+ console.log(pc15.bold(pc15.blue("\n========================================\nMESH TEST PIPELINE\n========================================\n")));
3224
+ console.log(pc15.bold(pc15.blue("[1/2] ROOT SERVICE TEST LIFECYCLES")));
3114
3225
  const serviceStatus = await runMeshServiceTests(options);
3115
3226
  if (serviceStatus !== 0) return serviceStatus;
3116
- console.log(pc14.bold(pc14.blue("[2/2] GLOBAL MESH E2E")));
3227
+ console.log(pc15.bold(pc15.blue("[2/2] GLOBAL MESH E2E")));
3117
3228
  return runMeshTestE2e(options);
3118
3229
  }
3119
- async function runMeshTestUnit(options = {}) {
3120
- const meshDir = resolveProjectDir(options.projectDir), meshPath = path.join(meshDir, "mesh.json"), raw = getMeshJson(meshDir), effective = resolveMeshStage(raw, "test", meshPath), services = loadEffectiveMeshServices(meshDir, effective, "test"), validated = validateMeshTestStage(services, meshDir, meshPath, Boolean(options.dryRun));
3121
- console.log(pc14.bold(pc14.blue("\nEXPLICIT MESH TEST-STAGE (UNIT/ISOLATED)\n")));
3122
- for (const [name, svc] of Object.entries(services).sort(([a], [b]) => a.localeCompare(b))) {
3123
- console.log(pc14.cyan(`-> Running isolated unit tests for [${name}]`));
3124
- const compiled = compileServiceComposition("test", svc.absolutePath, { meshMode: true, full: false, externalAppEnv: {}, deferReferenceResolution: true, appServiceName: "app" });
3125
- const app = compiled.compose.services.app;
3126
- applyTestAppPublications(validated, name, app, compiled.endpoints.app);
3127
- const endpoints = { app: { [name]: compiled.endpoints.app }, dependencies: { [name]: compiled.endpoints.dependencies } };
3128
- const refCtx = { services: { [name]: svc }, bindings: /* @__PURE__ */ new Map(), endpoints, stage: "test", meshJsonPath: meshPath };
3129
- const env = svc.meshEnv;
3130
- for (const key of ["EXEC_MODE", "INFRA_MODE", ...Object.keys(svc.effectiveBuild.app.endpoints).some((k) => svc.effectiveBuild.app.endpoints[k]?.primary) ? ["PORT"] : []]) if (key in env) throw new ConfigError({ sourceFile: meshPath, configPath: `services.${name}.env.${key}`, stage: "test", composition: "mesh", reason: "Mesh service env cannot set Builder-owned environment" });
3131
- const resolvedBuild = resolveMeshAppEnvironmentLayers(name, compiled.appEnvironmentLayers, refCtx, new Set(Object.keys(svc.meshEnv)));
3132
- for (const [depName, depEnv] of Object.entries(compiled.dependencyEnvironments ?? {})) resolveServiceBuildEnvThroughMesh(name, depEnv, refCtx, `services.${name}.dependencies.${depName}.env`);
3133
- const resolved = resolveMeshEnvMap(env, refCtx, `services.${name}.env`);
3134
- app.environment = { ...resolvedBuild, ...resolved, ...compiled.builderInternalEnvironment ?? {} };
3135
- const projectName = `${deriveProjectName(raw.name ?? path.basename(meshDir), "dev")}-${name}-test`;
3136
- compiled.compose.name = projectName;
3137
- const yaml = stringify(compiled.compose);
3138
- if (options.debug) console.log(redactYamlSecrets(yaml));
3139
- if (options.dryRun) {
3140
- console.log(pc14.green(`[DRY-RUN] Unit tests for ${name} compiled.`));
3141
- continue;
3142
- }
3143
- await teardownCompose(yaml, svc.absolutePath, { removeVolumes: true, silent: true });
3144
- writeRunState(svc.absolutePath, { projectName, stage: "test-unit", projectDir: svc.absolutePath });
3145
- const status = await runWithCleanup(() => runCompose(["up", "--build", "--abort-on-container-exit", "--exit-code-from", "app"], yaml, svc.absolutePath, { removeVolumes: true }), async () => {
3146
- await teardownCompose(yaml, svc.absolutePath, { removeVolumes: true });
3147
- clearRunState(svc.absolutePath);
3148
- });
3149
- if (status !== 0) return status;
3150
- }
3151
- return 0;
3152
- }
3153
3230
 
3154
3231
  // src/commands/mesh/commands/up/handler.ts
3155
3232
  async function handleMeshUp(rawStage = "dev", options = {}) {
3156
3233
  const stage = (rawStage || "dev").toLowerCase();
3234
+ if (stage === "test-unit") {
3235
+ throw new ScriptError(
3236
+ "mesh up test-unit is no longer supported because meshes have no test topology. Use builder service up test-unit -C <service> for isolated tests, or builder mesh up test for the complete test pipeline."
3237
+ );
3238
+ }
3239
+ if (!MESH_COMMAND_STAGES.includes(stage)) {
3240
+ throw new ScriptError(
3241
+ `Unknown mesh stage: "${rawStage}". Supported stages: ${MESH_COMMAND_STAGES.join(", ")}`
3242
+ );
3243
+ }
3157
3244
  const projectDir = resolveProjectDir(options.projectDir);
3158
- const runOptions = {
3159
- ...options,
3160
- projectDir
3161
- };
3162
- if (["dev", "prod", "test-unit", "test-e2e", "test"].includes(stage) && !options.skipChecks) {
3245
+ const runOptions = { ...options, projectDir };
3246
+ if (!options.skipChecks) {
3163
3247
  checkMesh(projectDir, {
3164
- requireTester: stage === "test-e2e" || stage === "test",
3165
- includeTestStage: stage === "test-unit"
3248
+ requireTester: stage === "test" || stage === "test-e2e"
3166
3249
  });
3167
3250
  }
3168
3251
  switch (stage) {
3169
3252
  case "dev":
3170
- return await runMeshDev(runOptions);
3253
+ return runMeshDev(runOptions);
3171
3254
  case "prod":
3172
- return await runMeshProd(runOptions);
3173
- case "test-unit":
3174
- return await runMeshTestUnit(runOptions);
3175
- case "test-e2e":
3176
- return await runMeshTestE2e(runOptions);
3255
+ return runMeshProd(runOptions);
3177
3256
  case "test":
3178
- return await runMeshTest(runOptions);
3257
+ return runMeshTest(runOptions);
3258
+ case "test-e2e":
3259
+ return runMeshTestE2e(runOptions);
3179
3260
  default:
3180
- throw new ScriptError(
3181
- `Unknown mesh stage: "${rawStage}". Supported stages: dev, prod, test, test-unit, test-e2e`
3182
- );
3261
+ throw new ScriptError(`Unsupported mesh command: ${stage}`);
3183
3262
  }
3184
3263
  }
3185
3264
 
3186
3265
  // src/commands/mesh/commands/up/command.ts
3187
3266
  var registerMeshUpCommand = (cmd) => {
3188
3267
  cmd.command("up [stage]").description(
3189
- "Start, build, or test the mesh environment (dev, prod, test, test-unit, test-e2e)"
3268
+ "Start, build, or test the mesh environment (dev, prod, test, test-e2e)"
3190
3269
  ).option("--debug", "Output the merged Docker Compose YAML configuration").option("-d, --detach", "Run containers in the background").option(
3191
3270
  "--dry-run",
3192
3271
  "Compile configuration and validate checks without starting containers"
@@ -3206,12 +3285,11 @@ Examples:
3206
3285
  $ builder mesh up dev
3207
3286
  $ builder mesh up prod
3208
3287
  $ builder mesh up test
3209
- $ builder mesh up test-unit
3210
3288
  $ builder mesh up test-e2e
3211
3289
 
3212
- JSON overlays: test-unit uses mesh/build test; test-e2e uses mesh/build e2e.
3290
+ Mesh JSON overlays: dev, prod, e2e. test-e2e uses base -> prod -> e2e.
3213
3291
  The test command runs each root service test lifecycle (unit, then service E2E) before global E2E.
3214
- The explicit test-unit stage exercises mesh.json.test overlays only.`
3292
+ For a service\u2019s isolated tests: builder service up test-unit -C <service>.`
3215
3293
  ).action(
3216
3294
  async (stage = "dev", options = {}) => {
3217
3295
  const exitCode = await handleMeshUp(stage, {
@@ -3239,7 +3317,7 @@ var registerMeshCommand = (program) => {
3239
3317
  registerMeshCheckCommand(meshCmd);
3240
3318
  };
3241
3319
  async function handlePrune(options = {}) {
3242
- console.log(pc14.cyan("\n\u{1F9F9} Pruning stopped Compose containers and unused networks..."));
3320
+ console.log(pc15.cyan("\n\u{1F9F9} Pruning stopped Compose containers and unused networks..."));
3243
3321
  const rmContainers = spawnSync("docker", ["container", "prune", "-f"], {
3244
3322
  stdio: "inherit",
3245
3323
  encoding: "utf-8"
@@ -3259,13 +3337,13 @@ async function handlePrune(options = {}) {
3259
3337
  });
3260
3338
  }
3261
3339
  if (options.volumes) {
3262
- console.log(pc14.cyan("\u{1F9F9} Pruning dangling volumes..."));
3340
+ console.log(pc15.cyan("\u{1F9F9} Pruning dangling volumes..."));
3263
3341
  spawnSync("docker", ["volume", "prune", "-f"], {
3264
3342
  stdio: "inherit",
3265
3343
  encoding: "utf-8"
3266
3344
  });
3267
3345
  }
3268
- console.log(pc14.green("\u2705 Docker environment pruned successfully.\n"));
3346
+ console.log(pc15.green("\u2705 Docker environment pruned successfully.\n"));
3269
3347
  return 0;
3270
3348
  }
3271
3349
 
@@ -3283,53 +3361,6 @@ var registerPruneCommand = (cmd) => {
3283
3361
 
3284
3362
  // src/types/index.ts
3285
3363
  var SERVICE_STAGES = ["dev", "prod", "test", "test-unit", "test-e2e"];
3286
- async function handleServiceDown(rawStage = "dev", options = {}) {
3287
- const projectDir = resolveProjectDir(options.projectDir);
3288
- const stage = (rawStage || "dev").toLowerCase();
3289
- const validStages = ["dev", "prod", "test", "test-unit", "test-e2e"];
3290
- if (!validStages.includes(stage)) {
3291
- throw new ScriptError(
3292
- `Unknown environment stage: "${rawStage}". Supported stages: dev, prod, test, test-unit, test-e2e`
3293
- );
3294
- }
3295
- console.log(
3296
- pc14.cyan(`
3297
- \u{1F9F9} Stopping and tearing down service environment [${stage}]...`)
3298
- );
3299
- if (options.debug) {
3300
- try {
3301
- let env = "dev";
3302
- if (stage === "prod") env = "prod";
3303
- else if (stage === "test" || stage === "test-unit") env = "test";
3304
- else if (stage === "test-e2e") env = "e2e";
3305
- const finalYamlConfig = compileEnvironment(env, projectDir);
3306
- console.log(
3307
- pc14.yellow("Final merged YAML configuration:\n"),
3308
- redactYamlSecrets(finalYamlConfig)
3309
- );
3310
- } catch {
3311
- }
3312
- }
3313
- const runState = readRunState(projectDir);
3314
- const candidateProjects = projectNamesForServiceStage(projectDir, stage);
3315
- if (runState?.projectName) {
3316
- candidateProjects.unshift(runState.projectName);
3317
- }
3318
- const uniqueProjects = Array.from(new Set(candidateProjects));
3319
- for (const proj of uniqueProjects) {
3320
- await teardownCompose("", projectDir, {
3321
- projectName: proj,
3322
- ...runState?.projectName === proj && runState.anonymousVolumeServices ? { anonymousVolumeServices: runState.anonymousVolumeServices } : {},
3323
- removeVolumes: Boolean(options.volumes)
3324
- });
3325
- }
3326
- clearRunState(projectDir);
3327
- console.log(
3328
- pc14.green(`\u2705 Service environment [${stage}] stopped and removed.
3329
- `)
3330
- );
3331
- return 0;
3332
- }
3333
3364
 
3334
3365
  // src/commands/service/commands/down/command.ts
3335
3366
  var registerDownCommand = (cmd) => {
@@ -3364,7 +3395,7 @@ Examples:
3364
3395
  };
3365
3396
  var runDev = async (options) => {
3366
3397
  console.log(
3367
- pc14.cyan(
3398
+ pc15.cyan(
3368
3399
  options.full ? `\u{1F680} Starting DEV environment (full / integrated)...` : `\u{1F680} Starting DEV environment...`
3369
3400
  )
3370
3401
  );
@@ -3376,12 +3407,12 @@ var runDev = async (options) => {
3376
3407
  const projectName = parsed?.name || "dev";
3377
3408
  if (options.debug) {
3378
3409
  console.log(
3379
- pc14.yellow("Final merged YAML configuration:\n"),
3410
+ pc15.yellow("Final merged YAML configuration:\n"),
3380
3411
  redactYamlSecrets(finalYamlConfig)
3381
3412
  );
3382
3413
  }
3383
3414
  if (options.dryRun) {
3384
- console.log(pc14.green("Dry run complete. Compose was not started."));
3415
+ console.log(pc15.green("Dry run complete. Compose was not started."));
3385
3416
  return 0;
3386
3417
  }
3387
3418
  const hostPorts = extractHostPorts(finalYamlConfig);
@@ -3412,7 +3443,7 @@ var runDev = async (options) => {
3412
3443
  return status;
3413
3444
  };
3414
3445
  var runProd = async (options) => {
3415
- console.log(pc14.cyan(`\u{1F3ED} Starting PROD environment...`));
3446
+ console.log(pc15.cyan(`\u{1F3ED} Starting PROD environment...`));
3416
3447
  const finalYamlConfig = compileEnvironment("prod", options.projectDir, {
3417
3448
  silenceWarnings: options.silenceWarnings
3418
3449
  });
@@ -3420,12 +3451,12 @@ var runProd = async (options) => {
3420
3451
  const projectName = parsed?.name || "prod";
3421
3452
  if (options.debug) {
3422
3453
  console.log(
3423
- pc14.yellow("Final merged YAML configuration:\n"),
3454
+ pc15.yellow("Final merged YAML configuration:\n"),
3424
3455
  redactYamlSecrets(finalYamlConfig)
3425
3456
  );
3426
3457
  }
3427
3458
  if (options.dryRun) {
3428
- console.log(pc14.green("Dry run complete. Compose was not started."));
3459
+ console.log(pc15.green("Dry run complete. Compose was not started."));
3429
3460
  return 0;
3430
3461
  }
3431
3462
  const hostPorts = extractHostPorts(finalYamlConfig);
@@ -3636,7 +3667,7 @@ async function handleExportEnv(rawStage, options = {}) {
3636
3667
  throw error;
3637
3668
  }
3638
3669
  files.push(filename);
3639
- console.log(pc14.green(`Exported ${snapshot.stage} application environment to ${filename}`));
3670
+ console.log(pc15.green(`Exported ${snapshot.stage} application environment to ${filename}`));
3640
3671
  break;
3641
3672
  }
3642
3673
  }
@@ -3712,10 +3743,10 @@ async function runCli(argv = process.argv) {
3712
3743
  (arg) => arg === "-h" || arg === "--help" || arg === "-V" || arg === "--version"
3713
3744
  );
3714
3745
  if (!isHelpOrVersion && argv.length > 2) {
3715
- console.log(pc14.dim(`builder v${version}`));
3746
+ console.log(pc15.dim(`builder v${version}`));
3716
3747
  }
3717
3748
  if (argv.length <= 2) {
3718
- console.log(pc14.dim(`builder v${version}
3749
+ console.log(pc15.dim(`builder v${version}
3719
3750
  `));
3720
3751
  cli.outputHelp();
3721
3752
  return;
@@ -3738,20 +3769,20 @@ async function runCli(argv = process.argv) {
3738
3769
  if (err instanceof ScriptError) {
3739
3770
  exitCode = err.exitCode;
3740
3771
  const formatted = err.message.startsWith("\u274C") ? err.message : `\u274C ${err.message}`;
3741
- console.error(pc14.red(`
3772
+ console.error(pc15.red(`
3742
3773
  ${formatted}
3743
3774
  `));
3744
3775
  if (isVerbose && err.stack) {
3745
- console.error(pc14.dim(err.stack));
3776
+ console.error(pc15.dim(err.stack));
3746
3777
  }
3747
3778
  } else {
3748
3779
  const message = errorMessage(err);
3749
3780
  const formatted = message.startsWith("\u274C") ? message : `\u274C Error: ${message}`;
3750
- console.error(pc14.red(`
3781
+ console.error(pc15.red(`
3751
3782
  ${formatted}
3752
3783
  `));
3753
3784
  if (isVerbose && err instanceof Error && err.stack) {
3754
- console.error(pc14.dim(err.stack));
3785
+ console.error(pc15.dim(err.stack));
3755
3786
  }
3756
3787
  }
3757
3788
  if (process.env.VITEST) {