Files
lemonade/test/test_tray_https.py
Jeremy FowersandClaude Opus 5 ffcfd6b595 ci: run packaging, PPA, distro, macOS and backend-validation jobs in the merge queue (#2911)
* ci: gate Fedora RPM and Debian 13 packaging behind the merge queue

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: gate Launchpad PPA binary builds behind the merge queue

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: gate Linux distro builds behind the merge queue

Drops the pull_request paths filter so the required check always reports;
a workflow that never triggers leaves it pending forever.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: gate llama.cpp, vLLM and sd.cpp validation behind the merge queue

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: validate committed backend pins in the merge queue

The validation workflows used `event_name != 'pull_request'` to mean both
"do the expensive work" and "resolve upstream releases instead of the
committed pins". Adding merge_group flipped both, so the required gate
validated whatever releases/latest returned rather than the queued commit
— a bad upstream release would have blocked every PR in the queue.

Scopes release discovery to schedule/workflow_dispatch, and runs the lite
matrix in the queue as PRs did.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: defer most macOS jobs to the merge queue, add ci:macos / ci:distros

macOS runners are the scarcest GitHub-hosted resource (org-wide cap: 5
concurrent) and observed queue waits on PR pushes reach 40+ minutes.
Build Embeddable Lemonade (macOS) stays on every PR push as the AppleClang
compile canary; the dmg/pkg build, its CLI/endpoint suite and the embeddable
archive smoke test move to the merge queue behind a new "macOS builds" gate.

Both escape hatches are opt-in per PR: label ci:macos or ci:distros.

- test-cli-endpoints splits into per-OS jobs so the macOS half can skip at
  job level. "Test CLI/Endpoints (macos-latest)" is a required check, and a
  required context that is never created leaves a PR pending forever, whereas
  a job skipped by `if:` reports success.
- The embeddable smoke steps move to a composite action so the macOS leg can
  become its own skippable job without duplicating them.
- test-dmg-inference is restricted to the unsigned fork-PR path. Every test
  step in it is conditioned on has_signing != 'true', so with signing secrets
  present it installed the .pkg and then ran nothing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: run Metal inference tests on the signed path so they gate merges

test-dmg-inference conditioned every test step on has_signing != 'true', so
llamacpp-metal, whisper-metal and kokoro-metal only ever ran on the unsigned
fork-PR path. merge_group is a signed context, so Metal inference never gated
a merge.

The job now resolves LEMOND_BIN/CLI_BINARY per path — installed .pkg when
signing secrets are present, build dir otherwise — and runs the same tests
against either. lemond is restarted explicitly so it inherits
GGML_METAL_NO_RESIDENCY; on the signed path that needs sudo because the .pkg
postflight starts it via launchd as root.

whisper-metal is dropped from build-lemonade-macos-dmg's inline unsigned
steps, since test-dmg-inference now covers it on both paths.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: move the moonshine test alongside the other macOS inference tests

Same gap as the Metal tests: moonshine ran only in
build-lemonade-macos-dmg's inline unsigned steps, so it never gated a merge.
It moves to test-dmg-inference, which now runs on both signing paths.

That leaves the last consumer of the inline "restart lemond so Metal env is
inherited" step with nothing to run, so it goes too. The macOS split is now
uniform: non-inference suite signed in test-cli-endpoints-macos and unsigned
inline in the build job, inference suite in test-dmg-inference on both.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: build a .pkg on both signing paths and unify the macOS test jobs

Packaging never needed Apple credentials — only notarization does.
package-macos and notarize are already separate CMake targets, and CPack only
passes productbuild --sign when INSTALLER_IDENTITY is set. The build action
conflated the two, so "no signing secrets" meant "no package at all", which
forced fork PRs to ship raw binaries, which forced a second install procedure
and a second set of tests.

build-macos-dmg now always runs package-macos (ad-hoc binaries, unsigned
installer when secrets are absent) and runs notarize only when signing.
build-lemonade-macos-dmg uploads lemonade-macos-pkg unconditionally.

test-cli-endpoints-macos and test-dmg-inference install that .pkg with no
has_signing branching. The two CLI/endpoint suites had drifted apart in both
directions, so the unified job is their union: server_router.py and
test_llamacpp_system_backend.py from the signed side, server_jobs.py,
server_websocket_auth.py, test_model_name_normalization.py and
test_tray_https.py from the unsigned side. All 16 macOS test scripts that ran
before still run.

Drops the inline unsigned test block from the build job and the
lemonade-unsigned-binaries artifact, so a fork-PR test failure no longer
reports as a failure of the required Build Lemonade macOS .dmg check.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: add disable_macos_signing dispatch input to exercise the unsigned path

Same-repo runs always have Apple secrets, so the unsigned macOS path is only
reachable from a fork PR. This input forces has_signing=false on demand,
making that path reproducible without one.

It also skips test-exe-inference and test-deb-inference, since a macOS
signing probe has no reason to occupy the self-hosted rigs.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: fix the two tests that assumed a build tree or a surviving server

test_tray_https.py hardcoded ./build/lemonade-tray and pointed
XDG_RUNTIME_DIR at ./build. It only ever ran inside the macOS build job, so
the build-tree assumption was invisible; it now accepts an installed binary
via LEMONADE_TRAY_BINARY, the build dir, or PATH, and uses a temp runtime dir.

Kokoro runs last in test-dmg-inference: evicting a Kokoro model takes lemond
down with it (#2916), so nothing may follow it in the same job. Moonshine and
Kokoro only became adjacent when the inference tests were unified.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: label every gated group, and document the policy

ci:distros now also activates the Launchpad PPA builds, and a new ci:upgrades
label activates the llama.cpp, vLLM and stable-diffusion.cpp validation
workflows. Every job that defers to the merge queue is now reachable from a
PR by label; nothing is merge-queue-only.

docs/dev/testing.md gains a short section on what defers, which label opts it
back in, and the two consequences that bite: a green unlabeled PR says
nothing about macOS or packaging, and a new suite added to a gated job only
runs in the queue by default.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* docs: keep the CI Expectations bullets with their intro paragraph

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: wait for both address families before restarting lemond

test-dmg-inference killed the .pkg-started lemond and then waited on
localhost before starting its own. On macOS localhost resolves to ::1 first,
so the wait returned as soon as the IPv6 socket was released while the IPv4
socket was still held. The new lemond then failed its IPv4 bind, logged it,
and served IPv6-only.

Every suite that talks to localhost kept passing against that half-bound
server; test/server_moonshine.py, which hardcodes 127.0.0.1, got
ECONNREFUSED. The wait now polls lsof for any listener on the port, and
readiness requires both 127.0.0.1 and [::1] so a half-bind fails loudly
instead of masquerading as a healthy server.

The Kokoro ordering comment is removed: it was based on a misreading of the
first failure, filed as #2916 and now closed in favor of #2917.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: stop the .pkg-started tray agent before the tray test

postinst-full-mac bootstraps com.lemonade.tray into the GUI domain, and the
tray is single-instance, so test_tray_https.py could not start its own
instance and failed with "lemonade-tray is already running". The test only
ever ran from a build tree before, where nothing had been installed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: make the macOS inference server restart race-free

The previous attempt failed in a way that looked like success. `launchctl
bootout` is asynchronous, so the .pkg-started lemond still held
127.0.0.1:13305 when the replacement started; the replacement logged "Port
13305 is already in use ... will now exit" and died, and the health check
then passed against the departing launchd instance. All four inference suites
subsequently failed with "Server is not running on port 13305".

The wait now polls until the port is genuinely free and hard-fails if it is
not, and readiness additionally checks that this job's own lemond process is
still alive, so a foreign server can no longer satisfy it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: address independent review findings

- launchpad-ppa: a ci:distros PR now builds the binary package, matching what
  the merge queue runs. It was building a source-only package, so the label
  opted into a strictly weaker check than the one it is meant to reproduce.
- test-cli-endpoints-macos now starts its own lemond instead of using the
  launchd instance, which inherits only the plist environment. The job
  declared GGML_METAL_NO_RESIDENCY and HF_HOME that never reached the server,
  and four suites moved into this job previously ran against a server that
  did inherit them.
- The restart dance is now .github/actions/restart-lemond-macos, shared by
  both macOS test jobs, and uses sudo for lsof: an unprivileged lsof cannot
  see a root-owned socket, so the port-free check was a false negative.
- Drop `unlabeled` from pull_request types. The auto-labeler fires on every
  newly opened PR, so label events already cost one cancel-and-restart;
  removing a label only ever drops work and does not need to re-trigger.
- Upload the .pkg with `if: always()` so an inline unit-test failure does not
  surface downstream as a missing artifact.
- Raise test-cli-endpoints-macos to 45m: it now runs a superset of the
  Windows suites.
- test_tray_https.py fails loudly when LEMONADE_TRAY_BINARY points nowhere
  instead of silently falling back.
- Stale metadata in build-macos-dmg, and a docs line that overstated .pkg
  coverage.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: verify the macOS test server is actually ours before running tests

kill -0 was the wrong liveness check. The child is disowned, so an exited
lemond lingers as an unreaped zombie and kill -0 keeps succeeding — which is
why the step reported "Server listening ... (PID 2775)" for a process that
had already exited with "Port 13305 is already in use".

Readiness now checks the process state (treating Z as dead) and confirms the
PID holding port 13305 is ours, so a departing launchd instance answering the
health check can no longer be mistaken for the server under test.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: keep test-cli-endpoints-macos on the launchd server; widen the port wait

Making that job restart lemond was the wrong answer to the review finding.
It passed against the launchd-started server and failed once it started its
own, so the honest fix is to stop declaring GGML_METAL_NO_RESIDENCY there —
it never reached that server before this PR either — and note where Metal
coverage actually lives.

For test-dmg-inference, which does need its own server, the port-free wait
now matches any socket state rather than LISTEN only: a socket in TIME_WAIT
still fails the IPv4 bind while -sTCP:LISTEN reports the port as free, which
is how a half-bound server got through.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: give lemond the Metal setting via launchd instead of restarting it

Killing the .pkg-started server and launching a replacement lost the race for
127.0.0.1:13305 in six consecutive runs. lemond binds the two address
families separately and keeps serving when only one succeeds, so the
replacement came up IPv6-only and every test using a literal IPv4 address
failed. Widening the port wait to non-LISTEN states did not close it.

Setting GGML_METAL_NO_RESIDENCY in the launchd domain before installing means
the postflight-started server has it from birth, with no restart and no race.
The job-level env still covers the install action's manual fallback, which
runs in the step's own shell. A new step asserts the setting actually reached
the listening process via `ps eww` rather than assuming it, so a server
without it fails the job instead of quietly testing something else.

test-cli-endpoints-macos already worked this way and passed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
2026-08-07 00:45:15 +00:00

145 lines
4.5 KiB
Python

import os
import shutil
import subprocess
import sys
import tempfile
import time
import http.server
import ssl
import threading
class MockHTTPSHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/api/v1/health":
self.server.health_checked = True
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.end_headers()
self.wfile.write(b'{"status":"ok"}')
else:
self.send_response(404)
self.end_headers()
def log_message(self, format, *args):
pass # Suppress output
def run_test():
with tempfile.TemporaryDirectory() as tmpdir:
key_path = os.path.join(tmpdir, "key.pem")
cert_path = os.path.join(tmpdir, "cert.pem")
# Generate self-signed certificate
try:
subprocess.run(
[
"openssl",
"req",
"-new",
"-newkey",
"rsa:2048",
"-days",
"1",
"-nodes",
"-x509",
"-subj",
"/CN=localhost",
"-keyout",
key_path,
"-out",
cert_path,
],
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
except Exception as e:
print(f"Error generating self-signed cert: {e}", file=sys.stderr)
sys.exit(1)
# Start Mock HTTPS Server on ephemeral port
server = http.server.HTTPServer(("127.0.0.1", 0), MockHTTPSHandler)
server.health_checked = False
port = server.server_port
# Wrap socket with SSL
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain(certfile=cert_path, keyfile=key_path)
server.socket = context.wrap_socket(server.socket, server_side=True)
server_thread = threading.Thread(target=server.serve_forever)
server_thread.daemon = True
server_thread.start()
# Accept either a build tree or an installed package.
override = os.environ.get("LEMONADE_TRAY_BINARY")
if override:
binary_path = override
else:
binary_path = "./build/lemonade-tray"
if not os.path.exists(binary_path):
binary_path = shutil.which("lemonade-tray") or binary_path
if not os.path.exists(binary_path):
print(f"lemonade-tray binary not found at {binary_path}", file=sys.stderr)
sys.exit(1)
runtime_dir = os.path.join(tmpdir, "runtime")
os.makedirs(runtime_dir, mode=0o700, exist_ok=True)
# Launch lemonade-tray pointing to mock HTTPS server
env = os.environ.copy()
env["LEMONADE_SKIP_VERIFY"] = "1"
env["XDG_RUNTIME_DIR"] = runtime_dir
env["RUNTIME_DIRECTORY"] = runtime_dir
proc = subprocess.Popen(
[binary_path, "--host", f"https://localhost:{port}", "--port", str(port)],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
env=env,
)
# Poll until mock HTTPS server receives a health check request
start_time = time.time()
success = False
while time.time() - start_time < 5:
if getattr(server, "health_checked", False):
success = True
break
if proc.poll() is not None:
# Process exited early
break
time.sleep(0.1)
proc.terminate()
stdout_data = ""
stderr_data = ""
try:
stdout_data, stderr_data = proc.communicate(timeout=1)
except subprocess.TimeoutExpired:
proc.kill()
try:
stdout_data, stderr_data = proc.communicate(timeout=1)
except Exception:
pass
server.shutdown()
server.server_close()
if success:
print("[PASS] HTTPS Tray E2E Smoke Test passed successfully.")
sys.exit(0)
else:
print("[FAIL] HTTPS Tray E2E Smoke Test failed.", file=sys.stderr)
print(f"Stdout: {stdout_data}", file=sys.stderr)
print(f"Stderr: {stderr_data}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
run_test()