Skip to content

Conversation

@khustup2
Copy link
Contributor

🚀 🚀 Pull Request

Impact

  • Bug fix (non-breaking change which fixes expected existing functionality)
  • Enhancement/New feature (adds functionality without impacting existing logic)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Things to be aware of

Things to worry about

Additional Context

Copilot AI review requested due to automatic review settings December 16, 2025 03:01
@khustup2 khustup2 merged commit b6e9b09 into main Dec 16, 2025
7 checks passed
@khustup2 khustup2 deleted the cicd-fix branch December 16, 2025 03:01
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
5 Security Hotspots

See analysis details on SonarQube Cloud

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the Python test infrastructure to fix CI/CD issues related to module imports and PostgreSQL permissions when running as root. The changes reorganize test utilities into a proper test_utils package and add support for running tests in containerized CI environments.

Key changes:

  • Reorganized test utilities from lib to test_utils package with proper __init__.py
  • Added permission handling for PostgreSQL operations when running as root user in CI/CD
  • Updated test fixtures to use proper temporary directories with correct ownership
  • Removed disabled PubMed test file

Reviewed changes

Copilot reviewed 39 out of 39 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
postgres/tests/py_tests/test_utils/init.py Creates new test_utils package with proper exports
postgres/tests/py_tests/test_utils/assertions.py Moves Assertions class to new package location
postgres/tests/py_tests/test_utils/helpers.py Moves helper functions to new package location
postgres/tests/py_tests/test_*.py (multiple files) Updates imports from lib.assertions to test_utils.assertions
postgres/tests/py_tests/conftest.py Adds root user permission handling and temp directory fixture
postgres/tests/py_tests/test_root_path.py Updates to use new temp_dir_for_postgres fixture
postgres/tests/py_tests/test_pubmed_table.py Removes disabled test file
postgres/tests/py_tests/requirements.txt Adds numpy dependency
postgres/tests/Makefile Removes PYTHONPATH=. from pytest commands
.github/workflows/pg-extension-build.yaml Adds postgres directory ownership and removes PYTHONPATH

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

from typing import Dict, AsyncGenerator

# Ensure the test directory is in Python path for lib imports
sys.path.insert(0, str(Path(__file__).parent))
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

Adding the test directory to sys.path can cause import conflicts and is an anti-pattern. Since test_utils is now a proper package with init.py, Python's standard import resolution should handle it without path manipulation. Consider removing this line.

Suggested change
sys.path.insert(0, str(Path(__file__).parent))

Copilot uses AI. Check for mistakes.
shutil.chown(str(data_dir), user=user, group=user)
# Run initdb as postgres user using su
result = subprocess.run(
["su", "-", user, "-c", f"{initdb} -D {data_dir} -U {user}"],
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The command is constructed using f-string interpolation without proper shell escaping. If data_dir or user contain special shell characters, this could lead to command injection. Use a list of arguments instead of a shell command string, or properly escape the variables.

Copilot uses AI. Check for mistakes.
# Run pg_ctl as postgres user with only essential environment variables
ld_library_path = env.get("LD_LIBRARY_PATH", "")
subprocess.run(
["su", "-", user, "-c", f"LD_LIBRARY_PATH={ld_library_path} {pg_ctl} -D {data_dir} -l {log_file} start"],
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The command string is vulnerable to shell injection if any of the path variables contain special characters. Use proper argument lists or shell escaping to prevent potential security issues.

Copilot uses AI. Check for mistakes.
user = os.environ.get("USER", "postgres")
if os.geteuid() == 0: # Running as root
result = subprocess.run(
["su", "-", user, "-c", f"{pg_ctl} status -D {data_dir}"],
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The command construction is vulnerable to shell injection. Use proper argument lists or shell escaping for the path variables.

Copilot uses AI. Check for mistakes.
user = os.environ.get("USER", "postgres")
if os.geteuid() == 0: # Running as root
subprocess.run(
["su", "-", user, "-c", f"{pg_ctl} stop -D {data_dir} -m fast"],
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The command string is vulnerable to shell injection if path variables contain special characters. Use proper argument lists or shell escaping.

Copilot uses AI. Check for mistakes.

# Ensure subdirectories are owned by postgres user
if os.geteuid() == 0:
import shutil
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The shutil module is imported inside a conditional block at line 104, but it's already used elsewhere in the codebase (e.g., in conftest.py). Consider moving this import to the top of the file with other imports for consistency and clarity.

Copilot uses AI. Check for mistakes.
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.

2 participants