gen-orb-mcp 0.1.16

Generate MCP servers from CircleCI orb definitions
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
//! Conformance rules for orb migration tooling.
//!
//! A `ConformanceRule` describes a single breaking change that occurred between
//! orb versions and how to detect and remediate it in a consumer's CI
//! configuration. Rules are generated automatically by the `OrbDiffer` and
//! embedded in the generated MCP server binary at release time — the orb author
//! never writes them manually.

use serde::{Deserialize, Serialize};

/// A single breaking-change rule embedded in the generated MCP server.
///
/// Describes something that is no longer valid in the target orb version,
/// along with how to remediate it in a consumer config.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", content = "data")]
pub enum ConformanceRule {
    /// A job was completely removed with no replacement.
    JobRemoved {
        /// The job name that was removed.
        name: String,
        /// The version in which this job was removed.
        since_version: String,
    },

    /// A job was renamed; the old name no longer exists.
    JobRenamed {
        /// The old job name.
        from: String,
        /// The new job name.
        to: String,
        /// Parameters that exist on `from` but not on `to`; strip them during
        /// migration.
        removed_parameters: Vec<String>,
        /// The version in which this rename occurred.
        since_version: String,
    },

    /// A parameter was removed from a job.
    ParameterRemoved {
        /// The job from which the parameter was removed.
        job: String,
        /// The parameter name that was removed.
        parameter: String,
        /// The version in which this parameter was removed.
        since_version: String,
    },

    /// A new mandatory parameter (no default value) was added to an existing
    /// job.
    ///
    /// Any consumer invocation of `job` must now supply `parameter`.
    /// The appropriate value is context-dependent and cannot be filled
    /// automatically.
    ParameterAdded {
        /// The job to which the parameter was added.
        job: String,
        /// The mandatory parameter name.
        parameter: String,
        /// The version in which this parameter was added.
        since_version: String,
    },

    /// A job's functionality was absorbed into another job.
    ///
    /// Any invocation of `absorbed` whose requires-chain includes `into`
    /// is redundant and should be removed.
    JobAbsorbed {
        /// The job that was absorbed (removed).
        absorbed: String,
        /// The job that absorbed it.
        into: String,
        /// The version in which this absorption occurred.
        since_version: String,
    },

    /// An enum parameter lost one of its allowed values.
    ParameterEnumValueRemoved {
        /// The job whose parameter lost a value.
        job: String,
        /// The parameter name.
        parameter: String,
        /// The value that was removed.
        removed_value: String,
        /// The value to substitute when the removed value is encountered.
        fallback_value: String,
        /// The version in which this value was removed.
        since_version: String,
    },

    /// A reusable command was completely removed with no replacement.
    CommandRemoved {
        /// The command name that was removed.
        name: String,
        /// The version in which this command was removed.
        since_version: String,
    },

    /// A reusable command was renamed; the old name no longer exists.
    CommandRenamed {
        /// The old command name.
        from: String,
        /// The new command name.
        to: String,
        /// Parameters that exist on `from` but not on `to`; strip them during
        /// migration.
        removed_parameters: Vec<String>,
        /// The version in which this rename occurred.
        since_version: String,
    },

    /// A parameter was renamed in a job (old name removed, new name added with
    /// the same value).
    ParameterRenamed {
        /// The job whose parameter was renamed.
        job: String,
        /// The old parameter name.
        from: String,
        /// The new parameter name.
        to: String,
        /// The version in which this rename occurred.
        since_version: String,
    },

    /// A parameter was removed from a reusable command.
    CommandParameterRemoved {
        /// The command from which the parameter was removed.
        command: String,
        /// The parameter name that was removed.
        parameter: String,
        /// The version in which this parameter was removed.
        since_version: String,
    },

    /// A new mandatory parameter (no default value) was added to an existing
    /// command.
    ///
    /// Any consumer invocation of `command` must now supply `parameter`.
    CommandParameterAdded {
        /// The command to which the parameter was added.
        command: String,
        /// The mandatory parameter name.
        parameter: String,
        /// The version in which this parameter was added.
        since_version: String,
    },
}

impl ConformanceRule {
    /// Returns the version in which this breaking change was introduced.
    pub fn since_version(&self) -> &str {
        match self {
            ConformanceRule::JobRemoved { since_version, .. } => since_version,
            ConformanceRule::JobRenamed { since_version, .. } => since_version,
            ConformanceRule::ParameterRemoved { since_version, .. } => since_version,
            ConformanceRule::ParameterAdded { since_version, .. } => since_version,
            ConformanceRule::JobAbsorbed { since_version, .. } => since_version,
            ConformanceRule::ParameterEnumValueRemoved { since_version, .. } => since_version,
            ConformanceRule::CommandRemoved { since_version, .. } => since_version,
            ConformanceRule::CommandRenamed { since_version, .. } => since_version,
            ConformanceRule::CommandParameterRemoved { since_version, .. } => since_version,
            ConformanceRule::CommandParameterAdded { since_version, .. } => since_version,
            ConformanceRule::ParameterRenamed { since_version, .. } => since_version,
        }
    }

    /// Returns a human-readable description of this rule.
    pub fn description(&self) -> String {
        match self {
            ConformanceRule::JobRemoved {
                name,
                since_version,
            } => {
                format!("Job `{name}` was removed in {since_version} with no replacement")
            }
            ConformanceRule::JobRenamed {
                from,
                to,
                since_version,
                ..
            } => {
                format!("Job `{from}` was renamed to `{to}` in {since_version}")
            }
            ConformanceRule::ParameterRemoved {
                job,
                parameter,
                since_version,
            } => {
                format!("Parameter `{parameter}` was removed from job `{job}` in {since_version}")
            }
            ConformanceRule::ParameterAdded {
                job,
                parameter,
                since_version,
            } => {
                format!(
                    "Mandatory parameter `{parameter}` was added to job `{job}` in \
                     {since_version}; all invocations must supply it"
                )
            }
            ConformanceRule::JobAbsorbed {
                absorbed,
                into,
                since_version,
            } => {
                format!(
                    "Job `{absorbed}` was absorbed into `{into}` in {since_version}; \
                     invocations of `{absorbed}` that require `{into}` are redundant"
                )
            }
            ConformanceRule::ParameterEnumValueRemoved {
                job,
                parameter,
                removed_value,
                fallback_value,
                since_version,
            } => {
                format!(
                    "Value `{removed_value}` was removed from parameter `{parameter}` \
                     of job `{job}` in {since_version}; use `{fallback_value}` instead"
                )
            }
            ConformanceRule::CommandRemoved {
                name,
                since_version,
            } => {
                format!("Command `{name}` was removed in {since_version} with no replacement")
            }
            ConformanceRule::CommandRenamed {
                from,
                to,
                since_version,
                ..
            } => {
                format!("Command `{from}` was renamed to `{to}` in {since_version}")
            }
            ConformanceRule::CommandParameterRemoved {
                command,
                parameter,
                since_version,
            } => {
                format!(
                    "Parameter `{parameter}` was removed from command `{command}` in \
                     {since_version}"
                )
            }
            ConformanceRule::CommandParameterAdded {
                command,
                parameter,
                since_version,
            } => {
                format!(
                    "Mandatory parameter `{parameter}` was added to command `{command}` in \
                     {since_version}; all invocations must supply it"
                )
            }
            ConformanceRule::ParameterRenamed {
                job,
                from,
                to,
                since_version,
            } => {
                format!(
                    "Parameter `{from}` was renamed to `{to}` in job `{job}` in {since_version}"
                )
            }
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_job_removed_round_trip() {
        let rule = ConformanceRule::JobRemoved {
            name: "choose_pipeline".to_string(),
            since_version: "5.0.0".to_string(),
        };
        let json = serde_json::to_string(&rule).unwrap();
        let back: ConformanceRule = serde_json::from_str(&json).unwrap();
        assert_eq!(rule, back);
    }

    #[test]
    fn test_job_renamed_since_version() {
        let rule = ConformanceRule::JobRenamed {
            from: "idiomatic_rust".to_string(),
            to: "idiomatic_rust_rolling".to_string(),
            removed_parameters: vec!["min_rust_version".to_string()],
            since_version: "5.0.0".to_string(),
        };
        assert_eq!(rule.since_version(), "5.0.0");
    }

    #[test]
    fn test_all_rules_serialize() {
        let rules = vec![
            ConformanceRule::JobRemoved {
                name: "choose_pipeline".to_string(),
                since_version: "5.0.0".to_string(),
            },
            ConformanceRule::JobRenamed {
                from: "idiomatic_rust".to_string(),
                to: "idiomatic_rust_rolling".to_string(),
                removed_parameters: vec!["min_rust_version".to_string()],
                since_version: "5.0.0".to_string(),
            },
            ConformanceRule::ParameterRemoved {
                job: "update_prlog".to_string(),
                parameter: "min_rust_version".to_string(),
                since_version: "5.0.0".to_string(),
            },
            ConformanceRule::ParameterAdded {
                job: "release_crate".to_string(),
                parameter: "package".to_string(),
                since_version: "5.0.0".to_string(),
            },
            ConformanceRule::JobAbsorbed {
                absorbed: "label".to_string(),
                into: "update_prlog".to_string(),
                since_version: "5.0.0".to_string(),
            },
            ConformanceRule::ParameterEnumValueRemoved {
                job: "update_changelog".to_string(),
                parameter: "update_log_option".to_string(),
                removed_value: "pipeline".to_string(),
                fallback_value: "halt".to_string(),
                since_version: "5.0.0".to_string(),
            },
            ConformanceRule::CommandRemoved {
                name: "old_command".to_string(),
                since_version: "5.0.0".to_string(),
            },
            ConformanceRule::CommandRenamed {
                from: "setup_rust".to_string(),
                to: "setup_rust_env".to_string(),
                removed_parameters: vec!["legacy_flag".to_string()],
                since_version: "5.0.0".to_string(),
            },
            ConformanceRule::CommandParameterRemoved {
                command: "build_binary".to_string(),
                parameter: "strip".to_string(),
                since_version: "5.0.0".to_string(),
            },
            ConformanceRule::CommandParameterAdded {
                command: "publish_crate".to_string(),
                parameter: "registry".to_string(),
                since_version: "5.0.0".to_string(),
            },
        ];

        let json = serde_json::to_string_pretty(&rules).unwrap();
        let back: Vec<ConformanceRule> = serde_json::from_str(&json).unwrap();
        assert_eq!(rules, back);
    }

    #[test]
    fn test_descriptions_are_non_empty() {
        let rules = vec![
            ConformanceRule::JobRemoved {
                name: "choose_pipeline".to_string(),
                since_version: "5.0.0".to_string(),
            },
            ConformanceRule::JobAbsorbed {
                absorbed: "label".to_string(),
                into: "update_prlog".to_string(),
                since_version: "5.0.0".to_string(),
            },
            ConformanceRule::ParameterAdded {
                job: "release_crate".to_string(),
                parameter: "package".to_string(),
                since_version: "5.0.0".to_string(),
            },
            ConformanceRule::CommandRemoved {
                name: "old_command".to_string(),
                since_version: "5.0.0".to_string(),
            },
            ConformanceRule::CommandParameterAdded {
                command: "publish_crate".to_string(),
                parameter: "registry".to_string(),
                since_version: "5.0.0".to_string(),
            },
        ];
        for rule in &rules {
            assert!(!rule.description().is_empty());
        }
    }

    // ── Fix #95: ParameterRenamed round-trip ────────────────────────────────

    #[test]
    fn test_parameter_renamed_round_trip() {
        let rule = ConformanceRule::ParameterRenamed {
            job: "test_features".to_string(),
            from: "min_rust_version".to_string(),
            to: "rust_version".to_string(),
            since_version: "6.0.0".to_string(),
        };
        let json = serde_json::to_string(&rule).unwrap();
        let back: ConformanceRule = serde_json::from_str(&json).unwrap();
        assert_eq!(rule, back);
        assert_eq!(rule.since_version(), "6.0.0");
        assert!(!rule.description().is_empty());
    }
}