Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee03089bcf | ||
|
|
341d276f18 | ||
|
|
2c8c98a11f |
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
placeholder
|
||||
@@ -0,0 +1,112 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from aios_chatgpt_bridge_v2 import OPERATION_REQUIRED_FIELDS
|
||||
from aios_chatgpt_bridge_v2_server import BridgeHandler, _HTTPError, ROUTES
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
OPENAPI = ROOT / "docs" / "gitops" / "openapi-chatgpt-actions.yaml"
|
||||
REQUIRED = {
|
||||
"task_id",
|
||||
"repository",
|
||||
"base_oid",
|
||||
"target_branch",
|
||||
"risk",
|
||||
"description",
|
||||
"idempotency_key",
|
||||
}
|
||||
OPTIONAL_CONTINUATION = {
|
||||
"expected_branch_oid",
|
||||
"generation",
|
||||
"parent_task_id",
|
||||
"parent_job_id",
|
||||
"priority",
|
||||
}
|
||||
|
||||
|
||||
def _document():
|
||||
return yaml.safe_load(OPENAPI.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def _create_request():
|
||||
return {
|
||||
"task_id": "continuation-contract-test",
|
||||
"repository": "aios/aios",
|
||||
"base_oid": "a" * 40,
|
||||
"target_branch": "agent/continuation-contract-test",
|
||||
"risk": "engineering",
|
||||
"description": "contract test",
|
||||
"idempotency_key": "continuation-contract-test-v1",
|
||||
}
|
||||
|
||||
|
||||
def test_create_governed_task_openapi_contract_exposes_continuation_fields():
|
||||
document = _document()
|
||||
operation = document["paths"]["/createGovernedTask"]["post"]
|
||||
schema_ref = operation["requestBody"]["content"]["application/json"]["schema"]
|
||||
schema = document["components"]["schemas"][schema_ref["$ref"].rsplit("/", 1)[-1]]
|
||||
|
||||
assert operation["operationId"] == "createGovernedTask"
|
||||
assert operation["security"] == [{"bearerAuth": []}]
|
||||
assert operation["x-openai-isConsequential"] is True
|
||||
assert set(schema["required"]) == REQUIRED
|
||||
assert schema["additionalProperties"] is False
|
||||
assert OPTIONAL_CONTINUATION <= set(schema["properties"])
|
||||
assert not OPTIONAL_CONTINUATION.intersection(schema["required"])
|
||||
assert schema["properties"]["repository"]["const"] == "aios/aios"
|
||||
assert schema["properties"]["generation"]["minimum"] == 1
|
||||
assert schema["properties"]["priority"] == {
|
||||
"type": "integer",
|
||||
"minimum": -100,
|
||||
"maximum": 100,
|
||||
}
|
||||
|
||||
|
||||
def test_create_governed_task_route_and_required_fields_match_bridge():
|
||||
assert ROUTES["/v2/governed-task"] == "createGovernedTask"
|
||||
assert tuple(OPERATION_REQUIRED_FIELDS["createGovernedTask"]) == (
|
||||
"task_id",
|
||||
"repository",
|
||||
"base_oid",
|
||||
"target_branch",
|
||||
"risk",
|
||||
"description",
|
||||
"idempotency_key",
|
||||
)
|
||||
|
||||
|
||||
def test_bridge_execution_plan_and_envelope_routes_remain_exposed():
|
||||
assert ROUTES["/v2/execution-envelope"] == "projectOnlineAgentExecution"
|
||||
assert ROUTES["/v2/execution-plan"] == "registerOnlineAgentExecutionPlan"
|
||||
|
||||
|
||||
def test_bridge_allowlist_accepts_parent_pair_and_priority_but_rejects_unknown():
|
||||
handler = BridgeHandler.__new__(BridgeHandler)
|
||||
body = _create_request()
|
||||
body.update(
|
||||
{
|
||||
"expected_branch_oid": "a" * 40,
|
||||
"generation": 2,
|
||||
"parent_task_id": "continuation-parent-test",
|
||||
"parent_job_id": "job-continuation-parent-test",
|
||||
"priority": 100,
|
||||
}
|
||||
)
|
||||
handler._allowed("createGovernedTask", body)
|
||||
|
||||
invalid = dict(body)
|
||||
invalid["unexpected_field"] = True
|
||||
with pytest.raises(_HTTPError, match="UNKNOWN_FIELDS"):
|
||||
handler._allowed("createGovernedTask", invalid)
|
||||
|
||||
|
||||
def test_openapi_does_not_add_credential_fields_to_create_contract():
|
||||
document = _document()
|
||||
properties = set(
|
||||
document["components"]["schemas"]["CreateGovernedTaskRequest"]["properties"]
|
||||
)
|
||||
forbidden = {"authorization", "bearer", "token", "credential", "secret", "password", "api_key"}
|
||||
assert properties.isdisjoint(forbidden)
|
||||
Reference in New Issue
Block a user