fix(enabled): close disabled-script execution on the async paths (review)
Holistic Phase-1 review found the "a disabled script can't execute via any path" guarantee (§4.3) held only for the sync user-route, the execute-by-id bypass, and the trigger outbox arm — three paths still ran disabled scripts: - Queue arm: `list_active_queue_consumers` filtered the trigger's `enabled` but not the bound script's. Add `JOIN scripts … AND s.enabled = TRUE` so a disabled script's queue trigger stops consuming. - Async-HTTP (202) + queued invoke() arms: `build_http_request` / `build_invoke_request` hardcoded `active: true`. Set it to `script.enabled`, and MOVE the dispatcher's fire-time `active` drop to after the source-kind match so it covers all three arms uniformly (previously trigger-only). - `invoke()` (script-to-script): `resolve_id`/`resolve_name` checked cross-app isolation but not `enabled`. A disabled target now resolves to NotFound (indistinguishable from absent), matching the data plane. Also (review LOW/§4.7): - The route-on/script-off 404 returned `NotFound(script_id)`, leaking the internal id and distinguishable from absent. Return the same flat "no route matches" 404 as the unmatched case. - Add the §4.7 "enabled endpoint with no route and no trigger" reachability warning (was unimplemented; only disabled-target shipped). Tested: manager-core lib 368 + orchestrator 75 + 22 project-tool journeys (incl. a new enabled-route→disabled-script flat-404 e2e) green; clippy -D warnings clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -473,6 +473,9 @@ impl ApplyService {
|
||||
// deployed-but-unreachable. Not an error (it's valid desired state),
|
||||
// but surfaced so the operator isn't surprised by a silent 404.
|
||||
report.warnings.extend(disabled_target_warnings(bundle));
|
||||
report
|
||||
.warnings
|
||||
.extend(unreachable_endpoint_warnings(bundle));
|
||||
|
||||
let bundle_scripts: HashMap<String, &BundleScript> = bundle
|
||||
.scripts
|
||||
@@ -1426,6 +1429,31 @@ fn reject_reserved_path(path: &str) -> Result<(), ApplyError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// §4.7 reachability warning: an *enabled* endpoint script with no route and
|
||||
/// no trigger has no event surface — it's only reachable via the
|
||||
/// execute-by-id bypass / `invoke()`. Modules are exempt (never invoked
|
||||
/// directly); disabled endpoints are intentionally inert, so skip them.
|
||||
fn unreachable_endpoint_warnings(bundle: &Bundle) -> Vec<String> {
|
||||
let bound: HashSet<&str> = bundle
|
||||
.routes
|
||||
.iter()
|
||||
.map(|r| r.script.as_str())
|
||||
.chain(bundle.triggers.iter().map(BundleTrigger::script))
|
||||
.collect();
|
||||
bundle
|
||||
.scripts
|
||||
.iter()
|
||||
.filter(|s| s.kind == ScriptKind::Endpoint && s.enabled && !bound.contains(s.name.as_str()))
|
||||
.map(|s| {
|
||||
format!(
|
||||
"endpoint `{}` has no route or trigger — only reachable via the \
|
||||
execute-by-id bypass / invoke()",
|
||||
s.name
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// §4.7 reachability warnings: an *enabled* route or trigger bound to a
|
||||
/// script the manifest marks *disabled* is deployed but unreachable (the
|
||||
/// route 404s, the trigger won't fire). Valid desired state, so a warning —
|
||||
@@ -2179,6 +2207,37 @@ mod tests {
|
||||
assert!(disabled_target_warnings(&b).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warns_on_unreachable_endpoint() {
|
||||
// §4.7: an enabled endpoint with no route and no trigger is flagged.
|
||||
let mut b = empty_bundle();
|
||||
b.scripts = vec![bundle_script("orphan", "x")];
|
||||
let w = unreachable_endpoint_warnings(&b);
|
||||
assert!(
|
||||
w.iter().any(|m| m.contains("no route or trigger")),
|
||||
"expected an unreachable-endpoint warning: {w:?}"
|
||||
);
|
||||
// Bound by a route → no warning.
|
||||
b.routes = vec![BundleRoute {
|
||||
script: "orphan".into(),
|
||||
method: None,
|
||||
host_kind: HostKind::Any,
|
||||
host: String::new(),
|
||||
host_param_name: None,
|
||||
path_kind: PathKind::Exact,
|
||||
path: "/o".into(),
|
||||
dispatch_mode: DispatchMode::Sync,
|
||||
enabled: true,
|
||||
}];
|
||||
assert!(unreachable_endpoint_warnings(&b).is_empty());
|
||||
// A module is exempt even with no binding.
|
||||
let mut m = empty_bundle();
|
||||
let mut lib = bundle_script("lib", "x");
|
||||
lib.kind = ScriptKind::Module;
|
||||
m.scripts = vec![lib];
|
||||
assert!(unreachable_endpoint_warnings(&m).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trigger_diff_create_noop_delete() {
|
||||
let s = script("h", "x");
|
||||
|
||||
Reference in New Issue
Block a user