Apply a bounded patch atomically in memory
Apply edits to a virtual repository mapping. Each edit supplies a relative POSIX path, nonempty old text, and replacement new text. Only existing files are supported, with at most one edit per path. The old text must occur exactly once in the original file. Reject absolute paths, empty/dot/traversal segments, backslashes, stale context, and ambiguity. Validate all edits before returning a new mapping. Never mutate inputs or execute the edited code. This is an educational patch format, not a Git patch parser or a security sandbox.
Your task
- Complete the starter function using the contract above.
- Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
- Run tests to record your result, then compare with the explained reference solution.
Examples
Inputold now <= expiry; new now < expiry
OutputA copied mapping with exactly that replacement
InputOne valid edit then one stale edit
OutputValueError; original mapping unchanged
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor