agents: login shells read the hive facts too; test the readers
Part of #5081. Follow-up to the review of #5131. - Before this PR, claude read CLAUDE_REMOTE_CONTROL_SESSION_NAME_PREFIX from managed-settings.json in every context. The environment generator reaches every unit of the container's manager, including `machinectl shell` (hivectl choom): machined starts it as a transient container-shell@ unit (systemd 260.5 src/machine/machine.c:980-1004), and every unit's exec environment starts from the manager environment the generators fill (src/core/unit.c:5557, src/core/manager.c:3990-4001). Shells no unit starts do not get it: `nixos-container root-login` / `run` enter with nsenter + `su -l`, and getty logins go through login(1). So hive-facts.nix now also exports the generator's output from /etc/set-environment (environment.extraInit). - The generator's read loop kept a last line only when it ended in a newline; it now keeps one without. - checks.script-test-agent-hive-facts runs the rendered generator and the shell snippet (under dash and bash's sh) against sample files: both facts, a planted LD_PRELOAD/PATH line, a last line without a newline, an empty file and no file. - identity.rs: hive_name()'s doc names the facts file as the source.
This commit is contained in:
parent
c87a4d2c1a
commit
c8df666bf3
6 changed files with 172 additions and 28 deletions
41
nix/script-tests/agent-hive-facts.nix
Normal file
41
nix/script-tests/agent-hive-facts.nix
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# `checks.script-test-agent-hive-facts` — runs the two readers of
|
||||
# `/etc/hyperhive-hive-facts` in ../agent-modules/hive-facts.nix: the systemd
|
||||
# environment generator and the login-shell snippet `/etc/set-environment`
|
||||
# sources. The cases are in ./agent-hive-facts.sh.
|
||||
#
|
||||
# What runs is the rendered generator and snippet. The one edit is the facts
|
||||
# file's path, moved under the build directory, and the snippet's reference to
|
||||
# the generator, pointed at that edited copy.
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
self,
|
||||
nixosSystem,
|
||||
}:
|
||||
let
|
||||
inherit
|
||||
(import ../module-eval/lib.nix {
|
||||
inherit
|
||||
pkgs
|
||||
lib
|
||||
self
|
||||
nixosSystem
|
||||
;
|
||||
})
|
||||
agentWith
|
||||
;
|
||||
|
||||
machine = agentWith { services.hyperhive.agent.user.name = "a1"; };
|
||||
in
|
||||
pkgs.runCommand "hyperhive-script-test-agent-hive-facts"
|
||||
{
|
||||
GENERATOR =
|
||||
machine.environment.etc."systemd/system-environment-generators/50-hyperhive-hive-facts".source;
|
||||
PROFILE = machine.environment.etc."hyperhive/hive-facts.sh".source;
|
||||
EXTRA_INIT = machine.environment.extraInit;
|
||||
SHELLS = "${pkgs.dash}/bin/dash ${pkgs.bash}/bin/sh";
|
||||
}
|
||||
''
|
||||
${pkgs.bash}/bin/bash ${./agent-hive-facts.sh}
|
||||
touch "$out"
|
||||
''
|
||||
Loading…
Reference in a new issue