From 1e634152ed96647fb59675745bd34c1b9d70f8c5 Mon Sep 17 00:00:00 2001 From: Brain <1a02c72794dcd0f07058a353bc3a81f4028b8c77c92c87fce6d5c8b85970a20b@buzz.block.builderlab.xyz> Date: Sat, 12 Sep 2026 10:24:35 -0600 Subject: [PATCH] feat(workflows): advertise host-bound forward lifecycle contract Signed-off-by: Brain <1a02c72794dcd0f07058a353bc3a81f4028b8c77c92c87fce6d5c8b85970a20b@buzz.block.builderlab.xyz> --- .../workflow_lifecycle/postgres_tests.rs | 40 +++++++++++++++++++ crates/buzz-relay/src/nip11.rs | 22 +++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/crates/buzz-relay/src/handlers/workflow_lifecycle/postgres_tests.rs b/crates/buzz-relay/src/handlers/workflow_lifecycle/postgres_tests.rs index 7ba5628ead..2c3b947d54 100644 --- a/crates/buzz-relay/src/handlers/workflow_lifecycle/postgres_tests.rs +++ b/crates/buzz-relay/src/handlers/workflow_lifecycle/postgres_tests.rs @@ -646,3 +646,43 @@ async fn ingest_rejects_alternate_workflow_deletion_entrances_before_storage() { assert_eq!(f.live().await, before, "workflow remains untouched"); } } + +#[tokio::test] +#[ignore = "requires isolated PostgreSQL"] +async fn nip11_workflow_contract_requires_bound_host_and_stable_identity() { + let mut f = Fixture::new().await; + // No stable key: no forward compatibility promise, even on a mapped host. + let state = Arc::get_mut(&mut f.state).expect("sole state owner"); + Arc::make_mut(&mut state.config).relay_private_key = None; + let info = crate::nip11::nip11_document(&f.state, f.tenant.host()).await; + assert!(info.workflows.is_none()); + let state = Arc::get_mut(&mut f.state).expect("sole state owner"); + Arc::make_mut(&mut state.config).relay_private_key = + Some(state.relay_keypair.secret_key().to_secret_hex()); + let info = crate::nip11::nip11_document(&f.state, f.tenant.host()).await; + let descriptor = info.workflows.expect("mapped stable relay advertises"); + assert_eq!(descriptor.lifecycle, 1); + assert_eq!(descriptor.host, f.tenant.host()); + assert_eq!( + info.relay_self, + Some(f.state.relay_keypair.public_key().to_hex()) + ); + assert!(info + .supported_extensions + .expect("extensions") + .contains(&"buzz-workflows".into())); + for host in ["", "unmapped-workflow.invalid"] { + let info = crate::nip11::nip11_document(&f.state, host).await; + assert!(info.workflows.is_none(), "unmapped host must not advertise"); + assert!(!info + .supported_extensions + .expect("extensions") + .contains(&"buzz-workflows".into())); + } + f.pool.close().await; + let info = crate::nip11::nip11_document(&f.state, f.tenant.host()).await; + assert!( + info.workflows.is_none(), + "failed binding must not advertise" + ); +} diff --git a/crates/buzz-relay/src/nip11.rs b/crates/buzz-relay/src/nip11.rs index e6b18cdd0f..3df57e2114 100644 --- a/crates/buzz-relay/src/nip11.rs +++ b/crates/buzz-relay/src/nip11.rs @@ -43,6 +43,9 @@ pub struct RelayInfo { /// NIP-PL executor descriptor. Present only when push delivery is configured. #[serde(skip_serializing_if = "Option::is_none")] pub push: Option, + /// Forward workflow lifecycle contract, bound to this request host. + #[serde(skip_serializing_if = "Option::is_none")] + pub workflows: Option, /// URL of the relay software repository. pub software: String, /// Relay software version string. @@ -69,6 +72,16 @@ pub struct RelayInfo { pub relay_self: Option, } +/// Positive evidence of atomic definition/runtime saves and canonical forward deletion. +/// This does not reconcile historical split state or grant execution authority. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct WorkflowDescriptor { + /// Lifecycle contract revision (not a software version or supported-kind list). + pub lifecycle: u32, + /// Normalized, resolved request host, including a non-default port. + pub host: String, +} + /// Public capability descriptor for relay-proxied GIF search. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct GifDescriptor { @@ -208,6 +221,7 @@ impl RelayInfo { supported_nips, supported_extensions: Some(supported_extensions), push: None, + workflows: None, software: "https://github.com/block/buzz".to_string(), version: env!("CARGO_PKG_VERSION").to_string(), limitation: Some(relay_limitation(max_message_length)), @@ -293,7 +307,7 @@ pub(crate) async fn nip11_document(state: &crate::state::AppState, raw_host: &st admin_api.as_deref(), state.config.klipy.as_ref().map(|_| "klipy"), ); - let tenant_host = if state.config.push_enabled { + let tenant_host = if state.config.push_enabled || relay_self.is_some() { crate::tenant::bind_community(&state.db, raw_host) .await .ok() @@ -313,6 +327,12 @@ pub(crate) async fn nip11_document(state: &crate::state::AppState, raw_host: &st .push("nip-pl".to_string()); info.push = Some(push); } + if let (Some(_), Some(host)) = (relay_self, tenant_host) { + info.supported_extensions + .get_or_insert_default() + .push("buzz-workflows".to_string()); + info.workflows = Some(WorkflowDescriptor { lifecycle: 1, host }); + } info }