Files
XC_VM/tests/Unit/SettingsIdleBufferRatioTest.php
T
rootandClaude Opus 5 f94608b732 fix(settings): the fanout idle buffer ratio takes a decimal, such as 0.25
The settings page ran every field in its numeric list through
value.replace(/[^0-9]/g, '') on input, and fanout_idle_buffer_ratio was in that
list. It is a fraction (0.1-1): typing 0.25 left 025, and touching the stored
0.50 left 050. A decimal(3,2) column refuses 25 under strict mode, so the save
failed, and where it was clamped the daemon got a ratio of 1 — the whole buffer
kept while idle, the opposite of what was asked.

The field now has its own filter: digits and one decimal point, a comma taken
as one (a pt/ru/de keyboard types 0,25), and inputmode=decimal. On save,
SettingsService normalises it the same way, rounds it to two decimals and keeps
it in the daemon's 0.1-1 range; a value that is not a number leaves the stored
one unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BbYsGKhirq9eRK8e6wsCHR
2026-09-13 09:02:40 +00:00

32 lines
1.4 KiB
PHP

<?php
use PHPUnit\Framework\TestCase;
use XcVm\Domain\Server\SettingsService;
/**
* The fanout idle buffer ratio is a fraction (0.1-1). The settings form stripped
* every non-digit from it, so 0.25 reached the server as 025; the save now takes
* what the operator typed, with a comma or a point, and keeps it in range.
*/
final class SettingsIdleBufferRatioTest extends TestCase {
public function testTakesTheFractionTheOperatorTyped(): void {
$this->assertSame(0.25, SettingsService::normalizeIdleBufferRatio('0.25'));
$this->assertSame(0.25, SettingsService::normalizeIdleBufferRatio('0,25'), 'a decimal comma');
$this->assertSame(0.5, SettingsService::normalizeIdleBufferRatio(' 0.50 '));
$this->assertSame(1.0, SettingsService::normalizeIdleBufferRatio('1'));
}
public function testKeepsItInTheDaemonsRange(): void {
$this->assertSame(0.1, SettingsService::normalizeIdleBufferRatio('0.01'));
$this->assertSame(1.0, SettingsService::normalizeIdleBufferRatio('25'));
$this->assertSame(0.33, SettingsService::normalizeIdleBufferRatio('0.333'));
}
public function testSomethingThatIsNotANumberIsNotSaved(): void {
$this->assertNull(SettingsService::normalizeIdleBufferRatio(''));
$this->assertNull(SettingsService::normalizeIdleBufferRatio('abc'));
$this->assertNull(SettingsService::normalizeIdleBufferRatio('0.2.5'));
$this->assertNull(SettingsService::normalizeIdleBufferRatio(null));
}
}