|
| 1 | +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import { describe, expect, it } from 'vitest' |
| 5 | +import { buildNodeLabelSegments } from '@/ui/utils/node-label-segments' |
| 6 | + |
| 7 | +// The node card header previously rendered `gpus[0].name` alone, so a host with |
| 8 | +// more than one GPU was represented by its first card and every other card was |
| 9 | +// invisible in the summary view. `buildNodeLabelSegments` emits one segment per |
| 10 | +// GPU instead. These tests pin that every GPU survives, in order, at the counts |
| 11 | +// real hosts actually have — including the 8-GPU servers this has to hold for. |
| 12 | + |
| 13 | +const gpuTexts = (name: string, ip: string, gpus: string[]) => |
| 14 | + buildNodeLabelSegments(name, ip, gpus) |
| 15 | + .filter(segment => segment.id.startsWith('gpu-')) |
| 16 | + .map(segment => segment.text) |
| 17 | + |
| 18 | +describe('buildNodeLabelSegments', () => { |
| 19 | + it('puts the name first, uppercased, followed by the address', () => { |
| 20 | + const segments = buildNodeLabelSegments('pluto.local.tld', '172.16.24.46', []) |
| 21 | + expect(segments).toEqual([ |
| 22 | + { id: 'primary', text: 'PLUTO.LOCAL.TLD' }, |
| 23 | + { id: 'ip', text: '172.16.24.46' } |
| 24 | + ]) |
| 25 | + }) |
| 26 | + |
| 27 | + it('falls back to the address as the primary segment when there is no name', () => { |
| 28 | + const segments = buildNodeLabelSegments('', '172.16.24.46', []) |
| 29 | + expect(segments).toEqual([{ id: 'primary', text: '172.16.24.46' }]) |
| 30 | + }) |
| 31 | + |
| 32 | + it('renders a single-GPU host unchanged', () => { |
| 33 | + expect(gpuTexts('TELESTO', '172.16.29.18', ['NVIDIA GeForce GTX 1060 6GB'])).toEqual([ |
| 34 | + 'NVIDIA GeForce GTX 1060 6GB' |
| 35 | + ]) |
| 36 | + }) |
| 37 | + |
| 38 | + it('renders BOTH cards of a dual-GPU host, in topology order', () => { |
| 39 | + // The reported case: only the first card was ever shown. |
| 40 | + expect( |
| 41 | + gpuTexts('pluto.local.tld', '172.16.24.46', [ |
| 42 | + 'Tesla P100-PCIE-16GB', |
| 43 | + 'NVIDIA GeForce RTX 3060' |
| 44 | + ]) |
| 45 | + ).toEqual(['Tesla P100-PCIE-16GB', 'NVIDIA GeForce RTX 3060']) |
| 46 | + }) |
| 47 | + |
| 48 | + it.each([3, 4, 5, 6, 7, 8])('renders every GPU on a %i-GPU host', count => { |
| 49 | + const gpus = Array.from({ length: count }, (_, index) => `NVIDIA H100 80GB HBM3 #${index}`) |
| 50 | + const texts = gpuTexts('dgx-01', '10.0.0.10', gpus) |
| 51 | + |
| 52 | + expect(texts).toHaveLength(count) |
| 53 | + expect(texts).toEqual(gpus) |
| 54 | + }) |
| 55 | + |
| 56 | + it('keeps ids unique and stable across an 8-GPU host so React can key them', () => { |
| 57 | + const gpus = Array.from({ length: 8 }, (_, index) => `NVIDIA A100-SXM4-80GB #${index}`) |
| 58 | + const ids = buildNodeLabelSegments('dgx-02', '10.0.0.11', gpus).map(segment => segment.id) |
| 59 | + |
| 60 | + expect(new Set(ids).size).toBe(ids.length) |
| 61 | + expect(ids).toEqual([ |
| 62 | + 'primary', |
| 63 | + 'ip', |
| 64 | + ...Array.from({ length: 8 }, (_, index) => `gpu-${index}`) |
| 65 | + ]) |
| 66 | + }) |
| 67 | + |
| 68 | + it('drops blank GPU names without disturbing the indices of the rest', () => { |
| 69 | + // A blank name would otherwise render a separator with nothing after it. |
| 70 | + const texts = gpuTexts('mixed', '10.0.0.12', ['Tesla P100-PCIE-16GB', '', 'RTX 3060']) |
| 71 | + expect(texts).toEqual(['Tesla P100-PCIE-16GB', 'RTX 3060']) |
| 72 | + }) |
| 73 | + |
| 74 | + it('emits no GPU segments for a host that reports none', () => { |
| 75 | + expect(gpuTexts('cpu-only', '10.0.0.13', [])).toEqual([]) |
| 76 | + }) |
| 77 | +}) |
0 commit comments