forked from 1b-agent/opencadstudio-upstream
feat(plugins): drop plugin API v2
A V2 plugin passed the version gate and then failed silently while registering its ribbon, since the ribbon wire types have moved on. The host now loads V3 and newer, so V2 plugins are rejected up front with a version message. The V2 compatibility fixture crate goes too. Fixes #1085 Fixes #987 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c45f22652d
commit
71b300cc44
6 files changed
+25
-110
No files matched your search
@@ -26,12 +26,14 @@ pub const API_VERSION: u32 = 7;
|
||||
|
||||
/// Oldest plugin API major the current host still loads. This keeps previously
|
||||
/// compiled cdylibs usable as long as their vtable layout is a prefix of the
|
||||
/// current `HostApi` trait.
|
||||
pub const API_VERSION_MIN_SUPPORTED: u32 = 2;
|
||||
/// current `HostApi` trait. V2 is no longer loaded: its ribbon wire types
|
||||
/// predate the current ones, so a V2 plugin passed the gate and then failed
|
||||
/// silently while registering its ribbon (#1085, #987).
|
||||
pub const API_VERSION_MIN_SUPPORTED: u32 = 3;
|
||||
|
||||
/// Environment variable that caps the API major accepted by the host at
|
||||
/// runtime. Set to `5` to disable V6 plugins, `4` to disable V5, or `2` for
|
||||
/// V2-only mode.
|
||||
/// runtime. Set to `5` to disable V6 plugins, `4` to disable V5, or `3` for
|
||||
/// V3-only mode.
|
||||
pub const MAX_API_VERSION_ENV: &str = "OCS_PLUGIN_MAX_API_VERSION";
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -112,18 +114,18 @@ mod tests {
|
||||
assert_eq!(effective_max_api_version(), 3);
|
||||
assert!(!host_accepts_plugin_version(4));
|
||||
assert!(host_accepts_plugin_version(3));
|
||||
assert!(host_accepts_plugin_version(2));
|
||||
assert!(!host_accepts_plugin_version(2));
|
||||
std::env::remove_var(MAX_API_VERSION_ENV);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn effective_max_v2_only_mode() {
|
||||
fn effective_max_below_minimum_is_v3_only_mode() {
|
||||
let _guard = ENV_LOCK.lock().unwrap();
|
||||
std::env::set_var(MAX_API_VERSION_ENV, "2");
|
||||
assert_eq!(effective_max_api_version(), 2);
|
||||
assert_eq!(effective_max_api_version(), 3);
|
||||
assert!(!host_accepts_plugin_version(4));
|
||||
assert!(!host_accepts_plugin_version(3));
|
||||
assert!(host_accepts_plugin_version(2));
|
||||
assert!(host_accepts_plugin_version(3));
|
||||
assert!(!host_accepts_plugin_version(2));
|
||||
std::env::remove_var(MAX_API_VERSION_ENV);
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,10 @@ mod tests {
|
||||
Some(env!("CARGO_PKG_VERSION"))
|
||||
);
|
||||
assert_eq!(value["api_version"].as_i64(), Some(crate::API_VERSION as i64));
|
||||
assert_eq!(value["api_version_min_supported"].as_i64(), Some(2));
|
||||
assert_eq!(
|
||||
value["api_version_min_supported"].as_i64(),
|
||||
Some(crate::API_VERSION_MIN_SUPPORTED as i64)
|
||||
);
|
||||
|
||||
// acadrust_version should have a patch component (e.g. "0.4.0").
|
||||
let opencadcodec = value["acadrust_version"].as_str().expect("acadrust_version string");
|
||||
|
||||
Reference in new issue
Block a user