fix a bug in the write function
implement test helpers
add dir.contains_file, document test helpers