Skip to content

Dev#140

Merged
theaskou merged 32 commits into
mainfrom
dev
Apr 18, 2025
Merged

Dev#140
theaskou merged 32 commits into
mainfrom
dev

Conversation

@Aleksandergreg
Copy link
Copy Markdown
Member

@Aleksandergreg Aleksandergreg commented Apr 16, 2025

Description

Added loggin for search, and made so that this gets saved in a Docker volume. Added the log files to gitignore, so these doesn't get shared to the public. Critical business information hihi
Related Issue:
If applicable, please reference the issue number that this pull request fixes:
Fixes #124 #137

Type of Change

Please check the type(s) of changes your code introduces:

  • Bug fix: Non-breaking change which fixes an issue.
  • New feature: Non-breaking change which adds functionality.
  • Breaking change: Fix or feature that would cause existing functionality to change.
  • Documentation update: Changes to documentation only.

Checklist

Before creating this pull request, please ensure that your code meets the following requirements:

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.

Summary by CodeRabbit

  • New Features

    • Introduced end-to-end (E2E) testing using Playwright, including test configuration, scripts, and workflows.
    • Added comprehensive Playwright tests for search, registration, login, about, and weather features.
    • Added a new SQL schema setup script for test databases.
  • Bug Fixes

    • Ensured proper creation and permissions for the log directory in the Sinatra app container.
  • Chores

    • Updated CI workflows to separate Ruby tests, Ruby linting, and Dockerfile linting.
    • Updated ignore patterns and added .gitignore for test artifacts.
    • Improved Docker Compose configuration with a dedicated log volume.
  • Refactor

    • Renamed helper methods for consistency.
    • Updated session secret assignment logic for clarity.
  • Revert

    • Removed route handlers for standard HTML pages from the Sinatra app.

@deepsource-io
Copy link
Copy Markdown

deepsource-io Bot commented Apr 16, 2025

Here's the code health analysis summary for commits de9dfaa..7f5aa57. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Ruby LogoRuby✅ SuccessView Check ↗
DeepSource Docker LogoDocker✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2025

Walkthrough

This set of changes introduces end-to-end Playwright tests for the Sinatra application, including new test scripts for core user flows such as about, login, registration, search, and weather. Supporting configuration files for Playwright and Node.js dependencies are added. The .gitignore is updated to exclude log and Playwright output files. The CI workflow is refactored into separate jobs for testing and linting, and a new Playwright workflow is introduced. The production Docker Compose setup gains a dedicated log volume, with corresponding changes to entrypoint scripts for permissions. Minor refactors and removals are made to route files and helper method names.

Changes

File(s) Change Summary
.github/workflows/ci.yaml Refactored into three jobs: Ruby tests, RuboCop linting, and Dockerfile linting; uses official Hadolint action; improved dependency setup and caching.
.github/workflows/continuous_delivery.yml Removed "feature/refactor" from workflow triggers; minor whitespace adjustment.
.github/workflows/playwright.yml Added new workflow to run Playwright end-to-end tests on push, PR, and manual triggers; sets up Ruby, Node.js, SQLite, and runs Playwright tests, uploading HTML reports.
.gitignore, sinatra/tests/.gitignore Updated to ignore additional log file patterns and Playwright/node-related output in the tests directory.
sinatra/docker-compose.prod.yml, sinatra/docker-entrypoint.sh Added and mounted a named volume sinatra_logs to /app/log; entrypoint ensures /app/log exists and is owned by appuser.
sinatra/app.rb, sinatra/benchmark_search.rb Minor refactors: session secret assignment separated into a variable; SQL query formatting improved; logger comment moved.
sinatra/helpers/application_helpers.rb, sinatra/routes/api.rb, sinatra/routes/pages.rb Renamed helper method get_cached_forecast to cached_forecast; updated internal calls; removed routes/pages.rb and all its route handlers.
sinatra/schema_test.sql Added new SQL schema for users and pages tables, with default records for testing.
sinatra/tests/e2e/about.spec.js, login.spec.js, register.spec.js, search.spec.js, weather.spec.js Added new Playwright end-to-end test scripts for about, login, registration, search, and weather features, covering both success and error scenarios.
sinatra/tests/package.json, playwright.config.js Added Node.js package and Playwright configuration for running and managing end-to-end tests.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant GitHub Actions
    participant Sinatra App
    participant Playwright

    Developer->>GitHub Actions: Push/PR to main/dev or manual dispatch
    GitHub Actions->>Sinatra App: Build and start app (test DB)
    GitHub Actions->>Playwright: Install dependencies, run tests
    Playwright->>Sinatra App: Simulate user actions (search, login, register, etc.)
    Sinatra App-->>Playwright: Responds to simulated requests
    Playwright->>GitHub Actions: Uploads HTML test report
Loading

Assessment against linked issues

Objective Addressed Explanation
Log user search queries with timestamp using lightweight logging (Logger/file/SQLite), persistent storage, easy access (Issue #124) Logging code is removed with the deletion of routes/pages.rb; unclear if logging remains elsewhere.
Logging does not significantly impact search performance (Issue #124) Cannot determine performance impact as logging implementation is not visible in the current changes.
Document the logging setup, including how to access the logs (Issue #124) No documentation changes regarding log access are present in this PR.

Possibly related PRs

  • Feature/e2e debug #143: Also adds the Playwright end-to-end test workflow, indicating directly related changes in test automation.
  • Dev #131: Introduces the routes/pages.rb file, which this PR removes, indicating a direct relationship in route management.
  • Feature/logging #139: Modifies the same Docker Compose and entrypoint files for logging support, closely related to the log volume and directory changes here.

Suggested reviewers

  • theaskou

Poem

In the warren of code where the carrots grow bright,
New tests now hop in, both by day and by night.
With Playwright they scurry, through login and search,
Ensuring each feature won’t leave us in lurch.
Logs find new burrows, and helpers rename—
This rabbit’s quite proud of a codebase less tame!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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.

Documentation and Community

  • 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.

Copy link
Copy Markdown

@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 (1)
.gitignore (1)

58-58: Remove duplicate ignore pattern for log files.

The *.log.* pattern is already present at line 60. Keeping only one instance is sufficient and keeps the .gitignore file clean.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de9dfaa and f056200.

📒 Files selected for processing (4)
  • .github/workflows/continuous_delivery.yml (1 hunks)
  • .gitignore (1 hunks)
  • sinatra/docker-compose.prod.yml (2 hunks)
  • sinatra/docker-entrypoint.sh (1 hunks)
🔇 Additional comments (3)
sinatra/docker-entrypoint.sh (1)

9-10: Log directory initialization and permissions are handled correctly.

The script now ensures /app/log exists and is owned by appuser, which is necessary for persistent logging in Docker.

sinatra/docker-compose.prod.yml (1)

8-8: Persistent log volume is correctly configured.

Mounting sinatra_logs at /app/log and defining the volume ensures logs are persisted as intended.

Also applies to: 37-37

.github/workflows/continuous_delivery.yml (1)

5-5: Workflow trigger branch list updated appropriately.

The workflow will now only trigger on pushes to "main" and "dev", which matches the intended branch policy.

Copy link
Copy Markdown

@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 (1)
.github/workflows/continuous_delivery.yml (1)

21-21: Remove trailing spaces for YAML cleanliness.

There is a trailing space at line 21. While this does not break the workflow, it's best practice to remove unnecessary whitespace to avoid potential YAML parsing issues in stricter environments.

-        with: 
+        with:
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 21-21: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f056200 and 16c22ef.

📒 Files selected for processing (2)
  • .github/workflows/ci.yaml (1 hunks)
  • .github/workflows/continuous_delivery.yml (2 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/continuous_delivery.yml

[error] 21-21: trailing spaces

(trailing-spaces)

🔇 Additional comments (3)
.github/workflows/continuous_delivery.yml (1)

5-5: Branch trigger update is correct.

Limiting the workflow to "main" and "dev" is clear and aligns with standard CD practices.

.github/workflows/ci.yaml (2)

8-8: Addition of workflow_dispatch is a good practice.

Allows manual triggering of CI, which is helpful for maintainers.


11-90: CI workflow modularization and improvements are well executed.

Splitting jobs for tests, Ruby linting, and Dockerfile linting increases clarity and maintainability. Use of official actions and explicit dependency installation is robust.

Copy link
Copy Markdown

@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 (1)
sinatra/helpers/application_helpers.rb (1)

78-105: Method renaming follows Ruby conventions

Renaming from get_cached_forecast to cached_forecast aligns with Ruby's idiomatic style, where methods that return values typically don't use a get_ prefix. The implementation logic remains unchanged.

The RuboCop static analysis identified this method as having high ABC complexity (Assignment Branch Condition size). Consider refactoring this method into smaller, more focused methods for better maintainability.

🧰 Tools
🪛 RuboCop (1.73)

[convention] 78-105: Assignment Branch Condition size for cached_forecast is too high. [<5, 24, 6> 25.24/23]

(Metrics/AbcSize)


[convention] 89-99: Do not use unless with else. Rewrite these with the positive case first.

(Style/UnlessElse)

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16c22ef and fde8af3.

📒 Files selected for processing (5)
  • sinatra/app.rb (2 hunks)
  • sinatra/benchmark_search.rb (1 hunks)
  • sinatra/helpers/application_helpers.rb (1 hunks)
  • sinatra/routes/api.rb (1 hunks)
  • sinatra/routes/pages.rb (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • sinatra/benchmark_search.rb
🧰 Additional context used
🧬 Code Graph Analysis (2)
sinatra/routes/api.rb (1)
sinatra/helpers/application_helpers.rb (1)
  • cached_forecast (78-105)
sinatra/routes/pages.rb (1)
sinatra/helpers/application_helpers.rb (1)
  • cached_forecast (78-105)
🪛 RuboCop (1.73)
sinatra/helpers/application_helpers.rb

[convention] 78-105: Assignment Branch Condition size for cached_forecast is too high. [<5, 24, 6> 25.24/23]

(Metrics/AbcSize)

🔇 Additional comments (4)
sinatra/app.rb (2)

25-26: Improved session secret generation code

Breaking out the default secret generation to a separate variable improves readability while maintaining the same security level with SecureRandom.hex(32).


71-72: Improved comment placement

Moving the comment about log rotation directly above the logger initialization line creates a clearer connection between the documentation and the code it describes.

sinatra/routes/api.rb (1)

45-45: Updated method call to match renamed helper

The change from get_cached_forecast to cached_forecast maintains consistency with the renamed helper method in application_helpers.rb.

sinatra/routes/pages.rb (1)

53-53: Updated method call to match renamed helper

The change from get_cached_forecast to cached_forecast maintains consistency with the renamed helper method in application_helpers.rb.

Copy link
Copy Markdown

@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: 1

🧹 Nitpick comments (11)
sinatra/tests/e2e/login.spec.js (2)

16-21: Consider using consistent selector approaches.

While the test logic works well, there's an inconsistency in selector usage. The form rendering test uses role-based selectors, but this test uses direct CSS selectors.

For consistency, consider using role-based selectors here as well:

- await page.fill('input[name="username"]', 'wronguser');
- await page.fill('input[name="password"]', 'badpass');
- await page.click('input[type="submit"]');
+ await page.getByRole('textbox', { name: /username/i }).fill('wronguser');
+ await page.getByRole('textbox', { name: /password/i }).fill('badpass');
+ await page.getByRole('button', { name: /log in/i }).click();

23-32: Use toHaveURL instead of direct URL comparison.

The skipped test correctly handles the test case that requires seeded data. However, the URL verification could be improved.

- expect(page.url()).toBe('/');
+ await expect(page).toHaveURL('/');

Using toHaveURL() is preferred as it's an async assertion that waits for the condition to be met, which is more reliable in end-to-end tests.

sinatra/tests/e2e/register.spec.js (1)

3-6: Fix indentation inconsistency.

The indentation in the beforeEach block uses 8 spaces while the rest of the file uses 2 spaces.

 test.describe('Registration Page', () => {
-    test.beforeEach(async ({ page }) => {
-        await page.goto('/register');
-      });
+  test.beforeEach(async ({ page }) => {
+    await page.goto('/register');
+  });
sinatra/tests/e2e/search.spec.js (1)

33-45: Fix duplicate comment on line 42.

There's a duplicate comment that should be updated to reflect the actual check being performed.

 // Check the URL updates with the search term
 expect(page.url()).toContain(`?q=${SEARCH_TERMS.invalid}`);

-// Check the URL updates with the search term
+// Check that no search results are found
 await expect(page.locator('.search-result-title')).toHaveCount(0);
 await expect(page.locator('#results')).toBeEmpty();
sinatra/tests/e2e/weather.spec.js (2)

8-8: Consider expanding error status code checking

The test only accounts for HTTP status codes 200 and 503, but there might be other valid error codes like 400, 404, or 429 (rate limiting) that could be returned by the weather API.

- expect([200, 503]).toContain(status);
+ expect([200, 400, 404, 429, 503]).toContain(status);

39-39: Remove trailing whitespace

There's an unnecessary trailing space after the semicolon.

- expect(itemCount).toBeGreaterThan(0); 
+ expect(itemCount).toBeGreaterThan(0);
sinatra/tests/playwright.config.js (2)

17-17: Consider making the database path configurable via environment variable

The database path is hardcoded in the command. For improved flexibility, consider reading it from an environment variable with a default fallback.

- command: 'DATABASE_PATH=./test/test_whoknows.db bundle exec rackup -p 4568',
+ command: 'DATABASE_PATH=${TEST_DB_PATH:-./test/test_whoknows.db} bundle exec rackup -p 4568',

38-38: Fix formatting in projects array closing

There's a formatting issue with the closing bracket of the projects array.

- },]
+ }
+ ]
.github/workflows/playwright.yml (3)

29-31: Consider using a dedicated SQL file for FTS table population

Line 31 contains a direct SQLite command to populate the full-text search table. For better maintainability, consider moving this to a dedicated SQL file like you did with schema_test.sql and fts5.sql.

- sqlite3 test/test_whoknows.db "INSERT INTO pages_fts(rowid,content,language) SELECT rowid,content,language FROM pages;"
+ sqlite3 test/test_whoknows.db < fts_populate.sql

And create a new file sinatra/fts_populate.sql with:

INSERT INTO pages_fts(rowid,content,language) SELECT rowid,content,language FROM pages;

40-53: Decide on server startup strategy

There are commented-out sections for starting the Sinatra app and waiting for it to be ready. Since the Playwright config already handles starting the server, either remove these comments or document why they're kept.

If these are no longer needed, consider removing them to keep the workflow file clean. If they're kept for reference, add a comment explaining why.


80-86: Decide on report deployment strategy

The GitHub Pages deployment section is commented out. If this is a planned feature, add a TODO comment with the next steps needed to implement it. If it's not planned, consider removing these comments.

If you intend to implement this feature later, consider adding a TODO comment:

# TODO: Implement GitHub Pages deployment for Playwright reports once permissions are configured
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fde8af3 and dc87e22.

⛔ Files ignored due to path filters (1)
  • sinatra/tests/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • .github/workflows/playwright.yml (1 hunks)
  • sinatra/schema_test.sql (1 hunks)
  • sinatra/tests/.gitignore (1 hunks)
  • sinatra/tests/e2e/about.spec.js (1 hunks)
  • sinatra/tests/e2e/login.spec.js (1 hunks)
  • sinatra/tests/e2e/register.spec.js (1 hunks)
  • sinatra/tests/e2e/search.spec.js (1 hunks)
  • sinatra/tests/e2e/weather.spec.js (1 hunks)
  • sinatra/tests/package.json (1 hunks)
  • sinatra/tests/playwright.config.js (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • sinatra/tests/.gitignore
  • sinatra/tests/package.json
  • sinatra/schema_test.sql
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: e2e
  • GitHub Check: e2e
🔇 Additional comments (10)
sinatra/tests/e2e/about.spec.js (1)

1-8: LGTM! Well-structured test for the about page.

This test effectively validates the critical elements of the about page: title, mission heading, and descriptive text. The selectors used are appropriate and follow Playwright best practices.

sinatra/tests/e2e/login.spec.js (1)

4-14: LGTM! Well-structured test setup and form rendering test.

Good organization with test.beforeEach for the login page navigation. The form rendering test uses appropriate role-based selectors to verify all form elements.

sinatra/tests/e2e/register.spec.js (3)

8-18: LGTM! Well-structured registration form test.

The form rendering test appropriately checks for all required elements with clear sections for the heading, inputs, and submit button.


20-30: LGTM! Good validation test for password mismatch.

This test effectively validates the password mismatch error case with appropriate error message verification.


32-42: LGTM! Strong approach to testing successful registration.

Using Date.now() to generate unique usernames is a good practice to avoid test data conflicts. The redirect and success message verification provide good end-to-end validation.

sinatra/tests/e2e/search.spec.js (2)

8-11: LGTM! Good use of constants for search terms.

Defining search terms as constants improves readability and maintainability.


15-31: LGTM! Comprehensive test for valid search results.

The test covers all the critical aspects of searching with a valid term: URL parameters, result count, and content verification.

sinatra/tests/e2e/weather.spec.js (1)

1-42: Well-structured test suite with comprehensive error handling

The test suite effectively covers both the API and UI aspects of the weather feature, handling both success and error scenarios appropriately. This is excellent test coverage.

sinatra/tests/playwright.config.js (1)

1-39: Well-configured Playwright setup with cross-browser testing

The configuration properly sets up parallel test execution, CI-specific settings, and multiple browser targets. Good job including all three major browser engines.

.github/workflows/playwright.yml (1)

1-87: Well-structured GitHub Actions workflow for E2E testing

The workflow correctly sets up all necessary dependencies and configurations for running the Playwright tests, including database preparation and artifact uploading.

Comment on lines +11 to +12
# permissions:
# contents: write # Needed for deploying to GitHub Pages
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Decide on GitHub Pages deployment strategy

The permissions section is commented out. If you plan to deploy reports to GitHub Pages in the future, consider either removing these comments or implementing the feature properly.


🌐 Web query:

How to deploy Playwright reports to GitHub Pages?

💡 Result:

How to Deploy Playwright Reports to GitHub Pages

Deploying Playwright HTML reports to GitHub Pages is a practical way to make your browser test results easily accessible to your team or stakeholders. Below is a step-by-step guide to automate this process using GitHub Actions.


1. Enable GitHub Pages on Your Repository

  • Create a gh-pages branch (you can do this manually or let an action manage it)[2][5].
  • In the repository settings, enable GitHub Pages and select the gh-pages branch as the source[2][5].

2. Use the Playwright HTML Reporter

  • Ensure you are using Playwright version 1.17.0 or newer, as the HTML reporter generates a static site[5][6].

  • In your test command, specify the HTML reporter:

    npx playwright test --reporter=html

    This creates a playwright-report directory containing static HTML files[5][6].


3. Set Up a GitHub Actions Workflow

Add or update a GitHub Actions workflow .github/workflows/playwright.yml to:

  • Install dependencies and browsers
  • Run Playwright tests and generate the report
  • Deploy the playwright-report folder to GitHub Pages using the popular peaceiris/actions-gh-pages GitHub Action[1][5].

Example workflow snippet:

name: Playwright Tests and Publish Report

on:
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18
      - name: Install dependencies
        run: npm ci
      - name: Install Playwright browsers
        run: npx playwright install --with-deps
      - name: Run Playwright tests
        run: npx playwright test --reporter=html
      - name: Deploy report to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./playwright-report

This workflow:

  • Runs the tests and generates playwright-report
  • Publishes playwright-report to the gh-pages branch, updating your GitHub Pages site[1][5]

4. Accessing Your Report

After the workflow runs, your report will be accessible at:

https://<username>.github.io/<repository>/

You can further organize reports by build number, branch, or run ID by customizing the publish_dir or artifacts paths[1][2].


Additional Tips

  • You can use GitHub Actions to display the report URL in the job summary for convenient sharing[1][2].
  • For merging reports from different shards or jobs, use npx playwright merge-reports before publishing[1].
  • The HTML report supports filters and trace viewing directly in the browser[6].

Summary Table

Step Command/Action
Enable GitHub Pages Set source branch to gh-pages
Generate Playwright HTML report npx playwright test --reporter=html
Deploy with GitHub Actions Use peaceiris/actions-gh-pages to publish playwright-report
Access report https://<username>.github.io/<repo>/

This approach ensures that your Playwright test reports are always available as a static site, making test results transparent and easily distributable[1][2][5][6][7].

Citations:


Enable GitHub Pages deployment in your Playwright workflow

To push the generated HTML report to GitHub Pages you’ll need to:

• Un‑comment and configure permissions at the top of .github/workflows/playwright.yml
• Install and use a “deploy to gh‑pages” action (e.g. peaceiris/actions-gh-pages) after npx playwright test --reporter=html

Suggested changes:

 name: Playwright Tests and Publish Report
+permissions:
+  contents: write   # allow pushing to gh-pages

 on:
   push:
     branches: [main]

 jobs:
   test:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v3
@@
       - name: Run Playwright tests
         run: npx playwright test --reporter=html
+      - name: Deploy report to GitHub Pages
+        uses: peaceiris/actions-gh-pages@v3
+        with:
+          github_token: ${{ secrets.GITHUB_TOKEN }}
+          publish_dir: ./playwright-report

• If you’re not ready to publish reports yet, remove the stale comments entirely.
• Otherwise add the full deployment job as shown above so your reports land on the gh-pages branch and appear at https://.github.io//.

Copy link
Copy Markdown

@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: 2

♻️ Duplicate comments (1)
.github/workflows/playwright.yml (1)

11-13: Decision needed: GitHub Pages deployment

The permissions section for GitHub Pages deployment is commented out. Either implement the feature or remove these comments.

This was mentioned in a previous review. Please decide whether to:

  1. Fully implement the GitHub Pages reporting feature (uncomment this section and lines 80-86)
  2. Remove all commented GitHub Pages related code for clarity
🧹 Nitpick comments (9)
.github/workflows/continuous_delivery.yml (1)

21-21: Remove trailing whitespace.

There's trailing whitespace after "with:" which should be removed to maintain clean YAML formatting.

-        with: 
+        with:
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 21-21: trailing spaces

(trailing-spaces)

sinatra/helpers/application_helpers.rb (1)

78-105: Consider breaking down the method for improved maintainability.

The method has a high complexity score (ABC size of 25.24/23). Consider refactoring into smaller helper methods for better maintainability and testability.

For example:

 # Retrieves forecast data, using cache if valid, otherwise fetches fresh data.
 def cached_forecast
   cache = settings.forecast_cache
   expiration = settings.forecast_cache_expiration

   # Check cache validity using UTC time for comparison
   # Use Time.now.utc for consistent time zone handling
   if cache.nil? || expiration < Time.now.utc
-    logger.info "Weather forecast cache miss or expired. Fetching new data."
-    new_forecast = fetch_forecast
-
-    # Update cache only if the fetch was successful (no 'error' key)
-    unless new_forecast.key?('error')
-      settings.forecast_cache = new_forecast
-      # Use Time.now.utc when setting the new expiration time
-      settings.forecast_cache_expiration = Time.now.utc + 3600 # 1 hour cache
-      logger.info "Weather forecast cache updated."
-      return new_forecast # Return the newly fetched data
-    else
-      # Log failure but return the error hash from fetch_forecast
-      logger.warn "Failed to fetch new forecast data. Returning error."
-      return new_forecast
-    end
+    fetch_and_update_cache
   else
     # Cache hit, return cached data
     logger.debug "Weather forecast cache hit."
     return cache
   end
 end
+
+ # Helper method to fetch and update the forecast cache
+ def fetch_and_update_cache
+   logger.info "Weather forecast cache miss or expired. Fetching new data."
+   new_forecast = fetch_forecast
+
+   # Update cache only if the fetch was successful (no 'error' key)
+   unless new_forecast.key?('error')
+     update_forecast_cache(new_forecast)
+   else
+     # Log failure but return the error hash from fetch_forecast
+     logger.warn "Failed to fetch new forecast data. Returning error."
+   end
+   new_forecast
+ end
+
+ # Helper method to update the forecast cache
+ def update_forecast_cache(forecast)
+   settings.forecast_cache = forecast
+   # Use Time.now.utc when setting the new expiration time
+   settings.forecast_cache_expiration = Time.now.utc + 3600 # 1 hour cache
+   logger.info "Weather forecast cache updated."
+ end
🧰 Tools
🪛 RuboCop (1.73)

[convention] 78-105: Assignment Branch Condition size for cached_forecast is too high. [<5, 24, 6> 25.24/23]

(Metrics/AbcSize)


[convention] 89-99: Do not use unless with else. Rewrite these with the positive case first.

(Style/UnlessElse)

sinatra/schema_test.sql (1)

15-21: Consider adding search indexes to the pages table.

Since this project is focused on search functionality (DynaSearch), consider adding full-text search indexes to the pages table to improve search performance.

For SQLite, you could add:

-- Add FTS5 virtual table for searching pages
CREATE VIRTUAL TABLE IF NOT EXISTS pages_fts USING fts5(
  title, 
  content, 
  content='pages', 
  tokenize='porter unicode61'
);

-- Create triggers to keep FTS table in sync
CREATE TRIGGER IF NOT EXISTS pages_ai AFTER INSERT ON pages BEGIN
  INSERT INTO pages_fts(rowid, title, content) VALUES (new.rowid, new.title, new.content);
END;
sinatra/tests/e2e/search.spec.js (1)

33-45: Duplicate comment on lines 39-42

Line 42 repeats the same comment as line 39, but the actions in lines 43-44 are actually checking for no results.

     // Check the URL updates with the search term
     expect(page.url()).toContain(`?q=${SEARCH_TERMS.invalid}`);
 
-    // Check the URL updates with the search term
+    // Verify no results are displayed
     await expect(page.locator('.search-result-title')).toHaveCount(0);
     await expect(page.locator('#results')).toBeEmpty();
sinatra/tests/playwright.config.js (1)

16-21: Web server configuration uses hardcoded paths

The database path and port are hardcoded in the command. Consider using environment variables for these values to make the configuration more flexible.

   webServer: {
-    command: 'DATABASE_PATH=./test/test_whoknows.db bundle exec rackup -p 4568',
+    command: `DATABASE_PATH=${process.env.TEST_DB_PATH || './test/test_whoknows.db'} bundle exec rackup -p ${process.env.TEST_PORT || 4568}`,
     url: 'http://127.0.0.1:4568',
     cwd: '../',
     reuseExistingServer: !process.env.CI,
   },
sinatra/tests/e2e/weather.spec.js (1)

25-41: Well-implemented UI test with conditional assertions

The UI test properly handles both success and error states of the weather page by:

  1. Verifying the heading is always visible
  2. Conditionally testing either the error message or forecast items

This makes the test resilient to different API states without requiring mocks.

-      expect(itemCount).toBeGreaterThan(0); 
+      expect(itemCount).toBeGreaterThan(0);
.github/workflows/playwright.yml (3)

33-39: Remove trailing whitespace

There's a trailing space after bundler-cache: true on line 37.

-        bundler-cache: true 
+        bundler-cache: true
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 37-37: trailing spaces

(trailing-spaces)


40-54: Decide on Sinatra app startup approach

These commented steps for starting the Sinatra app suggest you've chosen a different approach (likely in the Playwright config). Consider removing these comments if they're no longer needed to keep the workflow file clean.


80-86: Clean up GitHub Pages deployment comments

The commented GitHub Pages deployment configuration contains doubly-commented lines (# #), indicating indecision or confusion. Either:

  1. Implement this feature completely (remove comments and configure correctly)
  2. Remove these lines entirely to keep the workflow file clean
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1399440 and 7f5aa57.

⛔ Files ignored due to path filters (1)
  • sinatra/tests/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (20)
  • .github/workflows/ci.yaml (1 hunks)
  • .github/workflows/continuous_delivery.yml (2 hunks)
  • .github/workflows/playwright.yml (1 hunks)
  • .gitignore (1 hunks)
  • sinatra/app.rb (2 hunks)
  • sinatra/benchmark_search.rb (1 hunks)
  • sinatra/docker-compose.prod.yml (2 hunks)
  • sinatra/docker-entrypoint.sh (1 hunks)
  • sinatra/helpers/application_helpers.rb (1 hunks)
  • sinatra/routes/api.rb (1 hunks)
  • sinatra/routes/pages.rb (1 hunks)
  • sinatra/schema_test.sql (1 hunks)
  • sinatra/tests/.gitignore (1 hunks)
  • sinatra/tests/e2e/about.spec.js (1 hunks)
  • sinatra/tests/e2e/login.spec.js (1 hunks)
  • sinatra/tests/e2e/register.spec.js (1 hunks)
  • sinatra/tests/e2e/search.spec.js (1 hunks)
  • sinatra/tests/e2e/weather.spec.js (1 hunks)
  • sinatra/tests/package.json (1 hunks)
  • sinatra/tests/playwright.config.js (1 hunks)
✅ Files skipped from review due to trivial changes (5)
  • sinatra/benchmark_search.rb
  • sinatra/routes/api.rb
  • sinatra/tests/.gitignore
  • sinatra/tests/package.json
  • sinatra/routes/pages.rb
🚧 Files skipped from review as they are similar to previous changes (5)
  • sinatra/docker-entrypoint.sh
  • .gitignore
  • sinatra/app.rb
  • sinatra/docker-compose.prod.yml
  • .github/workflows/ci.yaml
🧰 Additional context used
🧬 Code Graph Analysis (3)
sinatra/tests/playwright.config.js (5)
sinatra/tests/e2e/login.spec.js (1)
  • require (1-1)
sinatra/tests/e2e/about.spec.js (1)
  • require (1-1)
sinatra/tests/e2e/search.spec.js (1)
  • require (1-1)
sinatra/tests/e2e/register.spec.js (1)
  • require (1-1)
sinatra/tests/e2e/weather.spec.js (1)
  • require (1-1)
sinatra/tests/e2e/search.spec.js (5)
sinatra/tests/e2e/login.spec.js (1)
  • require (1-1)
sinatra/tests/e2e/about.spec.js (1)
  • require (1-1)
sinatra/tests/e2e/register.spec.js (1)
  • require (1-1)
sinatra/tests/playwright.config.js (1)
  • require (2-2)
sinatra/tests/e2e/weather.spec.js (1)
  • require (1-1)
sinatra/tests/e2e/weather.spec.js (5)
sinatra/tests/e2e/login.spec.js (1)
  • require (1-1)
sinatra/tests/e2e/about.spec.js (1)
  • require (1-1)
sinatra/tests/e2e/search.spec.js (1)
  • require (1-1)
sinatra/tests/e2e/register.spec.js (1)
  • require (1-1)
sinatra/tests/playwright.config.js (1)
  • require (2-2)
🪛 YAMLlint (1.35.1)
.github/workflows/playwright.yml

[error] 37-37: trailing spaces

(trailing-spaces)

.github/workflows/continuous_delivery.yml

[error] 21-21: trailing spaces

(trailing-spaces)

🪛 RuboCop (1.73)
sinatra/helpers/application_helpers.rb

[convention] 78-105: Assignment Branch Condition size for cached_forecast is too high. [<5, 24, 6> 25.24/23]

(Metrics/AbcSize)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e
🔇 Additional comments (18)
.github/workflows/continuous_delivery.yml (1)

4-5: Appropriate update to the workflow trigger branches.

Switching from "feature/refactor" to "dev" for the continuous delivery workflow is a good change that aligns with standard Git workflow practices.

sinatra/helpers/application_helpers.rb (1)

78-78: Good method naming improvement.

Renaming from get_cached_forecast to cached_forecast follows Ruby conventions by removing the redundant "get_" prefix while maintaining clarity.

🧰 Tools
🪛 RuboCop (1.73)

[convention] 78-105: Assignment Branch Condition size for cached_forecast is too high. [<5, 24, 6> 25.24/23]

(Metrics/AbcSize)

sinatra/tests/e2e/about.spec.js (1)

3-8: Well-structured Playwright test.

This test effectively checks the critical elements of the about page. Good use of Playwright's role-based selectors and appropriate assertions.

sinatra/tests/e2e/login.spec.js (3)

1-8: Well-structured test setup with clear navigation

The test organization with a beforeEach hook that navigates to the login page before each test is a good practice that reduces code duplication and ensures consistent test preconditions.


9-14: Good use of role-based and attribute selectors

Using a combination of role-based selectors (getByRole) and attribute selectors (locator) follows Playwright best practices and makes tests more resilient to UI implementation changes.


16-21: Valid error case testing

Testing the error scenario with invalid credentials is important for verifying proper user feedback. The test correctly checks for the presence of an error message.

sinatra/tests/e2e/search.spec.js (2)

1-11: Good use of constants for test data

Defining search terms as constants at the top of the file improves maintainability and makes it clear what values are being tested.


14-31: Well-structured positive test case

The test properly validates multiple aspects of the search functionality, including URL updates and result content verification. The use of case-insensitive comparison in line 29 is a good practice.

sinatra/tests/playwright.config.js (2)

1-14: Well-configured Playwright settings with CI awareness

The configuration effectively handles different environments (CI vs local) with appropriate settings for retries, parallel execution, and reporting. This ensures tests run reliably in both scenarios.


23-39: Good cross-browser test coverage

Testing across multiple browsers (Chromium, Firefox, WebKit) ensures the application works consistently for different users. The use of Playwright's device configurations simplifies this setup.

sinatra/tests/e2e/register.spec.js (3)

1-18: Comprehensive form validation test

The test thoroughly checks all form elements, which helps ensure the UI renders correctly. The combination of role-based and attribute selectors follows Playwright best practices.


20-30: Good validation of error handling

Testing the password mismatch scenario is important for verifying error handling. The test properly checks both the visibility and content of the error message.


32-42: Excellent use of unique data for registration test

Using timestamp-based unique values for username and email prevents test data collisions and potential test failures due to duplicate registrations. This is a best practice for registration tests.

sinatra/tests/e2e/weather.spec.js (2)

1-3: Good implementation of Playwright test structure!

The test suite is well-structured with proper imports and test organization, matching the pattern used in other test files.


4-23: Well-designed API test with thorough error handling

This test effectively validates both success and error paths:

  • Properly checks for both 200 and 503 status codes
  • For success: Verifies expected properties and data structure
  • For errors: Confirms proper error format with status and message

The conditional testing logic ensures robust validation regardless of the API state.

.github/workflows/playwright.yml (3)

1-9: Well-configured workflow triggers

The workflow is properly set up to run on:

  • Pushes to dev/main branches
  • Pull requests to dev/main branches
  • Manual workflow dispatch

This ensures comprehensive test coverage at appropriate points in the development cycle.


26-32: Well-structured database preparation

The test database setup is comprehensive:

  1. Applies schema from SQL files
  2. Sets up full-text search
  3. Populates the virtual table

This ensures tests run against a properly configured database environment.


66-71: Good security practice with API key

Properly passing the WeatherBit API key as an environment variable from GitHub secrets follows security best practices. This ensures the key isn't exposed in logs or code.

Comment thread sinatra/schema_test.sql
Comment on lines +10 to +12
-- Create a default user, The password is 'password' (MD5 hashed)
INSERT INTO users (username, email, password)
VALUES ('test', 'keamonk1@stud.kea.dk', '123');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix password handling in test user.

There are issues with the test user's password:

  1. The comment states the password is MD5 hashed, but '123' appears to be plaintext
  2. MD5 is insecure for password storage even if it were used

While this may be acceptable for testing, ensure production code uses secure password hashing (like bcrypt, which I see is used in the application helpers).

-- Create a default user, The password is 'password' (MD5 hashed)
+-- Create a default user with a plaintext password (for testing only)
 INSERT INTO users (username, email, password) 
     VALUES ('test', 'keamonk1@stud.kea.dk', '123');
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
-- Create a default user, The password is 'password' (MD5 hashed)
INSERT INTO users (username, email, password)
VALUES ('test', 'keamonk1@stud.kea.dk', '123');
-- Create a default user with a plaintext password (for testing only)
INSERT INTO users (username, email, password)
VALUES ('test', 'keamonk1@stud.kea.dk', '123');

Comment on lines +23 to +32
// Requires seeded user: username 'test', password '123'
test.skip('allows successful login', async ({ page }) => {
await page.fill('input[name="username"]', 'test');
await page.fill('input[name="password"]', '123');
await page.click('input[type="submit"]');

// Verify redirect to home
expect(page.url()).toBe('/');
await expect(page.getByText('You were successfully logged in.')).toBeVisible();
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider adding a data seeding mechanism

The skipped test for successful login requires seeded test data, but there's no clear indication of how or where this data should be created.


🏁 Script executed:

#!/bin/bash
# Check if there's a database seeding script or fixture in the codebase
fd -t f "seed|fixture" --full-path sinatra/

# Check for any references to test user creation in the codebase
rg -t ruby "test.*user|fixture.*user|seed.*user" sinatra/

Length of output: 435


Add a data‑seeding mechanism for the “allows successful login” E2E test

This test is currently skipped because it depends on a pre‑existing user (test/123), but there’s no fixture or seed script to create that account before Playwright runs.

Please add a clear seeding step—for example, a Playwright fixture or a standalone scripts/seed entrypoint—that inserts the test user into the database prior to executing this spec.

• Location: sinatra/tests/e2e/login.spec.js (lines 23–32)
• Suggestion:
– Create a seedTestUser() helper (via direct DB call or API endpoint) and invoke it in a Playwright beforeAll or custom fixture.
– Alternatively, add a CLI script (scripts/seed.js or seeds/) that your CI/test runner can invoke to populate test data.
• Verify that running the seed step enables this test to pass reliably.

@theaskou
Copy link
Copy Markdown
Contributor

Nice! Looking forward to see how it works

@theaskou theaskou merged commit b39de12 into main Apr 18, 2025
9 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.

Let them search - Week 2

3 participants