forked from vhaudiquet/rhema-claw
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78fdec4f49 |
No files matched your search
@@ -126,6 +126,30 @@ fn interactive_dispatch() -> DispatcherConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The forge dispatcher's timing: the library defaults, except the lease
|
||||||
|
/// TTL.
|
||||||
|
///
|
||||||
|
/// A forge turn is not a chat step. The handler clones a repository,
|
||||||
|
/// reads it, and may build and test a fix — tens of minutes of wall
|
||||||
|
/// clock — and nothing renews the lease once the turn is under way:
|
||||||
|
/// `SessionContext::poll_inbox` renews, and the handler calls it once, at
|
||||||
|
/// the start; the commit hook that runs between tool calls *checkpoints*,
|
||||||
|
/// which fails on a lapsed lease instead of extending one. So the TTL is
|
||||||
|
/// a hard ceiling on a whole turn: cross it and the turn dies on its next
|
||||||
|
/// tool call, after which the driver's own checkpoint and release both
|
||||||
|
/// report `Expired` and the key ends with no outcome recorded — a silent
|
||||||
|
/// kill, indistinguishable from a pass that found nothing.
|
||||||
|
///
|
||||||
|
/// `DispatcherConfig::default`'s ten minutes are the spec's example
|
||||||
|
/// values, sized for a single agent step. An hour matches the
|
||||||
|
/// interactive lane's choice for the same reason: the work is long.
|
||||||
|
pub fn forge_dispatch() -> DispatcherConfig {
|
||||||
|
DispatcherConfig {
|
||||||
|
lease_ttl_millis: 3_600_000,
|
||||||
|
..DispatcherConfig::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The resident daemon: the extension set's sources (the forge watches,
|
/// The resident daemon: the extension set's sources (the forge watches,
|
||||||
/// the task scheduler, the coding jobs, the calendar reminders), the
|
/// the task scheduler, the coding jobs, the calendar reminders), the
|
||||||
/// three drivers, and the HTTP surface.
|
/// three drivers, and the HTTP surface.
|
||||||
@@ -154,8 +178,8 @@ impl Daemon {
|
|||||||
/// Assembles the daemon over `config`: the shared SQLite store, one
|
/// Assembles the daemon over `config`: the shared SQLite store, one
|
||||||
/// source per forge kind reading the watch table, the interactive
|
/// source per forge kind reading the watch table, the interactive
|
||||||
/// dispatcher, and both handlers running `provider`. `dispatch` is
|
/// dispatcher, and both handlers running `provider`. `dispatch` is
|
||||||
/// the forge dispatcher's timing — the resident loop uses the
|
/// the forge dispatcher's timing — [`forge_dispatch`] in both shapes,
|
||||||
/// defaults, `--once` zeroes the debounce.
|
/// with `--once` zeroing the debounce.
|
||||||
pub fn build(
|
pub fn build(
|
||||||
config: &ClawConfig,
|
config: &ClawConfig,
|
||||||
backends: Arc<BackendRegistry>,
|
backends: Arc<BackendRegistry>,
|
||||||
@@ -580,7 +604,7 @@ pub async fn run_once(
|
|||||||
) -> Result<TickReport, ClawError> {
|
) -> Result<TickReport, ClawError> {
|
||||||
let dispatch = DispatcherConfig {
|
let dispatch = DispatcherConfig {
|
||||||
debounce_window_millis: 0,
|
debounce_window_millis: 0,
|
||||||
..DispatcherConfig::default()
|
..forge_dispatch()
|
||||||
};
|
};
|
||||||
let daemon = Daemon::build(config, backends, dispatch)?;
|
let daemon = Daemon::build(config, backends, dispatch)?;
|
||||||
daemon.bootstrap().await?;
|
daemon.bootstrap().await?;
|
||||||
@@ -591,6 +615,20 @@ pub async fn run_once(
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_forge_dispatcher_leases_for_a_turn_not_a_step() {
|
||||||
|
let dispatch = forge_dispatch();
|
||||||
|
assert_eq!(
|
||||||
|
dispatch.lease_ttl_millis, 3_600_000,
|
||||||
|
"an hour: a turn clones, reads, builds and tests"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
dispatch.debounce_window_millis,
|
||||||
|
DispatcherConfig::default().debounce_window_millis,
|
||||||
|
"the rest stays the library's defaults"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn the_interactive_dispatcher_dispatches_now_and_leases_long() {
|
fn the_interactive_dispatcher_dispatches_now_and_leases_long() {
|
||||||
let dispatch = interactive_dispatch();
|
let dispatch = interactive_dispatch();
|
||||||
|
|||||||
@@ -565,22 +565,6 @@ impl ForgeSource {
|
|||||||
fed += 1;
|
fed += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The row is decided — dispatched, surfaced, or ignored — so
|
|
||||||
// consume it: `mark_read` is what stops the feed returning
|
|
||||||
// it. Deciding without consuming is a loop: the poll's cursor
|
|
||||||
// never passes a row the forge still considers unread, so
|
|
||||||
// every pass re-decides it and re-dispatches a turn for a
|
|
||||||
// thread that already has one, and a restart (the cursor is
|
|
||||||
// in memory) replays the whole unread feed.
|
|
||||||
//
|
|
||||||
// Best-effort: an unread row costs a repeat, never a lost
|
|
||||||
// event, so a failed call is logged and the poll carries on.
|
|
||||||
if let Err(err) = client.mark_read(notification).await {
|
|
||||||
eprintln!(
|
|
||||||
"[claw] warning: mark-read of {} failed: {err}",
|
|
||||||
notification.id
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if let Some(cursor) = page.cursor {
|
if let Some(cursor) = page.cursor {
|
||||||
self.account_cursors
|
self.account_cursors
|
||||||
@@ -705,65 +689,6 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The account poll consumes what it decides. The feed is
|
|
||||||
/// at-least-once — the cursor never passes a row the forge still
|
|
||||||
/// considers unread, and a restart asks for the whole unread feed
|
|
||||||
/// again — so a row that is triaged but not marked read comes back
|
|
||||||
/// with the same dedup id on the next pass, and every pass dispatches
|
|
||||||
/// a fresh turn for a thread that already has one.
|
|
||||||
#[tokio::test]
|
|
||||||
async fn a_triaged_account_notification_is_marked_read() {
|
|
||||||
let server = MockServer::start().await;
|
|
||||||
Mock::given(method("GET"))
|
|
||||||
.and(path("/notifications"))
|
|
||||||
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!([
|
|
||||||
{
|
|
||||||
"id": 42188,
|
|
||||||
"unread": true,
|
|
||||||
"reason": "mention",
|
|
||||||
"updated_at": "2026-10-05T12:00:00Z",
|
|
||||||
"subject": {
|
|
||||||
"title": "Add the widget flange",
|
|
||||||
"url": "https://api.github.com/repos/acme/widgets/pulls/142",
|
|
||||||
"type": "PullRequest"
|
|
||||||
},
|
|
||||||
"repository": { "full_name": "acme/widgets" }
|
|
||||||
}
|
|
||||||
])))
|
|
||||||
.mount(&server)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let store = Arc::new(ClawStore::in_memory().expect("store opens"));
|
|
||||||
let (dispatcher, accounts, notifications) = test_parts(store.clone());
|
|
||||||
// The store mints the id; the watch row is what names it.
|
|
||||||
let account = accounts
|
|
||||||
.put(rhema_identity::AccountDraft::new(
|
|
||||||
"forge bot",
|
|
||||||
"github",
|
|
||||||
rhema_identity::Secret::new(rhema_identity::SecretKind::Token, "acct-tok"),
|
|
||||||
))
|
|
||||||
.expect("account lands");
|
|
||||||
store
|
|
||||||
.add_account_watch("github", Some(&server.uri()), &account.id)
|
|
||||||
.expect("account watch lands");
|
|
||||||
let source = ForgeSource::new(&dispatcher, "github", store, accounts, notifications);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
source.detect().await.expect("the pass runs"),
|
|
||||||
1,
|
|
||||||
"a mention dispatches a turn"
|
|
||||||
);
|
|
||||||
|
|
||||||
// The read route keys on the notification, not the thread.
|
|
||||||
let requests = server.received_requests().await.expect("recording is on");
|
|
||||||
let reads: Vec<_> = requests
|
|
||||||
.iter()
|
|
||||||
.filter(|request| request.method.as_str() == "PUT")
|
|
||||||
.collect();
|
|
||||||
assert_eq!(reads.len(), 1, "one mark-read per triaged row");
|
|
||||||
assert_eq!(reads[0].url.path(), "/notifications/threads/42188");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The parts a test source polls through, all in memory.
|
/// The parts a test source polls through, all in memory.
|
||||||
fn test_parts(
|
fn test_parts(
|
||||||
store: Arc<ClawStore>,
|
store: Arc<ClawStore>,
|
||||||
@@ -1047,7 +972,6 @@ mod tests {
|
|||||||
title: Some("Add the flange".to_owned()),
|
title: Some("Add the flange".to_owned()),
|
||||||
url: None,
|
url: None,
|
||||||
timestamp: Timestamp::parse("2026-10-08T00:00:00Z").expect("parses"),
|
timestamp: Timestamp::parse("2026-10-08T00:00:00Z").expect("parses"),
|
||||||
read_key: Some("1".to_owned()),
|
|
||||||
raw: serde_json::json!({}),
|
raw: serde_json::json!({}),
|
||||||
};
|
};
|
||||||
let payload = |notification: &Notification| {
|
let payload = |notification: &Notification| {
|
||||||
@@ -1092,7 +1016,6 @@ mod tests {
|
|||||||
title: Some("a title".to_owned()),
|
title: Some("a title".to_owned()),
|
||||||
url: None,
|
url: None,
|
||||||
timestamp: Timestamp::parse("2026-11-21T00:00:00Z").expect("parses"),
|
timestamp: Timestamp::parse("2026-11-21T00:00:00Z").expect("parses"),
|
||||||
read_key: Some("1".to_owned()),
|
|
||||||
raw: serde_json::json!({}),
|
raw: serde_json::json!({}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -977,7 +977,6 @@ mod tests {
|
|||||||
"title": "Add the widget flange",
|
"title": "Add the widget flange",
|
||||||
"url": null,
|
"url": null,
|
||||||
"timestamp": "2026-10-03T09:00:00Z",
|
"timestamp": "2026-10-03T09:00:00Z",
|
||||||
"read_key": "42188",
|
|
||||||
"raw": {},
|
"raw": {},
|
||||||
}))
|
}))
|
||||||
.expect("notification fixture parses")
|
.expect("notification fixture parses")
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ pub use bootstrap::{
|
|||||||
render_system,
|
render_system,
|
||||||
};
|
};
|
||||||
pub use config::{ClawConfig, ConfigError};
|
pub use config::{ClawConfig, ConfigError};
|
||||||
pub use daemon::{ClawError, Daemon, TickReport, run_once};
|
pub use daemon::{ClawError, Daemon, TickReport, forge_dispatch, run_once};
|
||||||
pub use environment::write_report;
|
pub use environment::write_report;
|
||||||
pub use extension::{ClawExtension, ExtensionDeps, Extensions, Lanes};
|
pub use extension::{ClawExtension, ExtensionDeps, Extensions, Lanes};
|
||||||
pub use forge::ForgeSource;
|
pub use forge::ForgeSource;
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ use std::path::PathBuf;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use rhema_claw::{ClawConfig, ClawError, Daemon, run_once};
|
use rhema_claw::{ClawConfig, ClawError, Daemon, forge_dispatch, run_once};
|
||||||
use rhema_rsd::{DispatcherConfig, Outcome};
|
use rhema_rsd::Outcome;
|
||||||
|
|
||||||
/// `rhema-claw` — the resident forge-watching agent daemon.
|
/// `rhema-claw` — the resident forge-watching agent daemon.
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
@@ -135,7 +135,7 @@ async fn run(args: Args) -> Result<(), ClawError> {
|
|||||||
// reads it next to the config that turns it on.
|
// reads it next to the config that turns it on.
|
||||||
config.validate_surface()?;
|
config.validate_surface()?;
|
||||||
eprintln!("[claw] note: resident sessions run tool calls without approval prompts");
|
eprintln!("[claw] note: resident sessions run tool calls without approval prompts");
|
||||||
let daemon = Daemon::build(&config, backends, DispatcherConfig::default())?;
|
let daemon = Daemon::build(&config, backends, forge_dispatch())?;
|
||||||
daemon.run().await
|
daemon.run().await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,17 +230,6 @@ pub struct Notification {
|
|||||||
/// When the notification row was last touched. The poll cursor
|
/// When the notification row was last touched. The poll cursor
|
||||||
/// advances to the newest of these.
|
/// advances to the newest of these.
|
||||||
pub timestamp: Timestamp,
|
pub timestamp: Timestamp,
|
||||||
/// What the backend's read-marking route keys on, when it has one —
|
|
||||||
/// GitHub's `PUT /notifications/threads/{id}` takes the numeric
|
|
||||||
/// notification id, which [`Notification::id`] embeds only as text
|
|
||||||
/// (its suffix is the dedup timestamp, not the row's identity).
|
|
||||||
/// `None` on a backend with no read route.
|
|
||||||
///
|
|
||||||
/// Defaulted on deserialize: rows already in a dispatcher inbox were
|
|
||||||
/// written before this field existed, and a replay must not fail on
|
|
||||||
/// one.
|
|
||||||
#[serde(default)]
|
|
||||||
pub read_key: Option<String>,
|
|
||||||
/// The untouched wire row, minus the keys the notification lifts.
|
/// The untouched wire row, minus the keys the notification lifts.
|
||||||
pub raw: serde_json::Value,
|
pub raw: serde_json::Value,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,7 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
use crate::error::ForgeError;
|
use crate::error::ForgeError;
|
||||||
use crate::event::{
|
use crate::event::{ForgeEvent, ForgeThreadKind, NotificationPage, RepoRef, Snapshot, Timestamp};
|
||||||
ForgeEvent, ForgeThreadKind, Notification, NotificationPage, RepoRef, Snapshot, Timestamp,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// One poll's worth of activity, with the cursor to continue from.
|
/// One poll's worth of activity, with the cursor to continue from.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@@ -102,25 +100,6 @@ pub trait Forge: Send + Sync {
|
|||||||
since: Option<&Timestamp>,
|
since: Option<&Timestamp>,
|
||||||
) -> Result<NotificationPage, ForgeError>;
|
) -> Result<NotificationPage, ForgeError>;
|
||||||
|
|
||||||
/// Marks `notification` read on the forge, so the account's feed
|
|
||||||
/// stops returning it.
|
|
||||||
///
|
|
||||||
/// The feed is at-least-once: `since` is inclusive at the boundary
|
|
||||||
/// and the cursor only ever advances to the newest row seen, so a row
|
|
||||||
/// that the poll cannot get past — anything at or before the cursor,
|
|
||||||
/// every poll — comes back for as long as the forge considers it
|
|
||||||
/// unread. Dedup ids absorb a repeat *within* one pass, but a row
|
|
||||||
/// re-read on the next pass is a fresh event with the same id, and a
|
|
||||||
/// restart drops the in-memory cursor entirely and asks for the whole
|
|
||||||
/// unread feed again. Deciding a row is therefore not the same as
|
|
||||||
/// consuming it; this is the call that consumes it.
|
|
||||||
///
|
|
||||||
/// The default is a no-op: a backend with no read route repeats its
|
|
||||||
/// rows, which its dedup ids absorb — noisier, never wrong.
|
|
||||||
async fn mark_read(&self, _notification: &Notification) -> Result<(), ForgeError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The login this client authenticates as — the backend's own answer
|
/// The login this client authenticates as — the backend's own answer
|
||||||
/// to "who am I".
|
/// to "who am I".
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -585,9 +585,6 @@ fn notification_event(row: &WireNotification) -> Result<Option<Notification>, Fo
|
|||||||
title: subject.title.clone(),
|
title: subject.title.clone(),
|
||||||
url: None,
|
url: None,
|
||||||
timestamp: updated,
|
timestamp: updated,
|
||||||
// No read-marking route in this backend yet; the feed's repeat is
|
|
||||||
// absorbed by the dedup id.
|
|
||||||
read_key: None,
|
|
||||||
raw: Value::Object(row.raw.clone()),
|
raw: Value::Object(row.raw.clone()),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,17 +120,6 @@ impl GitHubForge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A PUT builder for `path` with auth applied.
|
|
||||||
fn put(&self, path: &str) -> reqwest::RequestBuilder {
|
|
||||||
let base = &self.base_url;
|
|
||||||
let request = self.http.put(format!("{base}{path}"));
|
|
||||||
if self.token.is_empty() {
|
|
||||||
request
|
|
||||||
} else {
|
|
||||||
request.bearer_auth(&self.token)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Follows `per_page`/`page` pagination until a short page.
|
/// Follows `per_page`/`page` pagination until a short page.
|
||||||
async fn paged<T: DeserializeOwned>(
|
async fn paged<T: DeserializeOwned>(
|
||||||
&self,
|
&self,
|
||||||
@@ -520,9 +509,6 @@ fn notification_event(row: &WireNotification) -> Result<Option<Notification>, Fo
|
|||||||
title: subject.title.clone(),
|
title: subject.title.clone(),
|
||||||
url: None,
|
url: None,
|
||||||
timestamp: updated,
|
timestamp: updated,
|
||||||
// `PUT /notifications/threads/{id}` is keyed on this same id:
|
|
||||||
// the notification, not the thread's number.
|
|
||||||
read_key: Some(id.to_string()),
|
|
||||||
raw: Value::Object(row.raw.clone()),
|
raw: Value::Object(row.raw.clone()),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -750,22 +736,6 @@ impl Forge for GitHubForge {
|
|||||||
}
|
}
|
||||||
Ok(NotificationPage::finish(notifications, since))
|
Ok(NotificationPage::finish(notifications, since))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn mark_read(&self, notification: &Notification) -> Result<(), ForgeError> {
|
|
||||||
let Some(read_key) = notification.read_key.as_deref() else {
|
|
||||||
// A row built without one is a shape break, not a forge
|
|
||||||
// outage: say so instead of silently re-reading it forever.
|
|
||||||
return Err(ForgeError::Parse(format!(
|
|
||||||
"notification {} carries no read key",
|
|
||||||
notification.id
|
|
||||||
)));
|
|
||||||
};
|
|
||||||
let path = format!("/notifications/threads/{read_key}");
|
|
||||||
let response = self.put(&path).send().await.map_err(ForgeError::network)?;
|
|
||||||
// 205 Reset Content: marked, nothing to decode.
|
|
||||||
ensure_success(response).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -957,7 +927,6 @@ mod tests {
|
|||||||
notification.id,
|
notification.id,
|
||||||
"github:notification:27210544329@2026-11-21T22:33:00Z"
|
"github:notification:27210544329@2026-11-21T22:33:00Z"
|
||||||
);
|
);
|
||||||
assert_eq!(notification.read_key.as_deref(), Some("27210544329"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -978,7 +947,6 @@ mod tests {
|
|||||||
notification.id,
|
notification.id,
|
||||||
"github:notification:42188@2026-10-08T12:00:00Z"
|
"github:notification:42188@2026-10-08T12:00:00Z"
|
||||||
);
|
);
|
||||||
assert_eq!(notification.read_key.as_deref(), Some("42188"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -331,9 +331,6 @@ fn todo_notification(row: &WireTodo) -> Result<Option<Notification>, ForgeError>
|
|||||||
title: target.title.clone(),
|
title: target.title.clone(),
|
||||||
url: row.target_url.clone(),
|
url: row.target_url.clone(),
|
||||||
timestamp: updated,
|
timestamp: updated,
|
||||||
// No read-marking route in this backend yet; the feed's repeat is
|
|
||||||
// absorbed by the dedup id.
|
|
||||||
read_key: None,
|
|
||||||
raw: Value::Object(row.raw.clone()),
|
raw: Value::Object(row.raw.clone()),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,6 @@ mod tests {
|
|||||||
title: None,
|
title: None,
|
||||||
url: None,
|
url: None,
|
||||||
timestamp: Timestamp::parse("2026-10-08T00:00:00Z").expect("parses"),
|
timestamp: Timestamp::parse("2026-10-08T00:00:00Z").expect("parses"),
|
||||||
read_key: Some("1".to_owned()),
|
|
||||||
raw: serde_json::json!({}),
|
raw: serde_json::json!({}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
//! wiremock server. Zero network.
|
//! wiremock server. Zero network.
|
||||||
|
|
||||||
use rhema_forge_integration::{
|
use rhema_forge_integration::{
|
||||||
EventKind, Forge, ForgeError, ForgeThreadKind, GitHubForge, Notification, NotificationReason,
|
EventKind, Forge, ForgeError, ForgeThreadKind, GitHubForge, NotificationReason, RepoRef,
|
||||||
RepoRef, Timestamp,
|
Timestamp,
|
||||||
};
|
};
|
||||||
use serde_json::{Value, json};
|
use serde_json::{Value, json};
|
||||||
use wiremock::matchers::{header, method, path, query_param};
|
use wiremock::matchers::{header, method, path, query_param};
|
||||||
@@ -533,89 +533,6 @@ async fn notifications_without_a_cursor_still_return_the_newest_seen() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A notification row, as the account's feed sends it.
|
|
||||||
fn notification_row(id: i64, reason: &str, number: u64) -> Value {
|
|
||||||
json!({
|
|
||||||
"id": id,
|
|
||||||
"unread": true,
|
|
||||||
"reason": reason,
|
|
||||||
"updated_at": "2026-10-05T12:00:00Z",
|
|
||||||
"subject": {
|
|
||||||
"title": "Add the widget flange",
|
|
||||||
"url": format!("https://api.github.com/repos/acme/widgets/issues/{number}"),
|
|
||||||
"type": "Issue"
|
|
||||||
},
|
|
||||||
"repository": { "full_name": "acme/widgets" }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deciding a row is not consuming it: the feed keeps returning anything
|
|
||||||
/// the account still has unread, so the read route is what ends the
|
|
||||||
/// repeat. It keys on the notification's own id, not the thread number —
|
|
||||||
/// the dedup id keeps that integer only as text.
|
|
||||||
#[tokio::test]
|
|
||||||
async fn marking_a_notification_read_puts_its_thread() {
|
|
||||||
let server = MockServer::start().await;
|
|
||||||
Mock::given(method("GET"))
|
|
||||||
.and(path("/notifications"))
|
|
||||||
.respond_with(
|
|
||||||
ResponseTemplate::new(200).set_body_json(json!([notification_row(
|
|
||||||
42188,
|
|
||||||
"review_requested",
|
|
||||||
142
|
|
||||||
)])),
|
|
||||||
)
|
|
||||||
.mount(&server)
|
|
||||||
.await;
|
|
||||||
Mock::given(method("PUT"))
|
|
||||||
.and(path("/notifications/threads/42188"))
|
|
||||||
.and(header("authorization", "Bearer tok"))
|
|
||||||
.respond_with(ResponseTemplate::new(205))
|
|
||||||
.mount(&server)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let forge = forge(&server);
|
|
||||||
let page = forge.notifications(None).await.expect("poll succeeds");
|
|
||||||
let notification = &page.notifications[0];
|
|
||||||
forge.mark_read(notification).await.expect("marks read");
|
|
||||||
|
|
||||||
let requests = server.received_requests().await.expect("recording is on");
|
|
||||||
let puts: Vec<_> = requests
|
|
||||||
.iter()
|
|
||||||
.filter(|request| request.method.as_str() == "PUT")
|
|
||||||
.collect();
|
|
||||||
assert_eq!(puts.len(), 1, "one read call, on the row's id");
|
|
||||||
assert_eq!(puts[0].url.path(), "/notifications/threads/42188");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A row that reaches the caller with no read key is a shape break, not a
|
|
||||||
/// silent no-op: re-reading the same thread forever is the failure this
|
|
||||||
/// whole route exists to stop.
|
|
||||||
#[tokio::test]
|
|
||||||
async fn a_notification_without_a_read_key_fails_loudly() {
|
|
||||||
// Defaulted on deserialize, so this is also the row an inbox written
|
|
||||||
// before the field existed decodes to.
|
|
||||||
let notification: Notification = serde_json::from_value(json!({
|
|
||||||
"id": "github:notification:42188@2026-10-05T12:00:00Z",
|
|
||||||
"reason": "review_requested",
|
|
||||||
"repo": { "owner": "acme", "name": "widgets" },
|
|
||||||
"number": 142,
|
|
||||||
"is_pr": false,
|
|
||||||
"actor": null,
|
|
||||||
"title": "Add the widget flange",
|
|
||||||
"url": null,
|
|
||||||
"timestamp": "2026-10-05T12:00:00Z",
|
|
||||||
"raw": {}
|
|
||||||
}))
|
|
||||||
.expect("a read-key-less row parses");
|
|
||||||
|
|
||||||
let err = GitHubForge::new("tok")
|
|
||||||
.mark_read(¬ification)
|
|
||||||
.await
|
|
||||||
.expect_err("loud failure");
|
|
||||||
assert!(matches!(err, ForgeError::Parse(_)), "got: {err:?}");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The mention gate asks the forge who the credential is, because a token
|
/// The mention gate asks the forge who the credential is, because a token
|
||||||
/// read from a watch row names nobody.
|
/// read from a watch row names nobody.
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
Reference in new issue
Block a user