From dbc417941bcc713b01813b8aab2de1c415b26bf7 Mon Sep 17 00:00:00 2001 From: mikemikimike <13286568797@163.com> Date: Tue, 1 Sep 2026 21:02:39 +0800 Subject: [PATCH] fix(ui): show allocated block resources Signed-off-by: mikemikimike <13286568797@163.com> --- .../Runs/Details/Jobs/List/helpers.test.ts | 56 +++++++++++++++++++ .../pages/Runs/Details/Jobs/List/helpers.ts | 8 ++- frontend/src/pages/Runs/List/helpers.ts | 4 +- frontend/src/types/run.d.ts | 3 + 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 frontend/src/pages/Runs/Details/Jobs/List/helpers.test.ts diff --git a/frontend/src/pages/Runs/Details/Jobs/List/helpers.test.ts b/frontend/src/pages/Runs/Details/Jobs/List/helpers.test.ts new file mode 100644 index 0000000000..325aa91a3e --- /dev/null +++ b/frontend/src/pages/Runs/Details/Jobs/List/helpers.test.ts @@ -0,0 +1,56 @@ +jest.mock('App/helpers', () => ({ getBaseUrl: () => '' })); +jest.mock('libs/fleet', () => ({ formatBackend: () => '-' })); + +import { getRunListItemResources } from '../../../List/helpers'; +import { getJobListItemResources } from './helpers'; + +const instanceResources: IResources = { + cpus: 4, + memory_mib: 16 * 1024, + gpus: [], + spot: false, +}; + +const blockResources: IResources = { + cpus: 1, + memory_mib: 4 * 1024, + gpus: [], + spot: false, +}; + +const submission: IJobSubmission = { + id: 'submission', + submission_num: 0, + status: 'running', + submitted_at: 0, + finished_at: null, + job_provisioning_data: { + backend: 'aws', + instance_type: { name: 't3.xlarge', resources: instanceResources }, + instance_id: 'instance', + hostname: 'localhost', + region: 'us-east-1', + price: 0, + username: 'ubuntu', + ssh_port: 22, + dockerized: false, + }, + job_runtime_data: { + offer: { instance: { name: 'block', resources: blockResources } }, + }, +}; + +const job = { job_spec: {}, job_submissions: [submission] } as IJob; + +describe('job resource display', () => { + test('uses allocated block resources when runtime offer is available', () => { + expect(getJobListItemResources(job)).toBe('cpu=1 mem=4GB'); + expect(getRunListItemResources({ jobs: [job], latest_job_submission: submission } as IRun)).toBe('cpu=1 mem=4GB'); + }); + + test('falls back to instance resources for older submissions', () => { + const legacySubmission = { ...submission, job_runtime_data: null }; + const legacyJob = { ...job, job_submissions: [legacySubmission] } as IJob; + expect(getJobListItemResources(legacyJob)).toBe('cpu=4 mem=16GB'); + }); +}); diff --git a/frontend/src/pages/Runs/Details/Jobs/List/helpers.ts b/frontend/src/pages/Runs/Details/Jobs/List/helpers.ts index 6fd1f30778..b746c8f306 100644 --- a/frontend/src/pages/Runs/Details/Jobs/List/helpers.ts +++ b/frontend/src/pages/Runs/Details/Jobs/List/helpers.ts @@ -6,8 +6,14 @@ import { capitalize } from 'libs'; import { formatBackend } from 'libs/fleet'; import { formatResources } from 'libs/resources'; +export const getJobSubmissionResources = (submission?: IJobSubmission | null) => { + return ( + submission?.job_runtime_data?.offer?.instance?.resources ?? submission?.job_provisioning_data?.instance_type?.resources + ); +}; + export const getJobListItemResources = (job: IJob) => { - const resources = job.job_submissions?.[job.job_submissions.length - 1]?.job_provisioning_data?.instance_type?.resources; + const resources = getJobSubmissionResources(job.job_submissions?.[job.job_submissions.length - 1]); return resources ? formatResources(resources) : '-'; }; diff --git a/frontend/src/pages/Runs/List/helpers.ts b/frontend/src/pages/Runs/List/helpers.ts index 28f29af288..72539d175b 100644 --- a/frontend/src/pages/Runs/List/helpers.ts +++ b/frontend/src/pages/Runs/List/helpers.ts @@ -6,7 +6,7 @@ import { formatResources } from 'libs/resources'; import { getBaseUrl } from 'App/helpers'; import { finishedJobs, finishedRunStatuses } from '../constants'; -import { getJobStatus } from '../Details/Jobs/List/helpers'; +import { getJobStatus, getJobSubmissionResources } from '../Details/Jobs/List/helpers'; export const getGroupedRunsByProjectAndRepoID = (runs: IRun[]) => { return _groupBy(runs, ({ project_name }) => project_name); @@ -17,7 +17,7 @@ export const getRunListItemResources = (run: IRun) => { return '-'; } - const resources = run.latest_job_submission?.job_provisioning_data?.instance_type?.resources; + const resources = getJobSubmissionResources(run.latest_job_submission); return resources ? formatResources(resources) : '-'; }; diff --git a/frontend/src/types/run.d.ts b/frontend/src/types/run.d.ts index a47a7ae571..b100074338 100644 --- a/frontend/src/types/run.d.ts +++ b/frontend/src/types/run.d.ts @@ -293,6 +293,9 @@ declare interface IJobProvisioningData { declare interface IJobRuntimeData { working_dir?: string | null; username?: string | null; + offer?: { + instance: InstanceType; + } | null; } declare interface IJobSubmission {