Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
dfb4908
Document configurable PostgreSQL storage design
mmpg-x86 Oct 14, 2026
953c8d2
Initialize pseudoterminals in display tests
mmpg-x86 Oct 15, 2026
ebb23b6
Parse opt-in PostgreSQL storage modes
mmpg-x86 Oct 15, 2026
8cc1137
Add PostgreSQL catalog migration foundation
mmpg-x86 Oct 15, 2026
282da5e
Support PostgreSQL for daemon storage
mmpg-x86 Oct 15, 2026
5ff2a61
Synchronize shared bug catalogs through PostgreSQL
mmpg-x86 Oct 15, 2026
0d7e948
Keep catalog merge bases until local changes are acknowledged
mmpg-x86 Oct 15, 2026
f0ab873
Keep imported discovery links scoped to their producer
mmpg-x86 Oct 15, 2026
1b9ef39
Honor the selected storage backend in database clients
mmpg-x86 Oct 15, 2026
dec5920
Provide OpenSSL dependencies for Linux Nix builds
mmpg-x86 Oct 15, 2026
9d63568
Run PostgreSQL integration coverage in CI
mmpg-x86 Oct 15, 2026
f74127a
Preserve ASCII subsystem scope matching on both backends
mmpg-x86 Oct 15, 2026
1256de8
Redact foreign duplicate history in scoped bug views
mmpg-x86 Oct 15, 2026
0a1ddeb
Bound pending catalog lookups to the requested bug views
mmpg-x86 Oct 15, 2026
67b4b3d
Preserve shared duplicate relationships during concurrent triage
mmpg-x86 Oct 15, 2026
b67bc94
Preserve analysis outcomes across shared catalog outages
mmpg-x86 Oct 15, 2026
44b0051
Recover ordinary PostgreSQL sessions after connection loss
mmpg-x86 Oct 15, 2026
ba8ef01
Keep the libSQL covering index for review statistics
mmpg-x86 Oct 15, 2026
3d64a2d
Exercise PostgreSQL adapter boundaries with deterministic fixtures
mmpg-x86 Oct 15, 2026
4447f1f
Describe PostgreSQL deployment and execution boundaries
mmpg-x86 Oct 15, 2026
56b079b
Keep shared publication scoped to the configured project
mmpg-x86 Oct 15, 2026
f5f686c
Scope PostgreSQL coordination locks to the configured schema
mmpg-x86 Oct 15, 2026
592d15d
Version shared mirror tracking and exclude local bookkeeping
mmpg-x86 Oct 15, 2026
44eb292
Reuse the shared catalog connection and TLS configuration
mmpg-x86 Oct 15, 2026
35b5c79
Discard PostgreSQL sessions after interrupted operations
mmpg-x86 Oct 15, 2026
672dbce
Classify transient catalog failures before refunding attempts
mmpg-x86 Oct 15, 2026
085e67a
Preserve legacy bug identifiers in project catalog namespaces
mmpg-x86 Oct 15, 2026
e875af3
Bound shared catalog synchronization with durable scheduling
mmpg-x86 Oct 15, 2026
490c9dc
Preserve original metadata when importing shared bug history
mmpg-x86 Oct 15, 2026
13fd37c
Match libSQL bug triage behavior on PostgreSQL
mmpg-x86 Oct 15, 2026
66e32d9
Verify the shared catalog readiness contract
mmpg-x86 Oct 15, 2026
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
Prev Previous commit
Next Next commit
Exercise PostgreSQL adapter boundaries with deterministic fixtures
Build integration settings from an isolated fixture and observe the
second dedup session waiting on the actual server advisory lock before
releasing its owner. Connection setup latency cannot satisfy the lock
exclusion assertion.

Cover integer limits, negative and fractional NUMERIC values, invalid
wire input, quoted SQL names and nested comments in the adapter tests.

Signed-off-by: Maciej Grochowski <maciej.grochowski@protonmail.com>
  • Loading branch information
mmpg-x86 committed Oct 15, 2026
commit 3d64a2d2812bc2c0de4154a1cef49855f572305d
60 changes: 60 additions & 0 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,4 +704,64 @@ mod tests {
);
assert!(placeholders("SELECT ?0").is_err());
}

#[test]
fn query_vocabulary_preserves_quoted_names_and_nested_comments() {
assert_eq!(
placeholders("SELECT strftime('%s','now'), datetime(?, 'unixepoch'), group_concat(name, ','), json_each(?), json_set(data, '$.x', ?), json_extract(data, '$.x') WHERE title NOT LIKE ?").unwrap(),
"SELECT sashiko_strftime('%s','now'), sashiko_datetime($1, 'unixepoch'), string_agg(name, ','), sashiko_json_ids($2), sashiko_json_set(data, '$.x', $3), sashiko_json_flag(data, '$.x') WHERE title NOT ILIKE $4"
);
assert_eq!(
placeholders("SELECT \"like\", 'datetime ''?''', ?1 /* outer ? /* json_set */ ? */ -- json_each ?\n").unwrap(),
"SELECT \"like\", 'datetime ''?''', $1 /* outer ? /* json_set */ ? */ -- json_each ?\n"
);
}

fn decode_numeric(weight: i16, negative: bool, scale: i16, digits: &[i16]) -> Value {
let header = [
i16::try_from(digits.len()).unwrap(),
weight,
if negative { 0x4000 } else { 0 },
scale,
];
let bytes: Vec<_> = header
.iter()
.chain(digits)
.flat_map(|v| v.to_be_bytes())
.collect();
Numeric::from_sql(&Type::NUMERIC, &bytes).unwrap().0
}

#[test]
fn numeric_wire_values_preserve_integer_limits_signs_and_fractions() {
assert_eq!(decode_numeric(0, false, 0, &[]), Value::Integer(0));
assert_eq!(
decode_numeric(1, true, 0, &[42, 1]),
Value::Integer(-420001)
);
assert_eq!(
decode_numeric(4, false, 0, &[922, 3372, 368, 5477, 5807]),
Value::Integer(i64::MAX)
);
assert_eq!(
decode_numeric(4, true, 0, &[922, 3372, 368, 5477, 5808]),
Value::Integer(i64::MIN)
);
for (weight, digits, expected) in [(0, vec![12, 3456], 12.3456), (-1, vec![1], 0.0001)] {
let Value::Real(actual) = decode_numeric(weight, false, 4, &digits) else {
panic!("expected a fractional value")
};
assert!((actual - expected).abs() < 1e-12);
}
for words in [
vec![0],
vec![2, 0, 0, 0, 1],
vec![1, 0, 0, 0, 10000],
vec![0, 0, -16384, 0],
vec![5, 4, 0, 0, 922, 3372, 368, 5477, 5808],
] {
let bytes: Vec<_> = words.into_iter().flat_map(i16::to_be_bytes).collect();
assert!(Numeric::from_sql(&Type::NUMERIC, &bytes).is_err());
}
}
}
67 changes: 53 additions & 14 deletions tests/integration/postgres_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ use sashiko::db::{BugLifecycleStatus, Database, ListBugsParams, NewBug, NewBugEn
use sashiko::settings::StorageSettings;
use serde_json::json;

fn test_settings() -> Result<sashiko::settings::Settings> {
Ok(toml::from_str(
"[ai]\nprovider='mock'\nmodel='test'\n[review]\nconcurrency=1\n",
)?)
}

#[tokio::test]
#[ignore = "requires SASHIKO_TEST_POSTGRES_URL_FILE pointing to a disposable PostgreSQL database"]
async fn postgres_daemon_storage_roundtrip() -> Result<()> {
Expand All @@ -16,7 +22,7 @@ async fn postgres_daemon_storage_roundtrip() -> Result<()> {
postgres_tls_require_only: true,
..Default::default()
};
let mut configured = sashiko::settings::Settings::new()?;
let mut configured = test_settings()?;
configured.storage = settings;
configured.storage.mode = sashiko::settings::StorageMode::Postgresql;
// A configured PostgreSQL client must ignore the legacy libSQL URL.
Expand Down Expand Up @@ -298,7 +304,7 @@ async fn exercise_daemon(db: &Database) -> Result<()> {
async fn postgres_shared_catalog_between_instances() -> Result<()> {
let file = std::env::var("SASHIKO_TEST_POSTGRES_URL_FILE")?;
let directory = tempfile::tempdir()?;
let mut settings = sashiko::settings::Settings::new()?;
let mut settings = test_settings()?;
settings.storage.mode = sashiko::settings::StorageMode::LibsqlSharedBugs;
settings.storage.postgres_url = Some(std::fs::read_to_string(file)?.trim().to_string());
settings.storage.postgres_schema = format!("test_{}", uuid::Uuid::new_v4().simple());
Expand Down Expand Up @@ -424,18 +430,7 @@ async fn exercise_shared(
second.sync_shared_bugs().await?;
let imported_duplicate = second.get_bug_by_bugid(&duplicate.bugid).await?.unwrap();
assert_eq!(imported_duplicate.duplicate_of_id, Some(mirror.id));
let guard = first.lock_bug_dedup().await?;
assert!(
tokio::time::timeout(
std::time::Duration::from_millis(100),
second.lock_bug_dedup()
)
.await
.is_err()
);
drop(guard);
let guard = second.lock_bug_dedup().await?;
drop(guard);
assert_shared_lock_exclusion(first, second, &settings.storage).await?;
// A local bug write commits while the catalog is unreachable, then a new
// daemon handle publishes the durable outbox after connectivity is restored.
let mut offline = settings.clone();
Expand Down Expand Up @@ -465,6 +460,50 @@ async fn exercise_shared(
Ok(())
}

async fn assert_shared_lock_exclusion(
first: &Database,
second: &Database,
settings: &StorageSettings,
) -> Result<()> {
let guard = first.lock_bug_dedup().await?.context("held dedup guard")?;
let pid = backend_pid(&guard).await?;
let control = postgres_control(settings).await?;
let params: [&(dyn tokio_postgres::types::ToSql + Sync); 1] = [&pid];
let waiter = second.lock_bug_dedup();
tokio::pin!(waiter);
tokio::time::timeout(std::time::Duration::from_secs(10), async {
loop {
tokio::select! {
acquired = &mut waiter => {
acquired?;
anyhow::bail!("second dedup guard acquired before the first was released");
}
row = control.query_one(
"SELECT EXISTS (
SELECT 1 FROM pg_catalog.pg_locks held
JOIN pg_catalog.pg_locks waiting
USING (locktype,database,classid,objid,objsubid)
WHERE held.pid=$1 AND held.locktype='advisory'
AND held.granted AND NOT waiting.granted)", &params,
) => {
if row?.get::<_, bool>(0) {
return Ok::<_, anyhow::Error>(());
}
}
}
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
}
})
.await
.context("second connection never entered the server lock wait")??;
drop(guard);
let guard = tokio::time::timeout(std::time::Duration::from_secs(10), waiter)
.await
.context("second dedup guard did not acquire after release")??;
drop(guard);
Ok(())
}

async fn shared_report(db: &Database, title: &str) -> Result<(i64, String)> {
let bugid = format!("sashiko-{}", uuid::Uuid::new_v4());
let bug: NewBug = serde_json::from_value(json!({
Expand Down