pmat 3.15.0

PMAT - Zero-config AI context generation and code quality toolkit (CLI, MCP, HTTP)
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
#![cfg_attr(coverage_nightly, coverage(off))]
use crate::services::renderer::{render_template, TemplateRenderer};
use serde_json::json;

#[test]
fn test_render_rust_cli_makefile() {
    let renderer = TemplateRenderer::new().unwrap();

    let template = r#"# {{ project_name }} - Rust CLI Application Makefile

.PHONY: all check lint test build run clean help

# Default target
all: check lint test build

# Type check
check:
    cargo check{% if target %} --target {{ target }}{% endif %}

# Lint with clippy
lint:
    cargo clippy --all-targets{% if target %} --target {{ target }}{% endif %} -- -D warnings

# Run tests
test:
    {% if has_tests %}cargo test{% if target %} --target {{ target }}{% endif %}{% else %}@echo "No tests configured"{% endif %}

# Build release binary
build:
    cargo build --release{% if target %} --target {{ target }}{% endif %}

# Run the application
run:
    cargo run{% if target %} --target {{ target }}{% endif %}{% if default_args %} -- {{ default_args }}{% endif %}

# Clean build artifacts
clean:
    cargo clean

# Show help
help:
    @echo "{{ project_name }} - Available targets:"
    @echo "  all    - Run check, lint, test, and build"
    @echo "  check  - Type check the code"
    @echo "  lint   - Run clippy linter"
    @echo "  test   - Run tests"
    @echo "  build  - Build release binary"
    @echo "  run    - Run the application"
    @echo "  clean  - Remove build artifacts"
    @echo "  help   - Show this help message"
"#;

    let params = json!({
        "project_name": "my-awesome-cli",
        "has_tests": true,
        "target": "x86_64-unknown-linux-gnu",
        "default_args": "--help"
    });

    let result = render_template(&renderer, template, params.as_object().unwrap().clone()).unwrap();

    assert!(result.contains("# my-awesome-cli - Rust CLI Application Makefile"));
    assert!(result.contains("cargo check --target x86_64-unknown-linux-gnu"));
    assert!(result.contains("cargo test --target x86_64-unknown-linux-gnu"));
    assert!(result.contains("cargo run --target x86_64-unknown-linux-gnu -- --help"));
}

#[test]
fn test_render_python_uv_makefile() {
    let renderer = TemplateRenderer::new().unwrap();

    let template = r#"# {{ project_name }} - Python UV CLI Application Makefile

.PHONY: all setup check lint test build run clean help

# Default target
all: check lint test

# Setup virtual environment
setup:
    uv venv
    uv pip install -e .{% if dev_dependencies %}
    uv pip install {% for dep in dev_dependencies %}{{ dep }} {% endfor %}{% endif %}

# Type check with mypy
check:
    {% if has_mypy %}uv run mypy {{ source_dir }}{% else %}@echo "Type checking not configured"{% endif %}

# Lint with ruff
lint:
    uv run ruff check {{ source_dir }}
    uv run ruff format --check {{ source_dir }}

# Run tests
test:
    {% if has_tests %}uv run pytest{% if test_args %} {{ test_args }}{% endif %}{% else %}@echo "No tests configured"{% endif %}

# Build distribution
build:
    uv build

# Run the application
run:
    uv run {{ entry_point }}{% if default_args %} {{ default_args }}{% endif %}

# Clean build artifacts
clean:
    rm -rf dist/ build/ *.egg-info
    find . -type d -name __pycache__ -exec rm -rf {} +
    find . -type f -name "*.pyc" -delete

# Show help
help:
    @echo "{{ project_name }} - Available targets:"
    @echo "  all    - Run check, lint, and test"
    @echo "  setup  - Setup virtual environment"
    @echo "  check  - Type check with mypy"
    @echo "  lint   - Lint with ruff"
    @echo "  test   - Run tests with pytest"
    @echo "  build  - Build distribution package"
    @echo "  run    - Run the application"
    @echo "  clean  - Remove build artifacts"
    @echo "  help   - Show this help message"
"#;

    let params = json!({
        "project_name": "python-data-processor",
        "source_dir": "src",
        "entry_point": "python -m data_processor",
        "has_mypy": true,
        "has_tests": true,
        "test_args": "-v --cov=src",
        "dev_dependencies": ["pytest", "pytest-cov", "mypy", "ruff"],
        "default_args": "--version"
    });

    let result = render_template(&renderer, template, params.as_object().unwrap().clone()).unwrap();

    assert!(result.contains("# python-data-processor - Python UV CLI Application Makefile"));
    assert!(result.contains("uv run mypy src"));
    // Allow for HTML entity encoding of = sign
    assert!(result.contains("uv run pytest -v --cov") && result.contains("src"));
    assert!(result.contains("uv pip install pytest pytest-cov mypy ruff"));
    assert!(result.contains("uv run python -m data_processor --version"));
}

#[test]
fn test_render_deno_typescript_makefile() {
    let renderer = TemplateRenderer::new().unwrap();

    let template = r#"# {{ project_name }} - Deno TypeScript CLI Application Makefile

.PHONY: all check lint test build run clean help

# Default target
all: check lint test

# Type check
check:
    deno check {{ entry_point }}{% if additional_files %} {% for file in additional_files %}{{ file }} {% endfor %}{% endif %}

# Lint
lint:
    deno lint{% if lint_args %} {{ lint_args }}{% endif %}

# Format check
format-check:
    deno fmt --check

# Format code
format:
    deno fmt

# Run tests
test:
    {% if has_tests %}deno test{% if test_args %} {{ test_args }}{% endif %}{% else %}@echo "No tests configured"{% endif %}

# Build standalone executable
build:
    deno compile{% if permissions %} {{ permissions }}{% endif %}{% if compile_args %} {{ compile_args }}{% endif %} -o {{ output_name }} {{ entry_point }}

# Run the application
run:
    deno run{% if permissions %} {{ permissions }}{% endif %} {{ entry_point }}{% if default_args %} {{ default_args }}{% endif %}

# Clean build artifacts
clean:
    rm -f {{ output_name }}{% if additional_outputs %} {% for output in additional_outputs %}{{ output }} {% endfor %}{% endif %}

# Show help
help:
    @echo "{{ project_name }} - Available targets:"
    @echo "  all          - Run check, lint, and test"
    @echo "  check        - Type check TypeScript code"
    @echo "  lint         - Lint code with deno lint"
    @echo "  format-check - Check code formatting"
    @echo "  format       - Format code"
    @echo "  test         - Run tests"
    @echo "  build        - Build standalone executable"
    @echo "  run          - Run the application"
    @echo "  clean        - Remove build artifacts"
    @echo "  help         - Show this help message"
"#;

    let params = json!({
        "project_name": "deno-file-processor",
        "entry_point": "src/main.ts",
        "output_name": "file-processor",
        "permissions": "--allow-read --allow-write --allow-net",
        "has_tests": true,
        "test_args": "--allow-read --allow-write --coverage=coverage",
        "additional_files": ["src/lib.ts", "src/utils.ts"],
        "compile_args": "--target x86_64-unknown-linux-gnu",
        "default_args": "--help"
    });

    let result = render_template(&renderer, template, params.as_object().unwrap().clone()).unwrap();

    assert!(result.contains("# deno-file-processor - Deno TypeScript CLI Application Makefile"));
    assert!(result.contains("deno check src/main.ts src/lib.ts src/utils.ts"));
    // Allow for HTML entity encoding of = sign
    assert!(
        result.contains("deno test --allow-read --allow-write --coverage")
            && result.contains("coverage")
    );
    assert!(result.contains("deno compile --allow-read --allow-write --allow-net --target x86_64-unknown-linux-gnu -o file-processor src/main.ts"));
    assert!(result.contains("deno run --allow-read --allow-write --allow-net src/main.ts --help"));
}

#[test]
fn test_render_readme_template() {
    let renderer = TemplateRenderer::new().unwrap();

    let template = r#"# {{ project_name }}

{{ description }}

## Features

{% for feature in features %}
- {{ feature }}
{% endfor %}

## Installation

```bash
{{ install_command }}
```

## Usage

```bash
{{ usage_example }}
```

{% if configuration %}
## Configuration

{{ configuration }}
{% endif %}

## Development

### Prerequisites

{% for prereq in prerequisites %}
- {{ prereq }}
{% endfor %}

### Building

```bash
{{ build_command }}
```

### Testing

```bash
{{ test_command }}
```

## License

{{ license }}
"#;

    let params = json!({
        "project_name": "Super CLI Tool",
        "description": "A powerful command-line tool for processing data efficiently.",
        "features": [
            "Fast parallel processing",
            "Support for multiple file formats",
            "Extensible plugin system",
            "Real-time progress reporting"
        ],
        "install_command": "cargo install super-cli-tool",
        "usage_example": "super-cli process input.csv -o output.json --parallel",
        "configuration": "Configuration can be provided via a `.super-cli.toml` file in your home directory.",
        "prerequisites": [
            "Rust 1.75 or later",
            "GNU Make",
            "Git"
        ],
        "build_command": "make build",
        "test_command": "make test",
        "license": "MIT License"
    });

    let result = render_template(&renderer, template, params.as_object().unwrap().clone()).unwrap();

    assert!(result.contains("# Super CLI Tool"));
    assert!(result.contains("A powerful command-line tool for processing data efficiently."));
    assert!(result.contains("- Fast parallel processing"));
    assert!(result.contains("cargo install super-cli-tool"));
    assert!(result.contains("super-cli process input.csv -o output.json --parallel"));
    // Check for the configuration text, allowing for HTML entity encoding of backticks
    assert!(
        result.contains("Configuration can be provided via a")
            && result.contains(".super-cli.toml")
            && result.contains("file in your home directory")
    );
}

#[test]
fn test_render_gitignore_template() {
    let renderer = TemplateRenderer::new().unwrap();

    let template = r#"# {{ project_type }} .gitignore

{% if ide_files %}
# IDE files
{% for file in ide_files %}
{{ file }}
{% endfor %}
{% endif %}

{% if build_artifacts %}
# Build artifacts
{% for artifact in build_artifacts %}
{{ artifact }}
{% endfor %}
{% endif %}

{% if language_specific %}
# {{ language }} specific
{% for pattern in language_specific %}
{{ pattern }}
{% endfor %}
{% endif %}

{% if os_specific %}
# OS specific
{% for pattern in os_specific %}
{{ pattern }}
{% endfor %}
{% endif %}

{% if custom_patterns %}
# Project specific
{% for pattern in custom_patterns %}
{{ pattern }}
{% endfor %}
{% endif %}
"#;

    let params = json!({
        "project_type": "Rust CLI Application",
        "language": "Rust",
        "ide_files": [
            ".idea/",
            ".vscode/",
            "*.swp",
            "*.swo",
            "*~"
        ],
        "build_artifacts": [
            "target/",
            "Cargo.lock",
            "dist/",
            "build/"
        ],
        "language_specific": [
            "**/*.rs.bk",
            "*.pdb"
        ],
        "os_specific": [
            ".DS_Store",
            "Thumbs.db",
            "desktop.ini"
        ],
        "custom_patterns": [
            ".env",
            "*.log",
            "temp/",
            "cache/"
        ]
    });

    let result = render_template(&renderer, template, params.as_object().unwrap().clone()).unwrap();

    assert!(result.contains("# Rust CLI Application .gitignore"));
    assert!(result.contains("# IDE files"));
    assert!(result.contains(".vscode/"));
    assert!(result.contains("# Build artifacts"));
    assert!(result.contains("target/"));
    assert!(result.contains("# Rust specific"));
    assert!(result.contains("**/*.rs.bk"));
    assert!(result.contains("# OS specific"));
    assert!(result.contains(".DS_Store"));
}

#[test]
fn test_render_with_conditionals() {
    let renderer = TemplateRenderer::new().unwrap();

    let template = r#"{% if enable_feature %}Feature is enabled!{% else %}Feature is disabled.{% endif %}
{% if not disable_option %}Option is active.{% endif %}
{% if language == "rust" %}This is a Rust project.{% endif %}
{% if environment != "production" %}Not in production.{% endif %}"#;

    let params = json!({
        "enable_feature": true,
        "disable_option": false,
        "language": "rust",
        "environment": "development"
    });

    let result = render_template(&renderer, template, params.as_object().unwrap().clone()).unwrap();

    assert!(result.contains("Feature is enabled!"));
    assert!(result.contains("Option is active."));
    assert!(result.contains("This is a Rust project."));
    assert!(result.contains("Not in production."));
}

#[test]
fn test_render_with_missing_parameters() {
    let renderer = TemplateRenderer::new().unwrap();

    let template = r#"Project: {{ project_name }}
Description: {{ description }}
Version: {{ version }}"#;

    let params = json!({
        "project_name": "Test Project"
        // Missing description and version
    });

    let result = render_template(&renderer, template, params.as_object().unwrap().clone()).unwrap();

    assert!(result.contains("Project: Test Project"));
    assert!(result.contains("Description: "));
    assert!(result.contains("Version: "));
}

#[test]
fn test_render_with_nested_loops() {
    let renderer = TemplateRenderer::new().unwrap();

    let template = r#"{% for category in categories %}
## {{ category.name }}
{% for item in category.items %}
- {{ item }}
{% endfor %}
{% endfor %}"#;

    let params = json!({
        "categories": [
            {
                "name": "Languages",
                "items": ["Rust", "Python", "TypeScript"]
            },
            {
                "name": "Tools",
                "items": ["Make", "Git", "Docker"]
            }
        ]
    });

    let result = render_template(&renderer, template, params.as_object().unwrap().clone()).unwrap();

    assert!(result.contains("## Languages"));
    assert!(result.contains("- Rust"));
    assert!(result.contains("- Python"));
    assert!(result.contains("## Tools"));
    assert!(result.contains("- Docker"));
}

#[test]
fn test_render_with_string_helpers() {
    let renderer = TemplateRenderer::new().unwrap();

    let template = r#"Snake: {{ name|snake_case }}
Kebab: {{ name|kebab_case }}
Pascal: {{ name|pascal_case }}
Year: {{ current_year() }}
Date: {{ current_date() }}"#;

    let params = json!({
        "name": "MyAwesomeProject"
    });

    let result = render_template(&renderer, template, params.as_object().unwrap().clone()).unwrap();

    assert!(result.contains("Snake: my_awesome_project"));
    assert!(result.contains("Kebab: my-awesome-project"));
    assert!(result.contains("Pascal: MyAwesomeProject"));
    assert!(result.contains("Year: 20")); // Partial match for year
    assert!(result.contains("Date: 20")); // Partial match for date
}