@hasna/terminal 2.2.0 → 2.3.0
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.
- package/dist/cli.js +29 -12
- package/package.json +1 -1
- package/src/ai.ts +50 -36
- package/src/cli.tsx +29 -12
- package/src/context-hints.ts +89 -0
- package/src/discover.ts +238 -0
- package/src/economy.ts +53 -0
- package/src/output-store.ts +65 -0
- package/src/providers/index.ts +4 -4
- package/src/sessions-db.ts +81 -0
- package/temp/rtk/.claude/agents/code-reviewer.md +221 -0
- package/temp/rtk/.claude/agents/debugger.md +519 -0
- package/temp/rtk/.claude/agents/rtk-testing-specialist.md +461 -0
- package/temp/rtk/.claude/agents/rust-rtk.md +511 -0
- package/temp/rtk/.claude/agents/technical-writer.md +355 -0
- package/temp/rtk/.claude/commands/diagnose.md +352 -0
- package/temp/rtk/.claude/commands/test-routing.md +362 -0
- package/temp/rtk/.claude/hooks/bash/pre-commit-format.sh +16 -0
- package/temp/rtk/.claude/hooks/rtk-rewrite.sh +70 -0
- package/temp/rtk/.claude/hooks/rtk-suggest.sh +152 -0
- package/temp/rtk/.claude/rules/cli-testing.md +526 -0
- package/temp/rtk/.claude/skills/issue-triage/SKILL.md +348 -0
- package/temp/rtk/.claude/skills/issue-triage/templates/issue-comment.md +134 -0
- package/temp/rtk/.claude/skills/performance.md +435 -0
- package/temp/rtk/.claude/skills/pr-triage/SKILL.md +315 -0
- package/temp/rtk/.claude/skills/pr-triage/templates/review-comment.md +71 -0
- package/temp/rtk/.claude/skills/repo-recap.md +206 -0
- package/temp/rtk/.claude/skills/rtk-tdd/SKILL.md +78 -0
- package/temp/rtk/.claude/skills/rtk-tdd/references/testing-patterns.md +124 -0
- package/temp/rtk/.claude/skills/security-guardian.md +503 -0
- package/temp/rtk/.claude/skills/ship.md +404 -0
- package/temp/rtk/.github/workflows/benchmark.yml +34 -0
- package/temp/rtk/.github/workflows/dco-check.yaml +12 -0
- package/temp/rtk/.github/workflows/release-please.yml +51 -0
- package/temp/rtk/.github/workflows/release.yml +343 -0
- package/temp/rtk/.github/workflows/security-check.yml +135 -0
- package/temp/rtk/.github/workflows/validate-docs.yml +78 -0
- package/temp/rtk/.release-please-manifest.json +3 -0
- package/temp/rtk/ARCHITECTURE.md +1491 -0
- package/temp/rtk/CHANGELOG.md +640 -0
- package/temp/rtk/CLAUDE.md +605 -0
- package/temp/rtk/CONTRIBUTING.md +199 -0
- package/temp/rtk/Cargo.lock +1668 -0
- package/temp/rtk/Cargo.toml +64 -0
- package/temp/rtk/Formula/rtk.rb +43 -0
- package/temp/rtk/INSTALL.md +390 -0
- package/temp/rtk/LICENSE +21 -0
- package/temp/rtk/README.md +386 -0
- package/temp/rtk/README_es.md +159 -0
- package/temp/rtk/README_fr.md +197 -0
- package/temp/rtk/README_ja.md +159 -0
- package/temp/rtk/README_ko.md +159 -0
- package/temp/rtk/README_zh.md +167 -0
- package/temp/rtk/ROADMAP.md +15 -0
- package/temp/rtk/SECURITY.md +217 -0
- package/temp/rtk/TEST_EXEC_TIME.md +102 -0
- package/temp/rtk/build.rs +57 -0
- package/temp/rtk/docs/AUDIT_GUIDE.md +432 -0
- package/temp/rtk/docs/FEATURES.md +1410 -0
- package/temp/rtk/docs/TROUBLESHOOTING.md +309 -0
- package/temp/rtk/docs/filter-workflow.md +102 -0
- package/temp/rtk/docs/images/gain-dashboard.jpg +0 -0
- package/temp/rtk/docs/tracking.md +583 -0
- package/temp/rtk/hooks/opencode-rtk.ts +39 -0
- package/temp/rtk/hooks/rtk-awareness.md +29 -0
- package/temp/rtk/hooks/rtk-rewrite.sh +61 -0
- package/temp/rtk/hooks/test-rtk-rewrite.sh +442 -0
- package/temp/rtk/install.sh +124 -0
- package/temp/rtk/release-please-config.json +10 -0
- package/temp/rtk/scripts/benchmark.sh +592 -0
- package/temp/rtk/scripts/check-installation.sh +162 -0
- package/temp/rtk/scripts/install-local.sh +37 -0
- package/temp/rtk/scripts/rtk-economics.sh +137 -0
- package/temp/rtk/scripts/test-all.sh +561 -0
- package/temp/rtk/scripts/test-aristote.sh +227 -0
- package/temp/rtk/scripts/test-tracking.sh +79 -0
- package/temp/rtk/scripts/update-readme-metrics.sh +32 -0
- package/temp/rtk/scripts/validate-docs.sh +73 -0
- package/temp/rtk/src/aws_cmd.rs +880 -0
- package/temp/rtk/src/binlog.rs +1645 -0
- package/temp/rtk/src/cargo_cmd.rs +1727 -0
- package/temp/rtk/src/cc_economics.rs +1157 -0
- package/temp/rtk/src/ccusage.rs +340 -0
- package/temp/rtk/src/config.rs +187 -0
- package/temp/rtk/src/container.rs +855 -0
- package/temp/rtk/src/curl_cmd.rs +134 -0
- package/temp/rtk/src/deps.rs +268 -0
- package/temp/rtk/src/diff_cmd.rs +367 -0
- package/temp/rtk/src/discover/mod.rs +274 -0
- package/temp/rtk/src/discover/provider.rs +388 -0
- package/temp/rtk/src/discover/registry.rs +2022 -0
- package/temp/rtk/src/discover/report.rs +202 -0
- package/temp/rtk/src/discover/rules.rs +667 -0
- package/temp/rtk/src/display_helpers.rs +402 -0
- package/temp/rtk/src/dotnet_cmd.rs +1771 -0
- package/temp/rtk/src/dotnet_format_report.rs +133 -0
- package/temp/rtk/src/dotnet_trx.rs +593 -0
- package/temp/rtk/src/env_cmd.rs +204 -0
- package/temp/rtk/src/filter.rs +462 -0
- package/temp/rtk/src/filters/README.md +52 -0
- package/temp/rtk/src/filters/ansible-playbook.toml +34 -0
- package/temp/rtk/src/filters/basedpyright.toml +47 -0
- package/temp/rtk/src/filters/biome.toml +45 -0
- package/temp/rtk/src/filters/brew-install.toml +37 -0
- package/temp/rtk/src/filters/composer-install.toml +40 -0
- package/temp/rtk/src/filters/df.toml +16 -0
- package/temp/rtk/src/filters/dotnet-build.toml +64 -0
- package/temp/rtk/src/filters/du.toml +16 -0
- package/temp/rtk/src/filters/fail2ban-client.toml +15 -0
- package/temp/rtk/src/filters/gcc.toml +49 -0
- package/temp/rtk/src/filters/gcloud.toml +22 -0
- package/temp/rtk/src/filters/hadolint.toml +24 -0
- package/temp/rtk/src/filters/helm.toml +29 -0
- package/temp/rtk/src/filters/iptables.toml +27 -0
- package/temp/rtk/src/filters/jj.toml +28 -0
- package/temp/rtk/src/filters/jq.toml +24 -0
- package/temp/rtk/src/filters/make.toml +41 -0
- package/temp/rtk/src/filters/markdownlint.toml +24 -0
- package/temp/rtk/src/filters/mix-compile.toml +27 -0
- package/temp/rtk/src/filters/mix-format.toml +15 -0
- package/temp/rtk/src/filters/mvn-build.toml +44 -0
- package/temp/rtk/src/filters/oxlint.toml +43 -0
- package/temp/rtk/src/filters/ping.toml +63 -0
- package/temp/rtk/src/filters/pio-run.toml +40 -0
- package/temp/rtk/src/filters/poetry-install.toml +50 -0
- package/temp/rtk/src/filters/pre-commit.toml +35 -0
- package/temp/rtk/src/filters/ps.toml +16 -0
- package/temp/rtk/src/filters/quarto-render.toml +41 -0
- package/temp/rtk/src/filters/rsync.toml +48 -0
- package/temp/rtk/src/filters/shellcheck.toml +27 -0
- package/temp/rtk/src/filters/shopify-theme.toml +29 -0
- package/temp/rtk/src/filters/skopeo.toml +45 -0
- package/temp/rtk/src/filters/sops.toml +16 -0
- package/temp/rtk/src/filters/ssh.toml +44 -0
- package/temp/rtk/src/filters/stat.toml +34 -0
- package/temp/rtk/src/filters/swift-build.toml +41 -0
- package/temp/rtk/src/filters/systemctl-status.toml +33 -0
- package/temp/rtk/src/filters/terraform-plan.toml +35 -0
- package/temp/rtk/src/filters/tofu-fmt.toml +16 -0
- package/temp/rtk/src/filters/tofu-init.toml +38 -0
- package/temp/rtk/src/filters/tofu-plan.toml +35 -0
- package/temp/rtk/src/filters/tofu-validate.toml +17 -0
- package/temp/rtk/src/filters/trunk-build.toml +39 -0
- package/temp/rtk/src/filters/ty.toml +50 -0
- package/temp/rtk/src/filters/uv-sync.toml +37 -0
- package/temp/rtk/src/filters/xcodebuild.toml +99 -0
- package/temp/rtk/src/filters/yamllint.toml +25 -0
- package/temp/rtk/src/find_cmd.rs +598 -0
- package/temp/rtk/src/format_cmd.rs +386 -0
- package/temp/rtk/src/gain.rs +723 -0
- package/temp/rtk/src/gh_cmd.rs +1651 -0
- package/temp/rtk/src/git.rs +2012 -0
- package/temp/rtk/src/go_cmd.rs +592 -0
- package/temp/rtk/src/golangci_cmd.rs +254 -0
- package/temp/rtk/src/grep_cmd.rs +288 -0
- package/temp/rtk/src/gt_cmd.rs +810 -0
- package/temp/rtk/src/hook_audit_cmd.rs +283 -0
- package/temp/rtk/src/hook_check.rs +171 -0
- package/temp/rtk/src/init.rs +1859 -0
- package/temp/rtk/src/integrity.rs +537 -0
- package/temp/rtk/src/json_cmd.rs +231 -0
- package/temp/rtk/src/learn/detector.rs +628 -0
- package/temp/rtk/src/learn/mod.rs +119 -0
- package/temp/rtk/src/learn/report.rs +184 -0
- package/temp/rtk/src/lint_cmd.rs +694 -0
- package/temp/rtk/src/local_llm.rs +316 -0
- package/temp/rtk/src/log_cmd.rs +248 -0
- package/temp/rtk/src/ls.rs +324 -0
- package/temp/rtk/src/main.rs +2482 -0
- package/temp/rtk/src/mypy_cmd.rs +389 -0
- package/temp/rtk/src/next_cmd.rs +241 -0
- package/temp/rtk/src/npm_cmd.rs +236 -0
- package/temp/rtk/src/parser/README.md +267 -0
- package/temp/rtk/src/parser/error.rs +46 -0
- package/temp/rtk/src/parser/formatter.rs +336 -0
- package/temp/rtk/src/parser/mod.rs +311 -0
- package/temp/rtk/src/parser/types.rs +119 -0
- package/temp/rtk/src/pip_cmd.rs +302 -0
- package/temp/rtk/src/playwright_cmd.rs +479 -0
- package/temp/rtk/src/pnpm_cmd.rs +573 -0
- package/temp/rtk/src/prettier_cmd.rs +221 -0
- package/temp/rtk/src/prisma_cmd.rs +482 -0
- package/temp/rtk/src/psql_cmd.rs +382 -0
- package/temp/rtk/src/pytest_cmd.rs +384 -0
- package/temp/rtk/src/read.rs +217 -0
- package/temp/rtk/src/rewrite_cmd.rs +50 -0
- package/temp/rtk/src/ruff_cmd.rs +402 -0
- package/temp/rtk/src/runner.rs +271 -0
- package/temp/rtk/src/summary.rs +297 -0
- package/temp/rtk/src/tee.rs +405 -0
- package/temp/rtk/src/telemetry.rs +248 -0
- package/temp/rtk/src/toml_filter.rs +1655 -0
- package/temp/rtk/src/tracking.rs +1416 -0
- package/temp/rtk/src/tree.rs +209 -0
- package/temp/rtk/src/tsc_cmd.rs +259 -0
- package/temp/rtk/src/utils.rs +432 -0
- package/temp/rtk/src/verify_cmd.rs +47 -0
- package/temp/rtk/src/vitest_cmd.rs +385 -0
- package/temp/rtk/src/wc_cmd.rs +401 -0
- package/temp/rtk/src/wget_cmd.rs +260 -0
- package/temp/rtk/tests/fixtures/dotnet/build_failed.txt +11 -0
- package/temp/rtk/tests/fixtures/dotnet/format_changes.json +31 -0
- package/temp/rtk/tests/fixtures/dotnet/format_empty.json +1 -0
- package/temp/rtk/tests/fixtures/dotnet/format_success.json +12 -0
- package/temp/rtk/tests/fixtures/dotnet/test_failed.txt +18 -0
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
use crate::tracking;
|
|
2
|
+
use crate::utils::truncate;
|
|
3
|
+
use anyhow::{Context, Result};
|
|
4
|
+
use serde::Deserialize;
|
|
5
|
+
use std::collections::HashMap;
|
|
6
|
+
use std::ffi::OsString;
|
|
7
|
+
use std::process::Command;
|
|
8
|
+
|
|
9
|
+
#[derive(Debug, Deserialize)]
|
|
10
|
+
#[allow(dead_code)]
|
|
11
|
+
struct GoTestEvent {
|
|
12
|
+
#[serde(rename = "Time")]
|
|
13
|
+
time: Option<String>,
|
|
14
|
+
#[serde(rename = "Action")]
|
|
15
|
+
action: String,
|
|
16
|
+
#[serde(rename = "Package")]
|
|
17
|
+
package: Option<String>,
|
|
18
|
+
#[serde(rename = "Test")]
|
|
19
|
+
test: Option<String>,
|
|
20
|
+
#[serde(rename = "Output")]
|
|
21
|
+
output: Option<String>,
|
|
22
|
+
#[serde(rename = "Elapsed")]
|
|
23
|
+
elapsed: Option<f64>,
|
|
24
|
+
#[serde(rename = "ImportPath")]
|
|
25
|
+
import_path: Option<String>,
|
|
26
|
+
#[serde(rename = "FailedBuild")]
|
|
27
|
+
failed_build: Option<String>,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#[derive(Debug, Default)]
|
|
31
|
+
struct PackageResult {
|
|
32
|
+
pass: usize,
|
|
33
|
+
fail: usize,
|
|
34
|
+
skip: usize,
|
|
35
|
+
build_failed: bool,
|
|
36
|
+
build_errors: Vec<String>,
|
|
37
|
+
failed_tests: Vec<(String, Vec<String>)>, // (test_name, output_lines)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
pub fn run_test(args: &[String], verbose: u8) -> Result<()> {
|
|
41
|
+
let timer = tracking::TimedExecution::start();
|
|
42
|
+
|
|
43
|
+
let mut cmd = Command::new("go");
|
|
44
|
+
cmd.arg("test");
|
|
45
|
+
|
|
46
|
+
// Force JSON output if not already specified
|
|
47
|
+
if !args.iter().any(|a| a == "-json") {
|
|
48
|
+
cmd.arg("-json");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for arg in args {
|
|
52
|
+
cmd.arg(arg);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if verbose > 0 {
|
|
56
|
+
eprintln!("Running: go test -json {}", args.join(" "));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let output = cmd
|
|
60
|
+
.output()
|
|
61
|
+
.context("Failed to run go test. Is Go installed?")?;
|
|
62
|
+
|
|
63
|
+
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
64
|
+
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
65
|
+
let raw = format!("{}\n{}", stdout, stderr);
|
|
66
|
+
|
|
67
|
+
let exit_code = output
|
|
68
|
+
.status
|
|
69
|
+
.code()
|
|
70
|
+
.unwrap_or(if output.status.success() { 0 } else { 1 });
|
|
71
|
+
let filtered = filter_go_test_json(&stdout);
|
|
72
|
+
|
|
73
|
+
if let Some(hint) = crate::tee::tee_and_hint(&raw, "go_test", exit_code) {
|
|
74
|
+
println!("{}\n{}", filtered, hint);
|
|
75
|
+
} else {
|
|
76
|
+
println!("{}", filtered);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Include stderr if present (build errors, etc.)
|
|
80
|
+
if !stderr.trim().is_empty() {
|
|
81
|
+
eprintln!("{}", stderr.trim());
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
timer.track(
|
|
85
|
+
&format!("go test {}", args.join(" ")),
|
|
86
|
+
&format!("rtk go test {}", args.join(" ")),
|
|
87
|
+
&raw,
|
|
88
|
+
&filtered,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
// Preserve exit code for CI/CD
|
|
92
|
+
if !output.status.success() {
|
|
93
|
+
std::process::exit(exit_code);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
Ok(())
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
pub fn run_build(args: &[String], verbose: u8) -> Result<()> {
|
|
100
|
+
let timer = tracking::TimedExecution::start();
|
|
101
|
+
|
|
102
|
+
let mut cmd = Command::new("go");
|
|
103
|
+
cmd.arg("build");
|
|
104
|
+
|
|
105
|
+
for arg in args {
|
|
106
|
+
cmd.arg(arg);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if verbose > 0 {
|
|
110
|
+
eprintln!("Running: go build {}", args.join(" "));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let output = cmd
|
|
114
|
+
.output()
|
|
115
|
+
.context("Failed to run go build. Is Go installed?")?;
|
|
116
|
+
|
|
117
|
+
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
118
|
+
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
119
|
+
let raw = format!("{}\n{}", stdout, stderr);
|
|
120
|
+
|
|
121
|
+
let exit_code = output
|
|
122
|
+
.status
|
|
123
|
+
.code()
|
|
124
|
+
.unwrap_or(if output.status.success() { 0 } else { 1 });
|
|
125
|
+
let filtered = filter_go_build(&raw);
|
|
126
|
+
|
|
127
|
+
if let Some(hint) = crate::tee::tee_and_hint(&raw, "go_build", exit_code) {
|
|
128
|
+
if !filtered.is_empty() {
|
|
129
|
+
println!("{}\n{}", filtered, hint);
|
|
130
|
+
} else {
|
|
131
|
+
println!("{}", hint);
|
|
132
|
+
}
|
|
133
|
+
} else if !filtered.is_empty() {
|
|
134
|
+
println!("{}", filtered);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
timer.track(
|
|
138
|
+
&format!("go build {}", args.join(" ")),
|
|
139
|
+
&format!("rtk go build {}", args.join(" ")),
|
|
140
|
+
&raw,
|
|
141
|
+
&filtered,
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
// Preserve exit code for CI/CD
|
|
145
|
+
if !output.status.success() {
|
|
146
|
+
std::process::exit(exit_code);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
Ok(())
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
pub fn run_vet(args: &[String], verbose: u8) -> Result<()> {
|
|
153
|
+
let timer = tracking::TimedExecution::start();
|
|
154
|
+
|
|
155
|
+
let mut cmd = Command::new("go");
|
|
156
|
+
cmd.arg("vet");
|
|
157
|
+
|
|
158
|
+
for arg in args {
|
|
159
|
+
cmd.arg(arg);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if verbose > 0 {
|
|
163
|
+
eprintln!("Running: go vet {}", args.join(" "));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
let output = cmd
|
|
167
|
+
.output()
|
|
168
|
+
.context("Failed to run go vet. Is Go installed?")?;
|
|
169
|
+
|
|
170
|
+
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
171
|
+
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
172
|
+
let raw = format!("{}\n{}", stdout, stderr);
|
|
173
|
+
|
|
174
|
+
let exit_code = output
|
|
175
|
+
.status
|
|
176
|
+
.code()
|
|
177
|
+
.unwrap_or(if output.status.success() { 0 } else { 1 });
|
|
178
|
+
let filtered = filter_go_vet(&raw);
|
|
179
|
+
|
|
180
|
+
if let Some(hint) = crate::tee::tee_and_hint(&raw, "go_vet", exit_code) {
|
|
181
|
+
if !filtered.is_empty() {
|
|
182
|
+
println!("{}\n{}", filtered, hint);
|
|
183
|
+
} else {
|
|
184
|
+
println!("{}", hint);
|
|
185
|
+
}
|
|
186
|
+
} else if !filtered.is_empty() {
|
|
187
|
+
println!("{}", filtered);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
timer.track(
|
|
191
|
+
&format!("go vet {}", args.join(" ")),
|
|
192
|
+
&format!("rtk go vet {}", args.join(" ")),
|
|
193
|
+
&raw,
|
|
194
|
+
&filtered,
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
// Preserve exit code for CI/CD
|
|
198
|
+
if !output.status.success() {
|
|
199
|
+
std::process::exit(exit_code);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
Ok(())
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
pub fn run_other(args: &[OsString], verbose: u8) -> Result<()> {
|
|
206
|
+
if args.is_empty() {
|
|
207
|
+
anyhow::bail!("go: no subcommand specified");
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
let timer = tracking::TimedExecution::start();
|
|
211
|
+
|
|
212
|
+
let subcommand = args[0].to_string_lossy();
|
|
213
|
+
let mut cmd = Command::new("go");
|
|
214
|
+
cmd.arg(&*subcommand);
|
|
215
|
+
|
|
216
|
+
for arg in &args[1..] {
|
|
217
|
+
cmd.arg(arg);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if verbose > 0 {
|
|
221
|
+
eprintln!("Running: go {} ...", subcommand);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
let output = cmd
|
|
225
|
+
.output()
|
|
226
|
+
.with_context(|| format!("Failed to run go {}", subcommand))?;
|
|
227
|
+
|
|
228
|
+
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
229
|
+
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
230
|
+
let raw = format!("{}\n{}", stdout, stderr);
|
|
231
|
+
|
|
232
|
+
print!("{}", stdout);
|
|
233
|
+
eprint!("{}", stderr);
|
|
234
|
+
|
|
235
|
+
timer.track(
|
|
236
|
+
&format!("go {}", subcommand),
|
|
237
|
+
&format!("rtk go {}", subcommand),
|
|
238
|
+
&raw,
|
|
239
|
+
&raw, // No filtering for unsupported commands
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
// Preserve exit code
|
|
243
|
+
if !output.status.success() {
|
|
244
|
+
std::process::exit(output.status.code().unwrap_or(1));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
Ok(())
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/// Parse go test -json output (NDJSON format)
|
|
251
|
+
fn filter_go_test_json(output: &str) -> String {
|
|
252
|
+
let mut packages: HashMap<String, PackageResult> = HashMap::new();
|
|
253
|
+
let mut current_test_output: HashMap<(String, String), Vec<String>> = HashMap::new(); // (package, test) -> outputs
|
|
254
|
+
let mut build_output: HashMap<String, Vec<String>> = HashMap::new(); // import_path -> error lines
|
|
255
|
+
|
|
256
|
+
for line in output.lines() {
|
|
257
|
+
let trimmed = line.trim();
|
|
258
|
+
if trimmed.is_empty() {
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
let event: GoTestEvent = match serde_json::from_str(trimmed) {
|
|
263
|
+
Ok(e) => e,
|
|
264
|
+
Err(_) => continue, // Skip non-JSON lines
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// Handle build-output/build-fail events (use ImportPath, no Package)
|
|
268
|
+
match event.action.as_str() {
|
|
269
|
+
"build-output" => {
|
|
270
|
+
if let (Some(import_path), Some(output_text)) = (&event.import_path, &event.output)
|
|
271
|
+
{
|
|
272
|
+
let text = output_text.trim_end().to_string();
|
|
273
|
+
if !text.is_empty() {
|
|
274
|
+
build_output
|
|
275
|
+
.entry(import_path.clone())
|
|
276
|
+
.or_default()
|
|
277
|
+
.push(text);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
"build-fail" => {
|
|
283
|
+
// build-fail has ImportPath — we'll handle it when the package-level fail arrives
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
_ => {}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
let package = event.package.unwrap_or_else(|| "unknown".to_string());
|
|
290
|
+
let pkg_result = packages.entry(package.clone()).or_default();
|
|
291
|
+
|
|
292
|
+
match event.action.as_str() {
|
|
293
|
+
"pass" => {
|
|
294
|
+
if event.test.is_some() {
|
|
295
|
+
pkg_result.pass += 1;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
"fail" => {
|
|
299
|
+
if let Some(test) = &event.test {
|
|
300
|
+
// Individual test failure
|
|
301
|
+
pkg_result.fail += 1;
|
|
302
|
+
|
|
303
|
+
// Collect output for failed test
|
|
304
|
+
let key = (package.clone(), test.clone());
|
|
305
|
+
let outputs = current_test_output.remove(&key).unwrap_or_default();
|
|
306
|
+
pkg_result.failed_tests.push((test.clone(), outputs));
|
|
307
|
+
} else if event.failed_build.is_some() {
|
|
308
|
+
// Package-level build failure
|
|
309
|
+
pkg_result.build_failed = true;
|
|
310
|
+
// Collect build errors from the import path
|
|
311
|
+
if let Some(import_path) = &event.failed_build {
|
|
312
|
+
if let Some(errors) = build_output.remove(import_path) {
|
|
313
|
+
pkg_result.build_errors = errors;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
"skip" => {
|
|
319
|
+
if event.test.is_some() {
|
|
320
|
+
pkg_result.skip += 1;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
"output" => {
|
|
324
|
+
// Collect output for current test
|
|
325
|
+
if let (Some(test), Some(output_text)) = (&event.test, &event.output) {
|
|
326
|
+
let key = (package.clone(), test.clone());
|
|
327
|
+
current_test_output
|
|
328
|
+
.entry(key)
|
|
329
|
+
.or_default()
|
|
330
|
+
.push(output_text.trim_end().to_string());
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
_ => {} // run, pause, cont, etc.
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Build summary
|
|
338
|
+
let total_packages = packages.len();
|
|
339
|
+
let total_pass: usize = packages.values().map(|p| p.pass).sum();
|
|
340
|
+
let total_fail: usize = packages.values().map(|p| p.fail).sum();
|
|
341
|
+
let total_skip: usize = packages.values().map(|p| p.skip).sum();
|
|
342
|
+
let total_build_fail: usize = packages.values().filter(|p| p.build_failed).count();
|
|
343
|
+
|
|
344
|
+
let has_failures = total_fail > 0 || total_build_fail > 0;
|
|
345
|
+
|
|
346
|
+
if !has_failures && total_pass == 0 {
|
|
347
|
+
return "Go test: No tests found".to_string();
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if !has_failures {
|
|
351
|
+
return format!(
|
|
352
|
+
"✓ Go test: {} passed in {} packages",
|
|
353
|
+
total_pass, total_packages
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
let mut result = String::new();
|
|
358
|
+
result.push_str(&format!(
|
|
359
|
+
"Go test: {} passed, {} failed",
|
|
360
|
+
total_pass,
|
|
361
|
+
total_fail + total_build_fail
|
|
362
|
+
));
|
|
363
|
+
if total_skip > 0 {
|
|
364
|
+
result.push_str(&format!(", {} skipped", total_skip));
|
|
365
|
+
}
|
|
366
|
+
result.push_str(&format!(" in {} packages\n", total_packages));
|
|
367
|
+
result.push_str("═══════════════════════════════════════\n");
|
|
368
|
+
|
|
369
|
+
// Show build failures first
|
|
370
|
+
for (package, pkg_result) in packages.iter() {
|
|
371
|
+
if !pkg_result.build_failed {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
result.push_str(&format!(
|
|
376
|
+
"\n📦 {} [build failed]\n",
|
|
377
|
+
compact_package_name(package)
|
|
378
|
+
));
|
|
379
|
+
|
|
380
|
+
for line in &pkg_result.build_errors {
|
|
381
|
+
let trimmed = line.trim();
|
|
382
|
+
// Skip the "# package" header line
|
|
383
|
+
if !trimmed.starts_with('#') && !trimmed.is_empty() {
|
|
384
|
+
result.push_str(&format!(" {}\n", truncate(trimmed, 120)));
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Show failed tests grouped by package
|
|
390
|
+
for (package, pkg_result) in packages.iter() {
|
|
391
|
+
if pkg_result.fail == 0 {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
result.push_str(&format!(
|
|
396
|
+
"\n📦 {} ({} passed, {} failed)\n",
|
|
397
|
+
compact_package_name(package),
|
|
398
|
+
pkg_result.pass,
|
|
399
|
+
pkg_result.fail
|
|
400
|
+
));
|
|
401
|
+
|
|
402
|
+
for (test, outputs) in &pkg_result.failed_tests {
|
|
403
|
+
result.push_str(&format!(" ❌ {}\n", test));
|
|
404
|
+
|
|
405
|
+
// Show failure output (limit to key lines)
|
|
406
|
+
let relevant_lines: Vec<&String> = outputs
|
|
407
|
+
.iter()
|
|
408
|
+
.filter(|line| {
|
|
409
|
+
let lower = line.to_lowercase();
|
|
410
|
+
!line.trim().is_empty()
|
|
411
|
+
&& !line.starts_with("=== RUN")
|
|
412
|
+
&& !line.starts_with("--- FAIL")
|
|
413
|
+
&& (lower.contains("error")
|
|
414
|
+
|| lower.contains("expected")
|
|
415
|
+
|| lower.contains("got")
|
|
416
|
+
|| lower.contains("panic")
|
|
417
|
+
|| line.trim().starts_with("at "))
|
|
418
|
+
})
|
|
419
|
+
.take(5)
|
|
420
|
+
.collect();
|
|
421
|
+
|
|
422
|
+
for line in relevant_lines {
|
|
423
|
+
result.push_str(&format!(" {}\n", truncate(line, 100)));
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
result.trim().to_string()
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/// Filter go build output - show only errors
|
|
432
|
+
fn filter_go_build(output: &str) -> String {
|
|
433
|
+
let mut errors: Vec<String> = Vec::new();
|
|
434
|
+
|
|
435
|
+
for line in output.lines() {
|
|
436
|
+
let trimmed = line.trim();
|
|
437
|
+
let lower = trimmed.to_lowercase();
|
|
438
|
+
|
|
439
|
+
// Skip package markers (# package/name lines without errors)
|
|
440
|
+
if trimmed.starts_with('#') && !lower.contains("error") {
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// Collect error lines (file:line:col format or error keywords)
|
|
445
|
+
if !trimmed.is_empty()
|
|
446
|
+
&& (lower.contains("error")
|
|
447
|
+
|| trimmed.contains(".go:")
|
|
448
|
+
|| lower.contains("undefined")
|
|
449
|
+
|| lower.contains("cannot"))
|
|
450
|
+
{
|
|
451
|
+
errors.push(trimmed.to_string());
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if errors.is_empty() {
|
|
456
|
+
return "✓ Go build: Success".to_string();
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
let mut result = String::new();
|
|
460
|
+
result.push_str(&format!("Go build: {} errors\n", errors.len()));
|
|
461
|
+
result.push_str("═══════════════════════════════════════\n");
|
|
462
|
+
|
|
463
|
+
for (i, error) in errors.iter().take(20).enumerate() {
|
|
464
|
+
result.push_str(&format!("{}. {}\n", i + 1, truncate(error, 120)));
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if errors.len() > 20 {
|
|
468
|
+
result.push_str(&format!("\n... +{} more errors\n", errors.len() - 20));
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
result.trim().to_string()
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/// Filter go vet output - show issues
|
|
475
|
+
fn filter_go_vet(output: &str) -> String {
|
|
476
|
+
let mut issues: Vec<String> = Vec::new();
|
|
477
|
+
|
|
478
|
+
for line in output.lines() {
|
|
479
|
+
let trimmed = line.trim();
|
|
480
|
+
|
|
481
|
+
// Collect issue lines (vet reports issues with file:line:col format)
|
|
482
|
+
if !trimmed.is_empty() && !trimmed.starts_with('#') && trimmed.contains(".go:") {
|
|
483
|
+
issues.push(trimmed.to_string());
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
if issues.is_empty() {
|
|
488
|
+
return "✓ Go vet: No issues found".to_string();
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
let mut result = String::new();
|
|
492
|
+
result.push_str(&format!("Go vet: {} issues\n", issues.len()));
|
|
493
|
+
result.push_str("═══════════════════════════════════════\n");
|
|
494
|
+
|
|
495
|
+
for (i, issue) in issues.iter().take(20).enumerate() {
|
|
496
|
+
result.push_str(&format!("{}. {}\n", i + 1, truncate(issue, 120)));
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if issues.len() > 20 {
|
|
500
|
+
result.push_str(&format!("\n... +{} more issues\n", issues.len() - 20));
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
result.trim().to_string()
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/// Compact package name (remove long paths)
|
|
507
|
+
fn compact_package_name(package: &str) -> String {
|
|
508
|
+
// Remove common module prefixes like github.com/user/repo/
|
|
509
|
+
if let Some(pos) = package.rfind('/') {
|
|
510
|
+
package[pos + 1..].to_string()
|
|
511
|
+
} else {
|
|
512
|
+
package.to_string()
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
#[cfg(test)]
|
|
517
|
+
mod tests {
|
|
518
|
+
use super::*;
|
|
519
|
+
|
|
520
|
+
#[test]
|
|
521
|
+
fn test_filter_go_test_all_pass() {
|
|
522
|
+
let output = r#"{"Time":"2024-01-01T10:00:00Z","Action":"run","Package":"example.com/foo","Test":"TestBar"}
|
|
523
|
+
{"Time":"2024-01-01T10:00:01Z","Action":"output","Package":"example.com/foo","Test":"TestBar","Output":"=== RUN TestBar\n"}
|
|
524
|
+
{"Time":"2024-01-01T10:00:02Z","Action":"pass","Package":"example.com/foo","Test":"TestBar","Elapsed":0.5}
|
|
525
|
+
{"Time":"2024-01-01T10:00:02Z","Action":"pass","Package":"example.com/foo","Elapsed":0.5}"#;
|
|
526
|
+
|
|
527
|
+
let result = filter_go_test_json(output);
|
|
528
|
+
assert!(result.contains("✓ Go test"));
|
|
529
|
+
assert!(result.contains("1 passed"));
|
|
530
|
+
assert!(result.contains("1 packages"));
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
#[test]
|
|
534
|
+
fn test_filter_go_test_with_failures() {
|
|
535
|
+
let output = r#"{"Time":"2024-01-01T10:00:00Z","Action":"run","Package":"example.com/foo","Test":"TestFail"}
|
|
536
|
+
{"Time":"2024-01-01T10:00:01Z","Action":"output","Package":"example.com/foo","Test":"TestFail","Output":"=== RUN TestFail\n"}
|
|
537
|
+
{"Time":"2024-01-01T10:00:02Z","Action":"output","Package":"example.com/foo","Test":"TestFail","Output":" Error: expected 5, got 3\n"}
|
|
538
|
+
{"Time":"2024-01-01T10:00:03Z","Action":"fail","Package":"example.com/foo","Test":"TestFail","Elapsed":0.5}
|
|
539
|
+
{"Time":"2024-01-01T10:00:03Z","Action":"fail","Package":"example.com/foo","Elapsed":0.5}"#;
|
|
540
|
+
|
|
541
|
+
let result = filter_go_test_json(output);
|
|
542
|
+
assert!(result.contains("1 failed"));
|
|
543
|
+
assert!(result.contains("TestFail"));
|
|
544
|
+
assert!(result.contains("expected 5, got 3"));
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
#[test]
|
|
548
|
+
fn test_filter_go_build_success() {
|
|
549
|
+
let output = "";
|
|
550
|
+
let result = filter_go_build(output);
|
|
551
|
+
assert!(result.contains("✓ Go build"));
|
|
552
|
+
assert!(result.contains("Success"));
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
#[test]
|
|
556
|
+
fn test_filter_go_build_errors() {
|
|
557
|
+
let output = r#"# example.com/foo
|
|
558
|
+
main.go:10:5: undefined: missingFunc
|
|
559
|
+
main.go:15:2: cannot use x (type int) as type string"#;
|
|
560
|
+
|
|
561
|
+
let result = filter_go_build(output);
|
|
562
|
+
assert!(result.contains("2 errors"));
|
|
563
|
+
assert!(result.contains("undefined: missingFunc"));
|
|
564
|
+
assert!(result.contains("cannot use x"));
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
#[test]
|
|
568
|
+
fn test_filter_go_vet_no_issues() {
|
|
569
|
+
let output = "";
|
|
570
|
+
let result = filter_go_vet(output);
|
|
571
|
+
assert!(result.contains("✓ Go vet"));
|
|
572
|
+
assert!(result.contains("No issues found"));
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
#[test]
|
|
576
|
+
fn test_filter_go_vet_with_issues() {
|
|
577
|
+
let output = r#"main.go:42:2: Printf format %d has arg x of wrong type string
|
|
578
|
+
utils.go:15:5: unreachable code"#;
|
|
579
|
+
|
|
580
|
+
let result = filter_go_vet(output);
|
|
581
|
+
assert!(result.contains("2 issues"));
|
|
582
|
+
assert!(result.contains("Printf format"));
|
|
583
|
+
assert!(result.contains("unreachable code"));
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
#[test]
|
|
587
|
+
fn test_compact_package_name() {
|
|
588
|
+
assert_eq!(compact_package_name("github.com/user/repo/pkg"), "pkg");
|
|
589
|
+
assert_eq!(compact_package_name("example.com/foo"), "foo");
|
|
590
|
+
assert_eq!(compact_package_name("simple"), "simple");
|
|
591
|
+
}
|
|
592
|
+
}
|