Skip to content

Commit 308d9f5

Browse files
authored
chore: fix Rust clippy/fmt errors and add Rust linting to CI (#2)
- Fix clippy errors: unwrap_used, manual_strip, dead code, needless_range_loop - Allow expect_used on static regex patterns in plugin_scan.rs - Add check-cfg for cfg(hyperlight) in native-globals Cargo.toml - Format all Rust code (analysis-guest + sandbox runtime) - Update CI to use just lint-all + test-all (adds Rust lint/fmt/clippy) - Rename just recipes for clarity: lint-rust -> lint-analysis-guest, etc. - Update all docs to reflect renamed recipes Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent a06a5c5 commit 308d9f5

19 files changed

Lines changed: 400 additions & 393 deletions

File tree

.claude/CLAUDE.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ just start # Run agent (tsx src/agent/index.ts)
4242

4343
# ── Testing ──
4444
just test # Run TypeScript tests
45-
just test-rust # Run Rust tests (analysis-guest)
46-
just test-all # Run all tests (TS + Rust)
45+
just test-analysis-guest # Run Rust tests (analysis-guest)
46+
just test-all # Run all tests (TS + Rust)
4747

4848
# ── Formatting ──
49-
just fmt # Format TypeScript/JavaScript
50-
just fmt-rust # Format Rust (analysis-guest)
51-
just fmt-runtime # Format Rust (sandbox/runtime)
52-
just fmt-all # Format all code
49+
just fmt # Format TypeScript/JavaScript
50+
just fmt-analysis-guest # Format Rust (analysis-guest)
51+
just fmt-runtime # Format Rust (sandbox/runtime)
52+
just fmt-all # Format all code
5353

5454
# ── Linting ──
55-
just lint # TypeScript: fmt-check + typecheck
56-
just lint-rust # Rust: clippy + fmt-check (analysis-guest)
57-
just lint-runtime # Rust: clippy + fmt-check (runtime)
58-
just lint-all # All lints
55+
just lint # TypeScript: fmt-check + typecheck
56+
just lint-analysis-guest # Rust: clippy + fmt-check (analysis-guest)
57+
just lint-runtime # Rust: clippy + fmt-check (runtime)
58+
just lint-all # All lints
5959

6060
# ── Quality Gate ──
6161
just check # Full quality gate: lint-all + test-all

.github/copilot-instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Individual commands:
4646
| `just fmt` | Format TS/JS with Prettier | Before committing |
4747
| `just lint` | `fmt-check` + `tsc --noEmit` | Quick validation |
4848
| `just test` | Run Vitest suite (30 test files, ~1700 tests) | After TS changes |
49-
| `just test-rust` | Run Rust tests in code-validator | After Rust changes |
49+
| `just test-analysis-guest` | Run Rust tests in code-validator | After Rust changes |
5050
| `just test-all` | Both TS + Rust tests | Full validation |
5151
| `just start` | Run agent with `tsx` (no build needed) | Dev/testing |
5252
| `just binary-release` | Build standalone binary to `dist/bin/hyperagent` | Release builds |
@@ -93,5 +93,5 @@ Before considering a change complete:
9393
1. `just fmt` — all code formatted
9494
2. `just lint` — TypeScript compiles with zero errors
9595
3. `just test` — all ~1700 tests pass
96-
4. If Rust code was changed: `just test-rust` passes
96+
4. If Rust code was changed: `just test-analysis-guest` passes
9797
5. No new `expect`/`unwrap`/`assert` in production TS code

.github/instructions/tests.instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Vitest test suite for Hyperagent.
1010

1111
```bash
1212
just test # Run all TypeScript tests
13-
just test-rust # Run Rust tests (analysis-guest)
13+
just test-analysis-guest # Run Rust tests (analysis-guest)
1414
just test-all # Run both
1515
```
1616

.github/workflows/pr-validate.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,11 @@ jobs:
3636
- name: Setup
3737
run: just setup
3838

39-
- name: Format check
40-
run: npm run fmt:check
39+
- name: Lint (TS + Rust)
40+
run: just lint-all
4141

42-
- name: Typecheck
43-
run: npm run typecheck
44-
45-
- name: Test
46-
run: just test
42+
- name: Test (TS + Rust)
43+
run: just test-all
4744

4845
# Build and test on all hypervisor configurations (1ES runners have Rust + just)
4946
# NOTE: Windows WHP support is temporarily disabled pending upstream

CLAUDE.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ just start # Run agent (tsx src/agent/index.ts)
4242

4343
# ── Testing ──
4444
just test # Run TypeScript tests
45-
just test-rust # Run Rust tests (analysis-guest)
46-
just test-all # Run all tests (TS + Rust)
45+
just test-analysis-guest # Run Rust tests (analysis-guest)
46+
just test-all # Run all tests (TS + Rust)
4747

4848
# ── Formatting ──
49-
just fmt # Format TypeScript/JavaScript
50-
just fmt-rust # Format Rust (analysis-guest)
51-
just fmt-runtime # Format Rust (sandbox/runtime)
52-
just fmt-all # Format all code
49+
just fmt # Format TypeScript/JavaScript
50+
just fmt-analysis-guest # Format Rust (analysis-guest)
51+
just fmt-runtime # Format Rust (sandbox/runtime)
52+
just fmt-all # Format all code
5353

5454
# ── Linting ──
55-
just lint # TypeScript: fmt-check + typecheck
56-
just lint-rust # Rust: clippy + fmt-check (analysis-guest)
57-
just lint-runtime # Rust: clippy + fmt-check (runtime)
58-
just lint-all # All lints
55+
just lint # TypeScript: fmt-check + typecheck
56+
just lint-analysis-guest # Rust: clippy + fmt-check (analysis-guest)
57+
just lint-runtime # Rust: clippy + fmt-check (runtime)
58+
just lint-all # All lints
5959

6060
# ── Quality Gate ──
6161
just check # Full quality gate: lint-all + test-all

Justfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,17 @@ lint: fmt-check typecheck
171171
@echo "✅ Lint passed — looking sharp"
172172

173173
# Lint Rust code in analysis-guest
174-
lint-rust:
174+
lint-analysis-guest:
175175
cd "{{analysis-guest-dir}}" && cargo fmt --check && cargo clippy --workspace -- -D warnings
176-
@echo "Rust lint passed"
176+
@echo "Analysis-guest lint passed"
177177

178178
# Format Rust code in analysis-guest
179-
fmt-rust:
179+
fmt-analysis-guest:
180180
cd "{{analysis-guest-dir}}" && cargo fmt
181181

182182
# Test Rust code in analysis-guest
183183
# Note: --test-threads=1 required because QuickJS context isn't thread-safe
184-
test-rust:
184+
test-analysis-guest:
185185
cd "{{analysis-guest-dir}}" && cargo test --workspace -- --test-threads=1
186186

187187
# ── HyperAgent Runtime (native modules) ──────────────────────────────
@@ -210,15 +210,15 @@ fmt-runtime:
210210
cd "{{runtime-dir}}" && cargo +1.89 fmt --all
211211

212212
# Full lint: TypeScript + Rust (analysis-guest + runtime)
213-
lint-all: lint lint-rust lint-runtime
213+
lint-all: lint lint-analysis-guest lint-runtime
214214
@echo "✅ All lints passed"
215215

216216
# Full format: TypeScript + Rust
217-
fmt-all: fmt fmt-rust fmt-runtime
217+
fmt-all: fmt fmt-analysis-guest fmt-runtime
218218
@echo "✅ All code formatted"
219219

220220
# Full test: TypeScript + Rust
221-
test-all: test test-rust
221+
test-all: test test-analysis-guest
222222
@echo "✅ All tests passed"
223223

224224
# ── OOXML Validation ─────────────────────────────────────────────────

docs/DEVELOPMENT.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ npm test -- tests/plugin-manager.test.ts
160160
npm test -- --coverage
161161

162162
# Rust tests only
163-
just test-rust # Tests analysis-guest
163+
just test-analysis-guest # Tests analysis-guest
164164

165165
# All tests (TS + Rust)
166166
just test-all
@@ -187,10 +187,10 @@ just fmt # Format TS/JS
187187
just lint # Check format + typecheck
188188

189189
# Rust only
190-
just fmt-rust # Format analysis-guest Rust
191-
just lint-rust # Clippy + format check for analysis-guest
192-
just fmt-runtime # Format runtime Rust
193-
just lint-runtime # Clippy + format check for runtime
190+
just fmt-analysis-guest # Format analysis-guest Rust
191+
just lint-analysis-guest # Clippy + format check for analysis-guest
192+
just fmt-runtime # Format runtime Rust
193+
just lint-runtime # Clippy + format check for runtime
194194

195195
# Everything (TS + Rust)
196196
just fmt-all # Format all code

src/code-validator/guest/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Analyze a library tarball for security issues.
163163
just test
164164

165165
# Rust tests only
166-
just test-rust
166+
just test-analysis-guest
167167

168168
# Node.js tests only
169169
just test-node

src/code-validator/guest/host/src/runtime.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,12 @@ pub(crate) fn get_analysis_runtime() -> Option<Handle> {
9494
///
9595
/// After calling this, `get_analysis_runtime()` will return `None`.
9696
pub(crate) fn shutdown_runtime() {
97-
if let Some(mutex) = ANALYSIS_RUNTIME.get() {
98-
if let Ok(mut guard) = mutex.lock() {
99-
if let Some(rt) = guard.take() {
100-
eprintln!("[hyperlight-analysis] Shutting down runtime...");
101-
rt.shutdown_timeout(SHUTDOWN_TIMEOUT);
102-
eprintln!("[hyperlight-analysis] Runtime shutdown complete");
103-
}
104-
}
97+
if let Some(mutex) = ANALYSIS_RUNTIME.get()
98+
&& let Ok(mut guard) = mutex.lock()
99+
&& let Some(rt) = guard.take()
100+
{
101+
eprintln!("[hyperlight-analysis] Shutting down runtime...");
102+
rt.shutdown_timeout(SHUTDOWN_TIMEOUT);
103+
eprintln!("[hyperlight-analysis] Runtime shutdown complete");
105104
}
106105
}

src/code-validator/guest/host/src/sandbox.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ use hyperlight_host::sandbox::uninitialized::GuestBinary;
3636
use hyperlight_host::{MultiUseSandbox, UninitializedSandbox};
3737
use napi::bindgen_prelude::*;
3838

39-
use crate::runtime::get_analysis_runtime;
4039
use crate::ANALYSIS_RUNTIME;
40+
use crate::runtime::get_analysis_runtime;
4141

4242
/// Heap size for the guest (16 MB).
4343
const GUEST_HEAP_SIZE: u64 = 16 * 1024 * 1024;
@@ -76,12 +76,8 @@ const GUEST_OUTPUT_SIZE: usize = 4 * 1024 * 1024;
7676
pub async fn call_guest_function(function_name: &str, input: String) -> Result<String> {
7777
let function_name = function_name.to_string();
7878

79-
let handle = get_analysis_runtime().ok_or_else(|| {
80-
Error::new(
81-
Status::GenericFailure,
82-
"Analysis runtime not available",
83-
)
84-
})?;
79+
let handle = get_analysis_runtime()
80+
.ok_or_else(|| Error::new(Status::GenericFailure, "Analysis runtime not available"))?;
8581

8682
// Run the blocking Hyperlight operations on the runtime's thread pool
8783
handle
@@ -101,12 +97,8 @@ pub async fn call_guest_function_2(
10197
) -> Result<String> {
10298
let function_name = function_name.to_string();
10399

104-
let handle = get_analysis_runtime().ok_or_else(|| {
105-
Error::new(
106-
Status::GenericFailure,
107-
"Analysis runtime not available",
108-
)
109-
})?;
100+
let handle = get_analysis_runtime()
101+
.ok_or_else(|| Error::new(Status::GenericFailure, "Analysis runtime not available"))?;
110102

111103
// Run the blocking Hyperlight operations on the runtime's thread pool
112104
handle

0 commit comments

Comments
 (0)