-
Notifications
You must be signed in to change notification settings - Fork 2
feat(ui): Add agent version compatibility check #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { compareVersions, isAgentCompatible } from "@/utils/version"; | ||
|
|
||
| describe("compareVersions", () => { | ||
| it("returns 0 for equal versions", () => { | ||
| expect(compareVersions("1.2.3", "1.2.3")).toBe(0); | ||
| }); | ||
|
|
||
| it("returns -1 when a < b", () => { | ||
| expect(compareVersions("0.1.4", "0.1.5")).toBe(-1); | ||
| expect(compareVersions("0.1.9", "0.2.0")).toBe(-1); | ||
| expect(compareVersions("0.9.9", "1.0.0")).toBe(-1); | ||
| }); | ||
|
|
||
| it("returns 1 when a > b", () => { | ||
| expect(compareVersions("0.1.5", "0.1.4")).toBe(1); | ||
| expect(compareVersions("1.0.0", "0.9.9")).toBe(1); | ||
| }); | ||
|
|
||
| it("handles v prefix", () => { | ||
| expect(compareVersions("v1.0.0", "1.0.0")).toBe(0); | ||
| }); | ||
|
|
||
| it("handles wildcard x as infinity", () => { | ||
| expect(compareVersions("0.5.0", "0.x.x")).toBe(-1); | ||
| expect(compareVersions("1.0.0", "0.x.x")).toBe(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe("isAgentCompatible", () => { | ||
| it("returns compatible for unknown version", () => { | ||
| const result = isAgentCompatible("unknown"); | ||
| expect(result.compatible).toBe(true); | ||
| }); | ||
|
|
||
| it("returns compatible for empty version", () => { | ||
| const result = isAgentCompatible(""); | ||
| expect(result.compatible).toBe(true); | ||
| }); | ||
|
|
||
| it("returns compatible for valid version", () => { | ||
| const result = isAgentCompatible("0.1.5"); | ||
| expect(result.compatible).toBe(true); | ||
| }); | ||
|
|
||
| it("returns incompatible for old version", () => { | ||
| const result = isAgentCompatible("0.1.3"); | ||
| expect(result.compatible).toBe(false); | ||
| expect(result.message).toContain("too old"); | ||
| }); | ||
|
|
||
| it("returns compatible for minimum version", () => { | ||
| const result = isAgentCompatible("0.1.4"); | ||
| expect(result.compatible).toBe(true); | ||
| }); | ||
|
|
||
| it("returns incompatible for version beyond max", () => { | ||
| const result = isAgentCompatible("1.0.0"); | ||
| expect(result.compatible).toBe(false); | ||
| expect(result.message).toContain("newer than supported"); | ||
| }); | ||
|
|
||
| it("flags dev versions as incompatible but dismissable", () => { | ||
| const versions = ["dev", "0.1.5-dev", "0.0.1-alpha", "1.0.0-rc.1", "0.2.0-beta", "0.0.0-snapshot"]; | ||
| for (const v of versions) { | ||
| const result = isAgentCompatible(v); | ||
| expect(result.compatible).toBe(false); | ||
| expect(result.dev).toBe(true); | ||
| expect(result.message).toContain("development build"); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| export const MIN_AGENT_VERSION = "0.1.4"; | ||
| export const MAX_AGENT_VERSION = "0.x.x"; | ||
|
|
||
| function parseVersion(version: string): number[] { | ||
| return version | ||
| .replace(/^v/, "") | ||
| .split(".") | ||
| .map((p) => (p === "x" ? Infinity : parseInt(p, 10) || 0)); | ||
| } | ||
|
|
||
| export function compareVersions(a: string, b: string): number { | ||
| const pa = parseVersion(a); | ||
| const pb = parseVersion(b); | ||
| const len = Math.max(pa.length, pb.length); | ||
|
|
||
| for (let i = 0; i < len; i++) { | ||
| const na = pa[i] ?? 0; | ||
| const nb = pb[i] ?? 0; | ||
| if (na < nb) return -1; | ||
| if (na > nb) return 1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| export function isAgentCompatible(agentVersion: string): { | ||
| compatible: boolean; | ||
| dev?: boolean; | ||
| message: string; | ||
| } { | ||
| if (!agentVersion || agentVersion === "unknown") { | ||
| return { compatible: true, message: "" }; | ||
| } | ||
|
|
||
| const version = agentVersion.replace(/^v/, ""); | ||
|
|
||
| if (/^dev$|-(dev|alpha|beta|rc|snapshot|canary)/i.test(version)) { | ||
| return { | ||
| compatible: false, | ||
| dev: true, | ||
| message: `Agent ${version} is a development build. Some features may not work as expected.`, | ||
| }; | ||
| } | ||
|
|
||
| if (compareVersions(version, MIN_AGENT_VERSION) < 0) { | ||
| return { | ||
| compatible: false, | ||
| message: `Agent ${version} is too old. This UI requires agent ${MIN_AGENT_VERSION} or newer.`, | ||
| }; | ||
| } | ||
|
|
||
| if (compareVersions(version, MAX_AGENT_VERSION) > 0) { | ||
| return { | ||
| compatible: false, | ||
| message: `Agent ${version} is newer than supported. This UI supports up to agent ${MAX_AGENT_VERSION}.`, | ||
| }; | ||
| } | ||
|
|
||
| return { compatible: true, message: "" }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.