P4 core: broker-held app connections + gated, broker-executed Slack posting

- app_connections repo; POST /api/apps/connect (keys/basic): the credential
  goes to the secret broker over its socket and only the encrypted ref lands
  in the row; disconnect endpoint; /api/apps directory merged with live
  connection status; audit rows for connect/disconnect
- Broker protocol: InvokeHttp carries a JSON body
- slack.post tool (SendsExternally -> gated): marked broker_executed — the
  runtime skips its own grant consumption and the BROKER independently
  verifies + consumes the single-use grant, then calls Slack with the bot
  token injected; the runtime never sees the credential
- Config: [broker] socket_path + [slack] base_url; e2e harness spawns the
  real teamclaw-broker daemon and the server hosts an e2e-only /__slack sink
- SlackApp: Connection tab stores the token via the broker; connected state
- Integration test: blocked while pending -> approved -> sink received
  exactly one post with 'Bearer xoxb-test-token' -> grant replay refused
- E2E journey: connect Slack in the panel -> gated post card with preview ->
  sink empty while pending -> approve -> exactly one post, queue clear

133 Rust + 63 frontend tests + 21 Playwright journeys.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Omar Sobh
2026-06-10 05:51:19 -05:00
co-authored by Claude Fable 5
parent 1fd2c287f1
commit 000b9b3a4b
40 changed files with 1058 additions and 80 deletions
+29
View File
@@ -11,6 +11,35 @@ use tc_domain::{
AccessPolicy, Agent, AgentId, AgentStatus, Role, User, UserId, Workspace, WorkspaceId,
};
/// In e2e mode the server hosts a Slack-shaped sink so journeys can assert
/// exactly what the broker posted, without external infrastructure.
pub fn slack_sink_router() -> axum::Router {
use std::sync::Arc;
use tokio::sync::Mutex;
type Posts = Arc<Mutex<Vec<serde_json::Value>>>;
let posts: Posts = Arc::new(Mutex::new(Vec::new()));
axum::Router::new()
.route(
"/__slack/chat.postMessage",
axum::routing::post(
|axum::extract::State(posts): axum::extract::State<Posts>,
axum::Json(body): axum::Json<serde_json::Value>| async move {
posts.lock().await.push(body);
axum::Json(serde_json::json!({"ok": true}))
},
),
)
.route(
"/__slack/posts",
axum::routing::get(
|axum::extract::State(posts): axum::extract::State<Posts>| async move {
axum::Json(posts.lock().await.clone())
},
),
)
.with_state(posts)
}
pub const E2E_OWNER_EMAIL: &str = "[email protected]";
pub const E2E_OWNER_PASSWORD: &str = "e2e-password";
+8 -1
View File
@@ -78,6 +78,8 @@ async fn run() -> Result<(), String> {
RuntimeConfig {
model: config.llm.model.clone(),
max_tokens: 4096,
broker_socket: Some(PathBuf::from(&config.broker.socket_path)),
slack_base_url: config.slack.base_url.clone(),
},
blob,
);
@@ -88,7 +90,12 @@ async fn run() -> Result<(), String> {
tc_scheduler::Scheduler::new(pool.clone(), runtime.clone())
.spawn(std::time::Duration::from_secs(5));
let app = tc_api::router(tc_api::AppState::new(pool, runtime));
let mut app = tc_api::router(
tc_api::AppState::new(pool, runtime).with_broker(PathBuf::from(&config.broker.socket_path)),
);
if e2e::enabled() {
app = app.merge(e2e::slack_sink_router());
}
let listener = tokio::net::TcpListener::bind(config.listen_addr)
.await
.map_err(|e| format!("bind {} failed: {e}", config.listen_addr))?;