Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/fkst-common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub struct DepartmentDecl {
#[serde(default)]
pub produces: Vec<String>,
#[serde(default)]
pub published_seam: Vec<String>,
#[serde(default)]
pub ephemeral: Vec<String>,
pub stall_window: String,
#[serde(default)]
Expand Down
100 changes: 98 additions & 2 deletions crates/fkst-common/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ pub fn validate_runtime_key(key: &str) -> Result<&str, FkstError> {
/// - queues default to one active consumer unless `fanout = true`
/// - queues with only producers emit startup warnings
/// - closed-world queues with only consumers are rejected unless a built-in
/// provider contract explicitly owns the queue
/// provider contract owns the queue or a consuming department publishes it
/// as an external seam
/// - partial-graph queues with only consumers emit startup warnings
/// - every department's `lua` path must exist on disk
/// - queue capacity > 0
Expand Down Expand Up @@ -218,6 +219,15 @@ pub fn validate_with_scope(
if let Some(contract) = built_in_provider_for_queue(qname) {
producers.push(contract.producer_label.to_string());
}
if let Some((department_name, _)) = cfg.department.iter().find(|(_, department)| {
department.consumes.iter().any(|queue| queue == qname)
&& department.published_seam.iter().any(|queue| queue == qname)
}) {
producers.push(format!(
"external seam declared by department '{}'",
department_name
));
}
let consumers = queue_consumers(cfg, qname);
if producers.is_empty() && consumers.is_empty() {
return Err(FkstError::Schema(format!(
Expand Down Expand Up @@ -443,6 +453,7 @@ mod tests {
owner_namespace: "pkg".to_string(),
consumes: vec!["tick".into()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: Vec::new(),
stall_window: "30s".into(),
graph_json: false,
Expand Down Expand Up @@ -563,7 +574,7 @@ mod tests {
}

#[test]
fn consumer_without_producer_fails() {
fn closed_world_consumer_without_published_seam_fails() {
let tmp = tempdir().unwrap();
let lua = touch(tmp.path(), "d.lua");
let mut cfg = cfg_minimal(&lua);
Expand All @@ -588,6 +599,91 @@ mod tests {
assert!(message.contains("no producer"), "{message}");
}

#[test]
fn closed_world_published_seam_satisfies_producer_requirement() {
let tmp = tempdir().unwrap();
let lua = touch(tmp.path(), "d.lua");
let mut cfg = cfg_minimal(&lua);
cfg.queue.insert(
"external_ingress".into(),
QueueDecl {
capacity: 10,
fanout: false,
},
);
let external_consumer = serde_json::from_value(serde_json::json!({
"lua": "d.lua",
"owner_root": ".",
"owner_namespace": "pkg",
"consumes": ["external_ingress"],
"produces": [],
"published_seam": ["external_ingress"],
"ephemeral": [],
"stall_window": "30s",
"graph_json": false,
"retry": null
}))
.unwrap();
cfg.department
.insert("external_consumer".into(), external_consumer);

let warnings = validate_with_scope(&cfg, tmp.path(), ValidationScope::ClosedWorld).unwrap();

assert!(warnings.is_empty(), "{warnings:?}");
}

#[test]
fn closed_world_published_seam_does_not_exempt_other_departments_queue() {
// The external-seam exemption requires the SAME department to both
// consume the queue AND declare it in its own published_seam. A
// department that publishes a seam it does not consume must not exempt
// a different department's producerless consumed queue.
let tmp = tempdir().unwrap();
let lua = touch(tmp.path(), "d.lua");
let mut cfg = cfg_minimal(&lua);
cfg.queue.insert(
"shared_ingress".into(),
QueueDecl {
capacity: 10,
fanout: false,
},
);
let publisher = serde_json::from_value(serde_json::json!({
"lua": "d.lua",
"owner_root": ".",
"owner_namespace": "pkg",
"consumes": [],
"produces": [],
"published_seam": ["shared_ingress"],
"ephemeral": [],
"stall_window": "30s",
"graph_json": false,
"retry": null
}))
.unwrap();
cfg.department.insert("publisher".into(), publisher);
let consumer = serde_json::from_value(serde_json::json!({
"lua": "d.lua",
"owner_root": ".",
"owner_namespace": "pkg",
"consumes": ["shared_ingress"],
"produces": [],
"published_seam": [],
"ephemeral": [],
"stall_window": "30s",
"graph_json": false,
"retry": null
}))
.unwrap();
cfg.department.insert("consumer".into(), consumer);

let err = validate_with_scope(&cfg, tmp.path(), ValidationScope::ClosedWorld).unwrap_err();
let message = err.to_string();

assert!(message.contains("shared_ingress"), "{message}");
assert!(message.contains("no producer"), "{message}");
}

#[test]
fn partial_graph_consumer_without_producer_warns() {
let tmp = tempdir().unwrap();
Expand Down
5 changes: 5 additions & 0 deletions crates/fkst-common/tests/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fn cfg_minimal(lua_file: &Path) -> Config {
owner_namespace: "pkg".to_string(),
consumes: vec!["tick".into()],
produces: vec![],
published_seam: vec![],
ephemeral: vec![],
stall_window: "30m".into(),
graph_json: false,
Expand Down Expand Up @@ -73,6 +74,7 @@ fn department_decl(lua_file: &Path, consumes: Vec<&str>, produces: Vec<&str>) ->
owner_namespace: "pkg".to_string(),
consumes: consumes.into_iter().map(String::from).collect(),
produces: produces.into_iter().map(String::from).collect(),
published_seam: vec![],
ephemeral: vec![],
stall_window: "30m".into(),
graph_json: false,
Expand Down Expand Up @@ -355,6 +357,7 @@ fn duplicate_consumers_without_fanout_rejected() {
owner_namespace: "pkg".to_string(),
consumes: vec!["tick".into()],
produces: vec![],
published_seam: vec![],
ephemeral: vec![],
stall_window: "30m".into(),
graph_json: false,
Expand Down Expand Up @@ -382,6 +385,7 @@ fn duplicate_consumers_with_fanout_pass() {
owner_namespace: "pkg".to_string(),
consumes: vec!["tick".into()],
produces: vec![],
published_seam: vec![],
ephemeral: vec![],
stall_window: "30m".into(),
graph_json: false,
Expand Down Expand Up @@ -413,6 +417,7 @@ fn mixed_retry_consumers_on_fanout_queue_pass() {
owner_namespace: "pkg".to_string(),
consumes: vec!["tick".into()],
produces: vec![],
published_seam: vec![],
ephemeral: vec![],
stall_window: "30m".into(),
graph_json: false,
Expand Down
2 changes: 2 additions & 0 deletions crates/fkst-framework/src/sdk_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ mod tests {
owner_namespace: "host".to_string(),
consumes: vec!["host.done".to_string()],
produces: vec![],
published_seam: vec![],
ephemeral: vec![],
stall_window: "30s".to_string(),
graph_json: false,
Expand All @@ -308,6 +309,7 @@ mod tests {
owner_namespace: "pkg".to_string(),
consumes: vec!["pkg.tick".to_string()],
produces: vec!["host.done".to_string()],
published_seam: vec![],
ephemeral: vec!["pkg.tick".to_string()],
stall_window: "45s".to_string(),
graph_json: false,
Expand Down
1 change: 1 addition & 0 deletions crates/fkst-framework/src/self_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ fn minimal_config(lua_rel: PathBuf, owner_root: &std::path::Path) -> Config {
owner_namespace: "pkg".to_string(),
consumes: vec!["self_test".into()],
produces: vec![],
published_seam: vec![],
ephemeral: vec![],
stall_window: "30s".into(),
graph_json: false,
Expand Down
11 changes: 11 additions & 0 deletions crates/fkst-framework/src/supervise/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,7 @@ units = [{units}]
owner_namespace: package_namespace(root),
consumes: vec!["jobs".to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: Vec::new(),
stall_window: stall_window.to_string(),
graph_json: false,
Expand Down Expand Up @@ -1555,6 +1556,7 @@ units = [{units}]
owner_namespace: "pkg".to_string(),
consumes: vec!["dead_letter".to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: vec!["dead_letter".to_string()],
stall_window: "30s".to_string(),
graph_json: false,
Expand Down Expand Up @@ -1590,6 +1592,7 @@ units = [{units}]
owner_namespace: "pkg".to_string(),
consumes: vec!["fkst.failure_fact".to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: vec!["fkst.failure_fact".to_string()],
stall_window: "30s".to_string(),
graph_json: false,
Expand Down Expand Up @@ -1631,6 +1634,7 @@ units = [{units}]
owner_namespace: "github-devloop".to_string(),
consumes: vec!["github-devloop.tick".to_string()],
produces: vec!["consensus.proposal".to_string()],
published_seam: Vec::new(),
ephemeral: vec!["github-devloop.tick".to_string()],
stall_window: "30s".to_string(),
graph_json: false,
Expand Down Expand Up @@ -1667,6 +1671,7 @@ units = [{units}]
owner_namespace: owner_namespace.clone(),
consumes: vec!["tick".to_string()],
produces: vec!["done".to_string()],
published_seam: Vec::new(),
ephemeral: vec!["tick".to_string()],
stall_window: "30s".to_string(),
graph_json: false,
Expand Down Expand Up @@ -1730,6 +1735,7 @@ units = [{units}]
owner_namespace: "pkg".to_string(),
consumes: vec!["done".to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: vec!["done".to_string()],
stall_window: "30s".to_string(),
graph_json: false,
Expand Down Expand Up @@ -1816,6 +1822,7 @@ units = [{units}]
owner_namespace: "pkg".to_string(),
consumes: vec!["done".to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: vec!["done".to_string()],
stall_window: "30s".to_string(),
graph_json: false,
Expand Down Expand Up @@ -1903,6 +1910,7 @@ units = [{units}]
owner_namespace: package_namespace(temp.path()),
consumes: vec!["jobs".to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: Vec::new(),
stall_window: "30s".to_string(),
graph_json: false,
Expand Down Expand Up @@ -2148,6 +2156,7 @@ units = [{units}]
owner_namespace: package_namespace(temp.path()),
consumes: vec!["jobs".to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: Vec::new(),
stall_window: "30s".to_string(),
graph_json: false,
Expand Down Expand Up @@ -2765,6 +2774,7 @@ units = [{units}]
owner_namespace: "pkg".to_string(),
consumes: vec!["next".to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: Vec::new(),
stall_window: "30s".to_string(),
graph_json: false,
Expand Down Expand Up @@ -2815,6 +2825,7 @@ units = [{units}]
owner_namespace: "pkg".to_string(),
consumes: vec!["next".to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: Vec::new(),
stall_window: "30s".to_string(),
graph_json: false,
Expand Down
3 changes: 3 additions & 0 deletions crates/fkst-framework/src/supervise/delivery_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ mod tests {
owner_namespace: "pkg".to_string(),
consumes: vec!["jobs".to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: if ephemeral {
vec!["jobs".to_string()]
} else {
Expand Down Expand Up @@ -740,6 +741,7 @@ mod tests {
owner_namespace: owner_namespace.to_string(),
consumes: vec![queue_name.to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: Vec::new(),
stall_window: "30s".to_string(),
graph_json: false,
Expand Down Expand Up @@ -775,6 +777,7 @@ mod tests {
owner_namespace: "pkg".to_string(),
consumes: vec!["merge-ready".to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: if ephemeral {
vec!["merge-ready".to_string()]
} else {
Expand Down
1 change: 1 addition & 0 deletions crates/fkst-framework/src/supervise/graph_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ fn scan_departments(
owner_namespace: graph_root.namespace.clone(),
consumes,
produces,
published_seam: published_seam.clone(),
ephemeral,
stall_window: if spec.stall_window.trim().is_empty() {
defaults.department_default_stall_window.clone()
Expand Down
1 change: 1 addition & 0 deletions crates/fkst-framework/src/supervise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ mod tests {
owner_namespace: "pkg".to_string(),
consumes: vec!["jobs".to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: if ephemeral {
vec!["jobs".to_string()]
} else {
Expand Down
1 change: 1 addition & 0 deletions crates/fkst-framework/src/supervise/source_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ mod tests {
owner_namespace: "pkg".to_string(),
consumes: vec![queue_name.to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: vec![queue_name.to_string()],
stall_window: "30s".to_string(),
graph_json: false,
Expand Down
2 changes: 2 additions & 0 deletions crates/fkst-framework/tests/supervise_graph_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,7 @@ fn duplicate_department_name_fails_closed() {
owner_namespace: "pkg".to_string(),
consumes: vec!["tick".into()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: Vec::new(),
stall_window: "30s".into(),
graph_json: false,
Expand All @@ -2007,6 +2008,7 @@ fn duplicate_department_name_fails_closed() {
owner_namespace: "pkg".to_string(),
consumes: vec!["tick".into()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: Vec::new(),
stall_window: "30s".into(),
graph_json: false,
Expand Down
1 change: 1 addition & 0 deletions crates/fkst-framework/tests/supervise_source_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fn fanout_router(queue_name: &str) -> (Fanout, DeliveryRouter) {
lua: "departments/test/main.lua".into(),
consumes: vec![queue_name.to_string()],
produces: Vec::new(),
published_seam: Vec::new(),
ephemeral: vec![queue_name.to_string()],
stall_window: "30s".to_string(),
graph_json: false,
Expand Down
Loading