fix(forge): consume a decided account notification
android / debug (pull_request) Successful in 2m14s
android / release (pull_request) Skipped
ci / test (pull_request) Failing after 33s
ci / chart (pull_request) Successful in 4s
ci / docker (pull_request) Successful in 1m29s
ci / checks (pull_request) Successful in 1m3s
ci / web (pull_request) Successful in 13s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (pull_request) Skipped
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (pull_request) Skipped
ci / publish-edge-chart (pull_request) Skipped
android / debug (pull_request) Successful in 2m14s
android / release (pull_request) Skipped
ci / test (pull_request) Failing after 33s
ci / chart (pull_request) Successful in 4s
ci / docker (pull_request) Successful in 1m29s
ci / checks (pull_request) Successful in 1m3s
ci / web (pull_request) Successful in 13s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (pull_request) Skipped
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (pull_request) Skipped
ci / publish-edge-chart (pull_request) Skipped
The account feed is at-least-once in a way the dedup ids do not cover.
`since` is inclusive at the boundary and `NotificationPage::finish`
advances its cursor only to the newest row seen, so a row the poll cannot
get past — anything at or before the cursor, which is every poll — comes
back for as long as the forge still considers it unread. Nothing marked
it read, and the daemon's cursor map is in memory, so a restart asked for
the whole unread feed again.
The result is a re-dispatch loop: the same notification id re-triaged
every pass, a fresh turn for a thread that already has one, and a second
comment on that thread if the first turn ever finished inside its lease.
Observed live on `vhaudiquet/orcaslicer-snap#10`: key revision 1 → 2 at
the 00:35 poll, `inbox_depth: 0`, no outcome — a re-dispatch of a turn
that was already running.
So consume what the poll decides:
- `Forge::mark_read` — a new default no-op on the trait, implemented for
GitHub as `PUT /notifications/threads/{id}`;
- `Notification::read_key` carries what that route keys on (GitHub keys
on the notification id, which the dedup id embeds only as text), and
defaults on deserialize so a payload already in an inbox still decodes;
- `poll_account` marks each row read once it is triaged — dispatched,
surfaced, or ignored; best-effort, since an unread row costs a repeat
and never a lost event.
Gitea and GitLab keep the no-op: neither has an account watch here yet.
This commit is contained in:
1 parent
c65f7fe962
commit
e07499f0b7
9 files changed
+237
-3
No files matched your search
@@ -2,8 +2,8 @@
|
||||
//! wiremock server. Zero network.
|
||||
|
||||
use rhema_forge_integration::{
|
||||
EventKind, Forge, ForgeError, ForgeThreadKind, GitHubForge, NotificationReason, RepoRef,
|
||||
Timestamp,
|
||||
EventKind, Forge, ForgeError, ForgeThreadKind, GitHubForge, Notification, NotificationReason,
|
||||
RepoRef, Timestamp,
|
||||
};
|
||||
use serde_json::{Value, json};
|
||||
use wiremock::matchers::{header, method, path, query_param};
|
||||
@@ -533,6 +533,89 @@ 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
|
||||
/// read from a watch row names nobody.
|
||||
#[tokio::test]
|
||||
|
||||
Reference in new issue
Block a user