Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

perf(email,auth): stop compiling the whole service in each lib test (#9825)

teoa8a652e73bfe
diff --git a/.agents/rules/rust/code.md b/.agents/rules/rust/code.md
index 4a3e4b90ac..05136b3d6b 100644
--- a/.agents/rules/rust/code.md
+++ b/.agents/rules/rust/code.md
@@ -74,6 +74,11 @@ Type design, idioms, errors and observability, performance, and tests.
and never record prompts, tool arguments or tool results as span fields or
logs — they are content, recorded on the spans under the
`OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` policy and a size budget.
+- **CS-73** A function that reaches a service's router or composition root is
+ never a non-generic `pub async fn`, even in a private module: rustc compiles
+ the body of every such function in every build, so the lib test compiles the
+ whole service. Use `pub(crate) async fn`, or `pub fn run() -> impl Future` over
+ a private `async fn` when another crate calls it.
- **CS-68** Don't mark types `#[non_exhaustive]` by default. Exhaustive matches
are how a new variant reaches every place that must handle it; reserve the
attribute for types published outside the workspace.
diff --git a/services/authentication_service/src/api.rs b/services/authentication_service/src/api.rs
index fbd72ee204..6cf9e3a3ed 100644
--- a/services/authentication_service/src/api.rs
+++ b/services/authentication_service/src/api.rs
@@ -55,7 +55,7 @@ mod test;
/// alongside `/` so the dedicated ALB keeps working during cutover.
const GATEWAY_PATH_PREFIX: &str = "/auth";
-pub async fn setup_and_serve(state: ApiContext, port: usize) -> anyhow::Result<()> {
+pub(crate) async fn setup_and_serve(state: ApiContext, port: usize) -> anyhow::Result<()> {
let cors = macro_cors::cors_layer_with_headers(vec![HeaderName::from_static(
MACRO_REFRESH_TOKEN_HEADER,
)]);
diff --git a/services/authentication_service/src/server.rs b/services/authentication_service/src/server.rs
index abbfd9c31a..05b95f85f9 100644
--- a/services/authentication_service/src/server.rs
+++ b/services/authentication_service/src/server.rs
@@ -106,7 +106,12 @@ use std::{sync::Arc, time::Duration};
use tokio_util::{sync::CancellationToken, task::TaskTracker};
/// Build the service from the environment and serve until shutdown.
-pub async fn run() -> anyhow::Result<()> {
+// Not a `pub async fn`: see CS-73.
+pub fn run() -> impl Future<Output = anyhow::Result<()>> {
+ run_server()
+}
+
+async fn run_server() -> anyhow::Result<()> {
let env = Environment::new_or_prod();
// One SDK config is sufficient for every AWS client in this process.
diff --git a/services/document_storage_service/AGENTS.md b/services/document_storage_service/AGENTS.md
index fe35d5607b..59506b6e5b 100644
--- a/services/document_storage_service/AGENTS.md
+++ b/services/document_storage_service/AGENTS.md
@@ -88,11 +88,6 @@ threads, pins, recents, notifications, folders, activity.
- Compose Soup without a separate property-definition reader; REST and GraphQL validate DATE range inputs before calling the service.
-- Don't declare a function that reaches the router `pub async fn`, even in a private
- module. rustc compiles the body of every non-generic `pub async fn` in every build,
- so the lib test would compile the whole service. `server::run` returns `impl Future`
- for that reason.
-
- Several behaviors are Cargo-feature-gated (`connection_gateway`,
`delete_document_worker`, `location_check`, all on by `default`) — a feature
disabled locally can hide a bug that only shows in deployed builds.
diff --git a/services/document_storage_service/src/api.rs b/services/document_storage_service/src/api.rs
index a1a54d3586..e8f3d42565 100644
--- a/services/document_storage_service/src/api.rs
+++ b/services/document_storage_service/src/api.rs
@@ -49,7 +49,6 @@ mod threads;
// auth based constants
pub const MACRO_INTERNAL_USER_ID: &str = "macro|[email protected]";
-// `pub(crate)`, not `pub`: see `server::run`.
pub(crate) async fn setup_and_serve(state: ApiContext) -> anyhow::Result<()> {
let sync_sessions = state.sync_sessions.clone();
let app = api_router(state.clone())
diff --git a/services/document_storage_service/src/server.rs b/services/document_storage_service/src/server.rs
index c23412f5f4..577edc4c22 100644
--- a/services/document_storage_service/src/server.rs
+++ b/services/document_storage_service/src/server.rs
@@ -209,9 +209,7 @@ maybe_env_vars! {
}
/// Build the service from the environment and serve until shutdown.
-// Not a `pub async fn`: rustc compiles the body of every non-generic `pub async fn`
-// in every build, tests included, even when nothing calls it. This one reaches the
-// whole router, so the lib test would compile the entire service.
+// Not a `pub async fn`: see CS-73.
pub fn run() -> impl Future<Output = anyhow::Result<()>> {
run_server()
}
diff --git a/services/email_service/src/api.rs b/services/email_service/src/api.rs
index 2efe746ae4..77ff87e014 100644
--- a/services/email_service/src/api.rs
+++ b/services/email_service/src/api.rs
@@ -27,7 +27,7 @@ mod test;
const GATEWAY_PATH_PREFIX: &str = "/email";
-pub async fn setup_and_serve(state: ApiContext) -> anyhow::Result<()> {
+pub(crate) async fn setup_and_serve(state: ApiContext) -> anyhow::Result<()> {
let env = state.config.environment;
let port = state.config.port;
let traced_api = api_router(state.clone()).with_state(state).layer(
diff --git a/services/email_service/src/server.rs b/services/email_service/src/server.rs
index d7f14b29a7..503bd042b6 100644
--- a/services/email_service/src/server.rs
+++ b/services/email_service/src/server.rs
@@ -48,7 +48,12 @@ use system_properties::{PgSystemPropertiesRepository, SystemPropertiesServiceImp
use tokio_util::task::TaskTracker;
/// Build the service from the environment and serve until shutdown.
-pub async fn run() -> anyhow::Result<()> {
+// Not a `pub async fn`: see CS-73.
+pub fn run() -> impl Future<Output = anyhow::Result<()>> {
+ run_server()
+}
+
+async fn run_server() -> anyhow::Result<()> {
let env = Environment::new_or_prod();
let aws_config = macro_aws_config::get_macro_aws_config().await;