Skip to content

Commit 752a460

Browse files
senamakelmedullabot
andcommitted
fix(core): use cfg-gated memory client and clean up test code
Split the `memory_client` method into two cfg-gated implementations so that test code builds a workspace-scoped client directly instead of relying on the global singleton, which is not booted under `cfg(test)`. Also replaced `vec!` with array literals, simplified iterator chains, and removed unnecessary `as_deref` calls across several modules to reduce allocations and improve clarity. Auto-committed-on: dragonfly Co-authored-by: Medulla <medulla@tinyhumans.ai>
1 parent 2c2be5e commit 752a460

7 files changed

Lines changed: 18 additions & 17 deletions

File tree

core/src/sync/composio/providers/types.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,17 +420,20 @@ impl ProviderContext {
420420

421421
/// Memory client handle if the global memory singleton is ready.
422422
/// Used by providers that want to persist sync snapshots.
423+
///
424+
/// Under `cfg(test)` the global singleton is not booted, so build a
425+
/// workspace-scoped client directly instead.
426+
#[cfg(test)]
423427
pub fn memory_client(&self) -> Option<crate::store::MemoryClientRef> {
424-
#[cfg(test)]
425-
{
426-
return crate::store::MemoryClient::from_workspace_dir(
427-
self.config.workspace_dir().clone(),
428-
)
428+
crate::store::MemoryClient::from_workspace_dir(self.config.workspace_dir().clone())
429429
.ok()
430-
.map(std::sync::Arc::new);
431-
}
430+
.map(std::sync::Arc::new)
431+
}
432432

433-
#[cfg(not(test))]
433+
/// Memory client handle if the global memory singleton is ready.
434+
/// Used by providers that want to persist sync snapshots.
435+
#[cfg(not(test))]
436+
pub fn memory_client(&self) -> Option<crate::store::MemoryClientRef> {
434437
crate::global::client_if_ready()
435438
}
436439
}

core/src/tinycortex/persona.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ mod tests {
345345

346346
#[test]
347347
fn status_scan_stops_parsing_at_the_configured_limit() {
348-
let paths = vec![PathBuf::from("one"), PathBuf::from("two")];
348+
let paths = [PathBuf::from("one"), PathBuf::from("two")];
349349
let reads = std::cell::Cell::new(0);
350350
let status = source_status(
351351
"fixture",

core/src/tool_memory/test_helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Memory for MockMemory {
7575
.filter(|((n, _), _)| n == ns)
7676
.map(|(_, v)| v.clone())
7777
.collect(),
78-
None => lock.iter().map(|(_, v)| v.clone()).collect(),
78+
None => lock.values().cloned().collect(),
7979
})
8080
}
8181
async fn forget(&self, namespace: &str, key: &str) -> anyhow::Result<bool> {

core/src/tree/retrieval/benchmarks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ async fn bench_scale_ingest_20_sources_no_real_data() {
323323
&scope_str,
324324
&owner_str,
325325
vec![(
326-
owner_str.clone().into(),
326+
owner_str.clone(),
327327
format!(
328328
"Scale test message {} from {} — verifying retrieval correctness \
329329
at volume with deterministic synthetic data. No PII present.",

core/src/tree/retrieval/integration_tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ fn chat_about_phoenix(seq: u32) -> ChatBatch {
6464
timestamp: Utc
6565
.timestamp_millis_opt(1_700_000_001_000 + (seq as i64) * 10_000)
6666
.unwrap(),
67-
text: format!(
68-
"Confirmed. I'll handle coordination. #launch-q2 tracked in \
67+
text: "Confirmed. I'll handle coordination. #launch-q2 tracked in \
6968
Notion. bob@example.com will cut the release."
70-
),
69+
.to_string(),
7170
source_ref: Some(format!("slack://phoenix/{seq}-reply")),
7271
},
7372
],

core/src/tree/score/embed/factory.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ fn resolve_embedder_choice(config: &Config) -> Result<EmbedderChoice> {
158158
// 2. Deliberate opt-out — vector search off by user choice.
159159
if config
160160
.embeddings_provider()
161-
.as_deref()
162-
.map(|s| s.trim())
161+
.map(str::trim)
163162
.is_some_and(|s| s == "none")
164163
{
165164
return Ok(EmbedderChoice::OptOut);

core/src/tree/summarise.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub async fn summarise(
2828
let Some(prepared) = tinycortex::memory::tree::prepare_summary_prompt(
2929
inputs,
3030
context,
31-
config.output_language().as_deref(),
31+
config.output_language(),
3232
) else {
3333
return Ok(SummaryOutput::default());
3434
};

0 commit comments

Comments
 (0)