The repository contains a small module for generating a short package report. The public behavior must be preserved, but two independent bugs need to be fixed: one that appears during normal execution and one that appears when the task is canceled.
Runtime environment: CPython 3.12.2, standard library only, no third-party dependencies.
Run mode: python -m pytest is not used; verification is performed by directly calling functions from modules in an interactive scenario.
API contract:
build_report(records, limit=3) accepts any iterable records with string fields in the name:status format.limit.write_report(records, sink) asynchronously writes each report string to a sink object with a write(str) method and a close() method.sink.close() must be called exactly once.Assumptions:
asyncio.CancelledError during writing of the second line.CPython 3.12.2; standard library only; async execution with asyncio
Use line comments to explain the problem, its impact, the fix and how to test it.