[test] Implement CustomRepositoryTest
Fix bugs detected by CustomRepositoryTest
[test] Implement FlatRepositoryTest
Fix test failures