|
| 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