Skip to content

Commit 8c32ee2

Browse files
committed
cli: Remove dead test code and unused helpers
Remove obsolete tests and helper functions that are no longer used
1 parent 78a3e20 commit 8c32ee2

File tree

6 files changed

+82
-239
lines changed

6 files changed

+82
-239
lines changed

cli/src/services/hooks/tests.rs

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use super::{
1616
apply_commit_msg_coauthor_policy, finalize_post_commit_trace, finalize_post_rewrite_remap,
1717
finalize_pre_commit_checkpoint, finalize_rewrite_trace, process_trace_retry_queue,
1818
resolve_pre_commit_checkpoint_path, run_commit_msg_subcommand_in_repo, run_hooks_subcommand,
19-
run_pre_commit_subcommand_in_repo, CommitMsgRuntimeState, HookSubcommand, PendingCheckpoint,
20-
PendingFileCheckpoint, PendingLineRange, PersistenceErrorClass, PersistenceFailure,
21-
PersistenceTarget, PersistenceWriteResult, PostCommitFinalization, PostCommitInput,
22-
PostCommitNoOpReason, PostCommitRuntimeState, PostRewriteFinalization, PostRewriteNoOpReason,
19+
CommitMsgRuntimeState, HookSubcommand, PendingCheckpoint, PendingFileCheckpoint,
20+
PendingLineRange, PersistenceErrorClass, PersistenceFailure, PersistenceTarget,
21+
PersistenceWriteResult, PostCommitFinalization, PostCommitInput, PostCommitNoOpReason,
22+
PostCommitRuntimeState, PostRewriteFinalization, PostRewriteNoOpReason,
2323
PostRewriteRuntimeState, PreCommitFinalization, PreCommitNoOpReason, PreCommitRuntimeState,
2424
PreCommitTreeAnchors, RetryMetricsSink, RetryProcessingMetric, RewriteMethod,
2525
RewriteRemapIngestion, RewriteRemapRequest, RewriteTraceFinalization, RewriteTraceInput,
@@ -792,44 +792,6 @@ fn pre_commit_finalization_uses_only_staged_ranges_and_captures_anchors() {
792792
);
793793
}
794794

795-
#[test]
796-
fn pre_commit_runtime_persists_staged_only_checkpoint_artifact() -> Result<()> {
797-
let repo = create_temp_repo()?;
798-
let tracked_file = repo.join("src").join("lib.rs");
799-
fs::create_dir_all(
800-
tracked_file
801-
.parent()
802-
.expect("tracked file path should have parent"),
803-
)?;
804-
fs::write(&tracked_file, "one\ntwo\nthree\nfour\n")?;
805-
run_git_in_repo(&repo, &["add", "."])?;
806-
run_git_in_repo(&repo, &["commit", "-m", "initial"])?;
807-
808-
fs::write(&tracked_file, "one\ntwo-staged\nthree\nfour\n")?;
809-
run_git_in_repo(&repo, &["add", "src/lib.rs"])?;
810-
fs::write(&tracked_file, "one\ntwo-staged\nthree\nfour-unstaged\n")?;
811-
812-
let message = run_pre_commit_subcommand_in_repo(&repo)?;
813-
assert_eq!(
814-
message,
815-
"pre-commit hook executed and finalized staged checkpoint for 1 file(s)."
816-
);
817-
818-
let checkpoint_path = resolve_pre_commit_checkpoint_path(&repo)?;
819-
let checkpoint = serde_json::from_slice::<serde_json::Value>(&fs::read(&checkpoint_path)?)?;
820-
821-
assert_eq!(checkpoint["version"], 1);
822-
assert_eq!(checkpoint["files"].as_array().map(Vec::len), Some(1));
823-
assert_eq!(checkpoint["files"][0]["path"], "src/lib.rs");
824-
assert_eq!(
825-
checkpoint["files"][0]["ranges"].as_array().map(Vec::len),
826-
Some(1)
827-
);
828-
assert_eq!(checkpoint["files"][0]["ranges"][0]["start_line"], 2);
829-
assert_eq!(checkpoint["files"][0]["ranges"][0]["end_line"], 2);
830-
Ok(())
831-
}
832-
833795
fn sample_commit_msg_runtime() -> CommitMsgRuntimeState {
834796
CommitMsgRuntimeState {
835797
sce_disabled: false,

cli/src/services/local_db.rs

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -286,21 +286,7 @@ mod tests {
286286
use crate::test_support::TestTempDir;
287287
use anyhow::Result;
288288

289-
use super::{apply_core_schema_migrations, run_smoke_check, LocalDatabaseTarget};
290-
291-
async fn fetch_single_integer(target: LocalDatabaseTarget<'_>, query: &str) -> Result<i64> {
292-
let conn = super::connect_local(target).await?;
293-
let mut rows = conn.query(query, ()).await?;
294-
let row = rows
295-
.next()
296-
.await?
297-
.ok_or_else(|| anyhow::anyhow!("integer query returned no rows"))?;
298-
let value = row.get_value(0)?;
299-
let value = *value
300-
.as_integer()
301-
.ok_or_else(|| anyhow::anyhow!("integer query returned non-integer"))?;
302-
Ok(value)
303-
}
289+
use super::{run_smoke_check, LocalDatabaseTarget};
304290

305291
#[test]
306292
fn in_memory_smoke_check_succeeds() -> Result<()> {
@@ -320,116 +306,4 @@ mod tests {
320306
assert!(path.exists());
321307
Ok(())
322308
}
323-
324-
#[test]
325-
fn reconciliation_schema_supports_replay_safe_runs_and_mapping_queries() -> Result<()> {
326-
let temp = TestTempDir::new("sce-reconciliation-schema-tests")?;
327-
let path = temp.path().join("reconciliation.db");
328-
let runtime = tokio::runtime::Builder::new_current_thread().build()?;
329-
330-
runtime.block_on(apply_core_schema_migrations(LocalDatabaseTarget::Path(
331-
&path,
332-
)))?;
333-
334-
runtime.block_on(async {
335-
let location = super::target_location(LocalDatabaseTarget::Path(&path))?;
336-
let db = turso::Builder::new_local(location).build().await?;
337-
let conn = db.connect()?;
338-
339-
conn.execute(
340-
"INSERT INTO repositories (canonical_root) VALUES (?1)",
341-
["/tmp/reconciliation-repo"],
342-
)
343-
.await?;
344-
345-
conn.execute(
346-
"INSERT INTO reconciliation_runs (repository_id, provider, idempotency_key, status) \
347-
VALUES (?1, ?2, ?3, ?4)",
348-
(1_i64, "github", "run:key:1", "completed"),
349-
)
350-
.await?;
351-
352-
conn.execute(
353-
"INSERT INTO conversations (repository_id, url, source) VALUES (?1, ?2, ?3)",
354-
(1_i64, "https://example.dev/conversations/abc", "github"),
355-
)
356-
.await?;
357-
358-
conn.execute(
359-
"INSERT INTO rewrite_mappings (\
360-
reconciliation_run_id, repository_id, old_commit_sha, new_commit_sha,\
361-
mapping_status, confidence, idempotency_key\
362-
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)",
363-
(
364-
1_i64,
365-
1_i64,
366-
"1111111111111111111111111111111111111111",
367-
"2222222222222222222222222222222222222222",
368-
"mapped",
369-
0.98_f64,
370-
"map:key:1",
371-
),
372-
)
373-
.await?;
374-
375-
let duplicate_run = conn
376-
.execute(
377-
"INSERT INTO reconciliation_runs (repository_id, provider, idempotency_key, status) \
378-
VALUES (?1, ?2, ?3, ?4)",
379-
(1_i64, "github", "run:key:1", "completed"),
380-
)
381-
.await;
382-
assert!(duplicate_run.is_err(), "run idempotency key should be unique");
383-
384-
let duplicate_mapping = conn
385-
.execute(
386-
"INSERT INTO rewrite_mappings (\
387-
reconciliation_run_id, repository_id, old_commit_sha, new_commit_sha,\
388-
mapping_status, confidence, idempotency_key\
389-
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)",
390-
(
391-
1_i64,
392-
1_i64,
393-
"1111111111111111111111111111111111111111",
394-
"3333333333333333333333333333333333333333",
395-
"mapped",
396-
0.70_f64,
397-
"map:key:1",
398-
),
399-
)
400-
.await;
401-
assert!(
402-
duplicate_mapping.is_err(),
403-
"mapping idempotency key should be unique"
404-
);
405-
406-
Ok::<(), anyhow::Error>(())
407-
})?;
408-
409-
let run_count = runtime.block_on(fetch_single_integer(
410-
LocalDatabaseTarget::Path(&path),
411-
"SELECT COUNT(*) FROM reconciliation_runs WHERE repository_id = 1 AND status = 'completed'",
412-
))?;
413-
assert_eq!(run_count, 1);
414-
415-
let mapped_count = runtime.block_on(fetch_single_integer(
416-
LocalDatabaseTarget::Path(&path),
417-
"SELECT COUNT(*) FROM rewrite_mappings WHERE repository_id = 1 AND old_commit_sha = '1111111111111111111111111111111111111111'",
418-
))?;
419-
assert_eq!(mapped_count, 1);
420-
421-
let joined_mapping_count = runtime.block_on(fetch_single_integer(
422-
LocalDatabaseTarget::Path(&path),
423-
"SELECT COUNT(*) FROM rewrite_mappings m JOIN reconciliation_runs r ON r.id = m.reconciliation_run_id JOIN repositories repo ON repo.id = m.repository_id WHERE r.repository_id = repo.id AND m.old_commit_sha = '1111111111111111111111111111111111111111'",
424-
))?;
425-
assert_eq!(joined_mapping_count, 1);
426-
427-
let conversation_count = runtime.block_on(fetch_single_integer(
428-
LocalDatabaseTarget::Path(&path),
429-
"SELECT COUNT(*) FROM conversations WHERE repository_id = 1 AND source = 'github'",
430-
))?;
431-
assert_eq!(conversation_count, 1);
432-
433-
Ok(())
434-
}
435309
}

cli/src/services/setup/tests.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,6 @@ fn setup_options_reject_repo_without_hooks() {
9494
);
9595
}
9696

97-
#[test]
98-
fn run_setup_hooks_reports_per_hook_statuses() -> Result<()> {
99-
let temp = TestTempDir::new("sce-setup-hook-install-tests")?;
100-
init_git_repo(temp.path())?;
101-
102-
let message = run_setup_hooks(temp.path())?;
103-
assert!(message.contains("Hook setup completed successfully."));
104-
assert!(message.contains("Repository root:"));
105-
assert!(message.contains("Hooks directory:"));
106-
assert!(message.contains("commit-msg: installed"));
107-
assert!(message.contains("post-commit: installed"));
108-
assert!(message.contains("pre-commit: installed"));
109-
assert!(message.contains("backup: not needed"));
110-
111-
Ok(())
112-
}
113-
11497
#[test]
11598
fn run_setup_hooks_rejects_missing_repo_path() {
11699
let missing_path = PathBuf::from("/definitely/missing/sce-test-repo");

cli/src/services/token_storage.rs

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ fn apply_secure_file_permissions(_path: &Path) -> Result<(), TokenStorageError>
273273

274274
#[cfg(test)]
275275
mod tests {
276-
use super::{delete_tokens_at_path, load_tokens_from_path, save_tokens_at_path, StoredTokens};
276+
use super::{delete_tokens_at_path, load_tokens_from_path};
277277
use std::fs;
278278
use std::path::PathBuf;
279279

@@ -290,17 +290,6 @@ mod tests {
290290
std::env::temp_dir().join(unique).join("tokens.json")
291291
}
292292

293-
fn fixture_tokens() -> StoredTokens {
294-
StoredTokens {
295-
access_token: "access-token".to_string(),
296-
token_type: "Bearer".to_string(),
297-
expires_in: 3600,
298-
refresh_token: "refresh-token".to_string(),
299-
scope: Some("openid profile".to_string()),
300-
stored_at_unix_seconds: 1_700_000_000,
301-
}
302-
}
303-
304293
#[test]
305294
fn load_missing_token_file_returns_none() {
306295
let token_path = unique_test_path("missing-file");
@@ -327,24 +316,6 @@ mod tests {
327316
);
328317
}
329318

330-
#[test]
331-
fn delete_existing_token_file_returns_true() {
332-
let token_path = unique_test_path("delete-existing");
333-
save_tokens_at_path(&token_path, &fixture_tokens()).expect("tokens should save");
334-
335-
let deleted = delete_tokens_at_path(&token_path).expect("delete should succeed");
336-
337-
assert!(deleted);
338-
assert!(!token_path.exists());
339-
340-
let _ = fs::remove_dir_all(
341-
token_path
342-
.parent()
343-
.and_then(|path| path.parent())
344-
.expect("temp tree should have two parent levels"),
345-
);
346-
}
347-
348319
#[test]
349320
fn delete_missing_token_file_returns_false() {
350321
let token_path = unique_test_path("delete-missing");
@@ -353,24 +324,4 @@ mod tests {
353324

354325
assert!(!deleted);
355326
}
356-
357-
#[cfg(unix)]
358-
#[test]
359-
fn save_sets_unix_file_permissions_to_0600() {
360-
use std::os::unix::fs::PermissionsExt;
361-
362-
let token_path = unique_test_path("unix-perms");
363-
save_tokens_at_path(&token_path, &fixture_tokens()).expect("tokens should save");
364-
365-
let metadata = fs::metadata(&token_path).expect("token file should exist");
366-
let mode = metadata.permissions().mode() & 0o777;
367-
assert_eq!(mode, 0o600);
368-
369-
let _ = fs::remove_dir_all(
370-
token_path
371-
.parent()
372-
.and_then(|path| path.parent())
373-
.expect("temp tree should have two parent levels"),
374-
);
375-
}
376327
}

context/plans/nix-flake-checks-refactor.md

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)