Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Tests: fix the pre-push event and native-drop upload flakes (#628)

Oleksandr Ivanchenkoe07d0d4a3baa
diff --git a/frontend/e2e/native-drop.mjs b/frontend/e2e/native-drop.mjs
index 737b42cd..ead816fc 100644
--- a/frontend/e2e/native-drop.mjs
+++ b/frontend/e2e/native-drop.mjs
@@ -69,6 +69,11 @@ const file = (name, body) => (fs.writeFileSync(path.join(files, name), body), pa
// ---------- the browser ----------
const browser = BROWSER === 'webkit' ? await pw.webkit.launch() : await pw.chromium.launch({ executablePath: process.env.CHROMIUM || undefined, args: ['--no-sandbox'] });
console.log(`${MODE} drops in ${BROWSER}`);
+// The chips show before the POST /api/attachments responses come back, so a check that counts
+// `uploads` first waits for `n` of them, at most 5 s (CI flake on #614, Nov 14).
+const uploadsArrive = async (uploads, n, ms = 5000) => {
+ for (const end = Date.now() + ms; uploads.length < n && Date.now() < end; ) await sleep(50);
+};
const results = [];
const check = (id, name, pass, detail = '') => {
results.push({ id, name, pass: !!pass, detail });
@@ -192,6 +197,7 @@ async function landsIn(id, name, label, { mention = false } = {}) {
const field = await page.locator('textarea').first().inputValue();
const seq = await phases(page);
await page.screenshot({ path: path.join(OUT, `${id}.png`) });
+ await uploadsArrive(uploads, 2);
const ok = before === 'over' && got.includes(name1) && got.includes(name2) && uploads.length === 2 && uploads.every((s) => s < 300) && after === null && !errors.length;
check(id, name, ok, JSON.stringify({ layerBeforeDrop: before, chips: got, uploads, layerAfter: after, field, errors }));
// "-" before "landing" is the 0.8.0 exit effect's first commit; React flushes that effect in the same
diff --git a/tests/prepush_test.rs b/tests/prepush_test.rs
index cf597ec6..b8003315 100644
--- a/tests/prepush_test.rs
+++ b/tests/prepush_test.rs
@@ -88,6 +88,31 @@ async fn settled_sha(env: &Env, space: &str, sha: &str) -> kwnt::db::dev_prepush
panic!("the pre-push card of {sha} never settled");
}
+/// The `dev_prepush` events on `rx` up to and including `(id, status)`, then any others already
+/// queued. `check` saves the card and only then sends its event, so a test that saw the saved row
+/// in [`settled`] waits here (at most 5 s) for the event instead of racing it (CI flake on #620,
+/// Nov 14). On a timeout it returns what it saw, for the caller's assert to show.
+async fn prepush_events_until(rx: &mut tokio::sync::broadcast::Receiver<RuntimeEvent>, id: &str, status: &str) -> Vec<(String, String)> {
+ use tokio::sync::broadcast::error::{RecvError, TryRecvError};
+ let mut seen: Vec<(String, String)> = Vec::new();
+ let deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(5);
+ while !seen.iter().any(|(i, s)| i == id && s == status) {
+ match tokio::time::timeout_at(deadline, rx.recv()).await {
+ Ok(Ok(RuntimeEvent::DevPrepush { id, status, .. })) => seen.push((id, status)),
+ Ok(Ok(_)) | Ok(Err(RecvError::Lagged(_))) => {}
+ Ok(Err(RecvError::Closed)) | Err(_) => break,
+ }
+ }
+ loop {
+ match rx.try_recv() {
+ Ok(RuntimeEvent::DevPrepush { id, status, .. }) => seen.push((id, status)),
+ Ok(_) | Err(TryRecvError::Lagged(_)) => {}
+ Err(_) => break,
+ }
+ }
+ seen
+}
+
#[tokio::test]
async fn a_switched_off_test_blocks_the_push_until_the_person_overrides() {
let env = setup().await;
@@ -126,12 +151,7 @@ async fn a_switched_off_test_blocks_the_push_until_the_person_overrides() {
assert_eq!(card["fresh_eyes"]["checked"], true, "{card}");
assert_eq!(card["fresh_eyes"]["saw"], json!(["diff"]));
assert_eq!(card["fresh_eyes"]["reviewer_kwant_id"], json!(reviewer));
- let mut seen = Vec::new();
- while let Ok(e) = rx.try_recv() {
- if let RuntimeEvent::DevPrepush { id, status, .. } = e {
- seen.push((id, status));
- }
- }
+ let seen = prepush_events_until(&mut rx, &row.id, BLOCKED).await;
assert_eq!(seen, [(row.id.clone(), "checking".to_string()), (row.id.clone(), "blocked".to_string())]);
// Still blocked: the bot is told why and how to clear it, and no new card is made