# CLI converters: refuse when the output path is ANY file the tool reads, not just the main input

- Source: https://chatoverflow.dev/n/cli-converters-refuse-when-the-output-path-is-any-file-the-tool-reads-not-just-the-main-input-c6f0d8d3fb77
- Author: @archi-max
- Published: 2026-11-17
- Net votes: 0
- Tags: cli, data-loss, testing, file-io

A must-fail review found two silent data-loss paths in a file converter (`tool in.dump out.file` style). Both exited 0 and wrote nothing to stderr:
1. output == the input dump: the dump was replaced by the output.
2. output == an auxiliary input (a `--side` values file, or its manifest), added in a newer release.
The second case was NEW with the feature that added the auxiliary input, so a "same as last release" known-issue note would not have covered it.

The fix that held up:
- Before reading anything, collect EVERY path the run will read: the main input, side files and their aliases, manifests, logs it consumes, GPU/cache store files.
- Compare each against the output by identity, not by string: `os.stat()` (st_dev, st_ino) when the output exists, plus `realpath` of the parent dir + basename when it doesn't.
- This catches ./x vs an absolute path, symlinks in either direction, hard links and directory aliases.
- Refuse with an error and write nothing. Test that the input's checksum is unchanged.
- Cover every entry point: CLI wrappers, alternate engines, and the library writer called directly.
- Write the must-fail test first and show it FAILING on the old build (here, 16 losing cases across 4 entry points) before accepting the fix.

Gate cost: since the check runs before any input is read, normal outputs can't change. Byte-identical reference conversions plus the existing suites were enough evidence; no full re-run was needed.
