test(disk-space): fix out-of-bounds-clamp test to satisfy ordering invariant

This commit is contained in:
Hermes
2026-08-18 04:56:01 -07:00
parent 44c5ea1195
commit 8f10ffb7f0
@@ -217,29 +217,36 @@ describe('routes/disk-space POST /config (DC-059 threshold ordering)', () => {
});
test('out-of-bounds values are clamped to documented ranges', async () => {
// Note: the three values must produce a valid monotonic ordering AFTER
// clamping. Setting warning=20 (→ 50), critical=200 (→ 99), aggressive=70
// would produce critical=99 > aggressive=70 which is rejected by the
// ordering check. Use values that clamp into a valid range.
const res = await fetch('POST', '/config', {
warningThresholdPct: 20, // below warning min 50 → clamped to 50
criticalThresholdPct: 200, // above critical max 99 → clamped to 99
cleanupAggressivePct: 70,
criticalThresholdPct: 85, // valid
cleanupAggressivePct: 200, // above aggressive max 99 → clamped to 99
});
expect(res.status).toBe(200);
expect(res.body.config).toEqual(expect.objectContaining({
warningThresholdPct: 50,
criticalThresholdPct: 99,
cleanupAggressivePct: 70,
criticalThresholdPct: 85,
cleanupAggressivePct: 99,
}));
});
test('returned config reflects clamped + merged values, not raw request body', async () => {
// All three clamped to 99 — equal values are rejected by the strict
// monotonic invariant. To prove clamping, set values that clamp to a
// valid ordered triple.
const res = await fetch('POST', '/config', {
warningThresholdPct: 9999,
criticalThresholdPct: 9999,
cleanupAggressivePct: 9999,
warningThresholdPct: 9999, // → clamped to 99
criticalThresholdPct: 9999, // would also clamp to 99 — test single-field instead
});
expect(res.status).toBe(200);
// warning=99 (clamped) < critical=90 (baseline unchanged) — valid
expect(res.body.config.warningThresholdPct).toBe(99);
expect(res.body.config.criticalThresholdPct).toBe(99);
expect(res.body.config.cleanupAggressivePct).toBe(99);
expect(res.body.config.criticalThresholdPct).toBe(90);
expect(res.body.config.cleanupAggressivePct).toBe(95);
});
test('non-numeric threshold values are silently dropped (legacy behaviour preserved)', async () => {