Skip to repository content340 lines · 11.7 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T06:48:15.982Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
debugger.rs
1mod go_locator {
2 use collections::HashMap;
3 use dap::{DapLocator, adapters::DebugAdapterName};
4 use gpui::TestAppContext;
5 use project::debugger::locators::go::{DelveLaunchRequest, GoLocator};
6 use task::{HideStrategy, RevealStrategy, RevealTarget, SaveStrategy, Shell, TaskTemplate};
7 #[gpui::test]
8 async fn test_create_scenario_for_go_build(_: &mut TestAppContext) {
9 let locator = GoLocator;
10 let task = TaskTemplate {
11 label: "go build".into(),
12 command: "go".into(),
13 args: vec!["build".into(), ".".into()],
14 env: Default::default(),
15 cwd: Some("${ZED_WORKTREE_ROOT}".into()),
16 use_new_terminal: false,
17 allow_concurrent_runs: false,
18 reveal: RevealStrategy::Always,
19 reveal_target: RevealTarget::Dock,
20 hide: HideStrategy::Never,
21 shell: Shell::System,
22 tags: vec![],
23 show_summary: true,
24 show_command: true,
25 save: SaveStrategy::default(),
26 hooks: Default::default(),
27 };
28
29 let scenario = locator
30 .create_scenario(&task, "test label", &DebugAdapterName("Delve".into()))
31 .await;
32
33 assert!(scenario.is_none());
34 }
35
36 #[gpui::test]
37 async fn test_skip_non_go_commands_with_non_delve_adapter(_: &mut TestAppContext) {
38 let locator = GoLocator;
39 let task = TaskTemplate {
40 label: "cargo build".into(),
41 command: "cargo".into(),
42 args: vec!["build".into()],
43 env: Default::default(),
44 cwd: Some("${ZED_WORKTREE_ROOT}".into()),
45 use_new_terminal: false,
46 allow_concurrent_runs: false,
47 reveal: RevealStrategy::Always,
48 reveal_target: RevealTarget::Dock,
49 hide: HideStrategy::Never,
50 shell: Shell::System,
51 tags: vec![],
52 show_summary: true,
53 show_command: true,
54 save: SaveStrategy::default(),
55 hooks: Default::default(),
56 };
57
58 let scenario = locator
59 .create_scenario(
60 &task,
61 "test label",
62 &DebugAdapterName("SomeOtherAdapter".into()),
63 )
64 .await;
65 assert!(scenario.is_none());
66
67 let scenario = locator
68 .create_scenario(&task, "test label", &DebugAdapterName("Delve".into()))
69 .await;
70 assert!(scenario.is_none());
71 }
72 #[gpui::test]
73 async fn test_go_locator_run(_: &mut TestAppContext) {
74 let locator = GoLocator;
75 let delve = DebugAdapterName("Delve".into());
76
77 let task = TaskTemplate {
78 label: "go run with flags".into(),
79 command: "go".into(),
80 args: vec![
81 "run".to_string(),
82 "-race".to_string(),
83 "-ldflags".to_string(),
84 "-X main.version=1.0".to_string(),
85 "./cmd/myapp".to_string(),
86 "--config".to_string(),
87 "production.yaml".to_string(),
88 "--verbose".to_string(),
89 ],
90 env: {
91 let mut env = HashMap::default();
92 env.insert("GO_ENV".to_string(), "production".to_string());
93 env
94 },
95 cwd: Some("/project/root".into()),
96 ..Default::default()
97 };
98
99 let scenario = locator
100 .create_scenario(&task, "test run label", &delve)
101 .await
102 .unwrap();
103
104 let config: DelveLaunchRequest = serde_json::from_value(scenario.config).unwrap();
105
106 assert_eq!(
107 config,
108 DelveLaunchRequest {
109 request: "launch".to_string(),
110 mode: "debug".to_string(),
111 program: "./cmd/myapp".to_string(),
112 build_flags: vec![
113 "-race".to_string(),
114 "-ldflags".to_string(),
115 "-X main.version=1.0".to_string()
116 ],
117 args: vec![
118 "--config".to_string(),
119 "production.yaml".to_string(),
120 "--verbose".to_string(),
121 ],
122 env: {
123 let mut env = HashMap::default();
124 env.insert("GO_ENV".to_string(), "production".to_string());
125 env
126 },
127 cwd: Some("/project/root".to_string()),
128 }
129 );
130 }
131
132 #[gpui::test]
133 async fn test_go_locator_test(_: &mut TestAppContext) {
134 let locator = GoLocator;
135 let delve = DebugAdapterName("Delve".into());
136
137 // Test with tags and run flag
138 let task_with_tags = TaskTemplate {
139 label: "test".into(),
140 command: "go".into(),
141 args: vec![
142 "test".to_string(),
143 "-tags".to_string(),
144 "integration,unit".to_string(),
145 "-run".to_string(),
146 "Foo".to_string(),
147 ".".to_string(),
148 ],
149 ..Default::default()
150 };
151 let result = locator
152 .create_scenario(&task_with_tags, "", &delve)
153 .await
154 .unwrap();
155
156 let config: DelveLaunchRequest = serde_json::from_value(result.config).unwrap();
157
158 assert_eq!(
159 config,
160 DelveLaunchRequest {
161 request: "launch".to_string(),
162 mode: "test".to_string(),
163 program: ".".to_string(),
164 build_flags: vec!["-tags".to_string(), "integration,unit".to_string(),],
165 args: vec![
166 "-test.run".to_string(),
167 "Foo".to_string(),
168 "-test.v".to_string()
169 ],
170 env: Default::default(),
171 cwd: None,
172 }
173 );
174 }
175
176 #[gpui::test]
177 async fn test_go_locator_unescapes_nested_subtest_regex(_: &mut TestAppContext) {
178 let locator = GoLocator;
179 let delve = DebugAdapterName("Delve".into());
180
181 // Delve receives the `-run` regex with no shell, so GoLocator must strip
182 // the escaping itself.
183 let task = TaskTemplate {
184 label: "test subtest".into(),
185 command: "go".into(),
186 args: vec![
187 "test".to_string(),
188 "-v".to_string(),
189 "-run".to_string(),
190 "\\^TestFoo\\$/\\^simple_subtest\\$".to_string(),
191 ],
192 ..Default::default()
193 };
194 let result = locator.create_scenario(&task, "", &delve).await.unwrap();
195 let config: DelveLaunchRequest = serde_json::from_value(result.config).unwrap();
196 assert_eq!(
197 config,
198 DelveLaunchRequest {
199 request: "launch".to_string(),
200 mode: "test".to_string(),
201 program: ".".to_string(),
202 build_flags: vec![],
203 args: vec![
204 "-test.v".to_string(),
205 "-test.run".to_string(),
206 "^TestFoo$/^simple_subtest$".to_string(),
207 ],
208 env: Default::default(),
209 cwd: None,
210 }
211 );
212 }
213
214 #[gpui::test]
215 async fn test_skip_unsupported_go_commands(_: &mut TestAppContext) {
216 let locator = GoLocator;
217 let task = TaskTemplate {
218 label: "go clean".into(),
219 command: "go".into(),
220 args: vec!["clean".into()],
221 env: Default::default(),
222 cwd: Some("${ZED_WORKTREE_ROOT}".into()),
223 use_new_terminal: false,
224 allow_concurrent_runs: false,
225 reveal: RevealStrategy::Always,
226 reveal_target: RevealTarget::Dock,
227 hide: HideStrategy::Never,
228 shell: Shell::System,
229 tags: vec![],
230 show_summary: true,
231 show_command: true,
232 save: SaveStrategy::default(),
233 hooks: Default::default(),
234 };
235
236 let scenario = locator
237 .create_scenario(&task, "test label", &DebugAdapterName("Delve".into()))
238 .await;
239 assert!(scenario.is_none());
240 }
241}
242
243mod python_locator {
244 use dap::{DapLocator, adapters::DebugAdapterName};
245 use serde_json::json;
246
247 use project::debugger::locators::python::*;
248 use task::{DebugScenario, TaskTemplate};
249
250 #[gpui::test]
251 async fn test_python_locator() {
252 let adapter = DebugAdapterName("Debugpy".into());
253 let build_task = TaskTemplate {
254 label: "run module '$ZED_FILE'".into(),
255 command: "$ZED_CUSTOM_PYTHON_ACTIVE_ZED_TOOLCHAIN".into(),
256 args: vec!["-m".into(), "$ZED_CUSTOM_PYTHON_MODULE_NAME".into()],
257 env: Default::default(),
258 cwd: Some("$ZED_WORKTREE_ROOT".into()),
259 use_new_terminal: false,
260 allow_concurrent_runs: false,
261 reveal: task::RevealStrategy::Always,
262 reveal_target: task::RevealTarget::Dock,
263 hide: task::HideStrategy::Never,
264 tags: vec!["python-module-main-method".into()],
265 shell: task::Shell::System,
266 show_summary: false,
267 show_command: false,
268 save: task::SaveStrategy::default(),
269 hooks: Default::default(),
270 };
271
272 let expected_scenario = DebugScenario {
273 adapter: "Debugpy".into(),
274 label: "run module 'main.py'".into(),
275 build: None,
276 config: json!({
277 "request": "launch",
278 "python": "$ZED_CUSTOM_PYTHON_ACTIVE_ZED_TOOLCHAIN",
279 "args": [],
280 "cwd": "$ZED_WORKTREE_ROOT",
281 "module": "$ZED_CUSTOM_PYTHON_MODULE_NAME",
282 }),
283 tcp_connection: None,
284 };
285
286 assert_eq!(
287 PythonLocator
288 .create_scenario(&build_task, "run module 'main.py'", &adapter)
289 .await
290 .expect("Failed to create a scenario"),
291 expected_scenario
292 );
293 }
294}
295
296mod memory {
297 use project::debugger::{
298 MemoryCell,
299 memory::{MemoryIterator, PageAddress, PageContents},
300 };
301
302 #[test]
303 fn iterate_over_unmapped_memory() {
304 let empty_iterator = MemoryIterator::new(0..=127, Default::default());
305 let actual = empty_iterator.collect::<Vec<_>>();
306 let expected = vec![MemoryCell(None); 128];
307 assert_eq!(actual.len(), expected.len());
308 assert_eq!(actual, expected);
309 }
310
311 #[test]
312 fn iterate_over_partially_mapped_memory() {
313 let it = MemoryIterator::new(
314 0..=127,
315 vec![(PageAddress(5), PageContents::mapped(vec![1]))].into_iter(),
316 );
317 let actual = it.collect::<Vec<_>>();
318 let expected = std::iter::repeat_n(MemoryCell(None), 5)
319 .chain(std::iter::once(MemoryCell(Some(1))))
320 .chain(std::iter::repeat_n(MemoryCell(None), 122))
321 .collect::<Vec<_>>();
322 assert_eq!(actual.len(), expected.len());
323 assert_eq!(actual, expected);
324 }
325
326 #[test]
327 fn reads_from_the_middle_of_a_page() {
328 let partial_iter = MemoryIterator::new(
329 20..=30,
330 vec![(PageAddress(0), PageContents::mapped((0..255).collect()))].into_iter(),
331 );
332 let actual = partial_iter.collect::<Vec<_>>();
333 let expected = (20..=30)
334 .map(|val| MemoryCell(Some(val)))
335 .collect::<Vec<_>>();
336 assert_eq!(actual.len(), expected.len());
337 assert_eq!(actual, expected);
338 }
339}
340