TestDiffReadOnlyToolThatEgressed: a read-only tool whose runtime opened a network connection violates its contract even though network is benign for bash -- the finding is CONDITIONAL on the declared contract, which is the core differentiator from a global policy rule.
(t *testing.T)
| 115 | // bash -- the finding is CONDITIONAL on the declared contract, which is the core |
| 116 | // differentiator from a global policy rule. |
| 117 | func TestDiffReadOnlyToolThatEgressed(t *testing.T) { |
| 118 | contracts := []IntentContract{{ |
| 119 | ID: "contract/tc3", Kind: ContractToolCall, ScopeAgent: "main", ToolCallID: "tc3", |
| 120 | Operation: "file_read", Profile: profileFor(profiles(), "file_read"), Confidence: 0.5, |
| 121 | }} |
| 122 | effects := []RuntimeEffect{ |
| 123 | {Kind: EffectNetworkConnect, Target: "1.2.3.4", AgentID: "main", ToolCallID: "tc3", EventID: "e10", Confidence: 1}, |
| 124 | } |
| 125 | diffs := Diff(contracts, effects) |
| 126 | if _, ok := findDiff(diffs, func(d IntentRuntimeDiff) bool { return d.Status == StatusMismatch }); !ok { |
| 127 | t.Fatalf("read-only tool that egressed must be a mismatch, got %+v", diffs) |
| 128 | } |
| 129 | // And the SAME effect under a bash/exec contract is allowed -> no mismatch. |
| 130 | contracts[0].Operation = "exec" |
| 131 | contracts[0].Profile = profileFor(profiles(), "exec") |
| 132 | if _, ok := findDiff(Diff(contracts, effects), func(d IntentRuntimeDiff) bool { return d.Status == StatusMismatch }); ok { |
| 133 | t.Fatal("network egress under a bash/exec contract is permitted; must not be a mismatch") |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | func containsKind(ks []EffectKind, want EffectKind) bool { |
| 138 | for _, k := range ks { |
nothing calls this directly
no test coverage detected