Skip to content

Latest commit

 

History

History
97 lines (71 loc) · 6.2 KB

AGENTS.md

File metadata and controls

97 lines (71 loc) · 6.2 KB

AGENTS.md

Azul is a Rust workspace implementing tiled transparency logs for deployment on Cloudflare Workers.

Tech Stack: Rust (edition 2021), Cloudflare Workers (WASM via worker-build), Cargo workspace resolver v2

Directory Structure

crates/ct_worker/      - Static CT API Worker (deployable); wrangler.jsonc here
crates/mirror_worker/     - Configurable tlog mirror/witness Worker (deployable)
crates/generic_log_worker/ - Shared Durable Object logic (Sequencer, Batcher, Cleaner)
crates/tlog_tiles/     - C2SP tlog-tiles spec impl (published to crates.io)
crates/static_ct_api/  - C2SP static-ct-api spec impl (published to crates.io)
fuzz/                  - cargo-fuzz targets for tlog parsing

Commands

cargo build                      # build all workspace crates
cargo clippy -- -D warnings      # lint; warnings are errors in CI
cargo test                       # run all unit tests (excludes integration_tests — requires wrangler dev)
cargo bench                      # run benchmarks (criterion in signed_note)

# Fuzzing (nightly required)
cargo fuzz run fuzz_parse_tile_path
cargo fuzz run fuzz_parse_checkpoint

# Worker local dev (run from a worker crate)
npx wrangler -e=dev dev
./reset-dev.sh                   # clear local wrangler state between runs

# Integration tests (requires wrangler dev to be running)

# CT worker tests — from crates/ct_worker/:
npx wrangler -e=dev dev &
# From workspace root:
cargo test -p integration_tests --test static_ct_api
# Override defaults:
BASE_URL=http://localhost:8787 LOG_NAME=dev2026h2a cargo test -p integration_tests --test static_ct_api

# Worker deploy
npx wrangler -e=${ENV} deploy
npx wrangler -e=${ENV} tail

Code Patterns

  • Worker crates use crate-type = ["cdylib"]; library crates use rlib
  • Worker build is handled by worker-build, not cargo build directly — wrangler.jsonc invokes it automatically
  • Config types live in separate sub-crates such as crates/ct_worker/config/ and crates/mirror_worker/config/
  • DEPLOY_ENV=<env> env var must be set when invoking worker-build manually; wrangler.jsonc sets it per environment
  • Route HTTP with axum::Router (worker features ["http", "axum"]), not the worker::Router. The #[event(fetch)] handler takes a HttpRequest, returns axum::http::Response<axum::body::Body>, and dispatches via tower_service::Service::call; handlers return impl IntoResponse. See mirror_worker/ct_worker for the pattern.

Workflow

Deploying a Worker

  1. Run ./scripts/create-log.sh to provision R2 bucket, KV namespace, and signing/witness keys
  2. Set required secrets: openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 | npx wrangler -e=${ENV} secret put SIGNING_KEY_${LOG_NAME}
  3. npx wrangler -e=${ENV} deploy from the worker's crate directory

Adding a New Workspace Crate

  1. Create crates/<name>/Cargo.toml with workspace = true fields
  2. Add the path to [workspace.members] in root Cargo.toml
  3. Add shared dependencies to [workspace.dependencies] rather than duplicating versions
  4. Symlink the workspace root LICENSE into the crate so the published tarball ships a copy: ln -s ../../LICENSE crates/<name>/LICENSE (or ../../../LICENSE for sub-crates one level deeper, e.g. the *_worker/config/ sub-crates). cargo package follows the symlink and embeds the resolved bytes. This applies even to publish = false crates for workspace-wide consistency.

Boundaries

✅ Always (for code changes): Before pushing any commit that touches Rust sources, Cargo.toml files, or anything else that affects the build, run the pre-push checks locally and confirm they pass:

cargo clippy --workspace --all-targets -- -Dwarnings -Dclippy::pedantic # lint everything (including fuzz)
cargo test                                                              # unit tests; uses default-members, so integration_tests and fuzz are skipped
cargo fmt --all --check                                                 # advisory in CI, easy to fix
cargo shear                                                             # unused-dependency check (incl. workspace deps); advisory in CI, easy to fix

integration_tests is excluded from the default test run because it requires a live wrangler dev instance (invoke it explicitly once wrangler is running; see the integration test workflow below). fuzz is excluded because it is the cargo-fuzz harness crate, run via cargo fuzz run <target> on a nightly toolchain. Both are still linted.

The pre-push checks may be skipped for changes that obviously cannot affect the build — pure documentation edits (README.md, AGENTS.md, *.md), license / license-symlink edits, comment-only edits, and similar. When in doubt, run them.

If any step fails, fix the issue in the commit it belongs to (use git commit --fixup=<sha> + git rebase --autosquash) rather than layering a separate "fix lint" commit on top.

✅ Always: Before pushing, re-read the commit message and verify it reflects the current state of the code — counts, type names, and described behaviors can drift as code evolves.

✅ Always: Add new shared dependencies to [workspace.dependencies] in root Cargo.toml. Do not add a dependency to a crate's Cargo.toml (or the root [workspace.dependencies] table) before you actually use it — cargo shear will flag speculative additions, including unused entries in [workspace.dependencies] that no member inherits. Suppress unavoidable false positives (e.g. getrandom, which is a feature-only edge) via [workspace.metadata.cargo-shear] ignored = [...].

✅ Always: Keep Workers-specific concerns (Durable Object storage formats, KV dedup cache, Worker runtime dependencies) out of the specification-level crates (tlog_tiles, static_ct_api, signed_note). Those crates implement public specs and are published to crates.io; they should not gain types, traits, or dependencies whose only consumers are Cloudflare Workers. Wire-format types used only by the sequencer and frontend belong in generic_log_worker or the concrete worker crate. ⚠️ Requires Approval: Publishing crates to crates.io (tlog_tiles, static_ct_api, signed_note, signed_note) — worker crates have publish = false