()
| 58 | # ============================================================================ |
| 59 | |
| 60 | def main(): |
| 61 | print("=" * 70) |
| 62 | print("generate_object Integration Test (Python SDK + MiniMax)") |
| 63 | print("=" * 70) |
| 64 | |
| 65 | from a3s_code import Agent, SessionOptions, PermissionPolicy |
| 66 | |
| 67 | config_content = load_config() |
| 68 | workspace = tempfile.mkdtemp(prefix="a3s-genobj-py-") |
| 69 | print(f"Workspace: {workspace}\n") |
| 70 | |
| 71 | agent = Agent.create(config_content) |
| 72 | policy = PermissionPolicy(default_decision="allow") |
| 73 | opts = SessionOptions() |
| 74 | opts.permission_policy = policy |
| 75 | session = agent.session(workspace, opts) |
| 76 | |
| 77 | # ── Test 1: Simple extraction ──────────────────────────────────────────── |
| 78 | |
| 79 | def test_extract_person(): |
| 80 | result = session.tool("generate_object", { |
| 81 | "schema": { |
| 82 | "type": "object", |
| 83 | "required": ["name", "age", "city"], |
| 84 | "properties": { |
| 85 | "name": {"type": "string"}, |
| 86 | "age": {"type": "integer"}, |
| 87 | "city": {"type": "string"}, |
| 88 | }, |
| 89 | }, |
| 90 | "prompt": 'Extract: "Bob Zhang is 32 years old and lives in Beijing."', |
| 91 | "schema_name": "person", |
| 92 | "mode": "tool", |
| 93 | }) |
| 94 | assert result.exit_code == 0, f"Tool failed: {result.output}" |
| 95 | parsed = json.loads(result.output) |
| 96 | obj = parsed["object"] |
| 97 | assert obj["name"].lower() == "bob zhang", f"name: {obj['name']}" |
| 98 | assert obj["age"] == 32, f"age: {obj['age']}" |
| 99 | assert "beijing" in obj["city"].lower(), f"city: {obj['city']}" |
| 100 | print(f" Result: {json.dumps(obj)}") |
| 101 | |
| 102 | run_test("generate_object: extract person info", test_extract_person) |
| 103 | |
| 104 | # ── Test 2: Enum classification ────────────────────────────────────────── |
| 105 | |
| 106 | def test_sentiment(): |
| 107 | result = session.tool("generate_object", { |
| 108 | "schema": { |
| 109 | "type": "object", |
| 110 | "required": ["sentiment"], |
| 111 | "properties": { |
| 112 | "sentiment": {"type": "string", "enum": ["positive", "negative", "neutral"]}, |
| 113 | }, |
| 114 | }, |
| 115 | "prompt": 'Classify: "I absolutely love this new feature, it works perfectly!"', |
| 116 | "schema_name": "sentiment", |
| 117 | }) |
no test coverage detected