File size: 1,713 Bytes
3ca7119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Synth tests for the harness-only stack (local app.py)."""

import sys
from pathlib import Path

CDK_DIR = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(CDK_DIR))


def test_harness_local_stack_synth():
    from aws_cdk import App, Environment
    from aws_cdk.assertions import Template
    from harness_local_stack import HarnessLocalStack

    app = App()
    stack = HarnessLocalStack(
        app,
        "DocRedactionHarnessLocal",
        env=Environment(account="123456789012", region="eu-west-2"),
    )
    template = Template.from_stack(stack)

    template.resource_count_is("AWS::BedrockAgentCore::Harness", 1)
    template.resource_count_is("AWS::S3::Bucket", 2)
    template.resource_count_is("Custom::CDKBucketDeployment", 1)
    template.resource_count_is("AWS::IAM::ManagedPolicy", 1)

    policies = template.find_resources("AWS::IAM::ManagedPolicy")
    doc = next(iter(policies.values()))["Properties"]["PolicyDocument"]
    actions = {
        a
        for stmt in doc["Statement"]
        for a in (
            [stmt["Action"]] if isinstance(stmt["Action"], str) else stmt["Action"]
        )
    }
    assert "bedrock-agentcore:InvokeHarness" in actions
    assert "bedrock-agentcore:InvokeAgentRuntime" in actions
    assert "s3:PutObject" in actions

    template.has_output("RedactionHarnessArn", {})
    template.has_output("LocalAppConfigSnippet", {})


def test_harness_local_config_default_model():
    import harness_local_config as cfg

    assert (
        cfg.default_harness_model_id("anthropic.claude-sonnet-5", "eu-west-2")
        == "anthropic.claude-sonnet-5"
    )
    assert cfg.default_harness_model_id("", "eu-west-2") == "anthropic.claude-sonnet-5"