Skip to content

Commit 89e4ef2

Browse files
committed
fix(ci): preserve routing failure diagnostics
1 parent 3cf0de8 commit 89e4ef2

2 files changed

Lines changed: 80 additions & 9 deletions

File tree

‎scripts/crabbox-wrapper.mjs‎

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,21 @@ function checkedOutput(
431431
};
432432
}
433433

434+
function recoveryCommand(commandArgs) {
435+
return [binary, ...commandArgs].map(recoveryCommandArgument).join(" ");
436+
}
437+
438+
function recoveryCommandArgument(value) {
439+
const text = `${value}`;
440+
if (/^[A-Za-z0-9_./:@%+=,-]+$/u.test(text)) {
441+
return text;
442+
}
443+
if (process.platform === "win32") {
444+
return `"${text.replaceAll('"', '""')}"`;
445+
}
446+
return `'${text.replaceAll("'", "'\\''")}'`;
447+
}
448+
434449
// Probe Crabbox metadata (`--version` / `run --help`) with one generous retry.
435450
// A cold Crabbox can be SIGKILLed by the snappy default timeout or emit nothing
436451
// on the first call, then be instant and clean on the next. Retrying keeps the
@@ -898,6 +913,7 @@ function crabboxProviderReadiness(providerName, versionText, targetContext) {
898913
return {
899914
ready: false,
900915
reason: `requires Crabbox >= ${formatVersionTuple(minimumBlacksmithCrabboxVersion)} for Blacksmith Testbox`,
916+
recovery: "update Crabbox, then retry",
901917
};
902918
}
903919
if (
@@ -907,10 +923,15 @@ function crabboxProviderReadiness(providerName, versionText, targetContext) {
907923
return {
908924
ready: false,
909925
reason: `requires Crabbox >= ${formatVersionTuple(minimumBrokeredDaytonaCrabboxVersion)} for brokered Daytona`,
926+
recovery: "update Crabbox, then retry",
910927
};
911928
}
912929
if (["aws", "azure", "daytona"].includes(canonicalProvider) && !managedBrokerAuthConfigured()) {
913-
return { ready: false, reason: "managed Crabbox broker auth unavailable" };
930+
return {
931+
ready: false,
932+
reason: "managed Crabbox broker auth unavailable",
933+
recovery: `run \`${recoveryCommand(["login", "--url", "https://crabbox.openclaw.ai"])}\`, then retry`,
934+
};
914935
}
915936
const doctorArgs = ["doctor", "--provider", canonicalProvider];
916937
if (targetContext.target) {
@@ -922,17 +943,40 @@ function crabboxProviderReadiness(providerName, versionText, targetContext) {
922943
doctorArgs.push("--json");
923944
const doctor = checkedOutput(binary, doctorArgs);
924945
if (doctor.status !== 0) {
925-
return { ready: false, reason: `doctor exited ${doctor.status}` };
946+
const diagnostic = compactDiagnosticText(doctor.text);
947+
return {
948+
ready: false,
949+
reason: `doctor exited ${doctor.status}${diagnostic ? `: ${diagnostic}` : ""}`,
950+
recovery: `run \`${recoveryCommand(doctorArgs)}\``,
951+
};
926952
}
927953
return { ready: true, reason: "doctor-ready" };
928954
}
929955

956+
function compactDiagnosticText(value, maxLength = 500) {
957+
const compact = `${value ?? ""}`.replace(/\s+/gu, " ").trim();
958+
if (compact.length <= maxLength) {
959+
return compact;
960+
}
961+
return `${compact.slice(0, Math.max(0, maxLength - 3))}...`;
962+
}
963+
930964
function formatProviderReadiness(readiness) {
931965
return [...readiness.entries()]
932966
.map(([candidate, status]) => `${candidate}:${status.ready ? "ready" : status.reason}`)
933967
.join(",");
934968
}
935969

970+
function providerRecoveryAdvice(readiness) {
971+
return [
972+
...new Set(
973+
[...readiness.values()]
974+
.map((status) => status.recovery)
975+
.filter((recovery) => typeof recovery === "string" && recovery.length > 0),
976+
),
977+
];
978+
}
979+
936980
function shouldRequireBrokeredCloud(commandArgs, providerName, explicitProviderRequested = false) {
937981
const canonicalProvider = canonicalProviderName(providerName);
938982
if (!["aws", "azure", "daytona"].includes(canonicalProvider)) {
@@ -1012,7 +1056,7 @@ function enforceBrokeredCloud(commandArgs, providerName, explicitProviderRequest
10121056
const canonicalProvider = canonicalProviderName(providerName);
10131057
const instructions = [
10141058
`[crabbox] provider=${canonicalProvider} requires a configured managed Crabbox broker for OpenClaw proof.`,
1015-
"[crabbox] run `crabbox login --url https://crabbox.openclaw.ai`, then retry.",
1059+
`[crabbox] run \`${recoveryCommand(["login", "--url", "https://crabbox.openclaw.ai"])}\`, then retry.`,
10161060
];
10171061
if (canonicalProvider !== "aws") {
10181062
instructions.push(
@@ -3783,13 +3827,25 @@ const version = probeCrabboxMetadata(binary, ["--version"]);
37833827
const help = probeCrabboxMetadata(binary, ["run", "--help"]);
37843828
const providers = parseProvidersFromHelp(help.text);
37853829
const displayBinary = binary === "crabbox" ? "crabbox" : relative(repoRoot, binary);
3830+
3831+
if (version.status !== 0 || help.status !== 0) {
3832+
console.error(
3833+
`[crabbox] bin=${displayBinary} version=${version.text || "unknown"} providers=${providers.join(",") || "unknown"}`,
3834+
);
3835+
console.error("[crabbox] selected binary failed basic --version/--help sanity checks");
3836+
process.exit(2);
3837+
}
3838+
37863839
const providerSelection = selectedProvider(args, providers, version.text);
37873840
if (providerSelection.error) {
37883841
console.error(`[crabbox] ${providerSelection.error}`);
37893842
if (providerSelection.readiness) {
37903843
console.error(
37913844
`[crabbox] provider readiness ${formatProviderReadiness(providerSelection.readiness)}`,
37923845
);
3846+
for (const recovery of providerRecoveryAdvice(providerSelection.readiness)) {
3847+
console.error(`[crabbox] recovery: ${recovery}`);
3848+
}
37933849
}
37943850
process.exit(2);
37953851
}
@@ -3813,11 +3869,6 @@ if (providerSelection.source === "policy") {
38133869
);
38143870
}
38153871

3816-
if (version.status !== 0 || help.status !== 0) {
3817-
console.error("[crabbox] selected binary failed basic --version/--help sanity checks");
3818-
process.exit(2);
3819-
}
3820-
38213872
if (provider && !isProviderAdvertised(provider, providers)) {
38223873
if (providers.length === 0) {
38233874
console.error(

‎test/scripts/crabbox-wrapper.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,10 @@ describe("scripts/crabbox-wrapper", () => {
14371437
expect(result.stdout).toBe("");
14381438
expect(result.stderr).toContain("no ready provider for workload=ci-fast");
14391439
expect(result.stderr).toContain("provider readiness");
1440+
expect(result.stderr).toContain('{"ok":false,"provider":"blacksmith-testbox"}');
1441+
expect(result.stderr).toMatch(
1442+
/recovery: run `\S+crabbox doctor --provider blacksmith-testbox --json`/u,
1443+
);
14401444
});
14411445

14421446
it("rejects unknown workload policies before execution", () => {
@@ -2221,7 +2225,7 @@ describe("scripts/crabbox-wrapper", () => {
22212225
expect(result.status).toBe(2);
22222226
expect(result.stdout).toBe("");
22232227
expect(result.stderr).toContain("provider=aws requires a configured managed Crabbox broker");
2224-
expect(result.stderr).toContain("crabbox login --url https://crabbox.openclaw.ai");
2228+
expect(result.stderr).toContain("login --url https://crabbox.openclaw.ai");
22252229
expect(result.stderr).not.toContain("--provider aws");
22262230
expect(result.stderr).not.toContain("OPENCLAW_CRABBOX_ALLOW_DIRECT_CLOUD");
22272231
});
@@ -3788,6 +3792,22 @@ describe("scripts/crabbox-wrapper", () => {
37883792
expect(result.stderr).toContain("selected binary failed basic --version/--help sanity checks");
37893793
});
37903794

3795+
it("rejects a broken binary before workload provider discovery", () => {
3796+
const helpText =
3797+
"provider: hetzner, aws, local-container, blacksmith-testbox, daytona, azure, or cloudflare\n";
3798+
const result = runWrapper(helpText, ["run", "--workload", "ci-fast", "--", "echo ok"], {
3799+
env: { OPENCLAW_TEST_CRABBOX_METADATA_PROBE_TIMEOUT_MS: "100" },
3800+
extraPathEntries: [makeSlowVersionCrabbox(helpText)],
3801+
nodePreload: testTimingPreload({ spawnTimeoutMs: 25 }),
3802+
});
3803+
3804+
expect(result.error).toBeUndefined();
3805+
expect(result.status).toBe(2);
3806+
expect(result.stderr).toContain("selected binary failed basic --version/--help sanity checks");
3807+
expect(result.stderr).not.toContain("no ready provider");
3808+
expect(result.stderr).not.toContain("provider readiness");
3809+
});
3810+
37913811
it("retries a cold Crabbox whose run --help is slower than the default probe timeout", () => {
37923812
const helpText = "provider: hetzner, aws, local-container, blacksmith-testbox, or cloudflare\n";
37933813
// First probe is SIGKILLed at 25ms; the retry gets the full generous timeout

0 commit comments

Comments
 (0)