complete secondary import migrations

This commit is contained in:
charlesgong-openai
2026-07-09 20:14:50 -04:00
parent 00e21e5036
commit daa735cfea
18 changed files with 1250 additions and 102 deletions
+85 -4
View File
@@ -162,12 +162,18 @@ pub(crate) fn parse_plugin_manifest_uri(
version,
description,
keywords,
skills,
mcp_servers,
apps,
hooks,
mut skills,
mut mcp_servers,
mut apps,
mut hooks,
interface,
} = serde_json::from_str::<RawPluginManifest>(contents)?;
if manifest_path
.to_string()
.ends_with(".cursor-plugin/plugin.json")
{
normalize_cursor_manifest_paths(&mut skills, &mut mcp_servers, &mut apps, &mut hooks);
}
let name = plugin_root
.basename()
.filter(|_| raw_name.trim().is_empty())
@@ -267,6 +273,45 @@ pub(crate) fn parse_plugin_manifest_uri(
})
}
fn normalize_cursor_manifest_paths(
skills: &mut Option<RawPluginManifestPaths>,
mcp_servers: &mut Option<RawPluginManifestMcpServers>,
apps: &mut Option<String>,
hooks: &mut Option<RawPluginManifestHooks>,
) {
match skills {
Some(RawPluginManifestPaths::Path(path)) => normalize_cursor_manifest_path(path),
Some(RawPluginManifestPaths::Paths(paths)) => {
paths.iter_mut().for_each(normalize_cursor_manifest_path);
}
Some(RawPluginManifestPaths::Invalid(_)) | None => {}
}
if let Some(RawPluginManifestMcpServers::Path(path)) = mcp_servers {
normalize_cursor_manifest_path(path);
}
if let Some(apps) = apps {
normalize_cursor_manifest_path(apps);
}
match hooks {
Some(RawPluginManifestHooks::Path(path)) => normalize_cursor_manifest_path(path),
Some(RawPluginManifestHooks::Paths(paths)) => {
paths.iter_mut().for_each(normalize_cursor_manifest_path);
}
Some(
RawPluginManifestHooks::Inline(_)
| RawPluginManifestHooks::InlineList(_)
| RawPluginManifestHooks::Invalid(_),
)
| None => {}
}
}
fn normalize_cursor_manifest_path(path: &mut String) {
if !path.starts_with("./") {
path.insert_str(0, "./");
}
}
fn resolve_manifest_hooks(
plugin_root: &PathUri,
hooks: Option<RawPluginManifestHooks>,
@@ -532,6 +577,7 @@ mod tests {
use crate::ExecutorPluginProvider;
const ALTERNATE_PLUGIN_MANIFEST_RELATIVE_PATH: &str = ".claude-plugin/plugin.json";
const CURSOR_PLUGIN_MANIFEST_RELATIVE_PATH: &str = ".cursor-plugin/plugin.json";
fn write_manifest(plugin_root: &Path, version: Option<&str>, interface: &str) {
fs::create_dir_all(plugin_root.join(".codex-plugin")).expect("create manifest dir");
@@ -558,6 +604,13 @@ mod tests {
fs::write(manifest_path, contents).expect("write manifest");
}
fn write_cursor_plugin_manifest(plugin_root: &Path, contents: &str) {
let manifest_path = plugin_root.join(CURSOR_PLUGIN_MANIFEST_RELATIVE_PATH);
fs::create_dir_all(manifest_path.parent().expect("manifest parent"))
.expect("create manifest dir");
fs::write(manifest_path, contents).expect("write manifest");
}
fn load_manifest(plugin_root: &Path) -> PluginManifest {
load_plugin_manifest(plugin_root).expect("load plugin manifest")
}
@@ -732,6 +785,34 @@ mod tests {
);
}
#[test]
fn cursor_plugin_manifest_accepts_bare_relative_paths() {
let tmp = tempdir().expect("tempdir");
let plugin_root = tmp.path().join("demo-plugin");
write_cursor_plugin_manifest(
&plugin_root,
r#"{
"name": "demo-plugin",
"skills": "skills",
"hooks": "hooks/hooks.json"
}"#,
);
let manifest = load_manifest(&plugin_root);
assert_eq!(
manifest.paths.skills,
vec![AbsolutePathBuf::try_from(plugin_root.join("skills")).expect("absolute skills")]
);
assert_eq!(
manifest.paths.hooks,
Some(PluginManifestHooks::Paths(vec![
AbsolutePathBuf::try_from(plugin_root.join("hooks/hooks.json"))
.expect("absolute hooks")
]))
);
}
#[test]
fn uri_manifest_uses_the_root_path_convention() {
let windows_root =
+8 -1
View File
@@ -21,6 +21,7 @@ const MARKETPLACE_MANIFEST_RELATIVE_PATHS: &[&str] = &[
".agents/plugins/marketplace.json",
".agents/plugins/api_marketplace.json",
".claude-plugin/marketplace.json",
".cursor-plugin/marketplace.json",
];
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -662,7 +663,13 @@ fn resolve_local_plugin_source_path(
}
// Non-root local sources must keep the explicit `./` prefix and remain normalized.
let Some(relative_path) = path.strip_prefix("./") else {
let relative_path = path.strip_prefix("./").or_else(|| {
marketplace_path
.as_path()
.ends_with(".cursor-plugin/marketplace.json")
.then_some(path)
});
let Some(relative_path) = relative_path else {
return Err(MarketplaceError::InvalidMarketplaceFile {
path: marketplace_path.to_path_buf(),
message: "local plugin source path must start with `./`".to_string(),
@@ -6,6 +6,8 @@ use tempfile::tempdir;
const ALTERNATE_MARKETPLACE_RELATIVE_PATH: &str = ".claude-plugin/marketplace.json";
const ALTERNATE_PLUGIN_MANIFEST_RELATIVE_PATH: &str = ".claude-plugin/plugin.json";
const CURSOR_MARKETPLACE_RELATIVE_PATH: &str = ".cursor-plugin/marketplace.json";
const CURSOR_PLUGIN_MANIFEST_RELATIVE_PATH: &str = ".cursor-plugin/plugin.json";
fn write_alternate_marketplace(repo_root: &Path, contents: &str) -> AbsolutePathBuf {
let marketplace_path = repo_root.join(ALTERNATE_MARKETPLACE_RELATIVE_PATH);
fs::create_dir_all(marketplace_path.parent().unwrap()).unwrap();
@@ -19,6 +21,19 @@ fn write_alternate_plugin_manifest(plugin_root: &Path, contents: &str) {
fs::write(manifest_path, contents).unwrap();
}
fn write_cursor_marketplace(repo_root: &Path, contents: &str) -> AbsolutePathBuf {
let marketplace_path = repo_root.join(CURSOR_MARKETPLACE_RELATIVE_PATH);
fs::create_dir_all(marketplace_path.parent().unwrap()).unwrap();
fs::write(&marketplace_path, contents).unwrap();
AbsolutePathBuf::try_from(marketplace_path).unwrap()
}
fn write_cursor_plugin_manifest(plugin_root: &Path, contents: &str) {
let manifest_path = plugin_root.join(CURSOR_PLUGIN_MANIFEST_RELATIVE_PATH);
fs::create_dir_all(manifest_path.parent().unwrap()).unwrap();
fs::write(manifest_path, contents).unwrap();
}
fn minimal_manifest_fallback(name: &str) -> MarketplacePluginManifestFallback {
MarketplacePluginManifestFallback {
contents: format!(
@@ -124,6 +139,37 @@ fn find_marketplace_plugin_supports_alternate_layout_and_string_local_source() {
);
}
#[test]
fn find_marketplace_plugin_supports_cursor_layout_and_bare_local_source() {
let tmp = tempdir().unwrap();
let repo_root = tmp.path().join("repo");
let plugin_root = repo_root.join("plugins/sample");
let marketplace_path = write_cursor_marketplace(
&repo_root,
r#"{
"name": "cursor-marketplace",
"plugins": [{"name": "sample", "source": "plugins/sample"}]
}"#,
);
write_cursor_plugin_manifest(&plugin_root, r#"{"name":"sample"}"#);
let resolved = find_marketplace_plugin(&marketplace_path, "sample").unwrap();
assert_eq!(
resolved.source,
MarketplacePluginSource::Local {
path: AbsolutePathBuf::try_from(plugin_root).unwrap(),
}
);
assert_eq!(
resolved
.manifest
.as_ref()
.map(|manifest| manifest.name.as_str()),
Some("sample")
);
}
#[test]
fn find_marketplace_plugin_supports_git_subdir_sources() {
let tmp = tempdir().unwrap();