mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-03 18:00:36 +00:00
Some checks failed
Integration Tests (Replay) / generate-matrix (push) Successful in 3s
SqlStore Integration Tests / test-postgres (3.12) (push) Failing after 0s
Integration Auth Tests / test-matrix (oauth2_token) (push) Failing after 1s
SqlStore Integration Tests / test-postgres (3.13) (push) Failing after 0s
Test External Providers Installed via Module / test-external-providers-from-module (venv) (push) Has been skipped
Test Llama Stack Build / generate-matrix (push) Successful in 5s
Python Package Build Test / build (3.12) (push) Failing after 4s
API Conformance Tests / check-schema-compatibility (push) Successful in 12s
Test llama stack list-deps / generate-matrix (push) Successful in 29s
Test Llama Stack Build / build-single-provider (push) Successful in 33s
Test llama stack list-deps / list-deps-from-config (push) Successful in 32s
UI Tests / ui-tests (22) (push) Successful in 39s
Test Llama Stack Build / build (push) Successful in 39s
Test llama stack list-deps / show-single-provider (push) Successful in 46s
Python Package Build Test / build (3.13) (push) Failing after 44s
Test External API and Providers / test-external (venv) (push) Failing after 44s
Vector IO Integration Tests / test-matrix (push) Failing after 56s
Test llama stack list-deps / list-deps (push) Failing after 47s
Unit Tests / unit-tests (3.12) (push) Failing after 1m42s
Unit Tests / unit-tests (3.13) (push) Failing after 1m55s
Test Llama Stack Build / build-ubi9-container-distribution (push) Successful in 2m0s
Test Llama Stack Build / build-custom-container-distribution (push) Successful in 2m2s
Integration Tests (Replay) / Integration Tests (, , , client=, ) (push) Failing after 2m42s
Pre-commit / pre-commit (push) Successful in 5m17s
# What does this PR do? the directory structure was src/llama-stack-api/llama_stack_api instead it should just be src/llama_stack_api to match the other packages. update the structure and pyproject/linting config --------- Signed-off-by: Charlie Doern <cdoern@redhat.com> Co-authored-by: Ashwin Bharambe <ashwin.bharambe@gmail.com>
111 lines
3.9 KiB
Python
111 lines
3.9 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the terms described in the LICENSE file in
|
|
# the root directory of this source tree.
|
|
|
|
|
|
from llama_stack.core.datatypes import ModelWithOwner, User
|
|
from llama_stack.core.store.registry import CachedDiskDistributionRegistry
|
|
from llama_stack_api import ModelType
|
|
|
|
|
|
async def test_registry_cache_with_acl(cached_disk_dist_registry):
|
|
model = ModelWithOwner(
|
|
identifier="model-acl",
|
|
provider_id="test-provider",
|
|
provider_resource_id="model-acl-resource",
|
|
model_type=ModelType.llm,
|
|
owner=User("testuser", {"roles": ["admin"], "teams": ["ai-team"]}),
|
|
)
|
|
|
|
success = await cached_disk_dist_registry.register(model)
|
|
assert success
|
|
|
|
cached_model = cached_disk_dist_registry.get_cached("model", "model-acl")
|
|
assert cached_model is not None
|
|
assert cached_model.identifier == "model-acl"
|
|
assert cached_model.owner.principal == "testuser"
|
|
assert cached_model.owner.attributes["roles"] == ["admin"]
|
|
assert cached_model.owner.attributes["teams"] == ["ai-team"]
|
|
|
|
fetched_model = await cached_disk_dist_registry.get("model", "model-acl")
|
|
assert fetched_model is not None
|
|
assert fetched_model.identifier == "model-acl"
|
|
assert fetched_model.owner.attributes["roles"] == ["admin"]
|
|
|
|
new_registry = CachedDiskDistributionRegistry(cached_disk_dist_registry.kvstore)
|
|
await new_registry.initialize()
|
|
|
|
new_model = await new_registry.get("model", "model-acl")
|
|
assert new_model is not None
|
|
assert new_model.identifier == "model-acl"
|
|
assert new_model.owner.principal == "testuser"
|
|
assert new_model.owner.attributes["roles"] == ["admin"]
|
|
assert new_model.owner.attributes["teams"] == ["ai-team"]
|
|
|
|
|
|
async def test_registry_empty_acl(cached_disk_dist_registry):
|
|
model = ModelWithOwner(
|
|
identifier="model-empty-acl",
|
|
provider_id="test-provider",
|
|
provider_resource_id="model-resource",
|
|
model_type=ModelType.llm,
|
|
owner=User("testuser", None),
|
|
)
|
|
|
|
await cached_disk_dist_registry.register(model)
|
|
|
|
cached_model = cached_disk_dist_registry.get_cached("model", "model-empty-acl")
|
|
assert cached_model is not None
|
|
assert cached_model.owner is not None
|
|
assert cached_model.owner.attributes is None
|
|
|
|
all_models = await cached_disk_dist_registry.get_all()
|
|
assert len(all_models) == 1
|
|
|
|
model = ModelWithOwner(
|
|
identifier="model-no-acl",
|
|
provider_id="test-provider",
|
|
provider_resource_id="model-resource-2",
|
|
model_type=ModelType.llm,
|
|
)
|
|
|
|
await cached_disk_dist_registry.register(model)
|
|
|
|
cached_model = cached_disk_dist_registry.get_cached("model", "model-no-acl")
|
|
assert cached_model is not None
|
|
assert cached_model.owner is None
|
|
|
|
all_models = await cached_disk_dist_registry.get_all()
|
|
assert len(all_models) == 2
|
|
|
|
|
|
async def test_registry_serialization(cached_disk_dist_registry):
|
|
attributes = {
|
|
"roles": ["admin", "researcher"],
|
|
"teams": ["ai-team", "ml-team"],
|
|
"projects": ["project-a", "project-b"],
|
|
"namespaces": ["prod", "staging"],
|
|
}
|
|
|
|
model = ModelWithOwner(
|
|
identifier="model-serialize",
|
|
provider_id="test-provider",
|
|
provider_resource_id="model-resource",
|
|
model_type=ModelType.llm,
|
|
owner=User("bob", attributes),
|
|
)
|
|
|
|
await cached_disk_dist_registry.register(model)
|
|
|
|
new_registry = CachedDiskDistributionRegistry(cached_disk_dist_registry.kvstore)
|
|
await new_registry.initialize()
|
|
|
|
loaded_model = await new_registry.get("model", "model-serialize")
|
|
assert loaded_model is not None
|
|
|
|
assert loaded_model.owner.attributes["roles"] == ["admin", "researcher"]
|
|
assert loaded_model.owner.attributes["teams"] == ["ai-team", "ml-team"]
|
|
assert loaded_model.owner.attributes["projects"] == ["project-a", "project-b"]
|
|
assert loaded_model.owner.attributes["namespaces"] == ["prod", "staging"]
|