meta-llama / llama-stack

Composable building blocks to build Llama Apps
MIT License
4.67k stars 599 forks source link

Add test::mock providers #436

Open ashwinb opened 1 week ago

ashwinb commented 1 week ago

🚀 The feature, motivation and pitch

We have a decently flexible testing system for testing various combinations of providers when composing a Llama Stack.

See https://github.com/meta-llama/llama-stack/blob/main/llama_stack/providers/tests/README.md

We need to add some mocks / fakes so it is easy quickly test through dependent code without provisioning heavy resources (especially for inference / tool calling)

Alternatives

No alternatives

Additional context

No response

vladimirivic commented 1 week ago

Taking this one. I spent some time reviewing the code and figuring out how we can do this in a way that is easy to setup yet generic enough to work seamlessly with the existing tests.

Proposal details:

Point 1

# Test fake config
class TestFakeProviderConfig(BaseModel):
  impls: Dict[Api, Any]

# Example:
memory_impl = TestFakeMemory()
memory_banks_impl = TestFakeMemoryBanks()

config = TestFakeProviderConfig(
    impls={
        Api.memory: memory_impl,
        Api.memory_banks: memory_banks_impl,
    }
)

 ProviderFixture(
    providers=[
        Provider(
            provider_id="test::test-fake",
            provider_type="test::test-fake",
            config=config.model_dump(),
        )
    ],
)

test_stack = test_fake_stack_fixture(config)

Point 2

# Fakes and their setup (dependency injection and stubbing)
memory_banks_impl = MemoryBanksTestFakeImpl()
memory_impl = MemoryTestFakeImpl()
memory_impl.set_memory_banks(memory_banks_impl)
memory_impl.set_stubs("query_documents", query_documents_stubs)

config = TestFakeProviderConfig(
    impls={
        Api.memory: memory_impl,
        Api.memory_banks: memory_banks_impl,
    }
)

Point 3

vladimirivic commented 6 days ago

Updating proposal. Actually we do not want to mock/fake provider as “test::test-fake” provider. Instead we want to initiate mocks for underlying APIs while provider fixtures can go through the full setup process.

Main points:

This way when developing support for new provider, writing mocks becomes a part of the implementation workflow but it's intuitive to follow and easy to implement.