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
8 changes: 8 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ For changes limited to Flutter/Dart code in the mobile app, run
Native code and build-configuration changes also require the corresponding
platform checks.

`clippy.toml` bans raw calls that review has caught before, and each error
names the replacement. When you fix a class of bug, or a reviewer asks how to
keep it from happening again, add a ban there or a check in the same PR, plus a
line in `crates/buzz-relay/src/clippy_ban_witness.rs`. To keep a banned call in
production code, use `#[expect(clippy::disallowed_methods, reason = "...")]`,
not `#[allow]`. Test code may use banned calls, but a new file under `tests/`
needs the `#![allow(...)]` line the other test files start with.

Run `just test` for integration tests if you touched `buzz-relay`,
`buzz-db`, or `buzz-auth` — these require a running Postgres and Redis.

Expand Down
47 changes: 47 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Clippy settings for every crate in the root workspace.
#
# Clippy reads the nearest clippy.toml and does not merge files, so a crate
# that adds its own clippy.toml must copy everything below. The desktop
# workspace has its own, empty clippy.toml and is not covered.
#
# Each ban names what to use instead. The bans cover production code, because
# a test client or a blocking sleep in a test cannot hurt the relay. Every crate
# root allows them under `cfg(test)`. Each file under `tests/` is its own crate,
# so a new one starts with:
#
# #![allow(clippy::disallowed_methods, clippy::disallowed_macros)]
#
# A production exception is fine when the call site says why. Use `expect`, not
# `allow`, so the exception fails the build once the banned call is gone:
#
# #[expect(clippy::disallowed_methods, reason = "one-shot startup probe")]
#
# Add a ban when review keeps catching the same raw call. Write the reason as
# the bug it prevents, so the error teaches the fix. Clippy ignores a ban whose
# path it cannot resolve, so add a line to crates/buzz-relay/src/clippy_ban_witness.rs
# too: it fails the build if the ban never fires.

disallowed-methods = [
# Outbound HTTP. reqwest's default client follows up to ten redirects and
# has no timeout; a signed NIP-98 delivery followed a redirect to the wrong
# endpoint (#7793).
{ path = "reqwest::Client::new", reason = "the default client follows redirects and never times out; build with reqwest::Client::builder() and set .timeout(), .connect_timeout() and .redirect()" },
{ path = "reqwest::get", reason = "uses a default client that follows redirects and never times out; build a client with reqwest::Client::builder()" },

# Redis. Every relay reconnects at once after a Redis restart, so a connect
# with no deadline stalls the whole fleet.
{ path = "redis::Client::open", reason = "use buzz_pubsub::redis_connection, which bounds the connect and response time" },

# Queues. AGENTS.md rule 4: bound every resource. An unbounded channel turns
# a slow consumer into unbounded memory.
{ path = "tokio::sync::mpsc::unbounded_channel", reason = "use tokio::sync::mpsc::channel(capacity) and decide what happens when it is full (AGENTS.md rule 4)" },

# Blocking. A blocking sleep parks a Tokio worker thread and every task on it.
{ path = "std::thread::sleep", reason = "blocks the async runtime; use tokio::time::sleep, or wait for a condition instead of a fixed time" },
]

disallowed-macros = [
{ path = "std::dbg", reason = "debug output; remove before committing" },
{ path = "std::todo", reason = "panics at runtime; return an error or finish the code path" },
{ path = "std::unimplemented", reason = "panics at runtime; return an error or finish the code path" },
]
6 changes: 6 additions & 0 deletions crates/buzz-acp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![deny(unsafe_code)]
// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

mod git;
#[cfg(all(test, unix))]
Expand Down Expand Up @@ -3281,6 +3283,10 @@ async fn run_harness(
// 2. We must never drop a steer outcome — losing an ack would leak a
// withheld event in `EventQueue::withheld_native_steer` until
// `IN_FLIGHT_DEADLINE_SECS` expires.
#[expect(
clippy::disallowed_methods,
reason = "producers are bounded by in-flight turns, and a dropped ack would leak a withheld event; see the comment above"
)]
let (steer_ack_tx, mut steer_ack_rx) = mpsc::unbounded_channel::<SteerAckEvent>();

// Startup is complete; the main loop now owns graceful shutdown.
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-acp/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

fn main() -> anyhow::Result<()> {
buzz_acp::run()
}
4 changes: 4 additions & 0 deletions crates/buzz-acp/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,10 @@ impl AgentPool {
/// loop skips failed agents — `new()` would pack agents densely and break
/// the index invariant.
pub fn from_slots(slots: Vec<Option<OwnedAgent>>) -> Self {
#[expect(
clippy::disallowed_methods,
reason = "at most one result per agent slot is in flight"
)]
let (result_tx, result_rx) = mpsc::unbounded_channel();
Self {
agents: slots,
Expand Down
4 changes: 4 additions & 0 deletions crates/buzz-acp/src/run_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ pub(crate) async fn run() -> i32 {
}
};
let config = runtime.config();
#[expect(
clippy::disallowed_methods,
reason = "existing default client; move to Client::builder() with timeouts"
)]
let rest = crate::relay::RestClient {
http: reqwest::Client::new(),
base_url: crate::relay::relay_ws_to_http(&config.relay_url),
Expand Down
2 changes: 2 additions & 0 deletions crates/buzz-acp/tests/git_bootstrap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Run the installed harness/helper personalities across a real process boundary.
#![cfg(unix)]
// Test code may use the production bans in clippy.toml.
#![allow(clippy::disallowed_methods, clippy::disallowed_macros)]

use base64::Engine;
use std::os::unix::fs::PermissionsExt;
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-acp/tests/run_task.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Exercise the shipped entrypoint, not a second task runner in test code.
#![cfg(unix)]
// Test code may use the production bans in clippy.toml.
#![allow(clippy::disallowed_methods, clippy::disallowed_macros)]

use serde_json::{json, Value};
use std::{
fs,
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-admin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
//! past every earlier list's. Concurrent CLI processes therefore serialize in
//! the database; the CLI only pushes the committed list to Redis.

// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

mod communities;
mod deletions;
mod nip_fi;
Expand Down
4 changes: 4 additions & 0 deletions crates/buzz-agent/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ pub async fn discover_databricks_models_with_cache_dir(
discover_databricks_models_with_token_source(cfg, token_source).await
}

#[expect(
clippy::disallowed_methods,
reason = "existing default client; move to Client::builder() with timeouts"
)]
async fn discover_databricks_models_with_token_source(
cfg: &Config,
token_source: Arc<dyn TokenSource>,
Expand Down
7 changes: 7 additions & 0 deletions crates/buzz-agent/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#![forbid(unsafe_code)]
// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

mod agent;
pub mod auth;
mod auth_http;
Expand Down Expand Up @@ -980,6 +983,10 @@ async fn acquire_session(
// clients target *this* turn (rejecting steers aimed at a turn that already
// ended); the channel carries mid-turn injections to the run loop.
s.active_run_id = Some(run_id.clone());
#[expect(
clippy::disallowed_methods,
reason = "steer messages come from one client during one turn"
)]
let (steer_tx, steer_rx) = mpsc::unbounded_channel();
s.steer_tx = Some(steer_tx);
let effective_model = s.effective_model.clone();
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-agent/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

fn main() {
if let Err(e) = buzz_agent::run() {
eprintln!("Error: {e}");
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-agent/tests/bin/auth_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
//! Result JSON: `{ "result": "ok"|"<error_code>", "bearer": <string|null>,
//! "launches": <u64> }`.

// Test code may use the production bans in clippy.toml.
#![allow(clippy::disallowed_methods, clippy::disallowed_macros)]

use std::fs;
use std::io::{Read, Write};
use std::net::TcpStream;
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-agent/tests/bin/fake_mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
//! a test issue parallel calls to distinctly named
//! tools and tell them apart in `FAKE_MCP_CALL_LOG`.

// Test code may use the production bans in clippy.toml.
#![allow(clippy::disallowed_methods, clippy::disallowed_macros)]

use std::io::{BufRead, Write};

use serde_json::{json, Value};
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-agent/tests/bin/lock_holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
//! After signaling readiness it blocks forever; the parent kills it to model a
//! crash mid-flow.

// Test code may use the production bans in clippy.toml.
#![allow(clippy::disallowed_methods, clippy::disallowed_macros)]

use std::fs;

use fs2::FileExt;
Expand Down
2 changes: 2 additions & 0 deletions crates/buzz-audio-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! This crate owns the v2 handshake, wire format, Opus encoding and receive jitter
//! buffering. It neither loads private keys nor starts background tasks.
#![deny(unsafe_code)]
// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

pub mod connection;
pub mod encoder;
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-audit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
//! The `audit_log` table is owned by `migrations/` — this crate is pure chain
//! logic and ships no DDL.

// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

/// Audit action types recorded in the log.
pub mod action;
/// Audit log entry types (stored and input).
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
//! - All paths produce an [`AuthContext`] bound to the connection.
//! - No JWT validation, no token management, no IdP runtime dependency.

// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

/// Channel access checking trait and helpers.
pub mod access;
/// Authentication error types.
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-backend-kubernetes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
//! `ok` field, because a provider that encoded outcomes in exit codes would
//! have a second, redundant error channel to keep in sync (§Provider Protocol).

// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

mod classify;
mod client;
mod cluster;
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

pub mod agent_management;
mod cached_assertion;
mod client;
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

#[tokio::main]
async fn main() {
std::process::exit(buzz_cli::run_from_args(std::env::args()).await);
Expand Down
2 changes: 2 additions & 0 deletions crates/buzz-conformance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

#![deny(unsafe_code)]
#![warn(missing_docs)]
// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

pub mod checker;
pub mod transitions;
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
//! Provides [`StoredEvent`], filter matching, kind constants, and event
//! verification. All other Buzz crates depend on this one.

// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

/// NIP-AM: Agent Turn Metric — payload type and encrypt/decrypt helpers.
pub mod agent_turn_metric;
/// Channel and membership enums shared across crates.
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-datastore-tracing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Policy-enforcing instrumentation for logical datastore operations.

// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
//! Existing crate-root modules, records, and [`Db`] methods remain the public
//! API. The internal `runtime` and `store` namespaces are not public APIs.

// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

/// Wrap `$retire`, an `UPDATE`/`DELETE` on `events` that retires a
/// coordinate's previous head, so the same statement drops those rows' mention
/// index entries. Mention-index reads (`#p` filters and feeds) never return a
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-deletion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#![warn(missing_docs)]
//! Shared durable whole-community deletion engine and store adapters.

// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

/// Synthetic user-deletion request intake.
pub mod user;

Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-dev-mcp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![cfg_attr(not(windows), forbid(unsafe_code))]
#![cfg_attr(windows, deny(unsafe_code))]
// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

use rmcp::{
handler::server::{router::tool::ToolRouter, wrapper::Parameters},
model::{CallToolResult, ServerCapabilities, ServerConfig},
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-dev-mcp/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

fn main() -> Result<(), Box<dyn std::error::Error>> {
buzz_dev_mcp::run()
}
3 changes: 3 additions & 0 deletions crates/buzz-feature-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#![warn(missing_docs)]
//! Typed boolean and integer feature flags for Buzz server components.

// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

use buzz_core::{CommunityId, PublicKey};

pub mod environment;
Expand Down
3 changes: 3 additions & 0 deletions crates/buzz-media/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
//!
//! Library crate — no Axum dependency for handlers. Axum handlers live in `buzz-relay`.

// Test code may use the production bans in clippy.toml.
#![cfg_attr(test, allow(clippy::disallowed_methods, clippy::disallowed_macros))]

pub mod auth;
pub mod bucket_index;
pub mod config;
Expand Down
4 changes: 4 additions & 0 deletions crates/buzz-mesh-smoke/examples/mesh_admission_smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
//!
//! Hardware-gated, not CI — loads a real model. Run with:
//! cargo run -p buzz-relay --example mesh_admission_smoke

// Test code may use the production bans in clippy.toml.
#![allow(clippy::disallowed_methods, clippy::disallowed_macros)]

use std::io::BufRead;
use std::process::{Child, Command, Stdio};
use std::time::Duration;
Expand Down
4 changes: 4 additions & 0 deletions crates/buzz-mesh-smoke/examples/mesh_agent_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
//! cargo build --release -p buzz-agent -p buzz-dev-mcp
//! cargo run -p buzz-relay --example mesh_agent_e2e
//! Env: MESH_E2E_MODEL overrides the served model ref.

// Test code may use the production bans in clippy.toml.
#![allow(clippy::disallowed_methods, clippy::disallowed_macros)]

use std::process::Stdio;
use std::time::Duration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
//! BUZZ_ADMIN_BIN=target/ci/buzz-admin \
//! cargo run --profile ci -p buzz-relay --example mesh_relay_lifecycle_smoke
//! ```

// Test code may use the production bans in clippy.toml.
#![allow(clippy::disallowed_methods, clippy::disallowed_macros)]

use std::collections::BTreeSet;
use std::io::{BufRead, Write};
use std::process::{Child, ChildStdout, Command, ExitStatus, Stdio};
Expand Down
4 changes: 4 additions & 0 deletions crates/buzz-mesh-smoke/examples/mesh_serve_client_smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
//! # or point at any local .gguf / hf model ref (e.g. the on-hardware 35B):
//! MESH_SMOKE_MODEL=/path/to/model.gguf \
//! cargo run -p buzz-relay --example mesh_serve_client_smoke

// Test code may use the production bans in clippy.toml.
#![allow(clippy::disallowed_methods, clippy::disallowed_macros)]

use std::time::Duration;

use mesh_llm_sdk::{client, serve, MeshDiscoveryMode};
Expand Down
4 changes: 4 additions & 0 deletions crates/buzz-mesh-smoke/examples/mesh_serve_smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
//!
//! Usage:
//! cargo run -p buzz-relay --example mesh_serve_smoke -- <path-to.gguf>

// Test code may use the production bans in clippy.toml.
#![allow(clippy::disallowed_methods, clippy::disallowed_macros)]

use std::time::Duration;

use mesh_llm_sdk::{serve, MeshDiscoveryMode};
Expand Down
Loading
Loading