Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(local): support signup and login without Doppler (#5552)
Cameron Pakf15a6aa6b979
diff --git a/.gitignore b/.gitignoreindex 9569451324..af449544a0 100644--- a/.gitignore+++ b/.gitignore@@ -33,3 +33,4 @@ infra/local/generated/**/target/**/ai_tools/schemas/.pi/outputs/+.commandcode/diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex e717a8c3af..5e6faa5c41 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -15,6 +15,7 @@ serve you including AI tools, but if you don't understand the work you'redoing it's probably not useful.You should:+- Understand the changes and decisions you made well enough to answer questions in review.- See your change working in a local development environment@@ -43,8 +44,7 @@ No generated boilerplate, no exhaustive file-by-file change lists.## Development setup-See [docs/RUNNING_LOCALLY.md](docs/RUNNING_LOCALLY.md) for running the full app-locally. The short version: use the Nix shell, then `just run_local`.+See [docs/RUNNING_LOCALLY.md](docs/RUNNING_LOCALLY.md) for running the full app locally.## Before you pushdiff --git a/README.md b/README.mdindex e06f48c35f..be8d623fa3 100644--- a/README.md+++ b/README.md@@ -1,4 +1,3 @@-<div align="center"><a target="_blank" href="https://macro.com"><img width="2195" height="721" alt="Frame 11" src="https://github.com/user-attachments/assets/50405352-785e-4984-b24f-544e89731acb" />@@ -46,18 +45,18 @@ Macro is composed of 'blocks' designed to be modular, extensible, and work togetEach surface is purpose-built for its job rather than composed from a generic block primitive — but every one of them shares the same backend; cross-references between a doc and a task, or a channel message and an email, are natively stored as a **bidirectional graph**.-| Block | Docs | What it does |-| --- | --- | --- |-| Email | [Docs →](https://docs.macro.com/product/email) | Multi-account unified inbox, keyboard shortcuts, and shared inboxes. Gmail. |-| Messages | [Docs →](https://docs.macro.com/product/channels) | Channels and direct messages designed for focused technical discussions. |-| Tasks | [Docs →](https://docs.macro.com/product/tasks) | Linear-inspired tasks, tightly integrated with channels, email, and agents. |-| Docs | [Docs →](https://docs.macro.com/product/docs) | Real-time collaborative, markdown-native docs built on CRDTs, with @mentions. |-| Canvas | [Docs →](https://docs.macro.com/product/canvas) | 2D board with embedded @links to tasks, files, and emails. |-| Agents | [Docs →](https://docs.macro.com/product/agents) | Unified, team-level memory. Can take action on your behalf. |-| Calls | [Docs →](https://docs.macro.com/product/calls) | Recorded, transcribed, and logged to team memory for agents. |-| File storage | [Docs →](https://docs.macro.com/product/folders) | Auto-imported from email and channels, fully searchable. |-| Pull requests | [Docs →](https://docs.macro.com/integrations/github) | Linked to tasks, embeddable in channels, available to agents. |-| CRM | [Docs →](https://docs.macro.com/product/crm) | Customer and contact objects, custom properties, email sync, enrichment. |+| Block | Docs | What it does |+| ------------- | --------------------------------------------------------- | ----------------------------------------------------------------------------- |+| Email | [Docs →](https://docs.macro.com/product/email) | Multi-account unified inbox, keyboard shortcuts, and shared inboxes. Gmail. |+| Messages | [Docs →](https://docs.macro.com/product/channels) | Channels and direct messages designed for focused technical discussions. |+| Tasks | [Docs →](https://docs.macro.com/product/tasks) | Linear-inspired tasks, tightly integrated with channels, email, and agents. |+| Docs | [Docs →](https://docs.macro.com/product/docs) | Real-time collaborative, markdown-native docs built on CRDTs, with @mentions. |+| Canvas | [Docs →](https://docs.macro.com/product/canvas) | 2D board with embedded @links to tasks, files, and emails. |+| Agents | [Docs →](https://docs.macro.com/product/agents) | Unified, team-level memory. Can take action on your behalf. |+| Calls | [Docs →](https://docs.macro.com/product/calls) | Recorded, transcribed, and logged to team memory for agents. |+| File storage | [Docs →](https://docs.macro.com/product/folders) | Auto-imported from email and channels, fully searchable. |+| Pull requests | [Docs →](https://docs.macro.com/integrations/github) | Linked to tasks, embeddable in channels, available to agents. |+| CRM | [Docs →](https://docs.macro.com/product/crm) | Customer and contact objects, custom properties, email sync, enrichment. |<br />@@ -168,7 +167,6 @@ Memory isn't supposed to encompass everything. Macro also has a tool/MCP surface[Agents docs →](https://docs.macro.com/product/agents)-Your coding agents can use Macro too. Point Claude Code, Codex, or any MCP client at your workspace:```bash@@ -203,26 +201,9 @@ Deeper reading: [key concepts](https://docs.macro.com/concepts/blocks) covers bl# Running it locally-```bash-git clone https://github.com/macro-inc/macro.git-cd macro-nix develop # Rust toolchain, Bun, sqlx, zig, cargo-zigbuild-just run_local # local infra + backend services + proxy + frontend-```--Tauri's large platform dependencies live in focused shells: use-`nix develop .#tauri-linux` for Linux desktop development or-`nix develop .#tauri-android` for Android development on x86_64 Linux.--`run_local` prints the frontend URL once the stack is up; `r` rebuilds changed Rust services, `q` tears it down. See [Running locally](docs/RUNNING_LOCALLY.md) for Doppler setup and named instances.+To run the full app on your machine, follow [Running locally](docs/RUNNING_LOCALLY.md).-```bash-just check # type check the workspace-just clippy # lints-just setup_test_envs # write the .env files tests need-cargo test # full test suite-cargo test -p email_service # a single service-```+To contribute, see [CONTRIBUTING.md](CONTRIBUTING.md).<br />diff --git a/docs/RUNNING_LOCALLY.md b/docs/RUNNING_LOCALLY.mdindex ed02a9c4e0..1018192328 100644--- a/docs/RUNNING_LOCALLY.md+++ b/docs/RUNNING_LOCALLY.md@@ -1,170 +1,295 @@# Running Locally-Use `just run_local` to run the full app on your machine.+This guide explains how to run Macro on your machine. The local stack runs without Doppler. It runs Postgres, Redis, LocalStack, OpenSearch, Kafka, and FusionAuth in Docker, with dummy AWS credentials and fixed test secrets.++## What You Need++Install these tools before you start:++1. [Nix](https://nix.dev/install-nix) package manager+2. [Docker](https://docs.docker.com/get-docker/) with the Compose v2 plugin (Docker Desktop, OrbStack, or Colima work)++Clone the repository:```bash-just run_local+git clone https://github.com/macro-inc/macro.git+cd macro```-This starts local infra, backend services, the local proxy, and the frontend.-When startup finishes, the command prints the frontend URL and the important-service URLs.+## Enter the Nix Shell-## Requirements+The Nix shell provides `just`, Cargo, the Rust toolchain, Bun, sqlx, zig, and cargo-zigbuild. You do not need to install `just` or Cargo separately.-The easiest path is to use the repo's Nix shell. It should provide the Rust-toolchain, `cargo-zigbuild`, Zig, Bun, sqlx, and the other project tools.+```bash+nix develop+```-Outside the Nix shell, you need at least:+If `nix develop` fails, enable the experimental features:-- Docker with Compose v2-- Doppler CLI-- Rust toolchain-- `cargo-zigbuild` and Zig-- Bun-- sqlx CLI+```bash+nix develop --extra-experimental-features nix-command --extra-experimental-features flakes+```-You should also be logged in to Doppler and have access to the `local` project:+Nix requires these experimental features to work. The command above enables them for one run. To enable them permanently, set this in `~/.config/nix/nix.conf`:-```bash-doppler login```+experimental-features = nix-command flakes+```++The default shell does not include the Tauri platform dependencies. They are large, so they live in their own shells. For Linux desktop development, use `nix develop .#tauri-linux`. For Android development on x86_64 Linux, use `nix develop .#tauri-android`.++## Start the Stack-`run_local` pulls the `lcl_personal` Doppler config by default. If you want to-run without Doppler, use:+Run this command from the repository root if you do not have Doppler access:```bash-just run_local --no-doppler --env-file ./local.env+just run_local --no-doppler```-## Running One Stack+The local stack does not need Doppler. It uses the code-defined local configuration with dummy AWS credentials and fixed test secrets. Most contributors are not on the team, so this is the common path.++The stack boots with stubbed values for every config the services require, including the third-party integrations (Google, GitHub, Stripe, CloudFront). Those flows do not work against real services with the stubs. The rest of the stack is fully functional: auth, documents, email, and search.-Start the default stack:+To use a real integration locally, supply its keys via `--env-file` — see [Integration Secrets](#integration-secrets) below.++Run this command if you have Doppler access. It pulls the `lcl_personal` config. Then it overlays the code-defined local defaults. Every integration value is real:```bashjust run_local```-Useful preflight:+If you prefer to test against real cloud infrastructure, you need [Doppler](https://www.doppler.com) for secrets management.++This command:++- Builds the Rust backend services+- Starts the local infrastructure (Postgres, Redis, LocalStack, OpenSearch, Kafka, FusionAuth)+- Starts the backend services+- Starts the local proxy and the frontend++When startup finishes, the command prints the frontend URL and the important service URLs.++Open the frontend URL in your browser.++The stack does not create accounts in advance. Passwordless login creates a user+on demand. Register with any email address. FusionAuth sends you a one-time code+by email. That email lands in **Mailpit** at http://localhost:8025, not in a real+inbox.++### Seeding sample data (recommended)++A bare stack has no content to click through. The seed CLI creates a realistic+world: users, teams, channels, projects, documents, tasks, chats, calls, emails,+and messages. The world uses realistic permissions.++From the repository root, after the stack is up:++```bash+just seed-scenario apply --file seed/scenarios/team-perms.json+```++`apply` creates a FusionAuth account for each persona. It prints a login link per+persona, for example `http://alice.localhost:3000/app/[email protected]`.+Open each link in a plain browser tab. Each persona hostname has its own cookie+jar. You can drive several personas side by side against one stack.++Useful commands:++- `just seed-scenario status --file seed/scenarios/team-perms.json` — show what is seeded and re-print the login links.+- `just seed-scenario reset --file seed/scenarios/team-perms.json` — remove the scenario's rows and its user accounts by email.+- `just seed-scenario matrix --file seed/scenarios/team-perms.json` — check the expected access level for every user and entity pair against the live database.++`apply` touches only rows that carry the scenario `5eed` id marker, plus the+persona accounts it created. It is safe to run against a stack that you tested in.++## Integration Secrets++A `--no-doppler` stack boots with deterministic stubs for every value the services' config loaders require. The stubs are enough to start the services. The third-party integrations they back do not work until you supply real values:++| Integration | Keys | Stub behavior |+| --- | --- | --- |+| Google login / Gmail | `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET_KEY` | Google SSO and Gmail inbox linking are unavailable. Local signup still works. The email service reports no Gmail grant and skips inbox syncing. |+| GitHub login | `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET`, `GITHUB_IDP_ID` | Login with GitHub is unavailable |+| Stripe billing | `STRIPE_SECRET_KEY`, `STRIPE_PRICE_ID` | Checkout and subscription endpoints fail. Signup still works: the create-user webhook detects the stub key and skips the real Stripe call. It stores a placeholder customer id instead. |+| CloudFront signed URLs | `DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_DISTRIBUTION_URL`, `DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PUBLIC_KEY_ID`, `DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PRIVATE_KEY` | Document download URLs are unsigned (fine against local S3) |++The other stubbed keys (`REDIS_HOST`, `MACRO_DB_URL`, `INTERNAL_API_KEY`, `AUTHENTICATION_SERVICE_SECRET_KEY`, `OPENSEARCH_USERNAME`, `OPENSEARCH_PASSWORD`) are internal plumbing with correct local values — you never need to override them.++To turn on an integration, create a `local.env` with the real values. Then pass it+to `run_local`:++```bash+just run_local --no-doppler --env-file ./local.env+```++Keys in the file override the code-defined defaults, so you only need to list the integrations you care about. With Doppler access, `just run_local` (without `--no-doppler`) supplies everything automatically.++## Check the Setup++Run the preflight check before the first start:```bashjust doctor-local```+The check tests the Docker daemon, the toolchain, and the required ports. It reports any problem and suggests a fix. If a start fails, run the check again.++## Control the Running Stack+While `run_local` is attached:-- Press `r` to rebuild and reload changed Rust services.-- Press `q` to tear the stack down and exit.+- Press `r` to rebuild the changed Rust services and reload them.+- Press `q` to stop the stack and exit.-Prefer `q` over just closing the terminal. It stops/removes the instance's-containers immediately, so the next startup does not have to clean up a stale-stack first.+Use `q`, not the terminal close button. `q` stops and removes the containers at once. The next start does not have to clean up a stale stack.-## Running Multiple Instances+## Run More than One Stack-Use named instances when you want multiple local stacks at once, especially-across worktrees:+Use named instances for several local stacks at once. This helps across worktrees:```bashjust run_local --instance agent-ajust run_local --instance agent-b```-Each named instance gets its own Compose project, volumes, networks, generated-env files, proxy, frontend port, and backend ports. Ports are deterministic for-the instance name, so the same name should get the same port window on every-run.+Each instance has its own resources:++- a Compose project+- volumes and networks+- env files+- a proxy port, a frontend port, and backend ports-If a generated port window conflicts with something else on your machine:+The ports are deterministic for the instance name. The same name gets the same+port window on every run.++If the port window conflicts with another program, change the base port:```bashjust run_local --instance agent-a --port-base 23000```-Generated files live at:+The generated files for an instance live here:```textinfra/local/generated/<instance>```-## What Gets Rebuilt+## Port Conflicts (macOS)++The default instance binds a fixed set of host ports. macOS reserves some of them+for its own services. If the app loads but API calls return unexpected HTML, a+port is probably hijacked by an unrelated process. The two most common conflicts+on a fresh Mac:++- **Port 8080** — macOS WebDriver service (`com.apple.WebDriver.HTTPService`). It listens on this port when remote automation is on. The auth service cannot bind it.+- **Port 8090** — another project's dev server, for example an Expo server with `--port 8090`. The proxy cannot bind it.++The frontend loads, but login and API calls hit the other process. You see HTML+or console errors instead of JSON. `just doctor-local` reports the busy ports+before you start.++Run the stack on a port window that is free on your machine. You do not need to+kill the other process:++```bash+just doctor-local # see which default ports are busy+just doctor-local --instance test --port-base 31000 # check the new window is free+just run_local --no-doppler --instance test --port-base 31000+```++A named instance binds every service at `port-base + offset`. A free base like+`31000` moves the whole stack to one contiguous window. Use any base that is free+on your machine. See `just doctor-local` for the busy ports. Keep the same+`--instance` name and `--port-base` on later runs so the ports stay deterministic.++Use the same two flags for every command. Run the stack, seed it, and check it+with the same `--instance` and `--port-base` values:++```bash+just run_local --no-doppler --instance test --port-base 31000+just seed-scenario --instance test --port-base 31000 apply --file seed/scenarios/team-perms.json+just seed-scenario --instance test --port-base 31000 status --file seed/scenarios/team-perms.json+just status_local --instance test --port-base 31000+```++If you omit `--port-base`, a named instance gets a deterministic port window+derived from its name. That window is different from the one you chose. A stack+started with an explicit `--port-base` must be seeded with the same explicit+`--port-base`, or the seed CLI looks at the wrong database. The default instance+(no `--instance`) always uses the fixed ports and needs no extra flags.++The seeded persona login links embed the frontend port. If you switch ports, run+`just seed-scenario apply` again to get links that match the new window.+`just status_local`, with the same two flags, prints the live endpoints.++## What the Stack Rebuilds-Rust backend services are built on the host with `cargo zigbuild` and mounted-into a shared runtime image. Docker is not compiling those Rust services during-normal `run_local`.+The Rust services are built on the host with `cargo zigbuild`. The binaries are mounted into a shared runtime image. Docker does not compile these services during a normal `run_local`.-Pressing `r` rebuilds the Rust binaries and restarts only the services whose-binaries changed.+Press `r` to rebuild the binaries. Only the services whose binaries changed restart.-The current rough edge is auxiliary Docker-built services:+Three services have Docker-built images. They are not rebuilt by default:- `sync_service`- `lexical_service`- `websocket_service`-Those are not rebuilt by default. If you change sync-service, lexical-service,-or anything that affects their Docker images, the running stack can keep using a-stale image.--To force those services to rebuild:+If you change these services, the running stack can use a stale image. Force a rebuild with this flag:```bashjust run_local --build-aux-services```-When the stack was started with `--build-aux-services`, pressing `r` also-rebuilds those auxiliary images and recreates their containers. That is slower,-so leave it off unless you are actively working on those services or need to-pick up a change there.+When you start the stack with `--build-aux-services`, press `r` to rebuild those images and recreate their containers. This is slower, so leave the flag off unless you work on those services.-If you already started without `--build-aux-services` and suspect a stale-sync/lexical image, press `q` and restart with the flag.+If you started without the flag and suspect a stale image, press `q`. Then start again with the flag.-## Headless Mode (previews, agents, CI)+## Headless Mode-`just stack` is the same stack without a terminal attached: no hotkey loop, no-dev server. The frontend is built once (a dev-mode bundle with production-optimizations) and served statically by the instance's Caddy proxy, so the whole-product lives behind **one origin** and a finished `up` leaves only Docker-containers running — nothing to babysit.+`just stack` runs the same stack without an attached terminal. There is no hotkey loop and no dev server. The frontend is built once and served statically by the proxy. The whole product lives behind one origin. A finished `up` leaves only Docker containers running.```bashjust stack up # bring everything up, print URLs, returnjust stack status --json # machine-readable state (containers, health, URLs)-just stack update # rebuild + reload only changed services (the `r` hotkey)+just stack update # rebuild and reload only the changed services (the `r` hotkey)just stack update --frontend # also rebuild the frontend bundle-just stack down # containers + volumes + state-```--All the `run_local` flags apply (`--instance`, `--no-doppler --env-file`,-`--no-build`, `--binaries-dir`); CI can hand in a prebuilt bundle with-`--frontend-dist`, and `--infra-only` stops after the infra bring-up + init-(the CI bake mode — without Doppler the app services have no env to boot-with, and the snapshot only captures infra volumes). The app is served at `<proxy>/app/` — the bundle resolves its-backend from the origin it is served on, so the same stack works on localhost-or behind a preview hostname without a rebuild.--`stack up` also caches the expensive infra init. The first cold run migrates-the DB, waits out the FusionAuth kickstart, and creates the search indices,-then saves those volumes as a content-addressed **init snapshot** (keyed by the-migrations, kickstart, index mappings, image pins, and container platform —-stored under `infra/local/generated/.snapshots`). Later runs whose inputs match restore the-snapshot and skip the init entirely; any input change is a cache miss and a-normal full init. `just stack snapshot` shows the current key; `--no-snapshot`-opts out. This is also what makes Fly previews boot fast — CI bakes the-snapshot into the preview image (see `infra/preview/README.md`).+just stack down # remove containers, volumes, and state+```++All the `run_local` flags apply to `stack` too. This includes `--instance`, `--no-doppler`, `--no-build`, and `--binaries-dir`. CI can pass a prebuilt bundle with `--frontend-dist`.++The app is served at `<proxy>/app/`. The bundle resolves its backend from the origin it is served on. The same stack works on localhost or behind a preview hostname without a rebuild.++### Init Snapshots++`stack up` caches the expensive infrastructure initialization. The first cold run:++- Migrates the database+- Waits for the FusionAuth kickstart+- Creates the search indices++It saves these volumes as an init snapshot. The snapshot is content-addressed and stored under `infra/local/generated/.snapshots`. Later runs restore the snapshot and skip the initialization. An input change causes a cache miss and a normal full init.++Useful commands:++```bash+just stack snapshot # show the current snapshot key+just stack up --no-snapshot # skip the snapshot cache+```++CI bakes the snapshot into the preview image. This is what makes Fly previews boot fast. See `infra/preview/README.md`.## Common Commands-Run local binaries against shared dev resources instead of a fully local stack:+Run local binaries against shared dev resources instead of a full local stack:```bashjust run_dev```-See what a running (or stopped) instance looks like — endpoints with live-reachability probes plus every container's state and host ports — without-starting or rebuilding anything:+`run_dev` uses shared dev resources. It needs Doppler and real cloud access. It is for contributors with team access.++See what a running or stopped instance looks like. The output shows endpoints with live reachability probes, plus the state and host ports of every container. It does not start or rebuild anything:```bashjust status_local@@ -176,7 +301,7 @@ Stop an instance but keep its volumes:just stop_local --instance agent-a```-Remove an instance's containers, volumes, and named-instance networks:+Remove the containers, volumes, and named-instance networks of an instance:```bashjust destroy_local --instance agent-adiff --git a/services/authentication_service/src/api/internal/google_access_token.rs b/services/authentication_service/src/api/internal/google_access_token.rsindex a0f6768bd1..1d400f743c 100644--- a/services/authentication_service/src/api/internal/google_access_token.rs+++ b/services/authentication_service/src/api/internal/google_access_token.rs@@ -47,6 +47,22 @@ async fn get_access_token(.get_identity_provider_id_by_name(identity_provider_name).await.map_err(|e| {+ // No Gmail identity provider configured (e.g. local / --no-doppler+ // stacks, or a deployment without the Google integration). This is+ // an expected "no grant" outcome, not a server fault: the email+ // service treats a 404 as NoGmailGrant and skips inbox init, while+ // a 500 would surface as a hard login failure.+ if matches!(e, FusionAuthClientError::NoIdentityProviderFound) {+ tracing::debug!(error=?e, "no {} identity provider configured", identity_provider_name);+ return (+ StatusCode::NOT_FOUND,+ Json(ErrorResponse {+ message: format!("No {} link found for this user", identity_provider_name)+ .into(),+ }),+ )+ .into_response();+ }tracing::error!(error=?e, "unable to find idp id for {}", identity_provider_name);(StatusCode::INTERNAL_SERVER_ERROR,diff --git a/services/authentication_service/src/service/user/create_user.rs b/services/authentication_service/src/service/user/create_user.rsindex f7683e4d8a..21e91fa5c0 100644--- a/services/authentication_service/src/service/user/create_user.rs+++ b/services/authentication_service/src/service/user/create_user.rs@@ -1,6 +1,29 @@use macro_db_client::user::organization::{get_organization_roles_for_user, match_user_to_organization,};+use macro_env_var::optional_read_env_var;++#[cfg(test)]+mod test;++/// The stub `STRIPE_SECRET_KEY` set by `run_local --no-doppler` (see+/// `tooling/xtask/crates/xtask_local/src/local/local_env.rs`). With this key a+/// real Stripe call would fail, so local signups skip it and store a+/// deterministic placeholder id instead.+const LOCAL_STRIPE_SECRET_STUB: &str = "local-stripe-secret";++fn is_local_stripe_stub() -> bool {+ optional_read_env_var("STRIPE_SECRET_KEY")+ .ok()+ .flatten()+ .is_some_and(|key| key == LOCAL_STRIPE_SECRET_STUB)+}++/// A unique placeholder Stripe customer id for local signups. `stripe_customer_id`+/// has a UNIQUE constraint, so it must be unique per user.+fn local_stripe_customer_id(email: &str) -> String {+ format!("local-stripe-customer-{email}")+}/// Creates a new user/// This is a fairly involved process and as such will be well documented and broken up into@@ -16,12 +39,17 @@ pub async fn create_user(db: &sqlx::Pool<sqlx::Postgres>,stripe_client: &stripe::Client,) -> anyhow::Result<(String, Option<i32>)> {- // NOTE: stripe adds in ~400ms of latency to this request. We may want to update our- // requirement that each customer exists in stripe and create stripe customers as needed.- let stripe_customer = create_stripe_user(email, stripe_client).await?;- tracing::trace!(stripe_customer_id=?stripe_customer.id.to_string(), "created stripe customer");-- let stripe_customer_id = stripe_customer.id.to_string();+ let stripe_customer_id = if is_local_stripe_stub() {+ // Local mode uses a stub key; don't call Stripe (it would 401 and+ // abort the transactional user.create webhook, blocking all signups).+ local_stripe_customer_id(email)+ } else {+ // NOTE: stripe adds in ~400ms of latency to this request. We may want to update our+ // requirement that each customer exists in stripe and create stripe customers as needed.+ let stripe_customer = create_stripe_user(email, stripe_client).await?;+ tracing::trace!(stripe_customer_id=?stripe_customer.id.to_string(), "created stripe customer");+ stripe_customer.id.to_string()+ };let organization_id = match_user_to_organization(db, email).await?;tracing::trace!(organization_id=?organization_id, "matched user to organization");diff --git a/services/authentication_service/src/service/user/create_user/test.rs b/services/authentication_service/src/service/user/create_user/test.rsnew file mode 100644index 0000000000..4edf0c4dbe--- /dev/null+++ b/services/authentication_service/src/service/user/create_user/test.rs@@ -0,0 +1,61 @@+use std::sync::Mutex;++use macro_env_var::optional_read_env_var;++use super::{LOCAL_STRIPE_SECRET_STUB, is_local_stripe_stub, local_stripe_customer_id};++/// Tests mutate the process env, which is process-global; serialize them so+/// they can't interleave.+static ENV_LOCK: Mutex<()> = Mutex::new(());++/// Restores the saved `STRIPE_SECRET_KEY` on drop, so a panicking test body+/// can't leak its value into later tests.+struct RestoreStripeKey(Option<String>);++impl Drop for RestoreStripeKey {+ fn drop(&mut self) {+ match self.0.take() {+ Some(saved) => unsafe { std::env::set_var("STRIPE_SECRET_KEY", saved) },+ None => unsafe { std::env::remove_var("STRIPE_SECRET_KEY") },+ }+ }+}++fn with_stripe_key(key: Option<&str>, f: impl FnOnce()) {+ let _guard = ENV_LOCK.lock().unwrap();+ let _restore = RestoreStripeKey(optional_read_env_var("STRIPE_SECRET_KEY").ok().flatten());+ match key {+ Some(key) => unsafe { std::env::set_var("STRIPE_SECRET_KEY", key) },+ None => unsafe { std::env::remove_var("STRIPE_SECRET_KEY") },+ };+ f();+}++#[test]+fn local_stub_key_is_detected() {+ with_stripe_key(Some(LOCAL_STRIPE_SECRET_STUB), || {+ assert!(is_local_stripe_stub());+ });+}++#[test]+fn real_key_is_not_detected_as_stub() {+ with_stripe_key(Some("sk_live_real_key"), || {+ assert!(!is_local_stripe_stub());+ });+}++#[test]+fn missing_key_is_not_detected_as_stub() {+ with_stripe_key(None, || {+ assert!(!is_local_stripe_stub());+ });+}++#[test]+fn local_stripe_customer_id_is_unique_per_email() {+ let alice = local_stripe_customer_id("[email protected]");+ let bob = local_stripe_customer_id("[email protected]");+ assert_ne!(alice, bob);+ assert!(alice.contains("[email protected]"));+}diff --git a/tooling/xtask/crates/xtask_local/src/local/env_layer.rs b/tooling/xtask/crates/xtask_local/src/local/env_layer.rsindex 667dddb4b9..ef6bd86675 100644--- a/tooling/xtask/crates/xtask_local/src/local/env_layer.rs+++ b/tooling/xtask/crates/xtask_local/src/local/env_layer.rs@@ -1,4 +1,7 @@//! Environment layering (lowest → highest precedence):+//! - Local only: the [`local_env::LocalEnv`] boot stubs — deterministic+//! placeholders that satisfy service config loaders on a `--no-doppler`+//! stack. Doppler overrides them, so real integration values always win.//! - Doppler (`lcl_personal`/`dev_personal`) — the integration/secret config//! services require.//! - Local only: the typed [`local_env::LocalEnv`] overlaid on top —@@ -51,14 +54,23 @@ pub fn resolve(// has — unlike the old defaults.env, which Doppler overrode). Dev keeps// Doppler as-is.let spec = mode.spec();+ let local = spec+ .overlay_local_env+ .then(|| local_env::LocalEnv::for_instance(mode, instance, static_frontend));let mut env = BTreeMap::new();+ // Boot stubs go in FIRST so Doppler overrides them: they only exist to keep+ // a `--no-doppler` stack's config loaders satisfied, never to replace a+ // real integration value a developer's Doppler config supplies.+ if let Some(local) = &local {+ env.extend(local.boot_stub_env());+ }let doppler_used = if no_doppler {false} else {pull_doppler(spec.doppler_config, &mut env)?};- if spec.overlay_local_env {- for (k, v) in local_env::LocalEnv::for_instance(mode, instance, static_frontend).to_env() {+ if let Some(local) = &local {+ for (k, v) in local.to_env() {env.insert(k, v);}// Opt-in local trace export: point services at the local OTLP collectordiff --git a/tooling/xtask/crates/xtask_local/src/local/local_env.rs b/tooling/xtask/crates/xtask_local/src/local/local_env.rsindex e8df51b218..472a0992d1 100644--- a/tooling/xtask/crates/xtask_local/src/local/local_env.rs+++ b/tooling/xtask/crates/xtask_local/src/local/local_env.rs@@ -1,16 +1,18 @@//! The typed, code-owned local-stack environment — the replacement for the//! checked-in `infra/local/defaults.env`.//!-//! Local mode is fully code-defined: it does NOT pull Doppler. Every value here-//! is deterministic and local-only — docker-network hostnames, LocalStack dummy-//! creds, fixed queue/bucket names, the fixed FusionAuth kickstart identity, and-//! per-instance internal secrets. Anything that needs a *real* secret or a real-//! integration (Gmail, Stripe, …) is intentionally absent: that's a `run_dev`-//! concern (Doppler), not a local one.+//! Every value here is deterministic and local-only — docker-network hostnames,+//! LocalStack dummy creds, fixed queue/bucket names, the fixed FusionAuth+//! kickstart identity, and per-instance internal secrets. Anything that needs a+//! *real* secret or a real integration (Gmail, Stripe, …) comes from Doppler or+//! `--env-file`; [`BootStubEnv`] only supplies placeholder fallbacks so a+//! `--no-doppler` stack's config loaders don't crash at startup.//!-//! [`LocalEnv::for_instance`] builds the struct; [`LocalEnv::to_env`] is the one-//! boundary that flattens it to the env map. Grouping makes additions land in a-//! named, testable place instead of a free-form dotenv file that quietly rots.+//! [`LocalEnv::for_instance`] builds the struct. Two boundaries flatten it to+//! env maps: [`LocalEnv::to_env`] (authoritative, layered above Doppler) and+//! [`LocalEnv::boot_stub_env`] (fallback, layered below Doppler). Grouping makes+//! additions land in a named, testable place instead of a free-form dotenv file+//! that quietly rots.use std::collections::BTreeMap;@@ -33,6 +35,7 @@ pub struct LocalEnv {mail: MailEnv,service_auth: ServiceAuthEnv,fusionauth: FusionAuthEnv,+ boot_stubs: BootStubEnv,}impl LocalEnv {@@ -55,6 +58,7 @@ impl LocalEnv {mail: MailEnv::local(),service_auth: ServiceAuthEnv::for_instance(name),fusionauth: FusionAuthEnv::for_instance(instance),+ boot_stubs: BootStubEnv,}}@@ -77,6 +81,16 @@ impl LocalEnv {self.fusionauth.write(&mut env);env}++ /// The boot-stub fallback layer (see [`BootStubEnv`]), kept separate from+ /// [`Self::to_env`] on purpose: the resolver layers these BELOW Doppler so+ /// real integration values win over the stubs, while `to_env`'s local+ /// plumbing is layered ABOVE Doppler and wins.+ pub fn boot_stub_env(&self) -> BTreeMap<String, String> {+ let mut env = BTreeMap::new();+ self.boot_stubs.write(&mut env);+ env+ }}/// Databases, search, and the LocalStack/AWS endpoint (dummy creds — no real AWS@@ -335,5 +349,192 @@ impl FusionAuthEnv {}}+/// Values the services' `macro_config` loaders require but that only exist in+/// Doppler's `lcl_personal` config. Without these a `--no-doppler` stack's+/// containers crash at startup ("missing required value") before any of the+/// integration the value backs is ever exercised. Each entry is a deterministic+/// local stub: good enough to boot, never a real secret, and only meaningful+/// for the specific integration it names (which won't work locally anyway —+/// that's what `--env-file` / `run_dev` are for).+///+/// Unlike the rest of [`LocalEnv`], these are a FALLBACK layer: the resolver+/// applies them below Doppler (see `env_layer::resolve`), so a developer with+/// Doppler access keeps every real integration value. A key here must never+/// also appear in [`LocalEnv::to_env`] — that would make precedence ambiguous+/// (a test enforces this).+struct BootStubEnv;++impl BootStubEnv {+ fn write(&self, env: &mut BTreeMap<String, String>) {+ // connection_gateway config reads `REDIS_HOST` (a Redis URL, not a+ // hostname — see `redis::Client::open`).+ env.insert("REDIS_HOST".into(), "redis://redis:6379".into());+ // email_service / connection_gateway open their own Postgres pool.+ env.insert(+ "MACRO_DB_URL".into(),+ "postgres://user:password@postgres:5432/macrodb".into(),+ );+ // services validating the shared internal auth header.+ env.insert(+ "INTERNAL_API_KEY".into(),+ identity::INTERNAL_AUTH_KEY.into(),+ );+ // document_cognition_service's soup client (internal HMAC).+ env.insert(+ "AUTHENTICATION_SERVICE_SECRET_KEY".into(),+ identity::INTERNAL_AUTH_KEY.into(),+ );+ // search_processing_service; the local cluster has the security plugin+ // disabled so these are accepted but ignored (same as opensearch.rs).+ env.insert("OPENSEARCH_USERNAME".into(), "macrouser".into());+ env.insert("OPENSEARCH_PASSWORD".into(), "local".into());+ // document_storage_service's presigned-URL config. Locally the+ // `is_local_aws()` branch skips CloudFront signing entirely, so only a+ // well-formed base URL is needed.+ env.insert(+ "DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_DISTRIBUTION_URL".into(),+ "http://localhost:8100".into(),+ );+ env.insert(+ "DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PUBLIC_KEY_ID".into(),+ "local-cloudfront-signer".into(),+ );+ env.insert(+ "DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PRIVATE_KEY".into(),+ "local".into(),+ );+ // The `ai_tools` tool-context env (document_storage_service builds one+ // at boot) reads this as a separate secret-name var.+ env.insert(+ "DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PRIVATE_KEY_SECRET_NAME".into(),+ "local-cloudfront-signer-private-key".into(),+ );+ // authentication_service's third-party OAuth/Stripe config. The FusionAuth+ // kickstart only creates the Google/GitHub IdPs when real creds are+ // present (see kickstart.rs), so these stubs just satisfy the loader.+ env.insert("GOOGLE_CLIENT_ID".into(), "local-google-client".into());+ env.insert(+ "GOOGLE_CLIENT_SECRET_KEY".into(),+ "local-google-client-secret".into(),+ );+ env.insert("GITHUB_CLIENT_ID".into(), "local-github-client".into());+ env.insert(+ "GITHUB_CLIENT_SECRET".into(),+ "local-github-client-secret".into(),+ );+ env.insert(+ "GITHUB_IDP_ID".into(),+ "99999999-9999-4999-8999-999999999999".into(),+ );+ env.insert("STRIPE_SECRET_KEY".into(), "local-stripe-secret".into());+ env.insert("STRIPE_PRICE_ID".into(), "local-stripe-price".into());+ env.insert(+ "STRIPE_WEBHOOK_SECRET_KEY".into(),+ "local-stripe-webhook-secret".into(),+ );+ // macro_auth's `JwtValidationArgs` (used by every service that mounts+ // the auth middleware) reads these at boot. The keys are only parsed+ // when a Macro API token is actually validated — normal local auth+ // uses FusionAuth JWTs — so dummies are fine.+ env.insert("MACRO_API_TOKEN_ISSUER".into(), "local".into());+ env.insert(+ "MACRO_API_TOKEN_PUBLIC_KEY".into(),+ "local-macro-api-token-public-key".into(),+ );+ env.insert(+ "MACRO_API_TOKEN_PRIVATE_SECRET_KEY".into(),+ "local-macro-api-token-private-key".into(),+ );+ env.insert("MACRO_API_TOKEN_EXPIRY_SECONDS".into(), "3600".into());+ // email_service's GCP pubsub queue (gmail watch notifications) and+ // its own CloudFront signer for attachment presigned URLs.+ env.insert("GMAIL_GCP_QUEUE".into(), "gmail-gcp-queue-local".into());+ env.insert("APOLLO_API_KEY".into(), "local".into());+ env.insert(+ "EMAIL_SERVICE_CLOUDFRONT_DISTRIBUTION_URL".into(),+ "http://localhost:8100".into(),+ );+ env.insert(+ "EMAIL_SERVICE_CLOUDFRONT_SIGNER_PRIVATE_KEY".into(),+ "local".into(),+ );+ env.insert(+ "EMAIL_SERVICE_CLOUDFRONT_SIGNER_PUBLIC_KEY_ID".into(),+ "local-cloudfront-signer".into(),+ );+ // notification_service's APNS/FCM push config — push won't work+ // locally, but the loader requires the keys.+ env.insert("APPLE_BUNDLE_ID".into(), "com.macro.local".into());+ env.insert(+ "SNS_APNS_PLATFORM_ARN".into(),+ "arn:aws:sns:us-east-1:000000000000:app/APNS/macro-local".into(),+ );+ env.insert(+ "SNS_FCM_PLATFORM_ARN".into(),+ "arn:aws:sns:us-east-1:000000000000:app/GCM/macro-local".into(),+ );+ // document_cognition_service's MCP credentials encryption key — must be+ // a base64-encoded 32-byte AES key (`AesKey::try_from`).+ env.insert(+ "MCP_CREDENTIALS_KEY_SECRET_NAME".into(),+ "VrOPM+uhQKuas1vO8FpyWDc/ZRhLAXYW5lRz8s0yyA4=".into(),+ );+ // document_cognition_service reads `ANTHROPIC_API_KEY` at boot+ // (`anthropic::Config::dangrously_try_from_env`); a dummy satisfies the+ // loader, real model calls just fail.+ env.insert("ANTHROPIC_API_KEY".into(), "local-anthropic-key".into());+ // document_cognition_service's MCP provider registry requires the+ // pre-registered OAuth creds (Slack + GitHub) at boot.+ env.insert(+ "SLACK_MCP_CLIENT_ID".into(),+ "local-slack-mcp-client".into(),+ );+ env.insert(+ "SLACK_MCP_CLIENT_SECRET".into(),+ "local-slack-mcp-secret".into(),+ );+ // document_storage_service's GitHub sync + LiveKit + LLM + Cal config.+ // All boot-required; the integrations they back are inert locally.+ env.insert("GITHUB_SYNC_APP_URL".into(), "http://localhost:8080".into());+ env.insert(+ "GITHUB_SYNC_APP_CLIENT_ID".into(),+ "local-github-sync-client".into(),+ );+ env.insert(+ "GITHUB_SYNC_APP_CLIENT_SECRET".into(),+ "local-github-sync-secret".into(),+ );+ env.insert(+ "GITHUB_INSTALLATION_STATE_SECRET".into(),+ "local-github-installation-state".into(),+ );+ env.insert(+ "GITHUB_WEBHOOK_SECRET_KEY".into(),+ "local-github-webhook-secret".into(),+ );+ env.insert(+ "GITHUB_SYNC_APP_PEM_SECRET_KEY".into(),+ "local-github-sync-pem".into(),+ );+ env.insert("LIVEKIT_SERVER_URL".into(), "http://localhost:7880".into());+ env.insert("LIVEKIT_API_KEY".into(), "local-livekit-key".into());+ env.insert("LIVEKIT_API_SECRET".into(), "local-livekit-secret".into());+ env.insert("OPENAI_API_KEY".into(), "local-openai-key".into());+ env.insert("COHERE_API_KEY".into(), "local-cohere-key".into());+ env.insert(+ "CAL_WEBHOOK_SECRET_KEY".into(),+ "local-cal-webhook-secret".into(),+ );+ env.insert(+ "CAL_EVENT_TYPE_CONTENT_NAMES_KEY".into(),+ r#"{"1":{"content_name":"local","value":0}}"#.into(),+ );+ // Meta (Facebook) tracking pixel config. Required by the config loader;+ // the pixel is inert locally.+ env.insert("META_PIXEL_ID".into(), "local-meta-pixel".into());+ env.insert("META_ACCESS_TOKEN".into(), "local-meta-access-token".into());+ }+}+#[cfg(test)]mod test;diff --git a/tooling/xtask/crates/xtask_local/src/local/local_env/test.rs b/tooling/xtask/crates/xtask_local/src/local/local_env/test.rsindex fd708290c4..401088dfe5 100644--- a/tooling/xtask/crates/xtask_local/src/local/local_env/test.rs+++ b/tooling/xtask/crates/xtask_local/src/local/local_env/test.rs@@ -2,9 +2,14 @@ use super::*;use crate::local::Mode;use crate::local::instance::{Instance, Port};+/// The merged env a `--no-doppler` stack sees: boot stubs below, the+/// authoritative local env on top (mirrors `env_layer::resolve`).fn local_env() -> BTreeMap<String, String> {let instance = Instance::derive(None, None).expect("default instance derives");- LocalEnv::for_instance(Mode::Local, &instance, true).to_env()+ let local = LocalEnv::for_instance(Mode::Local, &instance, true);+ let mut env = local.boot_stub_env();+ env.extend(local.to_env());+ env}/// Every key a local service relies on must be present — this is the test that@@ -31,6 +36,57 @@ fn emits_required_keys() {"FUSIONAUTH_PUBLIC_URL","FUSIONAUTH_OAUTH_REDIRECT_URI","JWT_SECRET_KEY",+ // Boot-blocking stubs — service config loaders require these even in a+ // no-doppler stack (see `BootStubEnv`).+ "REDIS_HOST",+ "MACRO_DB_URL",+ "INTERNAL_API_KEY",+ "AUTHENTICATION_SERVICE_SECRET_KEY",+ "OPENSEARCH_USERNAME",+ "OPENSEARCH_PASSWORD",+ "DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_DISTRIBUTION_URL",+ "DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PUBLIC_KEY_ID",+ "DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PRIVATE_KEY",+ "DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PRIVATE_KEY_SECRET_NAME",+ "GOOGLE_CLIENT_ID",+ "GOOGLE_CLIENT_SECRET_KEY",+ "GITHUB_CLIENT_ID",+ "GITHUB_CLIENT_SECRET",+ "GITHUB_IDP_ID",+ "STRIPE_SECRET_KEY",+ "STRIPE_PRICE_ID",+ "STRIPE_WEBHOOK_SECRET_KEY",+ "MACRO_API_TOKEN_ISSUER",+ "MACRO_API_TOKEN_PUBLIC_KEY",+ "MACRO_API_TOKEN_PRIVATE_SECRET_KEY",+ "MACRO_API_TOKEN_EXPIRY_SECONDS",+ "GMAIL_GCP_QUEUE",+ "APOLLO_API_KEY",+ "EMAIL_SERVICE_CLOUDFRONT_DISTRIBUTION_URL",+ "EMAIL_SERVICE_CLOUDFRONT_SIGNER_PRIVATE_KEY",+ "EMAIL_SERVICE_CLOUDFRONT_SIGNER_PUBLIC_KEY_ID",+ "APPLE_BUNDLE_ID",+ "SNS_APNS_PLATFORM_ARN",+ "SNS_FCM_PLATFORM_ARN",+ "MCP_CREDENTIALS_KEY_SECRET_NAME",+ "ANTHROPIC_API_KEY",+ "SLACK_MCP_CLIENT_ID",+ "SLACK_MCP_CLIENT_SECRET",+ "GITHUB_SYNC_APP_URL",+ "GITHUB_SYNC_APP_CLIENT_ID",+ "GITHUB_SYNC_APP_CLIENT_SECRET",+ "GITHUB_INSTALLATION_STATE_SECRET",+ "GITHUB_WEBHOOK_SECRET_KEY",+ "GITHUB_SYNC_APP_PEM_SECRET_KEY",+ "LIVEKIT_SERVER_URL",+ "LIVEKIT_API_KEY",+ "LIVEKIT_API_SECRET",+ "OPENAI_API_KEY",+ "COHERE_API_KEY",+ "CAL_WEBHOOK_SECRET_KEY",+ "CAL_EVENT_TYPE_CONTENT_NAMES_KEY",+ "META_PIXEL_ID",+ "META_ACCESS_TOKEN",] {assert!(env.contains_key(key),@@ -39,6 +95,53 @@ fn emits_required_keys() {}}+/// Boot stubs are a fallback layer BELOW Doppler; `to_env` is authoritative+/// ABOVE Doppler. A key present in both would make its precedence ambiguous —+/// whichever map wrote last would silently win.+#[test]+fn boot_stubs_do_not_overlap_authoritative_env() {+ let instance = Instance::derive(None, None).expect("default instance derives");+ let local = LocalEnv::for_instance(Mode::Local, &instance, true);+ let authoritative = local.to_env();+ for key in local.boot_stub_env().keys() {+ assert!(+ !authoritative.contains_key(key),+ "{key} is in both boot_stub_env and to_env"+ );+ }+}++/// The boot stubs must be local-only values: the same in-network endpoints the+/// rest of the env uses, dummy creds, and never a real secret or deployed URL.+#[test]+fn boot_stubs_are_local_only() {+ let env = local_env();+ assert_eq!(+ env.get("REDIS_HOST").map(String::as_str),+ Some("redis://redis:6379")+ );+ assert_eq!(+ env.get("MACRO_DB_URL").map(String::as_str),+ Some("postgres://user:password@postgres:5432/macrodb")+ );+ // INTERNAL_API_KEY must agree with the internal-auth key other services+ // validate against, or every internal call 401s.+ assert_eq!(+ env.get("INTERNAL_API_KEY"),+ env.get("INTERNAL_API_SECRET_KEY"),+ "INTERNAL_API_KEY must match INTERNAL_API_SECRET_KEY"+ );+ assert_eq!(+ env.get("AUTHENTICATION_SERVICE_SECRET_KEY"),+ env.get("INTERNAL_API_SECRET_KEY"),+ "AUTHENTICATION_SERVICE_SECRET_KEY must match INTERNAL_API_SECRET_KEY"+ );+ assert_eq!(+ env.get("OPENSEARCH_USERNAME").map(String::as_str),+ Some("macrouser")+ );+}+/// Local must never point at real dev/prod infrastructure: endpoints are docker/// aliases / localhost, and creds are the LocalStack dummies. (Note `ISSUER` is/// the local `local.macro.com` JWT issuer — a value, not an endpoint — so we