Skip to content

Commit 08fa6af

Browse files
committed
{"schema":"cmsg/1","type":"refactor","scope":"global","summary":"Use runtime SQLx queries in tests","intent":"Allow tests to use sqlx::query/query_as/query_scalar without compile-time macros","impact":"Test code no longer depends on SQLx macros while production code remains macro-checked","breaking":false,"risk":"low","refs":["pr:32"]}
1 parent e8158a1 commit 08fa6af

6 files changed

Lines changed: 139 additions & 141 deletions

File tree

packages/elf-service/tests/acceptance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,13 @@ mod acceptance {
266266
collection: &str,
267267
vector_dim: u32,
268268
) -> color_eyre::Result<()> {
269-
let _ = client.delete_collection(collection.to_string()).await;
270269
let max_attempts = 8;
271270

272271
let mut backoff = Duration::from_millis(100);
273272
let mut last_err = None;
274273

275274
for attempt in 1..=max_attempts {
275+
let _ = client.delete_collection(collection.to_string()).await;
276276
let mut vectors_config = VectorsConfigBuilder::default();
277277
vectors_config.add_named_vector_params(
278278
DENSE_VECTOR_NAME,
@@ -317,7 +317,7 @@ mod acceptance {
317317
}
318318

319319
pub async fn reset_db(pool: &sqlx::PgPool) -> color_eyre::Result<()> {
320-
sqlx::query!(
320+
sqlx::query(
321321
"\
322322
TRUNCATE memory_hits, memory_note_versions, note_chunk_embeddings, memory_note_chunks, \
323323
note_embeddings, search_trace_items, search_traces, search_trace_outbox, search_sessions, \

packages/elf-service/tests/acceptance/chunk_search.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ async fn reset_collection(service: &ElfService) {
100100
async fn insert_note(pool: &PgPool, note_id: Uuid, note_text: &str, embedding_version: &str) {
101101
let now = OffsetDateTime::now_utc();
102102

103-
sqlx::query!(
103+
sqlx::query(
104104
"\
105-
INSERT INTO memory_notes (
106-
note_id,
107-
tenant_id,
105+
INSERT INTO memory_notes (
106+
note_id,
107+
tenant_id,
108108
project_id,
109109
agent_id,
110110
scope,
@@ -139,28 +139,28 @@ VALUES (
139139
$14,
140140
$15,
141141
$16,
142-
$17,
143-
$18
144-
)",
145-
note_id,
146-
"t",
147-
"p",
148-
"a",
149-
"agent_private",
150-
"fact",
151-
None::<String>,
152-
note_text,
153-
0.4_f32,
154-
0.9_f32,
155-
"active",
156-
now,
157-
now,
158-
None::<OffsetDateTime>,
159-
embedding_version,
160-
serde_json::json!({}),
161-
0_i64,
162-
None::<OffsetDateTime>,
142+
$17,
143+
$18
144+
)",
163145
)
146+
.bind(note_id)
147+
.bind("t")
148+
.bind("p")
149+
.bind("a")
150+
.bind("agent_private")
151+
.bind("fact")
152+
.bind(Option::<String>::None)
153+
.bind(note_text)
154+
.bind(0.4_f32)
155+
.bind(0.9_f32)
156+
.bind("active")
157+
.bind(now)
158+
.bind(now)
159+
.bind(Option::<OffsetDateTime>::None)
160+
.bind(embedding_version)
161+
.bind(serde_json::json!({}))
162+
.bind(0_i64)
163+
.bind(Option::<OffsetDateTime>::None)
164164
.execute(pool)
165165
.await
166166
.expect("Failed to insert memory note.");
@@ -177,26 +177,26 @@ async fn insert_chunk(
177177
text: &str,
178178
embedding_version: &str,
179179
) {
180-
sqlx::query!(
180+
sqlx::query(
181181
"\
182-
INSERT INTO memory_note_chunks (
183-
chunk_id,
182+
INSERT INTO memory_note_chunks (
183+
chunk_id,
184184
note_id,
185185
chunk_index,
186186
start_offset,
187187
end_offset,
188188
text,
189189
embedding_version
190+
)
191+
VALUES ($1, $2, $3, $4, $5, $6, $7)",
190192
)
191-
VALUES ($1, $2, $3, $4, $5, $6, $7)",
192-
chunk_id,
193-
note_id,
194-
chunk_index,
195-
start_offset,
196-
end_offset,
197-
text,
198-
embedding_version,
199-
)
193+
.bind(chunk_id)
194+
.bind(note_id)
195+
.bind(chunk_index)
196+
.bind(start_offset)
197+
.bind(end_offset)
198+
.bind(text)
199+
.bind(embedding_version)
200200
.execute(pool)
201201
.await
202202
.expect("Failed to insert chunk metadata.");

packages/elf-service/tests/acceptance/outbox_eventual_consistency.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@ async fn wait_for_status(
3636
) -> Option<OutboxRow> {
3737
let deadline = Instant::now() + timeout;
3838
loop {
39-
let row: Option<OutboxRow> = sqlx::query_as!(
40-
OutboxRow,
39+
let row: Option<OutboxRow> = sqlx::query_as::<_, OutboxRow>(
4140
"\
4241
SELECT
43-
status AS \"status!\",
44-
attempts AS \"attempts!\",
42+
status,
43+
attempts,
4544
last_error
4645
FROM indexing_outbox
4746
WHERE note_id = $1",
48-
note_id,
4947
)
48+
.bind(note_id)
5049
.fetch_optional(pool)
5150
.await
5251
.ok()
@@ -206,7 +205,9 @@ async fn outbox_retries_to_done() {
206205

207206
let now = OffsetDateTime::now_utc();
208207

209-
sqlx::query!("UPDATE indexing_outbox SET available_at = $1 WHERE note_id = $2", now, note_id,)
208+
sqlx::query("UPDATE indexing_outbox SET available_at = $1 WHERE note_id = $2")
209+
.bind(now)
210+
.bind(note_id)
210211
.execute(&service.db.pool)
211212
.await
212213
.expect("Failed to update available_at.");

packages/elf-service/tests/acceptance/rebuild_qdrant.rs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ async fn rebuild_uses_postgres_vectors_only() {
5656
service.cfg.storage.qdrant.vector_dim
5757
);
5858

59-
sqlx::query!(
59+
sqlx::query(
6060
"\
61-
INSERT INTO memory_notes (
62-
note_id,
63-
tenant_id,
61+
INSERT INTO memory_notes (
62+
note_id,
63+
tenant_id,
6464
project_id,
6565
agent_id,
6666
scope,
@@ -95,68 +95,68 @@ VALUES (
9595
$14,
9696
$15,
9797
$16,
98-
$17,
99-
$18
100-
)",
101-
note_id,
102-
"t",
103-
"p",
104-
"a",
105-
"agent_private",
106-
"fact",
107-
None::<String>,
108-
"Fact: Rebuild works.",
109-
0.5_f32,
110-
0.9_f32,
111-
"active",
112-
now,
113-
now,
114-
None::<OffsetDateTime>,
115-
embedding_version.as_str(),
116-
serde_json::json!({}),
117-
0_i64,
118-
None::<OffsetDateTime>,
98+
$17,
99+
$18
100+
)",
119101
)
102+
.bind(note_id)
103+
.bind("t")
104+
.bind("p")
105+
.bind("a")
106+
.bind("agent_private")
107+
.bind("fact")
108+
.bind(Option::<String>::None)
109+
.bind("Fact: Rebuild works.")
110+
.bind(0.5_f32)
111+
.bind(0.9_f32)
112+
.bind("active")
113+
.bind(now)
114+
.bind(now)
115+
.bind(Option::<OffsetDateTime>::None)
116+
.bind(embedding_version.as_str())
117+
.bind(serde_json::json!({}))
118+
.bind(0_i64)
119+
.bind(Option::<OffsetDateTime>::None)
120120
.execute(&service.db.pool)
121121
.await
122122
.expect("Failed to insert memory note.");
123123

124124
let chunk_id = Uuid::new_v4();
125125
let text = "Fact: Rebuild works.";
126126

127-
sqlx::query!(
127+
sqlx::query(
128128
"\
129-
INSERT INTO memory_note_chunks (
130-
chunk_id,
129+
INSERT INTO memory_note_chunks (
130+
chunk_id,
131131
note_id,
132132
chunk_index,
133133
start_offset,
134134
end_offset,
135135
text,
136136
embedding_version
137+
)
138+
VALUES ($1, $2, $3, $4, $5, $6, $7)",
137139
)
138-
VALUES ($1, $2, $3, $4, $5, $6, $7)",
139-
chunk_id,
140-
note_id,
141-
0_i32,
142-
0_i32,
143-
text.len() as i32,
144-
text,
145-
embedding_version.as_str(),
146-
)
140+
.bind(chunk_id)
141+
.bind(note_id)
142+
.bind(0_i32)
143+
.bind(0_i32)
144+
.bind(text.len() as i32)
145+
.bind(text)
146+
.bind(embedding_version.as_str())
147147
.execute(&service.db.pool)
148148
.await
149149
.expect("Failed to insert chunk metadata.");
150150

151-
sqlx::query!(
151+
sqlx::query(
152152
"\
153-
INSERT INTO note_chunk_embeddings (chunk_id, embedding_version, embedding_dim, vec)
154-
VALUES ($1, $2, $3, $4::text::vector)",
155-
chunk_id,
156-
embedding_version.as_str(),
157-
3_i32,
158-
"[0,0,0]",
153+
INSERT INTO note_chunk_embeddings (chunk_id, embedding_version, embedding_dim, vec)
154+
VALUES ($1, $2, $3, $4::text::vector)",
159155
)
156+
.bind(chunk_id)
157+
.bind(embedding_version.as_str())
158+
.bind(3_i32)
159+
.bind("[0,0,0]")
160160
.execute(&service.db.pool)
161161
.await
162162
.expect("Failed to insert chunk embedding.");

0 commit comments

Comments
 (0)