Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,42 +1114,6 @@ pub(crate) mod tests {
);
}

#[test]
fn only_claude_hook_invocations_are_admitted_to_managed_hook_telemetry() {
const HOOK: Option<ManagedSpanKind> = Some(ManagedSpanKind::ClaudeHook);
const COMMAND: Option<ManagedSpanKind> = Some(ManagedSpanKind::Command);
let cases: [(&[&str], bool, Option<ManagedSpanKind>); 20] = [
(&["sce", "hooks", "claude-mutation-scope"], false, HOOK),
(&["sce", "hooks", "claude-model-state"], false, HOOK),
(&["sce", "hooks", "diff-trace"], true, HOOK),
(&["sce", "hooks", "diff-trace"], false, None),
(&["sce", "hooks", "conversation-trace"], true, HOOK),
(&["sce", "hooks", "conversation-trace"], false, None),
(&["sce", "policy", "bash"], true, HOOK),
(&["sce", "policy", "bash"], false, None),
(&["sce", "hooks", "pre-commit"], true, None),
(&["sce", "--verbose", "hooks", "codex"], true, None),
(&["sce", "hooks", "codex-mutation-scope"], true, None),
(&["sce", "hooks", "opencode-mutation-scope"], true, None),
(&["sce", "hooks", "pi-mutation-scope"], true, None),
(&["sce", "hooks"], true, None),
(&["sce", "auth", "telemetry-headers"], true, None),
(&["sce", "setup"], true, None),
(&["sce", "setup", "--claude"], true, None),
(&["sce", "auth", "login"], true, COMMAND),
(&["sce", "config", "show"], false, COMMAND),
(&["sce", "doctor"], true, COMMAND),
];
for (args, claude_caller, expected) in cases {
let args = args.iter().map(ToString::to_string).collect::<Vec<_>>();
assert_eq!(
managed_span_kind(&args, claude_caller),
expected,
"{args:?} claude_caller={claude_caller}"
);
}
}

#[tokio::test]
async fn disallowed_managed_telemetry_resolves_to_noop_without_credential_lookup() {
let telemetry =
Expand Down
188 changes: 0 additions & 188 deletions cli/src/app/doctor_reconciliation_cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ const STATE_FILE: &str = "ref-maintenance.json";
const LOCK_FILE: &str = "mutation-cursor.lock";
const RECONCILIATION_DETAIL_PREFIX: &str = "Snapshot ref reconciliation";

const AUTH_DB_TEST_SECRET: &str = "doctor-cli-test-secret";
const UNREADABLE_AUTH_DB: &[u8] = b"not an encrypted auth database";

const TELEMETRY_ENABLED_CONFIG: &str = r#"{"telemetry":{"enabled":true}}"#;
const TELEMETRY_OPT_IN_NOTE: &str = "Managed telemetry export is off because telemetry.enabled is not true; set telemetry.enabled: true in the global SCE config to resume it.";
const EXIT_SUCCESS: &str = "success";
const EXIT_FAILURE: &str = "failure";

Expand Down Expand Up @@ -143,12 +138,6 @@ impl Sandbox {
.expect("state JSON")
}

fn telemetry_enabled_config(&self) -> String {
let path = self.dir.path().join("telemetry-enabled.json");
std::fs::write(&path, TELEMETRY_ENABLED_CONFIG).expect("telemetry config");
path.to_string_lossy().into_owned()
}

fn run(&self, args: &[&str]) -> CliRun {
self.run_with_env(args, &[])
}
Expand Down Expand Up @@ -612,180 +601,3 @@ async fn doctor_fix_recovers_from_every_initial_maintenance_state_condition() {
);
}
}

fn global_state_warnings(report: &Value) -> Vec<Value> {
report["problems"]
.as_array()
.expect("problems array")
.iter()
.filter(|problem| problem["category"] == "global_state" && problem["severity"] == "warning")
.cloned()
.collect()
}

#[tokio::test(flavor = "multi_thread")]
async fn doctor_on_fresh_state_reports_unconfigured_telemetry_without_a_warning() {
let sandbox = Sandbox::new("https://example.invalid/org/repo-a.git");
let auth_dir = sandbox.state_root().join("sce");
let config = sandbox.telemetry_enabled_config();

let report = sandbox
.run_with_env(
&["doctor", "--format", "json"],
&[
(AUTH_DB_ENCRYPTION_KEY_ENV, ""),
("SCE_CONFIG_FILE", config.as_str()),
],
)
.json();

assert_eq!(report["managed_telemetry"]["state"], "not_configured");
let warnings = global_state_warnings(&report);
assert!(warnings.is_empty(), "{warnings:#?}");
assert!(!auth_dir.join("auth.db").exists());
}

#[tokio::test(flavor = "multi_thread")]
async fn doctor_fix_reports_unreadable_telemetry_credentials_without_auth_side_effects() {
let sandbox = Sandbox::new("https://example.invalid/org/repo-a.git");
let auth_dir = sandbox.state_root().join("sce");
std::fs::create_dir_all(&auth_dir).expect("auth dir");
let auth_db = auth_dir.join("auth.db");
std::fs::write(&auth_db, UNREADABLE_AUTH_DB).expect("auth DB");
let config = sandbox.telemetry_enabled_config();
let env = [
(AUTH_DB_ENCRYPTION_KEY_ENV, AUTH_DB_TEST_SECRET),
("SCE_CONFIG_FILE", config.as_str()),
];

let fix = sandbox.run_with_env(&["doctor", "--fix", "--format", "json"], &env);
let report = fix.json();

assert_eq!(
report["managed_telemetry"],
serde_json::json!({
"state": "disabled",
"reason": "database_error",
"kind": "managed_telemetry_database_error",
"severity": "warning",
"next_action": "manual_steps",
}),
"{}",
fix.stdout
);
let warnings = global_state_warnings(&report);
assert_eq!(warnings.len(), 1, "{}", fix.stdout);
assert_eq!(warnings[0]["fixability"], "manual_only");
assert_eq!(warnings[0]["remediation"]["next_action"], "manual_steps");
let summary = warnings[0]["summary"].as_str().expect("summary");
let fixes = report["fix_results"]
.as_array()
.expect("fix_results array")
.iter()
.filter(|entry| {
entry["category"] == "global_state"
&& entry["detail"]
.as_str()
.is_some_and(|detail| detail.starts_with(summary))
})
.collect::<Vec<_>>();
assert_eq!(fixes.len(), 1, "{}", fix.stdout);
assert_eq!(fixes[0]["outcome"], "manual");
assert_eq!(
std::fs::read(&auth_db).expect("auth DB kept"),
UNREADABLE_AUTH_DB
);
assert!(!fix.stdout.contains(AUTH_DB_TEST_SECRET));
assert!(!fix.stderr.contains(AUTH_DB_TEST_SECRET));
}

#[tokio::test(flavor = "multi_thread")]
async fn doctor_reports_post_commit_auto_sync_disabled_when_auth_is_disabled() {
let sandbox = Sandbox::new("https://example.invalid/org/repo-a.git");
let config_dir = sandbox.repo.join(".sce");
std::fs::create_dir_all(&config_dir).expect("config dir");
let config = config_dir.join("config.json");

std::fs::write(&config, r#"{"agent_trace":{"auto_sync":true}}"#).expect("config");
let allowed = sandbox.run(&["doctor", "--format", "json"]).json();
assert_eq!(allowed["post_commit_auto_sync"]["enabled"], true);
assert_ne!(allowed["post_commit_auto_sync"]["state"], "disabled");

std::fs::write(
&config,
r#"{"agent_trace":{"auto_sync":true},"auth":{"mode":"disabled"}}"#,
)
.expect("config");
let report = sandbox.run(&["doctor", "--format", "json"]).json();
assert_eq!(
report["post_commit_auto_sync"],
serde_json::json!({
"state": "disabled",
"enabled": false,
"source": "config_file",
"config_source": "default_discovered_local",
})
);
let text = sandbox.run(&["doctor"]);
assert!(
text.stdout
.contains("[PASS] Post-commit Agent Trace auto-sync (disabled by config)\n"),
"{}",
text.stdout
);
}

#[tokio::test(flavor = "multi_thread")]
async fn doctor_with_telemetry_disabled_by_config_never_reads_the_auth_db() {
let sandbox = Sandbox::new("https://example.invalid/org/repo-a.git");
let auth_dir = sandbox.state_root().join("sce");
let env = [(AUTH_DB_ENCRYPTION_KEY_ENV, "")];

let fresh = sandbox.run_with_env(&["doctor"], &env);
assert!(
fresh
.stdout
.contains("[PASS] Managed telemetry (disabled by config)\n"),
"{}",
fresh.stdout
);
assert!(
!fresh.stdout.contains(TELEMETRY_OPT_IN_NOTE),
"{}",
fresh.stdout
);
assert!(!auth_dir.join("auth.db").exists());

std::fs::create_dir_all(&auth_dir).expect("auth dir");
let auth_db = auth_dir.join("auth.db");
std::fs::write(&auth_db, UNREADABLE_AUTH_DB).expect("auth DB");

let report = sandbox
.run_with_env(&["doctor", "--format", "json"], &env)
.json();
assert_eq!(
report["managed_telemetry"],
serde_json::json!({
"state": "disabled_by_config",
"reason": "disabled_by_config",
"kind": null,
"severity": null,
"next_action": null,
})
);
let warnings = global_state_warnings(&report);
assert!(warnings.is_empty(), "{warnings:#?}");

let text = sandbox.run_with_env(&["doctor"], &env);
assert!(
text.stdout.contains(&format!(
"[PASS] Managed telemetry (disabled by config)\n {TELEMETRY_OPT_IN_NOTE}\n"
)),
"{}",
text.stdout
);
assert_eq!(
std::fs::read(&auth_db).expect("auth DB kept"),
UNREADABLE_AUTH_DB
);
}
Loading
Loading