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
1 change: 1 addition & 0 deletions .github/workflows/app-ffi-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ on:
branches: [feat-cmux-next]
paths:
- "cmux-tui/crates/cmux-app-ffi/**"
- "cmux-tui/crates/cmux-bookmarks-core/**"
- "cmux-tui/crates/cmux-focus-core/**"
- "cmux-tui/crates/cmux-layout-reducer/**"
- "cmux-tui/crates/cmux-layout-reducer-ffi/**"
Expand Down
9 changes: 9 additions & 0 deletions cmux-tui/crates/cmux-app-ffi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion cmux-tui/crates/cmux-layout-reducer-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ edition = "2024"
rust-version = "1.91"
license = "GPL-3.0-or-later"
publish = false
description = "C ABI for the pure cmux sidebar drop resolver, section layout reducer, Tasks preview and window focus rules"
description = "C ABI for the pure cmux sidebar drop resolver, section layout reducer, Tasks preview, bookmark preview and window focus rules"

[workspace]

[lib]
crate-type = ["staticlib", "rlib"]

[dependencies]
# Without its `url` feature: the app links no URL parser (cmux-bookmarks-core `validate_url`).
cmux-bookmarks-core = { path = "../cmux-bookmarks-core" }
cmux-focus-core = { path = "../cmux-focus-core" }
cmux-layout-reducer = { path = "../cmux-layout-reducer" }
cmux-tasks-core = { path = "../cmux-tasks-core" }
Expand Down
8 changes: 8 additions & 0 deletions cmux-tui/crates/cmux-layout-reducer-ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Narrow C ABI for `cmux-layout-reducer`'s sidebar drop resolver
//! (`sidebar_drop`) and sidebar section layout reducer (`sidebar_layout`),
//! plus `cmux-tasks-core`'s optimistic Tasks preview (`tasks_preview`),
//! `cmux-bookmarks-core`'s optimistic bookmark tree (`bookmarks_apply`: the
//! confirmed listing with the pending ops applied by the daemon's rules),
//! `cmux-focus-core`'s per-key rules (`focus_type_ahead`,
//! `focus_child_window_key`) and agent cursor visibility
//! (`agent_cursor_visibility`), the window focus machine (`cmux_focus_*`,
Expand Down Expand Up @@ -141,6 +143,12 @@ pub unsafe extern "C" fn cmux_layout_reducer_json(
serde_json::to_vec(&cmux_tasks_core::preview::respond(&request))
.map_err(|_| ERR_INVALID)?
}
b"bookmarks_apply" => {
let request: cmux_bookmarks_core::preview::Request =
serde_json::from_slice(request).map_err(|_| ERR_INVALID)?;
serde_json::to_vec(&cmux_bookmarks_core::preview::respond(request))
.map_err(|_| ERR_INVALID)?
}
b"focus_type_ahead" => {
let request: cmux_focus_core::wire::TypeAheadRequest =
serde_json::from_slice(request).map_err(|_| ERR_INVALID)?;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! `bookmarks_apply` through the C ABI, under `bookmarks_apply::` so the
//! fleet's one-substring test filter selects it.

#[path = "bookmarks_apply_ffi/cases.rs"]
mod bookmarks_apply;
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//! `bookmarks_apply` through the C ABI: the app sends its confirmed bookmark
//! listing and its pending ops and shows the tree that comes back, so its
//! optimistic view follows the daemon's rules (layer-ownership.md V-11).

use cmux_layout_reducer_ffi::{ERR_INVALID, OK, cmux_layout_reducer_json};
use serde_json::{Value, json};

fn call(request: &Value) -> (i32, Value) {
let request = serde_json::to_vec(request).unwrap();
let mut output = vec![0u8; 1 << 16];
let mut len = 0usize;
let code = unsafe {
cmux_layout_reducer_json(
request.as_ptr(),
request.len(),
c"bookmarks_apply".as_ptr(),
output.as_mut_ptr(),
output.len(),
&mut len,
)
};
let body =
if code == OK { serde_json::from_slice(&output[..len]).unwrap() } else { Value::Null };
(code, body)
}

const FOLDER: &str = "bm_00000000000000000000000000000001";
const PAGE: &str = "bm_00000000000000000000000000000002";

#[test]
fn two_quick_edits_both_show_on_the_confirmed_tree() {
let confirmed = json!([
{"id": FOLDER, "browser_profile_id": "default", "parent": "bar", "kind": "folder", "index": 0,
"title": "Work", "created_ms": 1},
{"id": PAGE, "browser_profile_id": "default", "parent": "bar", "kind": "url", "index": 1,
"title": "Page", "url": "https://example.com/", "created_ms": 2},
]);
let (code, body) = call(&json!({
"browser_profile_id": "default",
"tree": confirmed,
"ops": [
{"op": "update", "bookmark": PAGE, "title": "Renamed"},
{"op": "move", "bookmark": PAGE, "parent": FOLDER, "index": 0},
{"op": "update", "bookmark": FOLDER, "url": "https://x.example"},
],
"now_ms": 10,
}));
assert_eq!(code, OK);
let tree = body["tree"].as_array().unwrap();
assert_eq!(tree.len(), 2);
assert_eq!(tree[1]["id"], PAGE);
assert_eq!(tree[1]["parent"], FOLDER);
assert_eq!(tree[1]["title"], "Renamed");
assert_eq!(body["results"][0]["changed"], true);
assert_eq!(body["results"][1]["result"]["bookmark"]["index"], 0);
assert_eq!(
body["results"][2],
json!({"error_code": "invalid_params", "reason": "invalid_kind", "message": "a folder has no url"})
);
}

#[test]
fn a_malformed_request_is_invalid() {
let (code, _) = call(&json!({"tree": []}));
assert_eq!(code, ERR_INVALID);
}
1 change: 1 addition & 0 deletions scripts/cmux-next/check_app_crate_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"cmux-layout-reducer-ffi",
"cmux-focus-core",
"cmux-tasks-core",
"cmux-bookmarks-core",
"cmux-palette-ranker",
"cmux-remote-browser",
}
Expand Down
4 changes: 3 additions & 1 deletion tests/test_app_crate_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_license_expressions(self):
self.assertFalse(gate.license_allowed("MIT AND GPL-2.0"))
self.assertFalse(gate.license_allowed(None))

def test_the_ten_first_party_gpl_crates_are_named_exactly(self):
def test_the_eleven_first_party_gpl_crates_are_named_exactly(self):
self.assertEqual(
sorted(gate.FIRST_PARTY_GPL),
sorted(
Expand All @@ -97,6 +97,8 @@ def test_the_ten_first_party_gpl_crates_are_named_exactly(self):
# 83755ce18d22 (cmux-focus-core over the app FFI) named these three in the gate.
"cmux-focus-core",
"cmux-tasks-core",
# The bookmark reducer the app links for its optimistic view (V-11).
"cmux-bookmarks-core",
"cmux-palette-ranker",
"cmux-remote-browser",
]
Expand Down
Loading