From 8f10ffb7f0315f77ef874d5074c0c17ccd6958c1 Mon Sep 17 00:00:00 2001 From: Hermes Date: Tue, 18 Aug 2026 04:56:01 -0700 Subject: [PATCH] test(disk-space): fix out-of-bounds-clamp test to satisfy ordering invariant --- .../routes/disk-space.routes.test.js | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/dashcaddy-api/__tests__/routes/disk-space.routes.test.js b/dashcaddy-api/__tests__/routes/disk-space.routes.test.js index 8caac5b..41c3acd 100644 --- a/dashcaddy-api/__tests__/routes/disk-space.routes.test.js +++ b/dashcaddy-api/__tests__/routes/disk-space.routes.test.js @@ -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 () => {