From d9b0f879d1df48727b20bf4edc4c0cd4ab02bdb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 23 Oct 2026 15:30:34 +0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20forge-core=20i?= =?UTF-8?q?ntegration=20tests=20build=20as=20one=20binary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Four test binaries (audit_store, read_pool, stars_store, store_basic) are now one `integration` binary. Binaries 4 to 1, test count unchanged at 29. The store open and db path helpers are deduped into tests/integration/common.rs. --- .../tests/{ => integration}/audit_store.rs | 15 ++++++--------- crates/forge-core/tests/integration/common.rs | 13 +++++++++++++ crates/forge-core/tests/integration/main.rs | 9 +++++++++ .../tests/{ => integration}/read_pool.rs | 0 .../tests/{ => integration}/stars_store.rs | 12 ++---------- .../tests/{ => integration}/store_basic.rs | 11 ++--------- docs/backlog.md | 2 +- 7 files changed, 33 insertions(+), 29 deletions(-) rename crates/forge-core/tests/{ => integration}/audit_store.rs (91%) create mode 100644 crates/forge-core/tests/integration/common.rs create mode 100644 crates/forge-core/tests/integration/main.rs rename crates/forge-core/tests/{ => integration}/read_pool.rs (100%) rename crates/forge-core/tests/{ => integration}/stars_store.rs (97%) rename crates/forge-core/tests/{ => integration}/store_basic.rs (98%) diff --git a/crates/forge-core/tests/audit_store.rs b/crates/forge-core/tests/integration/audit_store.rs similarity index 91% rename from crates/forge-core/tests/audit_store.rs rename to crates/forge-core/tests/integration/audit_store.rs index 391d00f..fd382f6 100644 --- a/crates/forge-core/tests/audit_store.rs +++ b/crates/forge-core/tests/integration/audit_store.rs @@ -1,14 +1,11 @@ //! Store tests for the audit log: record, filtered listing, cursor paging and retention purge. -use std::path::Path; use std::time::Duration; use forge_core::time::stamp_ago; use forge_core::{AuditAction, AuditCursor, AuditEntry, AuditFilter, Store, User}; -async fn open_store(path: &Path) -> Store { - Store::open(path).await.expect("open store") -} +use crate::common::{db_path, open_store}; async fn user(store: &Store, name: &str) -> User { store.create_user(name, None, "h", false).await.unwrap() @@ -24,7 +21,7 @@ fn entry(action: AuditAction, actor: Option<&User>) -> AuditEntry { #[tokio::test] async fn record_and_list_round_trip_with_all_fields() { let dir = tempfile::tempdir().unwrap(); - let store = open_store(&dir.path().join("forge.db")).await; + let store = open_store(&db_path(&dir)).await; let tahinli = user(&store, "tahinli").await; let mut e = entry(AuditAction::RepoRenamed, Some(&tahinli)); e.target_kind = "repo".into(); @@ -44,7 +41,7 @@ async fn record_and_list_round_trip_with_all_fields() { #[tokio::test] async fn anonymous_entries_store_a_null_actor() { let dir = tempfile::tempdir().unwrap(); - let store = open_store(&dir.path().join("forge.db")).await; + let store = open_store(&db_path(&dir)).await; let mut e = AuditEntry::new(AuditAction::LoginFailed); e.target_name = "mallory".into(); store.record_audit(&e).await.unwrap(); @@ -59,7 +56,7 @@ async fn anonymous_entries_store_a_null_actor() { #[tokio::test] async fn filters_by_actor_action_target_and_involved_user() { let dir = tempfile::tempdir().unwrap(); - let store = open_store(&dir.path().join("forge.db")).await; + let store = open_store(&db_path(&dir)).await; let tahinli = user(&store, "tahinli").await; let bob = user(&store, "bob").await; @@ -118,7 +115,7 @@ async fn filters_by_actor_action_target_and_involved_user() { #[tokio::test] async fn cursor_pages_newest_first_without_gaps() { let dir = tempfile::tempdir().unwrap(); - let store = open_store(&dir.path().join("forge.db")).await; + let store = open_store(&db_path(&dir)).await; let mut written = Vec::new(); for _ in 0..5 { let e = AuditEntry::new(AuditAction::Logout); @@ -143,7 +140,7 @@ async fn cursor_pages_newest_first_without_gaps() { #[tokio::test] async fn purge_removes_only_entries_older_than_cutoff() { let dir = tempfile::tempdir().unwrap(); - let store = open_store(&dir.path().join("forge.db")).await; + let store = open_store(&db_path(&dir)).await; let mut old = AuditEntry::new(AuditAction::Logout); old.at = "2020-01-01T00:00:00.000000000Z".into(); store.record_audit(&old).await.unwrap(); diff --git a/crates/forge-core/tests/integration/common.rs b/crates/forge-core/tests/integration/common.rs new file mode 100644 index 0000000..083c651 --- /dev/null +++ b/crates/forge-core/tests/integration/common.rs @@ -0,0 +1,13 @@ +//! Helpers shared by the store test modules. + +use std::path::{Path, PathBuf}; + +use forge_core::Store; + +pub fn db_path(dir: &tempfile::TempDir) -> PathBuf { + dir.path().join("forge.db") +} + +pub async fn open_store(path: &Path) -> Store { + Store::open(path).await.expect("open store") +} diff --git a/crates/forge-core/tests/integration/main.rs b/crates/forge-core/tests/integration/main.rs new file mode 100644 index 0000000..ca3f441 --- /dev/null +++ b/crates/forge-core/tests/integration/main.rs @@ -0,0 +1,9 @@ +//! Store integration tests for forge-core, built as one test binary. + +#[allow(dead_code)] +mod common; + +mod audit_store; +mod read_pool; +mod stars_store; +mod store_basic; diff --git a/crates/forge-core/tests/read_pool.rs b/crates/forge-core/tests/integration/read_pool.rs similarity index 100% rename from crates/forge-core/tests/read_pool.rs rename to crates/forge-core/tests/integration/read_pool.rs diff --git a/crates/forge-core/tests/stars_store.rs b/crates/forge-core/tests/integration/stars_store.rs similarity index 97% rename from crates/forge-core/tests/stars_store.rs rename to crates/forge-core/tests/integration/stars_store.rs index 9febb43..0136817 100644 --- a/crates/forge-core/tests/stars_store.rs +++ b/crates/forge-core/tests/integration/stars_store.rs @@ -1,18 +1,10 @@ //! Store tests for stars, the public repo listing and the 0005 migration. -use std::path::{Path, PathBuf}; - +use forge_core::Visibility; use forge_core::store::RepoSort; use forge_core::store::migrate::{MIGRATIONS, migrate}; -use forge_core::{Store, Visibility}; - -fn db_path(dir: &tempfile::TempDir) -> PathBuf { - dir.path().join("forge.db") -} -async fn open_store(path: &Path) -> Store { - Store::open(path).await.expect("open store") -} +use crate::common::{db_path, open_store}; #[tokio::test] async fn star_and_unstar_round_trip_with_count() { diff --git a/crates/forge-core/tests/store_basic.rs b/crates/forge-core/tests/integration/store_basic.rs similarity index 98% rename from crates/forge-core/tests/store_basic.rs rename to crates/forge-core/tests/integration/store_basic.rs index 2ca28c1..2755934 100644 --- a/crates/forge-core/tests/store_basic.rs +++ b/crates/forge-core/tests/integration/store_basic.rs @@ -1,17 +1,10 @@ //! Store round-trip tests against a real turso database file in a temp directory. use forge_core::time::{now_stamp, stamp_after}; -use forge_core::{Error, Role, Store, Visibility}; -use std::path::{Path, PathBuf}; +use forge_core::{Error, Role, Visibility}; use std::time::Duration; -fn db_path(dir: &tempfile::TempDir) -> PathBuf { - dir.path().join("forge.db") -} - -async fn open_store(path: &Path) -> Store { - Store::open(path).await.expect("open store") -} +use crate::common::{db_path, open_store}; #[tokio::test] async fn create_user_and_lookup_case_insensitively() { diff --git a/docs/backlog.md b/docs/backlog.md index 66c1991..39e5128 100644 --- a/docs/backlog.md +++ b/docs/backlog.md @@ -51,7 +51,7 @@ Status: `[ ]` todo, `[~]` in progress, `[x]` done. ## Tech debt - [x] A shared test fixture `test_support::app(dir) -> (AppState, Router)`: Config and AppState literals are copied into about 8 test modules, and every new field breaks them all -- [x] Store read pool: one writer connection plus 4 `query_only` readers (`Store::read_conn`); pure-SELECT functions use the readers (rules in the `Store` doc comment, proof in `crates/forge-core/tests/read_pool.rs`) +- [x] Store read pool: one writer connection plus 4 `query_only` readers (`Store::read_conn`); pure-SELECT functions use the readers (rules in the `Store` doc comment, proof in `crates/forge-core/tests/integration/read_pool.rs`) - [x] Login and git auth throttling (`throttle.rs`, `client_ip.rs`, `trusted_proxies`) ## Later