Thank you for your interest in contributing to token-privilege! This document provides guidelines and information for contributors.
This project follows the Contributor Covenant Code of Conduct. Please be respectful and constructive in all interactions.
Before working in a specific area, check GOTCHAS.md for hard-won lessons and edge cases organized by domain. It covers unsafe code rules, clippy/rustdoc pitfalls, CI quirks, pre-commit hook behavior, and platform-specific considerations.
- Rust 1.91+ (see
rust-toolchain.toml) - Git with commit signing configured
- mise for toolchain management
git clone https://github.com/EvilBit-Labs/token-privilege.git
cd token-privilege
mise install
cargo buildAfter mise install, the following tools are available: just, cargo-nextest, cargo-llvm-cov, cargo-deny, and cargo-audit.
All commands are orchestrated through the justfile:
| Command | Description |
|---|---|
just ci-check |
Full CI parity check (run before pushing) |
just test |
Run all tests via cargo nextest |
just test-all |
Run all tests including ignored/slow tests |
just lint |
Run all linters (fmt, clippy, actions, docs) |
just fmt |
Format all code |
just coverage |
Generate lcov coverage report |
just coverage-check |
Coverage with --fail-under-lines 85 |
just audit |
Run cargo audit |
just deny |
Run cargo deny check |
just docs-build |
Build rustdoc and mdBook |
Run a single test:
cargo nextest run -E 'test(test_name)'Run clippy manually:
cargo clippy -- -D warningsThe crate has five source files in src/:
| File | Role |
|---|---|
lib.rs |
Public API, re-exports, module declarations, non-Windows stubs |
elevation.rs |
is_elevated() implementation |
privilege.rs |
Privilege querying and enumeration functions |
error.rs |
TokenPrivilegeError enum (uses thiserror) |
ffi.rs |
All unsafe Win32 FFI, RAII handle wrapper |
Layered design: consumer crate -> public API (lib.rs) -> domain modules (elevation.rs, privilege.rs) -> FFI boundary (ffi.rs) -> windows crate -> Win32 kernel.
Create branches from main using the following prefixes:
feat/-- new featuresfix/-- bug fixesdocs/-- documentation onlyrefactor/-- code restructuring without behavior changetest/-- adding or updating testschore/-- maintenance (deps, CI config, tooling)perf/-- performance improvementsci/-- CI/CD pipeline changes
Before submitting a PR, verify that:
- All tests pass (
just test) - No clippy warnings (
cargo clippy -- -D warnings) - Code is formatted (
just fmt-check) - Documentation builds (
just docs-build) - Coverage is at least 85% (
just coverage-check)
- All
unsafecode MUST be confined toffi.rs. - Every
unsafeblock MUST have a// SAFETY:comment explaining the invariants. undocumented_unsafe_blocks = "deny"is enforced via Clippy configuration.- Never introduce
unsafein any other module. If you need new FFI calls, add them toffi.rsand expose a safepub(crate)wrapper.
- Unit tests live in each module as
#[cfg(test)] mod tests. - Integration tests live in
tests/. - Windows-specific tests are gated with
#[cfg(target_os = "windows")]. - Non-Windows stub tests verify that all public functions return
Err(TokenPrivilegeError::UnsupportedPlatform). SeChangeNotifyPrivilegeis the reliable test privilege -- it is enabled on all Windows processes by default.- Use
cargo-nextest(notcargo test) for running tests.
Use Conventional Commits format:
<type>(<scope>): <description>
Types: feat, fix, refactor, docs, test, chore, perf, ci
Scopes: lib, api, error, elevation, privilege, privileges, ffi, safety, security, docs, book, tests, ci, deps, release
Special rules:
- Changes touching
unsafeMUST useffiorsafetyscope with safety invariant in the commit body. - Cross-platform behavior changes must note Windows vs non-Windows impact.
- Fork the repository.
- Create a branch from
mainusing the naming convention above. - Make your changes with conventional commit messages.
- Sign your commits with the DCO sign-off (
git commit -s). - Open a PR against
mainwith a clear description of the change. - Ensure CI passes -- the pipeline runs formatting, linting, tests, and coverage checks.
- A maintainer will review your PR. Address any feedback and push additional commits (do not force-push during review).
All contributions require a Developer Certificate of Origin sign-off. Use the -s flag when committing:
git commit -s -m "feat(privilege): add new privilege constant"By contributing, you agree that your contributions will be dual licensed under MIT and Apache-2.0, without any additional terms or conditions.