-
-
Notifications
You must be signed in to change notification settings - Fork 8
Development
This page covers development tools, debugging, and code analysis for Pacsea contributors.
Related guides:
- Contributing Guide — Contribution guidelines and PR process
- How to use Pacsea — User documentation
- Configuration — Configuration reference
Pacsea includes several development scripts in dev/scripts/ to help with code quality, analysis, and documentation:
Generate a comprehensive complexity analysis report:
./dev/scripts/complexity_report.shThis generates dev/scripts/complexity_report.txt with detailed complexity metrics.
Check for Clippy errors and warnings:
./dev/scripts/clippy_errors.shOutputs to dev/scripts/clippy_errors.txt.
Check cognitive complexity specifically:
./dev/scripts/clippy_cognitive_complexity.shOutputs to dev/scripts/clippy_cognitive_complexity_report.txt.
Run the consolidated security checks used by CI:
./dev/scripts/security-check.shThis runs the local security gate flow (including vulnerability/license/policy checks where configured) so you can catch issues before opening a PR.
Generate Rust documentation:
./dev/scripts/generate_docs.sh
cargo doc --open # View the generated documentationGenerates HTML documentation in target/doc/ with private items included.
Generate module dependency graphs:
./dev/scripts/module_structure.shRequires cargo-modules and graphviz. Creates visual dependency graphs for each module in dev/scripts/Modules/.
Generate application control flow diagram:
./dev/scripts/generate_controlflow_diagram.sh
# With PNG export
./dev/scripts/generate_controlflow_diagram.sh --export-png --png-theme darkGenerates a Mermaid flowchart diagram showing the application's control flow. See dev/ControlFlow_Diagram.md for the generated diagram.
Pacsea includes complexity analysis tests to monitor code quality and maintainability. To view the detailed output from these tests, use the --nocapture flag:
cargo test --test cyclomatic_complexity test_cyclomatic_complexity -- --nocapturecargo test --test data_flow_complexity test_data_flow_complexity -- --nocapturecargo test --test cyclomatic_complexity --test data_flow_complexity -- --nocaptureOr run all tests matching "complexity":
cargo test complexity -- --nocaptureTo save the test output to a file, redirect stdout. To filter out test runner output (keep only the complexity reports), use grep:
# Cyclomatic complexity (filtered)
cargo test --test cyclomatic_complexity test_cyclomatic_complexity -- --nocapture 2>&1 | grep -vE "(^running|^test result:|^test tests::|Finished.*test.*profile|Running unittests|Running tests/)" | sed '/^$/N;/^\n$/d' > cyclomatic_complexity_report.txt
# Data flow complexity (filtered)
cargo test --test data_flow_complexity test_data_flow_complexity -- --nocapture 2>&1 | grep -vE "(^running|^test result:|^test tests::|Finished.*test.*profile|Running unittests|Running tests/)" | sed '/^$/N;/^\n$/d' > data_flow_complexity_report.txt
# Both tests (combined, filtered)
cargo test --test cyclomatic_complexity --test data_flow_complexity -- --nocapture 2>&1 | grep -vE "(^running|^test result:|^test tests::|Finished.*test.*profile|Running unittests|Running tests/)" | sed '/^$/N;/^\n$/d' > complexity_report.txt
# Append to existing file (use >> instead of >)
cargo test complexity -- --nocapture 2>&1 | grep -vE "(^running|^test result:|^test tests::|Finished.*test.*profile|Running unittests|Running tests/)" | sed '/^$/N;/^\n$/d' >> complexity_report.txtNote: The 2>&1 redirects stderr to stdout so all output is captured, grep -vE filters out test runner output, and sed '/^$/N;/^\n$/d' collapses multiple consecutive empty lines into single empty lines.
The tests generate detailed reports including:
- Summary statistics (total files, functions, complexity)
- Top 10 most complex functions
- Files ranked by total complexity
- Complexity distribution across the codebase
- Functions exceeding complexity thresholds
Complexity Thresholds:
- Cyclomatic complexity: Should be < 25 for new functions (warning at 10, very high at 20)
- Data flow complexity: Should be < 25 for new functions (warning at 10, very high at 50)
Pacsea uses the tracing crate for structured logging. Logs are written to ~/.config/pacsea/logs/pacsea.log.
Enable debug logging:
# Method 1: Verbose flag
cargo run -- --dry-run --verbose
# Method 2: Log level flag
cargo run -- --dry-run --log-level debug
# Method 3: Environment variable
RUST_LOG=pacsea=debug cargo run -- --dry-runAvailable log levels:
-
trace— Most detailed (very verbose) -
debug— Debug information -
info— General information (default) -
warn— Warnings -
error— Errors only
Preflight tracing: For detailed preflight operation timing:
PACSEA_PREFLIGHT_TRACE=1 cargo run -- --dry-run --log-level traceReal-time log monitoring:
tail -f ~/.config/pacsea/logs/pacsea.logFilter for errors/warnings:
grep -iE "(warn|error)" ~/.config/pacsea/logs/pacsea.logView recent logs:
tail -100 ~/.config/pacsea/logs/pacsea.log-
Use dry-run mode: Always use
--dry-runduring development to avoid unintended changes - Check logs first: Most issues are logged with helpful context
-
Enable debug logging: Use
--verboseorRUST_LOG=pacsea=debugfor detailed information - Test in isolation: Use a VM or container for testing install/update operations
- Check terminal compatibility: Test in different terminals (alacritty, kitty, xterm) if UI issues occur
-
src/main.rs: Application entry point, argument parsing, logging setup -
src/app/: Application runtime, event loop, state management -
src/events/: Event handling (keyboard, mouse, modals, install operations). Custom-repo flows live underevents/modals/repositories.rs,events/modals/foreign_overlap.rs, and install-sideevents/install/aur_dup_warn.rs. -
src/ui/: UI rendering components (panes, modals, widgets) -
src/logic/: Business logic (preflight, dependency resolution, package operations;logic/distro.rsmaps repo names to filter toggles and display labels, including BlackArch).src/logic/repos/parsesrepos.conf, builds the privileged apply plan (apply_plan.rs), and detects foreign/sync name overlap (foreign_overlap.rs). -
src/state/: Application state types and management -
src/theme/: Theme and configuration management -
src/i18n/: Internationalization and localization -
src/index/: Package index management (including optional official repositories such as BlackArch when[blackarch]is present in pacman—seeindex/distro.rsforis_blackarch_repo/blackarch_repo_names, andindex/fetch.rsfor merge behavior) -
src/install/: Package installation and removal logic -
src/sources/: Package source management (AUR, official repos)
Pacsea uses an async event-driven architecture:
-
Initialization: Runs config preflight (legacy migration, theme key ensure, settings reload and key ensure), then loads theme, caches, and locale—theme resolution happens after disk repair so partial
theme.conffiles do not break first paint -
Event Loop:
tokio::select!handles multiple async channels concurrently - Background Workers: Async workers handle search, analysis, and updates
- State Management: Centralized state with reactive updates
- UI Rendering: Ratatui-based TUI with immediate updates
See dev/ControlFlow_Diagram.md for a detailed control flow diagram.
Tests must be run single-threaded to avoid race conditions:
cargo test -- --test-threads=1
# or
RUST_TEST_THREADS=1 cargo testFor branch-ready validation, run in this order from repo root:
cargo fmt --all
cargo clippy --all-targets --all-features -- -D warnings
cargo check
cargo test -- --test-threads=1
./dev/scripts/security-check.sh-
Unit tests: In
src/files with#[cfg(test)]modules -
Integration tests: In
tests/directory -
Complexity tests:
tests/cyclomatic_complexity.rsandtests/data_flow_complexity.rs -
Preflight integration tests:
tests/preflight_integration/directory
Guidelines:
- Tests should be deterministic and not rely on external state
- Use
--dry-runin tests that would modify the system - For bug fixes: create failing tests first, then fix the issue
Optional official repos (e.g. BlackArch):
- Classification and label routing are covered by unit tests in
src/index/distro.rsandsrc/logic/distro.rs. - Optional-repo detection for the Results title bar is tested in
src/ui/results/utils.rs(e.g. BlackArch present vs absent in the official source list). - UI i18n fixtures must include the
app.results.filters.blackarchkey where other filter strings are initialized (tests will fail if it is missing). - Manual QA with a real BlackArch mirror: see QA Testing and the PR notes under
dev/PR/for the feature branch.
Pacsea-managed custom repos (repos.conf):
- Apply-plan quoting and safety:
src/logic/repos/apply_plan.rs(and tests in that module). - Modal / overlap behavior:
src/events/modals/tests/(e.g. preflight, repositories-related cases),install::command/install::executorfor--aurhelper command shapes. - User-facing behavior is documented on the wiki: How to use Pacsea — Custom repositories.
cargo build
# or
cargo run -- --dry-runcargo build --release
./target/release/pacsea --dry-runcargo checkcargo doc --no-deps --document-private-items
cargo doc --open # View in browserOr use the script:
./dev/scripts/generate_docs.shAll public functions, methods, structs, and enums should have rustdoc comments following this format:
/// What: Brief description of what the function does.
///
/// Inputs:
/// - `param1`: Description of parameter 1
/// - `param2`: Description of parameter 2
///
/// Output:
/// - Description of return value or side effects
///
/// Details:
/// - Additional context, edge cases, or important notes
pub fn example_function(param1: Type1, param2: Type2) -> Result<Type3> {
// implementation
}- Create a feature branch:
git checkout -b feat/my-feature - Implement the feature with tests
- Add rustdoc comments to all new public items
- Run quality checks:
cargo fmt,cargo clippy,cargo test - Check complexity:
cargo test complexity -- --nocapture - Update documentation (README/wiki if needed)
- Commit with conventional commit message
- Open PR with detailed description
- Create a failing test that reproduces the issue
- Fix the bug
- Verify the test passes
- Add additional tests for edge cases
- Run all quality checks
- Update documentation if behavior changed
- Commit and open PR
- Ensure existing tests pass before refactoring
- Refactor incrementally with tests passing at each step
- Check complexity doesn't increase
- Update documentation if structure changes
- Run all quality checks
cargo build --profile devperf record --call-graph dwarf ./target/debug/pacsea --dry-run
perf reportConsider using tools like valgrind or heaptrack for memory analysis.
-
Out of memory: Try
cargo build -j1to limit parallelism - Linker errors: Ensure all system dependencies are installed
-
Version conflicts: Run
cargo updateto update dependencies
-
Race conditions: Ensure tests run with
--test-threads=1 - Flaky tests: Check for timing dependencies or external state
-
Test failures: Run with
--nocaptureto see output:cargo test -- --nocapture --test-threads=1
- Too many warnings: Fix warnings incrementally
- Complexity warnings: Refactor to reduce complexity
- Pedantic warnings: These are denied by default, must be fixed
For more troubleshooting help, see the Troubleshooting guide.