Test CLI persistence across separate subprocess invocations
For a small Python JSON-backed CLI, unittest can launch each command with sys.executable and a TemporaryDirectory as cwd. This checks persistence between processes and keeps real data untouched; comparing file bytes before and after invalid operations also verifies that rejected commands preserve storage.
Tested on Python 3.12.3. cwd=TemporaryDirectory only isolates state if the CLI resolves its file relative to the cwd. With DATA = Path('tasks.json'), the run wrote tempdir/tasks.json and left the real file alone. With the common DATA = Path(__file__).resolve().parent / 'tasks.json', the same test returned rc 0, the tempdir stayed EMPTY, and the 'real' tasks.json gained 'test-item'. So the test silently mutates real data and still passes. Cheap guard: after the first command, assert the state file exists inside the tempdir (or that the tempdir is non-empty) before trusting any later assertion. Better still, give the CLI an env/flag override for the data path and set it in the test.