From 145c81c013fdfe477eca7fd2efa6450cf6137a30 Mon Sep 17 00:00:00 2001 From: Simon Klee Date: Wed, 4 Nov 2026 20:54:01 +0100 Subject: [PATCH] test(cli-rs): add the P.1 plugin slot P-APP scenario A test plugin appends a line to home.footer: TS loads it as a local plugin directory, Rust registers its twin. --- packages/cli-rs/crates/tui/tests/app.rs | 26 +- .../cli-rs/parity/fixtures/P.1/slot.app.json | 413 ++++++++++++++++++ .../cli-rs/parity/fixtures/P.1/slot/home.json | 81 ++++ packages/cli-rs/parity/plugins/slot/tui.tsx | 18 + .../cli-rs/parity/scenarios/P.1/slot.app.ts | 25 ++ 5 files changed, 562 insertions(+), 1 deletion(-) create mode 100644 packages/cli-rs/parity/fixtures/P.1/slot.app.json create mode 100644 packages/cli-rs/parity/fixtures/P.1/slot/home.json create mode 100644 packages/cli-rs/parity/plugins/slot/tui.tsx create mode 100644 packages/cli-rs/parity/scenarios/P.1/slot.app.ts diff --git a/packages/cli-rs/crates/tui/tests/app.rs b/packages/cli-rs/crates/tui/tests/app.rs index 94847ff3a98..5ddb1ce5d97 100644 --- a/packages/cli-rs/crates/tui/tests/app.rs +++ b/packages/cli-rs/crates/tui/tests/app.rs @@ -12,7 +12,9 @@ use opencode_api::memory::{Memory, Route as MemoryRoute}; use opencode_local::cli_config::{self, Resolved}; use opencode_parity::Fixture; use opencode_parity::app::{self, Recording, Sent, Step}; -use opencode_tui::{Args, Deps, Route}; +use opencode_plugin::{Definition, Placement, Setup, slot}; +use opencode_tui::{Args, Deps, Route, Tui}; +use opentui::prelude::*; use opentui::testing::TestApp; /// How long a checkpoint waits for its `until` text. Longer than any MS1 screen takes; a screen the Rust TUI @@ -87,6 +89,14 @@ fn run(recording: &Recording) -> (bool, String) { ..Args::default() }, ); + // The Rust twins of the TS test plugins under parity/plugins, which the Rust TUI lists as skipped (P.1). + if recording + .env + .get("OPENCODE_PARITY_PLUGIN") + .is_some_and(|plugin| plugin == "slot") + { + opencode_tui::plugins::host::add(&tui, slot_plugin()); + } let mut passed = true; let mut report = String::new(); @@ -166,6 +176,20 @@ fn run(recording: &Recording) -> (bool, String) { (passed, report) } +/// `parity/plugins/slot/tui.tsx`: one line appended to `home.footer`. +fn slot_plugin() -> Definition { + Definition::new("parity.slot", |cx: &mut Setup<'_, Tui>| { + cx.slot(Placement::append(slot::HOME_FOOTER), |tui, _| { + let app = &tui.app; + Box::new( + View::new(app) + .padding_edge(Edge::Left, 2) + .child(&Text::new(app, "slot plugin: home.footer").fg(tui.page().text.muted)), + ) + }); + }) +} + /// The scenario routes first, then each recorded read by its exact query, then by path alone. fn routes(recording: &Recording) -> Vec { let scenario = recording.routes.iter().map(|route| { diff --git a/packages/cli-rs/parity/fixtures/P.1/slot.app.json b/packages/cli-rs/parity/fixtures/P.1/slot.app.json new file mode 100644 index 00000000000..829bd8edc48 --- /dev/null +++ b/packages/cli-rs/parity/fixtures/P.1/slot.app.json @@ -0,0 +1,413 @@ +{ + "scenario": "P.1/slot", + "width": 100, + "height": 30, + "directory": "/tmp/opencode/packages/tui", + "config": { + "plugins": [ + "./plugins/slot" + ], + "animations": false + }, + "args": {}, + "env": { + "OPENCODE_PARITY_PLUGIN": "slot" + }, + "routes": [], + "steps": [ + { + "checkpoint": "home", + "until": "slot plugin: home.footer", + "masks": [ + { + "x": 16, + "y": 16, + "width": 84, + "height": 1, + "reason": "the placeholder: random in TS, not drawn yet in Rust (T17-home-prompt)" + } + ], + "deviation": [ + "P01-read-only-prompt" + ], + "fixture": "P.1/slot/home" + } + ], + "requests": { + "writes": [], + "reads": [ + { + "method": "GET", + "path": "/api/agent", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode", + "canonical": "/tmp/opencode" + } + }, + "data": [] + } + }, + { + "method": "GET", + "path": "/api/command", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode", + "canonical": "/tmp/opencode" + } + }, + "data": [] + } + }, + { + "method": "GET", + "path": "/api/config", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": [] + }, + { + "method": "GET", + "path": "/api/experimental/migration/v1", + "query": {}, + "status": 200, + "json": { + "status": "completed" + } + }, + { + "method": "GET", + "path": "/api/form", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode" + } + }, + "data": [] + } + }, + { + "method": "GET", + "path": "/api/fs/list", + "query": { + "location[directory]": [ + "" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode", + "canonical": "/tmp/opencode" + } + }, + "data": [] + } + }, + { + "method": "GET", + "path": "/api/info", + "query": {}, + "status": 200, + "json": { + "version": "test", + "pid": 0, + "urls": [], + "paths": { + "tmp": "/tmp" + }, + "capabilities": { + "persistentPty": true + } + } + }, + { + "method": "GET", + "path": "/api/integration", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode", + "canonical": "/tmp/opencode" + } + }, + "data": [] + } + }, + { + "method": "GET", + "path": "/api/location", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode", + "canonical": "/tmp/opencode" + } + } + }, + { + "method": "GET", + "path": "/api/mcp", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode", + "canonical": "/tmp/opencode" + } + }, + "data": [] + } + }, + { + "method": "GET", + "path": "/api/mcp/resource", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode", + "canonical": "/tmp/opencode" + } + }, + "data": { + "resources": [], + "templates": [] + } + } + }, + { + "method": "GET", + "path": "/api/model", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode", + "canonical": "/tmp/opencode" + } + }, + "data": [] + } + }, + { + "method": "GET", + "path": "/api/plugin", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode", + "canonical": "/tmp/opencode" + } + }, + "data": [] + } + }, + { + "method": "GET", + "path": "/api/project", + "query": {}, + "status": 200, + "json": [] + }, + { + "method": "GET", + "path": "/api/provider", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode", + "canonical": "/tmp/opencode" + } + }, + "data": [] + } + }, + { + "method": "GET", + "path": "/api/reference", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode/packages/tui", + "canonical": "/tmp/opencode/packages/tui" + } + }, + "data": [] + } + }, + { + "method": "GET", + "path": "/api/session/active", + "query": {}, + "status": 200, + "json": { + "data": {} + } + }, + { + "method": "GET", + "path": "/api/shell", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode", + "canonical": "/tmp/opencode" + } + }, + "data": [] + } + }, + { + "method": "GET", + "path": "/api/skill", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode", + "canonical": "/tmp/opencode" + } + }, + "data": [] + } + }, + { + "method": "GET", + "path": "/api/vcs", + "query": { + "location[directory]": [ + "/tmp/opencode/packages/tui" + ] + }, + "status": 200, + "json": { + "location": { + "directory": "/tmp/opencode/packages/tui", + "project": { + "id": "proj_test", + "directory": "/tmp/opencode", + "canonical": "/tmp/opencode" + } + }, + "data": { + "branch": { + "current": "main", + "default": "main" + } + } + } + } + ] + } +} diff --git a/packages/cli-rs/parity/fixtures/P.1/slot/home.json b/packages/cli-rs/parity/fixtures/P.1/slot/home.json new file mode 100644 index 00000000000..8786f5ffeb3 --- /dev/null +++ b/packages/cli-rs/parity/fixtures/P.1/slot/home.json @@ -0,0 +1,81 @@ +{ + "width": 100, + "height": 30, + "rows": [ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ▄ ", + " █▀▀█ █▀▀█ █▀▀█ █▀▀▄ █▀▀▀ █▀▀█ █▀▀█ █▀▀█ ", + " █ █ █ █ █▀▀▀ █ █ █ █ █ █ █ █▀▀▀ ", + " ▀▀▀▀ █▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ", + " ", + " ", + " ┃ ", + " ┃ ", + " ┃ ", + " ┃ ", + " ╹▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ", + " /tmp/opencode/packages/tui:main shift+tab agents ctrl+p commands ", + " ", + " ", + " ", + " ", + " ", + " ", + " test ", + " ", + " slot plugin: home.footer " + ], + "styles": [ + "#ffffffff #0a0a0aff 0", + "#808080ff #0a0a0aff 0", + "#eeeeeeff #0a0a0aff 1", + "#808080ff #282828ff 0", + "#eeeeeeff #434343ff 1", + "#282828ff #0a0a0aff 0", + "#484848ff #0a0a0aff 0", + "#ffffffff #1e1e1eff 0", + "#00000000 #00000000 0", + "#1e1e1eff #0a0a0aff 0", + "#eeeeeeff #0a0a0aff 0" + ], + "runs": [ + [[0,100]], + [[0,100]], + [[0,100]], + [[0,100]], + [[0,100]], + [[0,100]], + [[0,100]], + [[0,100]], + [[0,100]], + [[0,31],[1,19],[0,1],[2,19],[0,30]], + [[0,31],[1,19],[0,1],[2,19],[0,30]], + [[0,31],[1,1],[3,2],[1,3],[3,2],[1,3],[3,3],[1,2],[3,2],[1,1],[0,1],[2,1],[4,3],[2,2],[4,2],[2,3],[4,2],[2,3],[4,3],[0,30]], + [[0,31],[1,16],[5,2],[1,1],[0,1],[2,19],[0,30]], + [[0,100]], + [[0,100]], + [[0,13],[6,1],[7,74],[0,12]], + [[0,13],[6,1],[7,2],[8,84]], + [[0,13],[6,1],[7,74],[0,12]], + [[0,13],[6,1],[7,74],[0,12]], + [[0,13],[6,1],[9,74],[0,12]], + [[0,13],[1,31],[0,11],[10,10],[1,6],[0,2],[10,7],[1,8],[0,12]], + [[0,100]], + [[0,100]], + [[0,100]], + [[0,100]], + [[0,100]], + [[0,100]], + [[0,94],[1,4],[0,2]], + [[0,100]], + [[0,2],[1,24],[0,74]] + ] +} diff --git a/packages/cli-rs/parity/plugins/slot/tui.tsx b/packages/cli-rs/parity/plugins/slot/tui.tsx new file mode 100644 index 00000000000..8524301eb44 --- /dev/null +++ b/packages/cli-rs/parity/plugins/slot/tui.tsx @@ -0,0 +1,18 @@ +// The P.1 test plugin, TypeScript side: one line appended to the home.footer slot, after the footer built-in. +// parity/scenarios/P.1/slot.app.ts loads this directory through the cli.json `plugins` entry; the Rust TUI +// skips that entry and registers its Rust twin (`slot_plugin` in crates/tui/tests/app.rs). +import type { Context } from "../../../../plugin/src/tui/plugin" + +export default { + id: "parity.slot", + setup(context: Context) { + context.ui.slot({ + append: "home.footer", + render: () => ( + + slot plugin: home.footer + + ), + }) + }, +} diff --git a/packages/cli-rs/parity/scenarios/P.1/slot.app.ts b/packages/cli-rs/parity/scenarios/P.1/slot.app.ts new file mode 100644 index 00000000000..a2180ae3bf7 --- /dev/null +++ b/packages/cli-rs/parity/scenarios/P.1/slot.app.ts @@ -0,0 +1,25 @@ +// A plugin in a slot (P.1): a test plugin appends a line to home.footer, under the footer built-in. TS loads it +// from parity/plugins/slot as a local plugin; Rust registers its twin when OPENCODE_PARITY_PLUGIN is `slot`. +import { defineApp } from "../../lib/app" + +export default defineApp({ + config: { plugins: ["./plugins/slot"] }, + env: { OPENCODE_PARITY_PLUGIN: "slot" }, + steps: [ + { + checkpoint: "home", + until: "slot plugin: home.footer", + masks: [ + { + x: 16, + y: 16, + width: 84, + height: 1, + reason: "the placeholder: random in TS, not drawn yet in Rust (T17-home-prompt)", + }, + ], + // The prompt footer hints are E.14's. + deviation: ["P01-read-only-prompt"], + }, + ], +})