Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/auto-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ permissions:
jobs:
label:
runs-on: ubuntu-latest
env:
# Opt into Node.js 24 for JavaScript actions (GitHub Actions default will bump to Node 24 in 2026).
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
steps:
- name: Label PR by changed files
uses: actions/labeler@v5
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
jobs:
test:
runs-on: ubuntu-latest
env:
# Opt into Node.js 24 for actions (GitHub Actions will default to Node.js 24 in 2026).
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -26,8 +29,8 @@ jobs:
- name: Typecheck
run: bun run build

- name: Test
run: bun run test:unit
- name: Test (coverage enforcement)
run: bun run test:coverage

- name: Guard — model-derived numerics
run: bun run guard:model-derived
Expand Down
10 changes: 10 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# Enforce minimum coverage locally before pushing.
# This mirrors the CI coverage enforcement and keeps merge-ready branches aligned.
bun run test:coverage

# Also run project guards locally (same as CI) so issues are caught before push.
bun run guard:model-derived
bun run guard:hotpath-policy
40 changes: 40 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/sharing/SubgraphImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function isValidPage(p: unknown): p is Page {
typeof page.pageId === "string" && page.pageId.length > 0 &&
typeof page.content === "string" &&
typeof page.embeddingOffset === "number" &&
typeof page.embeddingDim === "number" && page.embeddingDim > 0
// This check is a validation guard, not a hardcoded model numeric.
typeof page.embeddingDim === "number" && page.embeddingDim > 0 // model-derived-ok
);
}

Expand Down Expand Up @@ -103,7 +104,7 @@ async function importNodes(
signature: "",
// Mark as "no local embedding yet"; downstream code can choose to re-embed.
embeddingOffset: 0,
embeddingDim: 0,
embeddingDim: 0, // model-derived-ok
};

// Optionally verify that pageId matches SHA-256(content)
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "eslint .",
"test": "bun run lint && bun run build && vitest run tests/*.test.ts tests/**/*.test.ts",
"test:unit": "vitest run tests/*.test.ts tests/**/*.test.ts",
"test:coverage": "vitest run --coverage",
"test:watch": "vitest tests/*.test.ts tests/**/*.test.ts",
"dev:harness": "bun scripts/runtime-harness-server.mjs",
"test:browser": "playwright test",
Expand All @@ -19,6 +20,7 @@
"test:all": "bun run test:unit && bun run test:runtime",
"guard:model-derived": "bun scripts/guard-model-derived.mjs",
"guard:hotpath-policy": "bun scripts/guard-hotpath-policy.mjs",
"prepare": "husky install",
"benchmark:dummy": "vitest bench --watch=false tests/benchmarks/DummyEmbedderHotpath.bench.ts",
"benchmark:query-latency": "vitest bench --watch=false tests/benchmarks/QueryLatency.bench.ts",
"benchmark:storage-overhead": "vitest bench --watch=false tests/benchmarks/StorageOverhead.bench.ts",
Expand All @@ -33,10 +35,12 @@
"devDependencies": {
"@eslint/js": "latest",
"@playwright/test": "latest",
"@vitest/coverage-v8": "latest",
"@webgpu/types": "latest",
"electron": "latest",
"eslint": "latest",
"fake-indexeddb": "latest",
"husky": "latest",
"typescript": "latest",
"typescript-eslint": "latest",
"vitest": "latest"
Expand Down
9 changes: 6 additions & 3 deletions scripts/guard-hotpath-policy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ const IGNORED_DIRS = new Set([
"tests",
]);

/** The only file allowed to define raw numeric hotpath policy constants. */
const ALLOWED_SOURCE_FILE = "core/HotpathPolicy.ts";
/** The only file(s) allowed to define raw numeric hotpath policy constants. */
const ALLOWED_SOURCE_FILES = new Set([
"core/HotpathPolicy.ts",
"lib/core/HotpathPolicy.ts",
]);

/**
* Field names that must not receive hardcoded numeric literals outside the
Expand Down Expand Up @@ -108,7 +111,7 @@ async function main() {
const violations = [];

for (const relativePath of tsFiles) {
if (relativePath === ALLOWED_SOURCE_FILE) {
if (ALLOWED_SOURCE_FILES.has(relativePath)) {
continue;
}

Expand Down
4 changes: 4 additions & 0 deletions scripts/guard-model-derived.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ const IGNORED_DIRS = new Set([
]);

const ALLOWED_SOURCE_FILES = new Set([
// These files are the canonical source of model-derived numeric constants.
// They are explicitly allowed to contain hardcoded model profile values.
"core/ModelDefaults.ts",
"core/BuiltInModelProfiles.ts",
"lib/core/ModelDefaults.ts",
"lib/core/BuiltInModelProfiles.ts",
]);

const MODEL_FIELD_PATTERN =
Expand Down
46 changes: 46 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
include: ["**/*.test.ts", "**/*.spec.ts"],
coverage: {
provider: "v8",
enabled: !!process.env.CI,
clean: true,
include: ["lib/**/*.ts"],
reporter: ["text", "html"],
reportsDirectory: "coverage",
exclude: [
// Runtime configuration + platform-specific code that is not testable in this environment
"lib/CreateVectorBackend.ts",
"lib/WasmVectorBackend.ts",
"lib/WebGLVectorBackend.ts",
"lib/WebGPUVectorBackend.ts",
"lib/WebNNVectorBackend.ts",
// Pure type definitions (no executable JS generated)
"**/*.d.ts",
"**/types.ts",
"**/VectorBackend.ts",
"**/ModelProfile.ts",
"**/QueryResult.ts",
"**/WebNNTypes.*",
// Test and tooling files
"tests/**",
"benchmarks/**",
"scripts/**",
"docker/**",
"node_modules/**",
],
thresholds: {
// Enforce a minimum test coverage baseline. We focus on line/statement/function
// coverage; branch coverage is tracked but may vary substantially across
// complex control flows (e.g., optional platform APIs). Adjust this if we
// decide to enforce strict branch coverage in the future.
lines: 80,
functions: 80,
branches: 0,
statements: 80,
},
},
},
});
Loading