Skip to content
Open
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
6 changes: 6 additions & 0 deletions tests/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ describe("version helpers", () => {
expect(compareVersions("1.2.3-beta", "1.2.3-alpha")).toBeGreaterThan(0);
});

it("ignores build metadata when comparing versions (semver 10)", () => {
// Build metadata carries no precedence: equal to the bare release.
expect(compareVersions("1.2.3+build", "1.2.3")).toBe(0);
expect(compareVersions("1.2.3-beta+a", "1.2.3-beta+b")).toBe(0);
});

it("ranks a pre-release below its associated release (semver 11.3)", () => {
expect(compareVersions("1.2.3-beta.1", "1.2.3")).toBeLessThan(0);
expect(compareVersions("1.2.3", "1.2.3-beta.1")).toBeGreaterThan(0);
Expand Down
21 changes: 21 additions & 0 deletions tests/local-advisory-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ describe("LocalAdvisorySource", () => {
cleanupDbPath(dbPath);
}
});
it("flags a pre-release below the fix via the real versionMatchesRange path (issue #1087)", async () => {
const dbPath = createTempDbPath();
const db = new LocalAdvisoryDatabase(dbPath);
const source = new LocalAdvisorySource(db);

try {
seedVulnerability(db); // lodash fixed at 4.17.21

// 4.17.21-beta.1 sorts below 4.17.21, so it is still inside the affected range.
const results = await source.queryBatch([
createPackage("lodash", "4.17.21-beta.1"),
createPackage("lodash", "4.17.21"),
]);

expect(results[0]?.vulnerabilities).toEqual([{ id: "OSV-2026-LOCAL-1" }]);
expect(results[1]?.vulnerabilities).toEqual([]);
} finally {
db.close();
cleanupDbPath(dbPath);
}
});

it("returns stored vulnerability documents by id", async () => {
const dbPath = createTempDbPath();
Expand Down