stmo-cli 0.11.0

Turn Claude Code into a data analyst on sql.telemetry.mozilla.org
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
#![allow(clippy::missing_errors_doc)]

use anyhow::{Context, Result};
use std::collections::HashMap;
use std::fs;
use std::path::{Path, PathBuf};

use crate::api::RedashClient;
use crate::models::{
    CreateDashboard, CreateWidget, Dashboard, DashboardMetadata, Query, WidgetMetadata,
    build_dashboard_level_parameter_mappings,
};

fn extract_dashboard_slugs_from_path(dashboards_dir: &Path) -> Result<Vec<String>> {
    if !dashboards_dir.exists() {
        return Ok(Vec::new());
    }

    let mut dashboard_slugs = Vec::new();

    for entry in fs::read_dir(dashboards_dir).context("Failed to read dashboards directory")? {
        let entry = entry.context("Failed to read directory entry")?;
        let path = entry.path();

        if path.extension().is_some_and(|ext| ext == "yaml")
            && let Some(filename) = path.file_name().and_then(|f| f.to_str())
            && let Some(slug) = filename
                .strip_suffix(".yaml")
                .and_then(|s| s.split_once('-'))
                .map(|(_, slug)| slug)
        {
            dashboard_slugs.push(slug.to_string());
        }
    }

    dashboard_slugs.sort_unstable();
    dashboard_slugs.dedup();

    Ok(dashboard_slugs)
}

fn extract_dashboard_slugs_from_directory() -> Result<Vec<String>> {
    extract_dashboard_slugs_from_path(Path::new("dashboards"))
}

pub async fn discover(client: &RedashClient) -> Result<()> {
    println!("Fetching your favorite dashboards from Redash...\n");
    let dashboards = client.fetch_favorite_dashboards().await?;

    if dashboards.is_empty() {
        println!("No dashboards found.");
        return Ok(());
    }

    println!("Found {} dashboards:\n", dashboards.len());

    for dashboard in &dashboards {
        let status_flags = match (dashboard.is_draft, dashboard.is_archived) {
            (true, true) => " [DRAFT, ARCHIVED]",
            (true, false) => " [DRAFT]",
            (false, true) => " [ARCHIVED]",
            (false, false) => "",
        };
        println!("  {} - {}{}", dashboard.slug, dashboard.name, status_flags);
    }

    println!("\nUsage:");
    println!("  stmo-cli dashboards fetch <slug> [<slug>...]");
    println!(
        "  stmo-cli dashboards fetch firefox-desktop-on-steamos bug-2006698---ccov-build-regression"
    );

    Ok(())
}

pub async fn fetch(client: &RedashClient, dashboard_slugs: Vec<String>) -> Result<()> {
    if dashboard_slugs.is_empty() {
        anyhow::bail!(
            "No dashboard slugs specified. Use 'dashboards discover' to see available dashboards.\n\nExample:\n  stmo-cli dashboards fetch firefox-desktop-on-steamos bug-2006698---ccov-build-regression"
        );
    }

    fs::create_dir_all("dashboards").context("Failed to create dashboards directory")?;

    println!("Fetching {} dashboards...\n", dashboard_slugs.len());

    let mut success_count = 0;
    let mut failed_slugs = Vec::new();

    for slug in &dashboard_slugs {
        match client.get_dashboard(slug).await {
            Ok(dashboard) => {
                let filename = format!("dashboards/{}-{}.yaml", dashboard.id, dashboard.slug);

                let metadata = DashboardMetadata {
                    id: dashboard.id,
                    name: dashboard.name.clone(),
                    slug: dashboard.slug.clone(),
                    user_id: dashboard.user_id,
                    is_draft: dashboard.is_draft,
                    is_archived: dashboard.is_archived,
                    filters_enabled: dashboard.filters_enabled,
                    tags: dashboard.tags.clone(),
                    widgets: dashboard
                        .widgets
                        .iter()
                        .map(|w| WidgetMetadata {
                            id: w.id,
                            width: w.width,
                            visualization_id: w.visualization_id,
                            query_id: w.visualization.as_ref().map(|v| v.query.id),
                            visualization_name: w.visualization.as_ref().map(|v| v.name.clone()),
                            text: w.text.clone(),
                            options: w.options.clone(),
                        })
                        .collect(),
                };

                let yaml_content = serde_yaml::to_string(&metadata)
                    .context("Failed to serialize dashboard metadata")?;
                fs::write(&filename, yaml_content)
                    .context(format!("Failed to write {filename}"))?;

                let status = if dashboard.is_archived {
                    " [ARCHIVED]"
                } else {
                    ""
                };
                println!("  ✓ {} - {}{}", dashboard.id, dashboard.name, status);
                success_count += 1;
            }
            Err(e) => {
                eprintln!("  âš  Dashboard '{slug}' failed to fetch: {e}");
                failed_slugs.push(slug.clone());
            }
        }
    }

    if failed_slugs.is_empty() {
        println!("\n✓ All dashboards fetched successfully");
        println!(
            "\nTip: Favorite these dashboards in the Redash web UI so they appear in 'dashboards discover'."
        );
        Ok(())
    } else {
        println!("\n✓ {success_count} dashboard(s) fetched successfully");
        anyhow::bail!(
            "{} dashboard(s) failed to fetch: {}",
            failed_slugs.len(),
            failed_slugs.join(", ")
        );
    }
}

pub async fn deploy(client: &RedashClient, dashboard_slugs: Vec<String>, all: bool) -> Result<()> {
    let existing_dashboard_slugs = extract_dashboard_slugs_from_directory()?;

    let slugs_to_deploy = if all {
        if existing_dashboard_slugs.is_empty() {
            anyhow::bail!("No dashboards found in dashboards/ directory. Use 'fetch' first.");
        }
        println!(
            "Deploying {} dashboards from local directory...\n",
            existing_dashboard_slugs.len()
        );
        existing_dashboard_slugs
    } else if !dashboard_slugs.is_empty() {
        println!(
            "Deploying {} specific dashboards...\n",
            dashboard_slugs.len()
        );
        dashboard_slugs
    } else {
        anyhow::bail!(
            "No dashboard slugs specified. Use --all to deploy all tracked dashboards, or provide specific slugs.\n\nExamples:\n  stmo-cli dashboards deploy --all\n  stmo-cli dashboards deploy firefox-desktop-on-steamos bug-2006698---ccov-build-regression"
        );
    };

    let mut success_count = 0;
    let mut failed_slugs = Vec::new();

    for slug in &slugs_to_deploy {
        match deploy_single_dashboard(client, slug).await {
            Ok(name) => {
                println!("  ✓ {name}");
                success_count += 1;
            }
            Err(e) => {
                eprintln!("  âš  Dashboard '{slug}' failed to deploy: {e}");
                failed_slugs.push(slug.clone());
            }
        }
    }

    if failed_slugs.is_empty() {
        println!("\n✓ All dashboards deployed successfully");
        Ok(())
    } else {
        println!("\n✓ {success_count} dashboard(s) deployed successfully");
        anyhow::bail!(
            "{} dashboard(s) failed to deploy: {}",
            failed_slugs.len(),
            failed_slugs.join(", ")
        );
    }
}

fn save_dashboard_yaml(
    dashboard: &crate::models::Dashboard,
    old_yaml_path: Option<std::path::PathBuf>,
) -> Result<()> {
    use crate::models::Widget;

    let filename = format!("dashboards/{}-{}.yaml", dashboard.id, dashboard.slug);

    let metadata = DashboardMetadata {
        id: dashboard.id,
        name: dashboard.name.clone(),
        slug: dashboard.slug.clone(),
        user_id: dashboard.user_id,
        is_draft: dashboard.is_draft,
        is_archived: dashboard.is_archived,
        filters_enabled: dashboard.filters_enabled,
        tags: dashboard.tags.clone(),
        widgets: dashboard
            .widgets
            .iter()
            .map(|w: &Widget| WidgetMetadata {
                id: w.id,
                width: w.width,
                visualization_id: w.visualization_id,
                query_id: w.visualization.as_ref().map(|v| v.query.id),
                visualization_name: w.visualization.as_ref().map(|v| v.name.clone()),
                text: w.text.clone(),
                options: w.options.clone(),
            })
            .collect(),
    };

    let yaml_content =
        serde_yaml::to_string(&metadata).context("Failed to serialize dashboard metadata")?;
    fs::write(&filename, &yaml_content).context(format!("Failed to write {filename}"))?;

    if let Some(old_path) = old_yaml_path
        && old_path != std::path::Path::new(&filename)
    {
        fs::remove_file(&old_path).context(format!("Failed to delete {}", old_path.display()))?;
    }

    Ok(())
}

async fn resolve_visualization_id(
    client: &RedashClient,
    widget: &WidgetMetadata,
    query_cache: &mut HashMap<u64, Query>,
) -> Result<Option<u64>> {
    if let Some(viz_id) = widget.visualization_id {
        return Ok(Some(viz_id));
    }

    let (Some(query_id), Some(viz_name)) = (widget.query_id, widget.visualization_name.as_deref())
    else {
        return Ok(None);
    };

    if let std::collections::hash_map::Entry::Vacant(e) = query_cache.entry(query_id) {
        e.insert(client.get_query(query_id).await?);
    }

    let query = query_cache.get(&query_id).expect("just inserted");
    if let Some(viz) = query.visualizations.iter().find(|v| v.name == viz_name) {
        Ok(Some(viz.id))
    } else {
        let available: Vec<&str> = query
            .visualizations
            .iter()
            .map(|v| v.name.as_str())
            .collect();
        anyhow::bail!(
            "No visualization named '{viz_name}' found on query {query_id}. Available: {available:?}"
        );
    }
}

async fn auto_populate_parameter_mappings(
    client: &RedashClient,
    query_id: u64,
    existing_mappings: Option<&serde_json::Value>,
    query_cache: &mut HashMap<u64, Query>,
) -> Result<Option<serde_json::Value>> {
    let should_build = match existing_mappings {
        None => true,
        Some(serde_json::Value::Object(m)) => m.is_empty(),
        Some(_) => false,
    };
    if !should_build {
        return Ok(None);
    }
    if let std::collections::hash_map::Entry::Vacant(e) = query_cache.entry(query_id) {
        e.insert(client.get_query(query_id).await?);
    }
    Ok(query_cache
        .get(&query_id)
        .filter(|q| !q.options.parameters.is_empty())
        .map(|q| build_dashboard_level_parameter_mappings(&q.options.parameters)))
}

fn find_dashboard_yaml(dashboard_slug: &str) -> Result<PathBuf> {
    let yaml_files: Vec<_> = fs::read_dir("dashboards")
        .context("Failed to read dashboards directory")?
        .filter_map(std::result::Result::ok)
        .filter(|entry| {
            entry.path().extension().is_some_and(|ext| ext == "yaml")
                && entry
                    .file_name()
                    .to_str()
                    .and_then(|name| name.strip_suffix(".yaml"))
                    .and_then(|name| name.split_once('-'))
                    .map(|(_, slug)| slug)
                    .is_some_and(|slug| slug == dashboard_slug)
        })
        .collect();

    if yaml_files.is_empty() {
        anyhow::bail!("No YAML file found for dashboard '{dashboard_slug}'");
    }
    if yaml_files.len() > 1 {
        anyhow::bail!("Multiple YAML files found for dashboard '{dashboard_slug}'");
    }
    Ok(yaml_files[0].path())
}

async fn resolve_widget_options(
    client: &RedashClient,
    widget: &WidgetMetadata,
    query_cache: &mut HashMap<u64, Query>,
) -> Result<(crate::models::WidgetOptions, bool)> {
    let mut options = widget.options.clone();
    let has_params = if let Some(query_id) = widget.query_id
        && let Some(mappings) = auto_populate_parameter_mappings(
            client,
            query_id,
            options.parameter_mappings.as_ref(),
            query_cache,
        )
        .await?
    {
        options.parameter_mappings = Some(mappings);
        true
    } else {
        false
    };
    Ok((options, has_params))
}

async fn deploy_single_dashboard(client: &RedashClient, dashboard_slug: &str) -> Result<String> {
    let yaml_path = find_dashboard_yaml(dashboard_slug)?;
    let yaml_content = fs::read_to_string(&yaml_path)
        .context(format!("Failed to read {}", yaml_path.display()))?;

    let local_metadata: DashboardMetadata =
        serde_yaml::from_str(&yaml_content).context("Failed to parse dashboard YAML")?;

    let (server_dashboard_id, slug_for_refetch, old_yaml_path) = if local_metadata.id == 0 {
        let created = client
            .create_dashboard(&CreateDashboard {
                name: local_metadata.name.clone(),
            })
            .await?;
        println!(
            "  ✓ Created new dashboard: {} - {}",
            created.id, created.name
        );
        client.favorite_dashboard(&created.slug).await?;
        (created.id, created.slug.clone(), Some(yaml_path.clone()))
    } else {
        let server_dashboard = client.get_dashboard(dashboard_slug).await?;

        let server_widget_ids: std::collections::HashSet<u64> =
            server_dashboard.widgets.iter().map(|w| w.id).collect();

        let local_widget_ids: std::collections::HashSet<u64> = local_metadata
            .widgets
            .iter()
            .filter(|w| w.id != 0)
            .map(|w| w.id)
            .collect();

        for widget_id in &server_widget_ids {
            if !local_widget_ids.contains(widget_id) {
                client.delete_widget(*widget_id).await?;
            }
        }

        (server_dashboard.id, dashboard_slug.to_string(), None)
    };

    let mut query_cache: HashMap<u64, Query> = HashMap::new();
    let mut any_widget_has_params = false;

    for widget in &local_metadata.widgets {
        let (options, has_params) =
            resolve_widget_options(client, widget, &mut query_cache).await?;
        if has_params {
            any_widget_has_params = true;
        }
        let payload = CreateWidget {
            dashboard_id: server_dashboard_id,
            visualization_id: resolve_visualization_id(client, widget, &mut query_cache).await?,
            text: widget.text.clone(),
            options,
            width: if widget.id == 0 { 1 } else { widget.width },
        };
        if widget.id == 0 {
            client.create_widget(&payload).await?;
        } else {
            client.update_widget(widget.id, &payload).await?;
        }
    }

    let updated_dashboard = Dashboard {
        id: server_dashboard_id,
        name: local_metadata.name.clone(),
        slug: local_metadata.slug.clone(),
        user_id: local_metadata.user_id,
        is_archived: local_metadata.is_archived,
        is_draft: local_metadata.is_draft,
        filters_enabled: any_widget_has_params || local_metadata.filters_enabled,
        tags: local_metadata.tags.clone(),
        widgets: vec![],
    };

    client.update_dashboard(&updated_dashboard).await?;

    let refreshed = client.get_dashboard(&slug_for_refetch).await?;

    save_dashboard_yaml(&refreshed, old_yaml_path)?;

    Ok(refreshed.name)
}

pub async fn archive(client: &RedashClient, dashboard_slugs: Vec<String>) -> Result<()> {
    if dashboard_slugs.is_empty() {
        anyhow::bail!(
            "No dashboard slugs specified.\n\nExample:\n  stmo-cli dashboards archive firefox-desktop-on-steamos bug-2006698---ccov-build-regression"
        );
    }

    println!("Archiving {} dashboards...\n", dashboard_slugs.len());

    let mut success_count = 0;
    let mut failed_slugs = Vec::new();

    for slug in &dashboard_slugs {
        match client.get_dashboard(slug).await {
            Ok(dashboard) => match client.archive_dashboard(dashboard.id).await {
                Ok(()) => {
                    let yaml_files: Vec<_> = fs::read_dir("dashboards")
                        .context("Failed to read dashboards directory")?
                        .filter_map(std::result::Result::ok)
                        .filter(|entry| {
                            entry.path().extension().is_some_and(|ext| ext == "yaml")
                                && entry
                                    .file_name()
                                    .to_str()
                                    .and_then(|name| name.strip_suffix(".yaml"))
                                    .and_then(|name| name.split_once('-'))
                                    .map(|(_, file_slug)| file_slug)
                                    .is_some_and(|file_slug| file_slug == slug)
                        })
                        .collect();

                    for file in yaml_files {
                        fs::remove_file(file.path())
                            .context(format!("Failed to delete {}", file.path().display()))?;
                    }

                    println!("  ✓ {} archived and local file deleted", dashboard.name);
                    success_count += 1;
                }
                Err(e) => {
                    eprintln!("  âš  Dashboard '{slug}' failed to archive: {e}");
                    failed_slugs.push(slug.clone());
                }
            },
            Err(e) => {
                eprintln!("  âš  Dashboard '{slug}' failed to fetch for archival: {e}");
                failed_slugs.push(slug.clone());
            }
        }
    }

    if failed_slugs.is_empty() {
        println!("\n✓ All dashboards archived successfully");
        Ok(())
    } else {
        println!("\n✓ {success_count} dashboard(s) archived successfully");
        anyhow::bail!(
            "{} dashboard(s) failed to archive: {}",
            failed_slugs.len(),
            failed_slugs.join(", ")
        );
    }
}

pub async fn unarchive(client: &RedashClient, dashboard_slugs: Vec<String>) -> Result<()> {
    if dashboard_slugs.is_empty() {
        anyhow::bail!(
            "No dashboard slugs specified.\n\nExample:\n  stmo-cli dashboards unarchive firefox-desktop-on-steamos bug-2006698---ccov-build-regression"
        );
    }

    println!("Unarchiving {} dashboards...\n", dashboard_slugs.len());

    let mut success_count = 0;
    let mut failed_slugs = Vec::new();

    for slug in &dashboard_slugs {
        match client.get_dashboard(slug).await {
            Ok(dashboard) => match client.unarchive_dashboard(dashboard.id).await {
                Ok(unarchived) => {
                    println!("  ✓ {} unarchived", unarchived.name);
                    success_count += 1;
                }
                Err(e) => {
                    eprintln!("  âš  Dashboard '{slug}' failed to unarchive: {e}");
                    failed_slugs.push(slug.clone());
                }
            },
            Err(e) => {
                eprintln!("  âš  Dashboard '{slug}' failed to fetch for unarchival: {e}");
                failed_slugs.push(slug.clone());
            }
        }
    }

    if failed_slugs.is_empty() {
        println!("\n✓ All dashboards unarchived successfully");
        println!("\nUse 'dashboards fetch' to download the YAML files:");
        println!("  stmo-cli dashboards fetch {}", dashboard_slugs.join(" "));
        Ok(())
    } else {
        println!("\n✓ {success_count} dashboard(s) unarchived successfully");
        anyhow::bail!(
            "{} dashboard(s) failed to unarchive: {}",
            failed_slugs.len(),
            failed_slugs.join(", ")
        );
    }
}

#[cfg(test)]
#[allow(clippy::missing_errors_doc)]
mod tests {
    use super::*;
    use tempfile::TempDir;

    #[test]
    fn test_extract_dashboard_slugs_from_directory_empty() {
        let temp_dir = TempDir::new().unwrap();
        let result = extract_dashboard_slugs_from_path(temp_dir.path());
        assert!(result.is_ok());
        let slugs = result.unwrap();
        assert!(slugs.is_empty());
    }

    #[test]
    fn test_extract_dashboard_slugs_with_triple_dash() {
        let temp_dir = TempDir::new().unwrap();
        let temp_path = temp_dir.path();

        fs::write(
            temp_path.join("2006698-bug-2006698---ccov-build-regression.yaml"),
            "test",
        )
        .unwrap();
        fs::write(
            temp_path.join("2570-firefox-desktop-on-steamos.yaml"),
            "test",
        )
        .unwrap();

        let result = extract_dashboard_slugs_from_path(temp_path);
        assert!(result.is_ok());

        let slugs = result.unwrap();

        assert!(slugs.contains(&"bug-2006698---ccov-build-regression".to_string()));
        assert!(slugs.contains(&"firefox-desktop-on-steamos".to_string()));
    }

    #[test]
    fn test_extract_dashboard_slugs_deduplication() {
        let temp_dir = TempDir::new().unwrap();
        let temp_path = temp_dir.path();

        fs::write(
            temp_path.join("2006698-bug-2006698---ccov-build-regression.yaml"),
            "test",
        )
        .unwrap();
        fs::write(
            temp_path.join("2006699-bug-2006698---ccov-build-regression.yaml"),
            "test",
        )
        .unwrap();

        let result = extract_dashboard_slugs_from_path(temp_path);
        assert!(result.is_ok());

        let slugs = result.unwrap();

        assert_eq!(slugs.len(), 1);
        assert_eq!(slugs[0], "bug-2006698---ccov-build-regression");
    }

    #[test]
    fn test_extract_dashboard_slugs_ignores_non_yaml() {
        let temp_dir = TempDir::new().unwrap();
        let temp_path = temp_dir.path();

        fs::write(
            temp_path.join("2006698-bug-2006698---ccov-build-regression.yaml"),
            "test",
        )
        .unwrap();
        fs::write(
            temp_path.join("2570-firefox-desktop-on-steamos.txt"),
            "test",
        )
        .unwrap();
        fs::write(temp_path.join("README.md"), "test").unwrap();

        let result = extract_dashboard_slugs_from_path(temp_path);
        assert!(result.is_ok());

        let slugs = result.unwrap();

        assert_eq!(slugs.len(), 1);
        assert_eq!(slugs[0], "bug-2006698---ccov-build-regression");
    }

    #[test]
    fn test_extract_dashboard_slugs_sorted() {
        let temp_dir = TempDir::new().unwrap();
        let temp_path = temp_dir.path();

        fs::write(temp_path.join("3000-zebra-dashboard.yaml"), "test").unwrap();
        fs::write(
            temp_path.join("2006698-bug-2006698---ccov-build-regression.yaml"),
            "test",
        )
        .unwrap();
        fs::write(temp_path.join("1000-alpha-dashboard.yaml"), "test").unwrap();

        let result = extract_dashboard_slugs_from_path(temp_path);
        assert!(result.is_ok());

        let slugs = result.unwrap();

        assert_eq!(slugs.len(), 3);
        assert_eq!(slugs[0], "alpha-dashboard");
        assert_eq!(slugs[1], "bug-2006698---ccov-build-regression");
        assert_eq!(slugs[2], "zebra-dashboard");
    }
}