mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 08:39:02 +03:00
fix(cli-rs): leave Luau out on x86_64 Windows MSVC for now
This commit is contained in:
@@ -154,7 +154,8 @@ it, how a handler waits (tasks, `await`, timers), the limits, and the shortest p
|
||||
process, in a sandboxed Luau VM of its own with a CPU budget and a 32 MiB heap; a project's plugin waits for the
|
||||
user's approval. `crates/plugin/examples/luau` holds the examples, and `crates/plugin/src/luau/opencode` the type stub
|
||||
that `luau-analyze` and luau-lsp read (`bun run check:luau-types` checks the examples). `OPENCODE_PLUGIN_LUAU=0` turns
|
||||
Luau plugins off.
|
||||
Luau plugins off. Not yet on x86_64 Windows, whose OpenTUI v0.9.2 library doesn't link beside Luau: a Luau plugin is
|
||||
listed as skipped there.
|
||||
- [`docs/P.4.md`](docs/P.4.md) is the reference: discovery, the JS host, and how to debug a TypeScript plugin.
|
||||
|
||||
`/plugins` shows each plugin's state, and the error of one that failed or was skipped ("view error"). The log (`opencode.log` in the `log`
|
||||
|
||||
@@ -26,8 +26,6 @@ url.workspace = true
|
||||
# The hash an approval of a project plugin names (rich-plugins 3.9).
|
||||
ring.workspace = true
|
||||
|
||||
# Luau plugins (O-178): a fourth carrier of contract 2.0, behind the default feature `luau`.
|
||||
mlua = { workspace = true, optional = true }
|
||||
|
||||
[features]
|
||||
# TypeScript TUI plugins on the JS host: the pipe carrier, the JS host and its embedded `host.ts` and `compat.js`
|
||||
@@ -37,6 +35,11 @@ ts = []
|
||||
# Luau plugins, in process (O-178). On by default; `OPENCODE_PLUGIN_LUAU=0` turns them off at run time.
|
||||
luau = ["dep:mlua"]
|
||||
|
||||
# Luau plugins (O-178): a fourth carrier of contract 2.0, behind the default feature `luau`. Not on x86_64 Windows MSVC
|
||||
# until OpenTUI's library links beside it (build.rs).
|
||||
[target.'cfg(not(all(target_arch = "x86_64", target_os = "windows", target_env = "msvc")))'.dependencies]
|
||||
mlua = { workspace = true, optional = true }
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
# Who owns the approvals file, and opening it without following a link.
|
||||
libc.workspace = true
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//! `cfg(luau)`: the `luau` feature, on a target whose link takes Luau. Code that runs Luau plugins is behind it, not
|
||||
//! behind the feature alone.
|
||||
|
||||
fn main() {
|
||||
println!("cargo::rustc-check-cfg=cfg(luau)");
|
||||
println!("cargo::rerun-if-changed=build.rs");
|
||||
// TODO(OpenTUI past v0.9.2): Luau is off on x86_64 Windows MSVC, the same target Cargo.toml leaves mlua out on.
|
||||
// OpenTUI v0.9.2's static library there bundles mingw's gdtoa, whose strtopx.obj (pulled by its sscanf) defines
|
||||
// `strtold`; ucrt's strtod.obj, which Luau's `strtod` pulls in, defines it too: LNK2005. Take this out once OpenTUI
|
||||
// ships a Windows library without bundled libc symbols.
|
||||
let cfg = |key: &str| std::env::var(format!("CARGO_CFG_TARGET_{key}")).unwrap_or_default();
|
||||
let windows_x64_msvc = cfg("ARCH") == "x86_64" && cfg("OS") == "windows" && cfg("ENV") == "msvc";
|
||||
if std::env::var_os("CARGO_FEATURE_LUAU").is_some() && !windows_x64_msvc {
|
||||
println!("cargo::rustc-cfg=luau");
|
||||
}
|
||||
}
|
||||
@@ -287,7 +287,7 @@ impl Default for Monitor {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
thread_local! {
|
||||
/// The thread's CPU time as the monitored call that runs began, when the monitor read the real clock.
|
||||
static CALL_CPU: Cell<Option<Duration>> = const { Cell::new(None) };
|
||||
@@ -295,23 +295,23 @@ thread_local! {
|
||||
|
||||
/// The thread's CPU time as the monitored call that runs on this thread began: one reading for the monitor and for a
|
||||
/// Luau call's budget. `None` outside a monitored call, or when a test set the monitor's clock.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
pub(crate) fn call_cpu() -> Option<Duration> {
|
||||
CALL_CPU.with(Cell::get)
|
||||
}
|
||||
|
||||
/// Publishes a monitored call's starting CPU time until it drops, also by unwinding.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
struct Published(Option<Duration>);
|
||||
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
impl Published {
|
||||
fn new(cpu: Option<Duration>) -> Self {
|
||||
Self(CALL_CPU.with(|call| call.replace(cpu)))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
impl Drop for Published {
|
||||
fn drop(&mut self) {
|
||||
CALL_CPU.with(|call| call.set(self.0));
|
||||
@@ -529,7 +529,7 @@ impl Monitor {
|
||||
(self.clock.borrow().clone(), self.queued.borrow().clone(), self.cpu.borrow().clone());
|
||||
let (start, waited, used) = (clock(), queued(), cpu());
|
||||
// A Luau call arms its budget from this reading rather than taking its own ([`call_cpu`]).
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
let _published = Published::new(used.filter(|_| !self.injected.get()));
|
||||
let generation = self.record.get().map(|(record, epoch)| {
|
||||
let now = if self.injected.get() { Instant::now() } else { start };
|
||||
|
||||
@@ -15,7 +15,7 @@ pub mod interact;
|
||||
pub mod limits;
|
||||
mod list;
|
||||
pub mod loader;
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
pub mod luau;
|
||||
pub mod mailbox;
|
||||
pub mod node;
|
||||
@@ -23,7 +23,7 @@ pub mod node;
|
||||
pub mod pipe;
|
||||
// A build with `luau` and without `ts` has no JS host: the Luau carrier walks its plugin directories with the pipe's
|
||||
// tree walker alone, of which what only the JS host calls goes unused.
|
||||
#[cfg(all(feature = "luau", not(feature = "ts")))]
|
||||
#[cfg(all(luau, not(feature = "ts")))]
|
||||
pub mod pipe {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) mod tree;
|
||||
@@ -2451,6 +2451,13 @@ pub const SKIPPED_JS_OFF: &str = "TypeScript TUI plugins run on the JS host, whi
|
||||
/// Why a TypeScript plugin is not loaded in a build without the `ts` feature, which has no JS host at all (ts-feature).
|
||||
pub const SKIPPED_NO_TS: &str =
|
||||
"this build of opencode-native has no TypeScript plugin support (built without the ts feature)";
|
||||
/// Why a Luau plugin is not loaded in a build without Luau: built without the `luau` feature, or on x86_64 Windows
|
||||
/// MSVC, where Luau is off until OpenTUI's library links beside it (build.rs).
|
||||
pub const SKIPPED_NO_LUAU: &str = if cfg!(feature = "luau") {
|
||||
"Luau plugins do not run on x86_64 Windows yet: OpenTUI's library there does not link beside Luau"
|
||||
} else {
|
||||
"this build of opencode-native has no Luau plugin support (built without the luau feature)"
|
||||
};
|
||||
/// Why a TypeScript plugin is not loaded when no JS host runs: [`SKIPPED_JS_OFF`], or [`SKIPPED_NO_TS`] in a build without
|
||||
/// the `ts` feature, which has none to turn on.
|
||||
pub const SKIPPED_OFF: &str = if cfg!(feature = "ts") { SKIPPED_JS_OFF } else { SKIPPED_NO_TS };
|
||||
|
||||
@@ -172,7 +172,7 @@ thread_local! {
|
||||
|
||||
/// Forgets this thread's last hash of the tree `target`: the next [`Artifact::tree`] of it reads every file, however
|
||||
/// its entries' metadata stayed.
|
||||
#[cfg(any(feature = "ts", feature = "luau"))]
|
||||
#[cfg(any(feature = "ts", luau))]
|
||||
pub(crate) fn forget(target: &Path) {
|
||||
if let Ok(path) = std::fs::canonicalize(target) {
|
||||
TREES.with(|trees| trees.borrow_mut().remove(&path));
|
||||
@@ -328,7 +328,7 @@ thread_local! {
|
||||
}
|
||||
|
||||
/// The SHA-256 in hex of the file at `path`, counted in [`hashed`].
|
||||
#[cfg(any(feature = "ts", feature = "luau"))]
|
||||
#[cfg(any(feature = "ts", luau))]
|
||||
pub(crate) fn digest_file(path: &Path) -> Result<String, String> {
|
||||
let mut file = File::open(path).map_err(|error| format!("{}: {error}", path.display()))?;
|
||||
sha256(&mut file).map_err(|error| format!("{}: {error}", path.display()))
|
||||
|
||||
@@ -115,7 +115,7 @@ pub enum Found {
|
||||
Tree(PathBuf),
|
||||
/// A Luau plugin's directory, hashed as a TypeScript plugin's tree and approved as a Luau plugin
|
||||
/// ([`crate::luau::artifact`]); also identified off the UI thread.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Luau(PathBuf),
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ impl Found {
|
||||
match self {
|
||||
Self::Build(identified) => identified,
|
||||
Self::Tree(dir) => Artifact::tree(&dir),
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Self::Luau(dir) => Artifact::tree(&dir).map(crate::luau::artifact),
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ impl Found {
|
||||
match self {
|
||||
Self::Build(_) => false,
|
||||
Self::Tree(_) => true,
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Self::Luau(_) => true,
|
||||
}
|
||||
}
|
||||
@@ -185,10 +185,10 @@ pub struct Loader {
|
||||
packages: RefCell<HashMap<String, npm::Package>>,
|
||||
/// A directory with a `plugin.toml` and no native build runs as a Luau plugin ([`crate::luau`]), its files walked,
|
||||
/// hashed and staged on threads of their own, as a TypeScript plugin's are (FT-2).
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
luau: Option<crate::pipe::tree::Trees>,
|
||||
/// A Luau plugin's sources, read and compiled on threads of their own.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
luau_builds: Option<crate::luau::Builds>,
|
||||
}
|
||||
|
||||
@@ -246,9 +246,9 @@ impl Loader {
|
||||
npm: None,
|
||||
server: RefCell::default(),
|
||||
packages: RefCell::default(),
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
luau: None,
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
luau_builds: None,
|
||||
}
|
||||
}
|
||||
@@ -256,7 +256,7 @@ impl Loader {
|
||||
/// Runs the directories with a `plugin.toml` and no native build as Luau plugins. `walked` runs on a walk's thread
|
||||
/// when a walk of a plugin's files found something new, a copy of approved files ended, or a build was compiled:
|
||||
/// the host reconciles.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
pub fn with_luau(self, walked: impl Fn() + Send + Sync + 'static) -> Self {
|
||||
let walked: std::sync::Arc<dyn Fn() + Send + Sync> = std::sync::Arc::new(walked);
|
||||
let wake = walked.clone();
|
||||
@@ -268,7 +268,7 @@ impl Loader {
|
||||
}
|
||||
|
||||
/// Whether `target` runs as a Luau plugin: it is a directory with a `plugin.toml` and no native build.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
fn luau_target(&self, target: &Target) -> bool {
|
||||
self.luau.is_some()
|
||||
&& target.library().is_none()
|
||||
@@ -276,19 +276,19 @@ impl Loader {
|
||||
}
|
||||
|
||||
/// Whether a walk, a copy or a compilation of a Luau plugin's files runs.
|
||||
#[cfg(all(test, feature = "luau"))]
|
||||
#[cfg(all(test, luau))]
|
||||
pub(crate) fn luau_walking(&self) -> bool {
|
||||
self.luau.as_ref().is_some_and(crate::pipe::tree::Trees::walking)
|
||||
|| self.luau_builds.as_ref().is_some_and(crate::luau::Builds::running)
|
||||
}
|
||||
|
||||
/// Whether a compiled Luau build waits for the next reconcile.
|
||||
#[cfg(all(test, feature = "luau"))]
|
||||
#[cfg(all(test, luau))]
|
||||
pub(crate) fn luau_ready(&self) -> bool {
|
||||
self.luau_builds.as_ref().is_some_and(crate::luau::Builds::ready)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "luau"))]
|
||||
#[cfg(not(luau))]
|
||||
fn luau_target(&self, _: &Target) -> bool {
|
||||
false
|
||||
}
|
||||
@@ -613,7 +613,7 @@ impl Loader {
|
||||
changed = true;
|
||||
}
|
||||
self.listed.replace(targets.iter().map(|target| target.target.clone()).collect());
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
if let Some(builds) = &self.luau_builds {
|
||||
builds.retain(|name| targets.iter().any(|known| known.target == name && self.luau_target(known)));
|
||||
}
|
||||
@@ -667,12 +667,16 @@ impl Loader {
|
||||
registry.set_unloaded(name, status);
|
||||
changed
|
||||
};
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
if self.luau_target(target)
|
||||
&& let Some(dir) = &target.local
|
||||
{
|
||||
return self.luau(host, registry, target, dir, &listed);
|
||||
}
|
||||
#[cfg(not(luau))]
|
||||
if target.library().is_none() && target.local.as_deref().is_some_and(|dir| dir.join("plugin.toml").is_file()) {
|
||||
return skip(crate::SKIPPED_NO_LUAU);
|
||||
}
|
||||
#[cfg(feature = "ts")]
|
||||
if self.scripted(target)
|
||||
&& let (Some(scripts), Some(dir)) = (&self.scripts, &target.local)
|
||||
@@ -895,7 +899,7 @@ impl Loader {
|
||||
/// ([`crate::luau::artifact`]), from the staged copy of the approved bytes, made off the UI thread too. It is
|
||||
/// admitted as a native build is ([`Registry::admit`]): a build the crash list names, safe mode and a client no
|
||||
/// parent guards hold it.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
fn luau(
|
||||
&self,
|
||||
host: &Rc<dyn Host>,
|
||||
@@ -1045,7 +1049,7 @@ impl Loader {
|
||||
/// TypeScript tree to hash ([`Found::identify`]). `None` when it is no target.
|
||||
pub fn found(&self, target: &str) -> Option<Found> {
|
||||
let known = self.targets().into_iter().find(|known| known.target == target)?;
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
if let (true, Some(dir)) = (self.luau_target(&known), &known.local) {
|
||||
return Some(Found::Luau(dir.clone()));
|
||||
}
|
||||
@@ -1222,7 +1226,7 @@ pub fn project_root(cwd: &Path) -> PathBuf {
|
||||
}
|
||||
|
||||
/// Lists the Luau plugin `name` as starting while its files are walked: whether the manager's list changed.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
fn luau_starting(registry: &Registry, name: &str, listed: &Option<Status>) -> bool {
|
||||
let status = Status::Skipped(crate::luau::STARTING.to_owned());
|
||||
let changed = listed.as_ref() != Some(&status);
|
||||
@@ -1278,7 +1282,7 @@ pub fn has_native_build(config_dir: &Path, cwd: &Path, configured: &[&str]) -> b
|
||||
discovered.chain(configured).flatten().any(|local| {
|
||||
let target = Target { target: String::new(), local: Some(local), options: None, project: false };
|
||||
// A Luau plugin runs in process too, and the crash list holds its build as it holds a library's.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
if crate::luau::enabled()
|
||||
&& target.library().is_none()
|
||||
&& target.local.as_deref().is_some_and(crate::luau::is_plugin)
|
||||
|
||||
@@ -2282,3 +2282,18 @@ fn a_build_without_ts_says_it_has_no_typescript_plugin_support() {
|
||||
assert_eq!(entry(®istry.entries(), "tui-pkg@1.0.0").status, skipped);
|
||||
assert_eq!(entry(®istry.entries(), &native).status, Status::Pending);
|
||||
}
|
||||
|
||||
// Expected (win-x64-link): a build without Luau, by feature or on x86_64 Windows MSVC, lists a Luau plugin directory as
|
||||
// skipped, saying it has no Luau support, not a TypeScript reason; a native build beside it loads.
|
||||
#[cfg(not(luau))]
|
||||
#[test]
|
||||
fn a_build_without_luau_says_it_has_no_luau_plugin_support() {
|
||||
let project = Project::new();
|
||||
write(&project.global().join("plugin.toml"), "id = \"hello\"\n");
|
||||
let native = project.plugin("native", "id=native");
|
||||
let (host, registry) = (host(), Registry::define(Vec::new(), []));
|
||||
project.loader(Rc::new(Fake::default()), Vec::new()).reconcile(&dynamic(&host), ®istry);
|
||||
let skipped = Status::Skipped(crate::SKIPPED_NO_LUAU.to_owned());
|
||||
assert_eq!(entry(®istry.entries(), &project.global().to_string_lossy()).status, skipped);
|
||||
assert_eq!(entry(®istry.entries(), &native).status, Status::Pending);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//! `cfg(luau)`: the `luau` feature, on a target whose link takes Luau. Code that runs Luau plugins is behind it, not
|
||||
//! behind the feature alone.
|
||||
|
||||
fn main() {
|
||||
println!("cargo::rustc-check-cfg=cfg(luau)");
|
||||
println!("cargo::rerun-if-changed=build.rs");
|
||||
// TODO(OpenTUI past v0.9.2): Luau is off on x86_64 Windows MSVC, the same target Cargo.toml leaves mlua out on.
|
||||
// OpenTUI v0.9.2's static library there bundles mingw's gdtoa, whose strtopx.obj (pulled by its sscanf) defines
|
||||
// `strtold`; ucrt's strtod.obj, which Luau's `strtod` pulls in, defines it too: LNK2005. Take this out once OpenTUI
|
||||
// ships a Windows library without bundled libc symbols.
|
||||
let cfg = |key: &str| std::env::var(format!("CARGO_CFG_TARGET_{key}")).unwrap_or_default();
|
||||
let windows_x64_msvc = cfg("ARCH") == "x86_64" && cfg("OS") == "windows" && cfg("ENV") == "msvc";
|
||||
if std::env::var_os("CARGO_FEATURE_LUAU").is_some() && !windows_x64_msvc {
|
||||
println!("cargo::rustc-cfg=luau");
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ fn question(target: &str, artifact: &Artifact, unsaved: Option<&str>) -> String
|
||||
unsaved.map(|reason| format!("\nYour answer lasts until opencode exits: {reason}.")).unwrap_or_default();
|
||||
// The real path as a user would type it: Windows' canonical form starts `\\?\` (`\\?\C:\`, `\\?\UNC\`).
|
||||
let path = opencode_util::path::strip_verbatim(&artifact.path.to_string_lossy()).into_owned();
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
if opencode_plugin::luau::approves(artifact) {
|
||||
return format!(
|
||||
"This project wants to run a Luau plugin inside opencode:\n\n{target}\nPlugin directory: {path}\
|
||||
@@ -141,7 +141,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
#[test]
|
||||
fn a_luau_plugin_is_asked_about_as_one() {
|
||||
let tree = Artifact { target: "/p".into(), path: "/p".into(), sha256: "ab".repeat(32), script: true };
|
||||
|
||||
@@ -217,7 +217,7 @@ impl Host for Tui {
|
||||
|
||||
fn pending(&self, target: &str) {
|
||||
let held = held(self, target).and_then(|(artifact, _)| artifact.ok());
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
if held.as_ref().is_some_and(opencode_plugin::luau::approves) {
|
||||
let message =
|
||||
"This project wants to run a Luau plugin inside opencode. Run /plugins to approve or decline it.";
|
||||
@@ -1359,7 +1359,7 @@ fn tell_skipped(tui: &Tui) {
|
||||
for entry in tui.plugins.entries() {
|
||||
let Status::Skipped(reason) = &entry.status else { continue };
|
||||
let starting = reason == opencode_plugin::loader::STARTING;
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
let starting = starting || reason == opencode_plugin::luau::STARTING;
|
||||
if !entry.key.starts_with("target:") || starting || !told.insert(entry.key) {
|
||||
continue;
|
||||
@@ -1522,7 +1522,7 @@ pub fn external_with(tui: &Rc<Tui>, external: External, scripts: Option<JsHost>)
|
||||
let project = opencode_plugin::loader::project_root(&external.cwd);
|
||||
let loader = Loader::new(Rc::new(Native), external.config_dir, external.cwd, entries);
|
||||
// Luau plugins (O-178): on in a build with them, unless `OPENCODE_PLUGIN_LUAU=0` turns them off.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
let loader = match opencode_plugin::luau::enabled() {
|
||||
true => {
|
||||
let proxy = tui.app.proxy();
|
||||
|
||||
@@ -95,7 +95,7 @@ const PORTS: [(&str, &str); 10] = [
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
enum Swap {
|
||||
Native(&'static str),
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Luau(&'static str),
|
||||
}
|
||||
|
||||
@@ -111,9 +111,9 @@ fn ports_replay_the_ts_recordings() {
|
||||
for (scenario, port) in PORTS {
|
||||
let recordings = Recording::all(Some(scenario)).unwrap_or_else(|error| panic!("{error}"));
|
||||
let recording = recordings.iter().find(|recording| recording.scenario == scenario).expect(scenario);
|
||||
#[cfg_attr(not(feature = "luau"), allow(unused_mut))]
|
||||
#[cfg_attr(not(luau), allow(unused_mut))]
|
||||
let mut swaps = vec![Swap::Native(port)];
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
swaps.push(Swap::Luau(port));
|
||||
for swap in swaps {
|
||||
let (passed, report) = run(recording, false, Some(swapped(swap)));
|
||||
@@ -274,9 +274,9 @@ fn run(
|
||||
let starting = || {
|
||||
tui.plugins.entries().iter().any(|entry| match &entry.status {
|
||||
opencode_plugin::Status::Skipped(reason) => {
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
let luau = reason == opencode_plugin::luau::STARTING;
|
||||
#[cfg(not(feature = "luau"))]
|
||||
#[cfg(not(luau))]
|
||||
let luau = false;
|
||||
luau || reason == opencode_plugin::loader::STARTING
|
||||
}
|
||||
@@ -674,7 +674,7 @@ fn swapped(swap: Swap) -> (opencode_util::temp::TempDir, std::path::PathBuf) {
|
||||
.expect("library");
|
||||
dir
|
||||
}
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Swap::Luau(name) => {
|
||||
let dir = root.path().join(format!("{name}.luau"));
|
||||
let examples = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../plugin/examples/luau");
|
||||
|
||||
@@ -46,7 +46,7 @@ mod plugin_fetch;
|
||||
mod plugin_flood;
|
||||
pub mod plugin_input;
|
||||
mod plugin_limits;
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
mod plugin_luau;
|
||||
mod plugin_machines;
|
||||
mod plugin_mail;
|
||||
|
||||
@@ -83,7 +83,7 @@ enum Carrier {
|
||||
CAbi,
|
||||
Pipe,
|
||||
/// A Luau plugin (spike `luau-spike`), in process on the linked path.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Luau,
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ fn request_ownership_over_the_pipe() {
|
||||
}
|
||||
|
||||
// Expected (luau-spike 1.2): a Luau plugin is on the linked path, so every row holds for it as in process.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
#[test]
|
||||
fn request_ownership_in_luau() {
|
||||
table(Carrier::Luau);
|
||||
@@ -223,9 +223,9 @@ fn request_ownership_in_luau() {
|
||||
// the route opens again and the server answers. In process, through the C ABI and in Luau.
|
||||
#[test]
|
||||
fn a_task_parked_on_its_mounts_fetch_goes_on_once_cancelled() {
|
||||
#[cfg_attr(not(feature = "luau"), allow(unused_mut))]
|
||||
#[cfg_attr(not(luau), allow(unused_mut))]
|
||||
let mut carriers = vec![Carrier::InProcess, Carrier::CAbi];
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
carriers.push(Carrier::Luau);
|
||||
for carrier in carriers {
|
||||
parked(carrier);
|
||||
@@ -242,7 +242,7 @@ fn parked(carrier: Carrier) {
|
||||
let entries = abi::export_plugin!(@loopback "test.parked", parked_plugin);
|
||||
opencode_plugin::loader::native::loopback(&host, entries).unwrap().0
|
||||
}
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Carrier::Luau => {
|
||||
let sources = opencode_plugin::luau::Sources::from_files([
|
||||
("plugin.toml", "id = \"test.parked\""),
|
||||
@@ -255,7 +255,7 @@ fn parked(carrier: Carrier) {
|
||||
opencode_tui::plugins::host::add(&h.tui, definition);
|
||||
let route = Route::Plugin { id: "test.parked".into(), name: "probe".into() };
|
||||
let resumed = || match carrier {
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Carrier::Luau => {
|
||||
let stored = opencode_plugin::Host::storage_read(&*h.tui, "plugin.test.parked.seen");
|
||||
let seen: Vec<String> = stored.and_then(|json| serde_json::from_str(&json).ok()).unwrap_or_default();
|
||||
@@ -313,7 +313,7 @@ fn parked_plugin(setup: &mut abi::Setup) -> Result<(), String> {
|
||||
}
|
||||
|
||||
/// [`parked_plugin`] in Luau: the surface's handler is the task; it records in its storage what its fetch gave.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
fn parked_script() -> String {
|
||||
let page = luau_literal(&serde_json::to_value(page()).unwrap());
|
||||
format!(
|
||||
@@ -752,7 +752,7 @@ enum Probe {
|
||||
Native(Harness),
|
||||
Pipe(Pipe, PathBuf),
|
||||
/// The Luau probe, which records what it saw in its storage.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Luau(Harness),
|
||||
}
|
||||
|
||||
@@ -770,7 +770,7 @@ impl Probe {
|
||||
pipe.active("example.probe");
|
||||
return Probe::Pipe(pipe, log);
|
||||
}
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
if carrier == Carrier::Luau {
|
||||
let harness = support::mount(80, 24, Deps { route: Route::Home, ..deps });
|
||||
let init = luau_script(row, mark);
|
||||
@@ -803,7 +803,7 @@ impl Probe {
|
||||
match self {
|
||||
Probe::Native(harness) => harness,
|
||||
Probe::Pipe(pipe, _) => &pipe.harness,
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Probe::Luau(harness) => harness,
|
||||
}
|
||||
}
|
||||
@@ -812,7 +812,7 @@ impl Probe {
|
||||
match self {
|
||||
Probe::Native(_) => "test.probe",
|
||||
Probe::Pipe(..) => "example.probe",
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Probe::Luau(_) => "test.probe",
|
||||
}
|
||||
}
|
||||
@@ -833,7 +833,7 @@ impl Probe {
|
||||
.filter_map(|line| line.strip_prefix("other "))
|
||||
.map(|mounted| mounted == "true")
|
||||
.collect(),
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Probe::Luau(harness) => luau_seen(harness, "other").iter().filter_map(serde_json::Value::as_bool).collect(),
|
||||
}
|
||||
}
|
||||
@@ -847,7 +847,7 @@ impl Probe {
|
||||
lines(log).into_iter().filter(|line| line.starts_with("asked")).map(|_| None).collect()
|
||||
}
|
||||
// 0 names no request: an effect, or a request the host did not take.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Probe::Luau(harness) => {
|
||||
luau_seen(harness, "asked").iter().map(|id| id.as_u64().filter(|id| *id != 0)).collect()
|
||||
}
|
||||
@@ -863,7 +863,7 @@ impl Probe {
|
||||
.into_iter()
|
||||
.filter_map(|line| line.strip_prefix("settled ").map(|settled| (None, settled.to_owned())))
|
||||
.collect(),
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Probe::Luau(harness) => luau_seen(harness, "replies")
|
||||
.iter()
|
||||
.map(|reply| (reply["id"].as_u64(), reply["text"].as_str().unwrap_or_default().to_owned()))
|
||||
@@ -1084,7 +1084,7 @@ export default {{ id: "example.probe", setup(api) {{
|
||||
}
|
||||
|
||||
/// What the Luau probe recorded under `field` of its storage.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
fn luau_seen(harness: &Harness, field: &str) -> Vec<serde_json::Value> {
|
||||
let stored = opencode_plugin::Host::storage_read(&*harness.tui, "plugin.test.probe.seen");
|
||||
let seen: serde_json::Value = stored.and_then(|json| serde_json::from_str(&json).ok()).unwrap_or_default();
|
||||
@@ -1092,7 +1092,7 @@ fn luau_seen(harness: &Harness, field: &str) -> Vec<serde_json::Value> {
|
||||
}
|
||||
|
||||
/// A JSON value as a Luau literal.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
fn luau_literal(value: &serde_json::Value) -> String {
|
||||
match value {
|
||||
serde_json::Value::Null => "nil".to_owned(),
|
||||
@@ -1115,7 +1115,7 @@ fn luau_literal(value: &serde_json::Value) -> String {
|
||||
|
||||
/// The probe in Luau: the same calls as the Rust one, which record in its storage what the calls got and what the
|
||||
/// replies said; its program is the Rust one's.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
fn luau_script(row: Row, mark: &Path) -> String {
|
||||
let (command, args) = witness(mark);
|
||||
let (kind, origin, close) = (format!("{:?}", row.kind), format!("{:?}", row.origin), format!("{:?}", row.close));
|
||||
|
||||
@@ -24,7 +24,7 @@ thread_local! {
|
||||
enum Carrier {
|
||||
Linked,
|
||||
CAbi,
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Luau,
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ fn carriers() -> Vec<Carrier> {
|
||||
vec![
|
||||
Carrier::Linked,
|
||||
Carrier::CAbi,
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Carrier::Luau,
|
||||
]
|
||||
}
|
||||
@@ -85,7 +85,7 @@ fn open(carrier: Carrier) -> Harness {
|
||||
let entries = abi::export_plugin!(@loopback "test.focus", probe);
|
||||
opencode_plugin::loader::native::loopback(&host, entries).unwrap().0
|
||||
}
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Carrier::Luau => {
|
||||
let sources = opencode_plugin::luau::Sources::from_files([
|
||||
("plugin.toml", "id = \"test.focus\""),
|
||||
@@ -146,7 +146,7 @@ fn page(wide: bool, show: bool) -> v2::Node {
|
||||
}
|
||||
|
||||
/// The probe in Luau.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
const LUAU: &str = r#"local plugin = require("@opencode/plugin")
|
||||
local show = false
|
||||
local function text(text) return { type = "text", spans = { { text = text } } } end
|
||||
|
||||
@@ -33,7 +33,7 @@ fn ticking(setup: &mut abi::Setup) -> Result<(), String> {
|
||||
}
|
||||
|
||||
/// [`ticking`] in Luau.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
const TICKING: &str = r#"local plugin = require("@opencode/plugin")
|
||||
return plugin.define(function(setup)
|
||||
plugin.every(1000, function() end)
|
||||
@@ -50,7 +50,7 @@ end)
|
||||
enum Carrier {
|
||||
InProcess,
|
||||
CAbi,
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Luau,
|
||||
}
|
||||
|
||||
@@ -59,9 +59,9 @@ enum Carrier {
|
||||
// no more. In process, through the C ABI and in Luau.
|
||||
#[test]
|
||||
fn a_ticking_plugin_that_changes_nothing_makes_no_frame() {
|
||||
#[cfg_attr(not(feature = "luau"), allow(unused_mut))]
|
||||
#[cfg_attr(not(luau), allow(unused_mut))]
|
||||
let mut carriers = vec![Carrier::InProcess, Carrier::CAbi];
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
carriers.push(Carrier::Luau);
|
||||
for carrier in carriers {
|
||||
ticks_without_frames(carrier);
|
||||
@@ -77,7 +77,7 @@ fn ticks_without_frames(carrier: Carrier) {
|
||||
let entries = abi::export_plugin!(@loopback "test.tick", ticking);
|
||||
opencode_plugin::loader::native::loopback(&host, entries).unwrap().0
|
||||
}
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Carrier::Luau => {
|
||||
let sources = opencode_plugin::luau::Sources::from_files([
|
||||
("plugin.toml", "id = \"test.tick\""),
|
||||
@@ -185,7 +185,7 @@ fn every_of_a_mount(setup: &mut abi::Setup) -> Result<(), String> {
|
||||
}
|
||||
|
||||
/// [`every_of_a_mount`] in Luau: it counts its ticks in its storage.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
const EVERY_OF_A_MOUNT: &str = r#"local plugin = require("@opencode/plugin")
|
||||
return plugin.define(function(setup)
|
||||
setup:storageKey("ticks")
|
||||
@@ -212,9 +212,9 @@ end)
|
||||
// activation; so the loop ends when the mount closes. In process, through the C ABI and in Luau.
|
||||
#[test]
|
||||
fn an_every_a_mount_started_ends_with_that_mount() {
|
||||
#[cfg_attr(not(feature = "luau"), allow(unused_mut))]
|
||||
#[cfg_attr(not(luau), allow(unused_mut))]
|
||||
let mut carriers = vec![Carrier::InProcess, Carrier::CAbi];
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
carriers.push(Carrier::Luau);
|
||||
for carrier in carriers {
|
||||
MOUNT_TICKS.set(0);
|
||||
@@ -225,7 +225,7 @@ fn an_every_a_mount_started_ends_with_that_mount() {
|
||||
let entries = abi::export_plugin!(@loopback "test.tick", every_of_a_mount);
|
||||
opencode_plugin::loader::native::loopback(&host, entries).unwrap().0
|
||||
}
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Carrier::Luau => {
|
||||
let files = [("plugin.toml", "id = \"test.tick\""), ("init.luau", EVERY_OF_A_MOUNT)];
|
||||
opencode_plugin::luau::define(&opencode_plugin::luau::Sources::from_files(files), None).unwrap().0
|
||||
@@ -234,7 +234,7 @@ fn an_every_a_mount_started_ends_with_that_mount() {
|
||||
};
|
||||
opencode_tui::plugins::host::add(&h.tui, definition);
|
||||
let ticks = || match carrier {
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Carrier::Luau => opencode_plugin::Host::storage_read(&*h.tui, "plugin.test.tick.ticks")
|
||||
.and_then(|json| serde_json::from_str::<serde_json::Value>(&json).ok())
|
||||
.and_then(|ticks| ticks["n"].as_u64())
|
||||
|
||||
@@ -123,7 +123,7 @@ pub(crate) enum Carrier<'a> {
|
||||
Npm(&'a str),
|
||||
/// The port's Luau twin (`crates/plugin/examples/luau/<name>`, spike `luau-spike`), in `<config>/plugins` as a user
|
||||
/// installs one, which the loader loads with Luau plugins on.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Luau(&'a str),
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ pub(crate) fn open_with(
|
||||
unpack(name, &plugin);
|
||||
plugin
|
||||
}
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
Carrier::Luau(name) => {
|
||||
let plugin = config.join("plugins").join(format!("{name}.luau"));
|
||||
crate::plugin_pipe::copy(
|
||||
@@ -769,9 +769,9 @@ fn the_published_session_usage_asks_for_the_sessions_location_first() {
|
||||
// `session.usage.updated` starts a run, as the last one ended. On the Rust port over the C ABI and on the Luau port.
|
||||
#[test]
|
||||
fn session_usage_ends_a_run_its_sidebar_closed_during() {
|
||||
#[cfg_attr(not(feature = "luau"), allow(unused_mut))]
|
||||
#[cfg_attr(not(luau), allow(unused_mut))]
|
||||
let mut carriers = vec![Carrier::Port("session-usage")];
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
carriers.push(Carrier::Luau("session-usage"));
|
||||
for carrier in carriers {
|
||||
closed_mid_run(carrier);
|
||||
@@ -785,9 +785,9 @@ fn session_usage_ends_a_run_its_sidebar_closed_during() {
|
||||
// Luau port.
|
||||
#[test]
|
||||
fn goal_plugin_counts_an_active_goals_time_each_second() {
|
||||
#[cfg_attr(not(feature = "luau"), allow(unused_mut))]
|
||||
#[cfg_attr(not(luau), allow(unused_mut))]
|
||||
let mut carriers = vec![Carrier::Port("goal-plugin")];
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
carriers.push(Carrier::Luau("goal-plugin"));
|
||||
for carrier in carriers {
|
||||
let sampled = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() - 10;
|
||||
|
||||
@@ -16,9 +16,9 @@ use serde_json::{Value, json};
|
||||
|
||||
/// The columns of a row: the published package `npm`, and the ports named `port`.
|
||||
fn columns<'a>(npm: &'a str, port: &'a str) -> Vec<Carrier<'a>> {
|
||||
#[cfg_attr(not(feature = "luau"), allow(unused_mut))]
|
||||
#[cfg_attr(not(luau), allow(unused_mut))]
|
||||
let mut columns = vec![Carrier::Npm(npm), Carrier::Port(port)];
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
columns.push(Carrier::Luau(port));
|
||||
columns
|
||||
}
|
||||
@@ -751,9 +751,9 @@ fn queue_manager_stages_sorts_clears_and_imports_alike_in_ts_rust_and_luau() {
|
||||
);
|
||||
step("cleared drafts", &["return"], None, "0 drafts");
|
||||
// A Luau plugin reads no files.
|
||||
#[cfg(feature = "luau")]
|
||||
#[cfg(luau)]
|
||||
let reads_files = !matches!(carrier, Carrier::Luau(_));
|
||||
#[cfg(not(feature = "luau"))]
|
||||
#[cfg(not(luau))]
|
||||
let reads_files = true;
|
||||
if reads_files {
|
||||
step("import", &["down", "down", "return"], Some(("messages.txt", &path)), "Stage 2 messages");
|
||||
|
||||
Reference in New Issue
Block a user