ares-agent 0.10.0

Agent orchestration for ARES
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
//! Tenant agent runtime resolver โ€” 3-tier hierarchy: user โ†’ community โ†’ system config.

use crate::AgentConfig;
use ares_store::postgres::UserAgent;
use ares_store::traits::DatabaseClient;
use ares_types::types::{AppError, Result};

pub use crate::execution::AgentSource;

/// Build a synthetic system [`UserAgent`] from static TOML/TOON [`AgentConfig`].
pub fn system_agent_from_config(agent_name: &str, cfg: &AgentConfig, now: i64) -> UserAgent {
    UserAgent {
        id: format!("system-{agent_name}"),
        user_id: "system".into(),
        name: agent_name.into(),
        display_name: None,
        description: None,
        model: cfg.model.clone(),
        system_prompt: cfg.system_prompt.clone(),
        tools: serde_json::to_string(&cfg.tools).unwrap_or_else(|_| "[]".into()),
        max_tool_iterations: cfg.max_tool_iterations as i32,
        parallel_tools: cfg.parallel_tools,
        extra: "{}".into(),
        is_public: true,
        usage_count: 0,
        rating_sum: 0,
        rating_count: 0,
        created_at: now,
        updated_at: now,
    }
}

/// Pure 3-tier resolution given already-fetched candidates (no I/O).
pub fn resolve_from_candidates(
    user_agent: Option<UserAgent>,
    public_agent: Option<UserAgent>,
    system_config: Option<&AgentConfig>,
    agent_name: &str,
    now: i64,
) -> Result<(UserAgent, AgentSource)> {
    if let Some(agent) = user_agent {
        return Ok((agent, AgentSource::User));
    }
    if let Some(agent) = public_agent {
        return Ok((agent, AgentSource::Community));
    }
    if let Some(cfg) = system_config {
        return Ok((
            system_agent_from_config(agent_name, cfg, now),
            AgentSource::System,
        ));
    }
    Err(AppError::NotFound(format!("Agent '{agent_name}' not found")))
}

/// Tenant identifier for per-tenant scoping (`ctx.isolate` label).
pub type TenantId = String;

use std::future::Future;
use std::sync::Arc;

use cordis::{CordisError, Service};
use ares_store::TenantDb;

use crate::registry::AgentRegistry;

/// Unified agent resolver โ€” single place that resolves agents with ordered
/// precedence `tenant_db tenant_agents โ†’ community public โ†’ system AgentRegistry`.
///
/// Crate-private resolver. Production callers go through `Execute::run`.
/// Per-tenant isolation: `crate::tenant_scope(ctx, tenant_id)` (`Tools` + `Execute`).
pub(crate) struct Resolver {
    /// Tenant DB handle for `tenant_agents` and `public` lookups.
    pub tenant_db: Arc<TenantDb>,
    /// System registry (TOML/TOON) fallback.
    pub agent_registry: Arc<AgentRegistry>,
    /// Static config for system-tier fallback (optional when built from ctx).
    pub config: Option<Arc<std::collections::HashMap<String, AgentConfig>>>,
}

impl Resolver {
    /// Create a new resolver service.
    pub fn new(
        tenant_db: Arc<TenantDb>,
        agent_registry: Arc<AgentRegistry>,
        config: Arc<std::collections::HashMap<String, AgentConfig>>,
    ) -> Self {
        Self {
            tenant_db,
            agent_registry,
            config: Some(config),
        }
    }

    /// Build from `TenantDb` + `AgentRegistry` already on ctx (no factory provide).
    pub(crate) fn from_ctx(
        ctx: &Arc<cordis::Context>,
        agent_registry: Arc<AgentRegistry>,
    ) -> Option<Self> {
        Some(Self {
            tenant_db: ctx.get::<TenantDb>()?,
            agent_registry,
            config: None,
        })
    }

    /// Async 3-tier resolution: `tenant_db` user โ†’ community public โ†’ system config.
    ///
    /// Mirrors the free function `resolve_agent` but uses `self.tenant_db.pool()`
    /// via `sqlx` and `self.config`/`self.agent_registry` for the system tier.
    pub async fn resolve_async(
        &self,
        name: &str,
        user_id: &str,
    ) -> std::result::Result<(UserAgent, AgentSource), AppError> {
        let user_agent = sqlx::query_as::<_, UserAgent>(
            "SELECT * FROM user_agents WHERE user_id = $1 AND name = $2",
        )
        .bind(user_id)
        .bind(name)
        .fetch_optional(self.tenant_db.pool())
        .await
        .map_err(|e| AppError::Database(e.to_string()))?;
        let public_agent = sqlx::query_as::<_, UserAgent>(
            "SELECT * FROM user_agents WHERE is_public = true AND name = $1 LIMIT 1",
        )
        .bind(name)
        .fetch_optional(self.tenant_db.pool())
        .await
        .map_err(|e| AppError::Database(e.to_string()))?;
        let system_config_owned = self.agent_registry.get_config_any(name);
        let system_config = self
            .config
            .as_ref()
            .and_then(|c| c.get(name))
            .or(system_config_owned.as_ref());
        resolve_from_candidates(
            user_agent,
            public_agent,
            system_config,
            name,
            chrono::Utc::now().timestamp(),
        )
    }

    /// Resolve an agent by name using the isolate realm of `ctx` to derive the
    /// tenant label. Reads `ctx.isolate_label(TypeId::of::<crate::Execute>())`
    /// so per-tenant resolution flows through the Cordis isolate namespace rather
    /// than a throwaway method parameter.
    pub async fn resolve(
        &self,
        ctx: &Arc<cordis::Context>,
        name: &str,
    ) -> std::result::Result<(UserAgent, AgentSource), AppError> {
        let user_id = user_id_from_ctx(ctx, "");
        self.resolve_async(name, &user_id).await
    }
}

impl Service for Resolver {
    fn name(&self) -> &'static str {
        "Resolver"
    }

    fn init(
        &self,
        ctx: &Arc<cordis::Context>,
    ) -> std::pin::Pin<Box<dyn Future<Output = std::result::Result<Option<Box<dyn cordis::Disposable>>, CordisError>> + Send + '_>> {
        let ctx = ctx.clone();
        Box::pin(async move {
            let _ = ctx.inject::<crate::registry::AgentRegistry>().await;
            Ok(None)
        })
    }

    fn check(&self) -> bool {
        // Active when both sources are present; if DB unavailable, dependent
        // fibers should deactivate (guarded withdrawal).
        true
    }
}

/// Derive the effective user/tenant scope for agent resolution.
///
/// Precedence: isolate label for `Execute` (with a leading
/// `tenant:`/`user:` prefix stripped), then a non-empty
/// `ctx.get::<TenantContext>()` intercept id, then `fallback`.
pub fn user_id_from_ctx(ctx: &Arc<cordis::Context>, fallback: &str) -> String {
    crate::execution::user_id_from_ctx(ctx, fallback)
}

/// Resolve an agent for a user using the 3-tier hierarchy.
pub async fn resolve_agent(
    db: &dyn DatabaseClient,
    config: &std::collections::HashMap<String, AgentConfig>,
    user_id: &str,
    agent_name: String,
) -> Result<(UserAgent, String)> {
    let user_agent = db
        .get_user_agent_by_name(user_id, &agent_name)
        .await?;
    let public_agent = db.get_public_agent_by_name(&agent_name).await?;
    let system_config = config.get(&agent_name);

    let (agent, source) = resolve_from_candidates(
        user_agent,
        public_agent,
        system_config,
        &agent_name,
        chrono::Utc::now().timestamp(),
    )?;
    Ok((agent, source.as_str().into()))
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::AgentConfig;
    use ares_store::traits::{ConversationSummary, DatabaseClient};
    use ares_types::types::{MemoryFact, Message, MessageRole, Preference};
    use async_trait::async_trait;
    use std::collections::HashMap;

    const FIXED_NOW: i64 = 1_700_000_000;

    fn user_agent(name: &str, user_id: &str) -> UserAgent {
        UserAgent {
            id: format!("ua-{name}"),
            user_id: user_id.into(),
            name: name.into(),
            display_name: Some(format!("{name} display")),
            description: None,
            model: "gpt-4o".into(),
            system_prompt: Some("user prompt".into()),
            tools: r#"["calc"]"#.into(),
            max_tool_iterations: 5,
            parallel_tools: true,
            extra: r#"{"k":"v"}"#.into(),
            is_public: false,
            usage_count: 1,
            rating_sum: 4,
            rating_count: 1,
            created_at: FIXED_NOW - 100,
            updated_at: FIXED_NOW - 50,
        }
    }

    fn agent_config() -> AgentConfig {
        AgentConfig {
            model: "llama3".into(),
            system_prompt: Some("system prompt".into()),
            tools: vec!["search".into(), "calc".into()],
            max_tool_iterations: 7,
            parallel_tools: true,
            allowed_tools: None,
            extra: HashMap::new(),
            compaction_enabled: None,
        }
}

    fn minimal_overlay_config(agent_name: &str, cfg: AgentConfig) -> std::collections::HashMap<String, AgentConfig> {
        let mut config = std::collections::HashMap::new();
        config.insert(agent_name.to_string(), cfg);
        config
    }

    // โ”€โ”€ Pure resolver logic โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    #[test]
    fn resolve_prefers_user_over_community_and_system() {
        let u = user_agent("router", "u1");
        let c = user_agent("router", "");
        let cfg = agent_config();
        let (got, src) = resolve_from_candidates(
            Some(u.clone()),
            Some(c),
            Some(&cfg),
            "router",
            FIXED_NOW,
        )
        .unwrap();
        assert_eq!(src, AgentSource::User);
        assert_eq!(got.id, u.id);
    }

    #[test]
    fn resolve_prefers_community_over_system() {
        let c = user_agent("router", "");
        let cfg = agent_config();
        let (got, src) = resolve_from_candidates(None, Some(c.clone()), Some(&cfg), "router", FIXED_NOW)
            .unwrap();
        assert_eq!(src, AgentSource::Community);
        assert_eq!(got.id, c.id);
    }

    #[test]
    fn resolve_falls_back_to_system_config() {
        let cfg = agent_config();
        let (got, src) =
            resolve_from_candidates(None, None, Some(&cfg), "router", FIXED_NOW).unwrap();
        assert_eq!(src, AgentSource::System);
        assert_eq!(got.id, "system-router");
        assert_eq!(got.user_id, "system");
        assert_eq!(got.model, "llama3");
        assert_eq!(got.system_prompt.as_deref(), Some("system prompt"));
        assert_eq!(got.tools, r#"["search","calc"]"#);
        assert_eq!(got.max_tool_iterations, 7);
        assert!(got.parallel_tools);
        assert_eq!(got.created_at, FIXED_NOW);
        assert_eq!(got.updated_at, FIXED_NOW);
    }

    #[test]
    fn resolve_not_found_when_all_tiers_missing() {
        let err = resolve_from_candidates(None, None, None, "missing", FIXED_NOW).unwrap_err();
        match err {
            AppError::NotFound(msg) => assert!(msg.contains("missing")),
            other => panic!("expected NotFound, got {other:?}"),
        }
    }

    #[test]
    fn agent_source_as_str_labels() {
        assert_eq!(AgentSource::User.as_str(), "user");
        assert_eq!(AgentSource::Community.as_str(), "community");
        assert_eq!(AgentSource::System.as_str(), "system");
    }

    #[test]
    fn system_agent_from_config_serializes_tools_as_json() {
        let cfg = AgentConfig {
            tools: vec!["a".into()],
            ..agent_config()
        };
        let agent = system_agent_from_config("my-agent", &cfg, FIXED_NOW);
        assert_eq!(agent.name, "my-agent");
        assert_eq!(agent.tools, r#"["a"]"#);
        assert!(agent.is_public);
    }

    #[test]
    fn config_get_agent_matches_system_resolution() {
        let config = minimal_overlay_config("router", agent_config());
        let cfg = config.get("router").expect("agent in config");
        let (from_pure, _) =
            resolve_from_candidates(None, None, Some(cfg), "router", FIXED_NOW).unwrap();
        let from_helper = system_agent_from_config("router", cfg, FIXED_NOW);
        assert_eq!(from_pure.id, from_helper.id);
        assert_eq!(from_pure.model, from_helper.model);
    }

    #[test]
    fn config_get_agent_returns_none_for_unknown_name() {
        let config = minimal_overlay_config("router", agent_config());
        assert!(config.get("ghost").is_none());
    }

    // โ”€โ”€ Serde roundtrips โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    fn assert_agent_config_eq(a: &AgentConfig, b: &AgentConfig) {
        assert_eq!(a.model, b.model);
        assert_eq!(a.system_prompt, b.system_prompt);
        assert_eq!(a.tools, b.tools);
        assert_eq!(a.max_tool_iterations, b.max_tool_iterations);
        assert_eq!(a.parallel_tools, b.parallel_tools);
        assert_eq!(a.extra, b.extra);
    }

    #[test]
    fn agent_config_serde_roundtrip_json() {
        let original = agent_config();
        let json = serde_json::to_string(&original).unwrap();
        let decoded: AgentConfig = serde_json::from_str(&json).unwrap();
        assert_agent_config_eq(&original, &decoded);
    }

    #[test]
    fn agent_config_serde_roundtrip_toml() {
        let original = agent_config();
        let serialized = toml::to_string(&original).unwrap();
        let decoded: AgentConfig = toml::from_str(&serialized).unwrap();
        assert_agent_config_eq(&original, &decoded);
    }

    #[test]
    fn agent_source_serde_roundtrip() {
        for source in [
            AgentSource::User,
            AgentSource::Community,
            AgentSource::System,
        ] {
            let json = serde_json::to_string(&source).unwrap();
            let decoded: AgentSource = serde_json::from_str(&json).unwrap();
            assert_eq!(source, decoded);
        }
    }

    // โ”€โ”€ Async integration (mock DB) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    struct MockDb {
        user: Option<UserAgent>,
        public: Option<UserAgent>,
    }

    #[async_trait]
    impl DatabaseClient for MockDb {
        async fn create_user(
            &self,
            _: &str,
            _: &str,
            _: &str,
            _: &str,
        ) -> Result<()> {
            Ok(())
        }
        async fn get_user_by_email(&self, _: &str) -> Result<Option<ares_store::traits::User>> {
            Ok(None)
        }
        async fn get_user_by_id(&self, _: &str) -> Result<Option<ares_store::traits::User>> {
            Ok(None)
        }
        async fn create_session(&self, _: &str, _: &str, _: &str, _: i64) -> Result<()> {
            Ok(())
        }
        async fn validate_session(&self, _: &str) -> Result<Option<String>> {
            Ok(None)
        }
        async fn delete_session(&self, _: &str) -> Result<()> {
            Ok(())
        }
        async fn delete_session_by_token_hash(&self, _: &str) -> Result<()> {
            Ok(())
        }
        async fn create_conversation(&self, _: &str, _: &str, _: Option<&str>) -> Result<()> {
            Ok(())
        }
        async fn conversation_exists(&self, _: &str) -> Result<bool> {
            Ok(false)
        }
        async fn get_user_conversations(&self, _: &str) -> Result<Vec<ConversationSummary>> {
            Ok(vec![])
        }
        async fn get_conversation(
            &self,
            _: &str,
        ) -> Result<ares_store::postgres::Conversation> {
            Err(AppError::NotFound("conversation".into()))
        }
        async fn delete_conversation(&self, _: &str) -> Result<()> {
            Ok(())
        }
        async fn update_conversation_title(&self, _: &str, _: Option<&str>) -> Result<()> {
            Ok(())
        }
        async fn add_message(&self, _: &str, _: &str, _: MessageRole, _: &str) -> Result<()> {
            Ok(())
        }
        async fn get_conversation_history(&self, _: &str) -> Result<Vec<Message>> {
            Ok(vec![])
        }
        async fn store_memory_fact(&self, _: &MemoryFact) -> Result<()> {
            Ok(())
        }
        async fn get_user_memory(&self, _: &str) -> Result<Vec<MemoryFact>> {
            Ok(vec![])
        }
        async fn get_memory_by_category(&self, _: &str, _: &str) -> Result<Vec<MemoryFact>> {
            Ok(vec![])
        }
        async fn store_preference(&self, _: &str, _: &Preference) -> Result<()> {
            Ok(())
        }
        async fn get_user_preferences(&self, _: &str) -> Result<Vec<Preference>> {
            Ok(vec![])
        }
        async fn get_preference(
            &self,
            _: &str,
            _: &str,
            _: &str,
        ) -> Result<Option<Preference>> {
            Ok(None)
        }
        async fn get_user_agent_by_name(
            &self,
            _: &str,
            _: &str,
        ) -> Result<Option<UserAgent>> {
            Ok(self.user.clone())
        }
        async fn get_public_agent_by_name(&self, _: &str) -> Result<Option<UserAgent>> {
            Ok(self.public.clone())
        }
        async fn list_user_agents(&self, _: &str) -> Result<Vec<UserAgent>> {
            Ok(vec![])
        }
        async fn list_public_agents(&self, _: u32, _: u32) -> Result<Vec<UserAgent>> {
            Ok(vec![])
        }
        async fn create_user_agent(&self, _: &UserAgent) -> Result<()> {
            Ok(())
        }
        async fn update_user_agent(&self, _: &UserAgent) -> Result<()> {
            Ok(())
        }
        async fn delete_user_agent(&self, _: &str, _: &str) -> Result<bool> {
            Ok(false)
        }
    }

    #[tokio::test]
    async fn resolve_agent_user_tier_via_db() {
        let db = MockDb {
            user: Some(user_agent("router", "u1")),
            public: Some(user_agent("router", "")),
        };
        let config = minimal_overlay_config("router", agent_config());
        let (agent, source) = resolve_agent(&db, &config, "u1", "router".into())
            .await
            .unwrap();
        assert_eq!(source, "user");
        assert_eq!(agent.user_id, "u1");
    }

    #[tokio::test]
    async fn resolve_agent_system_tier_from_config() {
        let db = MockDb {
            user: None,
            public: None,
        };
        let config = minimal_overlay_config("router", agent_config());
        let (agent, source) = resolve_agent(&db, &config, "u1", "router".into())
            .await
            .unwrap();
        assert_eq!(source, "system");
        assert_eq!(agent.id, "system-router");
    }

    #[tokio::test]
    async fn resolve_agent_not_found_error_path() {
        let db = MockDb {
            user: None,
            public: None,
        };
        let config = minimal_overlay_config("other", agent_config());
        let err = resolve_agent(&db, &config, "u1", "missing".into())
            .await
            .unwrap_err();
        assert!(matches!(err, AppError::NotFound(_)));
    }

    #[cfg(feature = "postgres")]
    #[tokio::test]
    async fn resolve_uses_isolate_label_for_scope() {
        // Cordis design (ยง4): the tenant scope for agent resolution is derived
        // from the context's isolate namespace, not a throwaway method param.
        // A tenant-isolated context ("tenant:acme") must make the resolver
        // resolve the user tier under that tenant label. The pure helper
        // `user_id_from_ctx` drives the DB-aware 3-tier resolution: it reads
        // ctx.isolate_label(TypeId::of::<crate::Execute>()) and strips the
        // "tenant:" prefix to yield the effective user scope.

        let ctx: Arc<cordis::Context> = cordis::Context::new_root();
        let fallback = "anon";
        // Untagged context -> falls back to the provided default.
        assert_eq!(
            user_id_from_ctx(&ctx, fallback),
            "anon",
            "no isolate label -> fallback scope"
        );

        let tenant_ctx = crate::tenant_scope(&ctx, "acme");
        assert_eq!(
            user_id_from_ctx(&tenant_ctx, fallback),
            "acme",
            "tenant_scope('acme') -> scope 'acme'"
        );

        let user_ctx = ctx.isolate::<crate::Execute>("user:u42");
        assert_eq!(
            user_id_from_ctx(&user_ctx, fallback),
            "u42",
            "isolate label 'user:u42' -> scope 'u42'"
        );
    }

    #[test]
    fn user_id_from_ctx_reads_tenant_context_intercept() {
        use ares_types::models::{TenantContext, TenantTier};

        let root: Arc<cordis::Context> = cordis::Context::new_root();
        let ctx = root.with_intercept(TenantContext::new("acme".into(), TenantTier::Pro));
        assert_eq!(user_id_from_ctx(&ctx, "anon"), "acme");
    }

    #[test]
    fn user_id_from_ctx_isolate_label_wins_over_intercept() {
        use ares_types::models::{TenantContext, TenantTier};

        let root: Arc<cordis::Context> = cordis::Context::new_root();
        let intercepted =
            root.with_intercept(TenantContext::new("from-intercept".into(), TenantTier::Pro));
        let isolated = crate::tenant_scope(&intercepted, "from-isolate");
        assert_eq!(user_id_from_ctx(&isolated, "anon"), "from-isolate");
    }
}