| 1 | //! Marketplace parser tests. Every fixture is a real published schema: |
| 2 | //! the Kimi fixture is `MoonshotAI/kimi-code/plugins/marketplace.json` |
| 3 | //! verbatim; the Kimi custom-marketplace, Claude, and Codex fixtures are |
| 4 | //! the documented examples from each format's official docs, verbatim. |
| 5 | //! No synthetic formats, no invented fields. |
| 6 | |
| 7 | use serde_json::Value; |
| 8 | |
| 9 | use super::parsers::MarketplaceDocument; |
| 10 | use super::parsers::parse_catalog; |
| 11 | use super::types::{ |
| 12 | CatalogTier, MarketplaceCatalogId, MarketplaceFormat, MarketplaceInstallPlan, |
| 13 | MarketplaceSourceSpec, |
| 14 | }; |
| 15 | |
| 16 | /// MoonshotAI/kimi-code `plugins/marketplace.json`, verbatim. |
| 17 | const KIMI_OFFICIAL_MARKETPLACE: &str = r#"{ |
| 18 | "version": "1", |
| 19 | "plugins": [ |
| 20 | { |
| 21 | "id": "kimi-datasource", |
| 22 | "tier": "official", |
| 23 | "displayName": "Kimi Datasource", |
| 24 | "version": "3.3.0", |
| 25 | "description": "Official datasource workflows.", |
| 26 | "keywords": ["data", "mcp"], |
| 27 | "source": "./official/kimi-datasource" |
| 28 | }, |
| 29 | { |
| 30 | "id": "kimi-webbridge", |
| 31 | "tier": "official", |
| 32 | "displayName": "Kimi WebBridge", |
| 33 | "version": "1.11.3", |
| 34 | "description": "Control your real browser from Kimi Code.", |
| 35 | "keywords": ["browser", "automation", "webbridge"], |
| 36 | "source": "./official/kimi-webbridge" |
| 37 | }, |
| 38 | { |
| 39 | "id": "superpowers", |
| 40 | "tier": "curated", |
| 41 | "displayName": "Superpowers", |
| 42 | "description": "Planning, TDD, debugging, and delivery workflows for coding agents.", |
| 43 | "homepage": "https://github.com/obra/superpowers", |
| 44 | "keywords": ["skills", "planning", "tdd", "debugging", "code-review"], |
| 45 | "source": "https://github.com/obra/superpowers" |
| 46 | }, |
| 47 | { |
| 48 | "id": "vercel-plugin", |
| 49 | "tier": "curated", |
| 50 | "displayName": "Vercel Plugin", |
| 51 | "description": "Comprehensive Vercel ecosystem plugin — skills, agents, and conventions for the Vercel platform.", |
| 52 | "homepage": "https://vercel.com/docs/agent-resources/vercel-plugin", |
| 53 | "keywords": ["vercel", "deployment", "nextjs", "skills", "agents"], |
| 54 | "source": "https://github.com/vercel/vercel-plugin" |
| 55 | }, |
| 56 | { |
| 57 | "id": "modern-web-guidance", |
| 58 | "tier": "curated", |
| 59 | "displayName": "Modern Web Guidance", |
| 60 | "description": "Modern web platform expertise, best practices, and browser compatibility data for coding agents, from the Google Chrome team.", |
| 61 | "homepage": "https://github.com/GoogleChrome/modern-web-guidance", |
| 62 | "keywords": ["web", "css", "browser", "frontend", "skills"], |
| 63 | "source": "https://github.com/GoogleChrome/modern-web-guidance" |
| 64 | } |
| 65 | ] |
| 66 | }"#; |
| 67 | |
| 68 | /// Kimi docs "Custom marketplace JSON" example, verbatim. |
| 69 | const KIMI_DOCS_CUSTOM: &str = r#"{ |
| 70 | "version": "2", |
| 71 | "plugins": [ |
| 72 | { |
| 73 | "id": "my-plugin", |
| 74 | "displayName": "My Plugin", |
| 75 | "source": "./my-plugin" |
| 76 | } |
| 77 | ] |
| 78 | }"#; |
| 79 | |
| 80 | /// Claude plugin-marketplaces docs example, verbatim. |
| 81 | const CLAUDE_DOCS_MARKETPLACE: &str = r#"{ |
| 82 | "name": "company-tools", |
| 83 | "owner": { |
| 84 | "name": "DevTools Team", |
| 85 | "email": "devtools@example.com" |
| 86 | }, |
| 87 | "plugins": [ |
| 88 | { |
| 89 | "name": "code-formatter", |
| 90 | "source": "./plugins/formatter", |
| 91 | "description": "Automatic code formatting on save", |
| 92 | "version": "2.1.0", |
| 93 | "author": { |
| 94 | "name": "DevTools Team" |
| 95 | } |
| 96 | }, |
| 97 | { |
| 98 | "name": "deployment-tools", |
| 99 | "source": { |
| 100 | "source": "github", |
| 101 | "repo": "company/deploy-plugin" |
| 102 | }, |
| 103 | "description": "Deployment automation tools" |
| 104 | } |
| 105 | ] |
| 106 | }"#; |
| 107 | |
| 108 | /// Codex plugin packaging docs marketplace example, verbatim. |
| 109 | const CODEX_DOCS_MARKETPLACE: &str = r#"{ |
| 110 | "name": "local-repo", |
| 111 | "plugins": [ |
| 112 | { |
| 113 | "name": "my-plugin", |
| 114 | "source": { |
| 115 | "source": "local", |
| 116 | "path": "./plugins/my-plugin" |
| 117 | }, |
| 118 | "policy": { |
| 119 | "installation": "AVAILABLE", |
| 120 | "authentication": "ON_INSTALL" |
| 121 | }, |
| 122 | "category": "Productivity" |
| 123 | } |
| 124 | ] |
| 125 | }"#; |
| 126 | |
| 127 | fn parse(id: &str, format: MarketplaceFormat, body: &str) -> super::types::MarketplaceCatalog { |
| 128 | let root: Value = serde_json::from_str(body).expect("fixture parses as JSON"); |
| 129 | parse_catalog(MarketplaceDocument { |
| 130 | catalog_id: MarketplaceCatalogId::new(id), |
| 131 | format, |
| 132 | root, |
| 133 | base: None, |
| 134 | }) |
| 135 | } |
| 136 | |
| 137 | fn parse_auto(id: &str, body: &str) -> super::types::MarketplaceCatalog { |
| 138 | parse(id, MarketplaceFormat::Auto, body) |
| 139 | } |
| 140 | |
| 141 | #[test] |
| 142 | fn native_catalog_retains_search_terms_from_the_bundled_snapshot() { |
| 143 | let snapshot: Value = |
| 144 | serde_json::from_str(include_str!("../../assets/first-party-marketplace.json")).unwrap(); |
| 145 | let source = &snapshot["catalog"]; |
| 146 | let catalog = parse( |
| 147 | "codewhale", |
| 148 | MarketplaceFormat::Codewhale, |
| 149 | &source.to_string(), |
| 150 | ); |
| 151 | let entries = source["plugins"].as_array().unwrap(); |
| 152 | assert!(entries.iter().any(|entry| entry["keywords"].is_array())); |
| 153 | for entry in entries { |
| 154 | let candidate = catalog |
| 155 | .candidate_by_name(entry["name"].as_str().unwrap()) |
| 156 | .unwrap(); |
| 157 | for (field, actual) in [ |
| 158 | ("keywords", &candidate.keywords), |
| 159 | ("categories", &candidate.categories), |
| 160 | ] { |
| 161 | let expected: Vec<String> = entry |
| 162 | .get(field) |
| 163 | .map(|value| serde_json::from_value(value.clone()).unwrap()) |
| 164 | .unwrap_or_default(); |
| 165 | assert_eq!(actual, &expected, "{} {field}", candidate.name); |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | #[test] |
| 171 | fn native_catalog_keeps_identity_without_fetching_artwork_or_granting_trust() { |
| 172 | let snapshot: Value = |
| 173 | serde_json::from_str(include_str!("../../assets/first-party-marketplace.json")).unwrap(); |
| 174 | let icon = snapshot["catalog"]["plugins"] |
| 175 | .as_array() |
| 176 | .unwrap() |
| 177 | .iter() |
| 178 | .find(|entry| entry["name"] == "computer-use") |
| 179 | .unwrap()["icon"] |
| 180 | .as_str() |
| 181 | .unwrap(); |
| 182 | let mut entry = serde_json::json!({"name":"computer-use","source":"github:codewhale-hq/codewhale-cu-plugin","display_name":"Computer Use","author":"Codewhale","icon":icon,"platforms":["macos","windows","linux"]}); |
| 183 | let catalog = parse( |
| 184 | "identity", |
| 185 | MarketplaceFormat::Codewhale, |
| 186 | &serde_json::json!({"name":"identity","plugins":[entry.clone()]}).to_string(), |
| 187 | ); |
| 188 | let candidate = catalog.candidate_by_name("computer-use").unwrap(); |
| 189 | assert_eq!(candidate.display_name.as_deref(), Some("Computer Use")); |
| 190 | assert_eq!(candidate.author.as_deref(), Some("Codewhale")); |
| 191 | assert_eq!(candidate.icon.as_deref(), Some(icon)); |
| 192 | assert_eq!( |
| 193 | candidate.when.as_ref().unwrap().os.as_ref().unwrap().len(), |
| 194 | 3 |
| 195 | ); |
| 196 | assert_eq!(candidate.provenance.tier, CatalogTier::Community); |
| 197 | assert!(!candidate.has_errors()); |
| 198 | entry["icon"] = serde_json::json!("https://publisher.example/tracker.png"); |
| 199 | let rejected = parse( |
| 200 | "identity", |
| 201 | MarketplaceFormat::Codewhale, |
| 202 | &serde_json::json!({"name":"identity","plugins":[entry]}).to_string(), |
| 203 | ); |
| 204 | let candidate = rejected.candidate_by_name("computer-use").unwrap(); |
| 205 | assert!(candidate.icon.is_none()); |
| 206 | assert!(candidate.has_errors()); |
| 207 | } |
| 208 | |
| 209 | #[test] |
| 210 | fn kimi_official_marketplace_parses_all_five_real_entries() { |
| 211 | let catalog = parse_auto("kimi", KIMI_OFFICIAL_MARKETPLACE); |
| 212 | assert_eq!(catalog.format, MarketplaceFormat::Kimi); |
| 213 | assert_eq!(catalog.total_candidates(), 5); |
| 214 | assert_eq!(catalog.error_count(), 0, "real catalog must parse cleanly"); |
| 215 | |
| 216 | let datasource = catalog.candidate_by_name("kimi-datasource").unwrap(); |
| 217 | assert_eq!(datasource.provenance.tier, CatalogTier::Official); |
| 218 | assert!(datasource.install_plan.is_supported()); |
| 219 | assert_eq!( |
| 220 | datasource.source, |
| 221 | MarketplaceSourceSpec::LocalPath { |
| 222 | path: "./official/kimi-datasource".into() |
| 223 | } |
| 224 | ); |
| 225 | |
| 226 | let superpowers = catalog.candidate_by_name("superpowers").unwrap(); |
| 227 | assert_eq!(superpowers.provenance.tier, CatalogTier::Curated); |
| 228 | assert!(superpowers.install_plan.is_supported()); |
| 229 | assert!(matches!( |
| 230 | &superpowers.source, |
| 231 | MarketplaceSourceSpec::GitHub { owner, repo, .. } |
| 232 | if owner == "obra" && repo == "superpowers" |
| 233 | )); |
| 234 | } |
| 235 | |
| 236 | #[test] |
| 237 | fn kimi_docs_custom_marketplace_parses() { |
| 238 | let catalog = parse_auto("kimi-custom", KIMI_DOCS_CUSTOM); |
| 239 | assert_eq!(catalog.format, MarketplaceFormat::Kimi); |
| 240 | assert_eq!(catalog.version.as_deref(), Some("2")); |
| 241 | let plugin = catalog.candidate_by_name("my-plugin").unwrap(); |
| 242 | assert_eq!( |
| 243 | plugin.display_name.as_deref(), |
| 244 | Some("My Plugin"), |
| 245 | "camelCase displayName is the documented field" |
| 246 | ); |
| 247 | } |
| 248 | |
| 249 | #[test] |
| 250 | fn kimi_relative_sources_keep_resolution_for_install_time() { |
| 251 | let catalog = parse("kimi", MarketplaceFormat::Kimi, KIMI_OFFICIAL_MARKETPLACE); |
| 252 | let datasource = catalog.candidate_by_name("kimi-datasource").unwrap(); |
| 253 | match &datasource.install_plan { |
| 254 | MarketplaceInstallPlan::Supported { spec, .. } => { |
| 255 | assert_eq!(spec, "path:./official/kimi-datasource"); |
| 256 | } |
| 257 | other => panic!("relative path must be a supported local plan: {other:?}"), |
| 258 | } |
| 259 | assert_eq!(catalog.base, None, "parser never invents a base"); |
| 260 | } |
| 261 | |
| 262 | #[test] |
| 263 | fn kimi_zip_sources_are_visible_but_not_advertised_as_installable() { |
| 264 | let body = r#"{ |
| 265 | "version": "2", |
| 266 | "plugins": [ |
| 267 | {"id": "zipped", "source": "https://example.invalid/zipped.zip"}, |
| 268 | {"id": "tarred", "source": "https://example.invalid/tarred.tgz"} |
| 269 | ] |
| 270 | }"#; |
| 271 | let catalog = parse("kimi", MarketplaceFormat::Kimi, body); |
| 272 | let zipped = catalog.candidate_by_name("zipped").unwrap(); |
| 273 | assert!(matches!( |
| 274 | zipped.source, |
| 275 | MarketplaceSourceSpec::ArchiveUrl { .. } |
| 276 | )); |
| 277 | assert!(matches!( |
| 278 | &zipped.install_plan, |
| 279 | MarketplaceInstallPlan::Unsupported { reason, .. } |
| 280 | if reason == super::parsers::kimi::KIMI_ZIP_UNSUPPORTED_REASON |
| 281 | )); |
| 282 | |
| 283 | let tarred = catalog.candidate_by_name("tarred").unwrap(); |
| 284 | assert!(matches!( |
| 285 | &tarred.install_plan, |
| 286 | MarketplaceInstallPlan::Supported { source_kind, .. } |
| 287 | if source_kind == super::parsers::kimi::KIMI_GZIP_TARBALL_SOURCE_KIND |
| 288 | )); |
| 289 | } |
| 290 | |
| 291 | #[test] |
| 292 | fn claude_docs_marketplace_parses_both_source_forms() { |
| 293 | let catalog = parse_auto("claude", CLAUDE_DOCS_MARKETPLACE); |
| 294 | assert_eq!(catalog.format, MarketplaceFormat::Claude); |
| 295 | assert_eq!(catalog.total_candidates(), 2); |
| 296 | assert_eq!(catalog.error_count(), 0); |
| 297 | |
| 298 | let formatter = catalog.candidate_by_name("code-formatter").unwrap(); |
| 299 | assert!(formatter.install_plan.is_supported()); |
| 300 | assert!(matches!( |
| 301 | formatter.source, |
| 302 | MarketplaceSourceSpec::LocalPath { .. } |
| 303 | )); |
| 304 | assert_eq!(formatter.version.as_deref(), Some("2.1.0")); |
| 305 | assert_eq!(formatter.author.as_deref(), Some("DevTools Team")); |
| 306 | |
| 307 | let deploy = catalog.candidate_by_name("deployment-tools").unwrap(); |
| 308 | assert!(matches!( |
| 309 | &deploy.source, |
| 310 | MarketplaceSourceSpec::GitHub { owner, repo, .. } |
| 311 | if owner == "company" && repo == "deploy-plugin" |
| 312 | )); |
| 313 | match &deploy.install_plan { |
| 314 | MarketplaceInstallPlan::Supported { spec, .. } => { |
| 315 | assert_eq!(spec, "github:company/deploy-plugin"); |
| 316 | } |
| 317 | other => panic!("github source must map to a supported plan: {other:?}"), |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | #[test] |
| 322 | fn claude_source_object_matrix_matches_documented_forms() { |
| 323 | // One entry per documented `source` discriminator, from the docs |
| 324 | // source-form table. npm/command stay honestly unsupported. |
| 325 | let body = r#"{ |
| 326 | "name": "matrix", "owner": {"name": "t"}, |
| 327 | "plugins": [ |
| 328 | {"name": "gh", "source": {"source": "github", "repo": "a/b", "ref": "v1"}}, |
| 329 | {"name": "u", "source": {"source": "url", "url": "https://git.example.com/x.git"}}, |
| 330 | {"name": "gs", "source": {"source": "git-subdir", "url": "https://github.com/a/sub", "path": "p"}}, |
| 331 | {"name": "np", "source": {"source": "npm", "package": "pkg"}}, |
| 332 | {"name": "ar", "source": {"source": "archive", "url": "https://x.example.com/p.tgz", "sha256": "ABCDEF0123456789abcdef0123456789abcdef0123456789abcdef0123456789"}}, |
| 333 | {"name": "cm", "source": {"source": "command", "command": "curl x"}} |
| 334 | ] |
| 335 | }"#; |
| 336 | let catalog = parse("claude", MarketplaceFormat::Claude, body); |
| 337 | assert_eq!(catalog.total_candidates(), 6); |
| 338 | |
| 339 | let gh = catalog.candidate_by_name("gh").unwrap(); |
| 340 | assert!(gh.install_plan.is_supported()); |
| 341 | assert!(matches!(&gh.source, |
| 342 | MarketplaceSourceSpec::GitHub { git_ref: Some(r), .. } if r == "v1")); |
| 343 | assert!( |
| 344 | matches!(&gh.install_plan, MarketplaceInstallPlan::Supported { spec, .. } if spec == "git:github.com/a/b@v1") |
| 345 | ); |
| 346 | |
| 347 | let url = catalog.candidate_by_name("u").unwrap(); |
| 348 | assert!(!url.install_plan.is_supported()); |
| 349 | assert!(matches!(url.source, MarketplaceSourceSpec::GitUrl { .. })); |
| 350 | |
| 351 | let gs = catalog.candidate_by_name("gs").unwrap(); |
| 352 | assert!(!gs.install_plan.is_supported()); |
| 353 | assert!( |
| 354 | matches!(&gs.source, MarketplaceSourceSpec::GitUrl { url } if url == "https://github.com/a/sub") |
| 355 | ); |
| 356 | |
| 357 | let np = catalog.candidate_by_name("np").unwrap(); |
| 358 | assert!(!np.install_plan.is_supported()); |
| 359 | assert!(matches!(&np.source, MarketplaceSourceSpec::Npm { package } if package == "pkg")); |
| 360 | |
| 361 | let ar = catalog.candidate_by_name("ar").unwrap(); |
| 362 | assert!(ar.install_plan.is_supported()); |
| 363 | let pin = "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"; |
| 364 | assert!(matches!(&ar.source, |
| 365 | MarketplaceSourceSpec::ArchiveUrl { url, sha256: Some(s) } |
| 366 | if url == "https://x.example.com/p.tgz" && s == pin)); |
| 367 | assert!(matches!(&ar.install_plan, |
| 368 | MarketplaceInstallPlan::Supported { spec, .. } |
| 369 | if *spec == format!("https://x.example.com/p.tgz#sha256={pin}"))); |
| 370 | |
| 371 | let cm = catalog.candidate_by_name("cm").unwrap(); |
| 372 | assert!(!cm.install_plan.is_supported()); |
| 373 | assert!(matches!(cm.source, MarketplaceSourceSpec::Refused { .. })); |
| 374 | } |
| 375 | |
| 376 | #[test] |
| 377 | fn claude_component_declarations_drive_compatibility() { |
| 378 | let body = r#"{ |
| 379 | "name": "comp", "owner": {"name": "t"}, |
| 380 | "plugins": [ |
| 381 | {"name": "skills-only", "source": "./a", "skills": ["s1", "s2"]}, |
| 382 | {"name": "mixed", "source": "./b", "skills": ["s1"], "commands": ["c1"], "hooks": ["h1"]}, |
| 383 | {"name": "commands-only", "source": "./c", "commands": ["c1"]}, |
| 384 | {"name": "nothing-declared", "source": "./d"}, |
| 385 | {"name": "mcp-only", "source": "./e", "mcpServers": {"docs": {"command": "x"}}} |
| 386 | ] |
| 387 | }"#; |
| 388 | let catalog = parse("claude", MarketplaceFormat::Claude, body); |
| 389 | use crate::manifest::PluginCompatibility as C; |
| 390 | assert_eq!( |
| 391 | catalog |
| 392 | .candidate_by_name("skills-only") |
| 393 | .unwrap() |
| 394 | .compatibility, |
| 395 | Some(C::Full) |
| 396 | ); |
| 397 | assert_eq!( |
| 398 | catalog.candidate_by_name("mixed").unwrap().compatibility, |
| 399 | Some(C::Partial) |
| 400 | ); |
| 401 | assert_eq!( |
| 402 | catalog |
| 403 | .candidate_by_name("commands-only") |
| 404 | .unwrap() |
| 405 | .compatibility, |
| 406 | Some(C::Unsupported) |
| 407 | ); |
| 408 | assert_eq!( |
| 409 | catalog |
| 410 | .candidate_by_name("nothing-declared") |
| 411 | .unwrap() |
| 412 | .compatibility, |
| 413 | None, |
| 414 | "no declaration means decided at install review, not guessed" |
| 415 | ); |
| 416 | assert_eq!( |
| 417 | catalog.candidate_by_name("mcp-only").unwrap().compatibility, |
| 418 | Some(C::Full), |
| 419 | "declared MCP without transport is treated as supported-capable" |
| 420 | ); |
| 421 | } |
| 422 | |
| 423 | #[test] |
| 424 | fn codex_docs_marketplace_parses_with_policy_as_display_only() { |
| 425 | let catalog = parse_auto("codex", CODEX_DOCS_MARKETPLACE); |
| 426 | assert_eq!(catalog.format, MarketplaceFormat::Codex); |
| 427 | assert_eq!(catalog.total_candidates(), 1); |
| 428 | |
| 429 | let plugin = catalog.candidate_by_name("my-plugin").unwrap(); |
| 430 | assert!(plugin.install_plan.is_supported()); |
| 431 | assert!(matches!( |
| 432 | plugin.source, |
| 433 | MarketplaceSourceSpec::LocalPath { .. } |
| 434 | )); |
| 435 | assert_eq!(plugin.categories, vec!["Productivity".to_string()]); |
| 436 | assert!( |
| 437 | !plugin |
| 438 | .diagnostics |
| 439 | .iter() |
| 440 | .any(|d| d.code == "NO_AUTO_INSTALL"), |
| 441 | "AVAILABLE policy needs no warning" |
| 442 | ); |
| 443 | } |
| 444 | |
| 445 | #[test] |
| 446 | fn codex_installed_by_default_never_auto_installs_and_says_so() { |
| 447 | let body = r#"{ |
| 448 | "name": "n", |
| 449 | "plugins": [ |
| 450 | {"name": "p", "source": {"source": "local", "path": "./p"}, |
| 451 | "policy": {"installation": "INSTALLED_BY_DEFAULT"}} |
| 452 | ] |
| 453 | }"#; |
| 454 | let catalog = parse("codex", MarketplaceFormat::Codex, body); |
| 455 | let plugin = catalog.candidate_by_name("p").unwrap(); |
| 456 | assert!( |
| 457 | plugin |
| 458 | .diagnostics |
| 459 | .iter() |
| 460 | .any(|d| d.code == "NO_AUTO_INSTALL"), |
| 461 | "auto-install policy must be visibly ignored on the entry itself" |
| 462 | ); |
| 463 | } |
| 464 | |
| 465 | #[test] |
| 466 | fn codex_not_available_downgrades_install_plan() { |
| 467 | let body = r#"{ |
| 468 | "name": "n", |
| 469 | "plugins": [ |
| 470 | {"name": "p", "source": {"source": "local", "path": "./p"}, |
| 471 | "policy": {"installation": "NOT_AVAILABLE"}} |
| 472 | ] |
| 473 | }"#; |
| 474 | let catalog = parse("codex", MarketplaceFormat::Codex, body); |
| 475 | let plugin = catalog.candidate_by_name("p").unwrap(); |
| 476 | assert!(!plugin.install_plan.is_supported()); |
| 477 | } |
| 478 | |
| 479 | #[test] |
| 480 | fn codewhale_native_catalog_maps_install_specs() { |
| 481 | let body = r#"{ |
| 482 | "name": "team", "description": "Team plugins", "version": "1", |
| 483 | "plugins": [ |
| 484 | {"name": "fmt", "source": "github:owner/repo", "version": "2.1.0"}, |
| 485 | {"name": "local", "source": "path:./bundled/fmt"}, |
| 486 | {"name": "bad", "source": "github:"} |
| 487 | ] |
| 488 | }"#; |
| 489 | let catalog = parse_auto("native", body); |
| 490 | assert_eq!(catalog.format, MarketplaceFormat::Codewhale); |
| 491 | assert_eq!(catalog.total_candidates(), 3); |
| 492 | |
| 493 | assert!( |
| 494 | catalog |
| 495 | .candidate_by_name("fmt") |
| 496 | .unwrap() |
| 497 | .install_plan |
| 498 | .is_supported() |
| 499 | ); |
| 500 | assert!( |
| 501 | catalog |
| 502 | .candidate_by_name("local") |
| 503 | .unwrap() |
| 504 | .install_plan |
| 505 | .is_supported() |
| 506 | ); |
| 507 | let bad = catalog.candidate_by_name("bad").unwrap(); |
| 508 | assert!( |
| 509 | !bad.install_plan.is_supported(), |
| 510 | "invalid spec stays visible and unsupported" |
| 511 | ); |
| 512 | } |
| 513 | |
| 514 | #[test] |
| 515 | fn malformed_entry_degrades_alone() { |
| 516 | let body = r#"{ |
| 517 | "version": "1", |
| 518 | "plugins": [ |
| 519 | {"id": "good", "source": "./good"}, |
| 520 | "not-an-object", |
| 521 | {"displayName": "missing id and source"}, |
| 522 | {"id": "also-good", "source": "https://github.com/a/b"} |
| 523 | ] |
| 524 | }"#; |
| 525 | let catalog = parse("kimi", MarketplaceFormat::Kimi, body); |
| 526 | assert_eq!(catalog.total_candidates(), 2, "survivors stay listed"); |
| 527 | assert!(catalog.candidate_by_name("good").is_some()); |
| 528 | assert!(catalog.candidate_by_name("also-good").is_some()); |
| 529 | assert!(catalog.error_count() >= 2); |
| 530 | } |
| 531 | |
| 532 | #[test] |
| 533 | fn missing_plugins_array_is_a_catalog_error() { |
| 534 | for (format, body) in [ |
| 535 | (MarketplaceFormat::Kimi, r#"{"version": "1"}"#), |
| 536 | ( |
| 537 | MarketplaceFormat::Claude, |
| 538 | r#"{"name": "x", "owner": {"name": "o"}}"#, |
| 539 | ), |
| 540 | (MarketplaceFormat::Codex, r#"{"name": "x"}"#), |
| 541 | (MarketplaceFormat::Codewhale, r#"{"name": "x"}"#), |
| 542 | ] { |
| 543 | let catalog = parse("t", format, body); |
| 544 | assert_eq!(catalog.total_candidates(), 0); |
| 545 | assert!(catalog.error_count() >= 1, "{format} needs a plugins array"); |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | #[test] |
| 550 | fn provenance_tiers_never_grant_trust() { |
| 551 | let catalog = parse("kimi", MarketplaceFormat::Kimi, KIMI_OFFICIAL_MARKETPLACE); |
| 552 | for candidate in &catalog.candidates { |
| 553 | assert!(!candidate.provenance.grants_trust()); |
| 554 | assert!( |
| 555 | candidate.compatibility.is_none() || !candidate.has_errors(), |
| 556 | "official/curated labels are display-only" |
| 557 | ); |
| 558 | } |
| 559 | let official = catalog.candidate_by_name("kimi-datasource").unwrap(); |
| 560 | assert_eq!(official.provenance.tier, CatalogTier::Official); |
| 561 | } |
| 562 | |
| 563 | #[test] |
| 564 | fn unknown_fields_warn_instead_of_being_reinterpreted() { |
| 565 | let body = r#"{ |
| 566 | "version": "1", |
| 567 | "plugins": [ |
| 568 | {"id": "p", "source": "./p", "download_url": "https://x", "entries": []} |
| 569 | ] |
| 570 | }"#; |
| 571 | let catalog = parse("kimi", MarketplaceFormat::Kimi, body); |
| 572 | assert_eq!(catalog.total_candidates(), 1); |
| 573 | let plugin = catalog.candidate_by_name("p").unwrap(); |
| 574 | assert!( |
| 575 | plugin |
| 576 | .diagnostics |
| 577 | .iter() |
| 578 | .any(|d| d.code == "UNKNOWN_FIELD" && d.message.contains("download_url")), |
| 579 | "invented fields must be visibly ignored, not parsed" |
| 580 | ); |
| 581 | } |
| 582 | |
| 583 | #[test] |
| 584 | fn archive_url_catalog_detection_preserves_native_and_kimi_identity() { |
| 585 | for url in [ |
| 586 | "https://example.invalid/plugins.tar.gz#path=plugins/tools", |
| 587 | "http://127.0.0.1:9000/plugins.tar.gz#path=plugins/tools", |
| 588 | ] { |
| 589 | let native = serde_json::json!({"plugins": [{"name": "tools", "source": url}]}); |
| 590 | let catalog = parse_auto("native", &native.to_string()); |
| 591 | assert_eq!(catalog.format, MarketplaceFormat::Codewhale); |
| 592 | assert_eq!(catalog.error_count(), 0); |
| 593 | assert!(matches!( |
| 594 | &catalog.candidate_by_name("tools").unwrap().install_plan, |
| 595 | MarketplaceInstallPlan::Supported { spec, .. } if spec == url |
| 596 | )); |
| 597 | |
| 598 | let kimi = serde_json::json!({"plugins": [{"id": "tools", "source": url}]}); |
| 599 | assert_eq!( |
| 600 | parse_auto("kimi", &kimi.to_string()).format, |
| 601 | MarketplaceFormat::Kimi |
| 602 | ); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | #[test] |
| 607 | fn auto_detection_reports_ambiguity_instead_of_guessing() { |
| 608 | let body = r#"{"plugins": [{"name": "p", "source": "./p"}]}"#; |
| 609 | let catalog = parse_auto("t", body); |
| 610 | assert_eq!(catalog.total_candidates(), 0); |
| 611 | assert!( |
| 612 | catalog |
| 613 | .diagnostics |
| 614 | .iter() |
| 615 | .any(|d| d.code == "AMBIGUOUS_FORMAT") |
| 616 | ); |
| 617 | } |
| 618 | |
| 619 | #[test] |
| 620 | fn non_object_catalog_fails_closed() { |
| 621 | let catalog = parse_auto("t", "[1, 2, 3]"); |
| 622 | assert_eq!(catalog.total_candidates(), 0); |
| 623 | assert!(catalog.error_count() >= 1); |
| 624 | } |
| 625 | |
| 626 | #[test] |
| 627 | fn claude_relative_install_source_is_rooted_outside_catalog_metadata() { |
| 628 | use super::document::{ |
| 629 | CatalogInstallResolution, load_catalog_document, resolve_candidate_install, |
| 630 | }; |
| 631 | let tmp = tempfile::tempdir().unwrap(); |
| 632 | let metadata = tmp.path().join(".claude-plugin"); |
| 633 | std::fs::create_dir_all(&metadata).unwrap(); |
| 634 | let path = metadata.join("marketplace.json"); |
| 635 | std::fs::write(&path, r#"{"name":"official","owner":{"name":"Example"},"plugins":[{"name":"linear","source":"./external_plugins/linear"}]}"#).unwrap(); |
| 636 | let loaded = load_catalog_document("official", tmp.path(), path.to_str().unwrap()).unwrap(); |
| 637 | let candidate = loaded.entry.catalog.candidate_by_name("linear").unwrap(); |
| 638 | let registry = crate::PluginRegistry::empty(tmp.path()); |
| 639 | let CatalogInstallResolution::Supported { spec, .. } = |
| 640 | resolve_candidate_install(&loaded.entry, candidate, ®istry) |
| 641 | else { |
| 642 | panic!("expected path source") |
| 643 | }; |
| 644 | assert_eq!( |
| 645 | std::path::Path::new(spec.strip_prefix("path:").unwrap()), |
| 646 | tmp.path().join("external_plugins/linear") |
| 647 | ); |
| 648 | } |
| 649 | |
| 650 | #[test] |
| 651 | fn catalog_names_are_validated_and_duplicates_fail_closed() { |
| 652 | let body = r#"{ |
| 653 | "name": "team", |
| 654 | "plugins": [ |
| 655 | {"name": "fmt", "source": "github:owner/fmt"}, |
| 656 | {"name": "fmt", "source": "github:someone-else/fmt"}, |
| 657 | {"name": "bad\u001b[31mname", "source": "github:owner/x"}, |
| 658 | {"name": "ok", "source": "github:owner/ok"} |
| 659 | ] |
| 660 | }"#; |
| 661 | let catalog = parse_auto("native", body); |
| 662 | assert_eq!(catalog.format, MarketplaceFormat::Codewhale); |
| 663 | assert_eq!( |
| 664 | catalog.total_candidates(), |
| 665 | 3, |
| 666 | "a control-bearing name never becomes a candidate" |
| 667 | ); |
| 668 | assert!(catalog.diagnostics.iter().any(|d| d.code == "INVALID_NAME")); |
| 669 | let duplicates: Vec<_> = catalog |
| 670 | .candidates |
| 671 | .iter() |
| 672 | .filter(|candidate| candidate.name == "fmt") |
| 673 | .collect(); |
| 674 | assert_eq!(duplicates.len(), 2); |
| 675 | for candidate in duplicates { |
| 676 | assert!( |
| 677 | candidate |
| 678 | .diagnostics |
| 679 | .iter() |
| 680 | .any(|d| d.code == "DUPLICATE_NAME"), |
| 681 | "an ambiguous identity must not be installable" |
| 682 | ); |
| 683 | assert!(candidate.has_errors()); |
| 684 | } |
| 685 | assert!(!catalog.candidate_by_name("ok").unwrap().has_errors()); |
| 686 | } |
| 687 | |
| 688 | #[test] |
| 689 | fn catalog_archive_sources_must_be_remote() { |
| 690 | // F01-03: a non-local source's spec is re-parsed by the installer, which |
| 691 | // reads any unprefixed value as a local directory. An archive `url` that |
| 692 | // is really a path must not reach it as one. |
| 693 | use super::document::{ |
| 694 | CatalogInstallResolution, load_catalog_document, resolve_candidate_install, |
| 695 | }; |
| 696 | let tmp = tempfile::tempdir().unwrap(); |
| 697 | let path = tmp.path().join("marketplace.json"); |
| 698 | std::fs::write( |
| 699 | &path, |
| 700 | r#"{"name":"n","owner":{"name":"t"},"plugins":[ |
| 701 | {"name":"absolute","source":{"source":"archive","url":"/etc"}}, |
| 702 | {"name":"parent","source":{"source":"archive","url":"../../outside"}}, |
| 703 | {"name":"prefixed","source":{"source":"archive","url":"path:/etc"}}, |
| 704 | {"name":"remote","source":{"source":"archive","url":"https://x.example.com/p.tgz"}} |
| 705 | ]}"#, |
| 706 | ) |
| 707 | .unwrap(); |
| 708 | let loaded = load_catalog_document("n", tmp.path(), path.to_str().unwrap()).unwrap(); |
| 709 | assert_eq!(loaded.entry.catalog.format, MarketplaceFormat::Claude); |
| 710 | let registry = crate::PluginRegistry::empty(tmp.path()); |
| 711 | for name in ["absolute", "parent", "prefixed"] { |
| 712 | let candidate = loaded.entry.catalog.candidate_by_name(name).unwrap(); |
| 713 | match resolve_candidate_install(&loaded.entry, candidate, ®istry) { |
| 714 | CatalogInstallResolution::Unsupported { reason } => { |
| 715 | assert!(reason.contains("is not a remote"), "{reason}"); |
| 716 | } |
| 717 | _ => panic!("archive `{name}` must not resolve to a local install"), |
| 718 | } |
| 719 | } |
| 720 | let remote = loaded.entry.catalog.candidate_by_name("remote").unwrap(); |
| 721 | let CatalogInstallResolution::Supported { spec, .. } = |
| 722 | resolve_candidate_install(&loaded.entry, remote, ®istry) |
| 723 | else { |
| 724 | panic!("a remote archive stays installable") |
| 725 | }; |
| 726 | assert_eq!(spec, "https://x.example.com/p.tgz"); |
| 727 | } |
| 728 | |
| 729 | #[test] |
| 730 | fn catalog_local_sources_cannot_leave_the_catalog_directory() { |
| 731 | use super::document::{ |
| 732 | CatalogInstallResolution, load_catalog_document, resolve_candidate_install, |
| 733 | }; |
| 734 | let tmp = tempfile::tempdir().unwrap(); |
| 735 | let path = tmp.path().join("marketplace.json"); |
| 736 | std::fs::write( |
| 737 | &path, |
| 738 | r#"{"name":"n","plugins":[ |
| 739 | {"name":"absolute","source":{"source":"local","path":"/etc"}}, |
| 740 | {"name":"parent","source":{"source":"local","path":"./plugins/../../outside"}}, |
| 741 | {"name":"inside","source":{"source":"local","path":"./plugins/inside"}} |
| 742 | ]}"#, |
| 743 | ) |
| 744 | .unwrap(); |
| 745 | let loaded = load_catalog_document("n", tmp.path(), path.to_str().unwrap()).unwrap(); |
| 746 | assert_eq!(loaded.entry.catalog.format, MarketplaceFormat::Codex); |
| 747 | let registry = crate::PluginRegistry::empty(tmp.path()); |
| 748 | for name in ["absolute", "parent"] { |
| 749 | let candidate = loaded.entry.catalog.candidate_by_name(name).unwrap(); |
| 750 | match resolve_candidate_install(&loaded.entry, candidate, ®istry) { |
| 751 | CatalogInstallResolution::Unsupported { reason } => { |
| 752 | assert!(reason.contains("leaves the catalog directory"), "{reason}"); |
| 753 | } |
| 754 | _ => panic!("`{name}` must not resolve outside the catalog"), |
| 755 | } |
| 756 | } |
| 757 | let inside = loaded.entry.catalog.candidate_by_name("inside").unwrap(); |
| 758 | let CatalogInstallResolution::Supported { spec, .. } = |
| 759 | resolve_candidate_install(&loaded.entry, inside, ®istry) |
| 760 | else { |
| 761 | panic!("a path inside the catalog stays installable") |
| 762 | }; |
| 763 | assert_eq!( |
| 764 | std::path::Path::new(spec.strip_prefix("path:").unwrap()), |
| 765 | tmp.path().join("./plugins/inside") |
| 766 | ); |
| 767 | } |
| 768 | |
| 769 | /// DSH plugin market index, format 1 (`reference/dsh` |
| 770 | /// `packages/util/plugin-market-index`): numeric `format`, localized display |
| 771 | /// text, and one installable record per version. |
| 772 | const DSH_MARKET_INDEX: &str = r#"{ |
| 773 | "format": 1, |
| 774 | "title": {"en": "Team market"}, |
| 775 | "description": {"en": "Reviewed bundles"}, |
| 776 | "metadata": {"categories": {"workflow": {"title": {"en": "Workflow"}}}}, |
| 777 | "plugins": [ |
| 778 | { |
| 779 | "name": "@acme/review", |
| 780 | "title": {"en": "Code review"}, |
| 781 | "description": {"en": "Review a diff before it lands."}, |
| 782 | "icon": "./icons/review.png", |
| 783 | "author": "Acme", |
| 784 | "homepage": "https://example.com/review", |
| 785 | "repository": {"url": "https://github.com/acme/review"}, |
| 786 | "metadata": {"category": "workflow", "keywords": ["review", "diff"]}, |
| 787 | "versions": [ |
| 788 | {"version": "1.9.0", "publishTimestamp": 1760000000, |
| 789 | "source": {"type": "npm"}, "engines": {"dsh": ">=0.2.0 <0.3.0"}}, |
| 790 | {"version": "1.10.0", "publishTimestamp": 1761000000, |
| 791 | "source": {"type": "npm"}, "engines": {"dsh": ">=0.2.0 <0.3.0"}} |
| 792 | ] |
| 793 | }, |
| 794 | { |
| 795 | "name": "acme-badge", |
| 796 | "title": "Badge", |
| 797 | "versions": [ |
| 798 | {"version": "2.0.0", "publishTimestamp": 1762000000, |
| 799 | "source": {"type": "git", "url": "https://github.com/acme/badge", |
| 800 | "commit": "0123456789abcdef0123456789abcdef01234567"}, |
| 801 | "engines": {"dsh": "0.2.1-rc.5"}} |
| 802 | ] |
| 803 | } |
| 804 | ] |
| 805 | }"#; |
| 806 | |
| 807 | fn parse_dsh(id: &str, body: &str, base: Option<&str>) -> super::types::MarketplaceCatalog { |
| 808 | let root: Value = serde_json::from_str(body).expect("fixture parses as JSON"); |
| 809 | parse_catalog(MarketplaceDocument { |
| 810 | catalog_id: MarketplaceCatalogId::new(id), |
| 811 | format: MarketplaceFormat::Auto, |
| 812 | root, |
| 813 | base: base.map(str::to_string), |
| 814 | }) |
| 815 | } |
| 816 | |
| 817 | #[test] |
| 818 | fn dsh_market_index_detects_and_keeps_the_highest_version() { |
| 819 | let catalog = parse_dsh( |
| 820 | "dsh", |
| 821 | DSH_MARKET_INDEX, |
| 822 | Some("https://example.com/market/index.json"), |
| 823 | ); |
| 824 | assert_eq!(catalog.format, MarketplaceFormat::Dsh); |
| 825 | assert_eq!(catalog.total_candidates(), 2); |
| 826 | assert_eq!(catalog.display_name.as_deref(), Some("Team market")); |
| 827 | |
| 828 | let review = catalog.candidate_by_name("@acme/review").unwrap(); |
| 829 | assert_eq!( |
| 830 | review.version.as_deref(), |
| 831 | Some("1.10.0"), |
| 832 | "versions sort by SemVer precedence" |
| 833 | ); |
| 834 | assert_eq!(review.display_name.as_deref(), Some("Code review")); |
| 835 | assert_eq!(review.author.as_deref(), Some("Acme")); |
| 836 | assert_eq!( |
| 837 | review.icon.as_deref(), |
| 838 | Some("https://example.com/market/icons/review.png"), |
| 839 | "a relative icon resolves against the index URL" |
| 840 | ); |
| 841 | assert_eq!( |
| 842 | review.keywords, |
| 843 | vec!["review".to_string(), "diff".to_string()] |
| 844 | ); |
| 845 | assert_eq!(review.categories, vec!["workflow".to_string()]); |
| 846 | assert!(matches!( |
| 847 | review.source, |
| 848 | MarketplaceSourceSpec::Npm { ref package } if package == "@acme/review" |
| 849 | )); |
| 850 | assert_eq!( |
| 851 | review.install_plan, |
| 852 | MarketplaceInstallPlan::Supported { |
| 853 | spec: "npm:@acme/review@1.10.0".to_string(), |
| 854 | source_kind: "npm registry tarball".to_string(), |
| 855 | }, |
| 856 | "an npm source plans the highest version's registry tarball" |
| 857 | ); |
| 858 | |
| 859 | let badge = catalog.candidate_by_name("acme-badge").unwrap(); |
| 860 | assert_eq!(badge.display_name.as_deref(), Some("Badge")); |
| 861 | assert_eq!(badge.icon, None, "no icon declared, none invented"); |
| 862 | match &badge.install_plan { |
| 863 | MarketplaceInstallPlan::Supported { spec, .. } => { |
| 864 | assert_eq!( |
| 865 | spec, |
| 866 | "git:github.com/acme/badge@0123456789abcdef0123456789abcdef01234567" |
| 867 | ); |
| 868 | } |
| 869 | other => panic!("a pinned GitHub source is installable, got {other:?}"), |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | #[test] |
| 874 | fn dsh_index_refuses_an_incompatible_dsh_range_before_download() { |
| 875 | let body = r#"{ |
| 876 | "format": 1, |
| 877 | "title": "t", |
| 878 | "plugins": [{ |
| 879 | "name": "future-bundle", |
| 880 | "versions": [{"version": "3.0.0", "publishTimestamp": 1, |
| 881 | "source": {"type": "npm"}, "engines": {"dsh": ">=0.3.0"}}] |
| 882 | }] |
| 883 | }"#; |
| 884 | let catalog = parse_dsh("dsh", body, None); |
| 885 | let plugin = catalog.candidate_by_name("future-bundle").unwrap(); |
| 886 | match &plugin.install_plan { |
| 887 | MarketplaceInstallPlan::Unsupported { reason, .. } => { |
| 888 | assert!(reason.contains("incompatible-version"), "{reason}"); |
| 889 | assert!(reason.contains(">=0.3.0"), "{reason}"); |
| 890 | } |
| 891 | other => panic!("an incompatible engine range must refuse, got {other:?}"), |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | #[test] |
| 896 | fn dsh_index_git_subdirectory_and_non_github_hosts_stay_unsupported() { |
| 897 | let body = r#"{ |
| 898 | "format": 1, |
| 899 | "title": "t", |
| 900 | "plugins": [ |
| 901 | {"name": "sub", "versions": [{"version": "1.0.0", "publishTimestamp": 1, |
| 902 | "source": {"type": "git", "url": "https://github.com/acme/mono", |
| 903 | "commit": "0123456789abcdef0123456789abcdef01234567", |
| 904 | "path": "packages/sub"}}]}, |
| 905 | {"name": "elsewhere", "versions": [{"version": "1.0.0", "publishTimestamp": 1, |
| 906 | "source": {"type": "git", "url": "https://gitlab.com/acme/plugin", |
| 907 | "commit": "0123456789abcdef0123456789abcdef01234567"}}]} |
| 908 | ] |
| 909 | }"#; |
| 910 | let catalog = parse_dsh("dsh", body, None); |
| 911 | let sub = catalog.candidate_by_name("sub").unwrap(); |
| 912 | assert!(matches!( |
| 913 | sub.install_plan, |
| 914 | MarketplaceInstallPlan::Unsupported { ref reason, .. } |
| 915 | if reason.contains("subdirectory") |
| 916 | )); |
| 917 | let elsewhere = catalog.candidate_by_name("elsewhere").unwrap(); |
| 918 | assert!(matches!( |
| 919 | elsewhere.source, |
| 920 | MarketplaceSourceSpec::GitUrl { .. } |
| 921 | )); |
| 922 | assert!(!elsewhere.install_plan.is_supported()); |
| 923 | } |
| 924 | |
| 925 | #[test] |
| 926 | fn dsh_index_degrades_one_malformed_entry_and_requires_format_one() { |
| 927 | let body = r#"{ |
| 928 | "format": 1, |
| 929 | "title": "t", |
| 930 | "plugins": [ |
| 931 | {"title": "no name", "versions": []}, |
| 932 | {"name": "ok", "versions": [{"version": "1.0.0", "publishTimestamp": 1, |
| 933 | "source": {"type": "npm"}}]} |
| 934 | ] |
| 935 | }"#; |
| 936 | let catalog = parse_dsh("dsh", body, None); |
| 937 | assert_eq!( |
| 938 | catalog.total_candidates(), |
| 939 | 1, |
| 940 | "the malformed entry alone is dropped" |
| 941 | ); |
| 942 | assert!(catalog.candidate_by_name("ok").is_some()); |
| 943 | assert!(catalog.diagnostics.iter().any(|d| d.code == "MISSING_NAME")); |
| 944 | |
| 945 | let not_format_one = parse_dsh("dsh", r#"{"format": 2, "plugins": []}"#, None); |
| 946 | assert_eq!(not_format_one.total_candidates(), 0); |
| 947 | assert!( |
| 948 | not_format_one |
| 949 | .diagnostics |
| 950 | .iter() |
| 951 | .any(|d| d.code == "UNDECLARED_FORMAT") |
| 952 | ); |
| 953 | } |
| 954 | |
| 955 | #[test] |
| 956 | fn dsh_index_unknown_fields_and_undeclared_category_are_reported_not_guessed() { |
| 957 | let body = r#"{ |
| 958 | "format": 1, |
| 959 | "title": "t", |
| 960 | "plugins": [{"name": "x", "unexpected": true, |
| 961 | "metadata": {"category": "undeclared", "keywords": ["k"]}, |
| 962 | "versions": [{"version": "1.0.0", "publishTimestamp": 1, |
| 963 | "source": {"type": "npm"}}]}] |
| 964 | }"#; |
| 965 | let catalog = parse_dsh("dsh", body, None); |
| 966 | let plugin = catalog.candidate_by_name("x").unwrap(); |
| 967 | assert!(plugin.diagnostics.iter().any(|d| d.code == "UNKNOWN_FIELD")); |
| 968 | assert!( |
| 969 | plugin |
| 970 | .diagnostics |
| 971 | .iter() |
| 972 | .any(|d| d.code == "UNDECLARED_CATEGORY") |
| 973 | ); |
| 974 | assert!(plugin.categories.is_empty()); |
| 975 | assert_eq!(plugin.keywords, vec!["k".to_string()]); |
| 976 | } |
| 977 | |
| 978 | #[test] |
| 979 | fn dsh_index_npm_sources_plan_an_exact_registry_tarball_or_say_why_not() { |
| 980 | use super::document::{CatalogInstallResolution, resolve_candidate_install}; |
| 981 | use super::store::StoredMarketplaceCatalog; |
| 982 | use crate::install::PluginInstallSource; |
| 983 | use codewhale_skill_install::install::InstallSource; |
| 984 | |
| 985 | let body = r#"{ |
| 986 | "format": 1, |
| 987 | "title": "t", |
| 988 | "plugins": [ |
| 989 | {"name": "@acme/review", "versions": [{"version": "1.10.0", "publishTimestamp": 1, |
| 990 | "source": {"type": "npm", "registry": "https://registry.npmjs.org/"}}]}, |
| 991 | {"name": "@acme/mirrored", "versions": [{"version": "2.0.0-rc.1", "publishTimestamp": 1, |
| 992 | "source": {"type": "npm", "registry": "https://registry.example.com/npm/"}}]}, |
| 993 | {"name": "plain-http", "versions": [{"version": "1.0.0", "publishTimestamp": 1, |
| 994 | "source": {"type": "npm", "registry": "http://registry.example.com"}}]}, |
| 995 | {"name": "with-credentials", "versions": [{"version": "1.0.0", "publishTimestamp": 1, |
| 996 | "source": {"type": "npm", "registry": "https://user:s3cret@registry.example.com"}}]}, |
| 997 | {"name": "tilde~name", "versions": [{"version": "1.0.0", "publishTimestamp": 1, |
| 998 | "source": {"type": "npm"}}]}, |
| 999 | {"name": "typed-registry", "versions": [ |
| 1000 | {"version": "2.0.0", "publishTimestamp": 2, "source": {"type": "npm", "registry": 7}}, |
| 1001 | {"version": "1.0.0", "publishTimestamp": 1, "source": {"type": "npm"}}]} |
| 1002 | ] |
| 1003 | }"#; |
| 1004 | let catalog = parse_dsh("dsh", body, None); |
| 1005 | assert_eq!(catalog.total_candidates(), 6); |
| 1006 | let plan = |name: &str| { |
| 1007 | catalog |
| 1008 | .candidate_by_name(name) |
| 1009 | .unwrap() |
| 1010 | .install_plan |
| 1011 | .clone() |
| 1012 | }; |
| 1013 | let supported = |name: &str| match plan(name) { |
| 1014 | MarketplaceInstallPlan::Supported { spec, source_kind } => { |
| 1015 | assert_eq!(source_kind, "npm registry tarball", "{name}"); |
| 1016 | spec |
| 1017 | } |
| 1018 | other => panic!("`{name}` must be installable, got {other:?}"), |
| 1019 | }; |
| 1020 | let refused = |name: &str| match plan(name) { |
| 1021 | MarketplaceInstallPlan::Unsupported { reason, .. } => reason, |
| 1022 | other => panic!("`{name}` must not be installable, got {other:?}"), |
| 1023 | }; |
| 1024 | |
| 1025 | let review = supported("@acme/review"); |
| 1026 | assert_eq!( |
| 1027 | review, "npm:@acme/review@1.10.0", |
| 1028 | "the default registry, named or not, is the installer's own npm spec" |
| 1029 | ); |
| 1030 | assert_eq!( |
| 1031 | PluginInstallSource::parse(&review).unwrap(), |
| 1032 | PluginInstallSource::Remote(InstallSource::DirectUrl( |
| 1033 | "https://registry.npmjs.org/@acme/review/-/review-1.10.0.tgz".into() |
| 1034 | )) |
| 1035 | ); |
| 1036 | let mirrored = supported("@acme/mirrored"); |
| 1037 | assert_eq!( |
| 1038 | mirrored, "https://registry.example.com/npm/@acme/mirrored/-/mirrored-2.0.0-rc.1.tgz", |
| 1039 | "a declared https registry is the one fetched, never the default in its place" |
| 1040 | ); |
| 1041 | |
| 1042 | let http = refused("plain-http"); |
| 1043 | assert!(http.contains("only over https"), "{http}"); |
| 1044 | let credentials = refused("with-credentials"); |
| 1045 | assert!(credentials.contains("without credentials"), "{credentials}"); |
| 1046 | assert!( |
| 1047 | !credentials.contains("s3cret"), |
| 1048 | "a refusal never repeats a credential: {credentials}" |
| 1049 | ); |
| 1050 | let name = refused("tilde~name"); |
| 1051 | assert!(name.contains("not an exact npm package version"), "{name}"); |
| 1052 | |
| 1053 | let typed = catalog.candidate_by_name("typed-registry").unwrap(); |
| 1054 | assert_eq!( |
| 1055 | typed.version.as_deref(), |
| 1056 | Some("1.0.0"), |
| 1057 | "a version whose registry is not a string is ignored, not fetched from the default registry" |
| 1058 | ); |
| 1059 | assert!( |
| 1060 | typed |
| 1061 | .diagnostics |
| 1062 | .iter() |
| 1063 | .any(|d| d.code == "INVALID_REGISTRY") |
| 1064 | ); |
| 1065 | assert_eq!(supported("typed-registry"), "npm:typed-registry@1.0.0"); |
| 1066 | |
| 1067 | let tmp = tempfile::tempdir().unwrap(); |
| 1068 | let registry = crate::PluginRegistry::empty(tmp.path()); |
| 1069 | let entry = StoredMarketplaceCatalog { |
| 1070 | added_at: String::new(), |
| 1071 | source_path: tmp.path().join("index.json").display().to_string(), |
| 1072 | catalog: catalog.clone(), |
| 1073 | }; |
| 1074 | for (name, expected) in [("@acme/review", &review), ("@acme/mirrored", &mirrored)] { |
| 1075 | let candidate = entry.catalog.candidate_by_name(name).unwrap(); |
| 1076 | let CatalogInstallResolution::Supported { spec, .. } = |
| 1077 | resolve_candidate_install(&entry, candidate, ®istry) |
| 1078 | else { |
| 1079 | panic!("`{name}` resolves to the reviewed installer") |
| 1080 | }; |
| 1081 | assert_eq!(&spec, expected); |
| 1082 | assert!(matches!( |
| 1083 | PluginInstallSource::parse(&spec).unwrap(), |
| 1084 | PluginInstallSource::Remote(InstallSource::DirectUrl(_)) |
| 1085 | )); |
| 1086 | } |
| 1087 | let candidate = entry.catalog.candidate_by_name("plain-http").unwrap(); |
| 1088 | assert!(matches!( |
| 1089 | resolve_candidate_install(&entry, candidate, ®istry), |
| 1090 | CatalogInstallResolution::Unsupported { .. } |
| 1091 | )); |
| 1092 | } |
| 1093 |