From ac365ee00e9122c91ce2d9275f8cd6f6972cb7cd Mon Sep 17 00:00:00 2001 From: Raing5Days Date: Wed, 21 Oct 2026 01:06:39 +0800 Subject: [PATCH 1/3] feat(cli-peer): serve the file explorer surface to controllers A Desktop controller driving a CLI Peer Host renders the workspace through the `explorer_*` reads and refreshes it from `file-system-changed`. The CLI Peer Host answered only the historical command names, so the file tree, the `@` reference picker and the editor breadcrumb all failed with "command 'explorer_get_children' is not supported on CLI peer host" even though this host already served the same directory read under another name. - Alias `explorer_get_children`, `explorer_get_children_paginated` and `explorer_get_file_tree` onto the existing readers instead of refusing them. - Add `get_file_tree`, `get_file_metadata`, `get_file_editor_sync_hash` and `create_file`, resolving local and remote-connection IO through a portable `path_operations` owner next to the existing read/write/rename helpers. - Add `start_file_watch`, `stop_file_watch` and `get_watched_paths`, and install the peer controller emitter for the watcher so change events reach attached controllers instead of leaving their tree stale after the first read. - Graduate the ten registry rows to `Handled`, correct the `stop_file_watch` remote-workspace stance, and regenerate the capability artifacts. - Declare `file-watch` in the CLI Core capability closure and pin the surface with a dispatch gate test. --- .../technical/tauri-command-map.json | 4 +- scripts/check-core-boundaries.test.mjs | 1 + .../cargo-dependency-boundaries.mjs | 4 + src/apps/cli/Cargo.toml | 1 + src/apps/cli/src/peer_host/bootstrap.rs | 4 + .../cli/src/peer_host/commands/filesystem.rs | 153 +++++++++++++++++- src/apps/cli/src/peer_host/commands/mod.rs | 26 ++- src/apps/cli/src/peer_host/dispatch.rs | 31 ++++ .../src/service/filesystem/path_operations.rs | 134 +++++++++++++++ .../generated/remote-surface-registry.json | 36 ++--- .../src/remote_surface/baseline.rs | 1 - .../src/remote_surface/table.rs | 20 +-- .../api/generated/remoteSurface.ts | 2 +- 13 files changed, 377 insertions(+), 40 deletions(-) diff --git a/docs/interactive-capabilities/technical/tauri-command-map.json b/docs/interactive-capabilities/technical/tauri-command-map.json index 47d1ea2f22..126203b715 100644 --- a/docs/interactive-capabilities/technical/tauri-command-map.json +++ b/docs/interactive-capabilities/technical/tauri-command-map.json @@ -3412,7 +3412,7 @@ "rustPath": "get_file_editor_sync_hash", "sourceFile": "src/apps/desktop/src/api/commands.rs", "signature": "fn get_file_editor_sync_hash( state: State<'_, AppState>, request: GetFileMetadataRequest, ) -> Result", - "remoteWorkspacePolicy": "LegacyUnaudited" + "remoteWorkspacePolicy": "RemoteRouted" }, { "id": "get_file_metadata", @@ -10202,7 +10202,7 @@ "rustPath": "stop_file_watch", "sourceFile": "src/apps/desktop/src/api/commands.rs", "signature": "fn stop_file_watch( state: State<'_, AppState>, request: Option, path: Option, ) -> Result<(), String>", - "remoteWorkspacePolicy": "WorkspaceAgnostic" + "remoteWorkspacePolicy": "RemoteUnsupported" }, { "id": "stop_mcp_server", diff --git a/scripts/check-core-boundaries.test.mjs b/scripts/check-core-boundaries.test.mjs index 4f3337ee13..4137fd7f83 100644 --- a/scripts/check-core-boundaries.test.mjs +++ b/scripts/check-core-boundaries.test.mjs @@ -1858,6 +1858,7 @@ const CLI_REVIEWED_CORE_FEATURES = [ ...ACP_REVIEWED_CORE_FEATURES, 'product-search', 'remote-connect', + 'file-watch', 'plugin-runtime', 'opencode-plugin-host', ]; diff --git a/scripts/core-boundaries/cargo-dependency-boundaries.mjs b/scripts/core-boundaries/cargo-dependency-boundaries.mjs index d9e789281b..43dea65d74 100644 --- a/scripts/core-boundaries/cargo-dependency-boundaries.mjs +++ b/scripts/core-boundaries/cargo-dependency-boundaries.mjs @@ -1459,6 +1459,10 @@ export function findProductEntrypointCoreFeatureViolations( ...coreCompatibilityReviewedFeatures, 'product-search', 'remote-connect', + // The CLI Peer Host answers `start_file_watch` / `stop_file_watch` for an + // attached controller, so it consumes the watcher owner directly instead + // of inheriting it from `external-sources`. + 'file-watch', 'plugin-runtime', 'opencode-plugin-host', 'ssh-remote', diff --git a/src/apps/cli/Cargo.toml b/src/apps/cli/Cargo.toml index 5de4e6c447..9b6819316e 100644 --- a/src/apps/cli/Cargo.toml +++ b/src/apps/cli/Cargo.toml @@ -37,6 +37,7 @@ openbitfun-core = { path = "../../crates/assembly/core", features = [ "subscription-auth", "remote-connect", "external-sources", + "file-watch", "plugin-runtime", "opencode-plugin-host", "ssh-remote", diff --git a/src/apps/cli/src/peer_host/bootstrap.rs b/src/apps/cli/src/peer_host/bootstrap.rs index c249c12c4f..e3ada85f4e 100644 --- a/src/apps/cli/src/peer_host/bootstrap.rs +++ b/src/apps/cli/src/peer_host/bootstrap.rs @@ -80,6 +80,10 @@ pub(crate) async fn ensure_peer_host_ready(runtime: &CliRuntimeContext) -> Resul // A mobile controller or IM bot that opens a workspace on this host changes // the catalog an attached Desktop controller renders; mirror the hint. workspace::start_workspace_catalog_publication(Arc::new(PeerControllerEventEmitter)); + // The file explorer on an attached controller refreshes from + // `file-system-changed`, so this host must publish its own watch events + // instead of leaving the tree stale after the first read. + openbitfun_core::service::initialize_file_watch_service(Arc::new(PeerControllerEventEmitter)); tracing::info!("CLI peer host services ready"); Ok(()) } diff --git a/src/apps/cli/src/peer_host/commands/filesystem.rs b/src/apps/cli/src/peer_host/commands/filesystem.rs index 7422cef735..910a4b3e0e 100644 --- a/src/apps/cli/src/peer_host/commands/filesystem.rs +++ b/src/apps/cli/src/peer_host/commands/filesystem.rs @@ -1,8 +1,10 @@ //! Filesystem HostInvoke handlers. +use openbitfun_core::service::filesystem::path_operations; +use openbitfun_core::service::workspace::WorkspaceKind; use serde_json::{json, Value}; -use crate::peer_host::args::{get_string, optional_string, request_value}; +use crate::peer_host::args::{get_string, optional_bool, optional_string, request_value}; use crate::peer_host::state::PeerHostState; async fn file_connection(state: &PeerHostState, request: &Value) -> Result, String> { @@ -95,6 +97,155 @@ pub(crate) async fn get_directory_children_paginated( })) } +fn file_tree_node_to_json(node: openbitfun_core::infrastructure::FileTreeNode) -> Value { + let mut json = json!({ + "path": node.path, + "name": node.name, + "isDirectory": node.is_directory, + "size": node.size, + "extension": node.extension, + "lastModified": node.last_modified + }); + if let Some(children) = node.children { + json["children"] = Value::Array(children.into_iter().map(file_tree_node_to_json).collect()); + } + json +} + +/// A directory request names a real directory on whichever filesystem the +/// request resolved to. Empty identity is the explicit runtime-local scope. +async fn ensure_directory_path(path: &str, connection: Option<&str>) -> Result<(), String> { + if let Some(id) = connection.filter(|id| !id.trim().is_empty()) { + path_operations::resolve_explicit_path_connection(path, id.trim()).await?; + return Ok(()); + } + let path_buf = std::path::Path::new(path); + if !path_buf.exists() { + return Err("Directory does not exist".to_string()); + } + if !path_buf.is_dir() { + return Err("Path is not a directory".to_string()); + } + Ok(()) +} + +/// Whole-tree read. Registered as `get_file_tree` and, for the current file +/// explorer controller, as `explorer_get_file_tree`. +pub(crate) async fn get_file_tree(state: &PeerHostState, args: &Value) -> Result { + let request = request_value(args); + let path = get_string(request, "path")?; + let preferred = file_connection(state, request).await?; + ensure_directory_path(&path, preferred.as_deref()).await?; + let nodes = state + .filesystem_service + .build_file_tree_on_connection(&path, preferred.as_deref()) + .await + .map_err(|e| format!("Failed to build file tree: {e}"))?; + let root_name = std::path::Path::new(&path) + .file_name() + .and_then(|name| name.to_str()) + .unwrap_or(&path) + .to_string(); + Ok(json!([json!({ + "path": path, + "name": root_name, + "isDirectory": true, + "size": Value::Null, + "extension": Value::Null, + "lastModified": Value::Null, + "children": nodes.into_iter().map(file_tree_node_to_json).collect::>() + })])) +} + +pub(crate) async fn get_file_metadata( + state: &PeerHostState, + args: &Value, +) -> Result { + let request = request_value(args); + let path = get_string(request, "path")?; + let hint = file_connection(state, request).await?; + let metadata = + path_operations::metadata(&state.filesystem_service, &path, hint.as_deref()).await?; + serde_json::to_value(metadata).map_err(|e| format!("Failed to serialize file metadata: {e}")) +} + +pub(crate) async fn get_file_editor_sync_hash( + state: &PeerHostState, + args: &Value, +) -> Result { + let request = request_value(args); + let path = get_string(request, "path")?; + let hint = file_connection(state, request).await?; + let (hash, is_remote) = + path_operations::editor_sync_hash(&state.filesystem_service, &path, hint.as_deref()) + .await?; + Ok(if is_remote { + json!({ "path": path, "hash": hash, "is_remote": true }) + } else { + json!({ "path": path, "hash": hash }) + }) +} + +pub(crate) async fn create_file(state: &PeerHostState, args: &Value) -> Result { + let request = request_value(args); + let path = get_string(request, "path")?; + let hint = file_connection(state, request).await?; + path_operations::create_empty_file(&state.filesystem_service, &path, hint.as_deref()).await?; + Ok(Value::Null) +} + +/// Resolve a watch request to a host-local path, mirroring the Desktop Host: +/// a workspace ID is the current ingress, and remote workspaces are refused +/// because the watcher only observes this host's filesystem. +async fn watch_target( + state: &PeerHostState, + request: &Value, +) -> Result<(String, Option), String> { + if let Some(workspace_id) = optional_string(request, "workspaceId") { + let record = state + .workspace_service + .require_workspace(&workspace_id) + .await + .map_err(|e| e.to_string())?; + if record.workspace_kind == WorkspaceKind::Remote { + return Err("Filesystem watching is not available for remote workspaces".into()); + } + return Ok(( + get_string(request, "path")?, + optional_bool(request, "recursive"), + )); + } + // Temporary 1.0.0 wire ingress; current callers must send the ID request. + let path = get_string(request, "path")?; + if state + .workspace_service + .upgrade_legacy_file_connection(&path, None, None) + .await + .map_err(|e| e.to_string())? + .is_some() + { + return Err("Filesystem watching is not available for remote workspaces".into()); + } + Ok((path, optional_bool(request, "recursive"))) +} + +pub(crate) async fn start_file_watch(state: &PeerHostState, args: &Value) -> Result { + let (path, recursive) = watch_target(state, request_value(args)).await?; + openbitfun_core::service::start_file_watch(path, recursive).await?; + Ok(Value::Null) +} + +pub(crate) async fn stop_file_watch(state: &PeerHostState, args: &Value) -> Result { + let (path, _) = watch_target(state, request_value(args)).await?; + openbitfun_core::service::stop_file_watch(path).await?; + Ok(Value::Null) +} + +pub(crate) async fn get_watched_paths() -> Result { + let paths = openbitfun_core::service::get_watched_paths().await?; + Ok(json!(paths)) +} + pub(crate) async fn check_path_exists( state: &PeerHostState, args: &Value, diff --git a/src/apps/cli/src/peer_host/commands/mod.rs b/src/apps/cli/src/peer_host/commands/mod.rs index fb302d9c1c..d25bdf5db8 100644 --- a/src/apps/cli/src/peer_host/commands/mod.rs +++ b/src/apps/cli/src/peer_host/commands/mod.rs @@ -109,12 +109,24 @@ pub(crate) fn dispatch<'a>( "terminal_shutdown_all" => Box::pin(terminal::shutdown_all()), // Filesystem "workspace_file_upload" => Box::pin(filesystem::workspace_file_upload(state, args)), - "get_directory_children" | "list_files" => { + "get_directory_children" | "list_files" | "explorer_get_children" => { Box::pin(filesystem::get_directory_children(state, args)) } - "get_directory_children_paginated" => { + "get_directory_children_paginated" | "explorer_get_children_paginated" => { Box::pin(filesystem::get_directory_children_paginated(state, args)) } + // Whole-tree read under its historical name and its file explorer alias. + "get_file_tree" | "explorer_get_file_tree" => { + Box::pin(filesystem::get_file_tree(state, args)) + } + "get_file_metadata" => Box::pin(filesystem::get_file_metadata(state, args)), + "get_file_editor_sync_hash" => { + Box::pin(filesystem::get_file_editor_sync_hash(state, args)) + } + "create_file" => Box::pin(filesystem::create_file(state, args)), + "start_file_watch" => Box::pin(filesystem::start_file_watch(state, args)), + "stop_file_watch" => Box::pin(filesystem::stop_file_watch(state, args)), + "get_watched_paths" => Box::pin(filesystem::get_watched_paths()), "check_path_exists" => Box::pin(filesystem::check_path_exists(state, args)), "create_directory" => Box::pin(filesystem::create_directory(state, args)), "read_file_content" => Box::pin(filesystem::read_file_content(state, args)), @@ -248,6 +260,16 @@ pub(crate) const HANDLED_COMMANDS: &[&str] = &[ "delete_file", "delete_directory", "list_directory_files", + "create_file", + "explorer_get_children", + "explorer_get_children_paginated", + "explorer_get_file_tree", + "get_file_tree", + "get_file_metadata", + "get_file_editor_sync_hash", + "get_watched_paths", + "start_file_watch", + "stop_file_watch", "list_subagents", "list_manageable_subagents", "test_ai_config_connection", diff --git a/src/apps/cli/src/peer_host/dispatch.rs b/src/apps/cli/src/peer_host/dispatch.rs index c1c21b5d4e..2063c677a2 100644 --- a/src/apps/cli/src/peer_host/dispatch.rs +++ b/src/apps/cli/src/peer_host/dispatch.rs @@ -361,6 +361,37 @@ mod tests { } } + /// The file explorer controller reads the workspace through the + /// `explorer_*` aliases, while the editor reads metadata, sync hashes and + /// watch state. These rows used to be refused as "no remote-workspace UI + /// surface", which broke the file tree, the `@` reference picker and the + /// editor breadcrumb in every CLI Peer session even though this host + /// already served the same reads under the historical names. + #[test] + fn file_explorer_surface_is_not_refused_before_dispatch() { + for command in [ + "explorer_get_children", + "explorer_get_children_paginated", + "explorer_get_file_tree", + "get_file_tree", + "get_file_metadata", + "get_file_editor_sync_hash", + "create_file", + "start_file_watch", + "stop_file_watch", + "get_watched_paths", + ] { + assert!( + !is_local_only_command(command), + "{command} must be routable to the peer host" + ); + assert!( + !is_cli_unsupported_command(command), + "{command} must reach its implemented handler, not the unsupported gate" + ); + } + } + #[tokio::test] async fn attach_detach_only_updates_delivery_subscribers() { let _ = handle_host_invoke( diff --git a/src/crates/assembly/core/src/service/filesystem/path_operations.rs b/src/crates/assembly/core/src/service/filesystem/path_operations.rs index b81f838cd5..791c9eef01 100644 --- a/src/crates/assembly/core/src/service/filesystem/path_operations.rs +++ b/src/crates/assembly/core/src/service/filesystem/path_operations.rs @@ -276,6 +276,140 @@ pub async fn exists( Ok(service.exists(path).await) } +/// Create an empty file, mirroring the desktop `create_file` semantics +/// (truncating an existing path) on either side of a filesystem connection. +pub async fn create_empty_file( + service: &FileSystemService, + path: &str, + hint: Option<&str>, +) -> Result<(), String> { + if let Some((fs, id)) = remote(path, hint).await? { + return fs + .write_file(&id, path, b"") + .await + .map_err(|e| format!("Failed to create remote file: {e}")); + } + service + .write_file_with_options( + path, + "", + crate::infrastructure::FileOperationOptions::default(), + ) + .await + .map(|_| ()) + .map_err(|e| format!("Failed to create file: {e}")) +} + +/// File metadata as a file explorer or editor reads it. +/// +/// One shape for both sides of a filesystem connection, so a host without a +/// graphical filesystem resolver still answers the same fields. +#[derive(Debug, Clone, serde::Serialize)] +#[serde(rename_all = "camelCase")] +pub struct PathMetadata { + pub path: String, + pub modified: u64, + pub size: u64, + pub is_file: bool, + pub is_dir: bool, + pub is_symlink: bool, + pub is_remote: bool, +} + +pub async fn metadata( + service: &FileSystemService, + path: &str, + hint: Option<&str>, +) -> Result { + if let Some((fs, id)) = remote(path, hint).await? { + let entry = fs + .stat(&id, path) + .await + .map_err(|e| format!("Failed to stat remote file: {e}"))?; + let (is_file, is_dir, is_symlink, size, modified) = match entry { + Some(entry) => ( + entry.is_file, + entry.is_dir, + entry.is_symlink, + entry.size.unwrap_or(0), + entry.modified.unwrap_or(0), + ), + None => (false, false, false, 0, 0), + }; + return Ok(PathMetadata { + path: path.to_string(), + modified, + size, + is_file, + is_dir, + is_symlink, + is_remote: true, + }); + } + + let path_ref = std::path::Path::new(path); + let link_metadata = std::fs::symlink_metadata(path_ref) + .map_err(|e| format!("Failed to inspect local file type '{path}': {e}"))?; + let metadata = std::fs::metadata(path_ref) + .map_err(|e| format!("Failed to stat local file '{path}': {e}"))?; + + // Not collapsible: on Windows a junction/reparse point is not reported as a + // symlink by `file_type()`, so the extra attribute check is load-bearing. + #[allow(clippy::needless_bool)] + let is_symlink = if link_metadata.file_type().is_symlink() { + true + } else { + #[cfg(windows)] + { + use std::os::windows::fs::MetadataExt; + const FILE_ATTRIBUTE_REPARSE_POINT: u32 = 0x0400; + link_metadata.file_attributes() & FILE_ATTRIBUTE_REPARSE_POINT != 0 + } + #[cfg(not(windows))] + { + false + } + }; + + let modified = metadata + .modified() + .unwrap_or(std::time::SystemTime::UNIX_EPOCH) + .duration_since(std::time::SystemTime::UNIX_EPOCH) + .unwrap_or_default() + .as_millis() as u64; + + Ok(PathMetadata { + path: path.to_string(), + modified, + size: metadata.len(), + is_file: metadata.is_file(), + is_dir: metadata.is_dir(), + is_symlink, + is_remote: false, + }) +} + +/// Editor external-sync hash plus whether the bytes came from a remote +/// connection, matching the desktop `get_file_editor_sync_hash` contract. +pub async fn editor_sync_hash( + service: &FileSystemService, + path: &str, + hint: Option<&str>, +) -> Result<(String, bool), String> { + if let Some((fs, id)) = remote(path, hint).await? { + let bytes = fs + .read_file(&id, path) + .await + .map_err(|e| format!("Failed to read remote file: {e}"))?; + return Ok((service.editor_sync_sha256_hex_from_raw_bytes(&bytes), true)); + } + let hash = service + .editor_sync_content_sha256_hex(path) + .await + .map_err(|e| e.to_string())?; + Ok((hash, false)) +} + #[cfg(test)] mod tests { #[tokio::test] diff --git a/src/crates/contracts/product-domains/src/generated/remote-surface-registry.json b/src/crates/contracts/product-domains/src/generated/remote-surface-registry.json index df6e555390..9f9f1d3c22 100644 --- a/src/crates/contracts/product-domains/src/generated/remote-surface-registry.json +++ b/src/crates/contracts/product-domains/src/generated/remote-surface-registry.json @@ -1,6 +1,6 @@ { "schemaVersion": 1, - "digest": "fnv1a64:ddf61f87bff00c48", + "digest": "fnv1a64:22d9460fcae1ea3a", "retiredCommandPrefixes": [ { "prefix": "lsp_", @@ -1372,8 +1372,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -2214,8 +2213,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host does not expose the remote-workspace UI surface" + "kind": "handled" } }, { @@ -2226,8 +2224,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host does not expose the remote-workspace UI surface" + "kind": "handled" } }, { @@ -2238,8 +2235,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host does not expose the remote-workspace UI surface" + "kind": "handled" } }, { @@ -2747,13 +2743,12 @@ { "id": "get_file_editor_sync_hash", "surface": "tauri_command", - "remoteWorkspace": "LegacyUnaudited", + "remoteWorkspace": "RemoteRouted", "peer": { "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -2764,8 +2759,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -2776,8 +2770,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -3458,8 +3451,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -7716,8 +7708,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -7830,13 +7821,12 @@ { "id": "stop_file_watch", "surface": "tauri_command", - "remoteWorkspace": "WorkspaceAgnostic", + "remoteWorkspace": "RemoteUnsupported", "peer": { "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { diff --git a/src/crates/contracts/product-domains/src/remote_surface/baseline.rs b/src/crates/contracts/product-domains/src/remote_surface/baseline.rs index da22ced120..475b86b4ca 100644 --- a/src/crates/contracts/product-domains/src/remote_surface/baseline.rs +++ b/src/crates/contracts/product-domains/src/remote_surface/baseline.rs @@ -70,7 +70,6 @@ pub(super) const UNAUDITED_BASELINE: &[&str] = &[ "get_custom_agent_detail", "get_default_review_team_definition", "get_file_change_history", - "get_file_editor_sync_hash", "get_global_config_health", "get_global_config_status", "get_mcp_prompt", diff --git a/src/crates/contracts/product-domains/src/remote_surface/table.rs b/src/crates/contracts/product-domains/src/remote_surface/table.rs index 6d41ca43b6..daee1c0036 100644 --- a/src/crates/contracts/product-domains/src/remote_surface/table.rs +++ b/src/crates/contracts/product-domains/src/remote_surface/table.rs @@ -192,7 +192,7 @@ pub(super) const OPERATIONS: &[OperationDefinition] = &[ op("create_cron_job", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("create_custom_agent", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("create_directory", Routed, Proxied, HANDLED), - op("create_file", Routed, Proxied, CLI_NOT_IMPLEMENTED), + op("create_file", Routed, Proxied, HANDLED), op("create_miniapp", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("create_session", Unaudited, Proxied, HANDLED), op("create_subagent", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), @@ -264,9 +264,9 @@ pub(super) const OPERATIONS: &[OperationDefinition] = &[ op("ensure_coordinator_session", Routed, Proxied, HANDLED), op("execute_tool", Routed, Proxied, CLI_NOT_IMPLEMENTED), op("expand_external_prompt_command_command", Unsupported, Proxied, CLI_NOT_IMPLEMENTED), - op("explorer_get_children", Routed, Proxied, CLI_NO_REMOTE_WORKSPACE_UI), - op("explorer_get_children_paginated", Routed, Proxied, CLI_NO_REMOTE_WORKSPACE_UI), - op("explorer_get_file_tree", Routed, Proxied, CLI_NO_REMOTE_WORKSPACE_UI), + op("explorer_get_children", Routed, Proxied, HANDLED), + op("explorer_get_children_paginated", Routed, Proxied, HANDLED), + op("explorer_get_file_tree", Routed, Proxied, HANDLED), op("export_config", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("export_diagnostics_bundle", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("export_local_file_to_path", Unsupported, Proxied, CLI_NOT_IMPLEMENTED), @@ -310,9 +310,9 @@ pub(super) const OPERATIONS: &[OperationDefinition] = &[ op("get_external_source_snapshot", Unsupported, Proxied, HANDLED), op("get_file_change_history", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("get_file_diff", Unsupported, Proxied, CLI_NOT_IMPLEMENTED), - op("get_file_editor_sync_hash", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), - op("get_file_metadata", Routed, Proxied, CLI_NOT_IMPLEMENTED), - op("get_file_tree", Routed, Proxied, CLI_NOT_IMPLEMENTED), + op("get_file_editor_sync_hash", Routed, Proxied, HANDLED), + op("get_file_metadata", Routed, Proxied, HANDLED), + op("get_file_tree", Routed, Proxied, HANDLED), op("get_frontend_update_status", LocalOnly, ControllerLocal, REFUSED), op("get_global_config_health", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("get_global_config_status", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), @@ -374,7 +374,7 @@ pub(super) const OPERATIONS: &[OperationDefinition] = &[ op("get_token_usage_statistics", Agnostic, Proxied, HANDLED), op("get_tool_info", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("get_turn_files", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), - op("get_watched_paths", LocalOnly, Proxied, CLI_NOT_IMPLEMENTED), + op("get_watched_paths", LocalOnly, Proxied, HANDLED), op("get_web_search_credential_status", Agnostic, Proxied, HANDLED), host_invoke_only("get_workspace_info", Agnostic, Proxied, HANDLED), op("get_workspace_reference_snapshot", Unsupported, Proxied, CLI_NOT_IMPLEMENTED), @@ -734,7 +734,7 @@ pub(super) const OPERATIONS: &[OperationDefinition] = &[ op("ssh_test_connection", Agnostic, Proxied, CLI_NO_DESKTOP_IDE_SURFACE), op("start_acp_dialog_turn", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("start_dialog_turn", Routed, Proxied, HANDLED), - op("start_file_watch", Unsupported, Proxied, CLI_NOT_IMPLEMENTED), + op("start_file_watch", Unsupported, Proxied, HANDLED), op("start_mcp_remote_oauth", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("start_mcp_server", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("start_search_file_contents_stream", Routed, Proxied, CLI_NOT_IMPLEMENTED), @@ -744,7 +744,7 @@ pub(super) const OPERATIONS: &[OperationDefinition] = &[ op("startup_window_control", LocalOnly, ControllerLocal, REFUSED), op("steer_dialog_turn", Agnostic, Proxied, CLI_NOT_IMPLEMENTED), op("stop_acp_client", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), - op("stop_file_watch", Agnostic, Proxied, CLI_NOT_IMPLEMENTED), + op("stop_file_watch", Unsupported, Proxied, HANDLED), op("stop_mcp_server", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("submit_acp_permission_response", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("submit_mcp_interaction_response", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), diff --git a/src/web-ui/src/infrastructure/api/generated/remoteSurface.ts b/src/web-ui/src/infrastructure/api/generated/remoteSurface.ts index 9b2f5dcfa9..de4506625a 100644 --- a/src/web-ui/src/infrastructure/api/generated/remoteSurface.ts +++ b/src/web-ui/src/infrastructure/api/generated/remoteSurface.ts @@ -1,6 +1,6 @@ // Generated by scripts/generate-interactive-capabilities.mjs; do not edit. // Source: openbitfun_product_domains::remote_surface (Product Operation Registry). -export const REMOTE_SURFACE_REGISTRY_DIGEST = "fnv1a64:ddf61f87bff00c48" as const; +export const REMOTE_SURFACE_REGISTRY_DIGEST = "fnv1a64:22d9460fcae1ea3a" as const; /** * Registered Tauri commands the Peer Device controller keeps on the controller From e2261245078f57c9c56701c2caac549e88f738b8 Mon Sep 17 00:00:00 2001 From: Raing5Days Date: Wed, 21 Oct 2026 11:39:14 +0800 Subject: [PATCH 2/3] feat(cli-peer): expose read-only Git panel commands Reuse GitService for repository, status, branches, log, diff, changed-file and revision reads. Preserve workspace-ID authority and reject remote workspaces without local fallback. Keep desktop owner DTOs, legacy payload compatibility and ownership-trust diagnostics. Add real-repository fixture tests covering nonmutation, wire fields and invalid inputs; update registry and generated projections. --- src/apps/cli/src/peer_host/commands/git.rs | 287 +++++++++++++++++- src/apps/cli/src/peer_host/commands/mod.rs | 18 ++ .../generated/remote-surface-registry.json | 29 +- .../src/remote_surface/table.rs | 18 +- .../api/generated/remoteSurface.ts | 2 +- 5 files changed, 314 insertions(+), 40 deletions(-) diff --git a/src/apps/cli/src/peer_host/commands/git.rs b/src/apps/cli/src/peer_host/commands/git.rs index 16f3cd7889..b690240cb1 100644 --- a/src/apps/cli/src/peer_host/commands/git.rs +++ b/src/apps/cli/src/peer_host/commands/git.rs @@ -2,9 +2,10 @@ use serde_json::{json, Value}; -use openbitfun_core::service::git::GitService; +use openbitfun_core::service::git::{trust, GitError, GitService}; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use crate::peer_host::args::{optional_string, request_value}; +use crate::peer_host::args::{get_string, optional_string, request_value}; async fn repository_path_for_workspace(request: &Value) -> Result { let service = openbitfun_core::service::workspace::get_global_workspace_service() @@ -21,18 +22,106 @@ async fn repository_path_for_workspace(request: &Value) -> Result Result { + if kind == openbitfun_core::service::workspace::WorkspaceKind::Remote { + return Err("CLI peer Git inspection does not support remote workspaces; local filesystem fallback was not attempted".into()); + } + Ok(if has_workspace_id || legacy_path.is_empty() { + root.to_string() + } else { + legacy_path + }) +} + +/// Read-only Git panel operations. Workspace resolution runs before opening a +/// repository so an SSH workspace can never fall back to a same-named local path. +pub(crate) async fn read(command: &str, args: &Value) -> Result { + let request = request_value(args); + let path = repository_path_for_workspace(request).await?; + read_at_path(command, &path, request).await +} + +fn git_result(command: &str, result: Result) -> Result { + let value = result.map_err(|error| match error.untrusted_repository_path() { + Some(path) => trust::untrusted_repository_error_message(path), + None => format!("{command} failed: {error}"), + })?; + serde_json::to_value(value).map_err(|error| format!("Invalid {command} response: {error}")) +} + +fn required_params(request: &Value) -> Result { + serde_json::from_value(request.get("params").cloned().unwrap_or(Value::Null)) + .map_err(|error| format!("Invalid Git params: {error}")) +} + +#[derive(Deserialize)] +struct BranchOptions { + #[serde(default, rename = "includeRemote", alias = "include_remote")] + include_remote: Option, +} + +async fn read_at_path(command: &str, path: &str, request: &Value) -> Result { + match command { + "git_get_repository" => git_result(command, GitService::get_repository(path).await), + "git_get_repository_basic" => { + git_result(command, GitService::get_repository_basic(path).await) + } + "git_get_status" => git_result(command, GitService::get_status(path).await), + "git_get_branches" | "git_get_enhanced_branches" => { + let options: BranchOptions = serde_json::from_value(request.clone()) + .map_err(|error| format!("Invalid Git branch request: {error}"))?; + let include_remote = options.include_remote.unwrap_or(false); + if command == "git_get_branches" { + git_result( + command, + GitService::get_branches(path, include_remote).await, + ) + } else { + git_result( + command, + GitService::get_enhanced_branches(path, include_remote).await, + ) + } + } + "git_get_commits" => { + // Like Desktop, absent/null log params select the owner's defaults. + let params = request.get("params").filter(|value| !value.is_null()); + let params = match params { + Some(params) => serde_json::from_value(params.clone()) + .map_err(|error| format!("Invalid Git log params: {error}"))?, + None => Default::default(), + }; + git_result(command, GitService::get_commits(path, params).await) + } + "git_get_diff" => { + let params = required_params(request)?; + git_result(command, GitService::get_diff(path, ¶ms).await) + } + "git_get_changed_files" => { + let params = required_params(request)?; + git_result(command, GitService::get_changed_files(path, ¶ms).await) + } + "git_resolve_revision" => { + let revision = get_string(request, "revision")?; + git_result(command, GitService::resolve_revision(path, &revision).await) + } + other => Err(format!("Unknown CLI peer Git read command '{other}'")), + } +} + pub(crate) async fn git_is_repository(args: &Value) -> Result { let request = request_value(args); let repository_path = repository_path_for_workspace(request).await?; @@ -63,3 +152,179 @@ pub(crate) async fn git_get_repository_trust(args: &Value) -> Result String { + let output = create_command("git") + .current_dir(path) + .args(["-c", "core.hooksPath=", "-c", "commit.gpgSign=false"]) + .args(args) + .env("GIT_CONFIG_NOSYSTEM", "1") + .env("GIT_CONFIG_GLOBAL", path.join("fixture-global-config")) + .output() + .unwrap(); + assert!( + output.status.success(), + "{}", + String::from_utf8_lossy(&output.stderr) + ); + String::from_utf8(output.stdout).unwrap().trim().to_string() + } + + fn fixture() -> tempfile::TempDir { + let dir = tempfile::tempdir().unwrap(); + git(dir.path(), &["init", "-b", "main"]); + git(dir.path(), &["config", "user.name", "Fixture"]); + git( + dir.path(), + &["config", "user.email", "fixture@example.invalid"], + ); + std::fs::write(dir.path().join("tracked.txt"), "before\n").unwrap(); + git(dir.path(), &["add", "tracked.txt"]); + git(dir.path(), &["commit", "-m", "initial fixture"]); + dir + } + + #[tokio::test] + async fn git_panel_reads_keep_owner_wire_shapes_and_do_not_mutate_repository() { + let dir = fixture(); + let path = dir.path().to_str().unwrap(); + let head = git(dir.path(), &["rev-parse", "HEAD"]); + std::fs::write(dir.path().join("tracked.txt"), "after\n").unwrap(); + std::fs::write(dir.path().join("untracked.txt"), "new\n").unwrap(); + let status_before = git(dir.path(), &["status", "--porcelain"]); + let index_before = std::fs::read(dir.path().join(".git/index")).unwrap(); + for command in ["git_get_repository", "git_get_repository_basic"] { + let result = read_at_path(command, path, &json!({})).await.unwrap(); + assert_eq!(result["current_branch"], "main"); + assert_eq!(result["is_bare"], false); + assert!(result["remotes"].is_array()); + } + let status = read_at_path("git_get_status", path, &json!({})) + .await + .unwrap(); + assert_eq!(status["unstaged"][0]["path"], "tracked.txt"); + assert_eq!(status["untracked"][0], "untracked.txt"); + for command in ["git_get_branches", "git_get_enhanced_branches"] { + let branches = read_at_path(command, path, &json!({"includeRemote": false})) + .await + .unwrap(); + assert!(branches + .as_array() + .unwrap() + .iter() + .any(|b| b["name"] == "main" && b["current"] == true)); + } + let commits = read_at_path( + "git_get_commits", + path, + &json!({"params": {"max_count": 1}}), + ) + .await + .unwrap(); + assert_eq!(commits.as_array().unwrap().len(), 1); + assert_eq!(commits[0]["hash"], head); + let diff = read_at_path( + "git_get_diff", + path, + &json!({"params": {"files": ["tracked.txt"], "reviewSafe": true}}), + ) + .await + .unwrap(); + assert!(diff.as_str().unwrap().contains("+after")); + let files = read_at_path( + "git_get_changed_files", + path, + &json!({"params": {"reviewSafe": true}}), + ) + .await + .unwrap(); + assert_eq!(files[0]["path"], "tracked.txt"); + assert_eq!(files[0]["status"], "modified"); + let revision = read_at_path("git_resolve_revision", path, &json!({"revision": "HEAD"})) + .await + .unwrap(); + assert_eq!(revision, head); + assert_eq!(git(dir.path(), &["status", "--porcelain"]), status_before); + assert_eq!(git(dir.path(), &["rev-parse", "HEAD"]), head); + assert_eq!( + std::fs::read(dir.path().join(".git/index")).unwrap(), + index_before + ); + assert_eq!( + std::fs::read_to_string(dir.path().join("tracked.txt")).unwrap(), + "after\n" + ); + } + + #[test] + fn workspace_identity_wins_and_remote_scope_never_uses_local_path() { + let sentinel = fixture(); + let root = sentinel.path().to_str().unwrap(); + assert_eq!( + resolved_repository_path(WorkspaceKind::Normal, root, "wrong-path".into(), true) + .unwrap(), + root + ); + assert_eq!( + resolved_repository_path(WorkspaceKind::Normal, root, "legacy-path".into(), false) + .unwrap(), + "legacy-path" + ); + for has_id in [true, false] { + let error = resolved_repository_path(WorkspaceKind::Remote, root, root.into(), has_id) + .unwrap_err(); + assert!(error.contains("local filesystem fallback was not attempted")); + } + } + + #[tokio::test] + async fn legacy_payloads_and_invalid_params_are_handled_without_fake_success() { + let dir = fixture(); + let path = dir.path().to_str().unwrap(); + let legacy = json!({"repository_path": path, "include_remote": false, "futureField": true}); + let wrapped = json!({"request": legacy}); + let old = read_at_path("git_get_branches", path, request_value(&legacy)) + .await + .unwrap(); + let new = read_at_path("git_get_branches", path, request_value(&wrapped)) + .await + .unwrap(); + assert_eq!(old, new); + for payload in [json!({}), json!({"params": null})] { + assert!(!read_at_path("git_get_commits", path, &payload) + .await + .unwrap() + .as_array() + .unwrap() + .is_empty()); + assert!(read_at_path("git_get_diff", path, &payload).await.is_err()); + } + assert!( + read_at_path("git_get_branches", path, &json!({"includeRemote": "yes"})) + .await + .is_err() + ); + assert!(read_at_path( + "git_get_commits", + path, + &json!({"params": {"max_count": "bad"}}) + ) + .await + .is_err()); + assert!(read_at_path( + "git_resolve_revision", + path, + &json!({"revision": "missing-fixture-ref"}) + ) + .await + .is_err()); + assert!(read_at_path("git_push", path, &json!({})).await.is_err()); + } +} diff --git a/src/apps/cli/src/peer_host/commands/mod.rs b/src/apps/cli/src/peer_host/commands/mod.rs index d25bdf5db8..63f82ca90f 100644 --- a/src/apps/cli/src/peer_host/commands/mod.rs +++ b/src/apps/cli/src/peer_host/commands/mod.rs @@ -212,6 +212,15 @@ pub(crate) fn dispatch<'a>( // Git (local workspace only) "git_is_repository" => Box::pin(git::git_is_repository(args)), "git_get_repository_trust" => Box::pin(git::git_get_repository_trust(args)), + "git_get_repository" + | "git_get_repository_basic" + | "git_get_status" + | "git_get_branches" + | "git_get_enhanced_branches" + | "git_get_commits" + | "git_get_diff" + | "git_get_changed_files" + | "git_resolve_revision" => Box::pin(git::read(command, args)), // Soft empty / no-op for Desktop-only subsystems "notify_cron_host_ready" => Box::pin(soft::notify_cron_host_ready()), @@ -332,6 +341,15 @@ pub(crate) const HANDLED_COMMANDS: &[&str] = &[ "get_workspace_info", "git_get_repository_trust", "git_is_repository", + "git_get_repository", + "git_get_repository_basic", + "git_get_status", + "git_get_branches", + "git_get_enhanced_branches", + "git_get_commits", + "git_get_diff", + "git_get_changed_files", + "git_resolve_revision", "initialize_workspace_startup_state", "list_files", "get_session_interaction_mailbox", diff --git a/src/crates/contracts/product-domains/src/generated/remote-surface-registry.json b/src/crates/contracts/product-domains/src/generated/remote-surface-registry.json index 9f9f1d3c22..684b02a49e 100644 --- a/src/crates/contracts/product-domains/src/generated/remote-surface-registry.json +++ b/src/crates/contracts/product-domains/src/generated/remote-surface-registry.json @@ -1,6 +1,6 @@ { "schemaVersion": 1, - "digest": "fnv1a64:22d9460fcae1ea3a", + "digest": "fnv1a64:99aaac0603a70b63", "retiredCommandPrefixes": [ { "prefix": "lsp_", @@ -3604,8 +3604,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -3616,8 +3615,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -3628,8 +3626,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -3640,8 +3637,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -3652,8 +3648,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -3688,8 +3683,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -3700,8 +3694,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -3723,8 +3716,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { @@ -3818,8 +3810,7 @@ "kind": "proxied" }, "cliPeer": { - "kind": "unsupported", - "reason": "the CLI peer host has no handler for this command" + "kind": "handled" } }, { diff --git a/src/crates/contracts/product-domains/src/remote_surface/table.rs b/src/crates/contracts/product-domains/src/remote_surface/table.rs index daee1c0036..bb7aeb3a42 100644 --- a/src/crates/contracts/product-domains/src/remote_surface/table.rs +++ b/src/crates/contracts/product-domains/src/remote_surface/table.rs @@ -387,17 +387,17 @@ pub(super) const OPERATIONS: &[OperationDefinition] = &[ op("git_commit", Routed, Proxied, CLI_NOT_IMPLEMENTED), op("git_create_branch", Routed, Proxied, CLI_NOT_IMPLEMENTED), op("git_delete_branch", Routed, Proxied, CLI_NOT_IMPLEMENTED), - op("git_get_branches", Routed, Proxied, CLI_NOT_IMPLEMENTED), - op("git_get_changed_files", Routed, Proxied, CLI_NOT_IMPLEMENTED), - op("git_get_commits", Routed, Proxied, CLI_NOT_IMPLEMENTED), - op("git_get_diff", Routed, Proxied, CLI_NOT_IMPLEMENTED), - op("git_get_enhanced_branches", Routed, Proxied, CLI_NOT_IMPLEMENTED), + op("git_get_branches", Routed, Proxied, HANDLED), + op("git_get_changed_files", Routed, Proxied, HANDLED), + op("git_get_commits", Routed, Proxied, HANDLED), + op("git_get_diff", Routed, Proxied, HANDLED), + op("git_get_enhanced_branches", Routed, Proxied, HANDLED), op("git_get_file_content", Routed, Proxied, CLI_NOT_IMPLEMENTED), op("git_get_graph", Unsupported, Proxied, CLI_NOT_IMPLEMENTED), - op("git_get_repository", Routed, Proxied, CLI_NOT_IMPLEMENTED), - op("git_get_repository_basic", Routed, Proxied, CLI_NOT_IMPLEMENTED), + op("git_get_repository", Routed, Proxied, HANDLED), + op("git_get_repository_basic", Routed, Proxied, HANDLED), op("git_get_repository_trust", Routed, Proxied, HANDLED), - op("git_get_status", Routed, Proxied, CLI_NOT_IMPLEMENTED), + op("git_get_status", Routed, Proxied, HANDLED), op("git_is_repository", Routed, Proxied, HANDLED), op("git_list_worktrees", Unsupported, Proxied, CLI_NOT_IMPLEMENTED), op("git_pull", Routed, Proxied, CLI_NOT_IMPLEMENTED), @@ -405,7 +405,7 @@ pub(super) const OPERATIONS: &[OperationDefinition] = &[ op("git_remove_worktree", Unsupported, Proxied, CLI_NOT_IMPLEMENTED), op("git_reset_files", Routed, Proxied, CLI_NOT_IMPLEMENTED), op("git_reset_to_commit", Routed, Proxied, CLI_NOT_IMPLEMENTED), - op("git_resolve_revision", Routed, Proxied, CLI_NOT_IMPLEMENTED), + op("git_resolve_revision", Routed, Proxied, HANDLED), op("git_trust_repository", Routed, OperatorOnly, REFUSED), op("grant_miniapp_path", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), op("grant_miniapp_workspace", Unaudited, Proxied, CLI_NOT_IMPLEMENTED), diff --git a/src/web-ui/src/infrastructure/api/generated/remoteSurface.ts b/src/web-ui/src/infrastructure/api/generated/remoteSurface.ts index de4506625a..2bc72a3dd8 100644 --- a/src/web-ui/src/infrastructure/api/generated/remoteSurface.ts +++ b/src/web-ui/src/infrastructure/api/generated/remoteSurface.ts @@ -1,6 +1,6 @@ // Generated by scripts/generate-interactive-capabilities.mjs; do not edit. // Source: openbitfun_product_domains::remote_surface (Product Operation Registry). -export const REMOTE_SURFACE_REGISTRY_DIGEST = "fnv1a64:22d9460fcae1ea3a" as const; +export const REMOTE_SURFACE_REGISTRY_DIGEST = "fnv1a64:99aaac0603a70b63" as const; /** * Registered Tauri commands the Peer Device controller keeps on the controller From c0bb1ddcf9e6c7f250176e5b87339178ff671660 Mon Sep 17 00:00:00 2001 From: Bob Lee Date: Mon, 2 Nov 2026 13:10:30 +0800 Subject: [PATCH 3/3] test(core): cover local create, metadata and editor sync hash path operations --- .../src/service/filesystem/path_operations.rs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/crates/assembly/core/src/service/filesystem/path_operations.rs b/src/crates/assembly/core/src/service/filesystem/path_operations.rs index 791c9eef01..1ff35ceda9 100644 --- a/src/crates/assembly/core/src/service/filesystem/path_operations.rs +++ b/src/crates/assembly/core/src/service/filesystem/path_operations.rs @@ -442,6 +442,59 @@ mod tests { .await; } + #[tokio::test] + async fn local_create_metadata_and_sync_hash_answer_the_desktop_shape() { + let temp = tempfile::tempdir().unwrap(); + let service = super::FileSystemService::default(); + let path = temp + .path() + .join("created.txt") + .to_string_lossy() + .to_string(); + std::fs::write(&path, "stale bytes").unwrap(); + // Desktop `create_file` truncates an existing path. + super::create_empty_file(&service, &path, Some("")) + .await + .unwrap(); + assert_eq!(std::fs::read_to_string(&path).unwrap(), ""); + + let file = super::metadata(&service, &path, Some("")).await.unwrap(); + assert!(file.is_file && !file.is_dir && !file.is_remote); + assert_eq!(file.size, 0); + let value = serde_json::to_value(&file).unwrap(); + for field in [ + "path", + "modified", + "size", + "isFile", + "isDir", + "isSymlink", + "isRemote", + ] { + assert!(value.get(field).is_some(), "missing {field}"); + } + let directory = temp.path().to_string_lossy().to_string(); + let directory = super::metadata(&service, &directory, Some("")) + .await + .unwrap(); + assert!(directory.is_dir && !directory.is_file); + assert!( + super::metadata(&service, &format!("{path}.missing"), Some("")) + .await + .is_err() + ); + + std::fs::write(&path, "synced").unwrap(); + let (hash, is_remote) = super::editor_sync_hash(&service, &path, Some("")) + .await + .unwrap(); + assert!(!is_remote); + assert_eq!( + hash, + service.editor_sync_content_sha256_hex(&path).await.unwrap() + ); + } + #[tokio::test] async fn explicit_local_scope_bypasses_same_path_remote_routing() { let temp = tempfile::tempdir().unwrap();