updated test file
Browse files- server/__pycache__/__init__.cpython-313.pyc +0 -0
- server/__pycache__/app.cpython-313.pyc +0 -0
- src/__pycache__/__init__.cpython-313.pyc +0 -0
- src/__pycache__/environment.cpython-313.pyc +0 -0
- src/__pycache__/generator.cpython-313.pyc +0 -0
- src/__pycache__/models.cpython-313.pyc +0 -0
- src/environment.py +4 -2
- test_env.py +63 -55
server/__pycache__/__init__.cpython-313.pyc
CHANGED
|
Binary files a/server/__pycache__/__init__.cpython-313.pyc and b/server/__pycache__/__init__.cpython-313.pyc differ
|
|
|
server/__pycache__/app.cpython-313.pyc
CHANGED
|
Binary files a/server/__pycache__/app.cpython-313.pyc and b/server/__pycache__/app.cpython-313.pyc differ
|
|
|
src/__pycache__/__init__.cpython-313.pyc
CHANGED
|
Binary files a/src/__pycache__/__init__.cpython-313.pyc and b/src/__pycache__/__init__.cpython-313.pyc differ
|
|
|
src/__pycache__/environment.cpython-313.pyc
CHANGED
|
Binary files a/src/__pycache__/environment.cpython-313.pyc and b/src/__pycache__/environment.cpython-313.pyc differ
|
|
|
src/__pycache__/generator.cpython-313.pyc
CHANGED
|
Binary files a/src/__pycache__/generator.cpython-313.pyc and b/src/__pycache__/generator.cpython-313.pyc differ
|
|
|
src/__pycache__/models.cpython-313.pyc
CHANGED
|
Binary files a/src/__pycache__/models.cpython-313.pyc and b/src/__pycache__/models.cpython-313.pyc differ
|
|
|
src/environment.py
CHANGED
|
@@ -96,9 +96,9 @@ class AdPolicyEnvironment(Environment):
|
|
| 96 |
return self._get_obs("Must call query_regulations first.", -0.2, False)
|
| 97 |
|
| 98 |
self.step_count += 1
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
| 102 |
response = self._execute_action(act_type)
|
| 103 |
|
| 104 |
# 4. Update state
|
|
@@ -106,7 +106,9 @@ class AdPolicyEnvironment(Environment):
|
|
| 106 |
self.api_failed = True
|
| 107 |
self.last_failed_action = act_type
|
| 108 |
self.last_error = response["error"]
|
|
|
|
| 109 |
else:
|
|
|
|
| 110 |
if act_type == self.last_failed_action:
|
| 111 |
self.api_recovered = True
|
| 112 |
self.last_error = None
|
|
|
|
| 96 |
return self._get_obs("Must call query_regulations first.", -0.2, False)
|
| 97 |
|
| 98 |
self.step_count += 1
|
| 99 |
+
|
| 100 |
|
| 101 |
+
# 3. Execute action
|
| 102 |
response = self._execute_action(act_type)
|
| 103 |
|
| 104 |
# 4. Update state
|
|
|
|
| 106 |
self.api_failed = True
|
| 107 |
self.last_failed_action = act_type
|
| 108 |
self.last_error = response["error"]
|
| 109 |
+
# Notice we DO NOT add to self.actions_taken here
|
| 110 |
else:
|
| 111 |
+
self.actions_taken.add(act_type) # <-- ADDED HERE: Only register successful actions
|
| 112 |
if act_type == self.last_failed_action:
|
| 113 |
self.api_recovered = True
|
| 114 |
self.last_error = None
|
test_env.py
CHANGED
|
@@ -1,57 +1,65 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
def run_test():
|
| 23 |
-
print("--- 🔄 Testing /reset ---")
|
| 24 |
-
reset_data = safe_post("reset")
|
| 25 |
-
if not reset_data: return
|
| 26 |
-
|
| 27 |
-
obs = reset_data.get('observation', reset_data)
|
| 28 |
-
print(f"Ad Loaded: {obs.get('headline', 'N/A')}\n")
|
| 29 |
-
|
| 30 |
-
print("--- 🔍 Testing 'analyze_image' Tool ---")
|
| 31 |
-
# Payload must be wrapped in 'action' for OpenEnv 2026
|
| 32 |
-
step1_payload = {
|
| 33 |
-
"action": {
|
| 34 |
-
"action_type": "analyze_image",
|
| 35 |
-
"reasoning": "Standard adversarial check."
|
| 36 |
-
}
|
| 37 |
-
}
|
| 38 |
-
s1_data = safe_post("step", step1_payload)
|
| 39 |
-
if s1_data:
|
| 40 |
-
s1_obs = s1_data.get('observation', s1_data)
|
| 41 |
-
print(f" {s1_obs.get('status_message', 'N/A')}\n")
|
| 42 |
-
|
| 43 |
-
print("--- ✅ Testing Final Decision ---")
|
| 44 |
-
step2_payload = {
|
| 45 |
-
"action": {
|
| 46 |
-
"action_type": "reject",
|
| 47 |
-
"reasoning": "Detected policy violation."
|
| 48 |
-
}
|
| 49 |
-
}
|
| 50 |
-
s2_data = safe_post("step", step2_payload)
|
| 51 |
-
if s2_data:
|
| 52 |
-
reward = s2_data.get('reward', 0.0)
|
| 53 |
-
done = s2_data.get('done', s2_data.get('terminal', False))
|
| 54 |
-
print(f"Final Reward: {reward} | Done: {done}")
|
| 55 |
|
| 56 |
if __name__ == "__main__":
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from src.environment import AdPolicyEnvironment
|
| 2 |
+
from src.models import AdAction
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def run_episode(task_id, actions):
|
| 6 |
+
env = AdPolicyEnvironment()
|
| 7 |
+
obs = env.reset(task_id=task_id)
|
| 8 |
+
|
| 9 |
+
for act in actions:
|
| 10 |
+
obs = env.step(
|
| 11 |
+
AdAction(
|
| 12 |
+
action_type=act,
|
| 13 |
+
reasoning="smoke test",
|
| 14 |
+
violation_category="NONE",
|
| 15 |
+
)
|
| 16 |
+
)
|
| 17 |
+
if obs.done:
|
| 18 |
+
break
|
| 19 |
+
|
| 20 |
+
return env, obs
|
| 21 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
if __name__ == "__main__":
|
| 24 |
+
env1, obs1 = run_episode(
|
| 25 |
+
"task_1_healthcare",
|
| 26 |
+
[
|
| 27 |
+
"query_regulations",
|
| 28 |
+
"analyze_image",
|
| 29 |
+
"check_advertiser_history",
|
| 30 |
+
"submit_audit",
|
| 31 |
+
"reject",
|
| 32 |
+
],
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
assert len(env1.trace) >= 4, f"Trace too short: {len(env1.trace)}"
|
| 36 |
+
assert isinstance(env1.total_reward, float), "Reward is not numeric"
|
| 37 |
+
assert all("summary" in t["result"] for t in env1.trace), "Bad trace format"
|
| 38 |
+
|
| 39 |
+
env2, obs2 = run_episode(
|
| 40 |
+
"task_10_failure",
|
| 41 |
+
[
|
| 42 |
+
"query_regulations",
|
| 43 |
+
"query_regulations",
|
| 44 |
+
"check_advertiser_history",
|
| 45 |
+
"submit_audit",
|
| 46 |
+
"reject",
|
| 47 |
+
],
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
assert len(env2.trace) >= 2, f"Failure trace too short: {len(env2.trace)}"
|
| 51 |
+
assert any("API failure" in t["result"]["summary"] for t in env2.trace), (
|
| 52 |
+
"Failure case did not trigger"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
print("STEP 7 SMOKE TEST PASSED")
|
| 56 |
+
print("\nTRACE 1:")
|
| 57 |
+
for row in env1.trace:
|
| 58 |
+
print(row)
|
| 59 |
+
|
| 60 |
+
print("\nTRACE 2:")
|
| 61 |
+
for row in env2.trace:
|
| 62 |
+
print(row)
|
| 63 |
+
|
| 64 |
+
print("\nTOTAL REWARD 1:", env1.total_reward)
|
| 65 |
+
print("TOTAL REWARD 2:", env2.total_reward)
|