repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
neovim/tests/bugabinga/pivi/partial_spec.lua
Raw---@diagnostic disable: duplicate-set-field, need-check-nil, param-type-mismatch, assign-type-mismatch
local partial = require 'bugabinga.pivi.partial'
local fixture = dofile 'tests/helpers/pivi_fixture.lua'
describe( 'pivi partial', function()
it( 'reports completion for valid arguments', function()
local result = partial.parse '{"path":"a.lua","new_text":"local x = 1"}'
assert.is_true( result.complete )
assert.equal( 'a.lua', result.value.path )
end )
it( 'recovers fields from a truncated object without throwing', function()
local result = partial.parse '{"path":"a.lua","new_text":"local x ='
assert.is_false( result.complete )
assert.is_nil( result.value )
assert.equal( 'a.lua', result.fields.path )
assert.equal( 'local x =', result.fields.new_text )
end )
it( 'decodes escapes inside a truncated string', function()
local result = partial.parse '{"new_text":"line one\\nline \\"two\\"'
assert.equal( 'line one\nline "two"', result.fields.new_text )
end )
it( 'survives every prefix of a complete argument object', function()
local complete = '{"path":"src/main.lua","old_text":"a","new_text":"b"}'
for length = 1, #complete do
local result = partial.parse( complete:sub( 1, length ) )
assert.is_table( result.fields )
end
end )
it( 'returns nothing for empty or non string input', function()
assert.is_false( partial.parse( '' ).complete )
assert.is_false( partial.parse( nil ).complete )
end )
it( 'recovers a path from every prefix of recorded argument deltas', function()
local accumulated, snapshots = '', {}
for _, event in ipairs( fixture.deltas 'rpc-tool-stream.jsonl' ) do
if event.type == 'toolcall_delta' then
accumulated = accumulated .. ( event.delta or '' )
table.insert( snapshots, accumulated )
end
end
assert.is_true( #snapshots > 1 )
local recovered = false
for _, snapshot in ipairs( snapshots ) do
local result = partial.parse( snapshot )
assert.is_table( result.fields )
if result.fields.path then recovered = true end
end
assert.is_true( recovered )
assert.is_true( partial.parse( accumulated ).complete )
end )
it( 'describes streaming edit intent', function()
local intent = partial.intent( 'edit', '{"path":"a.lua","new_text":"half' )
assert.is_false( intent.complete )
assert.equal( 'edit', intent.tool )
assert.equal( 'a.lua', intent.path )
assert.equal( 'half', intent.text )
end )
it( 'describes complete edit intent', function()
local intent = partial.intent( 'write', '{"path":"a.lua","content":"done"}' )
assert.is_true( intent.complete )
assert.equal( 'done', intent.text )
end )
end )