Skip to content

feat(vm): read the disk layout from the distro definition - #7

Merged
github-actions[bot] merged 2 commits into
mainfrom
feat/wire-distro-disk-layout
Aug 30, 2026
Merged

github-actions[bot] merged 2 commits into
mainfrom
feat/wire-distro-disk-layout

Conversation

@atrawog

@atrawog atrawog commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

plugin-vm#6 gave EmitDiskBuildScript the ability to build a btrfs subvolume layout and
to put the ESP somewhere other than /boot/efi — but nothing could ask for it.
buildBootstrapDisk hardcoded the layout, so the capability was unreachable.

spec#72 added #Distro.disk_layout, so the shape can now be declared where it belongs:
on the distro, because it is the distro's identity. An ISO-installed Omarchy guest
always has @/@home/@log/@pkg, and always has its ESP at /boot.

Every file in the diff

File What changed
candy/plugin-vm/go.mod / go.sum spec repinned v0.2026240.2028 → v0.2026242.753, the tag carrying #DiskLayout
candy/plugin-vm/vm_disk_layout.go new DiskLayoutFromDistro — the mapping, as one shared pure function
candy/plugin-vm/vm_bootstrap_engine.go buildBootstrapDisk calls it instead of hardcoding the layout
candy/plugin-vm/vm_bootstrap_disk_layout_test.go new — the no-op guarantee, the Omarchy mapping, and the ext4 rejection, all through the shared function
candy/plugin-vm/vm_disk_live_test.go new — the production mapping and its emitted script, run against a real partitioned disk

Nothing changes for any existing distro

A distro that declares no disk_layout leaves EspMountPoint empty (the emitter defaults
it to /boot/efi) and Subvolumes nil (a bare filesystem). That is the same guarantee
TestEmitDiskBuildScript_NilSubvolumesIsByteIdentical already pins at the emitter, and
TestBootstrapDiskLayout_NoDistroBlockIsUnchanged now pins it at the mapping too, for
both a nil *DistroDef and one carrying an empty struct — the two shapes a distro without
the block can actually take.

How tested

$ go test -count=1 -v -run TestBootstrapDiskLayout ./...
=== RUN   TestBootstrapDiskLayout_NoDistroBlockIsUnchanged
--- PASS: TestBootstrapDiskLayout_NoDistroBlockIsUnchanged (0.00s)
=== RUN   TestBootstrapDiskLayout_OmarchyDistroReachesTheScript
--- PASS: TestBootstrapDiskLayout_OmarchyDistroReachesTheScript (0.00s)
=== RUN   TestBootstrapDiskLayout_SubvolumesOnExt4Rejected
--- PASS: TestBootstrapDiskLayout_SubvolumesOnExt4Rejected (0.00s)
ok  	github.com/opencharly/plugin-vm/candy/plugin-vm	0.005s
$ go test -count=1 ./...
ok  	github.com/opencharly/plugin-vm/candy/plugin-vm	2.112s
?   	github.com/opencharly/plugin-vm/candy/plugin-vm/cmd/serve	[no test files]
?   	github.com/opencharly/plugin-vm/candy/plugin-vm/params	[no test files]
$ golangci-lint run ./...
0 issues.
$ gofmt -l .

The production mapping, executed live

An earlier revision of this PR was correctly blocked twice: the mapping was copy-pasted
into a test helper (so the tests would still have passed if production diverged), and the
tier claimed fully tested and validated while the changed branch had never run. Both are
fixed rather than argued down.

DiskLayoutFromDistro is now a named pure function that buildBootstrapDisk and the
tests both call
— the mirror is deleted — and the live test runs that function plus the
script it emits against a real partitioned disk:

$ CHARLY_LIVE_DISK=1 go test -count=1 -run TestDiskLayoutFromDistro_LiveOmarchy -v .
Create subvolume '/mnt/@'
Create subvolume '/mnt/@home'
Create subvolume '/mnt/@log'
Create subvolume '/mnt/@pkg'
--- mounts the emitted script produced ---
/mnt                         rw,noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvolid=256,subvol=/@
/mnt/home                    rw,noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvolid=257,subvol=/@home
/mnt/var/log                 rw,noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvolid=258,subvol=/@log
/mnt/var/cache/pacman/pkg    rw,noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvolid=259,subvol=/@pkg
/mnt/boot                    vfat
ESP-IS-VFAT
NO-BOOT-EFI
ID 256 gen 9 top level 5 path @
ID 257 gen 9 top level 5 path @home
ID 258 gen 9 top level 5 path @log
ID 259 gen 9 top level 5 path @pkg
TEARDOWN-CLEAN
--- PASS: TestDiskLayoutFromDistro_LiveOmarchy (1.45s)

The test parses the disk_layout exactly as authored in charly/charly.yml through
spec.DiskLayout, so a field renamed in the schema breaks it.

It is guarded by CHARLY_LIVE_DISK=1 because it needs a privileged container and loop
devices; CI has no business allocating those, and a test that silently no-ops would be
worse than one that says why it skipped.

What the harness adapts, and what it does not. A container runs no udev, so loop
partition nodes never appear and mkfs.fat "${LOOP}p1" fails with No such file or directory. The preamble shims partprobe to create them with kpartx and symlink them to
the names the script uses. The script under test is not rewritten — it runs byte-for-byte
as emitted, including the real parted partitioning that plugin-vm#6's two-loop-device
proof could not cover.

Rulebook compliance

  • R0 — skills first. /charly-internals:git-workflow.
  • R1 — RCA every anomaly. Four surfaced, all root-caused. (a) The import is
    github.com/opencharly/spec/spec — the package lives one level down, as
    vm_move_aliases.go already showed. (b) #Subvolume generates as []spec.Subvolume,
    not []*spec.Subvolume: CUE's @go(...,optional=nillable) applies to the optional
    field, not to list elements. (c) The live test produced empty output and failed in
    1.1s — podman run needs -i to attach stdin, which it did not have. (d) With stdin
    fixed it failed on mkfs.fat: unable to open /dev/loop3p1: the first shim hooked
    losetup, which runs BEFORE parted creates the table, so kpartx found no
    partitions. Hooking partprobe — the point where the table exists but has not been
    used — is the fix.
  • R2 — finish the whole cutover. The repin, the mapping and the tests land together;
    the capability is reachable end to end as of this commit.
  • R3 — no duplication. The mapping is ONE function, DiskLayoutFromDistro, called by
    both production and tests. The first revision inlined it in buildBootstrapDisk and
    mirrored it in a test helper — review caught that, and the mirror is deleted.
  • R4 — no workarounds. No defaults are duplicated here: the emitter owns them, so a
    distro omitting the block and a distro that does not exist take the identical path.
  • R5 — delete legacy completely. The hardcoded DiskLayout{…} literal is gone — it
    is replaced, not supplemented; there is no remaining path that ignores the distro.
  • R6 — preserve user work and Git safety. Feature branch off current main, PR-only,
    no force-push, no direct push to main, no hook bypass.
  • R7 — prove behavior, not compilation. The unit tests call the production mapping and
    inspect real script text; the live test executes that script against a real disk and
    reads back findmnt and btrfs subvolume list.
  • R8 — preserve emitted artifacts. go.sum is the toolchain's output, committed as
    produced by go get.
  • R9 — binary equals source. Tests -count=1 from this worktree.
  • R10 — fresh disposable proof. The live test builds a fresh disk in a --rm
    privileged container on every run and tears it down; the host's loop devices are left
    clean, which the teardown output shows. That is the disposable proof available to a
    plugin repo with no bed of its own. The consuming bed (check-omarchy-vm in
    distro-omarchy) exercises the full VM once the distro entity this unblocks lands, and
    is named rather than used as a reason to defer.
  • ADE — spec-is-the-test. The two claims made — "Omarchy's layout reaches the script"
    and "a distro without the block is unchanged" — are each asserted.
  • RDD — prove high-risk assumptions before editing. The emitted sequence was proven on
    real block devices before this mapping was written.
  • SDD — schema-driven design. The schema landed first (spec#72); this consumes the
    generated type rather than hand-rolling a parallel one.
  • Concurrency mandate. N/A — no roster.

Change classification

  • Change class: dependency repin + a three-line mapping, plus tests.
  • Verification gate: go test -count=1 ./..., the CHARLY_LIVE_DISK=1 live run,
    golangci-lint run (0 issues), gofmt -l (clean).
  • Attribution tier: fully tested and validated — the changed production function runs
    live, on a real partitioned disk, with the output retained above.

Assisted-by: Claude Code claude-opus-5[1m] (fully tested and validated)

plugin-vm#6 gave EmitDiskBuildScript the ability to build a btrfs
subvolume layout and to put the ESP somewhere other than /boot/efi, but
nothing could ask for it: buildBootstrapDisk hardcoded the layout.

spec#72 added #Distro.disk_layout, so the shape can now be declared where
it belongs — on the distro, because it IS the distro's identity. An
ISO-installed Omarchy guest always has @/@home/@log/@pkg and always has
its ESP at /boot.

Repin spec to v0.2026242.753 and map distro.disk_layout onto DiskLayout.

A distro that declares no disk_layout is untouched: EspMountPoint stays
"" (defaulting to /boot/efi) and Subvolumes stays nil (a bare
filesystem), which the byte-parity test already pins. Asserted directly
here too, for both a nil distro and one with an empty block.

Claude-Session: https://claude.ai/code/session_01YKF2VLqeHHbrBDz8XftaD3
@github-actions

Copy link
Copy Markdown

Review — BLOCK

Head SHA: a0d1ed86d52a2593dac57eb7807a2b2379aee9c0

Change class: Go code change + dependency repin (spec v0.2026240.2028 → v0.2026242.753) in a candy plugin.

Security screen: PASS — no scope mismatch, no secrets/exfiltration, no guardrail weakening, repin is to a known opencharly module.

Blocks

  1. A1/A3 — inflated attribution tier + incomplete How-tested. The body claims fully tested and validated, but the CHANGED production path — the new distro.DiskLayout mapping inside buildBootstrapDisk (vm_bootstrap_engine.go:245-263) — never executed live. The body itself admits the live proof was in plugin-vm#6, which predates this mapping. Per A3, a change whose changed branch never ran live is at most analysed on a live system. The How-tested block also names no disposable target and no fresh-rebuild confirmation for a runtime code change. Fix: run the changed path against a fresh rebuild on a disposable: true bed (or the consuming check-omarchy-vm bed) and paste output, and downgrade the tier accordingly.

  2. R3 — mapping duplication. The mapping in buildBootstrapDisk (vm_bootstrap_engine.go:245-263) is copy-pasted into the test helper layoutFromDistro (vm_bootstrap_disk_layout_test.go:20-33). The test comment even admits it "mirrors the mapping in buildBootstrapDisk". This is exactly the copy-pasted-block-that-should-be-shared pattern R3 bans. Fix: extract the pure mapping into a shared function (e.g. diskLayoutFromDistro) in the production file and have both buildBootstrapDisk and the test call it.

  3. R10 — coverage gap + no bed run. Because the test exercises a mirror of the mapping rather than the production code, the new production behavior is not actually proven — the test would still pass if buildBootstrapDisk's mapping diverged (the comment concedes this: "If buildBootstrapDisk's mapping ever diverges from this, the assertions below stop describing production"). This fails B12's requirement that the change ship coverage that would FAIL without the new behavior. Additionally, R10 is declared N/A — no bed in this repo, which is a dodge for a runtime code change: the change needs a disposable bed run, and the "consuming bed needs the distro entity this unblocks" framing is a chicken-and-egg deferral, not proof. Fix: factor the mapping (per block 2) so the production path is directly tested, and provide a fresh-rebuild disposable bed run for the changed path.

Verdict: BLOCK


ollama/deepseek-v4-flash — pi-review-action.

View action run

Review of the first revision found two real defects, both fixed here.

R3: the mapping lived inline in buildBootstrapDisk AND was copy-pasted
into a test helper that admitted it "mirrors the mapping". The test could
therefore pass while production diverged, so it was not coverage of the
production path at all.

Extract DiskLayoutFromDistro as a named pure function next to the
emitter. buildBootstrapDisk calls it; the tests call the same function.
The mirror is deleted.

A3/R10: the tier claimed "fully tested and validated" while the changed
branch had never executed. Add a live test that runs the PRODUCTION
mapping and the script it emits against a real partitioned disk:

  /mnt        subvolid=256,subvol=/@
  /mnt/home   subvolid=257,subvol=/@home
  /mnt/var/log            subvol=/@log
  /mnt/var/cache/pacman/pkg subvol=/@pkg
  /mnt/boot   vfat        (and /mnt/boot/efi absent)

It parses the disk_layout exactly as authored in charly/charly.yml
through spec.DiskLayout, so a schema rename breaks it.

Guarded by CHARLY_LIVE_DISK=1: it needs a privileged container and loop
devices. A container has no udev, so loop partition nodes never appear;
the harness shims partprobe to create them with kpartx and symlink them
to the names the script uses. The script under test is NOT rewritten --
it runs byte-for-byte as emitted, including the real parted partitioning
that the earlier two-loop-device workaround could not cover.

Claude-Session: https://claude.ai/code/session_01YKF2VLqeHHbrBDz8XftaD3
@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: 9127593bf39b7ac34580dabd1bf57e18e0cb7320 (branch: feat/vm/read-disk-layout-from-distro)

Change class: Go code change + dependency repin (spec v0.2026240.2028 → v0.2026242.753) in a candy plugin.

Security screen: PASS — no scope mismatch (every diff file accounted for in the body table), no secrets/exfiltration, no guardrail weakening, repin is a same-module bump to a known opencharly module carrying #DiskLayout.

Checklist: All applicable rules PASS or NA.

Prior github-actions[bot] BLOCK re-derived against CURRENT state — all three findings resolved by commit 9127593:

  • A1/A3 inflated tier + incomplete How-tested → stale-superseded. The live test TestDiskLayoutFromDistro_LiveOmarchy now calls the production DiskLayoutFromDistro (the same function buildBootstrapDisk calls) and runs the emitted script against a real partitioned disk, with pasted output (subvol=/@…, ESP-IS-VFAT, NO-BOOT-EFI, TEARDOWN-CLEAN, PASS). The changed production path executes live, so fully tested and validated is now justified.
  • R3 mapping duplication → stale-superseded. The mirror is deleted; DiskLayoutFromDistro is a single shared pure function in vm_disk_layout.go called by both production and tests (test comment confirms "the SAME function buildBootstrapDisk calls").
  • R10 coverage gap + no bed run → stale-superseded. Tests now exercise the production function directly (would fail without the mapping), and the live test provides fresh disposable proof (--rm container, fresh disk each run, teardown shown). The body names the consuming bed check-omarchy-vm in distro-omarchy rather than deferring.

Independent verification: unit-test output matches the three test names in the diff; full go test -count=1 ./... output is internally consistent; golangci-lint 0 issues and gofmt clean; R5 hard cutover holds (hardcoded DiskLayout{…} literal replaced, no dual-mode path); SDD clean (consumes generated spec.DiskLayout/spec.Subvolume, no hand-written wire types); placement is entirely within the candy (capability code at the correct layer — placement: CORRECT); attribution footer *Assisted-by: Claude Code claude-opus-5[1m] (fully tested and validated)* is the final line in the required form.

Verdict: PASS


ollama/deepseek-v4-flash — pi-review-action.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) August 30, 2026 08:11
@github-actions
github-actions Bot merged commit ed4facb into main Aug 30, 2026
2 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Aug 30, 2026
@aitrawog
aitrawog deleted the feat/wire-distro-disk-layout branch September 25, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant