-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_agent_proposal_functional_v0.py
More file actions
184 lines (150 loc) · 6.42 KB
/
Copy pathtest_agent_proposal_functional_v0.py
File metadata and controls
184 lines (150 loc) · 6.42 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"""Deterministic, no-network functional smoke for the Agent Proposal Gateway.
This exercises the full existing pipeline end to end with an in-process mock
provider only:
mock provider output
-> Agent Proposal Gateway
-> DSM validation
-> Agent Memory audit write
-> explain decision
-> markdown audit
It asserts the pipeline *functions* (status, hashes, audit, explain, markdown).
It does not assert business truth, repeatability, or reliability. No live
provider, no network, no new API, and no change to validation behavior.
"""
from __future__ import annotations
import json
from pathlib import Path
from eval.skill_retrieval_v0 import load_records
from tools.agent_proposal_gateway_v0 import (
ACCEPTED_FOR_AUDIT,
REJECTED_BY_VALIDATOR,
run_agent_proposal_gateway,
)
REPO_ROOT = Path(__file__).resolve().parents[1]
RECORDS_PATH = REPO_ROOT / "datasets" / "dsm_reasoning_v0" / "records.jsonl"
class _ConformantMockProvider:
"""In-process provider returning a full-contract, honest structured proposal."""
metadata = {
"kind": "mock",
"name": "functional-conformant",
"model": "functional-no-network",
"base_url_label": "local-test",
}
def propose(self, context: dict) -> dict:
required = list(context["required_checks"])
structured = {
"proposal": "Audit-ready scaffold that accounts for each required check.",
"model_proposed_action": (
"Send to audit; do not finalize a business outcome."
),
"claimed_checks": required,
"claimed_check_coverage": [
{
"check_id": check,
"coverage": (
f"The proposal accounts for {check} without claiming truth "
"or final business authority."
),
}
for check in required
],
"limitations": [
"Validated for form and honesty only, not factual truth.",
"Candidate rules remain candidate unless DSM marks them validated.",
],
"candidate_rule_handling": "Candidate rules remain candidate.",
"truth_claim": False,
}
return {
"raw_output": json.dumps(structured, sort_keys=True),
"structured_output": structured,
}
class _EchoOnlyMockProvider:
"""In-process provider that echoes check labels without substantive coverage."""
metadata = {
"kind": "mock",
"name": "functional-echo-only",
"model": "functional-no-network",
"base_url_label": "local-test",
}
def propose(self, context: dict) -> dict:
structured = {
"proposal": "Echo-only proposal.",
"claimed_checks": [
{"check_id": check, "coverage": check}
for check in context["required_checks"]
],
"limitations": ["Labels were echoed without substantive coverage."],
"candidate_rule_handling": "Candidate rules remain candidate.",
"truth_claim": False,
}
return {
"raw_output": json.dumps(structured, sort_keys=True),
"structured_output": structured,
}
def _run(provider, tmp_path: Path, name: str) -> dict:
return run_agent_proposal_gateway(
load_records(RECORDS_PATH),
provider=provider,
data_dir=tmp_path / name,
user_id="mohamed",
domain="omari_ai",
skill_id="omari_ai.lead_capture_reliability",
task_type="prioritization_decision",
known_inputs={
"customer_name": "Before",
"interruption_detected": True,
},
)
def _codes(issues: list[dict]) -> set[str]:
return {issue["code"] for issue in issues}
def test_functional_accepted_path_runs_gateway_validation_audit_explain_markdown(
tmp_path,
):
result = _run(_ConformantMockProvider(), tmp_path, "accepted")
context = result["context"]
proposal = result["proposal"]
validation = result["validation"]
persistence = result["persistence"]
markdown = persistence["markdown"]
# Validation decided accept with no warnings or rejections.
assert validation["status"] == ACCEPTED_FOR_AUDIT
assert validation["warnings"] == []
assert validation["rejections"] == []
assert validation["model_proposed"] is True
# Hashes are present across context and wrapped proposal.
assert context["input_context_hash"].startswith("v1:")
assert proposal["input_context_hash"] == context["input_context_hash"]
assert proposal["raw_output_hash"].startswith("v1:")
# Provider metadata is carried through, untrusted but recorded.
assert proposal["provider"] == _ConformantMockProvider.metadata
assert proposal["agent_supplied_status"] is None
# Agent Memory audit was written and is explainable.
assert persistence["decision_hash"].startswith("v1:")
assert persistence["validation_status"] == ACCEPTED_FOR_AUDIT
assert persistence["model_proposed"] is True
assert persistence["explain"]["status"] == "ok"
# Markdown audit was produced with the expected, honest framing.
assert "# Agent Memory Audit Report" in markdown
assert ACCEPTED_FOR_AUDIT in markdown
assert "Provider metadata" in markdown
assert "raw_output_hash" in markdown
assert '"business_decision":"not_produced"' in markdown
# Candidate content stays candidate; nothing was auto-promoted.
assert "promoted_candidate_rules" not in proposal["structured_output"]
assert "remains candidate" in markdown
def test_functional_rejected_path_still_produces_auditable_explainable_record(
tmp_path,
):
# A small negative case: echo-only output is rejected, yet the audit trail
# and explanation are still produced (rejection is auditable, not silent).
result = _run(_EchoOnlyMockProvider(), tmp_path, "rejected")
validation = result["validation"]
persistence = result["persistence"]
assert validation["status"] == REJECTED_BY_VALIDATOR
assert "required_check_not_covered_or_surfaced" in _codes(validation["rejections"])
# Audit still produced and still explainable on rejection.
assert persistence["decision_hash"].startswith("v1:")
assert persistence["validation_status"] == REJECTED_BY_VALIDATOR
assert persistence["explain"]["status"] == "ok"
assert "# Agent Memory Audit Report" in persistence["markdown"]