Skip to content

CodeRabbit Generated Unit Tests: Add unit tests for PR changes#1865

Closed
coderabbitai[bot] wants to merge 2 commits intomainfrom
coderabbitai/utg/41137d8
Closed

CodeRabbit Generated Unit Tests: Add unit tests for PR changes#1865
coderabbitai[bot] wants to merge 2 commits intomainfrom
coderabbitai/utg/41137d8

Conversation

@coderabbitai
Copy link
Contributor

@coderabbitai coderabbitai bot commented Mar 18, 2026

Unit test generation was requested by @ritwik-g.

The following files were modified:

  • docker/tests/test_dockerfiles.py

@coderabbitai
Copy link
Contributor Author

coderabbitai bot commented Mar 18, 2026

Important

Review skipped

This PR was authored by the user configured for CodeRabbit reviews. CodeRabbit does not review PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b5bea14c-f0ad-4d25-b022-e8a5fb24ab09

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@ritwik-g ritwik-g closed this Mar 18, 2026
@sonarqubecloud
Copy link

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 18, 2026

Greptile Summary

This PR adds a new test file (docker/tests/test_dockerfiles.py) that validates the structural correctness of 7 service Dockerfiles after the removal of ARG VERSION and the version= label — changes that are made in the companion PR #1864. The tests are well-structured and cover both positive assertions (correct maintainer/description labels and base images) and negative assertions (absence of ARG VERSION and version= labels).

Key issues found:

  • Tests will fail immediately on main: The Dockerfiles in docker/dockerfiles/ still contain ARG VERSION=dev and version="${VERSION}". All negative-assertion tests (test_no_arg_version_in_dockerfile, test_no_version_label_in_base_stage, test_no_version_arg_default_dev, test_no_version_label_value_interpolation, test_no_version_key_in_any_stage) will fail for all 7 Dockerfiles. This PR must be merged together with (or after) PR [FIX] Remove VERSION arg from Dockerfile base stages to fix CI cache #1864 that actually removes those from the Dockerfiles.
  • Latent bug in get_label_block_keys: For single-line (non-backslash-continued) LABEL instructions, the function appends the following instruction's line before detecting the block end, potentially extracting spurious label keys from adjacent ENV declarations that use quoted values. This is harmless for the current Dockerfiles but is a correctness issue.
  • Redundant test test_worker_unified_distinct_base_image: Fully duplicates the assertions already covered by test_base_stage_from_instruction + EXPECTED_BASE_IMAGES.
  • Unusual default-parameter test: test_version_arg_removed_not_merely_commented uses a default function parameter as a test fixture workaround, covering only backend.Dockerfile, while test_no_arg_version_in_dockerfile already covers all 7 files with @pytest.mark.parametrize.

Confidence Score: 2/5

  • Not safe to merge independently — the majority of the new tests will fail against the current state of main because the Dockerfiles have not yet been updated.
  • The test file itself is syntactically correct and the testing strategy is sound, but it was authored against the post-PR-[FIX] Remove VERSION arg from Dockerfile base stages to fix CI cache #1864 Dockerfile state. Since PR [FIX] Remove VERSION arg from Dockerfile base stages to fix CI cache #1864 has not yet been merged, merging this PR alone will introduce a failing CI suite. The latent logic bug in get_label_block_keys and the redundant/fragile tests also reduce confidence.
  • docker/tests/test_dockerfiles.py — all negative-assertion tests will fail; get_label_block_keys has a latent off-by-one termination bug.

Important Files Changed

Filename Overview
docker/tests/test_dockerfiles.py New test file verifying Dockerfile structure after ARG VERSION removal; majority of tests will immediately fail against current main-branch Dockerfiles that still contain ARG VERSION=dev and version="${VERSION}", plus a latent bug in get_label_block_keys for single-line LABEL instructions and a redundant/unusual default-parameter test.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[pytest collects test_dockerfiles.py] --> B[read_dockerfile: load Dockerfile text]
    B --> C{Test category}
    C --> D[Negative assertions\nARG VERSION absent\nversion= label absent]
    C --> E[Positive assertions\nmaintainer label present\ndescription label present]
    C --> F[Structural assertions\nFROM AS base image correct\nFile exists]
    D --> G[get_base_stage_content\nextract FROM...AS base block]
    E --> G
    G --> H[get_label_block_keys\nextract LABEL keys via regex]
    H --> I{Single-line LABEL?}
    I -- Yes --> J[⚠️ Next instruction line\nappended before break\nlatent false-key bug]
    I -- No, multi-line --> K[Correctly terminates\non missing backslash]
    D --> L{Current Dockerfiles\nhave ARG VERSION=dev?}
    L -- Yes --> M[❌ Tests FAIL on main\nbefore PR-1864 merges]
    L -- No after PR-1864 --> N[✅ Tests PASS]
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: docker/tests/test_dockerfiles.py
Line: 112-153

Comment:
**Tests will fail against current Dockerfiles**

The tests assert the *post-PR-#1864* state (i.e., `ARG VERSION` and `version=` label are absent), but the actual Dockerfiles in `docker/dockerfiles/` still contain both of those. For example, `backend.Dockerfile` currently has:

```
ARG VERSION=dev
LABEL maintainer="Zipstack Inc." \
    description="Backend Service Container" \
    version="${VERSION}"
```

This means the following tests will **immediately fail** for all 7 Dockerfiles when run against the current `main` branch:
- `test_no_arg_version_in_dockerfile`
- `test_no_version_label_in_base_stage`
- `test_no_version_arg_default_dev`
- `test_no_version_label_value_interpolation`

These tests should be committed together with (or after) PR #1864 that actually removes `ARG VERSION` from the Dockerfiles — not independently on top of `main`.

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

---

This is a comment left during a code review.
Path: docker/tests/test_dockerfiles.py
Line: 92-99

Comment:
**`get_label_block_keys` can include the next instruction's content**

When a LABEL uses only a single key on one line (not backslash-continued), the function appends the *next* instruction's line before breaking. For example, given:

```dockerfile
LABEL maintainer="Zipstack Inc."
ENV DJANGO_SETTINGS_MODULE="backend.settings.dev"
```

1. The `LABEL` line is appended; the second outer `if` sees it matches `^LABEL\b` so doesn't break.
2. The `ENV` line enters `elif in_label:` and is appended.
3. `label_lines[-2]` (the LABEL line) doesn't end with `\\` → break.
4. But the `ENV` line is now in `label_content`, and `DJANGO_SETTINGS_MODULE="backend.settings.dev"` matches `\b(\w+)\s*=\s*"[^"]*"` — so `DJANGO_SETTINGS_MODULE` would be returned as a label key.

This doesn't affect the current Dockerfiles (which all use multi-line backslash-continued LABELs), but it is a latent bug. The inner `elif` break on `label_lines[-2]` is a safety net for "we've already passed the LABEL block", but it fires one line too late. Consider guarding upfront instead:

```python
elif in_label:
    # If previous line didn't end with continuation, we've left the LABEL block
    if not label_lines[-1].endswith("\\"):
        break
    label_lines.append(stripped)
```

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

---

This is a comment left during a code review.
Path: docker/tests/test_dockerfiles.py
Line: 239-250

Comment:
**Test with default parameter is redundant and pytest-fragile**

`test_version_arg_removed_not_merely_commented` uses a default function parameter (`dockerfile_name: str = "backend.Dockerfile"`) to act as a standalone test. Pytest will use the default value since `dockerfile_name` is not a registered fixture, so collection won't crash — but this is an unusual pattern that some linters and pytest plugins may flag.

More importantly, this test is almost entirely redundant with `test_no_arg_version_in_dockerfile`, which already covers all 7 Dockerfiles with `@pytest.mark.parametrize`. The only difference is that this version strips comment lines first, but since `test_no_arg_version_in_dockerfile` also uses `re.MULTILINE` and comment lines would not match `^\s*ARG\s+VERSION\b` anyway (a comment line starts with `#`, not whitespace followed by `ARG`), the comment-stripping step adds no meaningful extra coverage.

Consider removing this test, or replacing it with a parametrized version that covers all Dockerfiles if the comment-stripping logic is intentional.

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

---

This is a comment left during a code review.
Path: docker/tests/test_dockerfiles.py
Line: 271-288

Comment:
**`test_worker_unified_distinct_base_image` duplicates `test_base_stage_from_instruction`**

Both `test_base_stage_from_instruction` (parametrized) and `test_worker_unified_distinct_base_image` (also parametrized over all 7 Dockerfiles) verify the exact same thing: the base image in the `FROM ... AS base` instruction for each Dockerfile. The duplicate assertion adds CI overhead (7 extra parametrized test runs) without additional coverage.

Consider removing `test_worker_unified_distinct_base_image` and relying on `test_base_stage_from_instruction` + `EXPECTED_BASE_IMAGES` instead, since that dict already encodes the per-Dockerfile expectations (including `worker-unified`'s distinct `python:3.12.9-slim` image).

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

Last reviewed commit: "[pre-commit.ci] auto..."

Comment on lines +112 to +153
@pytest.mark.parametrize("dockerfile_name", ALL_DOCKERFILES)
def test_no_arg_version_in_dockerfile(dockerfile_name: str) -> None:
"""Verify that ARG VERSION is not present anywhere in the Dockerfile."""
content = read_dockerfile(dockerfile_name)
# Match any ARG instruction that declares VERSION (with or without default)
assert not re.search(
r"^\s*ARG\s+VERSION\b", content, re.MULTILINE
), f"{dockerfile_name}: ARG VERSION declaration must not be present (removed in PR)"


@pytest.mark.parametrize("dockerfile_name", ALL_DOCKERFILES)
def test_no_version_label_in_base_stage(dockerfile_name: str) -> None:
"""Verify that the version label is not present in the base stage LABEL instruction."""
content = read_dockerfile(dockerfile_name)
base_stage = get_base_stage_content(content)
# Match 'version=' as a label key (with optional whitespace / backslash continuation)
assert not re.search(
r"\bversion\s*=", base_stage, re.IGNORECASE
), (
f"{dockerfile_name}: 'version=' label must not be present in base stage "
"(removed in PR)"
)


@pytest.mark.parametrize("dockerfile_name", ALL_DOCKERFILES)
def test_no_version_arg_default_dev(dockerfile_name: str) -> None:
"""Regression: the exact old pattern 'ARG VERSION=dev' must be absent."""
content = read_dockerfile(dockerfile_name)
assert "ARG VERSION=dev" not in content, (
f"{dockerfile_name}: The exact old pattern 'ARG VERSION=dev' "
"must have been removed by this PR"
)


@pytest.mark.parametrize("dockerfile_name", ALL_DOCKERFILES)
def test_no_version_label_value_interpolation(dockerfile_name: str) -> None:
"""Regression: the exact old label value 'version=\"${VERSION}\"' must be absent."""
content = read_dockerfile(dockerfile_name)
assert 'version="${VERSION}"' not in content, (
f"{dockerfile_name}: The old label 'version=\"${{VERSION}}\"' "
"must have been removed by this PR"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

P1 Tests will fail against current Dockerfiles

The tests assert the post-PR-#1864 state (i.e., ARG VERSION and version= label are absent), but the actual Dockerfiles in docker/dockerfiles/ still contain both of those. For example, backend.Dockerfile currently has:

ARG VERSION=dev
LABEL maintainer="Zipstack Inc." \
    description="Backend Service Container" \
    version="${VERSION}"

This means the following tests will immediately fail for all 7 Dockerfiles when run against the current main branch:

  • test_no_arg_version_in_dockerfile
  • test_no_version_label_in_base_stage
  • test_no_version_arg_default_dev
  • test_no_version_label_value_interpolation

These tests should be committed together with (or after) PR #1864 that actually removes ARG VERSION from the Dockerfiles — not independently on top of main.

Prompt To Fix With AI
This is a comment left during a code review.
Path: docker/tests/test_dockerfiles.py
Line: 112-153

Comment:
**Tests will fail against current Dockerfiles**

The tests assert the *post-PR-#1864* state (i.e., `ARG VERSION` and `version=` label are absent), but the actual Dockerfiles in `docker/dockerfiles/` still contain both of those. For example, `backend.Dockerfile` currently has:

```
ARG VERSION=dev
LABEL maintainer="Zipstack Inc." \
    description="Backend Service Container" \
    version="${VERSION}"
```

This means the following tests will **immediately fail** for all 7 Dockerfiles when run against the current `main` branch:
- `test_no_arg_version_in_dockerfile`
- `test_no_version_label_in_base_stage`
- `test_no_version_arg_default_dev`
- `test_no_version_label_value_interpolation`

These tests should be committed together with (or after) PR #1864 that actually removes `ARG VERSION` from the Dockerfiles — not independently on top of `main`.

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

Comment on lines +92 to +99
elif in_label:
label_lines.append(stripped)
# Continuation ends when the previous line does NOT end with backslash
if not label_lines[-2].endswith("\\"):
break
if in_label and label_lines and not label_lines[-1].endswith("\\"):
if len(label_lines) >= 1 and not re.match(r"^LABEL\b", label_lines[-1], re.IGNORECASE):
break
Copy link
Contributor

Choose a reason for hiding this comment

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

P2 get_label_block_keys can include the next instruction's content

When a LABEL uses only a single key on one line (not backslash-continued), the function appends the next instruction's line before breaking. For example, given:

LABEL maintainer="Zipstack Inc."
ENV DJANGO_SETTINGS_MODULE="backend.settings.dev"
  1. The LABEL line is appended; the second outer if sees it matches ^LABEL\b so doesn't break.
  2. The ENV line enters elif in_label: and is appended.
  3. label_lines[-2] (the LABEL line) doesn't end with \\ → break.
  4. But the ENV line is now in label_content, and DJANGO_SETTINGS_MODULE="backend.settings.dev" matches \b(\w+)\s*=\s*"[^"]*" — so DJANGO_SETTINGS_MODULE would be returned as a label key.

This doesn't affect the current Dockerfiles (which all use multi-line backslash-continued LABELs), but it is a latent bug. The inner elif break on label_lines[-2] is a safety net for "we've already passed the LABEL block", but it fires one line too late. Consider guarding upfront instead:

elif in_label:
    # If previous line didn't end with continuation, we've left the LABEL block
    if not label_lines[-1].endswith("\\"):
        break
    label_lines.append(stripped)
Prompt To Fix With AI
This is a comment left during a code review.
Path: docker/tests/test_dockerfiles.py
Line: 92-99

Comment:
**`get_label_block_keys` can include the next instruction's content**

When a LABEL uses only a single key on one line (not backslash-continued), the function appends the *next* instruction's line before breaking. For example, given:

```dockerfile
LABEL maintainer="Zipstack Inc."
ENV DJANGO_SETTINGS_MODULE="backend.settings.dev"
```

1. The `LABEL` line is appended; the second outer `if` sees it matches `^LABEL\b` so doesn't break.
2. The `ENV` line enters `elif in_label:` and is appended.
3. `label_lines[-2]` (the LABEL line) doesn't end with `\\` → break.
4. But the `ENV` line is now in `label_content`, and `DJANGO_SETTINGS_MODULE="backend.settings.dev"` matches `\b(\w+)\s*=\s*"[^"]*"` — so `DJANGO_SETTINGS_MODULE` would be returned as a label key.

This doesn't affect the current Dockerfiles (which all use multi-line backslash-continued LABELs), but it is a latent bug. The inner `elif` break on `label_lines[-2]` is a safety net for "we've already passed the LABEL block", but it fires one line too late. Consider guarding upfront instead:

```python
elif in_label:
    # If previous line didn't end with continuation, we've left the LABEL block
    if not label_lines[-1].endswith("\\"):
        break
    label_lines.append(stripped)
```

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

Comment on lines +239 to +250
def test_version_arg_removed_not_merely_commented(dockerfile_name: str = "backend.Dockerfile") -> None:
"""Regression: the VERSION ARG is not present even as a comment."""
content = read_dockerfile(dockerfile_name)
# The arg must not appear as an active instruction anywhere
active_lines = [
line for line in content.splitlines() if not line.strip().startswith("#")
]
active_content = "\n".join(active_lines)
assert not re.search(r"^\s*ARG\s+VERSION\b", active_content, re.MULTILINE), (
"backend.Dockerfile: ARG VERSION must not appear as an active (non-comment) "
"instruction"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

P2 Test with default parameter is redundant and pytest-fragile

test_version_arg_removed_not_merely_commented uses a default function parameter (dockerfile_name: str = "backend.Dockerfile") to act as a standalone test. Pytest will use the default value since dockerfile_name is not a registered fixture, so collection won't crash — but this is an unusual pattern that some linters and pytest plugins may flag.

More importantly, this test is almost entirely redundant with test_no_arg_version_in_dockerfile, which already covers all 7 Dockerfiles with @pytest.mark.parametrize. The only difference is that this version strips comment lines first, but since test_no_arg_version_in_dockerfile also uses re.MULTILINE and comment lines would not match ^\s*ARG\s+VERSION\b anyway (a comment line starts with #, not whitespace followed by ARG), the comment-stripping step adds no meaningful extra coverage.

Consider removing this test, or replacing it with a parametrized version that covers all Dockerfiles if the comment-stripping logic is intentional.

Prompt To Fix With AI
This is a comment left during a code review.
Path: docker/tests/test_dockerfiles.py
Line: 239-250

Comment:
**Test with default parameter is redundant and pytest-fragile**

`test_version_arg_removed_not_merely_commented` uses a default function parameter (`dockerfile_name: str = "backend.Dockerfile"`) to act as a standalone test. Pytest will use the default value since `dockerfile_name` is not a registered fixture, so collection won't crash — but this is an unusual pattern that some linters and pytest plugins may flag.

More importantly, this test is almost entirely redundant with `test_no_arg_version_in_dockerfile`, which already covers all 7 Dockerfiles with `@pytest.mark.parametrize`. The only difference is that this version strips comment lines first, but since `test_no_arg_version_in_dockerfile` also uses `re.MULTILINE` and comment lines would not match `^\s*ARG\s+VERSION\b` anyway (a comment line starts with `#`, not whitespace followed by `ARG`), the comment-stripping step adds no meaningful extra coverage.

Consider removing this test, or replacing it with a parametrized version that covers all Dockerfiles if the comment-stripping logic is intentional.

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

Comment on lines +271 to +288
@pytest.mark.parametrize("dockerfile_name", ALL_DOCKERFILES)
def test_worker_unified_distinct_base_image(dockerfile_name: str) -> None:
"""Verify worker-unified uses python:3.12.9-slim while others use python:3.12-slim-trixie."""
content = read_dockerfile(dockerfile_name)
match = re.search(
r"^FROM\s+(\S+)\s+AS\s+base\b", content, re.MULTILINE | re.IGNORECASE
)
assert match is not None
actual_image = match.group(1)
if dockerfile_name == "worker-unified.Dockerfile":
assert actual_image == "python:3.12.9-slim", (
"worker-unified.Dockerfile must use python:3.12.9-slim as base image"
)
else:
assert actual_image == "python:3.12-slim-trixie", (
f"{dockerfile_name}: non-worker-unified Dockerfiles must use "
"python:3.12-slim-trixie as base image"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

P2 test_worker_unified_distinct_base_image duplicates test_base_stage_from_instruction

Both test_base_stage_from_instruction (parametrized) and test_worker_unified_distinct_base_image (also parametrized over all 7 Dockerfiles) verify the exact same thing: the base image in the FROM ... AS base instruction for each Dockerfile. The duplicate assertion adds CI overhead (7 extra parametrized test runs) without additional coverage.

Consider removing test_worker_unified_distinct_base_image and relying on test_base_stage_from_instruction + EXPECTED_BASE_IMAGES instead, since that dict already encodes the per-Dockerfile expectations (including worker-unified's distinct python:3.12.9-slim image).

Prompt To Fix With AI
This is a comment left during a code review.
Path: docker/tests/test_dockerfiles.py
Line: 271-288

Comment:
**`test_worker_unified_distinct_base_image` duplicates `test_base_stage_from_instruction`**

Both `test_base_stage_from_instruction` (parametrized) and `test_worker_unified_distinct_base_image` (also parametrized over all 7 Dockerfiles) verify the exact same thing: the base image in the `FROM ... AS base` instruction for each Dockerfile. The duplicate assertion adds CI overhead (7 extra parametrized test runs) without additional coverage.

Consider removing `test_worker_unified_distinct_base_image` and relying on `test_base_stage_from_instruction` + `EXPECTED_BASE_IMAGES` instead, since that dict already encodes the per-Dockerfile expectations (including `worker-unified`'s distinct `python:3.12.9-slim` image).

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

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