TEST_F(OptimizePipeline, ExclusionProjectThenProjectPushDown) {
    auto pipeline = Pipeline::parse(
        makeVector(fromjson("{$_internalUnpackBucket: { exclude: [], timeField: 'time',"
                            "metaField: 'myMeta', bucketMaxSpanSeconds: 3600}}"),
                   fromjson("{$project: {myMeta: 0}}"),
                   fromjson("{$project: {myMeta: 1, a: 1, _id: 0}}")),
        getExpCtx());
    ASSERT_EQ(3u, pipeline->getSources().size());

    pipeline->optimizePipeline();

    // We should push down the exclusion project on the metaField then internalize the remaining
    // project.
    auto serialized = pipeline->serializeToBson();
    ASSERT_EQ(2u, serialized.size());
    ASSERT_BSONOBJ_EQ(fromjson("{$project: {meta: false, _id: true}}"), serialized[0]);
    ASSERT_BSONOBJ_EQ(
        fromjson("{$_internalUnpackBucket: { include: ['a', 'myMeta'], timeField: 'time', "
                 "metaField: 'myMeta', bucketMaxSpanSeconds: 3600}}"),
        serialized[1]);
}
TEST_F(OptimizePipeline, ExclusionProjectThenProjectPushDown) {
    auto pipeline = Pipeline::parse(
        makeVector(fromjson("{$_internalUnpackBucket: { exclude: [], timeField: 'time',"
                            "metaField: 'myMeta', bucketMaxSpanSeconds: 3600}}"),
                   fromjson("{$project: {myMeta: 0}}"),
                   fromjson("{$project: {myMeta: 1, a: 1, _id: 0}}")),
        getExpCtx());
    ASSERT_EQ(3u, pipeline->getSources().size());

    pipeline->optimizePipeline();

     
     
    auto serialized = pipeline->serializeToBson();
    ASSERT_EQ(2u, serialized.size());
    ASSERT_BSONOBJ_EQ(fromjson("{$project: {meta: false, _id: true}}"), serialized[0]);
    ASSERT_BSONOBJ_EQ(
        fromjson("{$_internalUnpackBucket: { include: ['a', 'myMeta'], timeField: 'time', "
                 "metaField: 'myMeta', bucketMaxSpanSeconds: 3600}}"),
        serialized[1]);
}