Skip to content

Commit c2e5b3a

Browse files
committed
feat(ci): add workload-aware Crabbox routing
1 parent b7eceb4 commit c2e5b3a

5 files changed

Lines changed: 892 additions & 36 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@
345345
"!docs/**/*.jpg",
346346
"!docs/**/*.png",
347347
"src/agents/templates/",
348+
"scripts/crabbox-routing-policy.mjs",
348349
"scripts/crabbox-wrapper-providers.mjs",
349350
"scripts/crabbox-wrapper.mjs",
350351
"scripts/testbox-lease-freshness.mjs",

‎scripts/crabbox-routing-policy.mjs‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const workloadAliases = new Map([
2+
["check", "ci-fast"],
3+
["ci", "ci-fast"],
4+
["ci-fast", "ci-fast"],
5+
["ci-proof", "ci-proof"],
6+
["desktop", "desktop"],
7+
["interactive", "interactive"],
8+
["release", "release-proof"],
9+
["release-proof", "release-proof"],
10+
["untrusted", "untrusted"],
11+
["windows", "windows"],
12+
]);
13+
14+
export function normalizeCrabboxWorkload(value) {
15+
const normalized = `${value ?? ""}`.trim().toLowerCase();
16+
if (!normalized) {
17+
return "";
18+
}
19+
return workloadAliases.get(normalized) ?? null;
20+
}
21+
22+
export function crabboxProviderChain({
23+
workload,
24+
configuredProvider,
25+
target,
26+
advertisedProviders,
27+
}) {
28+
const providers = new Set(advertisedProviders);
29+
const normalizedConfigured = `${configuredProvider ?? ""}`.trim();
30+
const normalizedTarget = `${target ?? ""}`.trim().toLowerCase();
31+
32+
if (normalizedTarget === "macos") {
33+
return available(["aws"], providers);
34+
}
35+
if (normalizedTarget === "windows" || workload === "windows") {
36+
return available(["azure", "aws"], providers);
37+
}
38+
39+
const cloudFallback = ["azure", "aws"];
40+
switch (workload) {
41+
case "ci-fast":
42+
return available(["blacksmith-testbox", "daytona", ...cloudFallback], providers);
43+
case "ci-proof":
44+
case "release-proof":
45+
return available(["blacksmith-testbox", "daytona", ...cloudFallback], providers);
46+
case "interactive":
47+
return available(["daytona", ...cloudFallback], providers);
48+
case "desktop":
49+
return available(cloudFallback, providers);
50+
case "untrusted":
51+
// Daytona remains excluded until its brokered isolation profile has live proof.
52+
return available(cloudFallback, providers);
53+
default:
54+
return available([normalizedConfigured], providers);
55+
}
56+
}
57+
58+
export function selectReadyCrabboxProvider(chain, readiness) {
59+
for (const provider of chain) {
60+
const status = readiness.get(provider);
61+
if (status?.ready) {
62+
return { provider, readiness: status };
63+
}
64+
}
65+
return null;
66+
}
67+
68+
function available(candidates, advertisedProviders) {
69+
return candidates.filter((provider) => provider && advertisedProviders.has(provider));
70+
}

0 commit comments

Comments
 (0)