Skip to content
29 changes: 29 additions & 0 deletions crates/ironclaw_reborn_composition/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3093,6 +3093,35 @@ fn local_dev_project_filesystem(
Ok(filesystem)
}

/// Test-only (C-SLACK-LIFECYCLE restart seam, issue #6105 T5): reopen the
/// composed Slack host-state filesystem at an existing local-dev
/// `storage_root` — a FRESH root filesystem (fresh durable-backend handles,
/// independent of the live runtime's `Arc`s) wrapped with the SAME
/// `slack_host_state_mount_view` production wraps it with. Mirrors the
/// production construction in [`build_reborn_services`]
/// (`local_dev_slack_host_state_filesystem` over the local-dev root), so a
/// restart-survival test proves durable Slack host state (identity bindings,
/// DM targets) is reconstructible the way a real process restart
/// reconstructs it. Tests only; zero bytes in production builds.
#[cfg(all(
feature = "test-support",
feature = "slack-v2-host-beta",
any(feature = "libsql", feature = "postgres")
))]
pub(crate) async fn open_local_dev_slack_host_state_filesystem_for_test(
storage_root: &Path,
) -> Result<Arc<ScopedFilesystem<LocalDevRootFilesystem>>, RebornBuildError> {
let workspace_root = storage_root.join("workspace");
let bundle = build_local_dev_root_filesystem(
storage_root,
&workspace_root,
None,
LocalDevStorageBackendInput::LocalDefault,
)
.await?;
Ok(local_dev_slack_host_state_filesystem(bundle.filesystem))
}

/// Test-only (E-DURABLE seam): open a FRESH, independent
/// [`ExtensionInstallationStore`] at an existing local-dev `storage_root`,
/// paralleling how `assert_reply_persists_after_reopen` opens a fresh libsql
Expand Down
96 changes: 92 additions & 4 deletions crates/ironclaw_reborn_composition/src/slack/slack_delivery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3742,16 +3742,104 @@ mod tests {
let record = wait_for_delivery_record(&delivery_store, run_id).await;

// Egress should have been called for chat.postMessage.
let post = egress
.calls()
.into_iter()
.find(|c| c.path == "/api/chat.postMessage")
.expect("expected chat.postMessage egress call");

// Right-target pin (#5943/#5877 shape, T1 of #6105): the posted body
// must carry the DM conversation id decoded from the saved
// preference's binding ref — not the run's current channel or another
// user's target.
let body = String::from_utf8(post.body).expect("postMessage body is UTF-8 JSON");
assert!(
body.contains(r#""channel":"D456""#),
"chat.postMessage must target the preference binding's DM conversation; body: {body}"
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Asserting on the serialized JSON string using contains is fragile and can lead to false positives or unexpected failures if the JSON formatting, spacing, or key order changes. It is more robust to parse the body as a JSON value and assert on the specific field.

Suggested change
let body = String::from_utf8(post.body).expect("postMessage body is UTF-8 JSON");
assert!(
body.contains(r#""channel":"D456""#),
"chat.postMessage must target the preference binding's DM conversation; body: {body}"
);
let body: serde_json::Value = serde_json::from_slice(&post.body).expect("postMessage body is valid JSON");
assert_eq!(
body.get("channel").and_then(|v| v.as_str()),
Some("D456"),
"chat.postMessage must target the preference binding's DM conversation; body: {body}"
);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 58d8237 — the body is now parsed with serde_json::from_slice and the channel field is asserted equal to "D456".


// Outcome should be Delivered.
assert_eq!(record.outcome, TriggeredRunDeliveryOutcomeKind::Delivered);
}

/// Delivery-honesty pin (#5944 shape, T1 of #6105): the RUN completed, but
/// Slack rejected the post (`200 {"ok":false,...}`). The delivery record
/// must say `Failed` — a `Delivered` here is exactly the "delivery
/// silently fails but run reports success" bug: run status alone cannot
/// distinguish the two, only this record can.
#[tokio::test]
async fn driver_slack_api_rejection_records_failed_not_delivered() {
let install = "test-install";
let scope = personal_turn_scope();
let run_id = TurnRunId::new();
let binding_ref =
test_slack_binding_ref(install, scope.agent_id.as_ref().expect("agent").as_str());

let coordinator = Arc::new(ScriptedTurnCoordinator::with_single_status(
TurnStatus::Completed,
));
let thread_service = Arc::new(InMemorySessionThreadService::default());
seed_finalized_assistant_message(&thread_service, &scope, run_id, "Hello from Ironclaw")
.await;

let outbound = Arc::new(InMemoryOutboundStateStore::default());
seed_personal_preference(&outbound, &scope, binding_ref).await;

// Slack accepts the HTTP call but rejects the post — the classic
// silent-failure shape (revoked channel, kicked bot, archived DM).
let egress = Arc::new(FakeProtocolHttpEgress::new(vec!["slack.com".to_string()]));
egress.allow_credential_handle("slack_bot_token");
egress.program_response(
"slack.com",
Ok(EgressResponse::new(
200,
serde_json::json!({"ok": false, "error": "channel_not_found"})
.to_string()
.into_bytes(),
)),
);

let delivery_store = Arc::new(InMemoryTriggeredRunDeliveryStore::default());
let route_store = Arc::new(InMemoryDeliveredGateRouteStore::default());
let services = make_services(
coordinator,
thread_service,
egress.clone(),
outbound,
install,
);
let settings = SlackFinalReplyDeliverySettings {
poll_interval: std::time::Duration::ZERO,
max_wait: std::time::Duration::from_secs(5),
max_concurrent_deliveries: NonZeroUsize::new(1).unwrap(),
max_pending_deliveries: NonZeroUsize::new(8).unwrap(),
};
let driver = TriggeredRunDeliveryDriver::with_settings(
services,
settings,
delivery_store.clone(),
route_store.clone(),
scope.agent_id.clone().expect("test scope has agent"),
);

let fire = minimal_trigger_fire(None);
driver.on_trigger_submitted(fire, run_id, scope).await;
let record = wait_for_delivery_record(&delivery_store, run_id).await;

// The post WAS attempted (this is not a skip/no-target case)…
assert!(
egress
.calls()
.iter()
.any(|c| c.path == "/api/chat.postMessage"),
"expected chat.postMessage egress call"
"expected the rejected chat.postMessage egress call"
);
// …and the rejection must be recorded as Failed, never Delivered.
assert_eq!(
record.outcome,
TriggeredRunDeliveryOutcomeKind::Failed,
"a Slack-rejected post on a Completed run must record Failed (#5944 honesty pair)"
);

// Outcome should be Delivered.
assert_eq!(record.outcome, TriggeredRunDeliveryOutcomeKind::Delivered);
}

#[tokio::test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct SlackChannelConnectionTestConfig {
/// See the module doc for the production call sites each method mirrors.
pub struct SlackChannelConnectionTestBundle {
tenant_id: TenantId,
host_user_id: UserId,
agent_id: AgentId,
installation_id: ironclaw_product_adapters::AdapterInstallationId,
team_id: SlackTeamId,
Expand Down Expand Up @@ -106,7 +107,7 @@ pub fn build_slack_channel_connection_for_test(
let state = Arc::new(FilesystemSlackHostState::new(
Arc::clone(&local_runtime.host_state_filesystem),
tenant_id.clone(),
host_user_id,
host_user_id.clone(),
agent_id.clone(),
None,
));
Expand Down Expand Up @@ -160,6 +161,7 @@ pub fn build_slack_channel_connection_for_test(
}
Ok(SlackChannelConnectionTestBundle {
tenant_id,
host_user_id,
agent_id,
installation_id,
team_id,
Expand Down Expand Up @@ -223,6 +225,44 @@ impl SlackChannelConnectionTestBundle {
Arc::clone(&self.facade)
}

/// Restart-survival probe (T5 of issue #6105): read the SAME active-state
/// identity-binding predicate as
/// [`Self::has_any_active_identity_binding`], but through a FRESH
/// `FilesystemSlackHostState` over a FRESH local-dev root filesystem
/// reopened at `storage_root` — fully independent of the live runtime's
/// in-memory handles. This is the integration-tier approximation of a
/// process restart: it proves the durable binding is reconstructible the
/// way production reconstructs it on boot (`build_reborn_services` →
/// `local_dev_slack_host_state_filesystem` → Slack host-state mounts).
/// Tests only.
#[cfg(any(feature = "libsql", feature = "postgres"))]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The helper has_active_identity_binding_after_reopen calls open_local_dev_slack_host_state_filesystem_for_test, which is conditionally compiled under the slack-v2-host-beta feature. However, has_active_identity_binding_after_reopen itself is only gated on any(feature = "libsql", feature = "postgres"). If slack-v2-host-beta is disabled but libsql or postgres is enabled, this will cause a compilation error. Update the cfg attribute to include feature = "slack-v2-host-beta".

    #[cfg(all(
        feature = "slack-v2-host-beta",
        any(feature = "libsql", feature = "postgres")
    ))]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a real compile hole — the enclosing module is already feature-gated. test_support/mod.rs declares #[cfg(feature = "slack-v2-host-beta")] mod slack_channel_connection;, and lib.rs gates pub mod test_support on test-support. So the helper's effective cfg chain is test-support ∧ slack-v2-host-beta ∧ any(libsql|postgres) — exactly the factory fn's gate. There is no feature combination that compiles the caller without the callee.

pub async fn has_active_identity_binding_after_reopen(
&self,
storage_root: &std::path::Path,
user_id: &UserId,
) -> Result<bool, String> {
let host_state_filesystem =
crate::factory::open_local_dev_slack_host_state_filesystem_for_test(storage_root)
.await
.map_err(|error| error.to_string())?;
let state = Arc::new(FilesystemSlackHostState::new(
host_state_filesystem,
self.tenant_id.clone(),
self.host_user_id.clone(),
self.agent_id.clone(),
None,
));
let lookup: Arc<dyn RebornUserIdentityLookup> = state;
lookup
.user_has_provider_binding_with_provider_user_id_prefix(
SLACK_IDENTITY_PROVIDER,
user_id,
None,
)
.await
.map_err(|error| error.to_string())
}

/// Surface (a) of the extensions page: what
/// `list_extensions` merges via
/// `ChannelConnectionFacade::caller_channel_connections`
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/auth_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,27 @@ async fn runtime_401_after_injection_populates_provider_credential_requirement()
wrong setup kind would route the WebUI to the wrong re-auth UI"
);

// T2 of the #6105 lifecycle transitions — the #5878 negative
// discriminator: a revoked/rejected token (provider 401) must surface
// EXCLUSIVELY as the re-auth gate asserted above, never as a generic
// model-visible failure ("the tool input could not be encoded" / "AI
// model provider was temporarily unavailable"). An empty reason matches
// any summary of the class, so this pins that NO Failed-classed tool
// error of any reason was persisted for the 401.
harness
.assert_no_tool_error(ToolErrorClass::Failed, "")
.await
.expect(
"a provider 401 must park at the auth gate, not persist a generic \
Failed tool error (#5878 misleading-error regression)",
);
// ...and it must not hot-retry the rejected credential: exactly the one
// 401 probe crossed the wire (#5878's "multiple retry attempts" shape).
harness
.assert_network_egress_count(1)
.await
.expect("a 401 must not be hot-retried against the provider");

// Drain the run cleanly (deny) so the test doesn't leak a blocked run.
harness
.deny_auth_gate(run_id, &gate_ref)
Expand Down
33 changes: 33 additions & 0 deletions tests/integration/group_extensions/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ mod support;
// Modules are alphabetical (rustfmt reorders `mod` decls); execution order is
// set by the `report.record(...)` sequence below, not declaration order.
mod scenario_activate_then_active_cross_thread;
mod scenario_credential_extension_lifecycle_state_machine;
mod scenario_extension_activation_reauth_gate;
mod scenario_install_then_visible_cross_thread;
mod scenario_install_unknown_extension_id_fails_safely;
mod scenario_remove_then_absent_cross_thread;
mod scenario_slack_channel_lifecycle_state_machine;
mod scenario_slack_state_survives_reopen;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The module scenario_slack_state_survives_reopen uses has_active_identity_binding_after_reopen and open_local_dev_extension_installation_store_for_test, which are conditionally compiled based on database features (libsql or postgres) and slack-v2-host-beta. Declaring this module unconditionally will cause compilation failures when these features are disabled. Gate the module declaration under the same feature flags.

Suggested change
mod scenario_slack_state_survives_reopen;
#[cfg(all(feature = "slack-v2-host-beta", any(feature = "libsql", feature = "postgres")))]
mod scenario_slack_state_survives_reopen;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These symbols come from the root crate's dev-dependency on ironclaw_reborn_composition, which pins features = ["test-support", "libsql", "webui-v2-beta", "slack-v2-host-beta"] unconditionally (workspace Cargo.toml, dev-dependencies). Those are composition-crate features — a root-crate feature selection cannot disable them, so the module compiles under every root feature set. The suggested cfg would test root-crate features that don't gate anything here (and slack-v2-host-beta isn't a root feature at all, which unexpected_cfgs would flag).

mod scenario_uninstalled_tool_call_denied_until_activated;

use reborn_support::group::{RebornIntegrationGroup, ScenarioReport};
Expand Down Expand Up @@ -83,5 +86,35 @@ async fn extensions_group_e2e() {
scenario_slack_channel_lifecycle_state_machine::run(&g).await,
);

// Scenario 7 (issue #6105, T3): exit edges for a credential-injection
// extension — activate → use → remove (#6029's wedged edge) → surfaces
// flip → reconfigure + reactivate → use again. Reuses "github" AFTER
// every other scenario that reads it has run (scenario 1 leaves it
// installed), so its install exercises the idempotent-reinstall arm.
report.record(
"credential_extension_lifecycle_state_machine",
scenario_credential_extension_lifecycle_state_machine::run(&g).await,
);

// Scenario 8 (issue #6105, T5): restart survival — the connected/installed
// Slack state scenario 6 left behind reads back through FRESH store
// handles reopened at the same on-disk storage_root (what a process
// restart reconstructs). Depends on scenario 6's end state.
report.record(
"slack_state_survives_reopen",
scenario_slack_state_survives_reopen::run(&g).await,
);
Comment on lines +109 to +112

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Gate the registration of scenario_slack_state_survives_reopen to match its module declaration, preventing compilation errors when the required features are disabled.

Suggested change
report.record(
"slack_state_survives_reopen",
scenario_slack_state_survives_reopen::run(&g).await,
);
#[cfg(all(feature = "slack-v2-host-beta", any(feature = "libsql", feature = "postgres")))]
report.record(
"slack_state_survives_reopen",
scenario_slack_state_survives_reopen::run(&g).await,
);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the module-declaration thread above: the dev-dependency enables slack-v2-host-beta/libsql on the composition crate unconditionally, so this registration compiles under every root feature set and the suggested cfg would reference root-crate features that don't exist.


// Scenario 9 (issue #6105 bucket-3 arms): activation-time re-auth gate —
// activate over a REVOKED credential parks BlockedAuth with a renderable
// provider requirement (#6043 shape), persists no misleading Failed error
// (#5878's reported extension_activate surface), and a reconfigure
// unwedges it. Uses "notion" (removed by scenario 2; credentials
// untouched by every other scenario).
report.record(
"extension_activation_reauth_gate",
scenario_extension_activation_reauth_gate::run(&g).await,
);

report.assert_all_passed();
}
Loading
Loading