Xorcism tests gap

I think that Xorcism is one of the best exercises in the Rust track and I really enjoyed doing it. However, when I asked an LLM to review my solution after all the tests had passed, it found a pretty important bug in my Write implementation: I was not handling partial writes correctly, i.e. the case when the downstream writer does not write the whole buffer. I think it would be nice to have a test case for that. I can contribute it.

Could you explain what the test gap is?

Is there an easy mistake someone could make that would miss something? Please share details!

Yes, it’s an easy mistake to make, and as far as I can see, everybody makes it. For example, here is my previous implementation of Write, and most other solutions I’ve seen do pretty much the same:

fn write(&mut self, buf: &[u8]) -> Result<usize, Error> {
    let mut buf_copy = buf.to_vec();
    self.xorcism.munge_in_place(&mut buf_copy);
    self.inner.write(&buf_copy)
}

The problem occurs when inner.write() writes fewer than buf.len() bytes, which is perfectly valid for a Write implementation. In that case, the state of self.xorcism has advanced by more bytes than were actually written, so the next call to write produces incorrect output.

Including me :slightly_smiling_face: I would appreciate an added test case for that. Sorry for the late reply, the forum doesn’t send me emails anymore and I don’t know how to fix it. Feel free to post a PR on GitHub directly, I’ll get notified of that.