Contributing¶
Set up a development environment, run the checks and submit changes. All contributors follow the Code of Conduct.
Workflow¶
- Discuss large changes in an issue before writing code.
- Create a fork, then a branch based on
main. - Write the change together with tests. See Tests.
- Send a pull request that targets
main.
Licensing¶
Gradient uses the AGPL-3.0-only license. Contributions fall under the same license. Every file must include this SPDX header:
// SPDX-FileCopyrightText: 2026 Wavelens GmbH <info@wavelens.io>
//
// SPDX-License-Identifier: AGPL-3.0-only
Development Setup¶
Requirements: Nix with flakes.
- Start an interactive NixOS test driver.
run_tests()boots a VM with a packaged server, PostgreSQL 18 forwarded to a host port, a usertestwith passwordpassword, and a project. Runcargo runinbackend/to work against that database.
backend/.cargo/config.toml caps parallel rustc jobs at 1 with [build] jobs = 1 to bound peak memory. Override the cap with cargo build -j N.
Checks¶
| Check | Command |
|---|---|
| Backend tests | nix build .#checks.x86_64-linux.unittest -L |
| CLI tests | nix build .#checks.x86_64-linux.cli-unittest -L |
| Clippy | nix build .#checks.x86_64-linux.clippy -L, ...cli-clippy -L, ...cli-static-clippy -L (the CLI without Nix support) |
| VM tests | nix build .#checks.x86_64-linux.gradient-<name> -L for api, cluster, deploy, e2e, eval, local-worker, scheduler, standalone, standalone-docker |
| Format | cargo fmt --all --check, in backend/ and cli/ |
| Licenses and advisories | cargo deny check, in backend/ and cli/. GPL-family dependencies are banned |
CI (.github/workflows/rust.yml) runs fmt, the #[allow] grep check and cargo-deny across both workspaces. The flake checks include Clippy.
Rust¶
- Run
cargo fmtbefore each commit. The devShell inflake.lockpins the toolchain version, andrust-toolchain.tomlmirrors that pin for rustup users. rustfmt.tomlsetsstyle_edition = "2024".- Every workspace has its own
deny.toml,clippy.tomlandrustfmt.toml. Keep these files in sync across workspaces. - The backend
clippy.tomlbanstokio::spawnand rawStatement. - Production code must not call
unwrap()(clippy::unwrap_used = "deny"). Use?, an explicit error branch, or.expect("<the invariant>")where the call cannot fail by construction. - For shared state, use
gradient_util::sync::Mutexrather thanstd::sync::Mutex. Poisoning gets ignored, so a panic in one critical section cannot break every laterlock()call. - Log through
tracing(info,debug,warn,error). Never useprintln!macros for logging. - Add
#[instrument]to significant async functions.
| Change | Also update |
|---|---|
New endpoint in backend/gradient-web/src/endpoints/ |
#[utoipa::path] on the handler and its route in backend/gradient-web/src/routes.rs. Handlers extract parameters, check authorization, query and respond |
| New table | A migration in backend/gradient-migration/src/, an entity in backend/gradient-entity/src/, see Migrations |
| Configuration option | A field in backend/gradient-types/src/cli/, or in backend/gradient-worker/src/config/options.rs for the worker, then the generated files below |
The handler annotations generate docs/gradient-api.yaml and the frontend types. Regenerate both files with these commands.
cargo run --manifest-path backend/Cargo.toml --features api-spec --bin gradient-api-spec > docs/gradient-api.yaml
cargo run --manifest-path backend/Cargo.toml --features api-spec --bin gradient-api-spec -- typescript > frontend/src/app/core/models/api.generated.ts
Flag, environment variable, NixOS option and the row in the Configuration reference derive from the field and its doc comment. Three commands refresh the generated files.
cargo run --manifest-path backend/Cargo.toml -p gradient-types --example options > backend/gradient-types/options.json
cargo run --manifest-path backend/Cargo.toml -p gradient-worker --example options > backend/gradient-worker/options.json
nix eval --json --file docs/tools/options.nix | python3 docs/tools/options.py > docs/generated/configuration-options.md
#[allow] Policy¶
#[allow(unused_imports)],#[allow(unused)]and#[allow(dead_code)]are forbidden (CI grep check). Contributors fix the warning instead.- Every other
#[allow(...)]must carryreason = "..."(clippy::allow_attributes_without_reason). - Uses of
#[allow(clippy::too_many_arguments)]are temporary, tracked in #503. allow-unwrap-in-testscan only reach code inside a#[test]function.- Integration tests and
gradient-test-supportuse a crate-level#![expect(clippy::unwrap_used, reason = "...")]attribute. - The
expectattribute will warn once the lastunwrap()call is gone.
Angular and TypeScript¶
- Build standalone components with signals (
signal(),computed()). Keep feature code in feature folders underfrontend/src/app/features/. - Take UI components from
gr-ui(@gradient/ui/ui, built on@angular/cdk). Render charts through<gr-metric-chart>(Apache ECharts). Get colours and spacing from the@gradient/ui/styles/variablesmodule. See the Frontend Style Guide. - Avoid UI or chart dependencies with a field-of-use restriction. The bundle is distributed under AGPL-3.0, and we cannot pass on a dependency licensed beyond MIT, BSD or Apache-2.0.
- A refreshed
pnpm-lock.yamlwill change thepnpmDepshash innix/packages/gradient-frontend.nix. To get the new hash, setlib.fakeHash, runnix build .#gradient-frontend.pnpmDepsand take the reported hash. minimumReleaseAgeinpnpm-workspace.yamlwill refuse packages younger than 24 hours. Run a localpnpm updateto pin the same versions the Nix build would take.
Nix¶
- Packages and modules live in
nix/: server options innix/modules/gradient.nix, worker options innix/modules/gradient-worker/, declarative state innix/modules/gradient-state.nix. - New modules need a NixOS VM test under
nix/tests/gradient/.