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
19 changes: 19 additions & 0 deletions api/src/unraid-api/graph/resolvers/servers/server.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe('ServerService', () => {
vi.mocked(getters.emhttp).mockReturnValue({
var: {
name: 'Tower',
mdState: 'STARTED',
fsState: 'Started',
},
} as any);
Expand All @@ -99,6 +100,24 @@ describe('ServerService', () => {
});
});

it('allows name change when mdState is STOPPED even if fsState is not Stopped (internal boot)', async () => {
vi.mocked(getters.emhttp).mockReturnValue({
var: {
name: 'Tower',
mdState: 'STOPPED',
fsState: 'Started',
regGuid: 'GUID-123',
port: '80',
comment: '',
},
networks: [{ ipaddr: ['192.168.1.10'] }],
} as unknown as ReturnType<typeof getters.emhttp>);

await expect(service.updateServerIdentity('NewTower', 'desc')).resolves.toMatchObject({
name: 'NewTower',
});
});

it('calls emcmd with expected params and returns optimistic server', async () => {
const result = await service.updateServerIdentity('Tower', 'Primary host');

Expand Down
5 changes: 4 additions & 1 deletion api/src/unraid-api/graph/resolvers/servers/server.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLError } from 'graphql';

import { emcmd } from '@app/core/utils/clients/emcmd.js';
import { getters } from '@app/store/index.js';
import { ArrayState } from '@app/unraid-api/graph/resolvers/array/array.model.js';
import {
ProfileModel,
Server,
Expand Down Expand Up @@ -100,8 +101,10 @@ export class ServerService {
}

if (name !== currentName) {
const mdState = currentEmhttp.var?.mdState;
const fsState = currentEmhttp.var?.fsState;
if (fsState !== 'Stopped') {
const arrayStopped = mdState === ArrayState.STOPPED || fsState === 'Stopped';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate rename on mdState before fsState fallback

The new arrayStopped check uses mdState === STOPPED || fsState === 'Stopped', which means a stale fsState value can still allow renaming even when mdState indicates the array is running. Since this change makes mdState the primary signal, fsState should only be consulted when mdState is unavailable; otherwise the guard can be bypassed in mixed-state conditions and the mutation may permit name changes while the array is effectively started.

Useful? React with 👍 / 👎.

if (!arrayStopped) {
throw new GraphQLError('The array must be stopped to change the server name.');
}
}
Expand Down
Loading