Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

2.1 KB
Raw Blame
"""Check the anonymous Swagger homepage through the deployed stage's ingress."""
import os
from pathlib import Path
from urllib.parse import urlsplit

import pytest
import yaml
from playwright.sync_api import expect, sync_playwright


@pytest.mark.smoke
def test_swagger_homepage_shows_applets_with_platform_operations():
    contract = Path(__file__).resolve().parents[3] / "openapi/apps.openapi.yaml"
    apps = yaml.safe_load(contract.read_text(encoding="utf-8"))
    prefix = apps["servers"][0]["url"]
    expected = {
        (prefix + path, method, operation["operationId"])
        for path, item in apps["paths"].items()
        for method, operation in item.items()
        if isinstance(operation, dict) and "operationId" in operation
    }

    with sync_playwright() as playwright:
        browser = playwright.chromium.launch(channel="chrome")
        page = browser.new_page()
        definition_requests = []

        def record_request(request):
            path = urlsplit(request.url).path
            if path.endswith(("/api-json", "/api-yaml", "/apps.openapi.yaml")):
                definition_requests.append(path)

        page.on("request", record_request)
        response = page.goto(os.environ["API_URL"])
        assert response.status == 200, f"Swagger homepage returned HTTP {response.status}"
        for tag in ("box", "volumes", "Applet"):
            expect(page.locator(f'h3[data-tag="{tag}"]')).to_be_visible()
        expect(page.locator(".topbar .download-url-wrapper")).to_be_hidden()
        expect(page.locator("#operations-Applet-listApps")).to_contain_text("/api/v1/{organizationId}/apps")
        assert not definition_requests, f"Swagger fetched separate definitions: {definition_requests}"

        paths = page.evaluate("window.ui.specSelectors.specJson().get('paths').toJS()")
        published = {
            (path, method, operation["operationId"])
            for path, item in paths.items()
            for method, operation in item.items()
            if isinstance(operation, dict) and "Applet" in operation.get("tags", [])
        }
        assert published == expected