🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(about): support build-time app version override (#19421)
AmAzing-f4b2334e8914
diff --git a/src/const/appVersion.ts b/src/const/appVersion.tsnew file mode 100644index 00000000000..79dba333f52--- /dev/null+++ b/src/const/appVersion.ts@@ -0,0 +1,4 @@+import { CURRENT_VERSION } from '@/const/version';++// Cloud injects the release version at build time; other Web builds use package metadata.+export const WEB_APP_VERSION = process.env.NEXT_PUBLIC_APP_VERSION || CURRENT_VERSION;diff --git a/src/features/Settings/about/features/appVersion.test.ts b/src/features/Settings/about/features/appVersion.test.tsnew file mode 100644index 00000000000..f7ffafb491e--- /dev/null+++ b/src/features/Settings/about/features/appVersion.test.ts@@ -0,0 +1,30 @@+import { afterEach, describe, expect, it, vi } from 'vitest';++vi.mock('@/const/version', () => ({ CURRENT_VERSION: '2.2.14' }));++afterEach(() => {+ vi.unstubAllEnvs();+ vi.unstubAllGlobals();+ vi.resetModules();+});++describe('APP_VERSION', () => {+ it('prefers the injected build version over package metadata', async () => {+ vi.stubEnv('NEXT_PUBLIC_APP_VERSION', '2.2.16');+ expect((await import('./appVersion')).APP_VERSION).toBe('2.2.16');+ });++ it.each([undefined, ''])(+ 'uses the package version without an injected value (%s)',+ async (value) => {+ vi.stubEnv('NEXT_PUBLIC_APP_VERSION', value);+ expect((await import('./appVersion')).APP_VERSION).toBe('2.2.14');+ },+ );++ it('keeps the desktop package version independent of the web build version', async () => {+ vi.stubEnv('NEXT_PUBLIC_APP_VERSION', '2.2.16');+ vi.stubGlobal('__MAIN_VERSION__', '2.2.15');+ expect((await import('./appVersion.desktop')).APP_VERSION).toBe('2.2.15');+ });+});diff --git a/src/features/Settings/about/features/appVersion.ts b/src/features/Settings/about/features/appVersion.tsindex 25f54ea41b5..f3e91f7f053 100644--- a/src/features/Settings/about/features/appVersion.ts+++ b/src/features/Settings/about/features/appVersion.ts@@ -1,3 +1 @@-import { CURRENT_VERSION } from '@/const/version';--export const APP_VERSION = CURRENT_VERSION;+export { WEB_APP_VERSION as APP_VERSION } from '@/const/appVersion';diff --git a/src/routes/(main)/agent/_layout/index.test.tsx b/src/routes/(main)/agent/_layout/index.test.tsxindex 710fb95bd64..c9113ac4f7f 100644--- a/src/routes/(main)/agent/_layout/index.test.tsx+++ b/src/routes/(main)/agent/_layout/index.test.tsx@@ -16,7 +16,10 @@ vi.mock('react-router', async () => {};});-vi.mock('@/const/version', () => ({ isDesktop: false }));+vi.mock(import('@/const/version'), async (importOriginal) => ({+ ...(await importOriginal()),+ isDesktop: false,+}));vi.mock('@/hooks/useInitAgentConfig', () => ({ useInitAgentConfig: vi.fn() }));vi.mock('@/features/ProtocolUrlHandler', () => ({ default: () => null }));vi.mock('./RegisterHotkeys', () => ({ default: () => null }));diff --git a/src/services/chat/chat.test.ts b/src/services/chat/chat.test.tsindex 0f0b61cc65c..10a9186831a 100644--- a/src/services/chat/chat.test.ts+++ b/src/services/chat/chat.test.ts@@ -100,7 +100,8 @@ vi.mock('i18next', () => ({}));// 默认设置 isServerMode 为 false-vi.mock('@/const/version', () => ({+vi.mock(import('@/const/version'), async (importOriginal) => ({+ ...(await importOriginal()),isServerMode: false,isDeprecatedEdition: true,isDesktop: false,diff --git a/src/store/chat/slices/thread/action.test.ts b/src/store/chat/slices/thread/action.test.tsindex f939b8dc9e0..359f834d90a 100644--- a/src/store/chat/slices/thread/action.test.ts+++ b/src/store/chat/slices/thread/action.test.ts@@ -23,7 +23,8 @@ vi.mock('@/libs/swr', async () => {});// Mock version constants-vi.mock('@/const/version', () => ({+vi.mock(import('@/const/version'), async (importOriginal) => ({+ ...(await importOriginal()),isDeprecatedEdition: false,isDesktop: false,}));diff --git a/src/store/global/actions/__tests__/general.test.ts b/src/store/global/actions/__tests__/general.test.tsindex cec328306e5..c1ce3190486 100644--- a/src/store/global/actions/__tests__/general.test.ts+++ b/src/store/global/actions/__tests__/general.test.ts@@ -1,7 +1,8 @@-import { act, renderHook } from '@testing-library/react';+import { act, renderHook, waitFor } from '@testing-library/react';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import * as activeWorkspaceSlugModule from '@/business/client/hooks/useActiveWorkspaceSlug';+import type * as VersionConstants from '@/const/version';import { CURRENT_VERSION } from '@/const/version';import { globalService } from '@/services/global';import { useGlobalStore } from '@/store/global';@@ -9,6 +10,22 @@ import { initialState } from '@/store/global/initialState';import { switchLang } from '@/utils/client/switchLang';import { withSWR } from '~test-utils';+const versionContext = vi.hoisted(() => ({ desktop: false, webVersion: '2.2.14' }));++vi.mock('@/const/version', async (importOriginal) => ({+ ...(await importOriginal<typeof VersionConstants>()),+ CURRENT_VERSION: '2.2.14',+ get isDesktop() {+ return versionContext.desktop;+ },+}));++vi.mock('@/const/appVersion', () => ({+ get WEB_APP_VERSION() {+ return versionContext.webVersion;+ },+}));+vi.mock('@/utils/client/switchLang', () => ({switchLang: vi.fn(),}));@@ -22,6 +39,8 @@ vi.mock('@/services/global', () => ({describe('generalActionSlice', () => {beforeEach(() => {vi.clearAllMocks();+ versionContext.desktop = false;+ versionContext.webVersion = '2.2.14';useGlobalStore.setState(initialState);});@@ -193,6 +212,28 @@ describe('generalActionSlice', () => {});describe('useCheckLatestVersion', () => {+ it.each([+ { desktop: false, expected: undefined, latest: '2.3.0' },+ { desktop: false, expected: true, latest: '2.4.0' },+ { desktop: true, expected: true, latest: '2.3.0' },+ ])(+ 'compares $latest against the platform version (desktop: $desktop)',+ async ({ desktop, expected, latest }) => {+ versionContext.desktop = desktop;+ versionContext.webVersion = '2.3.0';+ vi.mocked(globalService.getLatestVersion).mockResolvedValueOnce(latest);++ const { result } = renderHook(() => useGlobalStore().useCheckLatestVersion(), {+ wrapper: withSWR,+ });++ await waitFor(() => expect(result.current.data).toBe(latest));++ expect(useGlobalStore.getState().hasNewVersion).toBe(expected);+ expect(useGlobalStore.getState().latestVersion).toBe(expected ? latest : undefined);+ },+ );+it('should not fetch version when check is disabled', () => {const getLatestVersionSpy = vi.spyOn(globalService, 'getLatestVersion');diff --git a/src/store/global/actions/general.ts b/src/store/global/actions/general.tsindex 3221bf8aed5..ad73debe034 100644--- a/src/store/global/actions/general.ts+++ b/src/store/global/actions/general.ts@@ -5,6 +5,7 @@ import type { SWRResponse } from 'swr';import { getActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';import { getActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';+import { WEB_APP_VERSION } from '@/const/appVersion';import { CURRENT_VERSION, isDesktop } from '@/const/version';import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';import { useOnlyFetchOnceSWR } from '@/libs/swr';@@ -250,9 +251,10 @@ export class GlobalGeneralActionImpl {{focusThrottleInterval: 1000 * 60 * 30,onSuccess: (data: string) => {- if (!valid(CURRENT_VERSION) || !valid(data)) return;+ const version = isDesktop ? CURRENT_VERSION : WEB_APP_VERSION;+ if (!valid(version) || !valid(data)) return;- const currentVersion = parse(CURRENT_VERSION);+ const currentVersion = parse(version);const latestVersion = parse(data);if (!currentVersion || !latestVersion) return;