Skip to content

Commit c90d803

Browse files
committed
fix(sandbox): reject unrepresentable quantities and keep the wizard's shared-kernel choice
1 parent ef2af31 commit c90d803

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎apps/sim/lib/core/config/env-capabilities.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,11 @@ describe('sandbox kind availability', () => {
817817
values: { ...KUBERNETES_FULL, SANDBOX_K8S_CPU: '0' },
818818
expected: { function: false, mothership: false, doc: false, pi: false },
819819
},
820+
{
821+
name: 'Kubernetes with a memory limit too large to represent',
822+
values: { ...KUBERNETES_FULL, SANDBOX_K8S_MEMORY: '1e9999' },
823+
expected: { function: false, mothership: false, doc: false, pi: false },
824+
},
820825
{
821826
name: 'Kubernetes with quantities in every grammar form',
822827
values: {

‎packages/deployment-config/src/env-capabilities.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,9 @@ export function kubernetesQuantityValue(quantity: string): number | null {
11131113
const match = KUBERNETES_QUANTITY_PATTERN.exec(quantity)
11141114
if (!match) return null
11151115
const [, mantissa, exponent = '', suffix] = match
1116-
return Number(`${mantissa}${exponent}`) * (suffix ? KUBERNETES_QUANTITY_SUFFIXES[suffix] : 1)
1116+
const value =
1117+
Number(`${mantissa}${exponent}`) * (suffix ? KUBERNETES_QUANTITY_SUFFIXES[suffix] : 1)
1118+
return Number.isFinite(value) ? value : null
11171119
}
11181120

11191121
const KUBERNETES_QUANTITY_KEYS = [

‎packages/sim-setup/src/capability-config.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,16 @@ describe('capability setup configuration', () => {
7979
expect(matchesSetupCondition(currentWhen, { SANDBOX_K8S_IMAGE_PULL_SECRET: 'ghcr' })).toBe(true)
8080
expect(matchesSetupCondition(currentWhen, { SANDBOX_K8S_RUNTIME_CLASS: 'gvisor' })).toBe(false)
8181
})
82+
83+
it('keeps the shared-kernel opt-in as the current isolation choice when a runtime class is also set', () => {
84+
const isolation = SANDBOX_SETUP.providers.kubernetes.prompts.find(
85+
(prompt) => prompt.type === 'choice' && prompt.id === 'kubernetes-isolation'
86+
)
87+
const options = isolation?.type === 'choice' ? isolation.options : []
88+
const values = { SANDBOX_K8S_RUNTIME_CLASS: 'gvisor', SANDBOX_K8S_ALLOW_UNISOLATED: 'true' }
89+
const current = options.filter(
90+
(option) => option.currentWhen && matchesSetupCondition(option.currentWhen, values)
91+
)
92+
expect(current.map((option) => option.id)).toEqual(['unisolated'])
93+
})
8294
})

‎packages/sim-setup/src/capability-config.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,16 @@ export const SANDBOX_SETUP = defineCapabilitySetup(SANDBOX_CAPABILITY, {
668668
id: 'runtime-class',
669669
label: 'Isolating RuntimeClass',
670670
hint: 'gVisor, Kata, or a microVM runtime installed in the cluster',
671-
currentWhen: { kind: 'present', key: 'SANDBOX_K8S_RUNTIME_CLASS' },
671+
currentWhen: {
672+
kind: 'all',
673+
conditions: [
674+
{ kind: 'present', key: 'SANDBOX_K8S_RUNTIME_CLASS' },
675+
{
676+
kind: 'not',
677+
condition: { kind: 'truthy', key: 'SANDBOX_K8S_ALLOW_UNISOLATED' },
678+
},
679+
],
680+
},
672681
prompts: [
673682
{
674683
type: 'field',

0 commit comments

Comments
 (0)