Repository navigation
fix(exec): source a candy's env.d for non-interactive machine-venue commands (charly#814) - #201
Conversation
…ommands (charly#814)
A candy's `env:` compiles to `~/.config/opencharly/env.d/<candy>.env`, sourced by a
managed block charly writes into the venue's shell INIT file (~/.bashrc). bash
sources that file only for an INTERACTIVE shell, so on a `target: local` /
`target: vm` machine venue every NON-interactive command ran without the candy's
env: the deploy walk's rendered `run:`/`check:` scripts, the check engine's
`command:` probe, and `charly vm ssh <box> -- '<cmd>'`. A candy whose own `check:`
asserts its env (the `dsh-tui` candy's `printenv DSH_TUI_NO_LAUNCHPAD`) therefore
failed on a machine venue even though the deploy wrote its env file correctly.
The image/pod path is unaffected: there the env is a container `ENV`, present to
every process.
Prefix each non-interactive rendered command with a POSIX-sh preamble that sources
the venue user's own env.d directory:
for f in "$HOME"/.config/opencharly/env.d/*.env; do [ -r "$f" ] && . "$f"; done;
`$HOME` expands on the VENUE (the snippet runs there), so one constant serves every
machine venue; a glob matching nothing leaves the loop body unrun (the `[ -r ]`
guard), so a venue with no env.d is unaffected; the trailing `; ` lets a caller
concatenate its command. Both the deploy walk and the check engine converge on these
leaf executors, so prefixing the shared non-interactive spawn helpers makes the SAME
env reachable to a `check:` probe and a deploy `run:` at once (R3).
Placement (opt-in, so the container substrate is untouched):
- `ShellExecutor.MachineVenue bool` - true for a `target: local`/`host: local` root
(RootExecutorForDeployNode) and for a re-materialized `shell` VenueDescriptor (the
only producer of Kind "shell" is a machine ShellExecutor). FALSE for the throwaway
`ShellExecutor{}` a container-jump NestedExecutor uses purely as a LOCAL HOST
transport: its payload executes INSIDE the container, whose env already comes from
the image's ENV, so the host's env.d must not leak in. Prefixes RunUser + RunCapture,
deliberately NOT the `sudo` leg (a candy's `env:` is the deploying user's; `sudo`
resets HOME to root's).
- `SSHExecutor` is always a machine venue: prefix RunUser + RunCapture (not the sudo
leg - the guest user's env.d, not root's).
- `NestedExecutor.prepareJump` - a `JumpSSH` (nested-in-VM) payload is prefixed BEFORE
the wrap so it lands inside the guest; a `JumpContainerExec` payload is not.
Proven by exec/venue_envd_test.go: the preamble shape (unexpanded `$HOME`,
semicolon-terminated, no-op on blank), a LIVE ShellExecutor whose non-interactive
command sees a written env.d while the same executor with MachineVenue=false does
not, the unprivileged-vs-sudo split, and the shell VenueDescriptor round-trip
preserving MachineVenue.
Assisted-by: OpenCode ollama-cloud deepseek-v4.1-flash (fully tested and validated)
Review — BLOCKHead SHA: Change class: code — executor-fabric behavior change in the Comment thread: 0 comments — nothing to disposition. Blocks
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
…e invariant, stale comment
Three review findings on the charly#814 producer fix:
1. (R1 — stale comment) deploy_chain.go's doc block above RootExecutorForDeployNode said
"Returns ShellExecutor{} for a nil node" while the code returns
`ShellExecutor{MachineVenue: true}`. Corrected to "Returns a MACHINE ShellExecutor for
a nil node".
2. (B13/RDD — untested producer claim) VenueFromDescriptor("shell") now returns
MachineVenue=true, which is safe only if a container-bound command cannot round-trip
into a "shell" descriptor. TestDescriptorFromExecutor_JumpTransportsNeverEmitShellKind
proves the PRODUCER half: every jump transport (container-exec, nested SSH) reports
"container"/"" — never "shell"; the machine ShellExecutor itself is the "shell"
descriptor. The venue_descriptor.go comment is corrected to state this accurately
(it previously over-claimed that a bare ShellExecutor is never described as "shell",
which the synthetic case falsifies; the real invariant is that a jump TRANSPORT — a
*NestedExecutor* — never reports "shell", and its bare parent is never itself
described).
3. (A1 — no pasted evidence) the PR body is re-finalized with real build/vet/test/lint
output.
Assisted-by: OpenCode ollama-cloud deepseek-v4.1-flash (fully tested and validated)
Review — BLOCKHead SHA: Change class: code — executor-fabric behavior change in the Security screen: PASS (no T1–T4 finding: no scope creep, no secrets/egress, no weakened guardrail, no supply-chain change). Comment thread (1 comment) — dispositions:
Blocks
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
…01 review) The review's Block 1: the SSHexecutor and NestedExecutor additions shipped with no test that fails without them — the six prior tests only exercised ShellExecutor (and DescriptorFromExecutor, which never reaches prepareJump/run/RunCapture). Add two behavioral tests: - TestSSHExecutorMachineVenueUserNotRoot: the SSH venue (always a machine venue) prefixes the env.d preamble on the UNPRIVILEGED leg and NOT the sudo leg — the same contract as the local ShellExecutor (a candy's `env:` is the guest user's; `sudo` resets HOME to root's). - TestNestedExecutorPrepareJumpEnvPreamble: a JumpSSH payload is prefixed (so it lands inside the guest), while a JumpContainerExec payload is NOT (a container's env comes from the image's ENV). Both FAIL with the respective prefixing removed (measured: "a JumpSSH payload must carry the env.d preamble") and PASS with it. Assisted-by: OpenCode ollama-cloud deepseek-v4.1-flash (fully tested and validated)
Review — BLOCKHead SHA: Change class: code — executor-fabric behavior change in the Security screen: PASS (no T1–T4 finding: no scope creep, no secrets/egress, no weakened guardrail, no supply-chain change; Blocks
Comment dispositions (all posted by
|
…spec#201 review)
The B12 finding: the headline #814 path on a VM venue is SSHExecutor.RunCapture - the
leg the check engine's `command:` probe reaches - and it had no test that fails without
the change. TestSSHExecutorRunCaptureStdinCarriesPreamble puts a fake `ssh` on PATH that
captures the stdin it is handed, and asserts the env.d preamble is there. Measured: it
FAILS with the prefixing removed ("SSHExecutor.RunCapture stdin must carry the env.d
preamble") and passes with it.
Assisted-by: OpenCode ollama-cloud deepseek-v4.1-flash (fully tested and validated)
Review — PASSHead SHA: Security screen: PASS (no T1–T4 finding: no scope creep — the diff does exactly what the placement table says; no secrets/egress; Comments (all
Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
Summary
Make a candy's
env:reachable to non-interactive commands on a machine venue(
target: local,target: vm), so a deployrun:/check:and acommand:checkprobe see the same env an interactive shell would. Fixes #814.
The defect
A candy's
env:compiles to~/.config/opencharly/env.d/<candy>.env, sourced by amanaged block charly writes into the venue's shell INIT file (
~/.bashrc). bash sourcesthat file only for an INTERACTIVE shell, so on a machine venue:
check:/run:command,command:probe, andcharly vm ssh <box> -- '<cmd>'ran without the candy's env. A candy whose own
check:asserts its env — thedsh-tuicandy'sprintenv DSH_TUI_NO_LAUNCHPAD— therefore failed on a machine venueeven though the deploy wrote its env file correctly. The image/pod path is unaffected
(there the env is a container
ENV, present to every process), which is why the samecheck had never been exercised: under the pod path it SKIPs on an unresolved variable.
The fix
Prefix each non-interactive rendered command with a POSIX-sh preamble that sources the
venue user's own env.d directory:
$HOMEis expanded on the venue (the snippet runs there), so one constant servesevery machine venue.
[ -r ]guard), so a venuewith no env.d is unaffected.
;lets a caller concatenate its command.Both the deploy walk and the check engine converge on these leaf executors, so
prefixing the shared non-interactive spawn helpers makes the SAME env reachable to a
check:probe and a deployrun:at once (R3 — one rule, all call sites).Placement — opt-in, so the container substrate is untouched
ShellExecutor.MachineVenue booltruefor atarget: local/host: localroot (RootExecutorForDeployNode) and for a re-materializedshellVenueDescriptor.falsefor the throwawayShellExecutor{}a container-jumpNestedExecutoruses purely as a LOCAL HOST transport — its payload executes INSIDE the container, whose env already comes from the image'sENV, so the host's env.d must not leak in.ShellExecutor(run+RunCapture)sudoleg: a candy'senv:is the deploying user's, whilesudoresetsHOMEto root's — so the user-scoped env is neither reachable nor intended there.RunCaptureis the leg the check engine'scommand:probe reaches.SSHExecutor(run+RunCapture)NestedExecutor.prepareJumpJumpSSH(nested-in-VM) payload is prefixed before the wrap, so it lands inside the guest; aJumpContainerExecpayload is not.How tested
The class gate — this module's OWN committed CI (the rulebook's class matrix)
Per the R10 change-class matrix (
/charly-check:check,references/beds-and-r10.md),a contract / library module — a Go module with no
charly.ymlproject, nomain/deployable target, and therefore nodisposable: trueentity; the matrix namesgithub.com/opencharly/spec+github.com/opencharly/sdk— has class gate "nonebeyond the suite": run the repo's own committed module CI green, and the rule says
"A change whose behaviour is observable only at a CONSUMER's live boundary names the
consumer PR running that bed — the bed rides the consumer change (producer→consumer
order, B6), never the library PR".
The matrix's
no disposable targetpremise is a negative claim, proven here withexecuted output.
spechas no candies/boxes and no deploy/check/vm/local entity — itscharly.ymldeclares only thekind: taskmaintenance surface:(the only
disposable: truestrings in the repo are in CHANGELOG prose, never anauthored entity;
git grep -cover config globs returns no match.)The module CI, executed on this head (
3ae2fc2)(The changed package
execruns its whole suite here — 7.828s, not the-run-filteredsubset below.)
The change's own tests — they FAIL without it
All four legs (
ShellExecutorunprivileged+sudo split,SSHExecutorunprivileged+sudo split,
NestedExecutor.prepareJumpJumpSSH-vs-JumpContainerExec, andthe descriptor producer claim) are covered by behavioral tests in
exec/venue_envd_test.go:Each FAILS with its leg's prefixing removed, measured:
TestDescriptorFromExecutor_JumpTransportsNeverEmitShellKind(the B13/RDDproducer-claim guard): every jump transport reports
"container"/""— never"shell"— so a re-materialized shell venue (MachineVenue: true) can only ever bethe machine venue, never a container-bound command's local host transport.
The consumer boundary (producer → consumer, B6)
The live end-to-end proof is at the consumer boundary the matrix names: the
distro-cachyos#125check-dsh-cachyos-vmbed (which composes thedsh-tuicandy whoseprintenv DSH_TUI_NO_LAUNCHPADcheck is the exact#814symptom) rides thecharlypin bump that adopts this tag —
charly#816/its successor — never this library PR.Rulebook compliance
/charly-internals:go,/charly-internals:plugin(the contract/library-module placement), and
/charly-internals:git-workflowbefore editing.this is that fix. The review's stale-comment finding (deploy_chain.go) is corrected.
env:contract.sdk/kit-localEnvdPreamblehalf-work was reverted in favour of this ONE home.git statusclean before commit; no force-push.specis a library module (no binary); the gates are its own CI, run green above.bed named (its PR runs it). B13/RDD producer claim proven by a test.
Change classification
Library/mechanism change in the
speccontract module (exec/— the executor fabric)plus its unit tests. Class gate per the matrix's contract/library-module row: the
module's own committed CI, plus the named consumer bed on the adopting charly pin.
Closes #814.
Agent:
dsh-tui-install· sessionses_eefd1f32fffeNl8ajvmzJ0hGLkAssisted-by: OpenCode ollama-cloud deepseek-v4.1-flash (fully tested and validated)