76 lines
2.6 KiB
Python
76 lines
2.6 KiB
Python
|
|
"""Terminal quick commands API — custom cmd stored without trailing CR."""
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.integration
|
||
|
|
@pytest.mark.asyncio
|
||
|
|
async def test_create_quick_command_stores_trimmed_cmd_without_cr(
|
||
|
|
integration_env, api_client, auth_headers
|
||
|
|
):
|
||
|
|
"""Frontend save uses cmd.trim() — store body only; CR is send-time in execQuickCmd."""
|
||
|
|
name = "verify-enter-fix"
|
||
|
|
cmd_body = "echo __nexus_qc_enter__"
|
||
|
|
|
||
|
|
create = await api_client.post(
|
||
|
|
"/api/terminal/quick-commands",
|
||
|
|
headers=auth_headers,
|
||
|
|
json={"name": name, "cmd": cmd_body},
|
||
|
|
)
|
||
|
|
assert create.status_code == 201, create.text
|
||
|
|
created = create.json()
|
||
|
|
cmd_id = created["id"]
|
||
|
|
assert created["cmd"] == cmd_body
|
||
|
|
assert not created["cmd"].endswith("\r")
|
||
|
|
|
||
|
|
listed = await api_client.get("/api/terminal/quick-commands", headers=auth_headers)
|
||
|
|
assert listed.status_code == 200
|
||
|
|
match = next((c for c in listed.json() if c["id"] == cmd_id), None)
|
||
|
|
assert match is not None
|
||
|
|
assert match["cmd"] == cmd_body
|
||
|
|
|
||
|
|
delete = await api_client.delete(
|
||
|
|
f"/api/terminal/quick-commands/{cmd_id}",
|
||
|
|
headers=auth_headers,
|
||
|
|
)
|
||
|
|
assert delete.status_code == 204
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.integration
|
||
|
|
@pytest.mark.asyncio
|
||
|
|
async def test_reorder_quick_commands_route_not_shadowed_by_id(
|
||
|
|
integration_env, api_client, auth_headers
|
||
|
|
):
|
||
|
|
"""PUT /quick-commands/reorder must not match /quick-commands/{id} (id=reorder → 422)."""
|
||
|
|
ids: list[int] = []
|
||
|
|
for i in range(2):
|
||
|
|
create = await api_client.post(
|
||
|
|
"/api/terminal/quick-commands",
|
||
|
|
headers=auth_headers,
|
||
|
|
json={"name": f"qc-order-{i}", "cmd": f"echo {i}"},
|
||
|
|
)
|
||
|
|
assert create.status_code == 201, create.text
|
||
|
|
ids.append(create.json()["id"])
|
||
|
|
|
||
|
|
listed = await api_client.get("/api/terminal/quick-commands", headers=auth_headers)
|
||
|
|
custom = [c for c in listed.json() if not c["is_builtin"] and c["id"] in ids]
|
||
|
|
assert len(custom) == 2
|
||
|
|
first_id, second_id = custom[0]["id"], custom[1]["id"]
|
||
|
|
|
||
|
|
reorder = await api_client.put(
|
||
|
|
"/api/terminal/quick-commands/reorder",
|
||
|
|
headers=auth_headers,
|
||
|
|
json={"ids": [second_id, first_id]},
|
||
|
|
)
|
||
|
|
assert reorder.status_code == 200, reorder.text
|
||
|
|
items = reorder.json()["items"]
|
||
|
|
custom_after = [c for c in items if not c["is_builtin"] and c["id"] in ids]
|
||
|
|
assert [c["id"] for c in custom_after] == [second_id, first_id]
|
||
|
|
|
||
|
|
for cmd_id in ids:
|
||
|
|
delete = await api_client.delete(
|
||
|
|
f"/api/terminal/quick-commands/{cmd_id}",
|
||
|
|
headers=auth_headers,
|
||
|
|
)
|
||
|
|
assert delete.status_code == 204
|