Skip to content

[TT-18717] Pass the Postgres MCP analytics DSN to API tests - #176

Closed
konrad-sol wants to merge 1 commit into
mainfrom
TT-18717-mcp-postgres-dsn
Closed

konrad-sol wants to merge 1 commit into
mainfrom
TT-18717-mcp-postgres-dsn

Conversation

@konrad-sol

Copy link
Copy Markdown
Collaborator

On Postgres environments the MCP analytics tests need TYK_TEST_MCP_POSTGRES_DSN; without it they read raw MCP records from Mongo and find none.

  • New db input on tests/api-tests, defaulting to matrix.envfiles.db like api_markers does.
  • For postgres*, adds the DSN to pytest.env in URL form (the action splits pytest.env on whitespace, so host=… port=… would break).

Merge order: draft until TykTechnologies/tyk-pro#115 is merged and released. Before that release the raw sql-mcp pump writes to dated (sharded) tables, so the tests would look for a table that does not exist. This action goes live for every consumer via @production on merge.

Related: https://github.com/TykTechnologies/tyk-analytics/pull/6479

🤖 Generated with Claude Code

Without TYK_TEST_MCP_POSTGRES_DSN the MCP analytics tests read raw records
from Mongo, so on Postgres environments they find nothing. Needs the
tyk-pro release with the unsharded raw sql-mcp pump (tyk-pro#115).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

zizmor findings

Severity Count
High 96
Medium 91
Low 2
Info 11

Full details are in the workflow run.

@probelabs

probelabs Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

This PR updates the api-tests GitHub Action to correctly run Multi-Cloud Platform (MCP) analytics tests against a Postgres database. It introduces a new db input to the action, which is used to conditionally set the TYK_TEST_MCP_POSTGRES_DSN environment variable. When the environment uses Postgres, this DSN is passed to pytest, directing the tests to read raw analytics records from Postgres instead of the default, MongoDB. This change fixes test failures on Postgres environments where tests were previously unable to find analytics data.

Files Changed Analysis

  • File: .github/actions/tests/api-tests/action.yaml
  • Changes: 10 additions, 0 deletions.
  • Summary: The changes are confined to this single GitHub Action file. A new db input was added, and a conditional shell script block was inserted to set the TYK_TEST_MCP_POSTGRES_DSN environment variable for Postgres-based test runs.

Architecture & Impact Assessment

  • Accomplishment: Fixes failing MCP analytics tests in CI environments that use Postgres by providing the necessary database connection string.
  • Key Technical Changes:
    • A new db input was added to the .github/actions/tests/api-tests composite action.
    • A conditional block was added to the action's run step to check the db input. If it starts with postgres, the TYK_TEST_MCP_POSTGRES_DSN environment variable is written to the pytest.env file.
  • Affected System Components: The primary impact is on the CI workflows that utilize the api-tests action. Any test suite running against a Postgres environment will now have the correct configuration to validate MCP analytics functionality.
graph TD
    A[Start api-tests action] --> B{Get `db` input};
    B --> C{"Is db value 'postgres*'?"};
    C -- Yes --> D[Add TYK_TEST_MCP_POSTGRES_DSN to pytest.env];
    D --> E[Run pytest];
    C -- No --> E;

Loading

Scope Discovery & Context Expansion

  • The change is localized to the CI test setup, specifically the api-tests GitHub Action. It doesn't alter any product code.
  • The broader context, indicated by the PR description, is a cross-repository effort to enable MCP analytics on Postgres. This PR provides the necessary CI configuration to validate that functionality.
  • The immediate impact is on CI workflows that use this action. These workflows will now correctly configure and run MCP analytics tests against Postgres backends, preventing false negatives in test results.
Metadata
  • Review Effort: 1 / 5
  • Primary Label: chore

Powered by Visor from Probelabs

Last updated: 2026-11-10T18:38:57.003Z | Triggered by: pr_opened | Commit: 1fabe65

💡 TIP: You can chat with Visor using /visor ask <your question>

@probelabs

probelabs Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Security Issues (1)

Severity Location Issue
🟡 Warning .github/actions/tests/api-tests/action.yaml:52
A hardcoded PostgreSQL connection string (DSN) is present in the action. This string includes the username, host, port, database name, and sets `sslmode=disable`, forcing an unencrypted connection. While intended for a local test environment, hardcoding connection details is inflexible and establishes a poor security precedent. If the test database configuration changes (e.g., requires a password or SSL), this action will fail or connect insecurely.
💡 SuggestionAvoid hardcoding the DSN. Instead, pass the full connection string as a dedicated input to the action. This allows the calling workflow to control the connection parameters, sourcing them from environment variables or secrets as needed, which is more secure and flexible.

Example implementation:

In action.yaml:

inputs:
  # ...
  mcp-postgres-dsn:
    description: &#39;Postgres DSN for MCP analytics tests.&#39;
    required: false

# ... inside the run step:
if [[ &#34;${{ inputs.db }}&#34; == postgres* &amp;&amp; -n &#34;${{ inputs.mcp-postgres-dsn }}&#34; ]]; then
  echo &#34;TYK_TEST_MCP_POSTGRES_DSN=${{ inputs.mcp-postgres-dsn }}&#34; &gt;&gt; pytest.env
fi

The calling workflow would then be responsible for providing the correct DSN.

Security Issues (1)

Severity Location Issue
🟡 Warning .github/actions/tests/api-tests/action.yaml:52
A hardcoded PostgreSQL connection string (DSN) is present in the action. This string includes the username, host, port, database name, and sets `sslmode=disable`, forcing an unencrypted connection. While intended for a local test environment, hardcoding connection details is inflexible and establishes a poor security precedent. If the test database configuration changes (e.g., requires a password or SSL), this action will fail or connect insecurely.
💡 SuggestionAvoid hardcoding the DSN. Instead, pass the full connection string as a dedicated input to the action. This allows the calling workflow to control the connection parameters, sourcing them from environment variables or secrets as needed, which is more secure and flexible.

Example implementation:

In action.yaml:

inputs:
  # ...
  mcp-postgres-dsn:
    description: &#39;Postgres DSN for MCP analytics tests.&#39;
    required: false

# ... inside the run step:
if [[ &#34;${{ inputs.db }}&#34; == postgres* &amp;&amp; -n &#34;${{ inputs.mcp-postgres-dsn }}&#34; ]]; then
  echo &#34;TYK_TEST_MCP_POSTGRES_DSN=${{ inputs.mcp-postgres-dsn }}&#34; &gt;&gt; pytest.env
fi

The calling workflow would then be responsible for providing the correct DSN.

\n\n ### Architecture Issues (1)
Severity Location Issue
🟡 Warning .github/actions/tests/api-tests/action.yaml:53
The PostgreSQL DSN is hard-coded within the action's script. This couples the action to a specific test environment configuration (e.g., hostname, port, credentials) and makes it difficult to reuse the action in environments with different configurations. For a reusable action intended for production use, configuration should be exposed as inputs rather than being hidden in the implementation.
💡 SuggestionTo improve configurability and transparency, extract the DSN into a new action input, using the current hard-coded value as its default. This makes the configuration explicit, self-documenting, and allows for overrides when necessary.
  1. Add a new input to the inputs section:
  postgres_mcp_dsn:
    description: &#39;DSN for MCP analytics tests on Postgres. Used when `db` starts with `postgres`.&#39;
    required: false
    default: &#39;postgresql://postgres@localhost:5432/tyk_analytics?sslmode=disable&#39;
  1. Use this new input in the run step:
          if [[ &#34;$DB&#34; == postgres* ]]; then
            echo &#34;TYK_TEST_MCP_POSTGRES_DSN=${{ inputs.postgres_mcp_dsn }}&#34; &gt;&gt; pytest.env
          fi

✅ Performance Check Passed

No performance issues found – changes LGTM.


Powered by Visor from Probelabs

Last updated: 2026-11-10T18:38:33.513Z | Triggered by: pr_opened | Commit: 1fabe65

💡 TIP: You can chat with Visor using /visor ask <your question>

@konrad-sol

Copy link
Copy Markdown
Collaborator Author

Closing: no longer needed. The API tests now detect a Postgres run themselves: Postgres matrix legs already pass -m "... not sql", and a pytest_configure hook uses that to point the MCP analytics reads at Postgres (TYK_TEST_POSTGRES_URL in pytest_ci.ini). See tyk-analytics#6479 and tyk-analytics#6494. tyk-pro#115 uses api-tests@production again.

@konrad-sol konrad-sol closed this Nov 13, 2026
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