fix(xray): read and write log.logLevel in the Xray basics tab

xray-core 26.11.9 (#7329) spells the key log.logLevel and still accepts
loglevel. A template written with the new spelling showed "warning" in the
panel, and changing the level added a second loglevel key beside it, leaving
the core to pick between two values.

The select now reads either spelling and saves a single logLevel key.
This commit is contained in:
Sanaei
2026-11-12 19:10:19 +01:00
parent bf2d0ada8b
commit bfe826c18f
2 changed files with 39 additions and 2 deletions
+5 -2
View File
@@ -414,12 +414,15 @@ export default function BasicsTab({
paddings="small"
control={
<Select
value={(log.loglevel as string) || 'warning'}
value={((log.logLevel ?? log.loglevel) as string) || 'warning'}
style={{ width: '100%' }}
options={LOG_LEVELS.map((s) => ({ value: s, label: s }))}
onChange={(v) =>
mutate((tt) => {
if (tt.log) tt.log.loglevel = v;
if (!tt.log) return;
// The core reads either spelling, so keeping both would let the stale one win.
delete tt.log.loglevel;
tt.log.logLevel = v;
})
}
/>
@@ -0,0 +1,34 @@
import { describe, it, expect, vi } from 'vitest';
import { fireEvent, screen } from '@testing-library/react';
import BasicsTab from '@/pages/xray/basics/BasicsTab';
import type { XraySettingsValue } from '@/hooks/useXraySetting';
import { renderWithProviders } from './test-utils';
// xray-core 26.11.9 (#7329) spells the key log.logLevel and still reads loglevel.
describe('BasicsTab log level spelling', () => {
it('shows a template written as logLevel and saves one key, not both spellings', () => {
const setTemplateSettings = vi.fn();
renderWithProviders(
<BasicsTab
templateSettings={{ log: { logLevel: 'debug' } } as unknown as XraySettingsValue}
setTemplateSettings={setTemplateSettings}
outboundTestUrl=""
onChangeOutboundTestUrl={vi.fn()}
onResetDefault={vi.fn()}
/>,
);
fireEvent.click(screen.getByRole('tab', { name: /Log/ }));
const combobox = screen.getByRole('combobox', { name: 'Log Level' });
expect(combobox.closest('.ant-select')?.textContent).toContain('debug');
fireEvent.mouseDown(combobox);
fireEvent.click(screen.getByTitle('error'));
const update = setTemplateSettings.mock.calls.at(-1)?.[0] as (
prev: XraySettingsValue,
) => XraySettingsValue;
const legacy = { log: { loglevel: 'warning' } } as unknown as XraySettingsValue;
expect(update(legacy).log).toEqual({ logLevel: 'error' });
});
});