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