Skip to repository content176 lines · 6.4 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T06:52:16.705Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
agent_registry_store.rs
1use std::{future, sync::Arc, time::Duration};
2
3use fs::FakeFs;
4use gpui::TestAppContext;
5use http_client::{AsyncBody, FakeHttpClient, HttpClient, Response};
6use project::{AgentRegistryStore, RegistryAgent};
7use serde_json::json;
8
9use crate::init_test;
10
11#[gpui::test]
12async fn registry_refresh_times_out_when_fetch_never_completes(cx: &mut TestAppContext) {
13 init_test(cx);
14
15 let fs = FakeFs::new(cx.executor());
16 let http_client =
17 FakeHttpClient::create(|_| future::pending::<anyhow::Result<Response<AsyncBody>>>())
18 as Arc<dyn HttpClient>;
19
20 let registry_store =
21 cx.update(|cx| AgentRegistryStore::init_global(cx, fs.clone(), http_client));
22 cx.run_until_parked();
23
24 cx.executor().advance_clock(Duration::from_secs(31));
25 cx.run_until_parked();
26
27 registry_store.update(cx, |store, _| {
28 assert!(!store.is_fetching());
29 assert!(
30 store
31 .fetch_error()
32 .is_some_and(|error| error.contains("timed out after 30s")),
33 "expected registry fetch timeout error, got {:?}",
34 store.fetch_error()
35 );
36 });
37}
38
39#[gpui::test]
40async fn registry_refresh_does_not_block_sequentially_on_hung_icon_downloads(
41 cx: &mut TestAppContext,
42) {
43 init_test(cx);
44
45 let fs = FakeFs::new(cx.executor());
46 let http_client = FakeHttpClient::create(|request| async move {
47 if request.uri().to_string().contains("registry.json") {
48 Ok(Response::builder()
49 .status(200)
50 .body(AsyncBody::from(
51 serde_json::to_string(&json!({
52 "version": "1",
53 "agents": [
54 {
55 "id": "slow-icon-a",
56 "name": "Slow Icon A",
57 "version": "1.0.0",
58 "description": "An agent with a slow icon.",
59 "icon": "https://example.test/slow-icon-a.svg",
60 "distribution": {
61 "npx": {
62 "package": "slow-icon-a"
63 }
64 }
65 },
66 {
67 "id": "slow-icon-b",
68 "name": "Slow Icon B",
69 "version": "1.0.0",
70 "description": "Another agent with a slow icon.",
71 "icon": "https://example.test/slow-icon-b.svg",
72 "distribution": {
73 "npx": {
74 "package": "slow-icon-b"
75 }
76 }
77 },
78 {
79 "id": "slow-icon-c",
80 "name": "Slow Icon C",
81 "version": "1.0.0",
82 "description": "A third agent with a slow icon.",
83 "icon": "https://example.test/slow-icon-c.svg",
84 "distribution": {
85 "npx": {
86 "package": "slow-icon-c"
87 }
88 }
89 }
90 ]
91 }))
92 .unwrap(),
93 ))
94 .unwrap())
95 } else {
96 future::pending::<anyhow::Result<Response<AsyncBody>>>().await
97 }
98 }) as Arc<dyn HttpClient>;
99
100 let registry_store =
101 cx.update(|cx| AgentRegistryStore::init_global(cx, fs.clone(), http_client));
102 cx.run_until_parked();
103
104 cx.executor().advance_clock(Duration::from_secs(11));
105 cx.run_until_parked();
106
107 registry_store.update(cx, |store, _| {
108 assert!(!store.is_fetching());
109 assert_eq!(store.agents().len(), 3);
110 assert_eq!(store.agents()[0].id().as_ref(), "slow-icon-a");
111 assert_eq!(store.agents()[1].id().as_ref(), "slow-icon-b");
112 assert_eq!(store.agents()[2].id().as_ref(), "slow-icon-c");
113 assert_eq!(store.fetch_error(), None);
114 });
115}
116
117#[gpui::test]
118async fn registry_refresh_preserves_optional_binary_checksums(cx: &mut TestAppContext) {
119 init_test(cx);
120
121 let checksum = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
122 let fs = FakeFs::new(cx.executor());
123 let http_client = FakeHttpClient::create(move |_| async move {
124 let body = serde_json::to_vec(&json!({
125 "version": "1",
126 "agents": [{
127 "id": "binary-agent",
128 "name": "Binary Agent",
129 "version": "1.0.0",
130 "description": "A binary agent.",
131 "distribution": {
132 "binary": {
133 "darwin-aarch64": {
134 "archive": "https://example.test/agent.zip",
135 "sha256": checksum,
136 "cmd": "./agent"
137 },
138 "linux-x86_64": {
139 "archive": "https://example.test/agent.zip",
140 "cmd": "./agent"
141 }
142 }
143 }
144 }]
145 }))?;
146 Ok(Response::builder()
147 .status(200)
148 .body(AsyncBody::from(body))?)
149 }) as Arc<dyn HttpClient>;
150
151 let registry_store =
152 cx.update(|cx| AgentRegistryStore::init_global(cx, fs.clone(), http_client));
153 cx.run_until_parked();
154
155 registry_store.read_with(cx, |store, _| {
156 let Some(RegistryAgent::Binary(agent)) = store.agents().first() else {
157 panic!("expected a binary registry agent");
158 };
159
160 assert_eq!(
161 agent
162 .targets
163 .get("darwin-aarch64")
164 .and_then(|target| target.sha256.as_deref()),
165 Some(checksum)
166 );
167 assert!(
168 agent
169 .targets
170 .get("linux-x86_64")
171 .is_some_and(|target| target.sha256.is_none())
172 );
173 assert_eq!(store.fetch_error(), None);
174 });
175}
176