Skip to content

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Sep 5, 2025

Description

LCORE-574: unit tests for customization

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Related Tickets & Documents

  • Related Issue #LCORE-574

Summary by CodeRabbit

  • Tests
    • Expanded coverage for configuration customization and system-prompt handling: validation of prompt file paths and loading content from single- and multi-line prompt files.
  • Chores
    • Added test resources for system prompts to support new test scenarios.

No user-facing changes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 5, 2025

Walkthrough

Adds two test resource files containing single-line and multiline system prompts and new unit tests for a Customization model that validate default flags, path validation, and loading prompt content from provided file paths.

Changes

Cohort / File(s) Summary
Test resources (system prompts)
tests/configuration/system_prompt.txt, tests/configuration/multiline_system_prompt.txt
Add plain-text fixtures: a single-line system prompt and a multiline OpenShift Lightspeed prompt used by tests.
Unit tests for Customization
tests/unit/models/test_config.py
Add tests for models.config.Customization: default values, disabled flag behavior, validation error for non-file paths, and loading single- and multi-line prompt content from valid file paths.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Test
  participant Customization
  participant FS as FileSystem

  Test->>Customization: instantiate Customization(system_prompt_path=path?)
  alt system_prompt_path provided
    Customization->>FS: stat(path) / is_file?
    alt not a file
      Customization-->>Test: raise ValidationError("Path does not point to a file")
    else file exists
      FS-->>Customization: read file contents
      Customization-->>Test: instance with system_prompt set to file contents
    end
  else no path provided
    Customization-->>Test: instance with system_prompt=None
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • manstis

Poem

A rabbit reads the prompts by night,
Paths and lines brought into light.
If not a file I gently warn,
If many lines, I greet the morn.
Tests hop in — all tidy, tight. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tisnik tisnik force-pushed the lcore-574-unit-tests-for-customization branch from e0cd8d9 to f8d4365 Compare September 5, 2025 06:40
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
tests/configuration/multiline_system_prompt.txt (1)

1-15: Avoid time-sensitive facts in fixtures.

Hardcoding “latest version is 4.19” will age and may cause churn when updating fixtures. Prefer a timeless phrasing.

Apply this diff:

- - The latest version of OpenShift is 4.19.
+ - OpenShift ships frequent minor releases; avoid claiming a specific "latest" version in static prompts.
tests/unit/models/test_config.py (3)

1170-1185: Good coverage for default/disabled states; add an interaction case.

Consider verifying behavior when both disable_query_system_prompt=True and a system_prompt_path are provided (should the path be ignored or error?). This guards against ambiguous configurations.

Proposed addition inside this test:

     with subtests.test(msg="System prompt is disabled"):
         c = Customization(disable_query_system_prompt=True)
         assert c is not None
         assert c.disable_query_system_prompt is True
         assert c.system_prompt_path is None
         assert c.system_prompt is None

+    with subtests.test(msg="Disabled overrides provided path (ignore or error)"):
+        # If spec says "ignore", expect None; if it should "error", expect ValidationError.
+        try:
+            c = Customization(
+                disable_query_system_prompt=True,
+                system_prompt_path="tests/configuration/system_prompt.txt",
+            )
+            # If constructible, assert prompt/path are not used.
+            assert c.system_prompt_path is None
+            assert c.system_prompt is None
+        except ValidationError:
+            # Also acceptable if the model enforces exclusivity.
+            pass

1187-1191: Nice negative test; consider directory-path case too.

Mirroring your TLS tests, add a case where system_prompt_path points to a directory to ensure the validator rejects it.

Apply:

 def test_service_customization_wrong_system_prompt_path() -> None:
     """Check the service customization class."""
     with pytest.raises(ValidationError, match="Path does not point to a file"):
         _ = Customization(system_prompt_path="/path/does/not/exists")
+
+    # directory instead of file
+    with pytest.raises(ValidationError, match="Path does not point to a file"):
+        _ = Customization(system_prompt_path="tests/")

1193-1211: Make fixture paths robust to working directory.

Deriving paths from this file avoids failures when pytest is invoked from non-repo roots.

Apply:

 def test_service_customization_correct_system_prompt_path(subtests) -> None:
     """Check the service customization class."""
-    with subtests.test(msg="One line system prompt"):
-        # pass a file containing system prompt
-        c = Customization(system_prompt_path="tests/configuration/system_prompt.txt")
-        assert c is not None
-        # check that the system prompt has been loaded from the provided file
-        assert c.system_prompt == "This is system prompt."
+    base_dir = Path(__file__).resolve().parents[2] / "configuration"
+
+    with subtests.test(msg="One line system prompt"):
+        c = Customization(system_prompt_path=str(base_dir / "system_prompt.txt"))
+        assert c is not None
+        assert c.system_prompt == "This is system prompt."
 
     with subtests.test(msg="Multi line system prompt"):
-        # pass a file containing system prompt
-        c = Customization(
-            system_prompt_path="tests/configuration/multiline_system_prompt.txt"
-        )
+        c = Customization(system_prompt_path=str(base_dir / "multiline_system_prompt.txt"))
         assert c is not None
         # check that the system prompt has been loaded from the provided file
         assert "You are OpenShift Lightspeed" in c.system_prompt
         assert "Here are your instructions" in c.system_prompt
         assert "Here are some basic facts about OpenShift" in c.system_prompt
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2c7b365 and f8d4365.

📒 Files selected for processing (3)
  • tests/configuration/multiline_system_prompt.txt (1 hunks)
  • tests/configuration/system_prompt.txt (1 hunks)
  • tests/unit/models/test_config.py (2 hunks)
🧰 Additional context used
🪛 LanguageTool
tests/configuration/multiline_system_prompt.txt

[grammar] ~1-~1: There might be a mistake here.
Context: ...t assistant for question-answering tasks related to the OpenShift container orche...

(QB_NEW_EN)

tests/configuration/system_prompt.txt

[grammar] ~1-~1: There might be a mistake here.
Context: This is system prompt.

(QB_NEW_EN)


[grammar] ~1-~1: There might be a mistake here.
Context: This is system prompt.

(QB_NEW_EN)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-pr
  • GitHub Check: e2e_tests
🔇 Additional comments (2)
tests/configuration/system_prompt.txt (1)

1-1: Fixture content LGTM; keep stable for exact-match assertion.

This string is intentionally simple and is asserted verbatim in tests. Avoid “fixing” grammar, as it would break the equality check.

tests/unit/models/test_config.py (1)

38-39: New import usage is appropriate.

Customization is exercised by tests below; import placement is fine.

@tisnik tisnik force-pushed the lcore-574-unit-tests-for-customization branch from f8d4365 to 9744ee5 Compare September 5, 2025 06:58
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (10)
tests/configuration/system_prompt.txt (1)

1-1: Grammar nit: add missing article for clarity (fixture).

Optional polish; if you change it, also update assertions in tests that compare the exact string.

Apply this diff if you want to fix the grammar:

-This is system prompt.
+This is a system prompt.
tests/configuration/multiline_system_prompt.txt (2)

13-13: Avoid hardcoding a time-sensitive version in test data.

Embedding “latest version is 4.19” will age quickly and can confuse future readers. Prefer a non-committal phrasing.

Suggested change:

-- The latest version of OpenShift is 4.19.
+- The latest version of OpenShift changes frequently; refer to official docs for the current release.

10-10: Rephrase unrealistic capability claim.

“Forbid mentioning last update” is fine, but “You have the most recent information” is brittle as a general rule. Consider neutral wording.

Suggested change:

-Do not mention your last update. You have the most recent information on OpenShift.
+Avoid mentioning a knowledge cutoff or “last update.”
tests/unit/models/test_config.py (7)

1191-1191: Prefer Path objects over raw strings for paths (consistency with rest of tests).

Apply:

-            system_prompt_path="tests/configuration/system_prompt.txt",
+            system_prompt_path=Path("tests/configuration/system_prompt.txt"),

1195-1195: Make the equality robust to trailing newline in the fixture.

If loader behavior changes (e.g., stops stripping), this stays green.

Apply:

-        assert c.system_prompt == "This is system prompt."
+        assert c.system_prompt.strip() == "This is system prompt."

1201-1204: Use tmp_path to avoid OS-specific absolute paths in negative test.

Keeps the test portable and hermetic.

Apply:

-def test_service_customization_wrong_system_prompt_path() -> None:
+def test_service_customization_wrong_system_prompt_path(tmp_path) -> None:
     """Check the service customization class."""
-    with pytest.raises(ValidationError, match="Path does not point to a file"):
-        _ = Customization(system_prompt_path="/path/does/not/exists")
+    with pytest.raises(ValidationError, match="Path does not point to a file"):
+        _ = Customization(system_prompt_path=tmp_path / "no-such-file.txt")

1210-1210: Nit: use Path for consistency.

Apply:

-        c = Customization(system_prompt_path="tests/configuration/system_prompt.txt")
+        c = Customization(system_prompt_path=Path("tests/configuration/system_prompt.txt"))

1213-1213: Same robustness tweak: strip newline in assertion.

Apply:

-        assert c.system_prompt == "This is system prompt."
+        assert c.system_prompt.strip() == "This is system prompt."

1218-1219: Nit: use Path for consistency.

Apply:

-        c = Customization(
-            system_prompt_path="tests/configuration/multiline_system_prompt.txt"
+        c = Customization(
+            system_prompt_path=Path("tests/configuration/multiline_system_prompt.txt")
         )

1170-1224: Optional: add a directory-path negative case for completeness.

Covers the “path exists but is not a file” branch exercised elsewhere (TLS tests).

Add the following test (placement anywhere in this file is fine):

def test_service_customization_system_prompt_path_points_to_directory() -> None:
    with pytest.raises(ValidationError, match="Path does not point to a file"):
        _ = Customization(system_prompt_path=Path("tests/"))
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f8d4365 and 9744ee5.

📒 Files selected for processing (3)
  • tests/configuration/multiline_system_prompt.txt (1 hunks)
  • tests/configuration/system_prompt.txt (1 hunks)
  • tests/unit/models/test_config.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/unit/models/test_config.py (1)
src/models/config.py (1)
  • Customization (416-431)
🪛 LanguageTool
tests/configuration/multiline_system_prompt.txt

[grammar] ~1-~1: There might be a mistake here.
Context: ...t assistant for question-answering tasks related to the OpenShift container orche...

(QB_NEW_EN)

tests/configuration/system_prompt.txt

[grammar] ~1-~1: There might be a mistake here.
Context: This is system prompt.

(QB_NEW_EN)


[grammar] ~1-~1: There might be a mistake here.
Context: This is system prompt.

(QB_NEW_EN)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-pr
  • GitHub Check: e2e_tests
🔇 Additional comments (3)
tests/unit/models/test_config.py (3)

38-38: LGTM: importing Customization where used.


1170-1198: Solid coverage for Customization defaults and disabled-mode semantics.

Nice use of subtests; behavior is clear and aligned with the model validator.


1170-1224: Confirmed get_attribute_from_file uses .rstrip() to trim trailing whitespace/newlines, so exact‐value assertions remain valid.

@tisnik tisnik merged commit 218c82e into lightspeed-core:main Sep 5, 2025
19 checks passed
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