Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions binary/tests/test_frozen_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,22 @@ def test_entry_in_a_nuitka_build_is_frozen_and_points_at_its_own_binary(monkeypa
assert sys.executable == os.path.join(os.path.abspath(REPO / "packaging"), "unbound-discovery")


def test_hook_entry_in_a_nuitka_build_points_at_its_own_binary(monkeypatch):
monkeypatch.setattr(sys, "frozen", False, raising=False)
monkeypatch.setattr(sys, "_MEIPASS", None, raising=False)
monkeypatch.setattr(sys, "executable", sys.executable)
spec = importlib.util.spec_from_file_location(
"unbound_hook_entry", REPO / "packaging" / "nuitka" / "unbound_hook_entry.py"
)
entry = importlib.util.module_from_spec(spec)
entry.__compiled__ = object() # what Nuitka defines in a compiled module
spec.loader.exec_module(entry)
bundle = os.path.abspath(REPO / "packaging" / "nuitka")
assert sys.frozen is True
assert sys._MEIPASS == bundle
assert sys.executable == os.path.join(bundle, "unbound-hook")


@pytest.mark.parametrize("supported, exit_code", [(True, 0), (False, 1)])
def test_entry_memory_fix_selftest_exits_by_the_agents_answer(monkeypatch, supported, exit_code):
seen_users = []
Expand Down
10 changes: 8 additions & 2 deletions packaging/nuitka/unbound_hook_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@

PyInstaller's bootloader sets sys.frozen and sys._MEIPASS, which
unbound_hook._resources.resource_root() uses to locate the vendored hook /
MDM setup sources. Nuitka 2.8 sets neither, so this shim provides both
before unbound_hook is imported:
MDM setup sources, and points sys.executable at the bundle's own binary.
Nuitka 2.8 does none of this, so this shim provides all three before
unbound_hook is imported:

* sys.frozen = True -> the vendored modules' frozen-mode gates engage
(discovery via the local binary), identical to the PyInstaller artifact.
* sys._MEIPASS = <dist dir> -> resource_root() resolves to
<dist>/vendored/, where build-nuitka.sh places the same data files the
.spec's VENDORED list places under PyInstaller's _MEIPASS.
* sys.executable = <dist>/unbound-hook -> the hooks' detached re-launches
(sync-skills, mcp-diagnostic, refresh-claude-ai-connectors) start this
binary. Nuitka leaves it at <dist>/python, which does not exist.

Under Nuitka --standalone the main module's __file__ lives in the dist
folder, so its dirname IS the bundle root. Run directly with python for a
Expand All @@ -29,6 +33,8 @@
if "__compiled__" in globals(): # Nuitka build only; inert under plain python
sys.frozen = True
sys._MEIPASS = os.path.dirname(os.path.abspath(__file__))
# Nuitka leaves sys.executable at <dist>/python; the hooks re-launch this binary through it.
sys.executable = os.path.join(sys._MEIPASS, "unbound-hook")
else:
# Dev fallback mirrors binary/src/entry.py: make unbound_hook importable
# from a plain repo checkout.
Expand Down
26 changes: 26 additions & 0 deletions packaging/scripts/smoke-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Smoke-run both freshly built bundles on the runner (WEB-4789):
# * --version on each binary
# * a REAL tool+event hook dispatch that proves a vendored module loaded
# * SessionStart re-launches the binary itself (sync-skills) through sys.executable
# * if Rosetta is available, repeat --version under forced x86_64 so the
# Intel slice is proven to EXECUTE, not just exist in lipo output.
# Usage: smoke-test.sh <dist-dir>
Expand Down Expand Up @@ -103,6 +104,31 @@ if grep -qv '^https://127\.0\.0\.1:9/' "$smoke_tmp/curl.log"; then
exit 1
fi

# Self re-launch: SessionStart starts a detached `<this binary> sync-skills`
# through sys.executable. A bundle whose sys.executable is not runnable
# (Nuitka points it at <dist>/python) fails open, so only the child's own
# request proves the re-launch worked: wait for its skills-sync URL in the log.
echo "--- unbound-hook hook claude-code SessionStart (sync-skills re-launch)"
: > "$smoke_tmp/curl.log"
session_start='{"hook_event_name":"SessionStart","source":"startup","session_id":"ci-smoke"}'
out="$(printf '%s' "$session_start" | env -u UNBOUND_GATEWAY_URL -u UNBOUND_DEVICE_TOKEN -u UNBOUND_CLAUDE_API_KEY \
HOME="$smoke_tmp/home" PATH="$smoke_tmp/bin:/usr/bin:/bin" \
SMOKE_CURL_LOG="$smoke_tmp/curl.log" "$hook" hook claude-code SessionStart)"
echo "$out"
synced=false
for _ in $(seq 1 30); do
if grep -qxF 'https://127.0.0.1:9/v1/hooks/skills/sync' "$smoke_tmp/curl.log"; then
synced=true
break
fi
sleep 1
done
cat "$smoke_tmp/curl.log"
if [[ "$synced" != true ]]; then
echo "FAIL: SessionStart did not re-launch '$hook sync-skills', so org skills would never sync on devices." >&2
exit 1
fi

if arch -x86_64 /usr/bin/true 2>/dev/null; then
echo "--- Rosetta present: re-running --version under x86_64"
arch -x86_64 "$hook" --version
Expand Down