graphcore-kernel 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- graphcore/__init__.py +5 -0
- graphcore/agent_frontend/__init__.py +8 -0
- graphcore/agent_frontend/api.py +69 -0
- graphcore/agent_frontend/base/__init__.py +11 -0
- graphcore/agent_frontend/base/views.py +167 -0
- graphcore/agent_frontend/client.py +31 -0
- graphcore/agent_frontend/context.py +157 -0
- graphcore/agent_frontend/errors.py +12 -0
- graphcore/agent_frontend/loading.py +54 -0
- graphcore/agent_frontend/registry.py +42 -0
- graphcore/agent_frontend/render.py +207 -0
- graphcore/agent_frontend/server.py +103 -0
- graphcore/agent_frontend/signatures.py +35 -0
- graphcore/agent_frontend/testing.py +45 -0
- graphcore/agent_frontend/tests/__init__.py +0 -0
- graphcore/agent_frontend/tests/fakes.py +114 -0
- graphcore/agent_frontend/tests/test_frontend.py +447 -0
- graphcore/agent_frontend/tests/test_loading.py +83 -0
- graphcore/agent_frontend/tests/test_server.py +109 -0
- graphcore/agent_frontend/tools.py +137 -0
- graphcore/api/__init__.py +4 -0
- graphcore/api/graph_api.py +378 -0
- graphcore/api/predicate_codec.py +81 -0
- graphcore/api/tests/__init__.py +0 -0
- graphcore/api/tests/test_changed_entities.py +109 -0
- graphcore/api/tests/test_graph_api.py +290 -0
- graphcore/api/tests/test_graph_api_access.py +94 -0
- graphcore/api/tests/test_graph_api_grants.py +90 -0
- graphcore/api/tests/test_predicate_codec.py +83 -0
- graphcore/api/tests/test_subtree_query.py +79 -0
- graphcore/apps.py +71 -0
- graphcore/auth/__init__.py +1 -0
- graphcore/auth/authn/README.md +178 -0
- graphcore/auth/authn/__init__.py +3 -0
- graphcore/auth/authn/authenticator.py +120 -0
- graphcore/auth/authn/onboarding.py +105 -0
- graphcore/auth/authn/principals.py +20 -0
- graphcore/auth/authn/resource_metadata.py +43 -0
- graphcore/auth/authn/service_accounts.py +96 -0
- graphcore/auth/authn/testing.py +96 -0
- graphcore/auth/authn/tests/__init__.py +0 -0
- graphcore/auth/authn/tests/test_authenticator.py +145 -0
- graphcore/auth/authn/tests/test_onboarding.py +145 -0
- graphcore/auth/authn/tests/test_service_accounts.py +180 -0
- graphcore/auth/authn/users.py +59 -0
- graphcore/auth/authz/__init__.py +0 -0
- graphcore/auth/authz/access_port.py +120 -0
- graphcore/auth/authz/adapter/__init__.py +0 -0
- graphcore/auth/authz/adapter/default_access_adapter.py +556 -0
- graphcore/auth/authz/adapter/tests/__init__.py +0 -0
- graphcore/auth/authz/adapter/tests/test_default_adapter.py +543 -0
- graphcore/auth/authz/adapter/tests/test_entity_write_hooks.py +207 -0
- graphcore/auth/authz/adapter/tests/test_group_types.py +70 -0
- graphcore/auth/authz/adapter/tests/test_sync_support.py +209 -0
- graphcore/auth/authz/defaults.py +26 -0
- graphcore/auth/authz/kernel_policy.py +191 -0
- graphcore/auth/authz/kernel_writes.py +31 -0
- graphcore/auth/authz/lookups.py +25 -0
- graphcore/auth/authz/policy.py +403 -0
- graphcore/auth/authz/tests/__init__.py +0 -0
- graphcore/auth/authz/tests/test_can_contain.py +150 -0
- graphcore/auth/authz/tests/test_contained_by.py +167 -0
- graphcore/auth/authz/tests/test_creation.py +391 -0
- graphcore/auth/authz/tests/test_delete_permission.py +82 -0
- graphcore/auth/authz/tests/test_granted_to_me.py +160 -0
- graphcore/auth/authz/tests/test_integration.py +637 -0
- graphcore/auth/authz/tests/test_invites.py +184 -0
- graphcore/auth/authz/tests/test_kernel_policy.py +140 -0
- graphcore/auth/authz/tests/test_lockout.py +132 -0
- graphcore/auth/authz/tests/test_policy.py +329 -0
- graphcore/auth/authz/tests/test_primitives.py +73 -0
- graphcore/auth/authz/tests/test_principal_creation.py +62 -0
- graphcore/bootstrap/__init__.py +0 -0
- graphcore/bootstrap/deployment.py +67 -0
- graphcore/bootstrap/signals.py +16 -0
- graphcore/bootstrap/tests/__init__.py +0 -0
- graphcore/bootstrap/tests/test_deployment_seed.py +154 -0
- graphcore/broadcast/__init__.py +4 -0
- graphcore/broadcast/broadcaster.py +201 -0
- graphcore/broadcast/channels.py +56 -0
- graphcore/broadcast/tests/__init__.py +0 -0
- graphcore/broadcast/tests/test_broadcaster.py +444 -0
- graphcore/celery.py +14 -0
- graphcore/docs/AGENT_FRONTEND_TDD.md +389 -0
- graphcore/docs/ARCHITECTURE_PRINCIPLES.md +152 -0
- graphcore/docs/AUTHORIZATION_TECHNICAL_TDD.md +1379 -0
- graphcore/docs/ENTITY_REFERENCE_TDD.md +561 -0
- graphcore/docs/GRAPHAPI_FRONT_DOOR.md +173 -0
- graphcore/docs/RUNTIME.md +90 -0
- graphcore/docs/SCHEDULING_TDD.md +244 -0
- graphcore/docs/STRATEGY_EXECUTION_TDD.md +1043 -0
- graphcore/docs/VIEW_ENTITY_TDD.md +522 -0
- graphcore/docs/VIEW_SYSTEM_TDD.md +307 -0
- graphcore/docs/__init__.py +0 -0
- graphcore/docs/doc_topics.py +97 -0
- graphcore/docs/docs_discovery.py +64 -0
- graphcore/docs/public_api.py +56 -0
- graphcore/domain/__init__.py +0 -0
- graphcore/domain/entity/Entity.py +204 -0
- graphcore/domain/entity/__init__.py +0 -0
- graphcore/domain/entity/deployment/Deployment.py +25 -0
- graphcore/domain/entity/deployment/__init__.py +0 -0
- graphcore/domain/entity/grant/Grant.py +31 -0
- graphcore/domain/entity/grant/__init__.py +0 -0
- graphcore/domain/entity/group/Group.py +48 -0
- graphcore/domain/entity/group/README.md +88 -0
- graphcore/domain/entity/group/__init__.py +0 -0
- graphcore/domain/entity/invite/Invite.py +31 -0
- graphcore/domain/entity/invite/__init__.py +0 -0
- graphcore/domain/entity/request_template/RequestTemplate.py +48 -0
- graphcore/domain/entity/request_template/__init__.py +0 -0
- graphcore/domain/entity/request_template/tests/__init__.py +0 -0
- graphcore/domain/entity/request_template/tests/test_request_template.py +52 -0
- graphcore/domain/entity/service_account/ServiceAccount.py +41 -0
- graphcore/domain/entity/service_account/__init__.py +0 -0
- graphcore/domain/entity/strategy_request/StrategyRequest.py +61 -0
- graphcore/domain/entity/strategy_request/__init__.py +0 -0
- graphcore/domain/entity/strategy_request/tests/__init__.py +0 -0
- graphcore/domain/entity/strategy_request/tests/test_strategy_request_entity.py +35 -0
- graphcore/domain/entity/tests/__init__.py +0 -0
- graphcore/domain/entity/tests/test_entity.py +227 -0
- graphcore/domain/entity/tests/test_grant_group_entities.py +36 -0
- graphcore/domain/entity/tests/test_write_once_fields.py +98 -0
- graphcore/domain/entity/user/User.py +39 -0
- graphcore/domain/entity/user/__init__.py +0 -0
- graphcore/domain/entity/user/tests/__init__.py +0 -0
- graphcore/domain/entity/user/tests/test_user_entity.py +33 -0
- graphcore/domain/entity/view/View.py +37 -0
- graphcore/domain/entity/view/__init__.py +0 -0
- graphcore/domain/entity/view/position.py +78 -0
- graphcore/domain/entity/view/tests/__init__.py +0 -0
- graphcore/domain/entity/view/tests/test_position.py +71 -0
- graphcore/domain/entity/view/tests/test_view_entity.py +134 -0
- graphcore/domain/strategy/BaseStrategy.py +759 -0
- graphcore/domain/strategy/DeploymentStrategies.py +55 -0
- graphcore/domain/strategy/GrantStrategies.py +189 -0
- graphcore/domain/strategy/GroupStrategies.py +193 -0
- graphcore/domain/strategy/InviteStrategies.py +84 -0
- graphcore/domain/strategy/RequestTemplateStrategies.py +126 -0
- graphcore/domain/strategy/ViewStrategies.py +219 -0
- graphcore/domain/strategy/__init__.py +0 -0
- graphcore/domain/strategy/runner.py +84 -0
- graphcore/domain/strategy/session.py +56 -0
- graphcore/domain/strategy/tests/BaseStrategyTest.py +167 -0
- graphcore/domain/strategy/tests/__init__.py +0 -0
- graphcore/domain/strategy/tests/test_BaseStrategies.py +870 -0
- graphcore/domain/strategy/tests/test_grant_strategies.py +245 -0
- graphcore/domain/strategy/tests/test_group_strategies.py +99 -0
- graphcore/domain/strategy/tests/test_runner.py +220 -0
- graphcore/domain/strategy/tests/test_strategy_locks.py +446 -0
- graphcore/domain/strategy/tests/test_utils.py +95 -0
- graphcore/domain/strategy/tests/test_view_strategies.py +436 -0
- graphcore/errors.py +145 -0
- graphcore/execution/README.md +97 -0
- graphcore/execution/StrategyExecutorService.py +333 -0
- graphcore/execution/__init__.py +0 -0
- graphcore/execution/dispatcher.py +19 -0
- graphcore/execution/environments/__init__.py +0 -0
- graphcore/execution/environments/celery.py +59 -0
- graphcore/execution/environments/in_process.py +55 -0
- graphcore/execution/local_session.py +117 -0
- graphcore/execution/redis_run_events.py +74 -0
- graphcore/execution/requests.py +22 -0
- graphcore/execution/run_events.py +85 -0
- graphcore/execution/strategy_context.py +54 -0
- graphcore/execution/tasks.py +34 -0
- graphcore/execution/tests/__init__.py +5 -0
- graphcore/execution/tests/contract.py +171 -0
- graphcore/execution/tests/support.py +310 -0
- graphcore/execution/tests/test_dispatchers.py +76 -0
- graphcore/execution/tests/test_executor.py +368 -0
- graphcore/execution/tests/test_local_session.py +95 -0
- graphcore/execution/tests/test_reconcile_runs.py +134 -0
- graphcore/execution/tests/test_run_events.py +106 -0
- graphcore/execution/tests/test_strategy_context.py +62 -0
- graphcore/gateway/__init__.py +1 -0
- graphcore/gateway/remote.py +35 -0
- graphcore/gateway/tests/__init__.py +0 -0
- graphcore/gateway/tests/test_remote.py +30 -0
- graphcore/graph/EntityService.py +710 -0
- graphcore/graph/__init__.py +0 -0
- graphcore/graph/entity_cache.py +152 -0
- graphcore/graph/tests/__init__.py +4 -0
- graphcore/graph/tests/test_EntityService.py +908 -0
- graphcore/graph/tests/test_EntityService_list.py +170 -0
- graphcore/graph/tests/test_EntityService_model_resolution.py +339 -0
- graphcore/graph/tests/test_EntityService_referrers.py +236 -0
- graphcore/graph/tests/test_EntityService_routing.py +119 -0
- graphcore/graph/tests/test_dependent_on.py +141 -0
- graphcore/graph/tests/test_engine_is_type_agnostic.py +25 -0
- graphcore/graph/tests/test_engine_resolves_read_permission.py +93 -0
- graphcore/graph/tests/test_entity_cache.py +159 -0
- graphcore/graph/tests/test_null_entity_cache.py +12 -0
- graphcore/management/__init__.py +0 -0
- graphcore/management/commands/__init__.py +0 -0
- graphcore/management/commands/dev_reset.py +18 -0
- graphcore/management/commands/graphcore_createadmin.py +65 -0
- graphcore/management/commands/graphcore_policy.py +59 -0
- graphcore/management/commands/graphcore_status.py +98 -0
- graphcore/management/tests/__init__.py +0 -0
- graphcore/management/tests/test_createadmin.py +78 -0
- graphcore/management/tests/test_policy_command.py +46 -0
- graphcore/management/tests/test_status_command.py +85 -0
- graphcore/migrations/0001_initial.py +186 -0
- graphcore/migrations/0002_invite.py +26 -0
- graphcore/migrations/__init__.py +0 -0
- graphcore/models.py +11 -0
- graphcore/persistence/ENTITY_REPOSITORY_TECHNICAL_TDD.md +396 -0
- graphcore/persistence/__init__.py +6 -0
- graphcore/persistence/django/__init__.py +0 -0
- graphcore/persistence/django/backends.py +43 -0
- graphcore/persistence/django/bindings.py +28 -0
- graphcore/persistence/django/cache.py +38 -0
- graphcore/persistence/django/compiler.py +214 -0
- graphcore/persistence/django/identity.py +18 -0
- graphcore/persistence/django/models.py +252 -0
- graphcore/persistence/django/repository.py +525 -0
- graphcore/persistence/django/tests/__init__.py +0 -0
- graphcore/persistence/django/tests/test_backends.py +68 -0
- graphcore/persistence/django/tests/test_compiler.py +269 -0
- graphcore/persistence/django/tests/test_repository.py +472 -0
- graphcore/persistence/django/tests/test_shared_column.py +120 -0
- graphcore/persistence/django/tests/test_threads.py +50 -0
- graphcore/persistence/django/tests/test_update_shape.py +175 -0
- graphcore/persistence/django/threads.py +38 -0
- graphcore/persistence/repository.py +172 -0
- graphcore/persistence/tests/__init__.py +0 -0
- graphcore/persistence/tests/contract.py +688 -0
- graphcore/persistence/tests/evaluate.py +51 -0
- graphcore/persistence/tests/fixtures.py +32 -0
- graphcore/persistence/tests/memory.py +263 -0
- graphcore/persistence/tests/test_memory_repository.py +10 -0
- graphcore/persistence/tests/test_query_types.py +127 -0
- graphcore/public/__init__.py +9 -0
- graphcore/public/api.py +9 -0
- graphcore/public/apps.py +10 -0
- graphcore/public/auth/__init__.py +1 -0
- graphcore/public/auth/grants.py +7 -0
- graphcore/public/auth/onboarding.py +8 -0
- graphcore/public/auth/perms.py +7 -0
- graphcore/public/auth/policy.py +10 -0
- graphcore/public/auth/roles.py +8 -0
- graphcore/public/auth/subjects.py +7 -0
- graphcore/public/entities/__init__.py +32 -0
- graphcore/public/errors.py +19 -0
- graphcore/public/persistence/__init__.py +44 -0
- graphcore/public/persistence/django.py +24 -0
- graphcore/public/scheduling.py +23 -0
- graphcore/public/strategies/__init__.py +85 -0
- graphcore/public/test_settings.py +16 -0
- graphcore/public/testing.py +47 -0
- graphcore/registry/EntityDirectory.py +246 -0
- graphcore/registry/README.md +147 -0
- graphcore/registry/StrategyDirectory.py +308 -0
- graphcore/registry/TYPE_METADATA_PLACEMENT.md +66 -0
- graphcore/registry/__init__.py +0 -0
- graphcore/registry/app_discovery.py +108 -0
- graphcore/registry/decorators.py +77 -0
- graphcore/registry/discovery.py +111 -0
- graphcore/registry/registry.py +79 -0
- graphcore/registry/tests/__init__.py +0 -0
- graphcore/registry/tests/test_agent_frontend_discovery.py +56 -0
- graphcore/registry/tests/test_app_config.py +36 -0
- graphcore/registry/tests/test_discovery.py +147 -0
- graphcore/registry/tests/test_entity_directory_storage.py +73 -0
- graphcore/registry/tests/test_import_package.py +87 -0
- graphcore/registry/tests/test_principal_flag.py +67 -0
- graphcore/registry/tests/test_strategy_directory.py +29 -0
- graphcore/routes/__init__.py +116 -0
- graphcore/routes/tests/__init__.py +0 -0
- graphcore/routes/tests/test_routes.py +90 -0
- graphcore/runtime.py +243 -0
- graphcore/scheduling/__init__.py +0 -0
- graphcore/scheduling/beat_scheduler.py +164 -0
- graphcore/scheduling/beat_tasks.py +63 -0
- graphcore/scheduling/scheduler.py +37 -0
- graphcore/scheduling/tests/__init__.py +0 -0
- graphcore/scheduling/tests/contract.py +136 -0
- graphcore/scheduling/tests/memory.py +42 -0
- graphcore/scheduling/tests/test_beat_scheduler.py +87 -0
- graphcore/scheduling/tests/test_memory_scheduler.py +15 -0
- graphcore/scheduling/tests/test_ticks.py +143 -0
- graphcore/tasks.py +9 -0
- graphcore/test_settings.py +78 -0
- graphcore/testing/__init__.py +0 -0
- graphcore/testing/case.py +112 -0
- graphcore/testing/runner.py +32 -0
- graphcore/testing/settings.py +26 -0
- graphcore/testing/tests/__init__.py +0 -0
- graphcore/testing/tests/agent_view_fixture.py +19 -0
- graphcore/testing/tests/test_case_and_runner.py +219 -0
- graphcore/testing/tests/test_settings_for_apps.py +50 -0
- graphcore/tests/__init__.py +0 -0
- graphcore/tests/ids.py +14 -0
- graphcore/tests/public_api_manifest.py +102 -0
- graphcore/tests/runs.py +7 -0
- graphcore/tests/test_app_discovery.py +90 -0
- graphcore/tests/test_composition_boundaries.py +231 -0
- graphcore/tests/test_docs_discovery.py +108 -0
- graphcore/tests/test_no_print.py +70 -0
- graphcore/tests/test_packaging.py +64 -0
- graphcore/tests/test_public_api_boundaries.py +229 -0
- graphcore/tests/test_public_api_contract.py +62 -0
- graphcore/tests/test_public_api_docs.py +28 -0
- graphcore/tests/test_runtime.py +42 -0
- graphcore/tests/test_shared_type_boundaries.py +128 -0
- graphcore/tests/test_shared_types.py +144 -0
- graphcore/tests/test_test_settings.py +45 -0
- graphcore/transport/__init__.py +0 -0
- graphcore/transport/agent_asgi.py +68 -0
- graphcore/transport/agent_client.py +85 -0
- graphcore/transport/channel_layer.py +68 -0
- graphcore/transport/consumers.py +507 -0
- graphcore/transport/routing.py +6 -0
- graphcore/transport/tests/__init__.py +0 -0
- graphcore/transport/tests/test_agent_client.py +31 -0
- graphcore/transport/tests/test_api_views.py +733 -0
- graphcore/transport/tests/test_channel_layer.py +96 -0
- graphcore/transport/tests/test_consumers.py +963 -0
- graphcore/transport/tests/test_resource_metadata.py +67 -0
- graphcore/transport/urls.py +29 -0
- graphcore/transport/views.py +358 -0
- graphcore/types/__init__.py +4 -0
- graphcore/types/access.py +114 -0
- graphcore/types/api.py +76 -0
- graphcore/types/entities.py +100 -0
- graphcore/types/entity_id.py +85 -0
- graphcore/types/execution.py +41 -0
- graphcore/types/identity.py +20 -0
- graphcore/types/onboarding.py +20 -0
- graphcore/types/query.py +116 -0
- graphcore/types/schedules.py +91 -0
- graphcore/types/strategy.py +73 -0
- graphcore/types/tests/__init__.py +0 -0
- graphcore/types/tests/test_entity_id.py +50 -0
- graphcore/urls.py +5 -0
- graphcore_kernel-0.1.0.dist-info/METADATA +94 -0
- graphcore_kernel-0.1.0.dist-info/RECORD +343 -0
- graphcore_kernel-0.1.0.dist-info/WHEEL +5 -0
- graphcore_kernel-0.1.0.dist-info/entry_points.txt +2 -0
- graphcore_kernel-0.1.0.dist-info/licenses/LICENSE +202 -0
- graphcore_kernel-0.1.0.dist-info/licenses/NOTICE +2 -0
- graphcore_kernel-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""`GraphCoreTestRunner`: Django's runner plus the project's own apps
|
|
2
|
+
(exported by `graphcore.public.testing`)."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from django.apps import apps
|
|
8
|
+
from django.conf import settings
|
|
9
|
+
from django.test.runner import DiscoverRunner
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class GraphCoreTestRunner(DiscoverRunner):
|
|
13
|
+
"""Django's runner, except that with no test labels it also runs the
|
|
14
|
+
tests of every GraphCore app inside this project, not only those under
|
|
15
|
+
the current directory. Installed app packages are not included."""
|
|
16
|
+
|
|
17
|
+
def build_suite(self, test_labels=None, **kwargs):
|
|
18
|
+
if not test_labels:
|
|
19
|
+
test_labels = ['.', *project_app_labels()]
|
|
20
|
+
return super().build_suite(test_labels, **kwargs)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def project_app_labels() -> list[str]:
|
|
24
|
+
"""The GraphCore apps whose code lives under the project root."""
|
|
25
|
+
project_root = Path(settings.BASE_DIR).resolve().parent
|
|
26
|
+
# GRAPHCORE_APPS holds module names; an installed app's label can differ.
|
|
27
|
+
modules = set(getattr(settings, 'GRAPHCORE_APPS', ()))
|
|
28
|
+
return [
|
|
29
|
+
config.name
|
|
30
|
+
for config in apps.get_app_configs()
|
|
31
|
+
if config.name in modules and Path(config.path).resolve().is_relative_to(project_root)
|
|
32
|
+
]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""`app_test_settings`: an app's settings for running its tests without a
|
|
2
|
+
project (exported by `graphcore.public.test_settings`)."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import importlib.util
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def app_test_settings(app: str) -> dict:
|
|
10
|
+
"""The kernel's test settings with `app` installed, testing in `test_<app>`.
|
|
11
|
+
|
|
12
|
+
`BASE_DIR` is set as a project beside the app's `apps/` directory would
|
|
13
|
+
have it, so `open_place` finds the app's agent views (and its siblings')
|
|
14
|
+
as the project would."""
|
|
15
|
+
from graphcore import test_settings as kernel
|
|
16
|
+
|
|
17
|
+
settings = {name: value for name, value in vars(kernel).items() if name.isupper()}
|
|
18
|
+
settings['INSTALLED_APPS'] = [*settings['INSTALLED_APPS'], app]
|
|
19
|
+
database = dict(settings['DATABASES']['default'])
|
|
20
|
+
if 'TEST' in database:
|
|
21
|
+
database['TEST'] = {**database['TEST'], 'NAME': f'test_{app}'}
|
|
22
|
+
settings['DATABASES'] = {'default': database}
|
|
23
|
+
# <apps>/<app>/backend/<app>/__init__.py
|
|
24
|
+
apps_dir = Path(importlib.util.find_spec(app).origin).resolve().parents[3]
|
|
25
|
+
settings['BASE_DIR'] = apps_dir.parent / 'backend'
|
|
26
|
+
return settings
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""An app's agent views, for `graphcore.testing.tests.test_case_and_runner`: `_Scope`'s
|
|
2
|
+
view, with a tool that sets an attribute on it."""
|
|
3
|
+
from graphcore.agent_frontend import agent_view, strategy_tool
|
|
4
|
+
from graphcore.public.persistence import ContainsValue
|
|
5
|
+
|
|
6
|
+
SCOPE_TYPE_ID = 'graphcore._Scope'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def scope_tools(ctx, scope):
|
|
10
|
+
return [strategy_tool('SetAttributes', bind=scope.entity_id)]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@agent_view('fixture.scope', default_for=[SCOPE_TYPE_ID], tools=scope_tools)
|
|
14
|
+
async def scope_view(ctx, scope):
|
|
15
|
+
descendants = await ctx.query(SCOPE_TYPE_ID, where=ContainsValue('ancestor_ids', scope.entity_id))
|
|
16
|
+
return [
|
|
17
|
+
f"proof: {scope.get_attribute('proof') if scope.has_attribute('proof') else 'none'}",
|
|
18
|
+
f"descendants: {len(descendants)}{' and more' if ctx.more else ''}",
|
|
19
|
+
]
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"""`GraphCoreTestCase` and `GraphCoreTestRunner`, as app authors import them."""
|
|
2
|
+
import re
|
|
3
|
+
import sys
|
|
4
|
+
import tempfile
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from unittest import mock
|
|
7
|
+
|
|
8
|
+
from django.apps import apps
|
|
9
|
+
from django.test import SimpleTestCase, TransactionTestCase, override_settings
|
|
10
|
+
|
|
11
|
+
from graphcore.agent_frontend import AgentError
|
|
12
|
+
from graphcore.agent_frontend.context import entity_address
|
|
13
|
+
from graphcore.domain.entity.Entity import Entity
|
|
14
|
+
from graphcore.execution.strategy_context import kernel_internal_context
|
|
15
|
+
from graphcore.public.errors import Forbidden
|
|
16
|
+
from graphcore.public.strategies import SetAttributes
|
|
17
|
+
from graphcore.public.testing import GraphCoreTestCase, GraphCoreTestRunner
|
|
18
|
+
from graphcore.registry.app_discovery import discover_agent_frontends
|
|
19
|
+
from graphcore.registry.registry import DEFAULT_REGISTRY
|
|
20
|
+
from graphcore.runtime import django_runtime
|
|
21
|
+
from graphcore.testing.tests.agent_view_fixture import SCOPE_TYPE_ID
|
|
22
|
+
|
|
23
|
+
TEST_REGISTRY = DEFAULT_REGISTRY.fork_open()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class _Scope(Entity):
|
|
27
|
+
"""A shareable type standing in for an app's."""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
TEST_REGISTRY.entities.register_entity(_Scope, app_label='graphcore')
|
|
31
|
+
TEST_REGISTRY.policy.define(_Scope, shareable=True)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class GraphCoreTestCaseTests(GraphCoreTestCase):
|
|
35
|
+
def setUp(self):
|
|
36
|
+
super().setUp()
|
|
37
|
+
self.runtime = django_runtime(TEST_REGISTRY)
|
|
38
|
+
self.api = self.runtime.graph_api
|
|
39
|
+
|
|
40
|
+
def set_attribute(self, entity_id):
|
|
41
|
+
return SetAttributes.request_constructor(
|
|
42
|
+
target_entity_id=entity_id, attribute_map={'proof': 1},
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
async def test_the_owner_of_a_fixture_can_run_strategies_on_it(self):
|
|
46
|
+
owner = await self.create_user('owner')
|
|
47
|
+
scope = await self.create_entity(_Scope, owner)
|
|
48
|
+
|
|
49
|
+
completed = await self.run_strategy(owner, self.set_attribute(scope.entity_id))
|
|
50
|
+
|
|
51
|
+
self.assertEqual(completed.target_entity_id, scope.entity_id)
|
|
52
|
+
self.assertEqual((await self.get_entity(owner, scope.entity_id)).get_attribute('proof'), 1)
|
|
53
|
+
|
|
54
|
+
async def test_run_strategy_enforces_authorization(self):
|
|
55
|
+
owner = await self.create_user('owner')
|
|
56
|
+
stranger = await self.create_user('stranger')
|
|
57
|
+
scope = await self.create_entity(_Scope, owner)
|
|
58
|
+
|
|
59
|
+
with self.assertRaises(Forbidden):
|
|
60
|
+
await self.run_strategy(stranger, self.set_attribute(scope.entity_id))
|
|
61
|
+
|
|
62
|
+
async def test_a_grant_changes_what_the_grantee_may_do(self):
|
|
63
|
+
owner = await self.create_user('owner')
|
|
64
|
+
editor = await self.create_user('editor')
|
|
65
|
+
scope = await self.create_entity(_Scope, owner)
|
|
66
|
+
|
|
67
|
+
await self.grant(owner, scope.entity_id, editor, 'editor')
|
|
68
|
+
|
|
69
|
+
await self.run_strategy(editor, self.set_attribute(scope.entity_id))
|
|
70
|
+
|
|
71
|
+
async def test_get_entity_is_a_tombstone_for_a_non_reader(self):
|
|
72
|
+
owner = await self.create_user('owner')
|
|
73
|
+
stranger = await self.create_user('stranger')
|
|
74
|
+
scope = await self.create_entity(_Scope, owner)
|
|
75
|
+
|
|
76
|
+
self.assertEqual((await self.get_entity(stranger, scope.entity_id)).cause, 'forbidden')
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class AgentViewTestingTests(GraphCoreTestCase):
|
|
80
|
+
def setUp(self):
|
|
81
|
+
super().setUp()
|
|
82
|
+
self.runtime = django_runtime(TEST_REGISTRY)
|
|
83
|
+
self.api = self.runtime.graph_api
|
|
84
|
+
|
|
85
|
+
def agent_frontends(self):
|
|
86
|
+
return ['graphcore.testing.tests.agent_view_fixture']
|
|
87
|
+
|
|
88
|
+
async def owned_scope(self):
|
|
89
|
+
owner = await self.create_user('owner')
|
|
90
|
+
return owner, await self.create_entity(_Scope, owner)
|
|
91
|
+
|
|
92
|
+
def test_the_fixture_names_scopes_type_id(self):
|
|
93
|
+
self.assertEqual(TEST_REGISTRY.entities.get_entity_type_id(_Scope), SCOPE_TYPE_ID)
|
|
94
|
+
|
|
95
|
+
async def test_the_owner_opens_the_apps_view_by_id_or_address(self):
|
|
96
|
+
owner, scope = await self.owned_scope()
|
|
97
|
+
|
|
98
|
+
place = await self.open_place(owner, scope.entity_id)
|
|
99
|
+
|
|
100
|
+
self.assertTrue(place.text.startswith(f"# {scope.entity_id} · {SCOPE_TYPE_ID}"))
|
|
101
|
+
self.assertIn('proof: none', place.text)
|
|
102
|
+
self.assertRegex(place.version, re.compile(r'^[0-9a-f]{16}$'))
|
|
103
|
+
self.assertIn('set_attributes', place.tools)
|
|
104
|
+
self.assertEqual(await self.open_place(owner, entity_address(scope.entity_id)), place)
|
|
105
|
+
|
|
106
|
+
async def test_a_tool_call_changes_the_place_and_returns_its_new_version(self):
|
|
107
|
+
owner, scope = await self.owned_scope()
|
|
108
|
+
before = await self.open_place(owner, scope.entity_id)
|
|
109
|
+
|
|
110
|
+
result = await self.call_tool(owner, scope.entity_id, 'set_attributes', {'attribute_map': {'proof': 1}})
|
|
111
|
+
|
|
112
|
+
after = await self.open_place(owner, scope.entity_id)
|
|
113
|
+
self.assertTrue(result['ok'])
|
|
114
|
+
self.assertIn('proof: 1', after.text)
|
|
115
|
+
self.assertNotEqual(after.version, before.version)
|
|
116
|
+
self.assertEqual(result['version'], after.version)
|
|
117
|
+
|
|
118
|
+
async def test_a_stranger_cannot_open_the_place(self):
|
|
119
|
+
owner, scope = await self.owned_scope()
|
|
120
|
+
stranger = await self.create_user('stranger')
|
|
121
|
+
|
|
122
|
+
with self.assertRaises(AgentError) as raised:
|
|
123
|
+
await self.open_place(stranger, scope.entity_id)
|
|
124
|
+
self.assertEqual(raised.exception.code, 'NotFound')
|
|
125
|
+
|
|
126
|
+
async def test_a_reader_sees_the_tool_but_its_call_is_refused(self):
|
|
127
|
+
owner, scope = await self.owned_scope()
|
|
128
|
+
reader = await self.create_user('reader')
|
|
129
|
+
await self.grant(owner, scope.entity_id, reader, 'viewer')
|
|
130
|
+
place = await self.open_place(reader, scope.entity_id)
|
|
131
|
+
|
|
132
|
+
with self.assertRaises(AgentError) as raised:
|
|
133
|
+
await self.call_tool(reader, scope.entity_id, 'set_attributes', {'attribute_map': {'proof': 1}})
|
|
134
|
+
|
|
135
|
+
self.assertIn('set_attributes', place.tools)
|
|
136
|
+
self.assertEqual(raised.exception.code, 'Refused')
|
|
137
|
+
self.assertEqual((await self.open_place(owner, scope.entity_id)).version, place.version)
|
|
138
|
+
|
|
139
|
+
async def test_bad_calls_raise_the_agents_error_codes(self):
|
|
140
|
+
owner, scope = await self.owned_scope()
|
|
141
|
+
seen = (await self.open_place(owner, scope.entity_id)).version
|
|
142
|
+
await self.call_tool(owner, scope.entity_id, 'set_attributes', {'attribute_map': {'proof': 1}})
|
|
143
|
+
|
|
144
|
+
for code, tool, params, seen_version in [
|
|
145
|
+
('Stale', 'set_attributes', {'attribute_map': {'proof': 2}}, seen),
|
|
146
|
+
('UnknownTool', 'no_such_tool', {}, None),
|
|
147
|
+
('InvalidRequest', 'set_attributes', {}, None),
|
|
148
|
+
]:
|
|
149
|
+
with self.subTest(code), self.assertRaises(AgentError) as raised:
|
|
150
|
+
await self.call_tool(owner, scope.entity_id, tool, params, seen_version)
|
|
151
|
+
self.assertEqual(raised.exception.code, code)
|
|
152
|
+
|
|
153
|
+
async def test_a_view_queries_every_page_and_versions_on_all_it_read(self):
|
|
154
|
+
owner, scope = await self.owned_scope()
|
|
155
|
+
children = []
|
|
156
|
+
for _ in range(250):
|
|
157
|
+
child = self.runtime.entity_service.create(_Scope)
|
|
158
|
+
child.owner, child.parent_id = owner.principal_entity_id, scope.entity_id
|
|
159
|
+
with kernel_internal_context():
|
|
160
|
+
children.append(await self.runtime.entity_service.save_entity(child, owner))
|
|
161
|
+
before = await self.open_place(owner, scope.entity_id)
|
|
162
|
+
|
|
163
|
+
await self.run_strategy(owner, SetAttributes.request_constructor(
|
|
164
|
+
target_entity_id=children[-1].entity_id, attribute_map={'proof': 1},
|
|
165
|
+
))
|
|
166
|
+
|
|
167
|
+
self.assertIn('descendants: 250\n', before.text + '\n')
|
|
168
|
+
self.assertNotEqual((await self.open_place(owner, scope.entity_id)).version, before.version)
|
|
169
|
+
|
|
170
|
+
async def test_the_base_home_view_loads_beside_the_app(self):
|
|
171
|
+
owner, _ = await self.owned_scope()
|
|
172
|
+
|
|
173
|
+
self.assertTrue((await self.open_place(owner, '/')).text.startswith('# Home'))
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
KERNEL_ROOT = Path(apps.get_app_config('graphcore').path)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
class GraphCoreTestRunnerTests(SimpleTestCase):
|
|
180
|
+
def _labels_built(self, test_labels):
|
|
181
|
+
with mock.patch('django.test.runner.DiscoverRunner.build_suite') as build_suite:
|
|
182
|
+
GraphCoreTestRunner().build_suite(test_labels)
|
|
183
|
+
return build_suite.call_args.args[0]
|
|
184
|
+
|
|
185
|
+
@override_settings(BASE_DIR=KERNEL_ROOT / 'backend', GRAPHCORE_APPS=['graphcore'])
|
|
186
|
+
def test_no_labels_adds_the_apps_inside_the_project(self):
|
|
187
|
+
self.assertEqual(self._labels_built([]), ['.', 'graphcore'])
|
|
188
|
+
|
|
189
|
+
@override_settings(BASE_DIR=Path('/elsewhere/backend'), GRAPHCORE_APPS=['graphcore'])
|
|
190
|
+
def test_apps_installed_outside_the_project_are_left_out(self):
|
|
191
|
+
self.assertEqual(self._labels_built([]), ['.'])
|
|
192
|
+
|
|
193
|
+
@override_settings(
|
|
194
|
+
BASE_DIR=Path(apps.get_app_config('auth').path) / 'backend',
|
|
195
|
+
GRAPHCORE_APPS=['django.contrib.auth'],
|
|
196
|
+
)
|
|
197
|
+
def test_an_app_whose_label_is_not_its_module_name_is_found(self):
|
|
198
|
+
self.assertEqual(self._labels_built([]), ['.', 'django.contrib.auth'])
|
|
199
|
+
|
|
200
|
+
@override_settings(BASE_DIR=KERNEL_ROOT / 'backend', GRAPHCORE_APPS=['graphcore'])
|
|
201
|
+
def test_explicit_labels_are_used_as_given(self):
|
|
202
|
+
self.assertEqual(self._labels_built(['some.label']), ['some.label'])
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class AgentFrontendsTests(SimpleTestCase):
|
|
206
|
+
def test_default_is_the_projects_app_frontends_and_entry_points(self):
|
|
207
|
+
self.addCleanup(lambda saved=list(sys.path): sys.path.__setitem__(slice(None), saved))
|
|
208
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
209
|
+
package = Path(tmp) / 'apps' / 'demo' / 'backend' / 'demo_agent_frontend'
|
|
210
|
+
package.mkdir(parents=True)
|
|
211
|
+
(package / '__init__.py').touch()
|
|
212
|
+
|
|
213
|
+
with override_settings(BASE_DIR=Path(tmp) / 'backend'), \
|
|
214
|
+
mock.patch('graphcore.testing.case.discover_agent_frontends',
|
|
215
|
+
wraps=discover_agent_frontends) as discover:
|
|
216
|
+
frontends = GraphCoreTestCase().agent_frontends()
|
|
217
|
+
|
|
218
|
+
discover.assert_called_once_with(Path(tmp).resolve() / 'apps')
|
|
219
|
+
self.assertEqual(frontends[-1], 'demo_agent_frontend')
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""`graphcore.public.test_settings`: an app's standalone test settings."""
|
|
2
|
+
import importlib
|
|
3
|
+
import sys
|
|
4
|
+
import tempfile
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from unittest import mock
|
|
7
|
+
|
|
8
|
+
from django.test import SimpleTestCase
|
|
9
|
+
|
|
10
|
+
from graphcore import test_settings as kernel
|
|
11
|
+
from graphcore.public.test_settings import app_test_settings
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class AppTestSettingsTests(SimpleTestCase):
|
|
15
|
+
def setUp(self):
|
|
16
|
+
tmp = tempfile.TemporaryDirectory()
|
|
17
|
+
self.addCleanup(tmp.cleanup)
|
|
18
|
+
self.apps = Path(tmp.name).resolve() / 'apps'
|
|
19
|
+
backend = self.apps / 'standalone_app' / 'backend'
|
|
20
|
+
(backend / 'standalone_app').mkdir(parents=True)
|
|
21
|
+
(backend / 'standalone_app' / '__init__.py').touch()
|
|
22
|
+
self.addCleanup(lambda saved=list(sys.path): sys.path.__setitem__(slice(None), saved))
|
|
23
|
+
sys.path.insert(0, str(backend))
|
|
24
|
+
importlib.invalidate_caches()
|
|
25
|
+
|
|
26
|
+
def test_the_kernels_settings_with_the_app_installed(self):
|
|
27
|
+
settings = app_test_settings('standalone_app')
|
|
28
|
+
|
|
29
|
+
self.assertEqual(settings['INSTALLED_APPS'], [*kernel.INSTALLED_APPS, 'standalone_app'])
|
|
30
|
+
self.assertEqual(settings['SECRET_KEY'], kernel.SECRET_KEY)
|
|
31
|
+
self.assertNotIn('database_settings', settings)
|
|
32
|
+
|
|
33
|
+
def test_base_dir_sits_beside_the_apps_directory_holding_the_app(self):
|
|
34
|
+
base_dir = app_test_settings('standalone_app')['BASE_DIR']
|
|
35
|
+
|
|
36
|
+
self.assertEqual(base_dir.parent / 'apps', self.apps)
|
|
37
|
+
|
|
38
|
+
def test_each_app_tests_in_a_database_of_its_own(self):
|
|
39
|
+
with mock.patch.object(kernel, 'DATABASES', {'default': kernel.database_settings('postgresql')}):
|
|
40
|
+
database = app_test_settings('standalone_app')['DATABASES']['default']
|
|
41
|
+
kernel_test_name = kernel.DATABASES['default']['TEST']['NAME']
|
|
42
|
+
|
|
43
|
+
self.assertEqual(database['TEST']['NAME'], 'test_standalone_app')
|
|
44
|
+
self.assertEqual(kernel_test_name, 'test_graphcore_framework')
|
|
45
|
+
|
|
46
|
+
def test_sqlite_needs_no_database_name(self):
|
|
47
|
+
with mock.patch.object(kernel, 'DATABASES', {'default': kernel.database_settings('sqlite')}):
|
|
48
|
+
database = app_test_settings('standalone_app')['DATABASES']['default']
|
|
49
|
+
|
|
50
|
+
self.assertEqual(database, kernel.database_settings('sqlite'))
|
|
File without changes
|
graphcore/tests/ids.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Identifiers for tests that have no `EntityService` to mint one.
|
|
2
|
+
|
|
3
|
+
A test whose entity is saved, or used as a `parent_id`, against a
|
|
4
|
+
Django-backed service needs a *local* id instead: derive it from
|
|
5
|
+
`service.backend_id`, since the persistence chokepoint rejects a foreign
|
|
6
|
+
parent.
|
|
7
|
+
"""
|
|
8
|
+
from graphcore.types.entity_id import new_entity_id
|
|
9
|
+
|
|
10
|
+
FIXTURE_BACKEND = '0000000001'
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def fixture_id(backend_id: str = FIXTURE_BACKEND) -> str:
|
|
14
|
+
return new_entity_id(backend_id)
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""Static export contract for graphcore's public API.
|
|
2
|
+
|
|
3
|
+
``MODULES`` records every canonical, app-author-facing module: its exact
|
|
4
|
+
symbols and its Django import phase (``pre_setup`` is safe before
|
|
5
|
+
``django.setup()``; ``post_setup`` touches models or the registry). There
|
|
6
|
+
is no legacy facade - every consumer imports these modules directly.
|
|
7
|
+
|
|
8
|
+
This module is a pure data literal — no Django imports, no dynamic
|
|
9
|
+
generation — so boundary checks can read it before ``django.setup()``.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from typing import Literal, NamedTuple
|
|
14
|
+
|
|
15
|
+
ImportPhase = Literal['pre_setup', 'post_setup']
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ModuleContract(NamedTuple):
|
|
19
|
+
symbols: tuple[str, ...]
|
|
20
|
+
import_phase: ImportPhase
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
MODULES: dict[str, ModuleContract] = {
|
|
24
|
+
'graphcore.public.apps': ModuleContract(
|
|
25
|
+
('GraphCoreAppConfig',), 'pre_setup',
|
|
26
|
+
),
|
|
27
|
+
'graphcore.public.auth.perms': ModuleContract(
|
|
28
|
+
('Perm', 'Read', 'Write', 'Delete', 'ManageAccess', 'Create', 'CreatePermission'), 'pre_setup',
|
|
29
|
+
),
|
|
30
|
+
'graphcore.public.auth.roles': ModuleContract(
|
|
31
|
+
('Role', 'VIEWER', 'EDITOR', 'ADMIN', 'MEMBER', 'DEFAULT_ROLES'), 'pre_setup',
|
|
32
|
+
),
|
|
33
|
+
'graphcore.public.auth.onboarding': ModuleContract(
|
|
34
|
+
('Onboarding',), 'pre_setup',
|
|
35
|
+
),
|
|
36
|
+
'graphcore.public.auth.subjects': ModuleContract(
|
|
37
|
+
('PUBLIC',), 'pre_setup',
|
|
38
|
+
),
|
|
39
|
+
'graphcore.public.auth.policy': ModuleContract(
|
|
40
|
+
('AccessPolicy', 'EffectivePolicy'), 'pre_setup',
|
|
41
|
+
),
|
|
42
|
+
'graphcore.public.auth.grants': ModuleContract(
|
|
43
|
+
('GrantInfo', 'AccessChange'), 'pre_setup',
|
|
44
|
+
),
|
|
45
|
+
'graphcore.public.entities': ModuleContract(
|
|
46
|
+
('Entity', 'register_entity', 'User', 'ServiceAccount', 'Group',
|
|
47
|
+
'Grant', 'View', 'Deployment'),
|
|
48
|
+
'post_setup',
|
|
49
|
+
),
|
|
50
|
+
'graphcore.public.persistence': ModuleContract(
|
|
51
|
+
('AllOf', 'AnyOf', 'ContainsAny', 'ContainsValue', 'DeleteReceipt',
|
|
52
|
+
'DeletedEntity', 'EntityFilter', 'EntityQuery', 'EntityRepository',
|
|
53
|
+
'Equal', 'InValues', 'PageRequest', 'Predicate', 'SaveReceipt'),
|
|
54
|
+
'post_setup',
|
|
55
|
+
),
|
|
56
|
+
'graphcore.public.persistence.django': ModuleContract(
|
|
57
|
+
('EntityModel', 'GrantModel', 'GroupModel', 'ServiceAccountModel',
|
|
58
|
+
'StrategyRequestModel', 'UserModel'),
|
|
59
|
+
'post_setup',
|
|
60
|
+
),
|
|
61
|
+
'graphcore.public.scheduling': ModuleContract(
|
|
62
|
+
('HeldTask', 'ScheduleInfo', 'ScheduleSpec', 'Scheduler'), 'pre_setup',
|
|
63
|
+
),
|
|
64
|
+
'graphcore.public.strategies': ModuleContract(
|
|
65
|
+
('Strategy', 'StrategyRequest', 'StrategyRequestPayload', 'register_strategy',
|
|
66
|
+
'AddMember', 'ChangeGrantRole', 'CreateView',
|
|
67
|
+
'CreateEntity', 'CreateGrant', 'CreateInvite', 'DeleteEntity',
|
|
68
|
+
'SetViewState', 'FindAndReplace',
|
|
69
|
+
'CreateRequestTemplate', 'ManageRequestTemplate', 'RequestTemplate',
|
|
70
|
+
'ModifyGroup', 'RemoveAttribute',
|
|
71
|
+
'RemoveMember', 'ReorderChild', 'ReparentChild',
|
|
72
|
+
'RevokeGrant', 'SetAttributes', 'CreateGroup',
|
|
73
|
+
'SetNewUserDefaults', 'ChangeTracker', 'RequestStatus', 'StrategyRunner',
|
|
74
|
+
'StrategySession', 'Workload'),
|
|
75
|
+
'post_setup',
|
|
76
|
+
),
|
|
77
|
+
'graphcore.public.errors': ModuleContract(
|
|
78
|
+
('ConcurrentModificationError', 'Conflict', 'DuplicateEntity', 'Forbidden', 'InvalidRequest',
|
|
79
|
+
'KernelError', 'NotFound', 'PreconditionFailed', 'StrategyFailed'), 'pre_setup',
|
|
80
|
+
),
|
|
81
|
+
'graphcore.public.api': ModuleContract(
|
|
82
|
+
('GraphAPI',), 'post_setup',
|
|
83
|
+
),
|
|
84
|
+
'graphcore.public.testing': ModuleContract(
|
|
85
|
+
('DispatcherContract', 'EntityRepositoryContract', 'GraphCoreTestCase', 'GraphCoreTestRunner',
|
|
86
|
+
'Place', 'SchedulerContract', 'StrategySessionContract'),
|
|
87
|
+
'post_setup',
|
|
88
|
+
),
|
|
89
|
+
'graphcore.public.test_settings': ModuleContract(
|
|
90
|
+
('app_test_settings',), 'pre_setup',
|
|
91
|
+
),
|
|
92
|
+
'graphcore.agent_frontend': ModuleContract(
|
|
93
|
+
('AgentError', 'AgentView', 'Context', 'RenderTooLarge', 'ToolSpec',
|
|
94
|
+
'agent_view', 'operation', 'strategy_tool'),
|
|
95
|
+
'pre_setup',
|
|
96
|
+
),
|
|
97
|
+
'graphcore.agent_frontend.base': ModuleContract(
|
|
98
|
+
('children_section', 'deployment_tools', 'entity_fields', 'entity_summary', 'entity_view',
|
|
99
|
+
'grouped', 'home_view', 'places', 'type_tools', 'view_tools', 'view_view'),
|
|
100
|
+
'pre_setup',
|
|
101
|
+
),
|
|
102
|
+
}
|
graphcore/tests/runs.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Running a payload in a test as a client would."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
async def run(executor, payload, principal, wait=True, callback_channel=None):
|
|
5
|
+
"""`(request, target)` for a succeeded run. A refusal or a failed run
|
|
6
|
+
raises the run's error."""
|
|
7
|
+
return await executor.submit(payload, principal, wait=wait, callback_channel=callback_channel)
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Tests for graphcore.registry.app_discovery."""
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from tempfile import TemporaryDirectory
|
|
4
|
+
from unittest.mock import MagicMock, patch
|
|
5
|
+
|
|
6
|
+
from django.test import TestCase
|
|
7
|
+
|
|
8
|
+
from graphcore.registry.app_discovery import (
|
|
9
|
+
add_in_project_apps_to_path,
|
|
10
|
+
discover_graphcore_apps,
|
|
11
|
+
list_apps_with_provenance,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _write_nested_app(root: Path, name: str) -> None:
|
|
16
|
+
pkg = root / name / "backend" / name
|
|
17
|
+
pkg.mkdir(parents=True)
|
|
18
|
+
(pkg / "__init__.py").write_text("")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class AppsDirScanTests(TestCase):
|
|
22
|
+
def test_scans_shaped_apps_sorted_skips_decoy(self):
|
|
23
|
+
with TemporaryDirectory() as tmp:
|
|
24
|
+
root = Path(tmp)
|
|
25
|
+
for name in ("zeta", "alpha"):
|
|
26
|
+
_write_nested_app(root, name)
|
|
27
|
+
(root / "decoy").mkdir()
|
|
28
|
+
(root / "flat" / "backend").mkdir(parents=True)
|
|
29
|
+
(root / "flat" / "backend" / "__init__.py").write_text("")
|
|
30
|
+
fake_eps = MagicMock()
|
|
31
|
+
fake_eps.select.return_value = []
|
|
32
|
+
with patch("graphcore.registry.app_discovery.entry_points", return_value=fake_eps):
|
|
33
|
+
self.assertEqual(
|
|
34
|
+
["alpha", "zeta"],
|
|
35
|
+
discover_graphcore_apps(root),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def test_missing_or_empty_apps_dir(self):
|
|
39
|
+
fake_eps = MagicMock()
|
|
40
|
+
fake_eps.select.return_value = []
|
|
41
|
+
with patch("graphcore.registry.app_discovery.entry_points", return_value=fake_eps):
|
|
42
|
+
with TemporaryDirectory() as tmp:
|
|
43
|
+
self.assertEqual([], discover_graphcore_apps(Path(tmp) / "nope"))
|
|
44
|
+
self.assertEqual([], discover_graphcore_apps(Path(tmp)))
|
|
45
|
+
|
|
46
|
+
def test_add_in_project_apps_to_path(self):
|
|
47
|
+
import sys
|
|
48
|
+
|
|
49
|
+
with TemporaryDirectory() as tmp:
|
|
50
|
+
root = Path(tmp)
|
|
51
|
+
_write_nested_app(root, "notes")
|
|
52
|
+
backend = str((root / "notes" / "backend").resolve())
|
|
53
|
+
self.assertNotIn(backend, sys.path)
|
|
54
|
+
add_in_project_apps_to_path(root)
|
|
55
|
+
self.assertIn(backend, sys.path)
|
|
56
|
+
sys.path.remove(backend)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class EntryPointTests(TestCase):
|
|
60
|
+
def test_entry_points_precede_scan_and_dedupe(self):
|
|
61
|
+
with TemporaryDirectory() as tmp:
|
|
62
|
+
root = Path(tmp)
|
|
63
|
+
_write_nested_app(root, "localapp")
|
|
64
|
+
_write_nested_app(root, "agents") # same label as entry point → dedupe
|
|
65
|
+
|
|
66
|
+
ep = MagicMock()
|
|
67
|
+
ep.value = "agents"
|
|
68
|
+
ep.dist = MagicMock()
|
|
69
|
+
ep.dist.name = "graphcore-agents"
|
|
70
|
+
fake_eps = MagicMock()
|
|
71
|
+
fake_eps.select.return_value = [ep]
|
|
72
|
+
|
|
73
|
+
with patch("graphcore.registry.app_discovery.entry_points", return_value=fake_eps):
|
|
74
|
+
self.assertEqual(["agents", "localapp"], discover_graphcore_apps(root))
|
|
75
|
+
|
|
76
|
+
ep2 = MagicMock()
|
|
77
|
+
ep2.value = "other"
|
|
78
|
+
ep2.dist = MagicMock()
|
|
79
|
+
ep2.dist.name = "graphcore-other"
|
|
80
|
+
fake_eps.select.return_value = [ep, ep2]
|
|
81
|
+
with patch("graphcore.registry.app_discovery.entry_points", return_value=fake_eps):
|
|
82
|
+
rows = list_apps_with_provenance(root)
|
|
83
|
+
self.assertEqual(
|
|
84
|
+
[
|
|
85
|
+
("agents", "entry point: graphcore-agents"),
|
|
86
|
+
("other", "entry point: graphcore-other"),
|
|
87
|
+
("localapp", "apps/ directory"),
|
|
88
|
+
],
|
|
89
|
+
rows,
|
|
90
|
+
)
|