Extract some of the command code into separate functions and write unit tests for them. Take a look at the available Lua testing libraries. Leave `vis` mocking for now, just the basic stuff.