---@diagnostic disable: duplicate-set-field, need-check-nil, param-type-mismatch, assign-type-mismatch local statusline = require 'bugabinga.statusline' local publisher = require 'bugabinga.pivi.publish' local consumer = require 'bugabinga.pivi_status' local publish = function( value ) vim.g.pivi = value end local session = function( fields ) return vim.tbl_extend( 'force', { name = 'work', connection = 'running', run = 'idle', queue = { steering = {}, follow_up = {}, }, compacting = false, summary = 'pi:idle', }, fields or {} ) end describe( 'pivi statusline consumer', function() after_each( function() vim.g.pivi = nil end ) it( 'shows nothing when pivi never published anything', function() vim.g.pivi = nil assert.equal( '', consumer.component() ) end ) it( 'shows nothing for an unknown active session', function() publish { active = 'absent', sessions = {}, } assert.equal( '', consumer.component() ) end ) it( 'shows a quiet marker while idle', function() publish { active = 'work', sessions = { work = session(), }, } assert.equal( 'π', consumer.component() ) end ) it( 'animates and names the running tool', function() publish { active = 'work', sessions = { work = session { run = 'running', tool = { id = 'c1', name = 'edit', }, }, }, } local shown = consumer.component() assert.is_true( shown:find( 'edit', 1, true ) ~= nil ) assert.is_true( #shown > #'π edit' ) end ) it( 'reports thinking, retry, compaction, and error distinctly', function() local seen = {} for _, fields in ipairs { { run = 'running', }, { run = 'retrying', }, { compacting = true, }, { error = 'boom', }, } do publish { active = 'work', sessions = { work = session( fields ), }, } table.insert( seen, consumer.component() ) end assert.is_true( seen[1]:find( 'thinking', 1, true ) ~= nil ) assert.is_true( seen[2]:find( 'retry', 1, true ) ~= nil ) assert.is_true( seen[3]:find( 'compacting', 1, true ) ~= nil ) assert.is_true( seen[4]:find( 'error', 1, true ) ~= nil ) end ) it( 'counts queued submissions', function() publish { active = 'work', sessions = { work = session { queue = { steering = { 'a', }, follow_up = { 'b', 'c', }, }, }, }, } assert.is_true( consumer.component():find( '+3', 1, true ) ~= nil ) end ) it( 'never treats a stopped session as busy', function() assert.is_false( consumer.busy( session { connection = 'stopped', run = 'running', } ) ) end ) it( 'announces findings that reached the quickfix list', function() local seen = {} local original = vim.notify vim.notify = function( message ) table.insert( seen, message ) end publisher.activity { kind = 'findings', count = 3, } publisher.activity { kind = 'findings', count = 0, } publisher.activity { kind = 'edit', } vim.notify = original assert.equal( 1, #seen ) assert.is_true( seen[1]:find( '3 findings', 1, true ) ~= nil ) end ) it( 'is registered with the statusline and evaluates without pivi loaded', function() package.loaded['bugabinga.pivi'] = nil vim.g.pivi = nil local rendered = statusline.plugins_component() assert.is_string( rendered ) assert.is_nil( package.loaded['bugabinga.pivi'] ) end ) end )