Skip to content

feature(ingestion-acceptance-tests): extend timeout logging#53812

Open
eli-r-ph wants to merge 1 commit intomasterfrom
eli.r/ingestion-acceptance-tests-better-timeout-report
Open

feature(ingestion-acceptance-tests): extend timeout logging#53812
eli-r-ph wants to merge 1 commit intomasterfrom
eli.r/ingestion-acceptance-tests-better-timeout-report

Conversation

@eli-r-ph
Copy link
Copy Markdown
Contributor

@eli-r-ph eli-r-ph commented Apr 9, 2026

Problem

Fix a small bug that prevents reporting in-flight jobs from snapshot when the job times out awaiting expected events.

Changes

  • Fix shutdown handling bug
  • Extend snapshot logging to Slack

How did you test this code?

Locally and in CI (new unit tests too)

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Publish to changelog?

N/A

Docs update

N/A

@eli-r-ph eli-r-ph requested a review from a team April 9, 2026 02:14
@eli-r-ph eli-r-ph self-assigned this Apr 9, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 9, 2026

Vulnerabilities

  • Credential exposure in Slack notification (slack.py line 151): config.project_api_key is now embedded in every Slack timeout alert. Slack messages are stored, indexed, and shareable — this is an unnecessary exposure of an active ingestion API key, even for a test project.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: posthog/temporal/ingestion_acceptance_test/slack.py
Line: 150-152

Comment:
**API key exposed in Slack notification**

`config.project_api_key` is a live ingestion credential being sent into a Slack message. Slack messages are persisted server-side, appear in search results, and can be forwarded or screen-shared — making this an unnecessary credential-leak surface. Even for a dedicated test project, the project API key can be used to ingest arbitrary events. Consider replacing this with a non-sensitive identifier (e.g., a truncated prefix like `phc_...abc`) or removing it entirely.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: posthog/temporal/tests/ingestion_acceptance_test/test_runner.py
Line: 199-241

Comment:
**Prefer parameterised tests**

The three `TestSnapshotWithPolls` tests share identical structure (set up `_tests`, set up `pending_polls_snapshot`, call `snapshot_with_polls`, assert result) with only inputs and expected output varying. Per the project's testing conventions, this should be a single `@pytest.mark.parametrize` test. The same pattern applies to `test_payload_renders_running_tests_with_poll_descriptions` and `test_payload_renders_running_test_without_poll_when_none` in `test_slack.py`.

```python
@pytest.mark.parametrize(
    "tests_by_tid, polls_by_tid, expected",
    [
        (
            {100: "TestA::test_one", 200: "TestB::test_two"},
            {100: "event UUID 'abc-123'", 200: "person with distinct_id 'xyz-456'"},
            [RunningTestInfo("TestA::test_one", "event UUID 'abc-123'"), RunningTestInfo("TestB::test_two", "person with distinct_id 'xyz-456'")],
        ),
        (
            {100: "TestA::test_one", 200: "TestB::test_two"},
            {100: "event UUID 'abc-123'"},
            [RunningTestInfo("TestA::test_one", "event UUID 'abc-123'"), RunningTestInfo("TestB::test_two", None)],
        ),
        ({}, {}, []),
    ],
)
def test_snapshot_with_polls(self, tests_by_tid, polls_by_tid, expected) -> None:
    rt = RunningTests()
    rt._tests = tests_by_tid
    mock_client = MagicMock()
    mock_client.pending_polls_snapshot.return_value = polls_by_tid
    assert rt.snapshot_with_polls(mock_client) == expected
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "extend timeout logging after job fail, e..." | Re-trigger Greptile

Comment on lines +150 to 152
f":stopwatch: Timeout: {config.activity_timeout_seconds}s | "
f":key: Token: `{config.project_api_key}`"
),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security API key exposed in Slack notification

config.project_api_key is a live ingestion credential being sent into a Slack message. Slack messages are persisted server-side, appear in search results, and can be forwarded or screen-shared — making this an unnecessary credential-leak surface. Even for a dedicated test project, the project API key can be used to ingest arbitrary events. Consider replacing this with a non-sensitive identifier (e.g., a truncated prefix like phc_...abc) or removing it entirely.

Prompt To Fix With AI
This is a comment left during a code review.
Path: posthog/temporal/ingestion_acceptance_test/slack.py
Line: 150-152

Comment:
**API key exposed in Slack notification**

`config.project_api_key` is a live ingestion credential being sent into a Slack message. Slack messages are persisted server-side, appear in search results, and can be forwarded or screen-shared — making this an unnecessary credential-leak surface. Even for a dedicated test project, the project API key can be used to ingest arbitrary events. Consider replacing this with a non-sensitive identifier (e.g., a truncated prefix like `phc_...abc`) or removing it entirely.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +199 to +241
class TestSnapshotWithPolls:
def test_correlates_tests_with_pending_polls_by_thread_id(self) -> None:
rt = RunningTests()
rt._tests = {100: "TestA::test_one", 200: "TestB::test_two"}

mock_client = MagicMock()
mock_client.pending_polls_snapshot.return_value = {
100: "event UUID 'abc-123'",
200: "person with distinct_id 'xyz-456'",
}

result = rt.snapshot_with_polls(mock_client)

assert result == [
RunningTestInfo(name="TestA::test_one", pending_poll="event UUID 'abc-123'"),
RunningTestInfo(name="TestB::test_two", pending_poll="person with distinct_id 'xyz-456'"),
]

def test_pending_poll_is_none_when_thread_has_no_active_poll(self) -> None:
rt = RunningTests()
rt._tests = {100: "TestA::test_one", 200: "TestB::test_two"}

mock_client = MagicMock()
mock_client.pending_polls_snapshot.return_value = {
100: "event UUID 'abc-123'",
}

result = rt.snapshot_with_polls(mock_client)

assert result == [
RunningTestInfo(name="TestA::test_one", pending_poll="event UUID 'abc-123'"),
RunningTestInfo(name="TestB::test_two", pending_poll=None),
]

def test_returns_empty_list_when_no_tests_running(self) -> None:
rt = RunningTests()

mock_client = MagicMock()
mock_client.pending_polls_snapshot.return_value = {}

result = rt.snapshot_with_polls(mock_client)

assert result == []
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Prefer parameterised tests

The three TestSnapshotWithPolls tests share identical structure (set up _tests, set up pending_polls_snapshot, call snapshot_with_polls, assert result) with only inputs and expected output varying. Per the project's testing conventions, this should be a single @pytest.mark.parametrize test. The same pattern applies to test_payload_renders_running_tests_with_poll_descriptions and test_payload_renders_running_test_without_poll_when_none in test_slack.py.

@pytest.mark.parametrize(
    "tests_by_tid, polls_by_tid, expected",
    [
        (
            {100: "TestA::test_one", 200: "TestB::test_two"},
            {100: "event UUID 'abc-123'", 200: "person with distinct_id 'xyz-456'"},
            [RunningTestInfo("TestA::test_one", "event UUID 'abc-123'"), RunningTestInfo("TestB::test_two", "person with distinct_id 'xyz-456'")],
        ),
        (
            {100: "TestA::test_one", 200: "TestB::test_two"},
            {100: "event UUID 'abc-123'"},
            [RunningTestInfo("TestA::test_one", "event UUID 'abc-123'"), RunningTestInfo("TestB::test_two", None)],
        ),
        ({}, {}, []),
    ],
)
def test_snapshot_with_polls(self, tests_by_tid, polls_by_tid, expected) -> None:
    rt = RunningTests()
    rt._tests = tests_by_tid
    mock_client = MagicMock()
    mock_client.pending_polls_snapshot.return_value = polls_by_tid
    assert rt.snapshot_with_polls(mock_client) == expected
Prompt To Fix With AI
This is a comment left during a code review.
Path: posthog/temporal/tests/ingestion_acceptance_test/test_runner.py
Line: 199-241

Comment:
**Prefer parameterised tests**

The three `TestSnapshotWithPolls` tests share identical structure (set up `_tests`, set up `pending_polls_snapshot`, call `snapshot_with_polls`, assert result) with only inputs and expected output varying. Per the project's testing conventions, this should be a single `@pytest.mark.parametrize` test. The same pattern applies to `test_payload_renders_running_tests_with_poll_descriptions` and `test_payload_renders_running_test_without_poll_when_none` in `test_slack.py`.

```python
@pytest.mark.parametrize(
    "tests_by_tid, polls_by_tid, expected",
    [
        (
            {100: "TestA::test_one", 200: "TestB::test_two"},
            {100: "event UUID 'abc-123'", 200: "person with distinct_id 'xyz-456'"},
            [RunningTestInfo("TestA::test_one", "event UUID 'abc-123'"), RunningTestInfo("TestB::test_two", "person with distinct_id 'xyz-456'")],
        ),
        (
            {100: "TestA::test_one", 200: "TestB::test_two"},
            {100: "event UUID 'abc-123'"},
            [RunningTestInfo("TestA::test_one", "event UUID 'abc-123'"), RunningTestInfo("TestB::test_two", None)],
        ),
        ({}, {}, []),
    ],
)
def test_snapshot_with_polls(self, tests_by_tid, polls_by_tid, expected) -> None:
    rt = RunningTests()
    rt._tests = tests_by_tid
    mock_client = MagicMock()
    mock_client.pending_polls_snapshot.return_value = polls_by_tid
    assert rt.snapshot_with_polls(mock_client) == expected
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant