refactor(orch): render the distro selection in provision.sh's own template - #3463
refactor(orch): render the distro selection in provision.sh's own template#3463tomassrnka wants to merge 2 commits into
Conversation
PR SummaryMedium Risk Overview Reviewed by Cursor Bugbot for commit 5b134af. Bugbot is set up for automated code reviews on this repo. Configure here. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
9437ec6 to
4b6d895
Compare
4b6d895 to
3f449f6
Compare
The three initSetup bodies leave their Go string literals for
init-{systemd,openrc,nixos}.sh, go:embed'd with the trailing newline
trimmed so they splice exactly like the literals did. Selector output is
unchanged apart from the entry comments moving in as # lines.
Rebased over #3440, which added chrony-source wiring to both init blocks
after this was written: the systemd drop-in, OpenRC's e2b-chrony-source
install and the unconditional command_args="-F 0" move into the new
files verbatim, checked byte-for-byte against main's literals.
First half of the #3411 follow-up (dobrac: init.go:21).
…plate
The selection structure (case arms, rejected-id guard, ID_LIKE loop,
error/warning text) moves verbatim from the ShellSelector string-builder
into provision.sh as inline template actions; the distro package now
contributes data only — distro.NewTemplateData(), with all shell-quoting
kept in Go. Fingerprint hashes the view data (%#v, so new fields are
covered automatically); the structure is already hashed via the raw
embedded template. Version 1 -> 2.
The render seam and its tests live in ungated files so they keep running
on darwin. Selection-text assertions move to base/provision_test.go
against the rendered script, with the guard-ordering anchor rewritten to
the fallback loop line (E2B_ID_LIKE is assigned earlier in the full
script). New guards: %q-vs-sh quoting assumptions pinned per profile
field, a leftover-"{{" render check, and a test that every ProfileView
field — including the init-setup body now sourced from a file — reaches
the rendered case arm. A dropped template action would otherwise leave
the Go-side tests green while the guest hits an undefined variable under
set -u.
#3440's chrony-deferral test now asserts on the rendered script rather
than the raw template: the init blocks moved out, so only the rendered
form covers both halves.
Rendered output verified byte-identical to main's ShellSelector output
modulo the added comments; customer-visible messages pinned byte-exact.
Completes the #3411 follow-up (dobrac: distro.go:160, provision.sh:29).
3f449f6 to
5b134af
Compare
The follow-up promised in the #3411 review (@dobrac's three comments: Go templating for the selector, profiles-as-data with selection living in provision.sh, init blocks in separate files). #3459 has merged; this now sits directly on main.
What changed
ShellSelector()string-builder into provision.sh as inlinetext/templateactions. Thedistropackage now contributes data only —distro.NewTemplateData()— with all shell-quoting kept in Go where it's unit-testable. NoFuncMap(repo precedent).distro/init-{systemd,openrc,nixos}.sh,go:embed'd.Hash()already hashes;distro.Fingerprint()covers the spliced data (%#vof the view — new fields fingerprint automatically).Version1 → 2. The dev/fallback provision version rotates once on deploy; production rollout stays gated by theBuildProvisionVersionLD flag.base/provision_test.goagainst the fully rendered script (the render seam and tests are build-tag-free, so they run on darwin). Every prior assertion is preserved, including the errexit guard (noif e2b_select_profile) and guard-before-fallback ordering. New: per-field%q-vs-sh quoting pins, byte-exact customer-message pins, and a leftover-{{render check.Verification
ShellSelector(): byte-identical for the whole selection function; only deliberate comment/blank-line additions in the tail.oraclelinux:9rejected with byte-identical ERROR lines;kalibuilds with the byte-identical ID_LIKE WARNING and boots;alpine(OpenRC path) builds and boots with envd healthy;ubuntuanddebianbuild and boot.sh -nclean on the rendered script.Rebase onto current main (#3478, #3440)
Both landed after the last rebase and both touch the code this PR moves, so the merge was semantic, not textual:
initSetupliterals this PR deletes — the systemd$E2B_TIMESYNC_UNIT.service.ddrop-in, OpenRC'se2b-chrony-sourceinstall, and the unconditionalcommand_args="-F 0". All three are now ininit-openrc.sh/init-systemd.sh, verified byte-for-byte against main's literals. fix(orch): choose the chrony time source at boot instead of at build time #3440'sprovision_test.goand its threedistro_test.gotests are kept; the chrony-deferral test now reads the rendered script, since the init blocks no longer live in the raw template.InitBinary: "/sbin/e2b-nixos-init"survives thedistro.gorewrite and reaches the rendered arm asE2B_INIT_BIN="/sbin/e2b-nixos-init".Tree swept for orphans of the moved code —
E2B_CHRONY_PHC,command_args="-F 0",e2b-chrony-source,E2B_TIMESYNC_UNIT,E2B_INIT_BIN,/sbin/e2b-nixos-init,ShellSelector,DistroSelector: every consumer has a definition, no definition is stranded.New test pinning the restored invariant:
TestProvisionScriptSplicesEveryProfileFieldasserts everyProfileViewfield — including the init-setup body now sourced from a file — reaches its rendered case arm. A dropped template action would otherwise leave the Go-side tests overProfiles/initSetupgreen while the guest hits an undefined variable underset -eu, on every distro. It subsumes the oldTestProvisionScriptInitSetup, which is removed.Re-verified after the rebase: rendered script byte-identical to main's
ShellSelector()output apart from the comments;sh -n,bash -nandshellcheck -s shclean on the three new files and on the rendered script.🤖 Generated with Claude Code