Skip to content

Commit bc254fa

Browse files
committed
ci: improve GitHub workflows with Rust caching, linting, and tests
- Add Swatinem/rust-cache for faster CI builds - Add cargo fmt --check to enforce code formatting - Add cargo clippy with -D warnings for strict linting - Add cargo test to run Rust unit tests in CI - Consolidate test and lint into single CI job - Fix Node version inconsistency (use 22 everywhere) - Fix clippy warnings in Rust code (too_many_arguments, redundant_closure) - Format all Rust code with cargo fmt
1 parent b0c92b9 commit bc254fa

File tree

8 files changed

+226
-121
lines changed

8 files changed

+226
-121
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ jobs:
4141
with:
4242
targets: ${{ matrix.target }}
4343

44+
- name: Cache Cargo
45+
uses: Swatinem/rust-cache@v2
46+
with:
47+
workspaces: native -> target
48+
key: ${{ matrix.target }}
49+
4450
- name: Install cross-compilation tools (Linux ARM64)
4551
if: matrix.target == 'aarch64-unknown-linux-gnu'
4652
run: |
@@ -76,7 +82,7 @@ jobs:
7682
- name: Setup Node.js
7783
uses: actions/setup-node@v4
7884
with:
79-
node-version: '24'
85+
node-version: '22'
8086
cache: 'npm'
8187
registry-url: 'https://registry.npmjs.org'
8288

@@ -97,3 +103,5 @@ jobs:
97103

98104
- name: Publish to npm
99105
run: npm publish --provenance --access public
106+
env:
107+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/ci.yml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,29 @@ jobs:
2020

2121
- name: Setup Rust
2222
uses: dtolnay/rust-toolchain@stable
23+
with:
24+
components: clippy, rustfmt
25+
26+
- name: Cache Cargo
27+
uses: Swatinem/rust-cache@v2
28+
with:
29+
workspaces: native -> target
2330

2431
- name: Install dependencies
2532
run: npm ci
2633

34+
- name: Check Rust formatting
35+
working-directory: native
36+
run: cargo fmt --check
37+
38+
- name: Run Clippy
39+
working-directory: native
40+
run: cargo clippy -- -D warnings
41+
42+
- name: Run Rust tests
43+
working-directory: native
44+
run: cargo test
45+
2746
- name: Build native module
2847
working-directory: native
2948
run: |
@@ -36,22 +55,8 @@ jobs:
3655
- name: Run typecheck
3756
run: npm run typecheck
3857

39-
- name: Run tests
40-
run: npm run test:run
41-
42-
lint:
43-
runs-on: ubuntu-latest
44-
steps:
45-
- uses: actions/checkout@v4
46-
47-
- name: Setup Node.js
48-
uses: actions/setup-node@v4
49-
with:
50-
node-version: '22'
51-
cache: 'npm'
52-
53-
- name: Install dependencies
54-
run: npm ci
55-
5658
- name: Run lint
5759
run: npm run lint
60+
61+
- name: Run tests
62+
run: npm run test:run

native/src/db.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rusqlite::{Connection, params, OptionalExtension};
1+
use rusqlite::{params, Connection, OptionalExtension};
22
use std::path::Path;
33
use thiserror::Error;
44

@@ -189,7 +189,11 @@ pub fn get_embeddings_batch(
189189
return Ok(vec![]);
190190
}
191191

192-
let placeholders: String = content_hashes.iter().map(|_| "?").collect::<Vec<_>>().join(",");
192+
let placeholders: String = content_hashes
193+
.iter()
194+
.map(|_| "?")
195+
.collect::<Vec<_>>()
196+
.join(",");
193197
let query = format!(
194198
"SELECT content_hash, embedding FROM embeddings WHERE content_hash IN ({})",
195199
placeholders
@@ -221,7 +225,11 @@ pub fn get_missing_embeddings(
221225
return Ok(vec![]);
222226
}
223227

224-
let placeholders: String = content_hashes.iter().map(|_| "?").collect::<Vec<_>>().join(",");
228+
let placeholders: String = content_hashes
229+
.iter()
230+
.map(|_| "?")
231+
.collect::<Vec<_>>()
232+
.join(",");
225233
let query = format!(
226234
"SELECT content_hash FROM embeddings WHERE content_hash IN ({})",
227235
placeholders
@@ -250,6 +258,7 @@ pub fn get_missing_embeddings(
250258
// ============================================================================
251259

252260
/// Insert or update a chunk
261+
#[allow(clippy::too_many_arguments)]
253262
pub fn upsert_chunk(
254263
conn: &Connection,
255264
chunk_id: &str,
@@ -280,10 +289,7 @@ pub fn upsert_chunk(
280289
}
281290

282291
/// Batch insert or update chunks within a single transaction
283-
pub fn upsert_chunks_batch(
284-
conn: &mut Connection,
285-
chunks: &[ChunkRow],
286-
) -> DbResult<()> {
292+
pub fn upsert_chunks_batch(conn: &mut Connection, chunks: &[ChunkRow]) -> DbResult<()> {
287293
if chunks.is_empty() {
288294
return Ok(());
289295
}
@@ -406,9 +412,8 @@ pub fn add_chunks_to_branch(conn: &Connection, branch: &str, chunk_ids: &[String
406412
return Ok(());
407413
}
408414

409-
let mut stmt = conn.prepare(
410-
"INSERT OR IGNORE INTO branch_chunks (branch, chunk_id) VALUES (?, ?)",
411-
)?;
415+
let mut stmt =
416+
conn.prepare("INSERT OR IGNORE INTO branch_chunks (branch, chunk_id) VALUES (?, ?)")?;
412417

413418
for chunk_id in chunk_ids {
414419
stmt.execute(params![branch, chunk_id])?;
@@ -428,9 +433,8 @@ pub fn add_chunks_to_branch_batch(
428433

429434
let tx = conn.transaction()?;
430435
{
431-
let mut stmt = tx.prepare(
432-
"INSERT OR IGNORE INTO branch_chunks (branch, chunk_id) VALUES (?, ?)",
433-
)?;
436+
let mut stmt =
437+
tx.prepare("INSERT OR IGNORE INTO branch_chunks (branch, chunk_id) VALUES (?, ?)")?;
434438

435439
for chunk_id in chunk_ids {
436440
stmt.execute(params![branch, chunk_id])?;

native/src/hasher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use xxhash_rust::xxh3::xxh3_64;
1+
use anyhow::Result;
22
use std::fs;
33
use std::path::Path;
4-
use anyhow::Result;
4+
use xxhash_rust::xxh3::xxh3_64;
55

66
pub fn xxhash_content(content: &str) -> String {
77
format!("{:016x}", xxh3_64(content.as_bytes()))
@@ -21,7 +21,7 @@ mod tests {
2121
let hash1 = xxhash_content("hello world");
2222
let hash2 = xxhash_content("hello world");
2323
let hash3 = xxhash_content("different content");
24-
24+
2525
assert_eq!(hash1, hash2);
2626
assert_ne!(hash1, hash3);
2727
assert_eq!(hash1.len(), 16);

native/src/inverted_index.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,11 @@ impl InvertedIndexInner {
150150
continue;
151151
}
152152

153-
let df = self
154-
.term_to_chunks
155-
.get(term)
156-
.map(|s| s.len())
157-
.unwrap_or(0) as f64;
153+
let df = self.term_to_chunks.get(term).map(|s| s.len()).unwrap_or(0) as f64;
158154
let idf = ((n - df + 0.5) / (df + 0.5) + 1.0).ln();
159155

160-
let tf_norm =
161-
(tf * (k1 + 1.0)) / (tf + k1 * (1.0 - b + b * (doc_length as f64 / avg_doc_length)));
156+
let tf_norm = (tf * (k1 + 1.0))
157+
/ (tf + k1 * (1.0 - b + b * (doc_length as f64 / avg_doc_length)));
162158
score += idf * tf_norm;
163159
}
164160

0 commit comments

Comments
 (0)