Files
w3cjandClaude Opus 5.5 97672c4267 refactor(backend): base's size as Go constants, base's disk in Lima's origin
Base's size was read from assets/base.yaml four ways: vm.BaseDisk's
line scanner (a new VM's smallest disk), SizeChoice.Fitted's same scanner
for CPUs and memory (devvm size -g and setup's question), Lima's
buildSize regexes (base's build size), and limactl create reading disk:
from the template on its input. Now backend.BaseCPUs, BaseMemoryGiB and
BaseDiskGiB are the one source:

- vm checks new VMs' disks against backend.BaseDiskGiB, and Fitted fits
  BaseCPUs and BaseMemoryGiB; SizeChoice has no Assets any more.
- Lima's buildSize uses the constants; its Origin carries base's disk as
  a step of its own ("disk", its GiB), which originOf requires and
  createArgs passes as --disk=, so base's key still hashes it, and the
  --from conversion's VM gets it too.
- base.yaml sets no cpus, memory or disk, and is hashed only into Lima's
  key as Lima's settings.

Tests: TestBuildImageBaseSize (pinned on the old code: base created with
4 CPUs, 8 GiB and a 100 GiB disk, now all flags and none in base.yaml),
TestBaseSize, TestOriginOfRefuses' no disk and bad disk; the limactl stub
reads create's --disk=. Docs: internals/images.md, internals/lima.md,
contributing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 15:55:01 -07:00

40 lines
1.5 KiB
Plaintext

# A small host, as the test build fakes one (2 CPUs, 7 GiB of memory and
# 1 GiB free, below GitHub's smallest runner): doctor warns about each, a
# build refuses the disk, base is fitted to the host, and sizes past the
# host are refused. Registries are never reached: HTTPS_PROXY points at
# nothing.
env DEVVM_TEST_CPUS=2
env DEVVM_TEST_MEMORY_GIB=7
env DEVVM_TEST_FREE_GIB=1
env HTTPS_PROXY=http://127.0.0.1:9
env https_proxy=http://127.0.0.1:9
# doctor warns, and passes.
exec devvm doctor
stdout '^doctor_ok backend=lima version=\S+$'
stderr '^devvm: disk_low_warning dir=\S+ free=1\.0 need=[0-9]+$'
stderr '^devvm: host_memory_low have=7 want=8$'
stderr '^devvm: host_cpus_few have=2 want=4$'
# A build needs more free space than that.
! exec devvm build base
stderr '^devvm: disk_low dir=\S+ free=1\.0 name=base need=[0-9]+$'
stub_calls
! stdout 'limactl create'
# With room, base gets the host's 2 CPUs and half its memory.
env DEVVM_TEST_FREE_GIB=500
exec devvm build base
stdout '^==> base_fitted cpus=2 memory=3\.5$'
stub_calls
stdout '^limactl create --tty=false --mount-none --name=devvm-img-[0-9a-f]{12} .* --cpus=2 --memory=3\.5 --disk=100 -$'
# Sizes past the host: more CPUs than it has, or more memory than leaves
# it 2 GiB.
! exec devvm size -g --cpus 3
stderr '^devvm: too_many_cpus have=2 want=3$'
! exec devvm size -g --memory 6
stderr '^devvm: too_much_memory have=7 max=5 want=6$'
exec devvm size -g --cpus 2 --memory 5
stdout '^==> size_defaults size=cpus=2 memory=5GiB$'