Add governed automation contracts
This commit is contained in:
75
tests/test_automation_contract.py
Normal file
75
tests/test_automation_contract.py
Normal file
@@ -0,0 +1,75 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from govoplan_core.core.automation import (
|
||||
CAPABILITY_AUTH_AUTOMATION_PRINCIPAL_PROVIDER,
|
||||
AutomationInvocation,
|
||||
AutomationPrincipalProvider,
|
||||
AutomationPrincipalRequest,
|
||||
AutomationPrincipalResolution,
|
||||
automation_principal_provider,
|
||||
)
|
||||
from govoplan_core.core.modules import ModuleContext, ModuleManifest
|
||||
from govoplan_core.core.registry import PlatformRegistry
|
||||
|
||||
|
||||
class _Provider:
|
||||
def resolve_automation_principal(self, session, *, request):
|
||||
del session
|
||||
return AutomationPrincipalResolution(
|
||||
allowed=True,
|
||||
principal={"account_id": request.account_id},
|
||||
granted_scopes=request.grant_scopes,
|
||||
)
|
||||
|
||||
|
||||
class AutomationContractTests(unittest.TestCase):
|
||||
def test_invocation_records_stable_trigger_provenance(self) -> None:
|
||||
invocation = AutomationInvocation(
|
||||
kind="event",
|
||||
trigger_ref="dataflow-trigger:1",
|
||||
event_id="event-1",
|
||||
event_type="files.uploaded",
|
||||
)
|
||||
|
||||
self.assertEqual("event", invocation.kind)
|
||||
self.assertEqual("event-1", invocation.event_id)
|
||||
|
||||
def test_principal_provider_is_runtime_resolved(self) -> None:
|
||||
provider = _Provider()
|
||||
self.assertIsInstance(provider, AutomationPrincipalProvider)
|
||||
registry = PlatformRegistry()
|
||||
registry.register(
|
||||
ModuleManifest(
|
||||
id="automation_contract_test",
|
||||
name="Automation contract test",
|
||||
version="test",
|
||||
capability_factories={
|
||||
CAPABILITY_AUTH_AUTOMATION_PRINCIPAL_PROVIDER: (
|
||||
lambda context: provider
|
||||
),
|
||||
},
|
||||
)
|
||||
)
|
||||
registry.configure_capability_context(
|
||||
ModuleContext(registry=registry, settings=object())
|
||||
)
|
||||
|
||||
self.assertIs(provider, automation_principal_provider(registry))
|
||||
result = provider.resolve_automation_principal(
|
||||
object(),
|
||||
request=AutomationPrincipalRequest(
|
||||
tenant_id="tenant-1",
|
||||
account_id="account-1",
|
||||
membership_id="membership-1",
|
||||
authorization_ref="trigger:1",
|
||||
grant_scopes=("dataflow:pipeline:run",),
|
||||
),
|
||||
)
|
||||
self.assertTrue(result.allowed)
|
||||
self.assertEqual(("dataflow:pipeline:run",), result.granted_scopes)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user