Skip to content

Conversation

ahnpnl
Copy link
Collaborator

@ahnpnl ahnpnl commented Aug 3, 2025

Summary

Fixes #4969

Test plan

Green CI

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

N.A.

Summary by CodeRabbit

  • Chores

    • Updated the template engine for generating Jest configuration files from EJS to Handlebars.
    • Replaced EJS dependencies with Handlebars in the project dependencies.
  • New Features

    • Introduced an automated code audit workflow that analyzes code for security and quality on key branches and pull requests.

Copy link

coderabbitai bot commented Aug 3, 2025

Walkthrough

A new GitHub Actions workflow for CodeQL auditing was added. The project’s template engine was switched from EJS to Handlebars, with all references updated accordingly. The EJS and its type definitions were removed from dependencies, replaced by Handlebars equivalents in both runtime and development dependencies.

Changes

Cohort / File(s) Change Summary
CI Workflow Addition
.github/workflows/audit.yml
Introduced a GitHub Actions workflow for CodeQL analysis on pushes and pull requests.
Dependency Update
package.json
Removed ejs and @types/ejs dependencies; added handlebars and @types/handlebars.
Template Engine Migration
src/cli/config/init.ts
Replaced EJS template rendering with Handlebars; updated template syntax and rendering logic.

Sequence Diagram(s)

sequenceDiagram
    participant CLI_User as CLI User
    participant CLI as CLI (init.ts)
    participant Handlebars as Handlebars Engine

    CLI_User->>CLI: Run config init
    CLI->>Handlebars: Compile template with data
    Handlebars-->>CLI: Rendered config content
    CLI->>CLI_User: Output generated config file
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Remove or update vulnerable EJS dependency (CVE-2023-29827) (#4969)
Replace EJS usage in codebase (#4969)
Update type definitions to match template engine change (#4969)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Poem

A rabbit hopped through code so bright,
Swapping EJS for Handlebars light.
Dependencies trimmed, the audit’s in play,
Security bugs now kept at bay.
With templates anew and workflows tight,
The codebase leaps to safer height!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 a30ed2c and 41012ae.

📒 Files selected for processing (1)
  • .github/workflows/audit.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/audit.yml
⏰ 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). (6)
  • GitHub Check: test-windows (18) / Run tests on Node v18 on windows-latest
  • GitHub Check: test-windows (22) / Run tests on Node v22 on windows-latest
  • GitHub Check: test-windows (20) / Run tests on Node v20 on windows-latest
  • GitHub Check: test-ubuntu (18) / Run tests on Node v18 on ubuntu-latest
  • GitHub Check: test-ubuntu (22) / Run tests on Node v22 on ubuntu-latest
  • GitHub Check: test-ubuntu (20) / Run tests on Node v20 on ubuntu-latest
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/replace-ejs

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 generate unit tests to generate unit tests 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.

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.

Copy link

github-actions bot commented Aug 3, 2025

PR Preview Action v1.6.2
Preview removed because the pull request was closed.
2025-08-03 13:07 UTC

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@ahnpnl ahnpnl marked this pull request as ready for review August 3, 2025 09:30
@ahnpnl ahnpnl requested a review from kulshekhar as a code owner August 3, 2025 09:30
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: 1

🧹 Nitpick comments (3)
package.json (1)

54-62: Consider peer-pinning for downstream template engines.

You added handlebars as a hard dependency. Because end-users rarely import it directly, bumping it is a risk-free semver-patch. You might loosen the caret version to ~4.7.8 or leave as caret but add an engines entry if you plan to move to v5 later.

src/cli/config/init.ts (1)

106-112: Optional: externalise template for readability.

Maintaining 20-line template literals inline is brittle. Moving JEST_CONFIG_TEMPLATE.hbs to src/cli/templates/ would:

• enable syntax-highlighting,
• ease future edits without TS recompile,
• allow pre-compilation if start-up perf matters.

.github/workflows/audit.yml (1)

11-14: Path ignore list misses .test.ts / .test.js.

If unit tests follow *.test.ts[x]? naming, CodeQL jobs will still run for doc-only changes. Add them if you want to save CI minutes.

-      - '**/*.spec.ts'
+      - '**/*.spec.ts'
+      - '**/*.test.ts'
+      - '**/*.test.js'
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8459897 and 93e44bc.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • .github/workflows/audit.yml (1 hunks)
  • package.json (2 hunks)
  • src/cli/config/init.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ahnpnl
PR: kulshekhar/ts-jest#4950
File: .github/workflows/pr-docs-check.yml:19-21
Timestamp: 2025-07-21T14:13:24.979Z
Learning: In ts-jest repository, adding `pull-requests: write` permission to the pr-docs-check.yml workflow's deploy-preview job breaks the GitHub Pages deployment, so this permission should be avoided in this specific workflow.
📚 Learning: in the ts-jest project, dependencies are only installed at the root level using the root package-loc...
Learnt from: ahnpnl
PR: kulshekhar/ts-jest#4950
File: .github/actions/setup-workspace/action.yml:28-28
Timestamp: 2025-07-21T14:09:03.234Z
Learning: In the ts-jest project, dependencies are only installed at the root level using the root package-lock.json file. Subdirectory package-lock.json files in e2e/ and examples/ directories don't affect the main workspace dependency installation, so they should not be included in GitHub Actions cache keys for the main workspace.

Applied to files:

  • package.json
  • src/cli/config/init.ts
📚 Learning: in ts-jest repository, adding `pull-requests: write` permission to the pr-docs-check.yml workflow's ...
Learnt from: ahnpnl
PR: kulshekhar/ts-jest#4950
File: .github/workflows/pr-docs-check.yml:19-21
Timestamp: 2025-07-21T14:13:24.979Z
Learning: In ts-jest repository, adding `pull-requests: write` permission to the pr-docs-check.yml workflow's deploy-preview job breaks the GitHub Pages deployment, so this permission should be avoided in this specific workflow.

Applied to files:

  • .github/workflows/audit.yml
🔇 Additional comments (5)
package.json (1)

54-62: Handlebars dependency verified – no outstanding CVEs

  • npm audit reports 0 vulnerabilities for [email protected]
  • npm view handlebars version confirms 4.7.8 is the latest release

No further action needed.

src/cli/config/init.ts (2)

17-23: Unescaped triple-stash may leak raw strings.

{{{ transformOpts }}} outputs unescaped text. It is safe today because the source is machine-generated JSON, but if future options include user-provided paths it could theoretically inject arbitrary code into the generated config. Consider {{ transformOpts }} plus pre-escaping with JSON.stringify to keep control.


106-112: All EJS references removed

I searched the codebase for any remaining EJS usage—imports, requires, .ejs templates, or a dependency entry in package.json—and found none. It’s safe to remove EJS entirely.

  • No import or require statements referencing “ejs”
  • No .ejs template files in the repo
  • No "ejs" entry in package.json
.github/workflows/audit.yml (2)

20-28: Workflow permissions are minimal – nice.

security-events: write plus read-only scopes follow GitHub’s recommendations. No pull-requests: write, so you avoided the pages deployment issue noted earlier. 👍


35-39: Shallow fetch depth set to 20 – confirm CodeQL accuracy.

CodeQL uses commit history for data-flow. Depth=20 is usually fine, but large refactors may exceed this window. If you see “history truncated” warnings, bump or drop the setting.

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

🧹 Nitpick comments (3)
.github/workflows/audit.yml (3)

11-14: Broaden the test-file exclusions to avoid unnecessary CI runs
Only *.spec.ts files are ignored. The repository also contains .test.ts and possibly .spec.js / .test.js syllables that will still trigger the workflow even though they are pure test changes. Consider expanding the glob to:

paths-ignore:
  - '**/*.md'
  - '**/*.txt'
  - '**/*.{spec,test}.{ts,js}'

35-39: Consider fetch-depth: 0 for more accurate CodeQL analysis
Limiting history to the last 20 commits may hide taint-tracking flows or cause baseline-diff noise. CodeQL’s guidance is to fetch the full history unless the repository is huge.

-        fetch-depth: 20
+        fetch-depth: 0   # full history for precise data-flow analysis

61-66: Redundant lockfile arguments
-r ./ already scans all nested package-lock.json files. Explicitly listing them is harmless but unnecessary; dropping them simplifies the command.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 93e44bc and a30ed2c.

📒 Files selected for processing (1)
  • .github/workflows/audit.yml (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: ahnpnl
PR: kulshekhar/ts-jest#4950
File: .github/workflows/pr-docs-check.yml:19-21
Timestamp: 2025-07-21T14:13:24.979Z
Learning: In ts-jest repository, adding `pull-requests: write` permission to the pr-docs-check.yml workflow's deploy-preview job breaks the GitHub Pages deployment, so this permission should be avoided in this specific workflow.
⏰ 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). (6)
  • GitHub Check: test-windows (18) / Run tests on Node v18 on windows-latest
  • GitHub Check: test-windows (22) / Run tests on Node v22 on windows-latest
  • GitHub Check: test-windows (20) / Run tests on Node v20 on windows-latest
  • GitHub Check: test-ubuntu (22) / Run tests on Node v22 on ubuntu-latest
  • GitHub Check: test-ubuntu (20) / Run tests on Node v20 on ubuntu-latest
  • GitHub Check: test-ubuntu (18) / Run tests on Node v18 on ubuntu-latest
🔇 Additional comments (1)
.github/workflows/audit.yml (1)

20-27: security-events: write will fail on PRs from forks
Forked PRs have no permission to write security events, causing the job to exit with HTTP 403. Guard the permission with a conditional or use:

permissions: read-all

for PRs, and elevate only on push to the default branches.

Copy link

sonarqubecloud bot commented Aug 3, 2025

@ahnpnl ahnpnl merged commit 322a3c7 into main Aug 3, 2025
22 checks passed
@ahnpnl ahnpnl deleted the fix/replace-ejs branch August 3, 2025 13:06
@coderabbitai coderabbitai bot mentioned this pull request Aug 3, 2025
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.

[Bug]: ts-jest includes vulnerable version of ejs (CVE-2023-29827)
2 participants