agent-file-tools 0.40.2

Agent File Tools — tree-sitter powered code analysis for AI agents
Documentation
use crate::helpers::AftProcess;
use std::fs;
use tempfile::TempDir;

const SAMPLE_QMD: &str = r#"---
title: My Quarto Document
author: Jane Doe
---

Setext Heading
==============

Some text under setext heading.

# Introduction

This is an introduction.

```{r}
# Some R code
x <- 1:10
plot(x)
```

## Section {#sec-id}

Some text under section with attribute.
"#;

#[test]
fn quarto_outline_extracts_headings() {
    let dir = TempDir::new().unwrap();
    let qmd_file = dir.path().join("document.qmd");
    fs::write(&qmd_file, SAMPLE_QMD).unwrap();

    let mut aft = AftProcess::spawn();
    aft.configure(dir.path());
    let resp = aft.send(&format!(
        r#"{{"id":"qmd-1","command":"outline","file":{}}}"#,
        crate::helpers::json_string(&qmd_file.display())
    ));

    assert_eq!(resp["success"], true, "outline should succeed: {:?}", resp);

    let text = resp["text"]
        .as_str()
        .expect("text field should be a string");

    // Headings should use 'h' kind abbreviation
    assert!(text.contains(" h "), "headings should use 'h' kind");

    // Check if ATX heading is present
    assert!(text.contains("Introduction"), "should have Introduction");

    // Check if Setext heading is present
    assert!(
        text.contains("Setext Heading"),
        "should have Setext Heading"
    );

    // Check if ATX-with-attribute heading is present.
    // NOTE: The {#sec-id} attribute currently leaks into the heading text,
    // which is an acceptable minor limitation for this release.
    assert!(
        text.contains("Section {#sec-id}"),
        "should have Section {{#sec-id}}"
    );
}