mirror of
https://github.com/rtk-ai/rtk.git
synced 2026-09-19 07:33:17 +08:00
test(hooks): scope Trae audit assertion to Unix as reviewed
This commit is contained in:
@@ -95,7 +95,6 @@ since the agent must type `rtk` itself. `rtk init` prints a note when it does th
|
||||
| `RTK_TEE_DIR` | Override the tee directory (tee mode) |
|
||||
| `RTK_TELEMETRY_DISABLED=1` | Disable telemetry |
|
||||
| `RTK_HOOK_AUDIT=1` | Enable hook audit logging |
|
||||
| `RTK_AUDIT_DIR` | Override the hook audit log directory for writing and reading logs |
|
||||
| `RTK_SUPPRESS_HOOK_WARNING=1` | Suppress the missing-hook warning only (not the outdated-hook upgrade prompt); `true`, `yes`, `on` also accepted |
|
||||
| `RTK_SUPPRESS_HOOK_WARNING=0` | Force the missing-hook warning back on, overriding `hooks.suppress_hook_warning`; `false`, `no`, `off` also accepted |
|
||||
| `SKIP_ENV_VALIDATION=1` | Skip env validation (useful with Next.js) |
|
||||
|
||||
@@ -526,10 +526,8 @@ fn sanitize_log_field(s: &str) -> String {
|
||||
}
|
||||
|
||||
fn audit_log_inner(action: &str, original: &str, rewritten: &str) -> Option<()> {
|
||||
let dir = match std::env::var("RTK_AUDIT_DIR") {
|
||||
Ok(dir) => std::path::PathBuf::from(dir),
|
||||
Err(_) => dirs::home_dir()?.join(".local").join("share").join("rtk"),
|
||||
};
|
||||
let home = dirs::home_dir()?;
|
||||
let dir = home.join(".local").join("share").join("rtk");
|
||||
crate::core::utils::create_private_dir(&dir).ok()?;
|
||||
let path = dir.join("hook-audit.log");
|
||||
let mut file = crate::core::utils::open_private(
|
||||
|
||||
@@ -20,7 +20,6 @@ fn run_trae_payload(payload: &str, home: &Path, audit: bool) -> Output {
|
||||
let mut child = Command::new(env!("CARGO_BIN_EXE_rtk"))
|
||||
.args(["hook", "trae"])
|
||||
.env("HOME", home)
|
||||
.env("RTK_AUDIT_DIR", home.join("audit"))
|
||||
.env("RTK_TELEMETRY_DISABLED", "1")
|
||||
.env("RTK_HOOK_AUDIT", if audit { "1" } else { "0" })
|
||||
.stdin(Stdio::piped())
|
||||
@@ -60,6 +59,8 @@ fn trae_hook_defers_unattestable_shell_constructs() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
// dirs::home_dir uses the Windows Known Folder API, so HOME cannot isolate this log.
|
||||
#[cfg(unix)]
|
||||
fn trae_hook_records_successful_rewrite_in_audit_log() {
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
let output = run_trae_hook("git status", home.path(), true);
|
||||
@@ -70,7 +71,7 @@ fn trae_hook_records_successful_rewrite_in_audit_log() {
|
||||
"expected a Trae rewrite response"
|
||||
);
|
||||
|
||||
let audit_path = home.path().join("audit/hook-audit.log");
|
||||
let audit_path = home.path().join(".local/share/rtk/hook-audit.log");
|
||||
let audit = std::fs::read_to_string(&audit_path)
|
||||
.unwrap_or_else(|error| panic!("missing audit log at {}: {error}", audit_path.display()));
|
||||
assert!(
|
||||
|
||||
Reference in New Issue
Block a user