Page:
Contributing
No results
1
Contributing
Vincent S. edited this page 2026-06-28 01:08:01 +02:00
Table of Contents
Contributing
Pre-commit gate
The repo ships a .githooks/pre-commit hook that runs:
cargo clippy --all-targets -- -D warnings
cargo test
It must be activated per clone:
git config core.hooksPath .githooks
Bypass a single commit with git commit --no-verify.
CI mirrors this gate: a Forgejo Actions workflow (
.forgejo/workflows/ci.yml) runs build + test +rustfmt --checkon every push.
Testing
cargo test # workspace tests (parsers, alert engine, server routes via tower oneshot)
cargo test -p alfred-core # one crate
cargo test parse_workspace_identifier # one test by name substring
cargo clippy --all-targets
Conventions
- Errors:
anyhowin the daemon; control handlers returnResult<String, String>mapped to HTTP status codes. - Config: structs use
#[serde(deny_unknown_fields)]and a realConfig::validate()(errors vs. warnings) — keep both in sync when adding fields. - Blocking work (subprocess calls, sysfs/statvfs, sqlite, NVML) belongs in
tokio::task::spawn_blockingor on the automation thread, never inline in an asynccollect(). (Some existing modules predate this rule.) - Optional-dep modules get a default-on Cargo feature gating both
dep:<crate>andpub mod <module>;+ thespawn_if_enabled!line.ModuleKindis never gated. See Modules.
Adding a module
See the checklist in Modules → Adding a module. The short version: ModuleKind (+ Display/FromStr/all()), config struct (+ validate()), spawn_if_enabled!, and both capabilities() and client/list.rs::builtin_metadata.
Gotchas
- Worker lifetime:
WorkerClientmust retain thetokio::process::Child(kill_on_drop); dropping the handle kills the worker. alfred-ytmdep pin: pinalloc-no-stdlibto2.0.4in the lockfile, orbrotli(pulled byreqwest) fails to compile.- Stdout discipline: client subcommands are waybar children — keep stdout pure JSON; logging is only initialised for
serve.
Seeded from the repo's README.md and CLAUDE.md — those remain the in-tree source of truth.