mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 20:53:15 +00:00
Applies the plan's C5 step: git mv every test per the domain-reorg
move-map (movemap-m50.txt) into tests/{agent,analyzer,auth,dashboard,
github,middleware,models,reviewer,sandbox,slack,tools,webhooks}/, plus
the 13 fork-only placements from the scoping report §2c (Atlassian
webhook tests -> tests/webhooks/, test_atlassian_connect.py and
test_auth_error_leak.py -> tests/auth/, jira/confluence util tests ->
tests/tools/, test_repo_binding_isolation.py -> tests/sandbox/,
bot-identity/autofix tests -> tests/github/).
Path-only move: the only content edits are parents[1] -> parents[2]
fixes in test_e2b_integration.py and test_daytona_integration.py,
required because their __file__-relative ROOT path gained one more
directory level in the move.
Monkeypatch retargets for these files were already completed in C4;
none remained outstanding here.
81 lines
2.5 KiB
Python
81 lines
2.5 KiB
Python
"""Tests for the Slack account-link prompt."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _jwt_secret(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setenv("DASHBOARD_JWT_SECRET", "test-secret")
|
|
|
|
|
|
def test_account_link_prompt_posts_generic_token_free_link(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
"""The prompt posts a plain settings link in the thread — no per-user token."""
|
|
import asyncio
|
|
|
|
from agent.webhooks import common as webhook_common
|
|
|
|
monkeypatch.setenv("DASHBOARD_BASE_URL", "https://app.example.com")
|
|
calls: dict[str, object] = {}
|
|
|
|
async def fake_reply(channel_id, thread_ts, text):
|
|
calls["reply"] = {"channel_id": channel_id, "thread_ts": thread_ts, "text": text}
|
|
return True
|
|
|
|
monkeypatch.setattr(webhook_common, "post_slack_thread_reply", fake_reply)
|
|
|
|
asyncio.run(
|
|
webhook_common._post_account_link_prompt("C1", "1.1", "U1", "d@x.com", reason="unlinked")
|
|
)
|
|
assert calls["reply"]["channel_id"] == "C1"
|
|
assert calls["reply"]["thread_ts"] == "1.1"
|
|
assert "https://app.example.com/my-settings" in calls["reply"]["text"]
|
|
# No signed account-link token may appear in the public thread.
|
|
assert "link=" not in calls["reply"]["text"]
|
|
|
|
|
|
def test_account_link_prompt_revoked_wording(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
import asyncio
|
|
|
|
from agent.webhooks import common as webhook_common
|
|
|
|
monkeypatch.setenv("DASHBOARD_BASE_URL", "https://app.example.com")
|
|
calls: dict[str, object] = {}
|
|
|
|
async def fake_reply(channel_id, thread_ts, text):
|
|
calls["text"] = text
|
|
return True
|
|
|
|
monkeypatch.setattr(webhook_common, "post_slack_thread_reply", fake_reply)
|
|
|
|
asyncio.run(
|
|
webhook_common._post_account_link_prompt("C1", "1.1", "U1", "d@x.com", reason="revoked")
|
|
)
|
|
assert "no longer valid" in calls["text"]
|
|
assert "link=" not in calls["text"]
|
|
|
|
|
|
def test_account_link_prompt_skips_when_dashboard_url_unset(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
import asyncio
|
|
|
|
from agent.webhooks import common as webhook_common
|
|
|
|
monkeypatch.delenv("DASHBOARD_BASE_URL", raising=False)
|
|
posted = False
|
|
|
|
async def fake_reply(channel_id, thread_ts, text):
|
|
nonlocal posted
|
|
posted = True
|
|
return True
|
|
|
|
monkeypatch.setattr(webhook_common, "post_slack_thread_reply", fake_reply)
|
|
|
|
asyncio.run(
|
|
webhook_common._post_account_link_prompt("C1", "1.1", "U1", "d@x.com", reason="unlinked")
|
|
)
|
|
assert posted is False
|