Files
wehub-resource-sync 1b279d4d10
Lua CI / lua-language-server type check (push) Failing after 1s
Lua CI / luacheck lint (push) Failing after 1s
Python CI / Python bindings (ubuntu-latest) (push) Failing after 1s
Build & Publish / Build Neovim aarch64-linux-android (push) Failing after 3s
Build & Publish / Build Neovim aarch64-unknown-linux-gnu (push) Failing after 0s
Build & Publish / Build Neovim aarch64-unknown-linux-musl (push) Failing after 1s
Build & Publish / Build Neovim x86_64-unknown-linux-gnu (push) Failing after 1s
Build & Publish / Build Neovim x86_64-unknown-linux-musl (push) Failing after 1s
Build & Publish / Build C FFI aarch64-linux-android (push) Failing after 1s
Build & Publish / Build C FFI aarch64-unknown-linux-gnu (push) Failing after 1s
Build & Publish / Build C FFI aarch64-unknown-linux-musl (push) Failing after 0s
Build & Publish / Build C FFI x86_64-unknown-linux-gnu (push) Failing after 1s
Build & Publish / Build C FFI x86_64-unknown-linux-musl (push) Failing after 3s
Build & Publish / Build MCP aarch64-unknown-linux-gnu (push) Failing after 1s
Build & Publish / Build MCP aarch64-unknown-linux-musl (push) Failing after 0s
Build & Publish / Build MCP x86_64-unknown-linux-gnu (push) Failing after 2s
Rust CI / Fuzz Tests (ubuntu-latest) (push) Failing after 1s
Rust CI / Build i686-unknown-linux-gnu (push) Failing after 1s
Rust CI / cargo fmt (push) Failing after 1s
Build & Publish / Build MCP x86_64-unknown-linux-musl (push) Failing after 4s
Build & Publish / Build Python wheels aarch64 (ubuntu-latest) (push) Failing after 1s
Build & Publish / Build Python wheels x86_64 (ubuntu-latest) (push) Failing after 1s
Build & Publish / Build Python sdist (push) Failing after 0s
Rust CI / Test (ubuntu-latest) (push) Failing after 1s
Rust CI / cargo clippy (push) Failing after 1s
Spelling / Spell Check with Typos (push) Failing after 1s
Stylua / Check lua files using Stylua (push) Failing after 1s
e2e Tests / e2e (ubuntu-latest) (push) Failing after 4s
e2e Tests / e2e (alpine-musl) (push) Successful in 58m54s
Build & Publish / Build C FFI aarch64-apple-darwin (push) Has been cancelled
Build & Publish / Build C FFI aarch64-pc-windows-msvc (push) Has been cancelled
Build & Publish / Build C FFI x86_64-apple-darwin (push) Has been cancelled
Build & Publish / Build C FFI x86_64-pc-windows-msvc (push) Has been cancelled
e2e Tests / e2e (macos-latest) (push) Has been cancelled
e2e Tests / e2e (windows-latest) (push) Has been cancelled
Nix CI / check (push) Has been cancelled
Python CI / Python bindings (macos-latest) (push) Has been cancelled
Python CI / Python bindings (windows-latest) (push) Has been cancelled
Build & Publish / Build Neovim aarch64-apple-darwin (push) Has been cancelled
Build & Publish / Build Neovim aarch64-pc-windows-msvc (push) Has been cancelled
Build & Publish / Build Neovim x86_64-apple-darwin (push) Has been cancelled
Build & Publish / Build Neovim x86_64-pc-windows-msvc (push) Has been cancelled
Build & Publish / Build MCP aarch64-apple-darwin (push) Has been cancelled
Build & Publish / Build MCP aarch64-pc-windows-msvc (push) Has been cancelled
Build & Publish / Build MCP x86_64-apple-darwin (push) Has been cancelled
Build & Publish / Build MCP x86_64-pc-windows-msvc (push) Has been cancelled
Build & Publish / Build Python wheels aarch64 (macos-latest) (push) Has been cancelled
Build & Publish / Build Python wheels x86_64 (macos-latest) (push) Has been cancelled
Build & Publish / Build Python wheels x86_64 (windows-latest) (push) Has been cancelled
Build & Publish / Release (push) Has been cancelled
Build & Publish / Publish Python wheels to PyPI (push) Has been cancelled
Build & Publish / Publish Rust crates (push) Has been cancelled
Build & Publish / Publish npm packages (push) Has been cancelled
Rust CI / Test (macos-latest) (push) Has been cancelled
Rust CI / Test (windows-latest) (push) Has been cancelled
Rust CI / Fuzz Tests (macos-latest) (push) Has been cancelled
Rust CI / Fuzz Tests (windows-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:24:42 +08:00

157 lines
4.9 KiB
TypeScript

import { FileFinder } from "./src/index";
import { resolve, dirname } from "node:path";
async function main() {
console.log("=== fff Test Script ===\n");
// Check if library is available
console.log("Checking library availability...");
const available = FileFinder.isAvailable();
console.log(`Library available: ${available}\n`);
if (!available) {
console.error("Native library not found!");
console.error("Build it with: cargo build --release -p fff-c");
process.exit(1);
}
// Health check (before creating instance)
console.log("Health check (no instance):");
const healthBefore = FileFinder.healthCheckStatic();
if (healthBefore.ok) {
console.log(` Version: ${healthBefore.value.version}`);
console.log(` Git available: ${healthBefore.value.git.available}`);
console.log(
` File picker initialized: ${healthBefore.value.filePicker.initialized}`,
);
} else {
console.error(` Error: ${healthBefore.error}`);
}
console.log();
// Initialize with the root project directory to test on more files
const testDir = resolve(dirname(import.meta.path), "../..");
console.log(`Creating instance with base path: ${testDir}`);
const createResult = FileFinder.create({
basePath: testDir,
});
if (!createResult.ok) {
console.error(`Create failed: ${createResult.error}`);
process.exit(1);
}
const finder = createResult.value;
console.log("Instance created successfully!\n");
// Wait for scan with polling to show progress
console.log("Waiting for initial scan...");
const startTime = Date.now();
let lastCount = 0;
while (finder.isScanning()) {
const progress = finder.getScanProgress();
if (progress.ok && progress.value.scannedFilesCount !== lastCount) {
lastCount = progress.value.scannedFilesCount;
console.log(` Scanning: ${lastCount} files...`);
}
await new Promise((r) => setTimeout(r, 100));
if (Date.now() - startTime > 30000) {
console.error(" Scan timeout after 30s");
break;
}
}
// Get final scan progress
const progress = finder.getScanProgress();
if (progress.ok) {
console.log(`Scan complete: ${progress.value.scannedFilesCount} files indexed`);
console.log(`Scan time: ${Date.now() - startTime}ms`);
}
console.log();
// Search test
console.log("Searching for 'lib.rs'...");
const searchResult = finder.fileSearch("lib.rs", { pageSize: 5 });
if (searchResult.ok) {
console.log(`Found ${searchResult.value.totalMatched} matches (showing first 5):\n`);
for (let i = 0; i < searchResult.value.items.length; i++) {
const item = searchResult.value.items[i];
const score = searchResult.value.scores[i];
console.log(` ${item.relativePath}`);
console.log(
` Score: ${score.total} (base: ${score.baseScore}, filename: ${score.filenameBonus})`,
);
console.log(` Git: ${item.gitStatus}`);
}
} else {
console.error(`Search failed: ${searchResult.error}`);
}
console.log();
// Search with different query
console.log("Searching for 'package.json'...");
const searchResult2 = finder.fileSearch("package.json", { pageSize: 3 });
if (searchResult2.ok) {
console.log(`Found ${searchResult2.value.totalMatched} matches:\n`);
for (const item of searchResult2.value.items) {
console.log(` ${item.relativePath}`);
}
} else {
console.error(`Search failed: ${searchResult2.error}`);
}
console.log();
// Health check (after init)
console.log("Health check (with instance):");
const healthAfter = finder.healthCheck();
if (healthAfter.ok) {
console.log(` File picker initialized: ${healthAfter.value.filePicker.initialized}`);
console.log(` Base path: ${healthAfter.value.filePicker.basePath}`);
console.log(` Indexed files: ${healthAfter.value.filePicker.indexedFiles}`);
if (healthAfter.value.git.repositoryFound) {
console.log(` Git workdir: ${healthAfter.value.git.workdir}`);
}
}
console.log();
// Test multiple instances
console.log("Testing multiple instances...");
const finder2Result = FileFinder.create({ basePath: testDir });
if (finder2Result.ok) {
const finder2 = finder2Result.value;
console.log(" Second instance created successfully");
finder2.waitForScanBlocking(5000);
const search2 = finder2.fileSearch("Cargo.toml");
if (search2.ok) {
console.log(
` Second instance found ${search2.value.totalMatched} matches for 'Cargo.toml'`,
);
}
finder2.destroy();
console.log(" Second instance destroyed");
// First instance should still work
const search3 = finder.fileSearch("Cargo.toml");
if (search3.ok) {
console.log(` First instance still works: ${search3.value.totalMatched} matches`);
}
}
console.log();
// Cleanup
console.log("Cleaning up...");
finder.destroy();
console.log(`Cleanup successful! (isDestroyed: ${finder.isDestroyed})`);
console.log("\n=== Test Complete ===");
}
main().catch(console.error);