Skip to content

Commit 66fe50e

Browse files
feat(resource): make resync DING subjects actionable
agent-identity: dev3.direct.omp.2cshu64q agent-persona: generalist agent-supervisor: unavailable agent-tool: OMP agent-tool-version: 18.0.9 agent-runtime: OMP 18.0.9 tooling-profile: dotfiles@b607597
1 parent 2ec73eb commit 66fe50e

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

src/resource_profile_supervisor.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ fn emit_pending_at(
995995
&active.desired.binding_name,
996996
digest,
997997
);
998-
let subject = format!("resource {} changed", active.desired.binding_name);
998+
let subject = publication_subject(&active.desired.binding_name, &topics);
999999
crate::event::emit_builtin_resync(
10001000
catalog_root,
10011001
this_host,
@@ -1014,6 +1014,14 @@ fn publication_event_id(recipient: &str, binding: &str, digest: SnapshotDigest)
10141014
hash_text(&format!("resource-profile\0{recipient}\0{binding}\0{digest}"))
10151015
}
10161016

1017+
fn publication_subject(binding: &str, topics: &[String]) -> String {
1018+
if topics.is_empty() {
1019+
format!("resource {binding} changed: snapshot updated")
1020+
} else {
1021+
format!("resource {binding} changed: {}", topics.join(", "))
1022+
}
1023+
}
1024+
10171025
fn binding_state_directory(desired: &DesiredBinding) -> anyhow::Result<PathBuf> {
10181026
let state = lexical_absolute(&crate::run::state_root())?;
10191027
Ok(state
@@ -1130,6 +1138,21 @@ mod tests {
11301138
assert!(!owner_matches(None, &old));
11311139
}
11321140

1141+
#[test]
1142+
fn publication_subject_names_the_semantic_topics_visible_in_ding() {
1143+
assert_eq!(
1144+
publication_subject(
1145+
"st2-resource-profiles-pr",
1146+
&["ci.failure".to_owned(), "mergeability.conflict".to_owned()]
1147+
),
1148+
"resource st2-resource-profiles-pr changed: ci.failure, mergeability.conflict"
1149+
);
1150+
assert_eq!(
1151+
publication_subject("review", &[]),
1152+
"resource review changed: snapshot updated"
1153+
);
1154+
}
1155+
11331156
#[test]
11341157
fn stale_protocol_failure_does_not_remove_the_replacement_process() {
11351158
let old = RuntimeOwner::new(

src/resync.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ fn emit_resync(
13461346
bus_id: &str,
13471347
transition: &PendingTransition,
13481348
) -> bool {
1349-
let subject = format!("resource {} changed", transition.binding);
1349+
let subject = resync_subject(&transition.binding);
13501350
match crate::event::emit_builtin_resync(
13511351
root,
13521352
this_host,
@@ -1368,6 +1368,14 @@ fn emit_resync(
13681368
}
13691369
}
13701370

1371+
fn resync_subject(binding: &str) -> String {
1372+
if binding == "declaration" {
1373+
"resource bindings changed: re-read agent spec".to_owned()
1374+
} else {
1375+
format!("resource {binding} changed: re-read carrier")
1376+
}
1377+
}
1378+
13711379
fn read_state(path: &Path, containment_root: Option<&Path>) -> std::io::Result<CarrierState> {
13721380
match containment_root {
13731381
Some(root) => read_confined(path, root),
@@ -1565,6 +1573,18 @@ mod tests {
15651573
}
15661574
}
15671575

1576+
#[test]
1577+
fn resync_subject_gives_the_agent_a_semantic_next_action() {
1578+
assert_eq!(
1579+
resync_subject("declaration"),
1580+
"resource bindings changed: re-read agent spec"
1581+
);
1582+
assert_eq!(
1583+
resync_subject("goal"),
1584+
"resource goal changed: re-read carrier"
1585+
);
1586+
}
1587+
15681588
fn owner_incarnation(seed: u64) -> crate::event::StreamOwnerIncarnation {
15691589
crate::event::StreamOwnerIncarnation::for_test(seed, seed + 1, 42, seed + 2)
15701590
}

0 commit comments

Comments
 (0)