Repository navigation
Fix rail divider under macOS window controls #1032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
skullvalanche
wants to merge
1
commit into
TinyComms:main
Choose a base branch
from
skullvalanche:skull/rail-divider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/bin/bash | ||
| set -eu | ||
| HERE=$(cd "$(dirname "$0")" && pwd) | ||
| exec python3 "$HERE/drive.py" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| #!/usr/bin/env python3 | ||
| """Check the rail edge in a captured window from the real macOS app.""" | ||
|
|
||
| import json | ||
| import os | ||
| from pathlib import Path | ||
| import struct | ||
| import subprocess | ||
| import tempfile | ||
| import time | ||
|
|
||
| OUT = Path(os.environ["E2E_OUT"]) | ||
| BIN = Path(os.environ["E2E_APP_DIR"]) / "Contents" / "MacOS" | ||
| HELPER = os.environ["E2E_HELPER"] | ||
| T0 = float(os.environ.get("E2E_T0") or time.time()) | ||
|
|
||
|
|
||
| def step(words, ok, shot=None): | ||
| entry = {"t": round(time.time() - T0, 2), "step": words, "ok": bool(ok)} | ||
| if shot: | ||
| entry["shot"] = shot | ||
| with (OUT / "steps.jsonl").open("a", encoding="utf-8") as log: | ||
| log.write(json.dumps(entry) + "\n") | ||
| print(("[ok] " if ok else "[FAILED] ") + words, flush=True) | ||
| if not ok: | ||
| raise RuntimeError(words) | ||
|
|
||
|
|
||
| def stop(proc): | ||
| if proc is None or proc.poll() is not None: | ||
| return | ||
| proc.terminate() | ||
| try: | ||
| proc.wait(timeout=5) | ||
| except subprocess.TimeoutExpired: | ||
| proc.kill() | ||
| proc.wait(timeout=5) | ||
|
|
||
|
|
||
| def helper(*args): | ||
| log = OUT / "helper-output.txt" | ||
| log.unlink(missing_ok=True) | ||
| subprocess.run(["open", "-W", "-n", "--stdout", str(log), "--stderr", str(log), | ||
| "-a", HELPER, "--args", *map(str, args)], check=True, timeout=30) | ||
| return log.read_text(encoding="utf-8") | ||
|
|
||
|
|
||
| def until(look, seconds=25): | ||
| deadline = time.monotonic() + seconds | ||
| while time.monotonic() < deadline: | ||
| value = look() | ||
| if value: | ||
| return value | ||
| time.sleep(0.25) | ||
| return None | ||
|
|
||
|
|
||
| def pixels(path): | ||
| png = path.read_bytes() | ||
| if png[:8] != b"\x89PNG\r\n\x1a\n": | ||
| raise RuntimeError("helper did not write a PNG") | ||
| width, height = struct.unpack(">II", png[16:24]) | ||
| rgb = subprocess.run([os.environ.get("E2E_FFMPEG", "ffmpeg"), "-v", "error", "-i", str(path), | ||
| "-f", "rawvideo", "-pix_fmt", "rgb24", "-"], check=True, | ||
| capture_output=True, timeout=20).stdout | ||
| if len(rgb) != width * height * 3: | ||
| raise RuntimeError("window image has the wrong pixel count") | ||
| return width, height, rgb | ||
|
|
||
|
|
||
| def edge_strength(rgb, width, x, y): | ||
| at = (y * width + x) * 3 | ||
| beside = (y * width + x - 6) * 3 | ||
| return sum(abs(rgb[at + channel] - rgb[beside + channel]) for channel in range(3)) | ||
|
|
||
|
|
||
| def divider_begins_below_strip(path, window_width): | ||
| width, height, rgb = pixels(path) | ||
| scale = width / window_width | ||
| if height < 120 * scale: | ||
| raise RuntimeError("the app window is too short to inspect the rail") | ||
| # Find the one-pixel edge near the 72-point rail boundary. The comparison pixel is safely | ||
| # inside the rail. Both samples are below the traffic lights and away from rail buttons. | ||
| candidates = range(round(70 * scale), round(73 * scale)) | ||
| upper = range(round(37 * scale), round(47 * scale)) | ||
| lower = range(round(65 * scale), round(85 * scale)) | ||
| scores = [] | ||
| for x in candidates: | ||
| top = sum(edge_strength(rgb, width, x, y) for y in upper) / len(upper) | ||
| bottom = sum(edge_strength(rgb, width, x, y) for y in lower) / len(lower) | ||
| scores.append((bottom, top, x)) | ||
| bottom, top, _ = max(scores) | ||
| return bottom >= 10 and top < bottom * 0.4 | ||
|
|
||
|
|
||
| def run(data): | ||
| env = dict(os.environ, TINYCLIENT_DIR=str(data)) | ||
| daemon = window = None | ||
| with (OUT / "app.log").open("wb") as log: | ||
| try: | ||
| daemon = subprocess.Popen([BIN / "chatd", "--seed-demo=live"], env=env, stdout=log, stderr=log) | ||
| step("demo chat service responds", until(lambda: subprocess.run( | ||
| [BIN / "tinyclient", "--text"], env=env, capture_output=True, timeout=5).returncode == 0)) | ||
| window = subprocess.Popen([BIN / "tinyclient"], env=env, stdout=log, stderr=log) | ||
| (OUT / "app.pid").write_text(str(window.pid), encoding="utf-8") | ||
|
|
||
| def visible(): | ||
| lines = helper("windows", "--pid", window.pid).splitlines() | ||
| return json.loads(lines[0]) if lines and lines[0].startswith("{") else None | ||
|
|
||
| info = until(visible) | ||
| step("the app window appears", info) | ||
| time.sleep(2) | ||
| shot = OUT / "rail-divider.png" | ||
| step("the lab helper captured the app window", "ok shot" in helper("shot", "--pid", window.pid, "--out", shot) | ||
| and shot.exists(), shot.name) | ||
| step("rail edge starts below the traffic lights", divider_begins_below_strip(shot, info["w"]), shot.name) | ||
| time.sleep(1) | ||
| finally: | ||
| stop(window) | ||
| stop(daemon) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| OUT.mkdir(parents=True, exist_ok=True) | ||
| (OUT / "steps.jsonl").write_text("", encoding="utf-8") | ||
| try: | ||
| with tempfile.TemporaryDirectory(prefix="tiny-rail-divider-", dir="/tmp") as data_dir: | ||
| run(Path(data_dir)) | ||
| except (RuntimeError, OSError, subprocess.SubprocessError) as error: | ||
| print(error, flush=True) | ||
| raise SystemExit(1) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "id": "rail-divider", | ||
| "title": "The macOS rail divider begins below the window controls", | ||
| "platforms": ["macos"], | ||
| "not_applicable": { | ||
| "windows": "Windows has no macOS traffic lights; its rail divider remains full height.", | ||
| "linux": "Linux has no macOS traffic lights; its rail divider remains full height.", | ||
| "android": "The phone layout has no macOS window controls.", | ||
| "ios": "The phone layout has no macOS window controls." | ||
| }, | ||
| "needs": [], | ||
| "release": false | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Residual: this runs
ffmpegfrom$E2E_FFMPEGorPATH, butrun-macos.shexports noE2E_FFMPEGon macOS, so the lab Mac needsffmpegon the PATH of an ssh session. Same ascall-video-seen,tiny-video-receivedandgpu-codecs-wave18; none of them has run on the lab yet.