1fn queue_search_scope(include_done: bool) -> &'static str {
16 if include_done {
17 "queue or done archive"
18 } else {
19 "active queue"
20 }
21}
22
23fn task_not_found_in_scope(
24 subject: &str,
25 task_id: &str,
26 include_done: bool,
27 include_done_hint: bool,
28) -> String {
29 let mut message = format!(
30 "{subject} '{task_id}' not found in {}.",
31 queue_search_scope(include_done)
32 );
33 if !include_done && include_done_hint {
34 message.push_str(" Use --include-done to search the done archive.");
35 }
36 message
37}
38
39fn task_not_found_short(task_id: &str) -> String {
40 format!("Task not found: {task_id}")
41}
42
43pub fn task_not_found_in_queue(task_id: &str) -> String {
45 task_not_found_in_scope("Task", task_id, false, false)
46}
47
48pub fn task_not_found_in_queue_or_done(task_id: &str) -> String {
50 task_not_found_in_scope("Task", task_id, true, false)
51}
52
53pub fn task_not_found_with_include_done_hint(task_id: &str) -> String {
55 task_not_found_in_scope("Task", task_id, false, true)
56}
57
58pub fn root_task_not_found(task_id: &str, include_done: bool) -> String {
60 task_not_found_in_scope("Root task", task_id, include_done, !include_done)
61}
62
63pub fn source_task_not_found(task_id: &str, search_done: bool) -> String {
65 task_not_found_in_scope("Source task", task_id, search_done, false)
66}
67
68pub fn task_not_found_batch_failure(task_id: &str) -> String {
70 task_not_found_short(task_id)
71}
72
73pub fn task_not_found_with_operation(operation: &str, task_id: &str) -> String {
75 format!(
76 "Queue query failed (operation={operation}): \
77 target task not found: {task_id}. \
78 Ensure it exists in .ralph/queue.jsonc."
79 )
80}
81
82pub fn task_not_found_in_done_archive(task_id: &str, context: &str) -> String {
84 format!("Task '{task_id}' not found in done archive for {context}.")
85}
86
87pub fn task_not_found_for_edit(operation: &str, task_id: &str) -> String {
89 format!(
90 "Queue {operation} failed (task_id={task_id}): \
91 task not found in .ralph/queue.jsonc."
92 )
93}
94
95pub fn task_not_found(task_id: &str) -> String {
97 task_not_found_short(task_id)
98}
99
100pub fn task_no_longer_exists(task_id: &str) -> String {
103 format!("Task '{task_id}' no longer exists in queue (may have been deleted or archived).")
104}
105
106#[cfg(test)]
107mod tests {
108 use super::*;
109
110 #[test]
111 fn task_not_found_in_active_queue_matches_contract() {
112 assert_eq!(
113 task_not_found_in_queue("RQ-100"),
114 "Task 'RQ-100' not found in active queue."
115 );
116 }
117
118 #[test]
119 fn task_not_found_in_queue_or_done_matches_contract() {
120 assert_eq!(
121 task_not_found_in_queue_or_done("RQ-100"),
122 "Task 'RQ-100' not found in queue or done archive."
123 );
124 }
125
126 #[test]
127 fn task_not_found_with_include_done_hint_matches_contract() {
128 assert_eq!(
129 task_not_found_with_include_done_hint("RQ-100"),
130 "Task 'RQ-100' not found in active queue. Use --include-done to search the done archive."
131 );
132 }
133
134 #[test]
135 fn root_task_not_found_without_done_search_includes_hint() {
136 assert_eq!(
137 root_task_not_found("RQ-100", false),
138 "Root task 'RQ-100' not found in active queue. Use --include-done to search the done archive."
139 );
140 }
141
142 #[test]
143 fn root_task_not_found_with_done_search_matches_contract() {
144 assert_eq!(
145 root_task_not_found("RQ-100", true),
146 "Root task 'RQ-100' not found in queue or done archive."
147 );
148 }
149
150 #[test]
151 fn source_task_not_found_without_done_search_matches_contract() {
152 assert_eq!(
153 source_task_not_found("RQ-100", false),
154 "Source task 'RQ-100' not found in active queue."
155 );
156 }
157
158 #[test]
159 fn source_task_not_found_with_done_search_matches_contract() {
160 assert_eq!(
161 source_task_not_found("RQ-100", true),
162 "Source task 'RQ-100' not found in queue or done archive."
163 );
164 }
165
166 #[test]
167 fn generic_task_not_found_matches_contract() {
168 assert_eq!(task_not_found("RQ-100"), "Task not found: RQ-100");
169 }
170
171 #[test]
172 fn batch_task_not_found_matches_contract() {
173 assert_eq!(
174 task_not_found_batch_failure("RQ-100"),
175 "Task not found: RQ-100"
176 );
177 }
178
179 #[test]
180 fn task_not_found_for_edit_matches_contract() {
181 assert_eq!(
182 task_not_found_for_edit("status", "RQ-100"),
183 "Queue status failed (task_id=RQ-100): task not found in .ralph/queue.jsonc."
184 );
185 }
186
187 #[test]
188 fn task_not_found_with_operation_matches_contract() {
189 assert_eq!(
190 task_not_found_with_operation("edit", "RQ-100"),
191 "Queue query failed (operation=edit): target task not found: RQ-100. Ensure it exists in .ralph/queue.jsonc."
192 );
193 }
194
195 #[test]
196 fn task_not_found_in_done_archive_matches_contract() {
197 assert_eq!(
198 task_not_found_in_done_archive("RQ-100", "restore"),
199 "Task 'RQ-100' not found in done archive for restore."
200 );
201 }
202
203 #[test]
204 fn task_no_longer_exists_matches_contract() {
205 assert_eq!(
206 task_no_longer_exists("RQ-100"),
207 "Task 'RQ-100' no longer exists in queue (may have been deleted or archived)."
208 );
209 }
210}