feat(workflows): advertise host-bound forward lifecycle contract

Signed-off-by: Brain <1a02c72794dcd0f07058a353bc3a81f4028b8c77c92c87fce6d5c8b85970a20b@buzz.block.builderlab.xyz>
This commit is contained in:
Brain
2026-09-12 10:24:35 -06:00
parent 30fef2c247
commit 1e634152ed
2 changed files with 61 additions and 1 deletions

View File

@@ -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"
);
}

View File

@@ -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<serde_json::Value>,
/// Forward workflow lifecycle contract, bound to this request host.
#[serde(skip_serializing_if = "Option::is_none")]
pub workflows: Option<WorkflowDescriptor>,
/// URL of the relay software repository.
pub software: String,
/// Relay software version string.
@@ -69,6 +72,16 @@ pub struct RelayInfo {
pub relay_self: Option<String>,
}
/// 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
}