Skip to content

Refactor Jest ci & Added comment workflow#6380

Open
sonalgaud12 wants to merge 3 commits intosugarlabs:masterfrom
sonalgaud12:ci-add
Open

Refactor Jest ci & Added comment workflow#6380
sonalgaud12 wants to merge 3 commits intosugarlabs:masterfrom
sonalgaud12:ci-add

Conversation

@sonalgaud12
Copy link
Contributor

@sonalgaud12 sonalgaud12 commented Mar 24, 2026

Splits the Jest workflow into two:

pr-jest-tests.yml — runs tests, enforces results, uploads artifacts
pr-jest-comment.yml — posts/updates a PR comment with test results via workflow_run

Why

This follows GitHub's recommended pattern for PR workflows: untrusted code runs under the safer pull_request event (read-only permissions), while comment posting runs in a trusted workflow_run context with only pull-requests: write.

Key Changes

pr-jest-tests.yml

pull_request_targetpull_request; permissions reduced to contents: read
Added --forceExit, continue-on-error: true, and step outputs instead of env vars
Replaced PR comment posting with a GitHub Step Summary + artifact upload

pr-jest-comment.yml

Downloads artifacts from the test run, generates a pass / fail comment
Posts a new comment or updates an existing one (deduped via marker)

PR Category

  • Bug Fix
  • Feature
  • Performance
  • Tests
  • Documentation

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@github-actions github-actions bot added performance Improves performance (load time, memory, rendering) tests Adds or updates test coverage size/L Large: 250-499 lines changed area/ci-cd Changes to CI/CD workflows labels Mar 24, 2026
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

Copy link
Contributor

@mahesh-09-12 mahesh-09-12 left a comment

Choose a reason for hiding this comment

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

Nice split, using pull_request + workflow_run makes sense, just one thing - with --forceExit + continue-on-error, are we sure the test results we upload are always complete? Wondering if the comment job could pick up partial results in some cases.
also, do test failures still fail CI clearly, or are they mostly shown in the PR comment now?

@yogibytes
Copy link
Contributor

Hey @sonalgaud12

Reviewed the workflow changes—solid approach on the split between pull_request and workflow_run. Found a few things we could improve: artifact retention, error handling, and concurrency control. Nothing breaking, just optimizations.

Open to collaborating on this? I've drafted a PR with solutions ready to go.

yogibytes added a commit to yogibytes/SugarLabs-musicblocks that referenced this pull request Mar 25, 2026
…t Listener Cleanup

- Refactor Jest workflow into two independent workflows for better security
  * pr-jest-tests.yml: Runs tests with pull_request event (read-only permissions)
  * pr-jest-comment.yml: Posts results via workflow_run (trusted context)

- Add artifact retention policy (7-day auto-cleanup) to prevent disk bloat
- Add concurrency control to prevent duplicate PR comments on rapid commits
- Add error handling for missing artifacts with graceful fallback
- Reduce permissions scope in test job to contents: read only

- Implement event listener cleanup to prevent accumulation vulnerability
  * Add _cleanupEventHandlers() method in Block class
  * Clean up CreateJS container event listeners
  * Clean up DOM event listeners from label input field
  * Call cleanup before marking blocks as trash in Blocks.moveToTrash()

Security improvements address all 4 weak points from Jest workflow audit:
✅ Artifact Retention - retention-days: 7
✅ Race Conditions - concurrency control group added
✅ Error Handling - continue-on-error: true with fallback
✅ Permissions - reduced to contents: read in untrusted context

Fixes vulnerability identified in PR sugarlabs#6380 review.
All 3948 Jest tests pass, no breaking changes.
yogibytes added a commit to yogibytes/SugarLabs-musicblocks that referenced this pull request Mar 25, 2026
…t Listener Cleanup

- Refactor Jest workflow into two independent workflows for better security
  * pr-jest-tests.yml: Runs tests with pull_request event (read-only permissions)
  * pr-jest-comment.yml: Posts results via workflow_run (trusted context)

- Add artifact retention policy (7-day auto-cleanup) to prevent disk bloat
- Add concurrency control to prevent duplicate PR comments on rapid commits
- Add error handling for missing artifacts with graceful fallback
- Reduce permissions scope in test job to contents: read only

- Implement event listener cleanup to prevent accumulation vulnerability
  * Add _cleanupEventHandlers() method in Block class
  * Clean up CreateJS container event listeners
  * Clean up DOM event listeners from label input field
  * Call cleanup before marking blocks as trash in Blocks.moveToTrash()

Security improvements address all 4 weak points from Jest workflow audit:
[1] Artifact Retention - retention-days: 7
[2] Race Conditions - concurrency control group added
[3] Error Handling - continue-on-error: true with fallback
[4] Permissions - reduced to contents: read in untrusted context

Fixes vulnerability identified in PR sugarlabs#6380 review.
All 3948 Jest tests pass, no breaking changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ci-cd Changes to CI/CD workflows performance Improves performance (load time, memory, rendering) size/L Large: 250-499 lines changed tests Adds or updates test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants