vibe_coding_tracker 1.3.2

Vibe Coding Tracker - AI coding assistant telemetry/usage parser, aggregate JSONL events into CodeAnalysis results
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
// Integration tests for CLI functionality
//
// These tests verify command-line interface operations (excluding TUI components)

use assert_cmd::Command;
use predicates::prelude::*;
use std::path::PathBuf;
use tempfile::TempDir;
use vibe_coding_tracker::VERSION;

#[test]
fn test_version_command() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("version");

    cmd.assert()
        .success()
        .stdout(predicate::str::contains("Version"));
}

#[test]
fn test_version_flag_outputs_build_version_only() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("--version");

    cmd.assert()
        .success()
        .stdout(predicate::eq(format!("{VERSION}\n")));
}

#[test]
fn test_short_version_flag_outputs_build_version_only() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("-V");

    cmd.assert()
        .success()
        .stdout(predicate::eq(format!("{VERSION}\n")));
}

#[test]
fn test_version_command_json() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("version").arg("--json");

    cmd.assert()
        .success()
        .stdout(predicate::str::contains("Version"));
}

#[test]
fn test_version_command_text() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("version").arg("--text");

    cmd.assert()
        .success()
        .stdout(predicate::str::contains("Version"));
}

#[test]
fn test_analysis_command_with_example_file() {
    let example_file = PathBuf::from("examples/test_conversation_claude_code.jsonl");

    if !example_file.exists() {
        eprintln!("Skipping test: example file not found");
        return;
    }

    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("analysis")
        .arg("--path")
        .arg(example_file.to_str().unwrap());

    cmd.assert()
        .success()
        .stdout(predicate::str::contains("extensionName"))
        .stdout(predicate::str::contains("records"));
}

#[test]
fn test_analysis_command_with_output_file() {
    let example_file = PathBuf::from("examples/test_conversation_claude_code.jsonl");
    let temp_dir = TempDir::new().unwrap();
    let output_file = temp_dir.path().join("output.json");

    if !example_file.exists() {
        eprintln!("Skipping test: example file not found");
        return;
    }

    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("analysis")
        .arg("--path")
        .arg(example_file.to_str().unwrap())
        .arg("--output")
        .arg(output_file.to_str().unwrap());

    cmd.assert().success();

    // Verify output file was created
    assert!(output_file.exists(), "Output file should be created");

    // Verify output file contains valid JSON
    let content = std::fs::read_to_string(&output_file).unwrap();
    let json: serde_json::Value = serde_json::from_str(&content).unwrap();
    assert!(json.is_object(), "Output should be valid JSON object");
}

#[test]
fn test_analysis_command_with_nonexistent_file() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("analysis")
        .arg("--path")
        .arg("nonexistent_file.jsonl");

    cmd.assert().failure(); // Should fail with nonexistent file
}

#[test]
fn test_analysis_batch_mode() {
    // This test is skipped because it may hang when scanning system directories
    // Use test_analysis_batch_mode_with_output instead which has explicit timeout
    eprintln!("Skipping test_analysis_batch_mode - may hang on system directories");
}

#[test]
fn test_analysis_batch_mode_with_output() {
    use std::time::Duration;

    let temp_dir = TempDir::new().unwrap();
    let output_file = temp_dir.path().join("batch_output.json");

    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("analysis")
        .arg("--output")
        .arg(output_file.to_str().unwrap())
        .timeout(Duration::from_secs(10)); // Add 10 second timeout

    // May timeout on slow systems or large session directories
    let output = cmd.output();

    if let Ok(output) = output
        && output.status.success()
        && output_file.exists()
    {
        let content = std::fs::read_to_string(&output_file).unwrap();
        let json: serde_json::Value = serde_json::from_str(&content).unwrap();
        assert!(json.is_array(), "Batch output should be JSON array");
    }
}

#[test]
fn test_analysis_command_json() {
    use std::time::Duration;

    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("analysis")
        .arg("--json")
        .timeout(Duration::from_secs(10));

    let output = cmd.output().expect("failed to spawn vct binary");

    // Allow timeout (env-dependent on session-directory size) but not other
    // failures — a non-zero exit means a regression in the --json path.
    if output.status.code().is_none() {
        return;
    }
    assert!(
        output.status.success(),
        "vct analysis --json failed: stderr={}",
        String::from_utf8_lossy(&output.stderr)
    );

    let stdout = String::from_utf8_lossy(&output.stdout);
    let json: serde_json::Value =
        serde_json::from_str(&stdout).expect("--json output should be valid JSON");
    assert!(
        json.is_array(),
        "--json output should be a JSON array of aggregated rows"
    );
}

#[test]
fn test_analysis_command_text() {
    use std::time::Duration;

    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("analysis")
        .arg("--text")
        .timeout(Duration::from_secs(10));

    let output = cmd.output().expect("failed to spawn vct binary");
    assert!(
        output.status.success() || output.status.code().is_none(),
        "vct analysis --text failed: stderr={}",
        String::from_utf8_lossy(&output.stderr)
    );
}

#[test]
fn test_analysis_command_table() {
    use std::time::Duration;

    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("analysis")
        .arg("--table")
        .timeout(Duration::from_secs(10));

    let output = cmd.output().expect("failed to spawn vct binary");
    assert!(
        output.status.success() || output.status.code().is_none(),
        "vct analysis --table failed: stderr={}",
        String::from_utf8_lossy(&output.stderr)
    );
}

#[test]
fn test_usage_command_json() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("usage").arg("--json");

    let output = cmd.output().expect("failed to spawn vct binary");
    assert!(
        output.status.success(),
        "vct usage --json failed: stderr={}",
        String::from_utf8_lossy(&output.stderr)
    );

    let stdout = String::from_utf8_lossy(&output.stdout);
    let json: serde_json::Value =
        serde_json::from_str(&stdout).expect("--json output should be valid JSON");
    assert!(json.is_array(), "--json output should be a JSON array");
}

#[test]
fn test_usage_command_text() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("usage").arg("--text");

    // Should succeed
    cmd.assert().success();
}

#[test]
fn test_usage_command_table() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("usage").arg("--table");

    // Should succeed
    cmd.assert().success();
}

#[test]
fn test_usage_command_with_output_file() {
    use std::time::Duration;

    let temp_dir = TempDir::new().unwrap();
    let output_file = temp_dir.path().join("usage_output.json");

    // usage has no single-file --path mode, so it scans real session
    // directories; guard with a timeout like the analysis batch test.
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("usage")
        .arg("--output")
        .arg(output_file.to_str().unwrap())
        .timeout(Duration::from_secs(10));

    let output = cmd.output();

    if let Ok(output) = output
        && output.status.success()
        && output_file.exists()
    {
        let content = std::fs::read_to_string(&output_file).unwrap();
        let json: serde_json::Value = serde_json::from_str(&content).unwrap();
        assert!(json.is_array(), "Usage output should be JSON array");
    }
}

#[test]
fn test_all_short_flag_parses() {
    use std::time::Duration;

    // `-a` is the short alias for `--all` on both subcommands. A parse error
    // would exit fast with a non-success code; a slow scan may hit the timeout
    // (code().is_none()), which we tolerate like the other batch tests.
    for subcommand in ["usage", "analysis"] {
        let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
        cmd.arg(subcommand)
            .arg("-a")
            .arg("--json")
            .timeout(Duration::from_secs(10));

        let output = cmd.output().expect("failed to spawn vct binary");
        assert!(
            output.status.success() || output.status.code().is_none(),
            "vct {} -a --json failed: stderr={}",
            subcommand,
            String::from_utf8_lossy(&output.stderr)
        );
    }
}

#[test]
fn test_help_command() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("--help");

    cmd.assert()
        .success()
        .stdout(predicate::str::contains("Usage"))
        .stdout(predicate::str::contains("Commands"));
}

#[test]
fn test_analysis_help() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("analysis").arg("--help");

    cmd.assert()
        .success()
        .stdout(predicate::str::contains("analysis"))
        .stdout(predicate::str::contains("--path"));
}

#[test]
fn test_usage_help() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("usage").arg("--help");

    cmd.assert()
        .success()
        .stdout(predicate::str::contains("usage"))
        .stdout(predicate::str::contains("--json"))
        .stdout(predicate::str::contains("--output"));
}

#[test]
fn test_version_help() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("version").arg("--help");

    cmd.assert()
        .success()
        .stdout(predicate::str::contains("version"));
}

#[test]
fn test_invalid_command() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("invalid_command");

    cmd.assert()
        .failure()
        .stderr(predicate::str::contains("error").or(predicate::str::contains("unrecognized")));
}

#[test]
fn test_usage_multiple_output_formats() {
    // --json/--text/--table belong to a single clap group and must be
    // mutually exclusive.
    for combo in [
        ["--json", "--text"],
        ["--json", "--table"],
        ["--text", "--table"],
    ] {
        let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
        cmd.arg("usage").args(combo);
        cmd.assert()
            .failure()
            .stderr(predicate::str::contains("cannot be used with"));
    }
}

#[test]
fn test_analysis_multiple_output_formats() {
    for combo in [
        ["--json", "--text"],
        ["--json", "--table"],
        ["--text", "--table"],
    ] {
        let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
        cmd.arg("analysis").args(combo);
        cmd.assert()
            .failure()
            .stderr(predicate::str::contains("cannot be used with"));
    }
}

#[test]
fn test_cli_with_env_vars() {
    // Test that environment variables are respected if defined
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.env("RUST_LOG", "debug");
    cmd.arg("version");

    cmd.assert().success();
}

#[test]
fn test_analysis_output_directory_creation() {
    let temp_dir = TempDir::new().unwrap();
    // Create parent directory first
    let nested_dir = temp_dir.path().join("nested").join("dir");
    std::fs::create_dir_all(&nested_dir).unwrap();
    let nested_output = nested_dir.join("output.json");

    let example_file = PathBuf::from("examples/test_conversation_claude_code.jsonl");

    if !example_file.exists() {
        eprintln!("Skipping test: example file not found");
        return;
    }

    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("analysis")
        .arg("--path")
        .arg(example_file.to_str().unwrap())
        .arg("--output")
        .arg(nested_output.to_str().unwrap());

    cmd.assert().success();

    // Verify output file was created
    assert!(nested_output.exists(), "Output file should be created");
}

#[test]
fn test_update_check_command() {
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("update").arg("--check");

    // Should succeed (network errors are handled gracefully)
    let output = cmd.output().unwrap();
    assert!(
        output.status.success() || output.status.code().is_some(),
        "Update check should complete"
    );
}

#[test]
fn test_cli_version_matches_cargo() {
    // Verify that CLI version output is valid JSON
    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("version").arg("--json");

    let output = cmd.output().unwrap();
    if output.status.success() {
        let stdout = String::from_utf8_lossy(&output.stdout);
        let json: serde_json::Value = serde_json::from_str(&stdout).unwrap();

        // Check for Version field (note: capital V)
        assert!(json["Version"].is_string(), "Should have Version field");
    }
}

#[test]
fn test_analysis_validates_file_extension() {
    let temp_dir = TempDir::new().unwrap();
    let wrong_ext = temp_dir.path().join("test.txt");
    std::fs::write(&wrong_ext, "test content").unwrap();

    let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
    cmd.arg("analysis")
        .arg("--path")
        .arg(wrong_ext.to_str().unwrap());

    // Behavior depends on implementation - may succeed or fail
    let _ = cmd.output();
}

#[test]
fn test_cli_handles_unicode_paths() {
    let temp_dir = TempDir::new().unwrap();
    let unicode_path = temp_dir.path().join("測試_test_файл.json");

    let example_file = PathBuf::from("examples/test_conversation_claude_code.jsonl");
    if example_file.exists() {
        std::fs::copy(&example_file, &unicode_path).ok();

        let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
        cmd.arg("analysis")
            .arg("--path")
            .arg(unicode_path.to_str().unwrap());

        // Should handle Unicode paths
        let _ = cmd.output();
    }
}

#[test]
fn test_cli_handles_spaces_in_paths() {
    let temp_dir = TempDir::new().unwrap();
    let space_path = temp_dir.path().join("file with spaces.jsonl");

    let example_file = PathBuf::from("examples/test_conversation_claude_code.jsonl");
    if example_file.exists() {
        std::fs::copy(&example_file, &space_path).ok();

        let mut cmd = Command::cargo_bin("vibe_coding_tracker").unwrap();
        cmd.arg("analysis")
            .arg("--path")
            .arg(space_path.to_str().unwrap());

        cmd.assert().success();
    }
}