Skip to content

chore: add reset main workflow command#69

Merged
ymkiux merged 1 commit intoSakuraByteCore:mainfrom
SurviveM:chore/reset-main-workflow
Apr 5, 2026
Merged

chore: add reset main workflow command#69
ymkiux merged 1 commit intoSakuraByteCore:mainfrom
SurviveM:chore/reset-main-workflow

Conversation

@SurviveM
Copy link
Copy Markdown
Collaborator

@SurviveM SurviveM commented Apr 5, 2026

Summary

  • add a dedicated reset-main workflow script for deterministic git cleanup
  • switch the reset flow from pull-based sync to fetch plus hard reset against origin/main
  • expose the workflow through npm run reset and cover it with unit tests

Tests

  • node tests/unit/run.mjs

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a reset command that synchronizes your local main branch with the remote origin to ensure consistency.
  • Chores

    • Improved the reset workflow to fetch the latest changes from remote before resetting your working tree, providing a more reliable synchronization method.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

@coderabbitai re-review
Stop making breaking changes, do a proper review!
If I merge this directly, will it introduce any regressions? Please list only the impacted issues. Do not include style suggestions, speculative concerns, or already-resolved items.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 5, 2026

📝 Walkthrough

Walkthrough

The repository's reset workflow is updated to fetch from the remote main branch before resetting the local working tree to origin/main, replacing the previous pull-based approach. An npm script entry is added to expose this command, and corresponding test assertions are updated to validate the new workflow.

Changes

Cohort / File(s) Summary
Reset Workflow Update
cmd/reset-main.js, tests/unit/reset-main.test.mjs
Modified git command sequence: added git fetch origin main --prune, changed hard reset target from HEAD to origin/main, replaced git pull origin main with git status --short --branch. Tests updated to assert the new command sequence and verify absence of pull command.
npm Script Registration
package.json
Added reset script entry that executes node cmd/reset-main.js.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A reset script hops into place,
Fetching from origin's remote space,
No more pulling, just pristine and clean,
The hardest reset you've ever seen,
Status reported with bunny's good cheer! 🌿

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a new reset-main workflow command exposed via npm script.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/unit/reset-main.test.mjs (1)

1-4: ⚠️ Potential issue | 🔴 Critical

Missing test import causes pipeline failure.

The test function is used on lines 13, 30, and 35, but it's never imported. This causes a ReferenceError and is likely the cause of the CI failure. For Node.js's built-in test runner, you need to import test from node:test.

🐛 Proposed fix
 import assert from 'assert';
 import fs from 'fs';
 import path from 'path';
 import { fileURLToPath } from 'url';
+import { test } from 'node:test';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/reset-main.test.mjs` around lines 1 - 4, The test suite is calling
the global test function but never imports it; add an explicit import for test
from Node's test runner (e.g., include "import { test } from 'node:test'"
alongside the existing imports) so the references to test() in this file resolve
and the CI no longer throws ReferenceError; ensure the import is placed at the
top with other imports where functions like test are used.
🧹 Nitpick comments (2)
cmd/reset-main.js (1)

19-43: Consider adding error handling for workflow steps.

The main() function catches errors from the initial repository check but doesn't handle failures in the subsequent git commands (lines 27-40). If git fetch fails due to network issues or git checkout fails due to conflicts, the script will throw an uncaught exception with a less informative error message.

💡 Proposed improvement
 function main() {
   try {
     run('git rev-parse --is-inside-work-tree');
   } catch (err) {
     console.error('Not inside a git repository.');
     process.exit(1);
   }

+  try {
     console.log('[1/5] Fetch origin/main');
     run('git fetch origin main --prune');

     console.log('[2/5] Checkout main');
     run('git checkout main');

     console.log('[3/5] Reset local changes to origin/main');
     run('git reset --hard origin/main');

     console.log('[4/5] Remove untracked files');
     run('git clean -fd');

     console.log('[5/5] Final status');
     run('git status --short --branch');

     console.log('Done. Working tree synced to origin/main.');
+  } catch (err) {
+    console.error('Reset workflow failed:', err.message);
+    process.exit(1);
+  }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/reset-main.js` around lines 19 - 43, The main() function currently only
handles errors from the initial git check; wrap each subsequent git step (the
run(...) calls for 'git fetch origin main --prune', 'git checkout main', 'git
reset --hard origin/main', 'git clean -fd', and 'git status --short --branch')
with error handling so failures produce clear messages and exit non‑zero: either
put each run call into a try/catch that logs a descriptive error via
console.error (including the command and the caught error) and calls
process.exit(1), or update the run(...) helper to return a status/error and
check it after each invocation; reference the main() function and each run(...)
invocation so the change is applied to those exact calls.
package.json (1)

29-29: Consider whether cmd/ should be added to files for npm publishing.

The new reset script references cmd/reset-main.js, but the cmd/ directory is not included in the files array (lines 9-19). If this script is intended for development/maintenance only and not for end-users of the published package, this is fine. Otherwise, add "cmd/" to the files array.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` at line 29, The package.json adds a "reset" npm script that
runs "cmd/reset-main.js" but the package's "files" array does not include the
cmd/ directory; decide whether cmd/reset-main.js should be published and if so
add "cmd/" to the "files" array in package.json, otherwise leave it out and
document that the script is development-only (or move the script into a
published location). Locate the "reset" script string and the "files" array in
package.json to make the appropriate update.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@tests/unit/reset-main.test.mjs`:
- Around line 1-4: The test suite is calling the global test function but never
imports it; add an explicit import for test from Node's test runner (e.g.,
include "import { test } from 'node:test'" alongside the existing imports) so
the references to test() in this file resolve and the CI no longer throws
ReferenceError; ensure the import is placed at the top with other imports where
functions like test are used.

---

Nitpick comments:
In `@cmd/reset-main.js`:
- Around line 19-43: The main() function currently only handles errors from the
initial git check; wrap each subsequent git step (the run(...) calls for 'git
fetch origin main --prune', 'git checkout main', 'git reset --hard origin/main',
'git clean -fd', and 'git status --short --branch') with error handling so
failures produce clear messages and exit non‑zero: either put each run call into
a try/catch that logs a descriptive error via console.error (including the
command and the caught error) and calls process.exit(1), or update the run(...)
helper to return a status/error and check it after each invocation; reference
the main() function and each run(...) invocation so the change is applied to
those exact calls.

In `@package.json`:
- Line 29: The package.json adds a "reset" npm script that runs
"cmd/reset-main.js" but the package's "files" array does not include the cmd/
directory; decide whether cmd/reset-main.js should be published and if so add
"cmd/" to the "files" array in package.json, otherwise leave it out and document
that the script is development-only (or move the script into a published
location). Locate the "reset" script string and the "files" array in
package.json to make the appropriate update.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 79b8cdaf-3d3b-46e0-8162-cda28e5e51a6

📥 Commits

Reviewing files that changed from the base of the PR and between 8da3370 and ef521b9.

📒 Files selected for processing (3)
  • cmd/reset-main.js
  • package.json
  • tests/unit/reset-main.test.mjs
📜 Review details
🧰 Additional context used
🪛 GitHub Actions: ci
package.json

[error] Command "npm run test:unit && npm run test:e2e" failed because test:unit returned a non-zero exit code (1 test failed).

🔇 Additional comments (3)
cmd/reset-main.js (1)

27-28: LGTM on the fetch-and-reset approach.

Using git fetch origin main --prune followed by git reset --hard origin/main is a cleaner and more deterministic approach than git pull, as it avoids potential merge conflicts and ensures the local branch exactly matches the remote.

tests/unit/reset-main.test.mjs (2)

13-27: Test assertions for git command sequence are correct.

The test properly verifies the new fetch-and-reset workflow and explicitly checks that git pull origin main is not present, which aligns with the PR's intent to replace pull-based sync with fetch + hard reset.


35-38: Good: Test validates npm script integration.

The test correctly verifies that package.json exposes the reset workflow via the reset script. The BOM stripping on line 36 is good defensive coding for Windows-originated JSON files.

@ymkiux ymkiux merged commit e5d3b2a into SakuraByteCore:main Apr 5, 2026
4 of 7 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.

2 participants