From 1e6c57afe499042a7bd2d2cc1a0053b0bf162be9 Mon Sep 17 00:00:00 2001 From: Sorra Date: Sun, 22 Mar 2026 05:27:47 -0700 Subject: [PATCH] WL-0MN0SS4UD0SJAC3T: add test to lock non-stacking in computeScore --- tests/computeScore.nonstack.test.ts | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/computeScore.nonstack.test.ts diff --git a/tests/computeScore.nonstack.test.ts b/tests/computeScore.nonstack.test.ts new file mode 100644 index 0000000..c7d0a41 --- /dev/null +++ b/tests/computeScore.nonstack.test.ts @@ -0,0 +1,39 @@ +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; +import { createTempDir, cleanupTempDir, createTempJsonlPath, createTempDbPath } from './test-utils.js'; +import { WorklogDatabase } from '../src/database.js'; + +describe('computeScore non-stacking invariant', () => { + let tempDir: string; + let dbPath: string; + let jsonlPath: string; + let db: WorklogDatabase; + + beforeEach(() => { + tempDir = createTempDir(); + dbPath = createTempDbPath(tempDir); + jsonlPath = createTempJsonlPath(tempDir); + db = new WorklogDatabase('TEST', dbPath, jsonlPath, true, true); + }); + + afterEach(() => { + db.close(); + cleanupTempDir(tempDir); + }); + + it('applies only the in-progress boost (not ancestor boost) when item is itself in-progress', async () => { + // Create a high-priority open item, then an in-progress parent (medium) + const highOpen = db.create({ title: 'High open item', priority: 'high' }); + // ensure a deterministic createdAt ordering + await new Promise(resolve => setTimeout(resolve, 10)); + const parent = db.create({ title: 'In-progress parent', priority: 'medium', status: 'in-progress' }); + db.create({ title: 'In-progress child', priority: 'medium', status: 'in-progress', parentId: parent.id }); + + db.reSort(); + + const updatedHighOpen = db.get(highOpen.id)!; + const updatedParent = db.get(parent.id)!; + + // With correct non-stacking: highOpen should sort above parent + expect(updatedHighOpen.sortIndex).toBeLessThan(updatedParent.sortIndex); + }); +});