refactor(delivery): use workspace out as artifact root
Some checks failed
Test Suite / test (3.11) (push) Failing after 1m24s
Test Suite / test (3.12) (push) Failing after 1m46s
Test Suite / test (3.13) (push) Failing after 2m1s

This commit is contained in:
Hua
2026-03-20 09:10:33 +08:00
parent 73af8c574e
commit 9ac73f1e26
13 changed files with 272 additions and 344 deletions

View File

@@ -1,44 +1,23 @@
import os
from pathlib import Path
import pytest
from aiohttp.test_utils import make_mocked_request
from nanobot.gateway.http import create_http_app, get_public_dir
from nanobot.gateway.http import create_http_app
@pytest.mark.asyncio
async def test_gateway_public_route_maps_requests_into_workspace_public(tmp_path) -> None:
public_dir = get_public_dir(tmp_path)
file_path = public_dir / "hello.txt"
file_path.write_text("hello", encoding="utf-8")
async def test_gateway_health_route_exists() -> None:
app = create_http_app()
request = make_mocked_request("GET", "/healthz", app=app)
match = await app.router.resolve(request)
app = create_http_app(tmp_path)
assert match.route.resource.canonical == "/healthz"
@pytest.mark.asyncio
async def test_gateway_public_route_is_not_registered() -> None:
app = create_http_app()
request = make_mocked_request("GET", "/public/hello.txt", app=app)
match = await app.router.resolve(request)
assert match.route.resource.canonical == "/public"
assert match["filename"] == "hello.txt"
assert Path(getattr(match.route.resource, "_directory")) == public_dir
@pytest.mark.asyncio
async def test_gateway_public_route_disables_symlink_following_and_allows_hard_links(tmp_path) -> None:
out_dir = tmp_path / "out"
out_dir.mkdir()
source = out_dir / "shot.png"
source.write_bytes(b"png")
public_dir = get_public_dir(tmp_path) / "qq"
public_dir.mkdir()
published = public_dir / "shot.png"
os.link(source, published)
app = create_http_app(tmp_path)
request = make_mocked_request("GET", "/public/qq/shot.png", app=app)
match = await app.router.resolve(request)
assert os.stat(source).st_ino == os.stat(published).st_ino
assert match.route.resource.canonical == "/public"
assert match["filename"] == "qq/shot.png"
assert getattr(match.route.resource, "_follow_symlinks") is False
assert match.http_exception.status == 404
assert [resource.canonical for resource in app.router.resources()] == ["/healthz"]