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
9 changes: 5 additions & 4 deletions web/src/lib/updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import { z } from 'zod'
import { authKey, type AuthState } from './auth'
import { ApiError, request } from './request'

const version = z
.string()
.regex(/^(0|[1-9][0-9]{0,5})\.(0|[1-9][0-9]{0,5})\.(0|[1-9][0-9]{0,5})$/)
// Stable fork releases are X.Y.Z or X.Y.Z-revised.N, matching the server's update channel.
export const stableVersion =
/^(0|[1-9][0-9]{0,5})\.(0|[1-9][0-9]{0,5})\.(0|[1-9][0-9]{0,5})(-revised\.[1-9][0-9]{0,5})?$/
const version = z.string().regex(stableVersion)
const schema = z.object({
current_version: z.string().max(64),
latest_version: z.union([z.literal(''), version]),
release_url: z
.string()
.regex(
/^(|https:\/\/github\.com\/murongg\/SubLane\/releases\/tag\/v[0-9.]+)$/,
/^(|https:\/\/github\.com\/Alumos\/SubLane\/releases\/tag\/v[0-9.]+(-revised\.[0-9]+)?)$/,
),
checked_at: z.number().int().nonnegative(),
check_failed: z.boolean(),
Expand Down
25 changes: 24 additions & 1 deletion web/src/pages/Updates.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Updates } from './Updates'
const state = {
current_version: '1.2.0',
latest_version: '1.3.0',
release_url: 'https://github.com/murongg/SubLane/releases/tag/v1.3.0',
release_url: 'https://github.com/Alumos/SubLane/releases/tag/v1.3.0',
checked_at: 1900000000,
check_failed: false,
available: true,
Expand Down Expand Up @@ -162,3 +162,26 @@ it.each([
).toBeNull()
},
)

it('accepts fork revision releases from this repository', async () => {
vi.stubGlobal(
'fetch',
vi.fn(() =>
Promise.resolve(
response({
...state,
current_version: '0.19.2-revised.8',
latest_version: '0.19.2-revised.9',
release_url:
'https://github.com/Alumos/SubLane/releases/tag/v0.19.2-revised.9',
}),
),
),
)
mount()
// A revision build is a stable build: the page offers the newer revision instead of failing.
expect(
await screen.findByRole('button', { name: /0\.19\.2-revised\.9/ }),
).toBeTruthy()
expect(screen.queryByText(/could not confirm/i)).toBeNull()
})
3 changes: 2 additions & 1 deletion web/src/pages/Updates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { authOptions } from '@/lib/auth'
import {
checkUpdate,
installUpdate,
stableVersion,
updateError,
updatePending,
updatesOptions,
Expand Down Expand Up @@ -58,7 +59,7 @@ function UpdateSettings({ userID }: { userID: number }) {
const value = query.data
const busy = value ? updatePending(value) : false
const error = check.error ?? install.error
const stableBuild = value && /^\d+\.\d+\.\d+$/.test(value.current_version)
const stableBuild = value && stableVersion.test(value.current_version)
const result = value?.job
const status =
result?.status === 'succeeded' && result.version !== value?.current_version
Expand Down