richfrem/agent-plugins-skills / plugins/agent-agentic-os/.apm/skills/running-control-plane
running-control-plane
FlaggedCRITICAL INTAKE GATEWAY: use at the start of any non-trivial engineering task, feature, refactor, multi-file bugfix, work package or new idea, including requests to explore, brainstorm, build, fix or change something, before planning or code changes. Enforces read-only discovery, 1-3 structured questions with defaults, control-plane registration and the immutable four-pillar TASK_SPEC.md. Also runs the rest of the control plane: health ("run health check", "check os metrics", "system monitor", event bus, locks, memory, "is my signing identity ready" status check), transition simulation ("dry run transition", "simulate transition", "check edge X -> Y"), worktree selection, and gating on/off ("disable the control plane", "turn off the push guard", "stop gating my commits"). Not for project setup or key creation (use setting-up-agentic-os) or improving skills (use improving-skills-in-lab).
tests/test_os_init_identity_bootstrap.py
View on GitHub"""
test_os_init_identity_bootstrap.py - init registers the human's identity, but only for a human.
Purpose:
A first init run used to leave the repo with gates wired and nobody authorized, and printed a setup
command that did not exist in consumer repos. Now:
* run in a human's interactive terminal, init OFFERS to enroll the human's key (it delegates to
setup_ciba_identity.py, which itself refuses without a terminal or as the agent account);
* run by an agent (no terminal) it enrolls NOTHING and prints a command that exists in the repo,
naming the key already on the machine;
* the agent's own simulation identity is created by default (it can never approve real work).
The invariant under test: init never creates or writes the human's trust file without a human.
"""
import os
import select
import shutil
import subprocess
import sys
import time
from pathlib import Path
import pytest
import init_agentic_os as init
INIT = Path(init.__file__).resolve()
SETUP = INIT.parent / "setup_ciba_identity.py" # the human setup script ships beside init
HAS_SSH_KEYGEN = shutil.which("ssh-keygen") is not None
@pytest.fixture
def repo(tmp_path):
root = tmp_path / "repo"
root.mkdir()
for cmd in (["git", "init", "-q"], ["git", "config", "user.email", "a@b.c"], ["git", "config", "user.name", "T"],
["git", "commit", "--allow-empty", "-q", "-m", "x"]):
subprocess.run(cmd, cwd=root, check=True, capture_output=True)
return root
def _boom(*a, **k):
raise AssertionError("the human setup must not run here")
def _never_asked(prompt):
raise AssertionError(f"must not prompt here: {prompt!r}")
# ---- finding the right command -----------------------------------------------------------------
def test_command_names_the_setup_script_that_ships_with_init(repo):
assert init.find_setup_script(repo) == SETUP
assert init.human_setup_command(repo) == f"python3 {SETUP}" # absolute: valid under any APM install location
def test_the_setup_script_exists_beside_init():
found = init.find_setup_script(Path("/nonexistent"))
assert found is not None and found.name == "setup_ciba_identity.py" and found.parent == INIT.parent
# ---- the offer: who may enroll -----------------------------------------------------------------
def test_non_interactive_never_enrolls_and_never_prompts(repo, capsys):
result = init.register_human_identity_step(repo, False, interactive=False, run=_boom, ask=_never_asked)
assert result == "not-interactive"
assert not (repo / "context" / "identity").exists()
out = capsys.readouterr().out
assert "Not enrolling from a non-interactive/agent context" in out
assert f"python3 {SETUP}" in out
def test_dry_run_neither_prompts_nor_runs(repo):
assert init.register_human_identity_step(repo, True, interactive=True, run=_boom, ask=_never_asked) == "dry-run"
def test_already_set_up_is_left_alone(repo, monkeypatch):
monkeypatch.setattr("control_plane.identity_setup.identity_status", lambda layout, **k: {"ready": True})
assert init.register_human_identity_step(repo, False, interactive=True, run=_boom, ask=_never_asked) == "already-ready"
def test_interactive_decline_runs_nothing(repo, capsys):
result = init.register_human_identity_step(repo, False, interactive=True, run=_boom, ask=lambda p: "n")
assert result == "declined"
assert not (repo / "context" / "identity").exists()
assert "Skipped. Later, run:" in capsys.readouterr().out
@pytest.mark.parametrize("answer", ["y", "Y", "yes", " YES "])
def test_interactive_accept_delegates_to_the_human_setup_script(repo, answer):
script = SETUP
calls = []
def fake_run(cmd, cwd=None, **k):
calls.append((cmd, cwd))
return subprocess.CompletedProcess(cmd, 0)
assert init.register_human_identity_step(repo, False, interactive=True, run=fake_run, ask=lambda p: answer) == "enrolled"
assert calls == [([sys.executable, str(script), "--repo-root", str(repo)], str(repo))]
def test_a_failed_setup_is_reported_not_swallowed(repo, capsys):
result = init.register_human_identity_step(
repo, False, interactive=True, ask=lambda p: "y", run=lambda cmd, **k: subprocess.CompletedProcess(cmd, 2))
assert result == "failed"
assert "did not complete (exit 2)" in capsys.readouterr().out
def test_missing_setup_script_is_reported(repo, monkeypatch):
monkeypatch.setattr(init, "find_setup_script", lambda target: None)
assert init.register_human_identity_step(repo, False, interactive=True, run=_boom, ask=_never_asked) == "unavailable"
# ---- the key already on this machine (public half only) --------------------------------------------
@pytest.mark.skipif(not HAS_SSH_KEYGEN, reason="ssh-keygen not available")
def test_machine_key_note_reports_the_public_fingerprint(tmp_path, monkeypatch):
home = tmp_path / "home"
(home / ".ssh").mkdir(parents=True)
subprocess.run(["ssh-keygen", "-q", "-t", "ed25519", "-N", "", "-f", str(home / ".ssh" / "agentic-os_signing")],
check=True, capture_output=True)
monkeypatch.setenv("HOME", str(home))
note = init.machine_key_note()
assert note and note.startswith("SHA256:") and "agentic-os_signing.pub" in note
assert "PRIVATE" not in note and not note.endswith("agentic-os_signing)") # only ever the .pub
def test_machine_key_note_is_none_without_a_key(tmp_path, monkeypatch):
monkeypatch.setenv("HOME", str(tmp_path / "empty-home"))
assert init.machine_key_note() is None
# ---- end to end through the real CLI ----------------------------------------------------------------
def _run_init(root, *extra):
return subprocess.run([sys.executable, str(INIT), "--target", str(root), "--retrofit", *extra],
capture_output=True, text=True, stdin=subprocess.DEVNULL)
@pytest.mark.skipif(not HAS_SSH_KEYGEN, reason="ssh-keygen not available")
def test_agent_run_init_creates_the_simulation_identity_but_never_the_human_one(repo):
res = _run_init(repo)
assert res.returncode == 0, res.stdout + res.stderr
assert (repo / "context" / "simulation" / "identity" / "simulation_key").exists()
assert not (repo / "context" / "identity").exists() # the human's trust file: never, without a human
assert "Not enrolling from a non-interactive/agent context" in res.stdout
assert "Simulation: ready" in res.stdout
@pytest.mark.skipif(not HAS_SSH_KEYGEN, reason="ssh-keygen not available")
def test_flags_opt_out_of_each_identity_step(repo):
res = _run_init(repo, "--no-simulation-identity", "--no-identity-prompt")
assert res.returncode == 0, res.stdout + res.stderr
assert not (repo / "context" / "simulation" / "identity").exists()
assert not (repo / "context" / "identity").exists()
assert "Not enrolling from a non-interactive/agent context" not in res.stdout
@pytest.mark.skipif(not HAS_SSH_KEYGEN, reason="ssh-keygen not available")
def test_printed_next_step_command_exists_in_the_repo(repo):
res = _run_init(repo)
assert f"python3 {SETUP}" in res.stdout
assert "plugins/agent-agentic-os/skills/setting-up-agentic-os/scripts/setup_ciba_identity.py" not in res.stdout
@pytest.mark.skipif(sys.platform.startswith("win"), reason="needs a POSIX pseudo-terminal")
@pytest.mark.skipif(not HAS_SSH_KEYGEN, reason="ssh-keygen not available")
def test_the_offer_appears_only_with_a_real_terminal_and_declining_changes_nothing(repo, tmp_path):
import pty
master, slave = pty.openpty()
env = {**os.environ, "HOME": str(tmp_path / "home")} # never touch the real ~/.ssh
(tmp_path / "home").mkdir()
# In a real terminal init first asks the plugin-contribution question; answer it by flag so the
# test reaches the identity offer.
proc = subprocess.Popen([sys.executable, str(INIT), "--target", str(repo), "--retrofit",
"--contribution-mode", "fork-and-pr"],
stdin=slave, stdout=slave, stderr=slave, env=env, close_fds=True)
os.close(slave)
output, deadline, answered = b"", time.time() + 90, False
while time.time() < deadline:
ready, _, _ = select.select([master], [], [], 0.5)
if ready:
try:
chunk = os.read(master, 4096)
except OSError:
break
if not chunk:
break
output += chunk
if not answered and b"Enroll your key in this repo now?" in output:
os.write(master, b"n\n") # decline
answered = True
elif proc.poll() is not None:
break
if proc.poll() is None:
proc.kill()
proc.wait(timeout=10)
os.close(master)
text = output.decode(errors="replace")
assert answered, f"the offer never appeared with a real terminal:\n{text[-800:]}"
assert "Skipped. Later, run:" in text
assert not (repo / "context" / "identity").exists() # declined: nothing enrolled
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 471k | Updated | Claude CodeCodex | Unverified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |