Skip to content

Commit 639ecf0

Browse files
ricsdeolclaude
andauthored
chore: quality improvement pass — tests, coverage, architecture (#3)
* docs: add quality improvement design spec Covers architecture refactoring (extract input.rs), test coverage tooling (cargo-llvm-cov, proptest, MockBackend), and code quality cleanup (dead_code audit, tokio feature slimming). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * docs: add quality improvement implementation plan 10-task plan covering: MockBackend tests, input.rs extraction, dead_code cleanup, proptest parsers, CI hardening with coverage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: slim tokio features, add proptest dev-dep * test: add MockBackend and Collector unit tests * refactor: extract input handling from main.rs into input.rs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test: add input handler unit tests * docs: clarify why std::thread::sleep is used in swap_reset * chore: remove unnecessary #[allow(dead_code)] suppressions * test: add proptest property-based tests for parsers Add property-based tests using proptest to linux.rs (parse_proc_swaps) and proc_reader.rs (parse_status, parse_stat_cpu_ticks) covering valid inputs, malformed inputs, and byte-conversion invariants. Also refactor resolve_key to use a KeyContext struct to resolve pre-existing clippy too_many_arguments warning. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * ci: add fmt check and coverage with cargo-llvm-cov * style: apply cargo fmt Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: fix cargo coverage alias and ci llvm-cov regex exclusion - Switch .cargo/config.toml alias to array syntax so the --ignore-filename-regex flag is passed as a discrete argument (string form silently dropped the regex under some cargo versions) - CI coverage step already uses the same exclusion flag to skip untestable UI/TUI/event-loop files; line coverage is now 82% on testable code, well above the 70% threshold Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix ci coverage * fix(ci): restore corrupted cache key in actions/cache step The key: field and end of the path block were mangled into a single line, causing "Input required and not supplied: key" in CI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 08614fe commit 639ecf0

25 files changed

+2431
-471
lines changed

.cargo/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[alias]
2+
# Run coverage excluding untestable UI/TUI/event-loop code.
3+
# Usage: cargo coverage
4+
coverage = ["llvm-cov", "--ignore-filename-regex", "src/(main|tui|ui/.*)", "--fail-under-lines", "70"]

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
uses: dtolnay/rust-toolchain@stable
2626
with:
2727
toolchain: "1.94.1"
28-
components: rustfmt, clippy
28+
components: rustfmt, clippy, llvm-tools-preview
2929

3030
- name: Cache cargo registry and build artifacts
3131
uses: actions/cache@v4
@@ -39,6 +39,9 @@ jobs:
3939
restore-keys: |
4040
${{ runner.os }}-cargo-
4141
42+
- name: Check formatting
43+
run: cargo fmt --check
44+
4245
- name: Build
4346
run: cargo build
4447

@@ -47,3 +50,8 @@ jobs:
4750

4851
- name: Tests
4952
run: cargo test
53+
54+
- uses: taiki-e/install-action@cargo-llvm-cov
55+
56+
- name: Coverage
57+
run: cargo llvm-cov --ignore-filename-regex "src/(main|tui|ui/.*)" --fail-under-lines 70

.rtk/filters.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Project-local RTK filters — commit this file with your repo.
2+
# Filters here override user-global and built-in filters.
3+
# Docs: https://github.com/rtk-ai/rtk#custom-filters
4+
schema_version = 1
5+
6+
# Example: suppress build noise from a custom tool
7+
# [filters.my-tool]
8+
# description = "Compact my-tool output"
9+
# match_command = "^my-tool\\s+build"
10+
# strip_ansi = true
11+
# strip_lines_matching = ["^\\s*$", "^Downloading", "^Installing"]
12+
# max_lines = 30
13+
# on_empty = "my-tool: ok"

CLAUDE.md

Lines changed: 101 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
55
## Commands
66

77
```bash
8-
cargo build # build debug
9-
cargo build --release # build release
10-
cargo run # run (requires Linux for full functionality)
11-
cargo test # run all tests
12-
cargo test <test_name> # run a single test
13-
cargo clippy -- -D warnings # lint
8+
rtk cargo build # build debug
9+
rtk cargo build --release # build release
10+
rtk cargo run # run (requires Linux for full functionality)
11+
rtk cargo test # run all tests
12+
rtk cargo test <test_name> # run a single test
13+
rtk cargo clippy -- -D warnings # lint
1414
```
1515

1616
## Project: swaptop
@@ -74,9 +74,9 @@ Phase 5 → create-swap wizard, tokio::process::Command, disk space validation
7474
Run these and fix any issues after implement all phases:
7575

7676
```bash
77-
cargo build # must compile clean (zero warnings)
78-
cargo clippy -- -D warnings # must pass with no warnings
79-
cargo test # all tests must pass
77+
rtk cargo build # must compile clean (zero warnings)
78+
rtk cargo clippy -- -D warnings # must pass with no warnings
79+
rtk cargo test # all tests must pass
8080
```
8181

8282
## Key constraints
@@ -86,3 +86,95 @@ cargo test # all tests must pass
8686
- `swapon`/`swapoff` require root — check `nix::unistd::geteuid() == 0` before calling
8787
- History is in-memory only (no persistence between sessions) — `VecDeque` capped at `max_history`
8888
- Chart widget expects `Vec<(f64, f64)>` — convert `Instant` to seconds-since-start when feeding charts
89+
90+
<!-- rtk-instructions v2 -->
91+
# RTK (Rust Token Killer) - Token-Optimized Commands
92+
93+
## Golden Rule
94+
95+
**Always prefix commands with `rtk`**. If RTK has a dedicated filter, it uses it. If not, it passes through unchanged. This means RTK is always safe to use.
96+
97+
**Important**: Even in command chains with `&&`, use `rtk`:
98+
```bash
99+
# ❌ Wrong
100+
git add . && git commit -m "msg" && git push
101+
102+
# ✅ Correct
103+
rtk git add . && rtk git commit -m "msg" && rtk git push
104+
```
105+
106+
## RTK Commands by Workflow
107+
108+
### Build & Compile (80-90% savings)
109+
```bash
110+
rtk cargo build # Cargo build output
111+
rtk cargo check # Cargo check output
112+
rtk cargo clippy # Clippy warnings grouped by file (80%)
113+
```
114+
115+
### Test (90-99% savings)
116+
```bash
117+
rtk cargo test # Cargo test failures only (90%)
118+
```
119+
120+
### Git (59-80% savings)
121+
```bash
122+
rtk git status # Compact status
123+
rtk git log # Compact log (works with all git flags)
124+
rtk git diff # Compact diff (80%)
125+
rtk git show # Compact show (80%)
126+
rtk git add # Ultra-compact confirmations (59%)
127+
rtk git commit # Ultra-compact confirmations (59%)
128+
rtk git push # Ultra-compact confirmations
129+
rtk git pull # Ultra-compact confirmations
130+
rtk git branch # Compact branch list
131+
rtk git fetch # Compact fetch
132+
rtk git stash # Compact stash
133+
rtk git worktree # Compact worktree
134+
```
135+
136+
Note: Git passthrough works for ALL subcommands, even those not explicitly listed.
137+
138+
### GitHub (26-87% savings)
139+
```bash
140+
rtk gh pr view <num> # Compact PR view (87%)
141+
rtk gh pr checks # Compact PR checks (79%)
142+
rtk gh run list # Compact workflow runs (82%)
143+
rtk gh issue list # Compact issue list (80%)
144+
rtk gh api # Compact API responses (26%)
145+
```
146+
147+
### Files & Search (60-75% savings)
148+
```bash
149+
rtk ls <path> # Tree format, compact (65%)
150+
rtk read <file> # Code reading with filtering (60%)
151+
rtk grep <pattern> # Search grouped by file (75%)
152+
rtk find <pattern> # Find grouped by directory (70%)
153+
```
154+
155+
### Analysis & Debug (70-90% savings)
156+
```bash
157+
rtk err <cmd> # Filter errors only from any command
158+
rtk log <file> # Deduplicated logs with counts
159+
rtk json <file> # JSON structure without values
160+
rtk deps # Dependency overview
161+
rtk env # Environment variables compact
162+
rtk summary <cmd> # Smart summary of command output
163+
rtk diff # Ultra-compact diffs
164+
```
165+
166+
### Network (65-70% savings)
167+
```bash
168+
rtk curl <url> # Compact HTTP responses (70%)
169+
rtk wget <url> # Compact download output (65%)
170+
```
171+
172+
### Meta Commands
173+
```bash
174+
rtk gain # View token savings statistics
175+
rtk gain --history # View command history with savings
176+
rtk discover # Analyze Claude Code sessions for missed RTK usage
177+
rtk proxy <cmd> # Run command without filtering (for debugging)
178+
rtk init # Add RTK instructions to CLAUDE.md
179+
```
180+
<!-- /rtk-instructions -->

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ edition = "2024"
66
[dependencies]
77
ratatui = "0.30.0"
88
crossterm = { version = "0.29.0", features = ["event-stream"] }
9-
tokio = { version = "1.51.1", features = ["full"] }
9+
tokio = { version = "1.51.1", features = ["macros", "rt-multi-thread", "time", "sync", "signal"] }
1010
tokio-util = "0.7.18"
1111
futures = "0.3.32"
1212
sysinfo = "0.38.4"
1313
nix = { version = "0.31.2", features = ["process", "signal", "mount", "user"] }
1414
color-eyre = "0.6.5"
1515
human_bytes = "0.4.3"
1616
glob = "0.3.3"
17+
18+
[dev-dependencies]
19+
proptest = "1"

0 commit comments

Comments
 (0)