Repository navigation
linux(socket): implement surface.action / tab.action (rename, pin, mark_read) #218
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
Merged
Merged
Changes from 1 commit
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
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,204 @@ | ||
| #!/usr/bin/env python3 | ||
| """Socket API: surface.action rename / clear_name / pin / unpin / mark_read / mark_unread. | ||
|
|
||
| Pure socket round-trip test — no GUI, no CLI binary, no platform-specific | ||
| filesystem assumptions. Designed to pass on both macOS and Linux daemons. | ||
| """ | ||
|
|
||
| import os | ||
| import sys | ||
| import time | ||
| from pathlib import Path | ||
|
|
||
| sys.path.insert(0, str(Path(__file__).parent)) | ||
| from cmux import cmux, cmuxError | ||
|
|
||
| SOCKET_PATH = os.environ.get("CMUX_SOCKET", "/tmp/cmux-debug.sock") | ||
|
|
||
|
|
||
| def _surfaces_in(c: cmux, workspace_id: str) -> list[dict]: | ||
| """Return raw surface.list rows (dicts) for the given workspace.""" | ||
| res = c._call("surface.list", {"workspace_id": workspace_id}) or {} | ||
| return list(res.get("surfaces") or []) | ||
|
|
||
|
|
||
| def _find_surface(rows: list[dict], surface_id: str) -> dict: | ||
| for row in rows: | ||
| if str(row.get("id")) == surface_id: | ||
| return row | ||
| raise cmuxError(f"surface {surface_id} missing from list: {rows}") | ||
|
|
||
|
|
||
| def main() -> int: | ||
| created_workspace: str | None = None | ||
| with cmux(SOCKET_PATH) as c: | ||
| # Create an isolated workspace so the test cannot disturb the user's | ||
| # current workspace state. | ||
| created_workspace = c.new_workspace() | ||
| if not created_workspace: | ||
| raise cmuxError("workspace.create returned no id") | ||
| c.select_workspace(created_workspace) | ||
| time.sleep(0.05) | ||
|
|
||
| # Locate the focused surface in the new workspace. | ||
| rows = _surfaces_in(c, created_workspace) | ||
| if not rows: | ||
| raise cmuxError(f"new workspace has no surfaces: {rows}") | ||
| focused = next((r for r in rows if r.get("focused")), rows[0]) | ||
| surface_id = str(focused["id"]) | ||
| original_title = str(focused.get("title", "")) | ||
|
|
||
| unique_title = f"renamed-via-action-{int(time.time() * 1000) % 100000}" | ||
|
|
||
| # ── rename ──────────────────────────────────────────────────────── | ||
| result = c._call( | ||
| "surface.action", | ||
| { | ||
| "workspace_id": created_workspace, | ||
| "surface_id": surface_id, | ||
| "action": "rename", | ||
| "title": unique_title, | ||
| }, | ||
| ) or {} | ||
| if result.get("action") != "rename": | ||
| raise cmuxError(f"rename: unexpected response: {result}") | ||
| if str(result.get("title")) != unique_title: | ||
| raise cmuxError(f"rename: title not echoed: {result}") | ||
|
|
||
| # Reflected in surface.list? | ||
| renamed = _find_surface(_surfaces_in(c, created_workspace), surface_id) | ||
| if str(renamed.get("title")) != unique_title: | ||
| raise cmuxError( | ||
| f"rename not reflected in surface.list: expected {unique_title!r}, " | ||
| f"got {renamed.get('title')!r}" | ||
| ) | ||
|
|
||
| # ── tab.action alias should hit the same handler ────────────────── | ||
| alias_title = f"{unique_title}-alias" | ||
| alias_result = c._call( | ||
| "tab.action", | ||
| { | ||
| "workspace_id": created_workspace, | ||
| "tab_id": surface_id, | ||
| "action": "rename", | ||
| "title": alias_title, | ||
| }, | ||
| ) or {} | ||
| if alias_result.get("action") != "rename": | ||
| raise cmuxError(f"tab.action alias: unexpected response: {alias_result}") | ||
| aliased = _find_surface(_surfaces_in(c, created_workspace), surface_id) | ||
| if str(aliased.get("title")) != alias_title: | ||
| raise cmuxError( | ||
| f"tab.action alias not reflected: expected {alias_title!r}, " | ||
| f"got {aliased.get('title')!r}" | ||
| ) | ||
|
|
||
| # ── clear_name ──────────────────────────────────────────────────── | ||
| cleared_resp = c._call( | ||
| "surface.action", | ||
| { | ||
| "workspace_id": created_workspace, | ||
| "surface_id": surface_id, | ||
| "action": "clear_name", | ||
| }, | ||
| ) or {} | ||
| if cleared_resp.get("action") != "clear_name": | ||
| raise cmuxError(f"clear_name: unexpected response: {cleared_resp}") | ||
| cleared = _find_surface(_surfaces_in(c, created_workspace), surface_id) | ||
| if str(cleared.get("title")) == alias_title: | ||
| raise cmuxError( | ||
| f"clear_name did not drop custom title: still {cleared.get('title')!r}" | ||
| ) | ||
| # Title falls back to process title or "Terminal"; we just assert it | ||
| # is no longer the custom alias. | ||
|
|
||
| # ── pin / unpin ─────────────────────────────────────────────────── | ||
| pin_resp = c._call( | ||
| "surface.action", | ||
| { | ||
| "workspace_id": created_workspace, | ||
| "surface_id": surface_id, | ||
| "action": "pin", | ||
| }, | ||
| ) or {} | ||
| if pin_resp.get("action") != "pin" or pin_resp.get("pinned") is not True: | ||
| raise cmuxError(f"pin: unexpected response: {pin_resp}") | ||
|
|
||
| unpin_resp = c._call( | ||
| "surface.action", | ||
| { | ||
| "workspace_id": created_workspace, | ||
| "surface_id": surface_id, | ||
| "action": "unpin", | ||
| }, | ||
| ) or {} | ||
| if unpin_resp.get("action") != "unpin" or unpin_resp.get("pinned") is not False: | ||
| raise cmuxError(f"unpin: unexpected response: {unpin_resp}") | ||
|
|
||
| # ── mark_read / mark_unread ─────────────────────────────────────── | ||
| for action in ("mark_unread", "mark_read"): | ||
| resp = c._call( | ||
| "surface.action", | ||
| { | ||
| "workspace_id": created_workspace, | ||
| "surface_id": surface_id, | ||
| "action": action, | ||
| }, | ||
| ) or {} | ||
| if resp.get("action") != action: | ||
| raise cmuxError(f"{action}: unexpected response: {resp}") | ||
|
|
||
| # ── unsupported action returns an error structure ───────────────── | ||
| try: | ||
| c._call( | ||
| "surface.action", | ||
| { | ||
| "workspace_id": created_workspace, | ||
| "surface_id": surface_id, | ||
| "action": "definitely-not-a-real-action", | ||
| }, | ||
| ) | ||
| # Some daemons may return a JSON body with an "error" field while | ||
| # still marking the response ok=true. Either is acceptable. | ||
| except cmuxError: | ||
| pass # expected | ||
|
|
||
| # ── focused-surface fallback (no surface_id provided) ───────────── | ||
| focus_fallback_title = f"{unique_title}-focused" | ||
| fallback_resp = c._call( | ||
| "surface.action", | ||
| { | ||
| "workspace_id": created_workspace, | ||
| "action": "rename", | ||
| "title": focus_fallback_title, | ||
| }, | ||
| ) or {} | ||
| if fallback_resp.get("action") != "rename": | ||
| raise cmuxError( | ||
| f"focused-surface fallback: unexpected response: {fallback_resp}" | ||
| ) | ||
|
|
||
| # Reset to clear the custom name we leaked into the workspace. | ||
| c._call( | ||
| "surface.action", | ||
| { | ||
| "workspace_id": created_workspace, | ||
| "surface_id": surface_id, | ||
| "action": "clear_name", | ||
| }, | ||
| ) | ||
|
|
||
| # Cleanup | ||
| c.close_workspace(created_workspace) | ||
| created_workspace = None | ||
|
|
||
| print("PASS: surface.action rename / clear_name / pin / unpin / mark_read / mark_unread") | ||
| return 0 | ||
|
|
||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| if __name__ == "__main__": | ||
| try: | ||
| raise SystemExit(main()) | ||
| except cmuxError as exc: | ||
| print(f"FAIL: {exc}", file=sys.stderr) | ||
| raise SystemExit(1) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.