feat(lanes): add --qc boot flag + QC_BOOT_ENV for deterministic QC stacks (E1)
This commit is contained in:
@@ -71,6 +71,11 @@ const DEFAULTS = Object.freeze({
|
||||
ENV_REWRITE: "",
|
||||
ENV_PRESERVE: "",
|
||||
UPLOAD_SUBDIR: "",
|
||||
// E1: space-separated KEY=value pairs injected into the BOOT hook's
|
||||
// environment only, only when `up` is called with qc:true — the deterministic
|
||||
// stack `ship-feature-lane`'s Stage 3 boots for QC. Empty = off, same as
|
||||
// every declaration above.
|
||||
QC_BOOT_ENV: "",
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -110,6 +115,25 @@ function splitList(value) {
|
||||
return [...new Set((value || "").split(/\s+/).filter(Boolean))];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a `QC_BOOT_ENV` declaration — space-separated `KEY=value` pairs — into
|
||||
* a plain object. A token with no `=` is dropped rather than throwing: a
|
||||
* malformed declaration should degrade to "that one pair is missing", not
|
||||
* crash a boot.
|
||||
*
|
||||
* @param {string} [value]
|
||||
* @returns {Record<string,string>}
|
||||
*/
|
||||
function parseQcBootEnv(value) {
|
||||
const out = {};
|
||||
for (const token of splitList(value)) {
|
||||
const eq = token.indexOf("=");
|
||||
if (eq <= 0) continue;
|
||||
out[token.slice(0, eq)] = token.slice(eq + 1);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and read a lane's profile.
|
||||
*
|
||||
@@ -204,7 +228,7 @@ die() { echo "profile: $*" >&2; exit 1; }
|
||||
* this file's own `module.exports` is still empty, handing `secrets.js` an
|
||||
* `undefined` parser. Deferring past module-load time breaks the cycle.
|
||||
*/
|
||||
function hookEnv(lane, profile) {
|
||||
function hookEnv(lane, profile, extraEnv = {}) {
|
||||
const { readSecrets } = require("./secrets");
|
||||
const dirs = slotDirs(lane.slot);
|
||||
const secrets = readSecrets();
|
||||
@@ -265,6 +289,7 @@ function hookEnv(lane, profile) {
|
||||
env[`${name.toUpperCase()}_PORT`] = String(port);
|
||||
}
|
||||
|
||||
Object.assign(env, extraEnv);
|
||||
return env;
|
||||
}
|
||||
|
||||
@@ -339,7 +364,7 @@ function runHook(lane, profile, name, args = [], options = {}) {
|
||||
],
|
||||
{
|
||||
cwd: lane.cwd,
|
||||
env: hookEnv(lane, profile),
|
||||
env: hookEnv(lane, profile, options.extraEnv),
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
}
|
||||
);
|
||||
@@ -390,6 +415,7 @@ module.exports = {
|
||||
PROFILE_SUBDIR,
|
||||
parseEnvFile,
|
||||
splitList,
|
||||
parseQcBootEnv,
|
||||
resolveProfile,
|
||||
profileSearchPaths,
|
||||
hookEnv,
|
||||
|
||||
@@ -41,7 +41,7 @@ const {
|
||||
portBase,
|
||||
dbName,
|
||||
} = require("./lane-slots");
|
||||
const { resolveProfile, profileSearchPaths, runHook } = require("./lane-profile");
|
||||
const { resolveProfile, profileSearchPaths, parseQcBootEnv, runHook } = require("./lane-profile");
|
||||
const { isListening, listenerPids } = require("./ports");
|
||||
const { seedEnv } = require("./lane-env");
|
||||
const { ensureDatabase, dropDatabase } = require("./lane-services");
|
||||
@@ -343,7 +343,7 @@ async function removeLaneData(lane, profile, options = {}) {
|
||||
*/
|
||||
async function upLane(lane, options = {}) {
|
||||
const profile = requireProfile(lane);
|
||||
const { build = true, onLine } = options;
|
||||
const { build = true, qc = false, onLine } = options;
|
||||
|
||||
let current = lane;
|
||||
if (!current.slot) {
|
||||
@@ -374,9 +374,11 @@ async function upLane(lane, options = {}) {
|
||||
await runRequiredHook(current, profile, "migrate", { onLine }, "EMIGRATEFAILED");
|
||||
if (db.created) await runRequiredHook(current, profile, "seed", { onLine }, "ESEEDFAILED");
|
||||
|
||||
const bootExtraEnv = qc ? parseQcBootEnv(profile.env.QC_BOOT_ENV) : undefined;
|
||||
const boot = await runHook(current, profile, "boot", build ? [] : ["--no-build"], {
|
||||
onLine,
|
||||
timeoutMs: BOOT_TIMEOUT_MS,
|
||||
extraEnv: bootExtraEnv,
|
||||
});
|
||||
if (boot.code !== 0) {
|
||||
throw Object.assign(new Error(`boot hook exited ${boot.code}`), {
|
||||
|
||||
Reference in New Issue
Block a user