Skip to content

Commit 6b31dd4

Browse files
committed
# Add 'latest' version support to findBestVersion
- Add support for explicit 'latest' keyword in version matching - Move version format validation after 'latest' check - Add test to verify 'latest' behaves same as no version specified - Update documentation to include 'latest' in version matching behavior
1 parent d058b48 commit 6b31dd4

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/store/VectorStoreService.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,25 @@ describe("VectorStoreService", () => {
294294
const error = await promise.catch((e) => e);
295295
expect(error.availableVersions).toEqual([]);
296296
});
297+
298+
it("should handle 'latest' the same as no version specified", async () => {
299+
const library = "test-lib";
300+
mockStore.queryUniqueVersions.mockResolvedValue([
301+
"1.0.0",
302+
"2.0.0",
303+
"3.0.0",
304+
]);
305+
306+
const latestVersion = await storeService.findBestVersion(
307+
library,
308+
"latest"
309+
);
310+
const defaultVersion = await storeService.findBestVersion(library);
311+
312+
expect(latestVersion).toBe("3.0.0");
313+
expect(defaultVersion).toBe("3.0.0");
314+
expect(mockStore.queryUniqueVersions).toHaveBeenCalledTimes(2);
315+
});
297316
});
298317

299318
describe("listLibraries", () => {

src/store/VectorStoreService.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class VectorStoreService {
5757
* Version matching behavior:
5858
* - Exact versions (e.g., "18.0.0"): Matches that version or any earlier version
5959
* - X-Range patterns (e.g., "5.x", "5.2.x"): Matches within the specified range
60-
* - No version: Returns the latest available version
60+
* - "latest" or no version: Returns the latest available version
6161
*
6262
* For documentation, we prefer matching older versions over no match at all,
6363
* since older docs are often still relevant and useful.
@@ -83,17 +83,9 @@ export class VectorStoreService {
8383
);
8484
}
8585

86-
if (targetVersion) {
87-
const versionRegex = /^(\d+)(?:\.(?:x(?:\.x)?|\d+(?:\.(?:x|\d+))?))?$|^$/;
88-
if (!versionRegex.test(targetVersion)) {
89-
logger.warn(`⚠️ Invalid version format: ${targetVersion}`);
90-
throw new VersionNotFoundError(library, targetVersion, validVersions);
91-
}
92-
}
93-
9486
const versionStrings = validVersions.map((v) => v.version);
9587

96-
if (!targetVersion) {
88+
if (!targetVersion || targetVersion === "latest") {
9789
const result = semver.maxSatisfying(versionStrings, "*");
9890
if (!result) {
9991
throw new VersionNotFoundError(
@@ -105,6 +97,12 @@ export class VectorStoreService {
10597
return result;
10698
}
10799

100+
const versionRegex = /^(\d+)(?:\.(?:x(?:\.x)?|\d+(?:\.(?:x|\d+))?))?$|^$/;
101+
if (!versionRegex.test(targetVersion)) {
102+
logger.warn(`⚠️ Invalid version format: ${targetVersion}`);
103+
throw new VersionNotFoundError(library, targetVersion, validVersions);
104+
}
105+
108106
let range = targetVersion;
109107

110108
if (!semver.validRange(targetVersion)) {

0 commit comments

Comments
 (0)