mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-03 18:43:38 +01:00
Report collector-only automatic update scope once when the typed helper-backed updater starts, and give operators the existing preflight/update procedure without widening helper authority or misclassifying healthy monitoring. Exercise the output and the copied, saved-state update commands with credential-free fixtures. Refs: #3754 Contract-Neutral: Clarifies existing collector-only update scope and installer-managed helper maintenance; no wire, privilege, activation or recovery contract changes. Change-source: pulse-maintainer
88 lines
4.0 KiB
Python
88 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Exercise the documented helper-update commands without root or services."""
|
|
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
class AgentHelperUpdateDocsTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.document = (ROOT / "docs/UNIFIED_AGENT.md").read_text()
|
|
self.section = self.document.split("### Updating the typed helper\n", 1)[1].split(
|
|
"\n### ", 1
|
|
)[0]
|
|
|
|
def test_copyable_commands_keep_saved_profile_and_preflight_separate(self):
|
|
commands = re.findall(r"```bash\n(.*?)\n\s*```", self.section, re.S)
|
|
self.assertEqual(len(commands), 2)
|
|
# A recorder stands in for sudo; neither root nor the real installer is
|
|
# executed. Spaces in HOME must survive both copied commands unchanged.
|
|
with tempfile.TemporaryDirectory(prefix="helper update docs ") as tmp:
|
|
root = Path(tmp)
|
|
bin_dir = root / "bin"
|
|
bin_dir.mkdir()
|
|
sudo = bin_dir / "sudo"
|
|
sudo.write_text(
|
|
"#!/usr/bin/env python3\n"
|
|
"import json, os, sys\n"
|
|
"with open(os.environ['CALLS'], 'a') as out:\n"
|
|
" out.write(json.dumps(sys.argv[1:]) + '\\n')\n"
|
|
)
|
|
sudo.chmod(0o700)
|
|
calls = root / "calls.jsonl"
|
|
env = {**os.environ, "HOME": str(root / "home with spaces"),
|
|
"PATH": str(bin_dir) + os.pathsep + os.environ["PATH"],
|
|
"CALLS": str(calls)}
|
|
for command in commands:
|
|
subprocess.run(["bash", "--noprofile", "--norc", "-eu", "-c", command],
|
|
env=env, check=True, capture_output=True, text=True)
|
|
observed = [json.loads(line) for line in calls.read_text().splitlines()]
|
|
installer = str(root / "home with spaces/.config/pulse/agent-install.sh")
|
|
self.assertEqual(observed, [
|
|
["bash", installer, "--preflight-only", "--update"],
|
|
["bash", installer, "--update"],
|
|
])
|
|
|
|
def test_guidance_separates_versions_and_preserves_actual_boundaries(self):
|
|
text = " ".join(self.section.split())
|
|
for required in (
|
|
"Automatic agent updates replace the collector only.",
|
|
"do not replace or restart `pulse-agent-helper`",
|
|
"does not establish the helper's release version",
|
|
"health check confirms the requested protocol",
|
|
"no `--version` option",
|
|
"No new token is needed",
|
|
"Preflight is not installation or proof of recovery",
|
|
"least-privilege/typed-helper profile",
|
|
"effective isolated unit and socket",
|
|
"Do not uninstall, re-enrol",
|
|
"remove `PrivateNetwork`",
|
|
"not a diagnostic retest request for a healthy host",
|
|
):
|
|
with self.subTest(required=required):
|
|
self.assertIn(required, text)
|
|
self.assertEqual((ROOT / "frontend-modern/public/docs/UNIFIED_AGENT.md").read_bytes(),
|
|
(ROOT / "docs/UNIFIED_AGENT.md").read_bytes())
|
|
helper_flags = (ROOT / "cmd/pulse-agent-helper/main.go").read_text().split(
|
|
"func parseFlags(", 1)[1].split("\nfunc ", 1)[0]
|
|
self.assertNotRegex(helper_flags, r'\.(?:Bool|String)\("version"')
|
|
# Keep the procedure attached to the real installer option, not the
|
|
# similarly named public server installer or an invented helper flag.
|
|
installer = (ROOT / "scripts/install.sh").read_text()
|
|
self.assertIn('--update) UPDATE_ONLY="true"; shift ;;', installer)
|
|
self.assertIn('recover_connection_state "$lifecycle_conn_env"', installer)
|
|
self.assertIn('verify_download_signature "$TMP_HELPER_BIN" "$helper_signature"', installer)
|
|
self.assertIn('provision_typed_privileged_helper', installer)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|