huskies: merge 730_story_use_numeric_only_story_ids_across_mcp_worktrees_git_branches_and_log_paths
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
//! Pure helpers for pipeline item ID parsing.
|
||||
//!
|
||||
//! Pipeline item IDs share the format `{number}_{type}_{slug}`, e.g.
|
||||
//! `"42_story_foo"`, `"7_bug_bar"`, `"100_refactor_baz"`. The functions here
|
||||
//! extract or validate the leading numeric segment without performing any I/O.
|
||||
//! Pipeline item IDs are numeric strings, e.g. `"42"`, `"730"`. Legacy items
|
||||
//! may use the old `{number}_{type}_{slug}` format (e.g. `"42_story_foo"`).
|
||||
//! The functions here extract or validate the leading numeric segment without
|
||||
//! performing any I/O.
|
||||
|
||||
/// Extract the numeric prefix from a pipeline item ID.
|
||||
///
|
||||
/// Returns the leading digit sequence from IDs like `"42_story_foo"` → `"42"`.
|
||||
/// Works for both numeric-only IDs (`"42"` → `"42"`) and legacy slug-format
|
||||
/// IDs (`"42_story_foo"` → `"42"`).
|
||||
/// Returns `None` if the ID has no leading digit sequence.
|
||||
pub fn extract_item_number(item_id: &str) -> Option<&str> {
|
||||
item_id
|
||||
@@ -16,9 +18,9 @@ pub fn extract_item_number(item_id: &str) -> Option<&str> {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Return `true` if `item_id` has a valid `{digits}_` prefix format.
|
||||
/// Return `true` if `item_id` starts with a numeric prefix.
|
||||
///
|
||||
/// Valid: `"42_story_foo"`, `"1_bug_bar"`.
|
||||
/// Valid: `"42"`, `"42_story_foo"`, `"1_bug_bar"`.
|
||||
/// Invalid: `"story_without_number"`, `""`, `"abc_story"`.
|
||||
pub fn has_valid_id_prefix(item_id: &str) -> bool {
|
||||
extract_item_number(item_id).is_some()
|
||||
@@ -42,6 +44,20 @@ mod tests {
|
||||
assert_eq!(extract_item_number("1_spike_research"), Some("1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_item_number_works_for_numeric_only_ids() {
|
||||
// Numeric-only IDs (the new canonical format).
|
||||
assert_eq!(extract_item_number("42"), Some("42"));
|
||||
assert_eq!(extract_item_number("730"), Some("730"));
|
||||
assert_eq!(extract_item_number("1"), Some("1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_valid_id_prefix_returns_true_for_numeric_only() {
|
||||
assert!(has_valid_id_prefix("42"));
|
||||
assert!(has_valid_id_prefix("730"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_item_number_returns_none_for_no_numeric_prefix() {
|
||||
assert_eq!(extract_item_number("story_without_number"), None);
|
||||
|
||||
Reference in New Issue
Block a user