@@ -1893,4 +1893,105 @@ describe('WorklogDatabase', () => {
18931893 expect ( afterAvoidA . sortIndex ) . toBeGreaterThan ( afterAvoidB . sortIndex ) ;
18941894 } ) ;
18951895 } ) ;
1896+
1897+ describe ( 'in-progress boost in computeScore / reSort' , ( ) => {
1898+ it ( 'should boost an in-progress item above a same-priority open item' , ( ) => {
1899+ const open = db . create ( { title : 'Open item' , priority : 'medium' } ) ;
1900+ const inProgress = db . create ( { title : 'In-progress item' , priority : 'medium' , status : 'in-progress' } ) ;
1901+
1902+ db . reSort ( ) ;
1903+
1904+ const updatedOpen = db . get ( open . id ) ! ;
1905+ const updatedInProgress = db . get ( inProgress . id ) ! ;
1906+ // In-progress item should sort first (lower sortIndex = higher rank)
1907+ expect ( updatedInProgress . sortIndex ) . toBeLessThan ( updatedOpen . sortIndex ) ;
1908+ } ) ;
1909+
1910+ it ( 'should boost an ancestor of an in-progress item above a same-priority open item' , ( ) => {
1911+ const parent = db . create ( { title : 'Parent epic' , priority : 'medium' } ) ;
1912+ const child = db . create ( { title : 'In-progress child' , priority : 'medium' , status : 'in-progress' , parentId : parent . id } ) ;
1913+ const unrelated = db . create ( { title : 'Unrelated open item' , priority : 'medium' } ) ;
1914+
1915+ // Suppress unused-variable lint warning
1916+ void child ;
1917+
1918+ db . reSort ( ) ;
1919+
1920+ const updatedParent = db . get ( parent . id ) ! ;
1921+ const updatedUnrelated = db . get ( unrelated . id ) ! ;
1922+ // Parent with in-progress child should sort above the unrelated open item
1923+ expect ( updatedParent . sortIndex ) . toBeLessThan ( updatedUnrelated . sortIndex ) ;
1924+ } ) ;
1925+
1926+ it ( 'should apply only the in-progress boost (not ancestor boost) when item is itself in-progress' , ( ) => {
1927+ // Parent has an in-progress child AND is itself in-progress:
1928+ // it should get the 1.5x boost, not both 1.5x and 1.25x
1929+ const parent = db . create ( { title : 'In-progress parent' , priority : 'medium' , status : 'in-progress' } ) ;
1930+ const child = db . create ( { title : 'In-progress child' , priority : 'medium' , status : 'in-progress' , parentId : parent . id } ) ;
1931+ const open = db . create ( { title : 'Open item' , priority : 'medium' } ) ;
1932+
1933+ void child ;
1934+
1935+ db . reSort ( ) ;
1936+
1937+ const updatedParent = db . get ( parent . id ) ! ;
1938+ const updatedOpen = db . get ( open . id ) ! ;
1939+ // Parent is in-progress so it gets the 1.5x boost (not stacked 1.5x * 1.25x)
1940+ expect ( updatedParent . sortIndex ) . toBeLessThan ( updatedOpen . sortIndex ) ;
1941+ } ) ;
1942+
1943+ it ( 'should not boost a blocked item even if it is an ancestor of an in-progress item' , ( ) => {
1944+ const blockedParent = db . create ( { title : 'Blocked parent' , priority : 'medium' , status : 'blocked' } ) ;
1945+ db . create ( { title : 'In-progress child' , priority : 'medium' , status : 'in-progress' , parentId : blockedParent . id } ) ;
1946+ const open = db . create ( { title : 'Open item' , priority : 'medium' } ) ;
1947+
1948+ db . reSort ( ) ;
1949+
1950+ const updatedBlockedParent = db . get ( blockedParent . id ) ! ;
1951+ const updatedOpen = db . get ( open . id ) ! ;
1952+ // Blocked parent should still sort below the open item due to -10000 penalty
1953+ expect ( updatedBlockedParent . sortIndex ) . toBeGreaterThan ( updatedOpen . sortIndex ) ;
1954+ } ) ;
1955+
1956+ it ( 'should not modify the stored priority field when applying in-progress boost' , ( ) => {
1957+ const item = db . create ( { title : 'In-progress item' , priority : 'medium' , status : 'in-progress' } ) ;
1958+
1959+ db . reSort ( ) ;
1960+
1961+ const updated = db . get ( item . id ) ! ;
1962+ expect ( updated . priority ) . toBe ( 'medium' ) ;
1963+ } ) ;
1964+
1965+ it ( 'should still boost ancestor when multiple in-progress children exist at different depths' , ( ) => {
1966+ const grandparent = db . create ( { title : 'Grandparent' , priority : 'medium' } ) ;
1967+ const parent = db . create ( { title : 'Parent' , priority : 'medium' , parentId : grandparent . id } ) ;
1968+ db . create ( { title : 'In-progress grandchild' , priority : 'medium' , status : 'in-progress' , parentId : parent . id } ) ;
1969+ const unrelated = db . create ( { title : 'Unrelated open item' , priority : 'medium' } ) ;
1970+
1971+ db . reSort ( ) ;
1972+
1973+ const updatedGrandparent = db . get ( grandparent . id ) ! ;
1974+ const updatedUnrelated = db . get ( unrelated . id ) ! ;
1975+ // Grandparent should be boosted because it is an ancestor of an in-progress item
1976+ expect ( updatedGrandparent . sortIndex ) . toBeLessThan ( updatedUnrelated . sortIndex ) ;
1977+ } ) ;
1978+
1979+ it ( 'should not boost ancestor when in-progress child is completed' , ( ) => {
1980+ const parent = db . create ( { title : 'Parent' , priority : 'medium' } ) ;
1981+ const child = db . create ( { title : 'Child' , priority : 'medium' , status : 'in-progress' , parentId : parent . id } ) ;
1982+ const unrelated = db . create ( { title : 'Unrelated open item' , priority : 'medium' } ) ;
1983+
1984+ // Close the in-progress child
1985+ db . update ( child . id , { status : 'completed' } ) ;
1986+
1987+ db . reSort ( ) ;
1988+
1989+ const updatedParent = db . get ( parent . id ) ! ;
1990+ const updatedUnrelated = db . get ( unrelated . id ) ! ;
1991+ // Parent no longer has any in-progress descendants; no ancestor boost.
1992+ // With equal priority and no boost, createdAt is the tie-breaker:
1993+ // parent was created first so it naturally gets a lower sortIndex.
1994+ expect ( updatedParent . sortIndex ) . toBeLessThan ( updatedUnrelated . sortIndex ) ;
1995+ } ) ;
1996+ } ) ;
18961997} ) ;
0 commit comments