Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

neovim/tests/helpers/pivi_fixture.lua

Raw
--- Recorded `pi --mode rpc` output.
--- Every fixture comes from a real run with the user's own Pi configuration
--- loaded, so extension traffic is part of the recording.
local jsonl = require 'bugabinga.pivi.jsonl'

local ROOT = 'tests/fixtures/pivi/'

local text = function( name )
  return table.concat( vim.fn.readfile( ROOT .. name ), '\n' ) .. '\n'
end

--- @return table[] frames every decoded record, in recorded order
local frames = function( name )
  local splitter = jsonl.splitter()
  local decoded = {}
  for _, record in ipairs( splitter.feed( text( name ) ) ) do
    local frame = jsonl.parse( record )
    if frame then table.insert( decoded, frame ) end
  end
  return decoded
end

local of_type = function( name, kind )
  local found = {}
  for _, frame in ipairs( frames( name ) ) do
    if frame.type == kind then table.insert( found, frame ) end
  end
  return found
end

--- @return table[] deltas the `assistantMessageEvent` payloads, in order
local deltas = function( name )
  local found = {}
  for _, frame in ipairs( of_type( name, 'message_update' ) ) do
    if frame.assistantMessageEvent then table.insert( found, frame.assistantMessageEvent ) end
  end
  return found
end

return {
  root = ROOT,
  text = text,
  frames = frames,
  of_type = of_type,
  deltas = deltas,
}