fix update center release tests for 1.3.0
This commit is contained in:
@@ -4,6 +4,7 @@ import { mkdtempSync } from 'node:fs';
|
|||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { tmpdir } from 'node:os';
|
import { tmpdir } from 'node:os';
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
|
import { resolveUpdateReminderCandidate } from '../../shared/updateCenterReminder.js';
|
||||||
import { waitForBackgroundTaskToReachTerminalState } from '../../test-fixtures/backgroundTaskTestUtils.js';
|
import { waitForBackgroundTaskToReachTerminalState } from '../../test-fixtures/backgroundTaskTestUtils.js';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -39,6 +40,12 @@ type DbModule = typeof import('../../db/index.js');
|
|||||||
type ConfigModule = typeof import('../../config.js');
|
type ConfigModule = typeof import('../../config.js');
|
||||||
type RuntimeStateModule = typeof import('../../services/updateCenterRuntimeStateService.js');
|
type RuntimeStateModule = typeof import('../../services/updateCenterRuntimeStateService.js');
|
||||||
|
|
||||||
|
function getNextPatchVersion(version: string) {
|
||||||
|
const match = String(version).trim().match(/^(\d+)\.(\d+)\.(\d+)$/);
|
||||||
|
if (!match) return '999.0.0';
|
||||||
|
return `${match[1]}.${match[2]}.${Number.parseInt(match[3], 10) + 1}`;
|
||||||
|
}
|
||||||
|
|
||||||
describe('update center routes', () => {
|
describe('update center routes', () => {
|
||||||
let app: FastifyInstance;
|
let app: FastifyInstance;
|
||||||
let db: DbModule['db'];
|
let db: DbModule['db'];
|
||||||
@@ -115,13 +122,14 @@ describe('update center routes', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('persists config and returns status with both version channels and helper summary', async () => {
|
it('persists config and returns status with both version channels and helper summary', async () => {
|
||||||
fetchLatestStableGitHubReleaseMock.mockResolvedValue({
|
const currentVersion = (await import('../../services/updateCenterVersionService.js')).getCurrentRuntimeVersion();
|
||||||
|
const githubRelease = {
|
||||||
source: 'github-release',
|
source: 'github-release',
|
||||||
rawVersion: 'v1.3.0',
|
rawVersion: 'v1.3.0',
|
||||||
normalizedVersion: '1.3.0',
|
normalizedVersion: '1.3.0',
|
||||||
url: 'https://github.com/cita-777/metapi/releases/tag/v1.3.0',
|
url: 'https://github.com/cita-777/metapi/releases/tag/v1.3.0',
|
||||||
});
|
} as const;
|
||||||
fetchLatestDockerHubTagMock.mockResolvedValue({
|
const dockerHubTag = {
|
||||||
source: 'docker-hub-tag',
|
source: 'docker-hub-tag',
|
||||||
rawVersion: 'latest',
|
rawVersion: 'latest',
|
||||||
normalizedVersion: 'latest',
|
normalizedVersion: 'latest',
|
||||||
@@ -130,8 +138,8 @@ describe('update center routes', () => {
|
|||||||
displayVersion: 'latest @ sha256:efb2ee655386',
|
displayVersion: 'latest @ sha256:efb2ee655386',
|
||||||
publishedAt: '2026-03-29T11:54:35.591877Z',
|
publishedAt: '2026-03-29T11:54:35.591877Z',
|
||||||
url: null,
|
url: null,
|
||||||
});
|
} as const;
|
||||||
getUpdateCenterHelperStatusMock.mockResolvedValue({
|
const helperStatus = {
|
||||||
ok: true,
|
ok: true,
|
||||||
releaseName: 'metapi',
|
releaseName: 'metapi',
|
||||||
namespace: 'ai',
|
namespace: 'ai',
|
||||||
@@ -151,7 +159,10 @@ describe('update center routes', () => {
|
|||||||
imageDigest: 'sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
|
imageDigest: 'sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
} as const;
|
||||||
|
fetchLatestStableGitHubReleaseMock.mockResolvedValue(githubRelease);
|
||||||
|
fetchLatestDockerHubTagMock.mockResolvedValue(dockerHubTag);
|
||||||
|
getUpdateCenterHelperStatusMock.mockResolvedValue(helperStatus);
|
||||||
|
|
||||||
const saveResponse = await app.inject({
|
const saveResponse = await app.inject({
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
@@ -179,8 +190,18 @@ describe('update center routes', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(statusResponse.statusCode).toBe(200);
|
expect(statusResponse.statusCode).toBe(200);
|
||||||
|
const expectedReminder = resolveUpdateReminderCandidate({
|
||||||
|
currentVersion,
|
||||||
|
helper: {
|
||||||
|
imageTag: helperStatus.imageTag,
|
||||||
|
imageDigest: helperStatus.imageDigest,
|
||||||
|
},
|
||||||
|
githubRelease,
|
||||||
|
dockerHubTag,
|
||||||
|
});
|
||||||
|
expect(expectedReminder).toBeTruthy();
|
||||||
expect(statusResponse.json()).toMatchObject({
|
expect(statusResponse.json()).toMatchObject({
|
||||||
currentVersion: '1.2.3',
|
currentVersion,
|
||||||
config: {
|
config: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
namespace: 'ai',
|
namespace: 'ai',
|
||||||
@@ -210,9 +231,9 @@ describe('update center routes', () => {
|
|||||||
runtime: {
|
runtime: {
|
||||||
lastCheckedAt: expect.any(String),
|
lastCheckedAt: expect.any(String),
|
||||||
lastCheckError: null,
|
lastCheckError: null,
|
||||||
lastResolvedSource: 'github-release',
|
lastResolvedSource: expectedReminder?.source,
|
||||||
lastResolvedDisplayVersion: '1.3.0',
|
lastResolvedDisplayVersion: expectedReminder?.displayVersion,
|
||||||
lastResolvedCandidateKey: 'github-release:1.3.0',
|
lastResolvedCandidateKey: expectedReminder?.candidateKey,
|
||||||
lastNotifiedCandidateKey: null,
|
lastNotifiedCandidateKey: null,
|
||||||
lastNotifiedAt: null,
|
lastNotifiedAt: null,
|
||||||
},
|
},
|
||||||
@@ -519,6 +540,8 @@ describe('update center routes', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('dedupes deploy requests while a task is already running', async () => {
|
it('dedupes deploy requests while a task is already running', async () => {
|
||||||
|
const currentVersion = (await import('../../services/updateCenterVersionService.js')).getCurrentRuntimeVersion();
|
||||||
|
const targetVersion = getNextPatchVersion(currentVersion);
|
||||||
await saveValidConfig();
|
await saveValidConfig();
|
||||||
|
|
||||||
let releaseDeploy: (() => void) | null = null;
|
let releaseDeploy: (() => void) | null = null;
|
||||||
@@ -533,7 +556,7 @@ describe('update center routes', () => {
|
|||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
targetSource: 'github-release',
|
targetSource: 'github-release',
|
||||||
targetTag: '1.3.0',
|
targetTag: targetVersion,
|
||||||
targetDigest: null,
|
targetDigest: null,
|
||||||
previousRevision: '12',
|
previousRevision: '12',
|
||||||
finalRevision: '13',
|
finalRevision: '13',
|
||||||
@@ -547,7 +570,7 @@ describe('update center routes', () => {
|
|||||||
url: '/api/update-center/deploy',
|
url: '/api/update-center/deploy',
|
||||||
payload: {
|
payload: {
|
||||||
source: 'github-release',
|
source: 'github-release',
|
||||||
targetVersion: '1.3.0',
|
targetVersion,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -556,7 +579,7 @@ describe('update center routes', () => {
|
|||||||
url: '/api/update-center/deploy',
|
url: '/api/update-center/deploy',
|
||||||
payload: {
|
payload: {
|
||||||
source: 'github-release',
|
source: 'github-release',
|
||||||
targetVersion: '1.3.0',
|
targetVersion,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user