Files
cleveragents-core/features/acms_context_policy_loader.feature
2026-06-17 23:15:50 -04:00

325 lines
11 KiB
Gherkin

Feature: ACMS Context Policy Configuration Loader
As a developer
I want to load and validate context policy configurations from YAML/TOML files
So that context policies can be flexibly configured per view
Background:
Given I have a context policy configuration loader
Scenario: Load valid YAML configuration
Given I have a YAML configuration file with:
"""
view_name: test_view
default_priority_weight: 1.5
default_budget: 1000
policies:
- name: policy1
description: Test policy
priority_weight: 2.0
budget_override: 500
enabled: true
scopes:
- name: file_type
value: python
"""
When I load the configuration from the YAML file
Then the configuration should have view_name "test_view"
And the configuration should have 1 policy
And the first policy should have name "policy1"
And the first policy should have priority_weight 2.0
And the first policy should have budget_override 500
Scenario: Load valid TOML configuration
Given I have a TOML configuration file with:
"""
view_name = "test_view"
default_priority_weight = 1.5
default_budget = 1000
[[policies]]
name = "policy1"
description = "Test policy"
priority_weight = 2.0
budget_override = 500
enabled = true
[[policies.scopes]]
name = "file_type"
value = "python"
"""
When I load the configuration from the TOML file
Then the configuration should have view_name "test_view"
And the configuration should have 1 policy
Scenario: Validate schema - missing required fields
Given I have a YAML configuration file with:
"""
policies:
- description: Missing name field
"""
When I try to load the configuration from the YAML file
Then I should get a validation error about missing name field
Scenario: Validate schema - invalid policy type
Given I have a YAML configuration file with:
"""
policies:
- "invalid_policy_string"
"""
When I try to load the configuration from the YAML file
Then I should get a validation error about policy type
Scenario: Validate schema - invalid numeric fields
Given I have a YAML configuration file with:
"""
default_priority_weight: "not_a_number"
policies: []
"""
When I try to load the configuration from the YAML file
Then I should get a validation error about numeric field
Scenario: Apply per-view policy with scope rules
Given I have a context policy configuration with:
| view_name | test_view |
| policies | 1 |
And the policy has scope rules:
| name | value |
| file_type | python |
When I apply the policy to context with file_type "python"
Then the policy should match the context
Scenario: Apply per-view policy with priority weights
Given I have a context policy configuration with multiple policies
And loader policy1 has priority_weight 1.0
And loader policy2 has priority_weight 2.0
When I assemble context with both policies
Then policy2 should be applied before policy1
Scenario: Apply per-view policy with budget overrides
Given I have a context policy configuration with:
| view_name | test_view |
| policies | 1 |
And the policy has budget_override 500
When I apply the policy to context
Then the assembled context should have budget 500
Scenario: Load configuration from non-existent file
Given I have a configuration file path that does not exist
When I try to load the configuration from the file
Then I should get a FileNotFoundError
Scenario: Load configuration with unsupported format
Given I have a configuration file with unsupported format ".json"
When I try to load the configuration from the file
Then I should get a ValueError about unsupported format
Scenario: Load configuration with registered extension but no loader branch
Given I have a configuration file with format ".json" temporarily registered
When I try to load the configuration from the file
Then I should get a ValueError about unsupported format
Scenario: Load configuration from string - YAML
Given I have a YAML configuration string:
"""
view_name: string_view
policies:
- name: policy1
"""
When I load the configuration from the YAML string
Then the configuration should have view_name "string_view"
Scenario: Load configuration from string - TOML
Given I have a TOML configuration string:
"""
view_name = "string_view"
[[policies]]
name = "policy1"
"""
When I load the configuration from the TOML string
Then the configuration should have view_name "string_view"
Scenario: Multiple scopes in a policy
Given I have a context policy configuration with:
| view_name | test_view |
| policies | 1 |
And the policy has multiple scope rules:
| name | value |
| file_type | python |
| path | src |
When I apply the policy to context with multiple scopes: file_type "python" path "src"
Then the policy should match the context
Scenario: Policy with list values in scope
Given I have a context policy configuration with:
| view_name | test_view |
| policies | 1 |
And the policy has scope with name "file_type" and values ["python", "javascript"]
When I apply the policy to context with file_type "python"
Then the policy should match the context
Scenario: Disabled policy should not be applied
Given I have a context policy configuration with:
| view_name | test_view |
| policies | 1 |
And the policy is disabled
When I assemble context
Then the policy should not be applied
Scenario: Policy metadata is preserved
Given I have a context policy configuration with:
| view_name | test_view |
| policies | 1 |
And the policy has metadata:
| key1 | value1 |
| key2 | value2 |
When I apply the policy to context
Then the assembled context should include the policy metadata
Scenario: Scope does not match when context key is missing
Given I have a context policy configuration with:
| view_name | test_view |
| policies | 1 |
And the policy has scope rules:
| name | value |
| file_type | python |
When I apply the policy to context without file_type
Then the policy should not match the context
Scenario: Scope list matches one context list value
Given I have a context policy configuration with:
| view_name | test_view |
| policies | 1 |
And the policy has scope with name "tags" and values ["backend", "api"]
When I apply the policy to context with tags ["frontend", "api"]
Then the policy should match the context
Scenario: Loader rejects empty YAML configuration
Given I have a YAML configuration file with:
"""
[]
"""
When I try to load the configuration from the YAML file
Then I should get a validation error about dictionary configuration
Scenario: Loader rejects unknown top-level fields
Given I have a YAML configuration file with:
"""
view_name: test_view
unexpected: true
policies: []
"""
When I try to load the configuration from the YAML file
Then I should get a validation error about unknown field
Scenario: Loader rejects invalid scopes list
Given I have a YAML configuration file with:
"""
policies:
- name: policy1
scopes: invalid
"""
When I try to load the configuration from the YAML file
Then I should get a validation error about scopes list
Scenario: Loader rejects invalid policies list
Given I have a YAML configuration file with:
"""
policies: invalid
"""
When I try to load the configuration from the YAML file
Then I should get a validation error about policies list
Scenario: Loader rejects invalid scope type
Given I have a YAML configuration file with:
"""
policies:
- name: policy1
scopes:
- invalid
"""
When I try to load the configuration from the YAML file
Then I should get a validation error about scope type
Scenario: Loader rejects scope missing name
Given I have a YAML configuration file with:
"""
policies:
- name: policy1
scopes:
- value: python
"""
When I try to load the configuration from the YAML file
Then I should get a validation error about missing name field
Scenario: Loader rejects scope missing value
Given I have a YAML configuration file with:
"""
policies:
- name: policy1
scopes:
- name: file_type
"""
When I try to load the configuration from the YAML file
Then I should get a validation error about scope value
Scenario: Direct policy parser rejects non-dictionary policy
When I parse an invalid non-dictionary policy directly
Then I should get a validation error about policy type
Scenario: Direct schema validator rejects non-dictionary configuration
When I validate a non-dictionary configuration directly
Then I should get a validation error about dictionary configuration
Scenario: Direct policy parser rejects missing name
When I parse a policy missing name directly
Then I should get a validation error about missing name field
Scenario: Direct scope parser rejects non-dictionary scope
When I parse an invalid non-dictionary scope directly
Then I should get a validation error about scope type
Scenario: Direct scope parser rejects missing name
When I parse a scope missing name directly
Then I should get a validation error about missing name field
Scenario: Direct scope parser rejects missing value
When I parse a scope missing value directly
Then I should get a validation error about scope value
Scenario: Direct scope parser accepts a valid scope
When I parse a valid scope directly
Then the parsed scope should have name "file_type"
Scenario: String loader rejects non-dictionary YAML
Given I have a YAML configuration string:
"""
[]
"""
When I load the configuration from the YAML string
Then I should get a validation error about dictionary configuration
Scenario: String loader rejects unsupported format
Given I have a YAML configuration string:
"""
policies: []
"""
When I try to load the configuration string as "json"
Then I should get a ValueError about unsupported format
Scenario: String loader rejects registered format with no parser branch
Given I have a YAML configuration string:
"""
policies: []
"""
When I try to load the configuration string as temporarily registered "json"
Then I should get a ValueError about unsupported format
Scenario: Loader rejects invalid default budget
Given I have a YAML configuration file with:
"""
default_budget: invalid
policies: []
"""
When I try to load the configuration from the YAML file
Then I should get a validation error about numeric field