A small module builds an event preview from an input stream and simultaneously saves a short summary to a file. Right now, with repeated calls and long sequences, the result looks unstable.
build_preview(source, limit) accepts any iterable object of strings and returns a list of the first limit non-empty, trimmed strings.PreviewStore keeps the latest previews by stream name and can write one report to a text file.PreviewStore object and call capture("alpha", data) twice with different inputs.build_preview() that yields several strings, including empty and whitespace-only ones.write_report(path, source) and verify that the file is available after completion.write_report() with an exception during writing and make sure the resource is released.limit constraint must be respected for any source, including generators.python -m pytest is not required; checks are aimed at direct calls to functions and methodsUse line comments to explain the problem, its impact, the fix and how to test it.