Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 51 additions & 12 deletions tests/steps/worker_steps.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#![allow(
clippy::expect_used,
clippy::unwrap_used,
reason = "simplify test output"
)]
//! Behavioural test steps for the worker task.
//!
//! These steps drive the Cucumber scenarios that verify the worker posts
//! queued comments and handles failures gracefully.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
//!
//! Uses Wiremock to stub the GitHub Issues API and yaque for the on-disk queue.
//! See also: `test-support::octocrab_for()` and `yaque::channel()`.

use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -34,6 +36,10 @@ impl std::fmt::Debug for WorkerWorld {
}

#[given("a queued comment request")]
#[expect(
clippy::expect_used,
reason = "test harness: fail fast on setup/IO errors"
)]
async fn queued_request(world: &mut WorkerWorld) {
let dir = TempDir::new().expect("tempdir");
let mut base = temp_config(&dir);
Expand Down Expand Up @@ -76,10 +82,21 @@ async fn github_error(world: &mut WorkerWorld) {
}

#[when("the worker runs briefly")]
#[expect(
clippy::expect_used,
reason = "test harness: fail fast on world state errors"
)]
async fn worker_runs(world: &mut WorkerWorld) {
let cfg = world.cfg.as_ref().unwrap().clone();
let rx = world.receiver.take().unwrap();
let server = world.server.as_ref().unwrap();
let cfg = world
.cfg
.as_ref()
.expect("configuration should be initialised")
.clone();
let rx = world
.receiver
.take()
.expect("receiver should be initialised");
let server = world.server.as_ref().expect("server should be initialised");
let octocrab = octocrab_for(server);
let handle = tokio::spawn(async move {
let _ = run_worker(cfg, rx, octocrab).await;
Expand All @@ -90,15 +107,37 @@ async fn worker_runs(world: &mut WorkerWorld) {
}

#[then("the comment is posted")]
#[expect(
clippy::expect_used,
reason = "test harness: expect wiremock state in assertion"
)]
async fn comment_posted(world: &mut WorkerWorld) {
let server = world.server.as_ref().unwrap();
assert!(!server.received_requests().await.unwrap().is_empty());
let server = world.server.as_ref().expect("server should be initialised");
assert!(
!server
.received_requests()
.await
.expect("inbound requests should be recorded")
.is_empty()
);
}

#[then("the queue retains the job")]
#[expect(
clippy::expect_used,
reason = "test harness: expect fs state in assertion"
)]
fn queue_retains(world: &mut WorkerWorld) {
let cfg = world.cfg.as_ref().unwrap();
assert!(std::fs::read_dir(&cfg.queue_path).unwrap().count() > 0);
let cfg = world
.cfg
.as_ref()
.expect("configuration should be initialised");
assert!(
std::fs::read_dir(&cfg.queue_path)
.expect("queue directory should be readable")
.count()
> 0
);
}

impl Drop for WorkerWorld {
Expand Down
Loading