Write a complete, functional program in the language of your choice that solves a specific data processing task, complete with automated tests and comprehensive documentation. Implement the task below as a function that parses CSV text with a category,value header, aggregates values by category, and returns [category, total] pairs sorted by descending total and then ascending category. Document the function and provide tests covering normal input, quoted categories, repeated categories, and edge values.
def aggregate_csv(csv_text):