Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
1cbb0ca
feat(setup): report run start and end to the install report [WEB-6392]
iyadzargar Nov 24, 2026
cb7a480
feat(setup): report every tool's setup outcome each run [WEB-6392]
iyadzargar Nov 24, 2026
4a78710
feat(backfill): send every run's outcome and carry an unsent one forw…
iyadzargar Nov 24, 2026
aef7fb9
feat(setup): forward hook errors stuck in error.log each run [WEB-6392]
iyadzargar Nov 24, 2026
fc2dafd
fix(setup): keep run report inputs from stopping the install [WEB-6392]
iyadzargar Nov 24, 2026
f895f48
fix(setup): cap and age-limit forwarded hook errors [WEB-6392]
iyadzargar Nov 24, 2026
3122695
fix(setup): count version-manager and editor installs as installed [W…
iyadzargar Nov 24, 2026
f248f2b
test(setup): guard linked error logs and redaction in forwarded hook …
iyadzargar Nov 24, 2026
e834e9b
test(setup): guard the scan output pipe against big output, held pipe…
iyadzargar Nov 24, 2026
81ca863
fix(setup): keep reading the scan's output when the MDM log can't be …
iyadzargar Nov 24, 2026
29cfcca
test(backfill): an unwritable hooks folder never breaks either upload…
iyadzargar Nov 24, 2026
223d720
fix(setup): keep report and hook-error keys off curl's command line […
iyadzargar Nov 24, 2026
11f4f62
fix(backfill): reserve enough time for the closing report to clear it…
iyadzargar Nov 24, 2026
18d225d
fix(setup): forward no hook errors where their place cannot be saved …
iyadzargar Nov 24, 2026
d66f5ce
fix(setup): let a refused key stop only its own tool's hook errors [W…
iyadzargar Nov 24, 2026
e0520ba
fix(setup): keep hook errors that share the last sent timestamp [WEB-…
iyadzargar Nov 24, 2026
7e704fd
fix(setup): forward a multi-line hook error with its later lines [WEB…
iyadzargar Nov 24, 2026
f6852ab
fix(backfill): report a run a cap cut short as stopped_by_cap [WEB-6392]
iyadzargar Nov 24, 2026
c10a63d
fix(setup): count nodenv, yarn, MacPorts and npmrc-prefix installs [W…
iyadzargar Nov 24, 2026
d8e0101
refactor(setup): find installed tools once a run and drop a dead back…
iyadzargar Nov 24, 2026
8559b6e
fix(setup): forward hook errors before the migration sweep removes Cu…
iyadzargar Nov 25, 2026
8dbb6f2
fix(setup): send one deferred report with the tamper state when every…
iyadzargar Nov 25, 2026
d6050f9
feat(setup): give each tool's MDM script the installed check the bina…
iyadzargar Nov 25, 2026
77ea00a
feat(setup): report every tool's outcome from the python MDM scripts …
iyadzargar Nov 25, 2026
0cb055d
fix(setup): skip only the home whose key the gateway refuses [WEB-6392]
iyadzargar Nov 25, 2026
8f3e7fa
fix(setup): forward hook errors with the key the hooks read first [WE…
iyadzargar Nov 25, 2026
7722b84
fix(setup): send copilot's tamper state only when every install fails…
iyadzargar Nov 25, 2026
0634eaa
fix(setup): count Copilot in Visual Studio and JetBrains as installed…
iyadzargar Nov 25, 2026
67b2eac
fix(setup): find homes and read each home's key once a run when forwa…
iyadzargar Nov 25, 2026
5732c7f
fix(setup): report the claude code settings file actually written, dr…
iyadzargar Nov 25, 2026
c7651d2
fix(backfill): report a run with an unreadable home as failed [WEB-6392]
iyadzargar Nov 26, 2026
c8651ce
fix(setup): redact every config key and common credential shapes from…
iyadzargar Nov 26, 2026
999c0fc
fix(setup): keep a hook error log the gateway has not taken across th…
iyadzargar Nov 26, 2026
b4bbbf0
fix(backfill): send a failed outcome when the run crashes before its …
iyadzargar Nov 26, 2026
fc0b1ef
fix(setup): report a tool setup that raises, and a backfill that fail…
iyadzargar Nov 26, 2026
f26394b
fix(setup): forward an oversized hook error log from its end and keep…
iyadzargar Nov 26, 2026
07984f5
fix(mdm): forward stuck hook errors from the python mdm scripts as th…
iyadzargar Nov 26, 2026
c3b5498
fix(setup): run claude-code, cursor and augment user checks through a…
iyadzargar Nov 26, 2026
f85c86c
fix(mdm): hash the copilot hook as a user's file before setup replace…
iyadzargar Nov 26, 2026
d0fcd16
fix(setup): keep a set-aside cursor log when a hook writes a new one …
iyadzargar Nov 26, 2026
e205c87
fix(setup): keep an unsent cursor log in place when it cannot be set …
iyadzargar Nov 26, 2026
77b7e4b
fix(mdm): bound every step error forwarding runs as the user, and kee…
iyadzargar Nov 26, 2026
aa983c0
fix(mdm): refuse a user's file reached through a link or junction on …
iyadzargar Nov 26, 2026
e46bdb9
fix(setup): keep every cursor log across the sweep and refuse hard li…
iyadzargar Nov 26, 2026
2b03cdf
refactor(setup): keep the cursor error log in place through cleanup i…
iyadzargar Nov 26, 2026
93b17fd
fix(setup): tell sent hook errors apart by digest at the saved timest…
iyadzargar Nov 26, 2026
10fd96a
fix(mdm): clear cursor's user hooks without following a link out of t…
iyadzargar Nov 26, 2026
8b31eab
fix(mdm): delete cursor's user hooks on windows through handles check…
iyadzargar Nov 26, 2026
5ef9e94
chore(setup): merge staging to pick up the antigravity installers [WE…
iyadzargar Nov 30, 2026
a374341
feat(mdm): report antigravity's setup outcome and forward its hook er…
iyadzargar Nov 30, 2026
d43c8a0
fix(setup): report copilot deferred when its hook installs for only s…
iyadzargar Nov 30, 2026
0925caf
fix(mdm): save a user's file on windows by handle into the checked fo…
iyadzargar Nov 30, 2026
65d25be
fix(mdm): keep setup report keys off curl's arguments and rename on w…
iyadzargar Nov 30, 2026
3f9aaed
chore(setup): merge staging and report antigravity's binary setup out…
iyadzargar Nov 30, 2026
d560a3d
fix(setup): count antigravity's config writes and forward its hook er…
iyadzargar Nov 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
595 changes: 574 additions & 21 deletions antigravity/hooks/mdm/setup.py

Large diffs are not rendered by default.

578 changes: 572 additions & 6 deletions augment/hooks/mdm/setup.py

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion binary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,21 @@ the python path, by design:
- **Per-component status** (`configured | skipped(reason) | deferred(reason)`)
with fail-open orchestration: a component failure is reported in the
summary + exit code but never aborts the others. `deferred` means a re-run
should retry; `skipped` is intentional.
should retry; `skipped` is intentional. Every tool that got its device key
sends this status, reason and `written_to` to `/api/v1/setup/complete/` each
run; a tool with no footprint on the Mac (`tool_installed()` in its MDM module) is still
written but reported `skipped` ("<Tool> is not installed"). A discovery run
that prints `Scan skipped: <reason>` is `skipped`. The run itself posts
`phase: start` first and `phase: end` last to the MDM install report.
Before the migration sweep (which removes `~/.cursor/hooks`), setup
forwards each tool's hook `error.log` entries, with the device key in the
home's `~/.unbound/config.json` (the key the hooks use), newer than
the last forwarded one to the gateway's `/v1/hooks/errors` (ten a request,
at most the newest 25 per tool and home, none older than seven days, with
`category: forwarded_error_log`),
recording the newest accepted timestamp in `.error_log_forwarded` beside the
log; a gateway that is down ends forwarding for the run, a refused key skips
that home (each home has its own key), and neither saves anything.
- **`detect_install_state`** is adapted: the python version checked for the
managed `unbound.py`, which no longer exists. Binary semantics: settings
file absent → `fresh`; present and referencing the binary → `persisted`;
Expand Down
596 changes: 525 additions & 71 deletions binary/src/unbound_hook/setup_cmd.py

Large diffs are not rendered by default.

113 changes: 113 additions & 0 deletions binary/tests/test_setup_discovery_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
"""WEB-6392: setup now reads the discovery scan's stdout (for the 'Scan skipped:' line) instead of
letting the scan inherit it. A pipe can stall a child that a shared stdout never could, so these run
_run_discovery against real child processes: a big and noisy scan, a grandchild that keeps the pipe
open, a scan that hangs past the backstop, and an MDM log that can no longer be written.
"""

import os
import signal
import sys
import time

import pytest

from unbound_hook import setup_cmd

OPTS = {"backend_url": "http://127.0.0.1:9"}
SKIPPED = ("skipped", "another scan is running")


def _scan(tmp_path, monkeypatch, body):
"""Stand in a discovery binary (a python script) and the owner-key lookup it needs."""
script = tmp_path / "unbound-discovery"
script.write_text(f"#!{sys.executable}\nimport os, subprocess, sys, time\n"
f"PIDS = {str(tmp_path / 'pids')!r}\n{body}")
script.chmod(0o755)
monkeypatch.setattr(setup_cmd, "DISCOVERY_BINARY", script)
monkeypatch.setattr(setup_cmd, "_fetch_device_owner_key", lambda opts: "owner-key")
return tmp_path / "pids"


def _alive(pid):
try:
os.kill(pid, 0)
except ProcessLookupError:
return False
return True


@pytest.fixture
def reap():
"""Kills whatever pids a scan wrote down, so no test leaves a process behind."""
files = []
yield files.append
for path in files:
for pid in (int(p) for p in path.read_text().split()) if path.exists() else ():
try:
os.kill(pid, signal.SIGKILL)
except ProcessLookupError:
pass


# A child that writes a pid down and keeps the scan's stdout open, as a helper the scan starts might.
SPAWN_HOLDER = ("holder = subprocess.Popen(['sleep', '30'])\n"
"open(PIDS, 'a').write(f'{holder.pid}\\n')\n")


def test_a_big_scan_whose_grandchild_keeps_the_pipe_is_read_through_and_not_waited_for(
tmp_path, monkeypatch, capsys, reap):
# 20 MB of output, the skipped line (CRLF) at line 500, then a grandchild holding the pipe open.
reap(_scan(tmp_path, monkeypatch,
"out = sys.stdout.buffer\nline = b'x' * 99 + b'\\n'\n"
"for _ in range(499): out.write(line)\n"
"out.write(b'Scan skipped: another scan is running\\r\\n')\n"
"for _ in range(200000): out.write(line)\n"
"out.flush()\n" + SPAWN_HOLDER))
began = time.monotonic()
assert setup_cmd._run_discovery(OPTS) == SKIPPED
# Nowhere near the grandchild's 30 s: setup gives a held pipe 5 s, then moves on.
assert time.monotonic() - began < 15
out = capsys.readouterr().out
assert out.count("x" * 99 + "\n") == 200499 # every line reached the MDM log
assert "Scan skipped: another scan is running" in out


def test_a_scan_past_the_backstop_is_killed_with_its_whole_group_and_deferred(tmp_path, monkeypatch, reap):
reap(_scan(tmp_path, monkeypatch,
SPAWN_HOLDER + "open(PIDS, 'a').write(f'{os.getpid()}\\n')\n"
"print('detecting', flush=True)\ntime.sleep(60)\n"))
monkeypatch.setattr(setup_cmd, "DISCOVERY_TIMEOUT_SECONDS", 1)
monkeypatch.setattr(setup_cmd, "DISCOVERY_KILL_GRACE_SECONDS", 0)
began = time.monotonic()
assert setup_cmd._run_discovery(OPTS) == ("deferred", "discovery exceeded 1s and was terminated")
assert time.monotonic() - began < 10
pids = [int(p) for p in (tmp_path / "pids").read_text().split()]
deadline = time.monotonic() + 5 # an orphaned grandchild is reaped by launchd/init, not by us
while any(_alive(pid) for pid in pids) and time.monotonic() < deadline:
time.sleep(0.1)
assert not [pid for pid in pids if _alive(pid)], "a scan process outlived the backstop kill"


class _UnwritableLog:
"""setup's stdout once the MDM agent reading it is gone, or the disk it goes to is full."""
encoding = "utf-8"

def write(self, text):
raise BrokenPipeError(32, "Broken pipe")

def flush(self):
raise BrokenPipeError(32, "Broken pipe")


def test_a_log_that_cannot_be_written_never_stalls_the_scan(tmp_path, monkeypatch, reap):
# Before setup piped it, the scan wrote to that log itself and carried on (its logging drops
# failed writes). Now setup must keep draining the pipe, or the scan blocks on a full one.
_scan(tmp_path, monkeypatch, "for n in range(40000): print('detecting', n)\nprint('Scan complete')\n")
monkeypatch.setattr(setup_cmd, "DISCOVERY_TIMEOUT_SECONDS", 20)
monkeypatch.setattr(setup_cmd, "DISCOVERY_KILL_GRACE_SECONDS", 0)
monkeypatch.setattr(sys, "stdout", _UnwritableLog())
began = time.monotonic()
result = setup_cmd._run_discovery(OPTS)
elapsed = time.monotonic() - began
assert result == ("configured", None)
assert elapsed < 10
26 changes: 26 additions & 0 deletions binary/tests/test_setup_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ def env(tmp_path, monkeypatch):
discovery_bin.write_text("#!/bin/sh\nexit 0\n")
discovery_bin.chmod(0o755)
monkeypatch.setattr(setup_cmd, "DISCOVERY_BINARY", discovery_bin)
# The run's own reports never leave the machine from a test; test_setup_reporting
# points them at a local server instead.
monkeypatch.setattr(setup_cmd, "_post_json", lambda *a, **k: (0, b""))
# Which tools look installed must not depend on the machine running the tests.
monkeypatch.setattr(setup_cmd, "_MACHINE_ROOT", tmp_path / "machine")
return {"tmp": tmp_path, "home": home, "modules": modules,
"notified": notified, "backfilled": backfilled, "bounded": bounded, "bootouts": bootouts,
"daemon_bootouts": daemon_bootouts}
Expand Down Expand Up @@ -1848,7 +1853,28 @@ def _as_user(_u, fn, *a, _timeout=None, **k): # the real helper returns None wh
setup_cmd.run(["--api-key", "admin-key"])
finally:
hooks_dir.chmod(0o755)
# One report: why setup deferred, carrying the tamper it found (WEB-6392).
assert _states(env, "copilot") == ["tampered"]
[report] = [k for a, k in env["notified"] if a[1] == "copilot"]
assert (report["status"], report["reason"]) == ("deferred", "hook install failed for all users")


def test_copilot_failing_for_one_of_two_users_is_deferred_not_configured(env, monkeypatch):
"""The MDM script says the same: the failed user has no hook, so the tool isn't configured on this device."""
second = env["tmp"] / "home2"
second.mkdir()
monkeypatch.setattr(env["modules"]["copilot"], "get_all_user_homes",
lambda: [(ME, env["home"]), (ME, second)])
monkeypatch.setattr(setup_cmd, "_tool_installed", lambda tool, homes: True)
real_install = setup_cmd._install_copilot_hooks_for_user
monkeypatch.setattr(setup_cmd, "_install_copilot_hooks_for_user",
lambda m, u, home: False if home == second else real_install(m, u, home))

setup_cmd.run(["--api-key", "admin-key"])

[report] = [k for a, k in env["notified"] if a[1] == "copilot"]
assert (report["status"], report["reason"]) == (
"deferred", "Installed Copilot hooks for 1 of 2 user(s) — 1 failed")


@pytest.mark.parametrize("tool", ["claude-code", "augment_code"])
Expand Down
Loading