diff --git a/rust/contracts/rust-core-api.md b/rust/contracts/rust-core-api.md index 4df21a34..e7022d9c 100644 --- a/rust/contracts/rust-core-api.md +++ b/rust/contracts/rust-core-api.md @@ -526,6 +526,7 @@ or removing a command fails until the table changes in the same commit. | `plugins.editorActions.decode` | Validate independent action registration, collection or click results | | `plugins.hostApi.describe` | Describe backend host methods and their required grants from Core's method table | | `plugins.hostApi.authorize` | Check a method, service and current session grants using Core's capability rules; the host still checks session and resource ownership | +| `plugins.workflow` | Validate workflow requests and project native preview, input, output, progress, status and network plans | | `plugins.editorProviders.decode` | Validate editor provider registrations and provider function results | | `keymap.decodeImport` | Validate a normalized shortcut import against the host's action catalog | | `keymap.planImportSources` | Plan the selected provider's declared shortcut source inputs | @@ -8813,9 +8814,10 @@ registration is permitted. See [fixtures](../fixtures/application/file-associati ## Plugin workflow projections (`plugins.workflow`) -`operation:"prepare"` takes `{method,params}` and returns strictly checked params -and `{textBytes,outputLines,outputBytes,resources}` limits. Network defaults are -resolved here. `quickPick` takes `{items,query}` and returns source `indices`; +`operation:"prepare"` takes `{method,params,manifest?}` and returns strictly checked params +and `{textBytes,httpHeaderBytes,outputLines,outputBytes,resources}` limits. Network and +preview defaults, resource preview types and status command declarations are resolved +here. `manifest` is the validated calling session manifest when `commandID` is used. `quickPick` takes `{items,query}` and returns source `indices`; `input` takes `{pick,value}` and returns `{valid}`. `status` takes bounded `items:[{id,priority}]` and returns ordered `ids`. `treePage` takes `{cursor, lastCursor,count,lastCount,rows,lastVisible}` and returns `{load}` only near the diff --git a/rust/crates/plugin-rpc/src/workflow.rs b/rust/crates/plugin-rpc/src/workflow.rs index 9ddd105b..fd9e8366 100644 --- a/rust/crates/plugin-rpc/src/workflow.rs +++ b/rust/crates/plugin-rpc/src/workflow.rs @@ -364,7 +364,8 @@ pub fn command(payload: Value) -> Result { let p = payload.as_object().ok_or_else(core_invalid)?; match p.get("operation").and_then(Value::as_str) { Some("prepare") => { - object(&payload, &["operation", "method", "params"]).map_err(|_| core_invalid())?; + object(&payload, &["operation", "method", "params", "manifest"]) + .map_err(|_| core_invalid())?; let method = p .get("method") .and_then(Value::as_str) @@ -374,6 +375,62 @@ pub fn command(payload: Value) -> Result { CoreError::new(ErrorCode::InvalidRequest, failure.message) .with_details(failure.code) })?; + let name = method.strip_prefix("lithe/host/").unwrap_or(method); + if name == "statusBar/setItem" { + if let Some(id) = params.get("commandID").and_then(Value::as_str) { + let declared = p + .get("manifest") + .and_then(|m| m.pointer("/ui/commands")) + .and_then(Value::as_array) + .is_some_and(|commands| { + commands.iter().any(|c| c["id"].as_str() == Some(id)) + }); + if !declared { + return Err(CoreError::new( + ErrorCode::InvalidRequest, + "The status command is not declared by this plugin.", + ) + .with_details(codes::HOST_INVALID_PARAMS)); + } + } + } + if matches!( + name, + "preview/openMarkdown" | "preview/openHTML" | "browser/openExternal" + ) { + if let Some(path) = params.pointer("/resource/path").and_then(Value::as_str) { + let extension = path + .rsplit('.') + .next() + .unwrap_or_default() + .to_ascii_lowercase(); + let supported = if name == "preview/openMarkdown" { + matches!(extension.as_str(), "md" | "markdown" | "mdown") + } else { + matches!(extension.as_str(), "html" | "htm" | "xhtml") + }; + if !supported { + return Err(CoreError::new( + ErrorCode::InvalidRequest, + "The resource does not support this preview kind.", + ) + .with_details(codes::HOST_UNSUPPORTED_OPTION)); + } + } + if name.starts_with("preview/") { + params + .as_object_mut() + .ok_or_else(core_invalid)? + .entry("presentation") + .or_insert(json!("editorAndPreview")); + } else if params.get("resource").is_some() { + params + .as_object_mut() + .ok_or_else(core_invalid)? + .entry("unsaved") + .or_insert(json!("requireSaved")); + } + } if method.ends_with("network/request") { let map = params.as_object_mut().ok_or_else(core_invalid)?; map.entry("method").or_insert(json!("GET")); @@ -601,6 +658,37 @@ mod tests { assert!(result["open"].as_str().unwrap().len() <= OUTPUT_LINE_BYTES); } + #[test] + fn native_plans_check_preview_type_and_own_command_before_side_effects() { + let context = json!({"contextID":"workspace","generation":1}); + let preview = json!({"operation":"prepare","method":"preview/openHTML","params":{ + "context":context,"resource":{"rootID":"root","path":"notes.txt"}}}); + assert!(command(preview.clone()).is_err()); + let mut valid = preview; + valid["params"]["resource"]["path"] = json!("page.HTML"); + assert_eq!( + command(valid).unwrap()["params"]["presentation"], + "editorAndPreview" + ); + let mut browser = json!({"operation":"prepare","method":"browser/openExternal","params":{ + "context":context,"resource":{"rootID":"root","path":"page.html"}}}); + assert_eq!( + command(browser.clone()).unwrap()["params"]["unsaved"], + "requireSaved" + ); + browser["params"]["unsaved"] = json!("openSavedFile"); + assert_eq!( + command(browser).unwrap()["params"]["unsaved"], + "openSavedFile" + ); + let mut status = json!({"operation":"prepare","method":"statusBar/setItem","params":{ + "context":context,"id":"state","text":"Ready","commandID":"run"}, + "manifest":{"ui":{"commands":[{"id":"other"}]}}}); + assert!(command(status.clone()).is_err()); + status["manifest"]["ui"]["commands"][0]["id"] = json!("run"); + assert!(command(status).is_ok()); + } + #[test] fn workflow_fixture_covers_projection_and_paging_boundaries() { let fixture: Value = diff --git a/rust/fixtures/plugins/workflow-v1.json b/rust/fixtures/plugins/workflow-v1.json index 83bc4d1d..cc4ad06c 100644 --- a/rust/fixtures/plugins/workflow-v1.json +++ b/rust/fixtures/plugins/workflow-v1.json @@ -1,5 +1,10 @@ { "cases": [ + { + "name": "browser resource defaults to requiring saved contents", + "request": {"operation":"prepare","method":"browser/openExternal","params":{"context":{"contextID":"workspace","generation":1},"resource":{"rootID":"root","path":"page.html"}}}, + "result": {"params":{"context":{"contextID":"workspace","generation":1},"resource":{"rootID":"root","path":"page.html"},"unsaved":"requireSaved"},"limits":{"textBytes":131072,"httpHeaderBytes":16384,"outputLines":4000,"outputBytes":524288,"resources":16}} + }, { "name": "filter matches every word across item fields in source order", "request": {"operation":"quickPick","items":[{"label":"Alpha","description":"Rust"},{"label":"Beta","detail":"RUST"}],"query":"rust beta"}, diff --git a/shared/plugins/contract/v1/README.md b/shared/plugins/contract/v1/README.md index 747df9ee..ee62bf5b 100644 --- a/shared/plugins/contract/v1/README.md +++ b/shared/plugins/contract/v1/README.md @@ -4478,7 +4478,10 @@ the user closes the tab or context. They do not write workspace files or bundle resources. A new call with the same ID updates its tab. Inline Markdown cannot resolve local or relative resources; inline HTML serves only its supplied page and cannot read adjacent local files. Remote web content follows the -existing preview policy. Resource previews use the live editor buffer. +existing preview policy. Resource previews use the live editor buffer. Markdown +resources require `.md`, `.markdown` or `.mdown`; HTML resources require `.html`, +`.htm` or `.xhtml` (case-insensitive), otherwise `unsupportedOption` is returned +before opening an editor tab. `presentation` defaults to `editorAndPreview`, or is `previewOnly`; `range` uses the normal one-based UTF-16 range and reveals its start as a caret. A missing native WebView may return `unsupportedOption` for HTML. diff --git a/shared/plugins/guides/plugin-api-pr-guide.zh-CN.md b/shared/plugins/guides/plugin-api-pr-guide.zh-CN.md index 15159289..fabbba9a 100644 --- a/shared/plugins/guides/plugin-api-pr-guide.zh-CN.md +++ b/shared/plugins/guides/plugin-api-pr-guide.zh-CN.md @@ -125,7 +125,7 @@ PR 必须逐项回答: 1. 在契约 README 写清参数、结果、错误码、权限、生命周期、缺省行为及平台限制;schema、fixture 和执行代码一致。 2. 在对应 `guides/` 或 `reference/` 专题页补充用法,并从已有入口链接到新页面。仅写在 PR、实施计划、宿主源码或 Agent Note 中,不算公开契约。 3. 更新 [协议更新记录](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/reference/protocol-changelog.md):修改协议或 API、PR、修改人(PR 作者)及合入日期。未合入就如实写“待合入”,合入时回填真实日期;没有新版本也要登记。确有新版本时,另更新“按协议查首次出现”。 -4. 新增或修改宿主方法、通知时,PR 正文逐个列出下表。Core 的 [API 总表](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/reference/api-catalog.md)中英方法或通知表,以及更新记录的“宿主方法(按 API 编号)”索引同步逐项登记;同类方法分几次 PR 加入时,分别记自己的 PR。 +4. 新增或修改宿主方法、通知时,PR 正文逐个列出下表,按 API 编号升序排列,“用途”用中文,方法名保持真实协议名;没有编号的 `—` 放在最后。Core 的 [API 总表](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/reference/api-catalog.md)中英方法或通知表,以及更新记录的“宿主方法(按 API 编号)”索引同步逐项登记;同类方法分几次 PR 加入时,分别记自己的 PR。创建 PR 后将文档中的“本 PR”回填为真实编号;合入日期只在确认合并后回填。 5. 搜索并检查所有受影响消费者;新增或修改的公共插件 API 在 Rust、Go、Node、Java 四个官方 SDK 中同步补齐,更新对应类型、专题说明和能力支持表。不能只补提出需求的插件所用语言。 新增或修改方法、通知的表格格式如下;把每一项单独填一行: diff --git a/shared/plugins/guides/plugin-workflows.md b/shared/plugins/guides/plugin-workflows.md index 623fd054..97535fef 100644 --- a/shared/plugins/guides/plugin-workflows.md +++ b/shared/plugins/guides/plugin-workflows.md @@ -30,6 +30,8 @@ try { `showInputBox` 的 `password:true` 用于明确向用户索取一个秘密,不预填、不记录;保存应调用本插件的 `credentials.set`。HTTP 不自动读取浏览器 Cookie,也不共享其他插件或宿主业务的凭据。默认返回重定向而不跟随,插件检查状态后自行决定下一步。网络请求由桌面发出,远程后端需要访问远端网络时使用自己的网络实现。 +状态项的 `commandID` 只能引用本插件清单声明的命令。资源预览按 Markdown 或 HTML 的扩展名选择对应方法;省略呈现方式时显示编辑器和预览。浏览器打开资源默认要求缓冲区已保存;仅在明确希望打开磁盘旧内容时传 `unsaved: "openSavedFile"`,宿主不会自动保存。 + 树先返回已加载条目和 `cursor`。`expand` 再加载某父节点的子项;`loadMore` 返回累积范围或补丁,并更新 cursor。`views.refresh(workspace,{instance:event.instance})` 使当前显示失效;刷新后使用稳定 item ID 保留选择和展开。不要把每页当成新的整棵树而丢掉先前条目。 ## English @@ -51,6 +53,8 @@ ID returned by progress creation is also its progress ID. SDK end methods dispos the local route; disposal of the subscription also ends the native progress. Use cancellation events to abort your own operation. +Status commands must be declared by the same plugin. Use the preview method matching the resource extension; omitted presentation shows the editor and preview. Opening a browser resource defaults to requiring saved contents. Pass `unsaved: "openSavedFile"` only to explicitly open the disk version; the host never saves automatically. + For lazy trees, return retained items and an opaque cursor. On expand/loadMore, return the full accumulated range or patches and advance the cursor. A repeated cursor or non-growing range stops automatic paging. Refresh only an instance diff --git a/shared/plugins/reference/api-catalog.md b/shared/plugins/reference/api-catalog.md index 4656e539..5a63e271 100644 --- a/shared/plugins/reference/api-catalog.md +++ b/shared/plugins/reference/api-catalog.md @@ -90,7 +90,7 @@ Lithe 的插件公共 API 按 [API 实施计划](https://github.com/1lck/Lithe-I | --- | --- | --- | --- | --- | | API-01、API-37 | `getCapabilities` | 查询协商的协议版本、后端运行位置(`backendAuthority`)、当前可用的服务和限制;由 Core 直接回答 | 每个插件会话都有 | 0 | | API-01 | `subscriptions/dispose` | 取消一个订阅,即 `workspace/watch`、`editor/registerActions`、`terminal/onExit` 返回的 `subscriptionID`;未知或已取消的 ID 也返回 `null` | 每个插件会话都有 | 0 | -| API-03 | `statusBar/setItem` | 创建或替换状态项 | `statusBar.write` | 0 | +| API-03 | `statusBar/setItem` | 创建或替换状态项;命令须属于本插件清单 | `statusBar.write` | 0 | | API-03 | `statusBar/removeItem` | 移除自己的状态项 | `statusBar.write` | 0 | | API-05 | `workspace/listContexts` | 列出当前的工作区上下文,带变化序号 `revision` | `workspace.metadata` | 0 | | API-05 | `workspace/getContext` | 读取一个工作区上下文 | `workspace.metadata` | 0 | @@ -120,9 +120,9 @@ Lithe 的插件公共 API 按 [API 实施计划](https://github.com/1lck/Lithe-I | API-13 | `views/refresh` | 使当前会话拥有的可见视图失效 | `views.refresh` | 0 | | API-15 | `editor/open` | 在编辑器中打开文件,没有缓冲区时从磁盘读取;可以前台或后台打开,并定位光标 | `editor.open` | 0 | | API-15 | `editor/reveal` | 参数和 `editor/open` 相同,但只处理已打开的文件;文件没打开时返回 `plugin.host.notFound`,不会从磁盘打开 | `editor.open` | 0 | -| API-16 | `preview/openMarkdown` | 预览资源或只读内联 Markdown | `preview.open` | 0 | -| API-16 | `preview/openHTML` | 预览 HTML 资源的实时缓冲区或只读内联文本(`editorAndPreview` 或 `previewOnly`) | `preview.open` | 0 | -| API-16 | `browser/openExternal` | 在外部浏览器打开 HTTP(S) 地址或已保存的 HTML 文件 | `browser.open` | 0 | +| API-16 | `preview/openMarkdown` | 预览 Markdown 资源(`.md`、`.markdown`、`.mdown`)或只读内联文本 | `preview.open` | 0 | +| API-16 | `preview/openHTML` | 预览 HTML 资源(`.html`、`.htm`、`.xhtml`)的实时缓冲区或只读内联文本;默认 `editorAndPreview` | `preview.open` | 0 | +| API-16 | `browser/openExternal` | 在外部浏览器打开 HTTP(S) 地址或已保存的 HTML 文件;默认 `requireSaved` | `browser.open` | 0 | | API-17 | `window/showQuickPick` | 选择一个或多个稳定条目 ID | `window.input` | 0 | | API-17 | `window/showInputBox` | 请求文本或掩码密码输入 | `window.input` | 0 | | API-17 | `window/showInformation` | 显示信息消息,可以带按钮,返回用户点的按钮序号 | `window.messages` | 0 | @@ -292,7 +292,7 @@ Requests a backend sends to the host, all prefixed `lithe/host/`; the tables omi | --- | --- | --- | --- | --- | | API-01, API-37 | `getCapabilities` | Reports the negotiated protocol version, where the backend runs (`backendAuthority`), and the services and limits available now; Core answers it itself | Every plugin-owned session | 0 | | API-01 | `subscriptions/dispose` | Cancels a subscription, that is, a `subscriptionID` returned by `workspace/watch`, `editor/registerActions`, or `terminal/onExit`; an unknown or already disposed ID also returns `null` | Every plugin-owned session | 0 | -| API-03 | `statusBar/setItem` | Create or replace a status item | `statusBar.write` | 0 | +| API-03 | `statusBar/setItem` | Create or replace a status item; commands must belong to the plugin manifest | `statusBar.write` | 0 | | API-03 | `statusBar/removeItem` | Remove an owned status item | `statusBar.write` | 0 | | API-05 | `workspace/listContexts` | Lists the current workspace contexts with the change counter `revision` | `workspace.metadata` | 0 | | API-05 | `workspace/getContext` | Reads one workspace context | `workspace.metadata` | 0 | @@ -322,9 +322,9 @@ Requests a backend sends to the host, all prefixed `lithe/host/`; the tables omi | API-13 | `views/refresh` | Invalidate a visible owned view instance | `views.refresh` | 0 | | API-15 | `editor/open` | Opens a file in the editor, reading it from disk when no buffer exists; opens it in the foreground or background and can place the caret | `editor.open` | 0 | | API-15 | `editor/reveal` | Takes the same params as `editor/open` but only handles files already open; a file that is not open returns `plugin.host.notFound` and is not opened from disk | `editor.open` | 0 | -| API-16 | `preview/openMarkdown` | Show a resource or read-only inline Markdown | `preview.open` | 0 | -| API-16 | `preview/openHTML` | Previews an HTML resource’s live buffer or read-only inline text (`editorAndPreview` or `previewOnly`) | `preview.open` | 0 | -| API-16 | `browser/openExternal` | Opens an HTTP(S) URL or a saved HTML file in the external browser | `browser.open` | 0 | +| API-16 | `preview/openMarkdown` | Show a Markdown resource (`.md`, `.markdown`, `.mdown`) or read-only inline text | `preview.open` | 0 | +| API-16 | `preview/openHTML` | Preview an HTML resource (`.html`, `.htm`, `.xhtml`) live buffer or read-only inline text; defaults to `editorAndPreview` | `preview.open` | 0 | +| API-16 | `browser/openExternal` | Open an HTTP(S) URL or a saved HTML file externally; defaults to `requireSaved` | `browser.open` | 0 | | API-17 | `window/showQuickPick` | Choose one or more stable item IDs | `window.input` | 0 | | API-17 | `window/showInputBox` | Request text or a masked password | `window.input` | 0 | | API-17 | `window/showInformation` | Shows an information message, optionally with buttons, and returns the index of the button the user chose | `window.messages` | 0 | diff --git a/shared/plugins/reference/protocol-changelog.md b/shared/plugins/reference/protocol-changelog.md index e573c6b2..b27ee48b 100644 --- a/shared/plugins/reference/protocol-changelog.md +++ b/shared/plugins/reference/protocol-changelog.md @@ -14,7 +14,7 @@ ## 待合入 -- [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193)(合入日期待合并时填写),[@xiaoyumuxi](https://github.com/xiaoyumuxi),`pluginAPIVersion` 0 / `litheFunctions` 0 内补充(API-03/12/13/16/17/18/22/38):新增 19 个独立授权方法,补齐输入、内联只读预览、文本对比、视图刷新、输出、可取消进度、状态项、剪贴板、文件管理器和有界 HTTP;已有 HTML 预览新增内联来源,浏览器资源形式补齐已保存/拒绝未保存语义。树新增 `hasChildren`、`cursor` 和 `expand`、`loadMore`、`refresh` 事件;后端保留完整已加载范围,分页无进展停止,失败显式重试。共享 `plugins.workflow` 负责严格参数、默认值、限额、搜索、排序、分页和输出增量,四种官方 SDK 同步包装与事件。没有新协议版本;宿主可用方法仍由 `getCapabilities` 发现。 +- [#194](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/194)(待合入),[@xiaoyumuxi](https://github.com/xiaoyumuxi),`pluginAPIVersion` 0 / `litheFunctions` 0 内修正(API-03、API-16):`plugins.workflow` 在原生副作用前校验状态项引用的命令属于调用会话清单、Markdown/HTML 资源扩展名及浏览器资源的 `unsaved` 默认值;预览省略 `presentation` 时仍为 `editorAndPreview`,浏览器省略 `unsaved` 时仍为 `requireSaved`。补齐内核命令总表遗漏的 `plugins.workflow`,修正 Rust SDK 测试模块位置,并在四种官方 SDK 验证进度取消、结束与订阅释放。没有新增方法、通知、权限、错误码或协议版本。 - [#191](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/191),[@xiaoyumuxi](https://github.com/xiaoyumuxi)(—,贡献规则与版本说明):新增插件 API PR 提交指南,明确 API-01–44 是可扩展领域、特有需求不得提升任何系统 API 版本,公共变化也须先证明兼容扩展不足;保留已有 1、2 等版本并按实际用法选最低值。要求统一日志具备可定位语义并集中脱敏、错误码全契约查重、Rust/Go/Node/Java 四个 SDK 在同一 PR 补齐,example 可后补。Core AI 入口及中英导航、契约和版本页同步纠正机械升版与全部填 0 的旧表述。没有新增运行时字段、方法、通知、错误码或版本;合入日期在合并时补齐。 - [#190](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/190),[@xiaoyumuxi](https://github.com/xiaoyumuxi)(API-07/08,`pluginAPIVersion` 0 内补充):Core 新增 `workspace.watchPlan`、`workspace.watchEvents`、`workspace.findFiles`、`workspace.findText`,宿主方法保持原名和权限。路由前严格校验监听与搜索参数,复用文件匹配、编码和隐藏/索引规则,以 no-follow 句柄处理实时磁盘;搜索分页有查询绑定游标、200 条总上限、取消和 30 秒预算,监听投影有排序去重、隐藏过滤和溢出重扫。桌面使用 Viva 原生事件,订阅受插件/会话/上下文约束,注册后先发重扫,释放前停止通知;无空闲轮询。macOS 原生事件与资源释放已验证,Windows 原生验证本轮未执行。没有新增协议版本、宿主方法或通知;合入日期在合并时补齐。 @@ -115,8 +115,9 @@ | API-01、API-37 | `getCapabilities` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-01 | `subscriptions/dispose` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-02 | `commands/didRun`(通知) | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | -| API-03 | `statusBar/setItem` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | -| API-03 | `statusBar/removeItem` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-03 | `statusBar/setItem` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-03 | `statusBar/setItem` | 0(原生执行前校验与默认值) | 待合入 | [#194](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/194) | +| API-03 | `statusBar/removeItem` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | | API-04、API-05 | `workspace/didChangeContexts`(通知) | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-05 | `workspace/listContexts` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-05 | `workspace/getContext` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | @@ -148,35 +149,38 @@ | API-11 | `workspace/rename` | 0 | 待合入 | [#183](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/183) | | API-11 | `workspace/copy` | 0 | 待合入 | [#183](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/183) | | API-11 | `workspace/trash` | 0 | 待合入 | [#183](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/183) | -| API-12 | `editor/showDiff` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-12 | `editor/showDiff` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | | API-12 | `documents/registerContentProvider` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | -| API-13 | `views/refresh` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-13 | `views/refresh` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | | API-15 | `editor/open` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-15 | `editor/reveal` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | -| API-16 | `preview/openMarkdown` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | -| API-16 | `preview/openHTML`(内联来源) | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | -| API-16 | `browser/openExternal`(资源打开) | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-16 | `preview/openMarkdown` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-16 | `preview/openMarkdown` | 0(原生执行前校验与默认值) | 待合入 | [#194](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/194) | +| API-16 | `preview/openHTML`(内联来源) | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-16 | `preview/openHTML` | 0(原生执行前校验与默认值) | 待合入 | [#194](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/194) | +| API-16 | `browser/openExternal`(资源打开) | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-16 | `browser/openExternal` | 0(原生执行前校验与默认值) | 待合入 | [#194](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/194) | | API-16 | `preview/openHTML` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-16 | `browser/openExternal` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | -| API-17 | `window/showQuickPick` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | -| API-17 | `window/showInputBox` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-17 | `window/showQuickPick` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-17 | `window/showInputBox` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | | API-17 | `window/showInformation` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-17 | `window/showWarning` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-17 | `window/showError` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | -| API-18 | `clipboard/readText` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | -| API-18 | `clipboard/writeText` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | -| API-18 | `workspace/reveal` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-18 | `clipboard/readText` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-18 | `clipboard/writeText` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-18 | `workspace/reveal` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | | API-21 | `credentials/get` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-21 | `credentials/set` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-21 | `credentials/delete` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | -| API-22 | `output/create` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | -| API-22 | `output/append` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | -| API-22 | `output/clear` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | -| API-22 | `output/show` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | -| API-22 | `output/dispose` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | -| API-22 | `progress/create` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | -| API-22 | `progress/report` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | -| API-22 | `progress/end` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-22 | `output/create` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-22 | `output/append` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-22 | `output/clear` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-22 | `output/show` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-22 | `output/dispose` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-22 | `progress/create` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-22 | `progress/report` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-22 | `progress/end` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | | API-22、API-25 | `languageServer/setStatus` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-23 | `run/start` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-23 | `run/stop` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | @@ -201,13 +205,19 @@ | API-30 | `debug/start` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-35 | `functions/providers` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | API-35 | `functions/invoke` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | -| API-38 | `network/request` | 0 | 待合入 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | +| API-38 | `network/request` | 0 | 2026-11-23 | [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | | API-40 | `workspace/getHostPaths` | 0 | 待合入 | [#151](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/151) | | — | `keymapImport/listInputs` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | — | `keymapImport/readChunk` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | ## 时间线(新的在上) +### 2026-11-23 + +| PR | 修改人 | API 编号 | 协议 / 能力 | 改动 | +| --- | --- | --- | --- | --- | +| [#193](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/193) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-03、API-12、API-13、API-16、API-17、API-18、API-22、API-38 | `pluginAPIVersion` 0 / `litheFunctions` 0 | 新增 19 个独立授权方法,补齐输入、内联只读预览、文本对比、视图刷新、输出、可取消进度、状态项、剪贴板、文件管理器和有界 HTTP;已有 HTML 预览新增内联来源,浏览器资源形式补齐已保存/拒绝未保存语义。树新增 `hasChildren`、`cursor` 和 `expand`、`loadMore`、`refresh` 事件;后端保留完整已加载范围,分页无进展停止,失败显式重试。共享 `plugins.workflow` 负责严格参数、默认值、限额、搜索、排序、分页和输出增量,四种官方 SDK 同步包装与事件。没有新协议版本;宿主可用方法仍由 `getCapabilities` 发现。 | + ### 2026-11-21 | PR | 修改人 | API 编号 | 协议 / 能力 | 改动 | diff --git a/shared/plugins/sdk/go/lithe/host_services_test.go b/shared/plugins/sdk/go/lithe/host_services_test.go index 3e23f5b1..cf2c5d80 100644 --- a/shared/plugins/sdk/go/lithe/host_services_test.go +++ b/shared/plugins/sdk/go/lithe/host_services_test.go @@ -1277,3 +1277,39 @@ func TestCancellingACallCancelsTheRelayedCallItWaitsOn(t *testing.T) { eq(t, cancels, encode(t, []any{map[string]any{"id": request["id"]}})) s.close() } + +func TestProgressCancellationAndEndReleaseSubscription(t *testing.T) { + backend := lithe.NewBackend("test-backend") + host := backend.Handle().Host() + s := startSession(t, backend, []any{0}) + creating := background(func() (*lithe.Subscription, error) { + return host.Progress().Create(testContext(), map[string]any{"title": "Index", "cancellable": true}) + }) + create := s.take("lithe/host/progress/create") + eq(t, create["params"], `{"context":{"contextID":"w1","generation":2},"title":"Index","cancellable":true}`) + s.reply(create, map[string]any{"progressID": "p1", "subscriptionID": "p1"}) + result := done(t, creating) + must(t, result.err) + subscription := result.value + s.notify("lithe/host/subscriptions/notify", map[string]any{"subscriptionID": "p1", "sequence": 1, "event": map[string]bool{"cancelled": true}}) + event, err := subscription.RecvTimeout(wait) + must(t, err) + eq(t, j(t, string(event.Event())), `{"cancelled":true}`) + ending := background(func() (json.RawMessage, error) { + return host.Progress().End(testContext(), map[string]any{"progressID": "p1"}) + }) + end := s.take("lithe/host/progress/end") + eq(t, end["params"], `{"context":{"contextID":"w1","generation":2},"progressID":"p1"}`) + s.reply(end, nil) + dispose := s.take("lithe/host/subscriptions/dispose") + eq(t, dispose["params"], `{"subscriptionID":"p1"}`) + if !subscription.IsDisposed() { + t.Fatal("ending progress left subscription live") + } + s.reply(dispose, nil) + must(t, done(t, ending).err) + if _, err := subscription.RecvTimeout(wait); !errors.Is(err, lithe.ErrSubscriptionDisposed) { + t.Fatalf("ended subscription: %v", err) + } + s.close() +} diff --git a/shared/plugins/sdk/java/plugin-sdk/src/test/java/io/github/litheidea/plugin/sdk/HostTest.java b/shared/plugins/sdk/java/plugin-sdk/src/test/java/io/github/litheidea/plugin/sdk/HostTest.java index 21b70087..de308541 100644 --- a/shared/plugins/sdk/java/plugin-sdk/src/test/java/io/github/litheidea/plugin/sdk/HostTest.java +++ b/shared/plugins/sdk/java/plugin-sdk/src/test/java/io/github/litheidea/plugin/sdk/HostTest.java @@ -1025,4 +1025,34 @@ void cancellingTheCallingFunctionCancelsItsRelayedCallOnTheWire() { map("code", -32800L, "message", "Cancelled.", "data", map("code", "plugin.host.cancelled")))); assertEquals(1, host.close()); } + + @Test + void progressCancellationAndEndReleaseSubscription() { + Backend backend = Backend.create(null, null); + TestHost host = session(backend); + try { + CompletableFuture cancelled = new CompletableFuture<>(); + CompletableFuture creating = backend.host().progress().create( + CONTEXT, map("title", "Index", "cancellable", true), event -> cancelled.complete(event.event())); + Map create = nextRequest(host, "lithe/host/progress/create"); + assertEquals(map("context", CONTEXT, "title", "Index", "cancellable", true), create.get("params")); + host.send(map("id", create.get("id"), "result", map("progressID", "p1", "subscriptionID", "p1"))); + Host.Subscription subscription = value(creating); + host.notify(Protocol.HOST_SUBSCRIPTION_NOTIFY, map("subscriptionID", "p1", "sequence", 1L, + "event", map("cancelled", true))); + assertEquals(map("cancelled", true), value(cancelled)); + CompletableFuture> ending = backend.host().progress().end(CONTEXT, map("progressID", "p1")); + Map end = nextRequest(host, "lithe/host/progress/end"); + assertEquals(map("context", CONTEXT, "progressID", "p1"), end.get("params")); + host.send(map("id", end.get("id"), "result", null)); + Map dispose = nextRequest(host, Protocol.HOST_SUBSCRIPTIONS_DISPOSE); + assertEquals(map("subscriptionID", "p1"), dispose.get("params")); + assertTrue(subscription.isDisposed()); + host.send(map("id", dispose.get("id"), "result", null)); + value(ending); + } finally { + host.close(); + } + } + } diff --git a/shared/plugins/sdk/node/test/host.test.mjs b/shared/plugins/sdk/node/test/host.test.mjs index fb6d2829..294a1b01 100644 --- a/shared/plugins/sdk/node/test/host.test.mjs +++ b/shared/plugins/sdk/node/test/host.test.mjs @@ -822,3 +822,32 @@ test('a relayed call holds one of the 16 host request slots until Core answers', assert.equal(outcomes[0].status, 'fulfilled'); assert.ok(outcomes.slice(1).every((outcome) => outcome.status === 'rejected' && outcome.reason.code === 'sdk.session.closed')); }); + + +test('progress cancellation is delivered and ending releases its subscription', async () => { + const { backend, host } = await session(); + try { + const cancelled = gate(); + const creating = backend.host.progress.create(CONTEXT, { title: 'Index', cancellable: true }, (event) => { + assert.deepEqual(event, { cancelled: true }); + cancelled.open(); + }); + const create = await nextRequest(host, 'lithe/host/progress/create'); + assert.deepEqual(create.params, { context: CONTEXT, title: 'Index', cancellable: true }); + host.send({ id: create.id, result: { progressID: 'p1', subscriptionID: 'p1' } }); + const subscription = await creating; + host.notify('lithe/host/subscriptions/notify', { subscriptionID: 'p1', sequence: 1, event: { cancelled: true } }); + await withTimeout(cancelled.opened, 'progress cancellation'); + const ending = backend.host.progress.end(CONTEXT, { progressID: 'p1' }); + const end = await nextRequest(host, 'lithe/host/progress/end'); + assert.deepEqual(end.params, { context: CONTEXT, progressID: 'p1' }); + host.send({ id: end.id, result: null }); + const dispose = await nextRequest(host, 'lithe/host/subscriptions/dispose'); + assert.deepEqual(dispose.params, { subscriptionID: 'p1' }); + assert.equal(subscription.disposed, true); + host.send({ id: dispose.id, result: null }); + await ending; + } finally { + await host.close(); + } +}); diff --git a/shared/plugins/sdk/rust/plugin-sdk/src/host.rs b/shared/plugins/sdk/rust/plugin-sdk/src/host.rs index 10513127..5b19ebab 100644 --- a/shared/plugins/sdk/rust/plugin-sdk/src/host.rs +++ b/shared/plugins/sdk/rust/plugin-sdk/src/host.rs @@ -1511,109 +1511,6 @@ fn relay_params(call: Value, serving: Option<&str>) -> Result { Ok(Value::Object(relayed)) } -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn contexts_are_references_or_full_contexts() { - let full = json!({ "contextID": "w1", "generation": 2, "name": "orders" }); - let context = WorkspaceContext::from_value(&full).unwrap(); - assert_eq!( - context.to_value(), - json!({ "contextID": "w1", "generation": 2 }) - ); - assert_eq!(WorkspaceContext::new("w1", 2).unwrap(), context); - // An invocation's context is exactly a reference. - assert_eq!(WorkspaceContext::from_reference(&full), None); - assert_eq!( - WorkspaceContext::from_reference(&context.to_value()), - Some(context) - ); - for invalid in [ - json!({ "contextID": "w1" }), - json!({ "contextID": "w1", "generation": 0 }), - json!({ "contextID": "../w", "generation": 1 }), - json!(null), - ] { - let error = WorkspaceContext::from_value(&invalid).unwrap_err(); - assert_eq!(error.code(), "sdk.host.invalidContext", "{invalid}"); - } - assert!(WorkspaceContext::new("", 1).is_err()); - } - - #[test] - fn a_relayed_call_keeps_only_the_fields_the_method_defines() { - let call = json!({ - "pluginID": "dev.lithe.fixture.java", "functionID": "project.describe", - "params": { "caller": "data" }, "timeoutMilliseconds": 900000, - "parentOperationID": "17", "caller": { "pluginID": "forged" }, - "context": { "contextID": "x" }, "extra": true - }); - let expected = json!({ - "pluginID": "dev.lithe.fixture.java", "functionID": "project.describe", - "params": { "caller": "data" }, "timeoutMilliseconds": 900000, - "parentOperationID": "17" - }); - // Core passes a `caller` inside `params` unchanged; only a top-level one is refused. - assert_eq!(relay_params(call, Some("served")).unwrap(), expected); - } - - #[test] - fn optional_fields_stay_out_and_the_parent_defaults_to_the_call_being_served() { - let call = json!({ "pluginID": "a.b", "functionID": "x.y" }); - assert_eq!(relay_params(call.clone(), None).unwrap(), call); - let served = relay_params(call, Some("op-7")).unwrap(); - assert_eq!(served["parentOperationID"], "op-7"); - assert!(served.get("params").is_none()); - assert!(served.get("timeoutMilliseconds").is_none()); - let named = json!({ "pluginID": "a.b", "functionID": "x.y", "parentOperationID": "own" }); - let relayed = relay_params(named, Some("op-7")).unwrap(); - assert_eq!(relayed["parentOperationID"], "own"); - // The host caps the timeout; the SDK sends what the plugin chose. - let mut slow = json!({ "pluginID": "a.b", "functionID": "x.y" }); - slow["timeoutMilliseconds"] = json!(700000); - let relayed = relay_params(slow, None).unwrap(); - assert_eq!(relayed["timeoutMilliseconds"], 700000); - } - - #[test] - fn an_invalid_relayed_call_is_refused_before_anything_is_sent() { - let valid = json!({ "pluginID": "a.b", "functionID": "x.y" }); - let with = |key: &str, value: Value| { - let mut call = valid.clone(); - call[key] = value; - call - }; - let without = |key: &str| { - let mut call = valid.clone(); - call.as_object_mut().unwrap().remove(key); - call - }; - for invalid in [ - json!("x.y"), - json!(null), - without("pluginID"), - with("pluginID", json!("")), - with("pluginID", json!(7)), - without("functionID"), - with("functionID", json!("Not-Valid")), - with("params", json!([])), - with("params", json!(null)), - with("timeoutMilliseconds", json!(0)), - with("timeoutMilliseconds", json!(-1)), - with("timeoutMilliseconds", json!(1.5)), - with("timeoutMilliseconds", json!("5000")), - with("parentOperationID", json!("")), - with("parentOperationID", json!("p".repeat(129))), - with("parentOperationID", json!(12)), - ] { - let error = relay_params(invalid.clone(), Some("op-1")).unwrap_err(); - assert_eq!(error.code(), "sdk.functions.invalidCall", "{invalid}"); - } - } -} - /// Native views services with session-owned resources. pub struct Views { host: Host, @@ -1731,3 +1628,106 @@ impl Network { self.host.scoped(methods::NETWORK_REQUEST, context, params) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn contexts_are_references_or_full_contexts() { + let full = json!({ "contextID": "w1", "generation": 2, "name": "orders" }); + let context = WorkspaceContext::from_value(&full).unwrap(); + assert_eq!( + context.to_value(), + json!({ "contextID": "w1", "generation": 2 }) + ); + assert_eq!(WorkspaceContext::new("w1", 2).unwrap(), context); + // An invocation's context is exactly a reference. + assert_eq!(WorkspaceContext::from_reference(&full), None); + assert_eq!( + WorkspaceContext::from_reference(&context.to_value()), + Some(context) + ); + for invalid in [ + json!({ "contextID": "w1" }), + json!({ "contextID": "w1", "generation": 0 }), + json!({ "contextID": "../w", "generation": 1 }), + json!(null), + ] { + let error = WorkspaceContext::from_value(&invalid).unwrap_err(); + assert_eq!(error.code(), "sdk.host.invalidContext", "{invalid}"); + } + assert!(WorkspaceContext::new("", 1).is_err()); + } + + #[test] + fn a_relayed_call_keeps_only_the_fields_the_method_defines() { + let call = json!({ + "pluginID": "dev.lithe.fixture.java", "functionID": "project.describe", + "params": { "caller": "data" }, "timeoutMilliseconds": 900000, + "parentOperationID": "17", "caller": { "pluginID": "forged" }, + "context": { "contextID": "x" }, "extra": true + }); + let expected = json!({ + "pluginID": "dev.lithe.fixture.java", "functionID": "project.describe", + "params": { "caller": "data" }, "timeoutMilliseconds": 900000, + "parentOperationID": "17" + }); + // Core passes a `caller` inside `params` unchanged; only a top-level one is refused. + assert_eq!(relay_params(call, Some("served")).unwrap(), expected); + } + + #[test] + fn optional_fields_stay_out_and_the_parent_defaults_to_the_call_being_served() { + let call = json!({ "pluginID": "a.b", "functionID": "x.y" }); + assert_eq!(relay_params(call.clone(), None).unwrap(), call); + let served = relay_params(call, Some("op-7")).unwrap(); + assert_eq!(served["parentOperationID"], "op-7"); + assert!(served.get("params").is_none()); + assert!(served.get("timeoutMilliseconds").is_none()); + let named = json!({ "pluginID": "a.b", "functionID": "x.y", "parentOperationID": "own" }); + let relayed = relay_params(named, Some("op-7")).unwrap(); + assert_eq!(relayed["parentOperationID"], "own"); + // The host caps the timeout; the SDK sends what the plugin chose. + let mut slow = json!({ "pluginID": "a.b", "functionID": "x.y" }); + slow["timeoutMilliseconds"] = json!(700000); + let relayed = relay_params(slow, None).unwrap(); + assert_eq!(relayed["timeoutMilliseconds"], 700000); + } + + #[test] + fn an_invalid_relayed_call_is_refused_before_anything_is_sent() { + let valid = json!({ "pluginID": "a.b", "functionID": "x.y" }); + let with = |key: &str, value: Value| { + let mut call = valid.clone(); + call[key] = value; + call + }; + let without = |key: &str| { + let mut call = valid.clone(); + call.as_object_mut().unwrap().remove(key); + call + }; + for invalid in [ + json!("x.y"), + json!(null), + without("pluginID"), + with("pluginID", json!("")), + with("pluginID", json!(7)), + without("functionID"), + with("functionID", json!("Not-Valid")), + with("params", json!([])), + with("params", json!(null)), + with("timeoutMilliseconds", json!(0)), + with("timeoutMilliseconds", json!(-1)), + with("timeoutMilliseconds", json!(1.5)), + with("timeoutMilliseconds", json!("5000")), + with("parentOperationID", json!("")), + with("parentOperationID", json!("p".repeat(129))), + with("parentOperationID", json!(12)), + ] { + let error = relay_params(invalid.clone(), Some("op-1")).unwrap_err(); + assert_eq!(error.code(), "sdk.functions.invalidCall", "{invalid}"); + } + } +} diff --git a/shared/plugins/sdk/rust/plugin-sdk/tests/host_services.rs b/shared/plugins/sdk/rust/plugin-sdk/tests/host_services.rs index c762041d..4b2fd136 100644 --- a/shared/plugins/sdk/rust/plugin-sdk/tests/host_services.rs +++ b/shared/plugins/sdk/rust/plugin-sdk/tests/host_services.rs @@ -1352,3 +1352,49 @@ fn cancelling_a_call_cancels_the_relayed_call_it_waits_on() { assert_eq!(cancels, [json!({ "id": request["id"] })]); session.close(); } + +#[test] +fn progress_cancellation_and_end_release_the_subscription() { + let backend = Backend::new("test-backend"); + let host = backend.handle().host(); + let mut session = Session::start(backend); + let creating = { + let host = host.clone(); + background(move || { + host.progress() + .create(&context(), json!({"title":"Index","cancellable":true})) + }) + }; + let create = session.take("lithe/host/progress/create"); + assert_eq!( + create["params"], + json!({"context":context().to_value(),"title":"Index","cancellable":true}) + ); + session.reply(&create, json!({"progressID":"p1","subscriptionID":"p1"})); + let subscription = done(&creating).unwrap(); + session.host.notify( + "lithe/host/subscriptions/notify", + json!({"subscriptionID":"p1","sequence":1,"event":{"cancelled":true}}), + ); + assert_eq!( + subscription.recv_timeout(WAIT).unwrap().event(), + &json!({"cancelled":true}) + ); + let ending = background(move || host.progress().end(&context(), json!({"progressID":"p1"}))); + let end = session.take("lithe/host/progress/end"); + assert_eq!( + end["params"], + json!({"context":context().to_value(),"progressID":"p1"}) + ); + session.reply(&end, Value::Null); + let dispose = session.take("lithe/host/subscriptions/dispose"); + assert_eq!(dispose["params"], json!({"subscriptionID":"p1"})); + assert!(subscription.is_disposed()); + session.reply(&dispose, Value::Null); + done(&ending).unwrap(); + assert_eq!( + subscription.recv_timeout(WAIT), + Err(RecvTimeoutError::Disconnected) + ); + session.close(); +}