Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(memory): make the entity-RPC assertions able to fail\n\nBoth CodeRabbit findings were right, and chasing the second exposed a third\nproblem underneath it.\n\n`delete_chunk_does_not_report_a_silent_success_without_the_family` accepted\neither `Err` or `Ok { deleted: false }`, because I wrote it without checking\nwhich the handler does. It returns `Err`, and the branch I allowed is precisely\nthe one `admin_tests` exists to forbid — a caller reading "nothing was removed"\nconcludes the content was already gone. It now requires the error.\n\nThe clamp test asserted that a log line existed and that the result was empty.\nBoth are true whether or not the handler clamps anything, so it could not fail.\n`EntityAwareDriver` now records every `limit` it is handed, and the test\nasserts `[MAX_LIST_LIMIT, 1]` for inputs `[u32::MAX, 0]` — measured where a\nclamp is observable, which is the value the driver receives.\n\nThat change immediately failed with `left: []`. Not because the driver was\nunbound — a probe confirmed `driver_id="entity-aware-test-driver"` — but\nbecause the line recording the limit had never landed: `cargo fmt` split the\nreturn type across lines before my edit ran, the search string stopped\nmatching, and a no-match replace silently does nothing.\n\nThe consequence is the part worth keeping. The two `kind` tests beside it\nassert an **empty list**, which is exactly what an unreached driver also\nproduces, so they had been passing without the driver being called at all — and\nonly the clamp assertion could tell. That is the same vacuous-pass shape this\nbranch has been finding all the way up the stack, this time in a test I wrote\nin the course of fixing it. Both now assert the driver was reached, so an empty\nlist means "the handler asked and got nothing" rather than "nobody asked".\n

Shanu397c1f671cc3
diff --git a/src/openhuman/memory/read_rpc/entities_tests.rs b/src/openhuman/memory/read_rpc/entities_tests.rs
index 6a08ed9991..a7cf15b1df 100644
--- a/src/openhuman/memory/read_rpc/entities_tests.rs
+++ b/src/openhuman/memory/read_rpc/entities_tests.rs
@@ -67,7 +67,11 @@ fn install_null_driver(cfg: &Config) {
/// **this handler's** mapping of a driver's answer, so the instrument has to be
/// something that produces the answer being mapped.
#[derive(Debug, Default)]
-struct EntityAwareDriver;
+struct EntityAwareDriver {
+ /// Every `limit` the handler forwarded, so a clamp can be asserted by the
+ /// value the driver *received* rather than by the shape of what came back.
+ limits_seen: std::sync::Mutex<Vec<usize>>,
+}
#[async_trait::async_trait]
impl tinymemory_api::provider::MemoryEntities for EntityAwareDriver {
@@ -102,11 +106,12 @@ impl tinymemory_api::provider::MemoryEntities for EntityAwareDriver {
async fn top_entities(
&self,
kind: Option<&str>,
- _limit: usize,
+ limit: usize,
) -> Result<
Vec<tinymemory_api::provider::types::EntityOccurrence>,
tinymemory_api::error::MemoryError,
> {
+ self.limits_seen.lock().expect("limits lock").push(limit);
// The contract's request-side vocabulary. Only `person` is needed here;
// what matters is that *some* kind is recognised and some other kind is
// not, so the handler's two branches are both reachable.
@@ -220,12 +225,14 @@ impl MemoryProvider for EntityAwareDriver {
}
}
-fn install_entity_driver(cfg: &Config) {
+fn install_entity_driver(cfg: &Config) -> Arc<EntityAwareDriver> {
+ let driver = Arc::new(EntityAwareDriver::default());
binding::install_for_test(
&cfg.workspace_dir,
&cfg.subsystems.memory,
- Arc::new(EntityAwareDriver) as Arc<dyn MemoryProvider>,
+ Arc::clone(&driver) as Arc<dyn MemoryProvider>,
);
+ driver
}
// ── the family-absent reads ────────────────────────────────────────────────
@@ -263,38 +270,40 @@ async fn delete_chunk_does_not_report_a_silent_success_without_the_family() {
install_null_driver(&cfg);
let outcome = delete_chunk_rpc(&cfg, "chunk-1".to_string()).await;
- match outcome {
- Err(_) => {}
- Ok(ok) => assert!(
- !ok.value.deleted,
- "a driver that cannot delete must not answer `deleted: true`; got {:?}",
- ok.value
- ),
- }
+ assert!(
+ outcome.is_err(),
+ "a delete the driver cannot perform must be an error, not a `deleted: false` \
+ success — a caller reading 'nothing was removed' concludes the content was \
+ already gone. Got: {:?}",
+ outcome.map(|ok| ok.value)
+ );
}
// ── the caps ───────────────────────────────────────────────────────────────
-/// `limit` is clamped rather than forwarded. Asserted through the handler's own
-/// log line, because the driver bound here indexes nothing and so cannot show
-/// the cap through a row count — and the clamp is the host's regardless of what
-/// the driver would have returned.
+/// `limit` is clamped at both ends before it reaches the driver.
+///
+/// Asserted on the value the driver was *handed*, which is the only thing that
+/// can show a clamp: the earlier version of this test checked that a log line
+/// existed and that the result was empty, and both are true whether or not the
+/// handler clamps anything. `MAX_LIST_LIMIT` is 1,000 and the floor is 1.
#[tokio::test]
-async fn top_entities_clamps_an_absurd_limit_rather_than_forwarding_it() {
+async fn top_entities_clamps_both_ends_of_the_limit_before_the_driver_sees_it() {
let (_tmp, cfg) = test_config();
- install_entity_driver(&cfg);
+ let driver = install_entity_driver(&cfg);
- let outcome = top_entities_rpc(&cfg, None, u32::MAX)
+ top_entities_rpc(&cfg, None, u32::MAX)
.await
.expect("top_entities");
- assert!(
- !outcome.logs.is_empty(),
- "the handler logs its resolved parameters; that log is the seam this asserts through"
+ top_entities_rpc(&cfg, None, 0).await.expect("top_entities");
+
+ let seen = driver.limits_seen.lock().expect("limits lock").clone();
+ assert_eq!(
+ seen,
+ vec![super::MAX_LIST_LIMIT as usize, 1],
+ "the ceiling must arrive as MAX_LIST_LIMIT and the floor as 1, not as \
+ u32::MAX and 0"
);
- // A zero limit is the other end of the same clamp: the floor is 1, so this
- // must not become "ask the driver for nothing".
- let floored = top_entities_rpc(&cfg, None, 0).await.expect("top_entities");
- assert!(floored.value.is_empty());
}
// ── the behaviour delta ────────────────────────────────────────────────────
@@ -309,7 +318,7 @@ async fn top_entities_clamps_an_absurd_limit_rather_than_forwarding_it() {
#[tokio::test]
async fn an_unknown_kind_degrades_to_an_empty_list_rather_than_an_error() {
let (_tmp, cfg) = test_config();
- install_entity_driver(&cfg);
+ let driver = install_entity_driver(&cfg);
let outcome = top_entities_rpc(&cfg, Some("definitely-not-a-kind".to_string()), 10)
.await
@@ -318,6 +327,15 @@ async fn an_unknown_kind_degrades_to_an_empty_list_rather_than_an_error() {
outcome.value.is_empty(),
"the pre-migration wire answered an empty list for an unknown kind"
);
+ // An empty list is also what an *unbound* driver produces, so the assertion
+ // above cannot stand alone: it would pass if this test's driver were never
+ // reached, and it did exactly that until the clamp test caught it.
+ assert_eq!(
+ driver.limits_seen.lock().expect("limits lock").len(),
+ 1,
+ "the handler must have reached this driver — otherwise the empty list \
+ above proves nothing about the map-back"
+ );
}
/// The narrowing half: a *recognised* kind is forwarded and answered normally,
@@ -325,10 +343,16 @@ async fn an_unknown_kind_degrades_to_an_empty_list_rather_than_an_error() {
#[tokio::test]
async fn a_recognised_kind_is_forwarded_rather_than_swallowed() {
let (_tmp, cfg) = test_config();
- install_entity_driver(&cfg);
+ let driver = install_entity_driver(&cfg);
let outcome = top_entities_rpc(&cfg, Some("person".to_string()), 10)
.await
.expect("a recognised kind is a normal query");
assert!(outcome.value.is_empty(), "this driver indexes no entities");
+ assert_eq!(
+ driver.limits_seen.lock().expect("limits lock").len(),
+ 1,
+ "the query must have reached the driver rather than being answered \
+ by the map-back"
+ );
}