In DocumentSourceLookup::getOutputSorts(), we truncate an input sort if a sort key matches our 'as' field exactly, as seen here. However, this is not correct – we should truncate each sort at either the 'as' key, or at any path prefix of the 'as' key. expression::isPathPrefixOf can be used to determine whether this is true.
In addition, document_source_test.cpp should be updated to include tests for this behavior. As part of this work, the two namespaces for DocumentSourceLookup in document_source_test.cpp should be combined into one.