@hasna/terminal 2.3.0 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/dist/App.js +404 -0
  2. package/dist/Browse.js +79 -0
  3. package/dist/FuzzyPicker.js +47 -0
  4. package/dist/Onboarding.js +51 -0
  5. package/dist/Spinner.js +12 -0
  6. package/dist/StatusBar.js +49 -0
  7. package/dist/ai.js +322 -0
  8. package/dist/cache.js +41 -0
  9. package/dist/cli.js +64 -16
  10. package/dist/command-rewriter.js +64 -0
  11. package/dist/command-validator.js +86 -0
  12. package/dist/compression.js +107 -0
  13. package/dist/context-hints.js +275 -0
  14. package/dist/diff-cache.js +107 -0
  15. package/dist/discover.js +212 -0
  16. package/dist/economy.js +123 -0
  17. package/dist/expand-store.js +38 -0
  18. package/dist/file-cache.js +72 -0
  19. package/dist/file-index.js +62 -0
  20. package/dist/history.js +62 -0
  21. package/dist/lazy-executor.js +54 -0
  22. package/dist/line-dedup.js +59 -0
  23. package/dist/loop-detector.js +75 -0
  24. package/dist/mcp/install.js +98 -0
  25. package/dist/mcp/server.js +569 -0
  26. package/dist/noise-filter.js +86 -0
  27. package/dist/output-processor.js +129 -0
  28. package/dist/output-router.js +41 -0
  29. package/dist/output-store.js +111 -0
  30. package/dist/parsers/base.js +2 -0
  31. package/dist/parsers/build.js +64 -0
  32. package/dist/parsers/errors.js +101 -0
  33. package/dist/parsers/files.js +78 -0
  34. package/dist/parsers/git.js +99 -0
  35. package/dist/parsers/index.js +48 -0
  36. package/dist/parsers/tests.js +89 -0
  37. package/dist/providers/anthropic.js +39 -0
  38. package/dist/providers/base.js +4 -0
  39. package/dist/providers/cerebras.js +95 -0
  40. package/dist/providers/groq.js +95 -0
  41. package/dist/providers/index.js +73 -0
  42. package/dist/providers/xai.js +95 -0
  43. package/dist/recipes/model.js +20 -0
  44. package/dist/recipes/storage.js +136 -0
  45. package/dist/search/content-search.js +68 -0
  46. package/dist/search/file-search.js +61 -0
  47. package/dist/search/filters.js +34 -0
  48. package/dist/search/index.js +5 -0
  49. package/dist/search/semantic.js +320 -0
  50. package/dist/session-boot.js +59 -0
  51. package/dist/session-context.js +55 -0
  52. package/dist/sessions-db.js +173 -0
  53. package/dist/smart-display.js +286 -0
  54. package/dist/snapshots.js +51 -0
  55. package/dist/supervisor.js +112 -0
  56. package/dist/test-watchlist.js +131 -0
  57. package/dist/tool-profiles.js +122 -0
  58. package/dist/tree.js +94 -0
  59. package/dist/usage-cache.js +65 -0
  60. package/package.json +8 -1
  61. package/src/ai.ts +8 -0
  62. package/src/cli.tsx +57 -18
  63. package/src/output-processor.ts +6 -1
  64. package/src/output-store.ts +58 -12
  65. package/src/tool-profiles.ts +139 -0
  66. package/.claude/scheduled_tasks.lock +0 -1
  67. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -20
  68. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -14
  69. package/CONTRIBUTING.md +0 -80
  70. package/benchmarks/benchmark.mjs +0 -115
  71. package/imported_modules.txt +0 -0
  72. package/temp/rtk/.claude/agents/code-reviewer.md +0 -221
  73. package/temp/rtk/.claude/agents/debugger.md +0 -519
  74. package/temp/rtk/.claude/agents/rtk-testing-specialist.md +0 -461
  75. package/temp/rtk/.claude/agents/rust-rtk.md +0 -511
  76. package/temp/rtk/.claude/agents/technical-writer.md +0 -355
  77. package/temp/rtk/.claude/commands/diagnose.md +0 -352
  78. package/temp/rtk/.claude/commands/test-routing.md +0 -362
  79. package/temp/rtk/.claude/hooks/bash/pre-commit-format.sh +0 -16
  80. package/temp/rtk/.claude/hooks/rtk-rewrite.sh +0 -70
  81. package/temp/rtk/.claude/hooks/rtk-suggest.sh +0 -152
  82. package/temp/rtk/.claude/rules/cli-testing.md +0 -526
  83. package/temp/rtk/.claude/skills/issue-triage/SKILL.md +0 -348
  84. package/temp/rtk/.claude/skills/issue-triage/templates/issue-comment.md +0 -134
  85. package/temp/rtk/.claude/skills/performance.md +0 -435
  86. package/temp/rtk/.claude/skills/pr-triage/SKILL.md +0 -315
  87. package/temp/rtk/.claude/skills/pr-triage/templates/review-comment.md +0 -71
  88. package/temp/rtk/.claude/skills/repo-recap.md +0 -206
  89. package/temp/rtk/.claude/skills/rtk-tdd/SKILL.md +0 -78
  90. package/temp/rtk/.claude/skills/rtk-tdd/references/testing-patterns.md +0 -124
  91. package/temp/rtk/.claude/skills/security-guardian.md +0 -503
  92. package/temp/rtk/.claude/skills/ship.md +0 -404
  93. package/temp/rtk/.github/workflows/benchmark.yml +0 -34
  94. package/temp/rtk/.github/workflows/dco-check.yaml +0 -12
  95. package/temp/rtk/.github/workflows/release-please.yml +0 -51
  96. package/temp/rtk/.github/workflows/release.yml +0 -343
  97. package/temp/rtk/.github/workflows/security-check.yml +0 -135
  98. package/temp/rtk/.github/workflows/validate-docs.yml +0 -78
  99. package/temp/rtk/.release-please-manifest.json +0 -3
  100. package/temp/rtk/ARCHITECTURE.md +0 -1491
  101. package/temp/rtk/CHANGELOG.md +0 -640
  102. package/temp/rtk/CLAUDE.md +0 -605
  103. package/temp/rtk/CONTRIBUTING.md +0 -199
  104. package/temp/rtk/Cargo.lock +0 -1668
  105. package/temp/rtk/Cargo.toml +0 -64
  106. package/temp/rtk/Formula/rtk.rb +0 -43
  107. package/temp/rtk/INSTALL.md +0 -390
  108. package/temp/rtk/LICENSE +0 -21
  109. package/temp/rtk/README.md +0 -386
  110. package/temp/rtk/README_es.md +0 -159
  111. package/temp/rtk/README_fr.md +0 -197
  112. package/temp/rtk/README_ja.md +0 -159
  113. package/temp/rtk/README_ko.md +0 -159
  114. package/temp/rtk/README_zh.md +0 -167
  115. package/temp/rtk/ROADMAP.md +0 -15
  116. package/temp/rtk/SECURITY.md +0 -217
  117. package/temp/rtk/TEST_EXEC_TIME.md +0 -102
  118. package/temp/rtk/build.rs +0 -57
  119. package/temp/rtk/docs/AUDIT_GUIDE.md +0 -432
  120. package/temp/rtk/docs/FEATURES.md +0 -1410
  121. package/temp/rtk/docs/TROUBLESHOOTING.md +0 -309
  122. package/temp/rtk/docs/filter-workflow.md +0 -102
  123. package/temp/rtk/docs/images/gain-dashboard.jpg +0 -0
  124. package/temp/rtk/docs/tracking.md +0 -583
  125. package/temp/rtk/hooks/opencode-rtk.ts +0 -39
  126. package/temp/rtk/hooks/rtk-awareness.md +0 -29
  127. package/temp/rtk/hooks/rtk-rewrite.sh +0 -61
  128. package/temp/rtk/hooks/test-rtk-rewrite.sh +0 -442
  129. package/temp/rtk/install.sh +0 -124
  130. package/temp/rtk/release-please-config.json +0 -10
  131. package/temp/rtk/scripts/benchmark.sh +0 -592
  132. package/temp/rtk/scripts/check-installation.sh +0 -162
  133. package/temp/rtk/scripts/install-local.sh +0 -37
  134. package/temp/rtk/scripts/rtk-economics.sh +0 -137
  135. package/temp/rtk/scripts/test-all.sh +0 -561
  136. package/temp/rtk/scripts/test-aristote.sh +0 -227
  137. package/temp/rtk/scripts/test-tracking.sh +0 -79
  138. package/temp/rtk/scripts/update-readme-metrics.sh +0 -32
  139. package/temp/rtk/scripts/validate-docs.sh +0 -73
  140. package/temp/rtk/src/aws_cmd.rs +0 -880
  141. package/temp/rtk/src/binlog.rs +0 -1645
  142. package/temp/rtk/src/cargo_cmd.rs +0 -1727
  143. package/temp/rtk/src/cc_economics.rs +0 -1157
  144. package/temp/rtk/src/ccusage.rs +0 -340
  145. package/temp/rtk/src/config.rs +0 -187
  146. package/temp/rtk/src/container.rs +0 -855
  147. package/temp/rtk/src/curl_cmd.rs +0 -134
  148. package/temp/rtk/src/deps.rs +0 -268
  149. package/temp/rtk/src/diff_cmd.rs +0 -367
  150. package/temp/rtk/src/discover/mod.rs +0 -274
  151. package/temp/rtk/src/discover/provider.rs +0 -388
  152. package/temp/rtk/src/discover/registry.rs +0 -2022
  153. package/temp/rtk/src/discover/report.rs +0 -202
  154. package/temp/rtk/src/discover/rules.rs +0 -667
  155. package/temp/rtk/src/display_helpers.rs +0 -402
  156. package/temp/rtk/src/dotnet_cmd.rs +0 -1771
  157. package/temp/rtk/src/dotnet_format_report.rs +0 -133
  158. package/temp/rtk/src/dotnet_trx.rs +0 -593
  159. package/temp/rtk/src/env_cmd.rs +0 -204
  160. package/temp/rtk/src/filter.rs +0 -462
  161. package/temp/rtk/src/filters/README.md +0 -52
  162. package/temp/rtk/src/filters/ansible-playbook.toml +0 -34
  163. package/temp/rtk/src/filters/basedpyright.toml +0 -47
  164. package/temp/rtk/src/filters/biome.toml +0 -45
  165. package/temp/rtk/src/filters/brew-install.toml +0 -37
  166. package/temp/rtk/src/filters/composer-install.toml +0 -40
  167. package/temp/rtk/src/filters/df.toml +0 -16
  168. package/temp/rtk/src/filters/dotnet-build.toml +0 -64
  169. package/temp/rtk/src/filters/du.toml +0 -16
  170. package/temp/rtk/src/filters/fail2ban-client.toml +0 -15
  171. package/temp/rtk/src/filters/gcc.toml +0 -49
  172. package/temp/rtk/src/filters/gcloud.toml +0 -22
  173. package/temp/rtk/src/filters/hadolint.toml +0 -24
  174. package/temp/rtk/src/filters/helm.toml +0 -29
  175. package/temp/rtk/src/filters/iptables.toml +0 -27
  176. package/temp/rtk/src/filters/jj.toml +0 -28
  177. package/temp/rtk/src/filters/jq.toml +0 -24
  178. package/temp/rtk/src/filters/make.toml +0 -41
  179. package/temp/rtk/src/filters/markdownlint.toml +0 -24
  180. package/temp/rtk/src/filters/mix-compile.toml +0 -27
  181. package/temp/rtk/src/filters/mix-format.toml +0 -15
  182. package/temp/rtk/src/filters/mvn-build.toml +0 -44
  183. package/temp/rtk/src/filters/oxlint.toml +0 -43
  184. package/temp/rtk/src/filters/ping.toml +0 -63
  185. package/temp/rtk/src/filters/pio-run.toml +0 -40
  186. package/temp/rtk/src/filters/poetry-install.toml +0 -50
  187. package/temp/rtk/src/filters/pre-commit.toml +0 -35
  188. package/temp/rtk/src/filters/ps.toml +0 -16
  189. package/temp/rtk/src/filters/quarto-render.toml +0 -41
  190. package/temp/rtk/src/filters/rsync.toml +0 -48
  191. package/temp/rtk/src/filters/shellcheck.toml +0 -27
  192. package/temp/rtk/src/filters/shopify-theme.toml +0 -29
  193. package/temp/rtk/src/filters/skopeo.toml +0 -45
  194. package/temp/rtk/src/filters/sops.toml +0 -16
  195. package/temp/rtk/src/filters/ssh.toml +0 -44
  196. package/temp/rtk/src/filters/stat.toml +0 -34
  197. package/temp/rtk/src/filters/swift-build.toml +0 -41
  198. package/temp/rtk/src/filters/systemctl-status.toml +0 -33
  199. package/temp/rtk/src/filters/terraform-plan.toml +0 -35
  200. package/temp/rtk/src/filters/tofu-fmt.toml +0 -16
  201. package/temp/rtk/src/filters/tofu-init.toml +0 -38
  202. package/temp/rtk/src/filters/tofu-plan.toml +0 -35
  203. package/temp/rtk/src/filters/tofu-validate.toml +0 -17
  204. package/temp/rtk/src/filters/trunk-build.toml +0 -39
  205. package/temp/rtk/src/filters/ty.toml +0 -50
  206. package/temp/rtk/src/filters/uv-sync.toml +0 -37
  207. package/temp/rtk/src/filters/xcodebuild.toml +0 -99
  208. package/temp/rtk/src/filters/yamllint.toml +0 -25
  209. package/temp/rtk/src/find_cmd.rs +0 -598
  210. package/temp/rtk/src/format_cmd.rs +0 -386
  211. package/temp/rtk/src/gain.rs +0 -723
  212. package/temp/rtk/src/gh_cmd.rs +0 -1651
  213. package/temp/rtk/src/git.rs +0 -2012
  214. package/temp/rtk/src/go_cmd.rs +0 -592
  215. package/temp/rtk/src/golangci_cmd.rs +0 -254
  216. package/temp/rtk/src/grep_cmd.rs +0 -288
  217. package/temp/rtk/src/gt_cmd.rs +0 -810
  218. package/temp/rtk/src/hook_audit_cmd.rs +0 -283
  219. package/temp/rtk/src/hook_check.rs +0 -171
  220. package/temp/rtk/src/init.rs +0 -1859
  221. package/temp/rtk/src/integrity.rs +0 -537
  222. package/temp/rtk/src/json_cmd.rs +0 -231
  223. package/temp/rtk/src/learn/detector.rs +0 -628
  224. package/temp/rtk/src/learn/mod.rs +0 -119
  225. package/temp/rtk/src/learn/report.rs +0 -184
  226. package/temp/rtk/src/lint_cmd.rs +0 -694
  227. package/temp/rtk/src/local_llm.rs +0 -316
  228. package/temp/rtk/src/log_cmd.rs +0 -248
  229. package/temp/rtk/src/ls.rs +0 -324
  230. package/temp/rtk/src/main.rs +0 -2482
  231. package/temp/rtk/src/mypy_cmd.rs +0 -389
  232. package/temp/rtk/src/next_cmd.rs +0 -241
  233. package/temp/rtk/src/npm_cmd.rs +0 -236
  234. package/temp/rtk/src/parser/README.md +0 -267
  235. package/temp/rtk/src/parser/error.rs +0 -46
  236. package/temp/rtk/src/parser/formatter.rs +0 -336
  237. package/temp/rtk/src/parser/mod.rs +0 -311
  238. package/temp/rtk/src/parser/types.rs +0 -119
  239. package/temp/rtk/src/pip_cmd.rs +0 -302
  240. package/temp/rtk/src/playwright_cmd.rs +0 -479
  241. package/temp/rtk/src/pnpm_cmd.rs +0 -573
  242. package/temp/rtk/src/prettier_cmd.rs +0 -221
  243. package/temp/rtk/src/prisma_cmd.rs +0 -482
  244. package/temp/rtk/src/psql_cmd.rs +0 -382
  245. package/temp/rtk/src/pytest_cmd.rs +0 -384
  246. package/temp/rtk/src/read.rs +0 -217
  247. package/temp/rtk/src/rewrite_cmd.rs +0 -50
  248. package/temp/rtk/src/ruff_cmd.rs +0 -402
  249. package/temp/rtk/src/runner.rs +0 -271
  250. package/temp/rtk/src/summary.rs +0 -297
  251. package/temp/rtk/src/tee.rs +0 -405
  252. package/temp/rtk/src/telemetry.rs +0 -248
  253. package/temp/rtk/src/toml_filter.rs +0 -1655
  254. package/temp/rtk/src/tracking.rs +0 -1416
  255. package/temp/rtk/src/tree.rs +0 -209
  256. package/temp/rtk/src/tsc_cmd.rs +0 -259
  257. package/temp/rtk/src/utils.rs +0 -432
  258. package/temp/rtk/src/verify_cmd.rs +0 -47
  259. package/temp/rtk/src/vitest_cmd.rs +0 -385
  260. package/temp/rtk/src/wc_cmd.rs +0 -401
  261. package/temp/rtk/src/wget_cmd.rs +0 -260
  262. package/temp/rtk/tests/fixtures/dotnet/build_failed.txt +0 -11
  263. package/temp/rtk/tests/fixtures/dotnet/format_changes.json +0 -31
  264. package/temp/rtk/tests/fixtures/dotnet/format_empty.json +0 -1
  265. package/temp/rtk/tests/fixtures/dotnet/format_success.json +0 -12
  266. package/temp/rtk/tests/fixtures/dotnet/test_failed.txt +0 -18
  267. package/tsconfig.json +0 -15
@@ -1,593 +0,0 @@
1
- use crate::binlog::{FailedTest, TestSummary};
2
- use chrono::{DateTime, FixedOffset};
3
- use quick_xml::events::{BytesStart, Event};
4
- use quick_xml::Reader;
5
- use std::path::{Path, PathBuf};
6
- use std::time::SystemTime;
7
-
8
- fn local_name(name: &[u8]) -> &[u8] {
9
- name.rsplit(|b| *b == b':').next().unwrap_or(name)
10
- }
11
-
12
- fn extract_attr_value(
13
- reader: &Reader<&[u8]>,
14
- start: &BytesStart<'_>,
15
- key: &[u8],
16
- ) -> Option<String> {
17
- for attr in start.attributes().flatten() {
18
- if local_name(attr.key.as_ref()) != key {
19
- continue;
20
- }
21
-
22
- if let Ok(value) = attr.decode_and_unescape_value(reader.decoder()) {
23
- return Some(value.into_owned());
24
- }
25
- }
26
-
27
- None
28
- }
29
-
30
- fn parse_usize_attr(reader: &Reader<&[u8]>, start: &BytesStart<'_>, key: &[u8]) -> usize {
31
- extract_attr_value(reader, start, key)
32
- .and_then(|v| v.parse::<usize>().ok())
33
- .unwrap_or(0)
34
- }
35
-
36
- fn parse_trx_duration(start: &str, finish: &str) -> Option<String> {
37
- let start_dt = DateTime::parse_from_rfc3339(start).ok()?;
38
- let finish_dt = DateTime::parse_from_rfc3339(finish).ok()?;
39
- format_duration_between(start_dt, finish_dt)
40
- }
41
-
42
- fn format_duration_between(
43
- start_dt: DateTime<FixedOffset>,
44
- finish_dt: DateTime<FixedOffset>,
45
- ) -> Option<String> {
46
- let diff = finish_dt.signed_duration_since(start_dt);
47
- let millis = diff.num_milliseconds();
48
- if millis <= 0 {
49
- return None;
50
- }
51
-
52
- if millis >= 1_000 {
53
- let seconds = millis as f64 / 1_000.0;
54
- return Some(format!("{seconds:.1} s"));
55
- }
56
-
57
- Some(format!("{millis} ms"))
58
- }
59
-
60
- fn parse_trx_time_bounds(content: &str) -> Option<(DateTime<FixedOffset>, DateTime<FixedOffset>)> {
61
- let mut reader = Reader::from_str(content);
62
- reader.config_mut().trim_text(true);
63
- let mut buf = Vec::new();
64
-
65
- loop {
66
- match reader.read_event_into(&mut buf) {
67
- Ok(Event::Start(e)) | Ok(Event::Empty(e)) => {
68
- if local_name(e.name().as_ref()) != b"Times" {
69
- buf.clear();
70
- continue;
71
- }
72
-
73
- let start = extract_attr_value(&reader, &e, b"start")?;
74
- let finish = extract_attr_value(&reader, &e, b"finish")?;
75
- let start_dt = DateTime::parse_from_rfc3339(&start).ok()?;
76
- let finish_dt = DateTime::parse_from_rfc3339(&finish).ok()?;
77
- return Some((start_dt, finish_dt));
78
- }
79
- Ok(Event::Eof) => break,
80
- Err(_) => return None,
81
- _ => {}
82
- }
83
-
84
- buf.clear();
85
- }
86
-
87
- None
88
- }
89
-
90
- /// Parse TRX (Visual Studio Test Results) file to extract test summary.
91
- /// Returns None if the file doesn't exist or isn't a valid TRX file.
92
- pub fn parse_trx_file(path: &Path) -> Option<TestSummary> {
93
- let content = std::fs::read_to_string(path).ok()?;
94
- parse_trx_content(&content)
95
- }
96
-
97
- pub fn parse_trx_file_since(path: &Path, since: SystemTime) -> Option<TestSummary> {
98
- let modified = std::fs::metadata(path).ok()?.modified().ok()?;
99
- if modified < since {
100
- return None;
101
- }
102
-
103
- parse_trx_file(path)
104
- }
105
-
106
- pub fn parse_trx_files_in_dir(dir: &Path) -> Option<TestSummary> {
107
- parse_trx_files_in_dir_since(dir, None)
108
- }
109
-
110
- pub fn parse_trx_files_in_dir_since(dir: &Path, since: Option<SystemTime>) -> Option<TestSummary> {
111
- if !dir.exists() || !dir.is_dir() {
112
- return None;
113
- }
114
-
115
- let mut summaries = Vec::new();
116
- let mut min_start: Option<DateTime<FixedOffset>> = None;
117
- let mut max_finish: Option<DateTime<FixedOffset>> = None;
118
- let entries = std::fs::read_dir(dir).ok()?;
119
- for entry in entries.flatten() {
120
- let path = entry.path();
121
- if path
122
- .extension()
123
- .is_none_or(|e| !e.eq_ignore_ascii_case("trx"))
124
- {
125
- continue;
126
- }
127
-
128
- if let Some(since) = since {
129
- let modified = match entry.metadata().ok().and_then(|m| m.modified().ok()) {
130
- Some(modified) => modified,
131
- None => continue,
132
- };
133
- if modified < since {
134
- continue;
135
- }
136
- }
137
-
138
- let content = match std::fs::read_to_string(&path) {
139
- Ok(content) => content,
140
- Err(_) => continue,
141
- };
142
-
143
- if let Some((start, finish)) = parse_trx_time_bounds(&content) {
144
- min_start = Some(min_start.map_or(start, |prev| prev.min(start)));
145
- max_finish = Some(max_finish.map_or(finish, |prev| prev.max(finish)));
146
- }
147
-
148
- if let Some(summary) = parse_trx_content(&content) {
149
- summaries.push(summary);
150
- }
151
- }
152
-
153
- if summaries.is_empty() {
154
- return None;
155
- }
156
-
157
- let mut merged = TestSummary::default();
158
- for summary in summaries {
159
- merged.passed += summary.passed;
160
- merged.failed += summary.failed;
161
- merged.skipped += summary.skipped;
162
- merged.total += summary.total;
163
- merged.failed_tests.extend(summary.failed_tests);
164
- merged.project_count += summary.project_count.max(1);
165
- if merged.duration_text.is_none() {
166
- merged.duration_text = summary.duration_text;
167
- }
168
- }
169
-
170
- if let (Some(start), Some(finish)) = (min_start, max_finish) {
171
- merged.duration_text = format_duration_between(start, finish);
172
- }
173
-
174
- Some(merged)
175
- }
176
-
177
- pub fn find_recent_trx_in_testresults() -> Option<PathBuf> {
178
- find_recent_trx_in_dir(Path::new("./TestResults"))
179
- }
180
-
181
- fn find_recent_trx_in_dir(dir: &Path) -> Option<PathBuf> {
182
- if !dir.exists() {
183
- return None;
184
- }
185
-
186
- std::fs::read_dir(dir)
187
- .ok()?
188
- .filter_map(|entry| entry.ok())
189
- .filter_map(|entry| {
190
- let path = entry.path();
191
- let is_trx = path
192
- .extension()
193
- .is_some_and(|ext| ext.eq_ignore_ascii_case("trx"));
194
- if !is_trx {
195
- return None;
196
- }
197
-
198
- let modified = entry.metadata().ok()?.modified().ok()?;
199
- Some((modified, path))
200
- })
201
- .max_by_key(|(modified, _)| *modified)
202
- .map(|(_, path)| path)
203
- }
204
-
205
- fn parse_trx_content(content: &str) -> Option<TestSummary> {
206
- #[derive(Clone, Copy)]
207
- enum CaptureField {
208
- Message,
209
- StackTrace,
210
- }
211
-
212
- let mut reader = Reader::from_str(content);
213
- reader.config_mut().trim_text(true);
214
- let mut buf = Vec::new();
215
- let mut summary = TestSummary::default();
216
- let mut saw_test_run = false;
217
- let mut in_failed_result = false;
218
- let mut in_error_info = false;
219
- let mut failed_test_name = String::new();
220
- let mut message_buf = String::new();
221
- let mut stack_buf = String::new();
222
- let mut capture_field: Option<CaptureField> = None;
223
-
224
- loop {
225
- match reader.read_event_into(&mut buf) {
226
- Ok(Event::Start(e)) => match local_name(e.name().as_ref()) {
227
- b"TestRun" => saw_test_run = true,
228
- b"Times" => {
229
- let start = extract_attr_value(&reader, &e, b"start");
230
- let finish = extract_attr_value(&reader, &e, b"finish");
231
- if let (Some(start), Some(finish)) = (start, finish) {
232
- summary.duration_text = parse_trx_duration(&start, &finish);
233
- }
234
- }
235
- b"Counters" => {
236
- summary.total = parse_usize_attr(&reader, &e, b"total");
237
- summary.passed = parse_usize_attr(&reader, &e, b"passed");
238
- summary.failed = parse_usize_attr(&reader, &e, b"failed");
239
- }
240
- b"UnitTestResult" => {
241
- let outcome = extract_attr_value(&reader, &e, b"outcome")
242
- .unwrap_or_else(|| "Unknown".to_string());
243
-
244
- if outcome == "Failed" {
245
- in_failed_result = true;
246
- in_error_info = false;
247
- capture_field = None;
248
- message_buf.clear();
249
- stack_buf.clear();
250
- failed_test_name = extract_attr_value(&reader, &e, b"testName")
251
- .unwrap_or_else(|| "unknown".to_string());
252
- }
253
- }
254
- b"ErrorInfo" => {
255
- if in_failed_result {
256
- in_error_info = true;
257
- }
258
- }
259
- b"Message" => {
260
- if in_failed_result && in_error_info {
261
- capture_field = Some(CaptureField::Message);
262
- message_buf.clear();
263
- }
264
- }
265
- b"StackTrace" => {
266
- if in_failed_result && in_error_info {
267
- capture_field = Some(CaptureField::StackTrace);
268
- stack_buf.clear();
269
- }
270
- }
271
- _ => {}
272
- },
273
- Ok(Event::Empty(e)) => match local_name(e.name().as_ref()) {
274
- b"Times" => {
275
- let start = extract_attr_value(&reader, &e, b"start");
276
- let finish = extract_attr_value(&reader, &e, b"finish");
277
- if let (Some(start), Some(finish)) = (start, finish) {
278
- summary.duration_text = parse_trx_duration(&start, &finish);
279
- }
280
- }
281
- b"Counters" => {
282
- summary.total = parse_usize_attr(&reader, &e, b"total");
283
- summary.passed = parse_usize_attr(&reader, &e, b"passed");
284
- summary.failed = parse_usize_attr(&reader, &e, b"failed");
285
- }
286
- b"UnitTestResult" => {
287
- let outcome = extract_attr_value(&reader, &e, b"outcome")
288
- .unwrap_or_else(|| "Unknown".to_string());
289
- if outcome == "Failed" {
290
- let name = extract_attr_value(&reader, &e, b"testName")
291
- .unwrap_or_else(|| "unknown".to_string());
292
- summary.failed_tests.push(FailedTest {
293
- name,
294
- details: Vec::new(),
295
- });
296
- }
297
- }
298
- _ => {}
299
- },
300
- Ok(Event::Text(e)) => {
301
- if !in_failed_result {
302
- buf.clear();
303
- continue;
304
- }
305
-
306
- let text = String::from_utf8_lossy(e.as_ref());
307
- match capture_field {
308
- Some(CaptureField::Message) => message_buf.push_str(&text),
309
- Some(CaptureField::StackTrace) => stack_buf.push_str(&text),
310
- None => {}
311
- }
312
- }
313
- Ok(Event::CData(e)) => {
314
- if !in_failed_result {
315
- buf.clear();
316
- continue;
317
- }
318
-
319
- let text = String::from_utf8_lossy(e.as_ref());
320
- match capture_field {
321
- Some(CaptureField::Message) => message_buf.push_str(&text),
322
- Some(CaptureField::StackTrace) => stack_buf.push_str(&text),
323
- None => {}
324
- }
325
- }
326
- Ok(Event::End(e)) => match local_name(e.name().as_ref()) {
327
- b"Message" | b"StackTrace" => {
328
- capture_field = None;
329
- }
330
- b"ErrorInfo" => {
331
- in_error_info = false;
332
- }
333
- b"UnitTestResult" => {
334
- if in_failed_result {
335
- let mut details = Vec::new();
336
-
337
- let message = message_buf.trim();
338
- if !message.is_empty() {
339
- details.push(message.to_string());
340
- }
341
-
342
- let stack = stack_buf.trim();
343
- if !stack.is_empty() {
344
- let stack_lines: Vec<&str> = stack.lines().take(3).collect();
345
- if !stack_lines.is_empty() {
346
- details.push(stack_lines.join("\n"));
347
- }
348
- }
349
-
350
- summary.failed_tests.push(FailedTest {
351
- name: failed_test_name.clone(),
352
- details,
353
- });
354
-
355
- in_failed_result = false;
356
- in_error_info = false;
357
- capture_field = None;
358
- message_buf.clear();
359
- stack_buf.clear();
360
- }
361
- }
362
- _ => {}
363
- },
364
- Ok(Event::Eof) => break,
365
- Err(_) => return None,
366
- _ => {}
367
- }
368
-
369
- buf.clear();
370
- }
371
-
372
- if !saw_test_run {
373
- return None;
374
- }
375
-
376
- // Calculate skipped from counters if available
377
- if summary.total > 0 {
378
- summary.skipped = summary
379
- .total
380
- .saturating_sub(summary.passed + summary.failed);
381
- }
382
-
383
- // Set project count to at least 1 if there were any tests
384
- if summary.total > 0 {
385
- summary.project_count = 1;
386
- }
387
-
388
- Some(summary)
389
- }
390
-
391
- #[cfg(test)]
392
- mod tests {
393
- use super::*;
394
- use std::time::Duration;
395
-
396
- #[test]
397
- fn test_parse_trx_content_extracts_passed_counts() {
398
- let trx = r#"<?xml version="1.0" encoding="utf-8"?>
399
- <TestRun xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
400
- <Times creation="2026-02-21T12:57:28.3323710+01:00" queuing="2026-02-21T12:57:28.3323710+01:00" start="2026-02-21T12:57:27.7149650+01:00" finish="2026-02-21T12:57:30.2214710+01:00" />
401
- <ResultSummary outcome="Completed">
402
- <Counters total="42" executed="42" passed="40" failed="2" error="0" timeout="0" aborted="0" inconclusive="0" />
403
- </ResultSummary>
404
- </TestRun>"#;
405
-
406
- let summary = parse_trx_content(trx).expect("valid TRX");
407
- assert_eq!(summary.total, 42);
408
- assert_eq!(summary.passed, 40);
409
- assert_eq!(summary.failed, 2);
410
- assert_eq!(summary.skipped, 0);
411
- assert_eq!(summary.duration_text.as_deref(), Some("2.5 s"));
412
- }
413
-
414
- #[test]
415
- fn test_parse_trx_content_extracts_failed_tests_with_details() {
416
- let trx = r#"<?xml version="1.0" encoding="utf-8"?>
417
- <TestRun>
418
- <Results>
419
- <UnitTestResult testName="MyTests.Calculator.Add_ShouldFail" outcome="Failed">
420
- <Output>
421
- <ErrorInfo>
422
- <Message>Expected: 5, Actual: 4</Message>
423
- <StackTrace>at MyTests.Calculator.Add_ShouldFail()\nat line 42</StackTrace>
424
- </ErrorInfo>
425
- </Output>
426
- </UnitTestResult>
427
- </Results>
428
- <ResultSummary><Counters total="1" executed="1" passed="0" failed="1" /></ResultSummary>
429
- </TestRun>"#;
430
-
431
- let summary = parse_trx_content(trx).expect("valid TRX");
432
- assert_eq!(summary.failed_tests.len(), 1);
433
- assert_eq!(
434
- summary.failed_tests[0].name,
435
- "MyTests.Calculator.Add_ShouldFail"
436
- );
437
- assert!(summary.failed_tests[0].details[0].contains("Expected: 5, Actual: 4"));
438
- }
439
-
440
- #[test]
441
- fn test_parse_trx_content_extracts_counters_when_attribute_order_varies() {
442
- let trx = r#"<?xml version="1.0" encoding="utf-8"?>
443
- <TestRun>
444
- <ResultSummary outcome="Completed">
445
- <Counters failed="3" passed="7" executed="10" total="10" />
446
- </ResultSummary>
447
- </TestRun>"#;
448
-
449
- let summary = parse_trx_content(trx).expect("valid TRX");
450
- assert_eq!(summary.total, 10);
451
- assert_eq!(summary.passed, 7);
452
- assert_eq!(summary.failed, 3);
453
- }
454
-
455
- #[test]
456
- fn test_parse_trx_content_extracts_failed_tests_when_attribute_order_varies() {
457
- let trx = r#"<?xml version="1.0" encoding="utf-8"?>
458
- <TestRun>
459
- <Results>
460
- <UnitTestResult outcome="Failed" testName="MyTests.Ordering.ShouldStillParse">
461
- <Output>
462
- <ErrorInfo>
463
- <Message>Boom</Message>
464
- <StackTrace>at MyTests.Ordering.ShouldStillParse()</StackTrace>
465
- </ErrorInfo>
466
- </Output>
467
- </UnitTestResult>
468
- </Results>
469
- <ResultSummary><Counters failed="1" passed="0" executed="1" total="1" /></ResultSummary>
470
- </TestRun>"#;
471
-
472
- let summary = parse_trx_content(trx).expect("valid TRX");
473
- assert_eq!(summary.failed, 1);
474
- assert_eq!(summary.failed_tests.len(), 1);
475
- assert_eq!(
476
- summary.failed_tests[0].name,
477
- "MyTests.Ordering.ShouldStillParse"
478
- );
479
- }
480
-
481
- #[test]
482
- fn test_parse_trx_content_returns_none_for_invalid_xml() {
483
- let not_trx = "This is not a TRX file";
484
- assert!(parse_trx_content(not_trx).is_none());
485
- }
486
-
487
- #[test]
488
- fn test_find_recent_trx_in_dir_returns_none_when_missing() {
489
- let temp_dir = tempfile::tempdir().expect("create temp dir");
490
- let missing_dir = temp_dir.path().join("TestResults");
491
-
492
- let found = find_recent_trx_in_dir(&missing_dir);
493
- assert!(found.is_none());
494
- }
495
-
496
- #[test]
497
- fn test_find_recent_trx_in_dir_picks_newest_trx() {
498
- let temp_dir = tempfile::tempdir().expect("create temp dir");
499
- let testresults_dir = temp_dir.path().join("TestResults");
500
- std::fs::create_dir_all(&testresults_dir).expect("create TestResults");
501
-
502
- let old_trx = testresults_dir.join("old.trx");
503
- let new_trx = testresults_dir.join("new.trx");
504
- std::fs::write(&old_trx, "old").expect("write old");
505
- std::thread::sleep(Duration::from_millis(5));
506
- std::fs::write(&new_trx, "new").expect("write new");
507
-
508
- let found = find_recent_trx_in_dir(&testresults_dir).expect("should find newest trx");
509
- assert_eq!(found, new_trx);
510
- }
511
-
512
- #[test]
513
- fn test_find_recent_trx_in_dir_ignores_non_trx_files() {
514
- let temp_dir = tempfile::tempdir().expect("create temp dir");
515
- let testresults_dir = temp_dir.path().join("TestResults");
516
- std::fs::create_dir_all(&testresults_dir).expect("create TestResults");
517
-
518
- let txt = testresults_dir.join("notes.txt");
519
- std::fs::write(&txt, "noop").expect("write txt");
520
-
521
- let found = find_recent_trx_in_dir(&testresults_dir);
522
- assert!(found.is_none());
523
- }
524
-
525
- #[test]
526
- fn test_parse_trx_files_in_dir_aggregates_counts_and_wall_clock_duration() {
527
- let temp_dir = tempfile::tempdir().expect("create temp dir");
528
- let trx_dir = temp_dir.path().join("TestResults");
529
- std::fs::create_dir_all(&trx_dir).expect("create TestResults");
530
-
531
- let trx_one = r#"<?xml version="1.0" encoding="utf-8"?>
532
- <TestRun>
533
- <Times start="2026-02-21T12:57:27.0000000+01:00" finish="2026-02-21T12:57:30.0000000+01:00" />
534
- <ResultSummary outcome="Completed">
535
- <Counters total="10" executed="10" passed="9" failed="1" />
536
- </ResultSummary>
537
- </TestRun>"#;
538
-
539
- let trx_two = r#"<?xml version="1.0" encoding="utf-8"?>
540
- <TestRun>
541
- <Times start="2026-02-21T12:57:28.0000000+01:00" finish="2026-02-21T12:57:29.0000000+01:00" />
542
- <ResultSummary outcome="Completed">
543
- <Counters total="20" executed="20" passed="20" failed="0" />
544
- </ResultSummary>
545
- </TestRun>"#;
546
-
547
- std::fs::write(trx_dir.join("a.trx"), trx_one).expect("write first trx");
548
- std::fs::write(trx_dir.join("b.trx"), trx_two).expect("write second trx");
549
-
550
- let summary = parse_trx_files_in_dir(&trx_dir).expect("merged summary");
551
- assert_eq!(summary.total, 30);
552
- assert_eq!(summary.passed, 29);
553
- assert_eq!(summary.failed, 1);
554
- assert_eq!(summary.duration_text.as_deref(), Some("3.0 s"));
555
- }
556
-
557
- #[test]
558
- fn test_parse_trx_files_in_dir_since_ignores_older_files() {
559
- let temp_dir = tempfile::tempdir().expect("create temp dir");
560
- let trx_dir = temp_dir.path().join("TestResults");
561
- std::fs::create_dir_all(&trx_dir).expect("create TestResults");
562
-
563
- let trx_old = r#"<?xml version="1.0" encoding="utf-8"?>
564
- <TestRun><ResultSummary><Counters total="2" executed="2" passed="2" failed="0" /></ResultSummary></TestRun>"#;
565
- std::fs::write(trx_dir.join("old.trx"), trx_old).expect("write old trx");
566
- std::thread::sleep(Duration::from_millis(5));
567
- let since = SystemTime::now();
568
- std::thread::sleep(Duration::from_millis(5));
569
-
570
- let trx_new = r#"<?xml version="1.0" encoding="utf-8"?>
571
- <TestRun><ResultSummary><Counters total="3" executed="3" passed="2" failed="1" /></ResultSummary></TestRun>"#;
572
- std::fs::write(trx_dir.join("new.trx"), trx_new).expect("write new trx");
573
-
574
- let summary = parse_trx_files_in_dir_since(&trx_dir, Some(since)).expect("merged summary");
575
- assert_eq!(summary.total, 3);
576
- assert_eq!(summary.failed, 1);
577
- }
578
-
579
- #[test]
580
- fn test_parse_trx_files_in_dir_since_handles_uppercase_extension() {
581
- let temp_dir = tempfile::tempdir().expect("create temp dir");
582
- let trx_dir = temp_dir.path().join("TestResults");
583
- std::fs::create_dir_all(&trx_dir).expect("create TestResults");
584
-
585
- let trx = r#"<?xml version="1.0" encoding="utf-8"?>
586
- <TestRun><ResultSummary><Counters total="3" executed="3" passed="2" failed="1" /></ResultSummary></TestRun>"#;
587
- std::fs::write(trx_dir.join("UPPER.TRX"), trx).expect("write trx");
588
-
589
- let summary = parse_trx_files_in_dir_since(&trx_dir, None).expect("summary");
590
- assert_eq!(summary.total, 3);
591
- assert_eq!(summary.failed, 1);
592
- }
593
- }