Skip to content

Conversation

@0xDEnYO
Copy link
Contributor

@0xDEnYO 0xDEnYO commented Sep 1, 2025

Which Jira task belongs to this PR?

Why did I implement it this way?

Checklist before requesting a review

Checklist for reviewer (DO NOT DEPLOY and contracts BEFORE CHECKING THIS!!!)

  • I have checked that any arbitrary calls to external contracts are validated and or restricted
  • I have checked that any privileged calls (i.e. storage modifications) are validated and or restricted
  • I have ensured that any new contracts have had AT A MINIMUM 1 preliminary audit conducted on by <company/auditor>

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 1, 2025

Walkthrough

Updates a package.json script to use bunx tsx for running a TypeScript utility and adds a new Bun-based TypeScript test runner script that discovers and executes .test.ts files under the script/ directory.

Changes

Cohort / File(s) Summary
NPM/Bun script updates
package.json
Changed script "okr:contract-coverage-above-90" to run bunx tsx script/utils/analyzeCoverage.ts instead of bun run script/utils/analyzeCoverage.ts.
TypeScript test runner
script/runTypescriptTests.ts
New Bun-based test runner: recursively finds script/**/*.test.ts excluding lib/ and node_modules/, prints discovered files, and runs them via bun test using child_process.execSync. Handles no-tests, success, and failure exit codes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

AuditNotRequired

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ts-testing-setup

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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
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.

Actionable comments posted: 2

Caution

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

⚠️ Outside diff range comments (1)
package.json (1)

100-101: Align test:ts with the same convention (use bunx tsx).

Our guideline says “script/**/*.ts: execute with bunx tsx”. Update the runner invocation accordingly.

-    "test:ts": "bun script/runTypescriptTests.ts",
+    "test:ts": "bunx tsx script/runTypescriptTests.ts",
🧹 Nitpick comments (3)
script/runTypescriptTests.ts (3)

26-27: Use Dirent to avoid extra stat calls and simplify traversal.

Less I/O and cleaner logic.

-import { readdirSync, statSync } from 'fs'
+import { readdirSync } from 'fs'
@@
-  try {
-    const items = readdirSync(dir)
-
-    for (const item of items) {
-      const fullPath = join(dir, item)
-      const stat = statSync(fullPath)
-
-      if (stat.isDirectory()) {
-        // Skip lib/ and node_modules/ directories
-        if (item === 'lib' || item === 'node_modules') continue
-
-        testFiles.push(...findTestFiles(fullPath))
-      } else if (item.endsWith('.test.ts')) testFiles.push(fullPath)
-    }
+  try {
+    const items = readdirSync(dir, { withFileTypes: true })
+    for (const entry of items) {
+      const fullPath = join(dir, entry.name)
+      if (entry.isDirectory()) {
+        // Skip common build/vendor dirs
+        if (entry.name === 'lib' || entry.name === 'node_modules' || entry.name === 'dist') continue
+        testFiles.push(...findTestFiles(fullPath))
+      } else if (entry.isFile() && entry.name.endsWith('.test.ts')) {
+        testFiles.push(fullPath)
+      }
+    }

Also applies to: 32-45


54-55: Deterministic output: sort discovered files before printing/running.

Improves reproducibility in CI logs.

-const testFiles = findTestFiles(scriptDir)
+const testFiles = findTestFiles(scriptDir).sort()

39-44: Consider skipping additional generated dirs (dist/build/coverage) if they ever appear under script/.

Future-proofing to avoid accidental test pickup from compiled outputs or reports.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between edd18fe and 74fed1c.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • script/runTypescriptTests.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
script/**/*.ts

📄 CodeRabbit inference engine (conventions.md)

Execute TypeScript scripts with bunx tsx

Files:

  • script/runTypescriptTests.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
PR: lifinance/contracts#0
File: conventions.md:0-0
Timestamp: 2025-08-29T09:56:59.784Z
Learning: Applies to script/**/*.ts : Execute TypeScript scripts with bunx tsx
Learnt from: 0xDEnYO
PR: lifinance/contracts#1139
File: package.json:81-82
Timestamp: 2025-05-14T03:33:25.089Z
Learning: Bun allows direct invocation of npm scripts defined in package.json without requiring the `bun run` prefix (e.g., `bun scriptName` works, not just `bun run scriptName`), unlike some other package managers like npm.
Learnt from: 0xDEnYO
PR: lifinance/contracts#1196
File: script/helperFunctions.sh:1447-1462
Timestamp: 2025-06-19T06:23:47.848Z
Learning: 0xDEnYO prefers to keep eval usage in local bash scripts when the security risk is acceptable in their controlled environment, prioritizing simplicity over security hardening for local tooling.
📚 Learning: 2025-08-29T09:56:59.784Z
Learnt from: CR
PR: lifinance/contracts#0
File: conventions.md:0-0
Timestamp: 2025-08-29T09:56:59.784Z
Learning: Applies to script/**/*.ts : Execute TypeScript scripts with bunx tsx

Applied to files:

  • package.json
  • script/runTypescriptTests.ts
📚 Learning: 2025-05-14T03:33:25.089Z
Learnt from: 0xDEnYO
PR: lifinance/contracts#1139
File: package.json:81-82
Timestamp: 2025-05-14T03:33:25.089Z
Learning: Bun allows direct invocation of npm scripts defined in package.json without requiring the `bun run` prefix (e.g., `bun scriptName` works, not just `bun run scriptName`), unlike some other package managers like npm.

Applied to files:

  • package.json
  • script/runTypescriptTests.ts
📚 Learning: 2025-08-29T09:56:59.784Z
Learnt from: CR
PR: lifinance/contracts#0
File: conventions.md:0-0
Timestamp: 2025-08-29T09:56:59.784Z
Learning: Applies to script/demoScripts/**/*.ts : TypeScript demo scripts must follow .eslintrc.cjs, use async/await, try/catch error handling, proper logging, env via getEnvVar(), citty for CLI, consola for logging, and exit with correct codes

Applied to files:

  • script/runTypescriptTests.ts
🧬 Code graph analysis (1)
script/runTypescriptTests.ts (1)
script/troncast/postinstall-tronweb-fix.mjs (2)
  • items (44-44)
  • fullPath (47-47)
⏰ 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). (1)
  • GitHub Check: run-unit-tests
🔇 Additional comments (1)
package.json (1)

91-91: Good switch to bunx tsx for TS execution.

This aligns with our convention for script/**/*.ts.

@@ -0,0 +1,76 @@
#!/usr/bin/env bun
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Execute this script with bunx tsx per repo convention.

Replace the Bun shebang and usage notes to match our standard.

-#!/usr/bin/env bun
+#!/usr/bin/env -S bunx tsx
@@
- * - npm run test:ts (runs all TypeScript tests)
- * - bun script/runTypescriptTests.ts (direct execution)
+ * - npm run test:ts (runs all TypeScript tests)
+ * - bunx tsx script/runTypescriptTests.ts (direct execution)

Note: If env -S is unavailable in some environments, drop the shebang and rely on package.json’s script.

Also applies to: 16-18

🤖 Prompt for AI Agents
In script/runTypescriptTests.ts around lines 1 and 16-18, replace the current
Bun shebang and accompanying usage notes with the repo-standard invocation using
bunx tsx: either change the shebang/launcher to use the env wrapper that runs
"bunx tsx" per convention or, if env -S is not supported in target environments,
remove the shebang entirely and update the repository scripts (package.json) and
the file's usage notes to instruct running via "bunx tsx
script/runTypescriptTests.ts"; ensure the usage text clearly reflects the chosen
approach.

Comment on lines +25 to +27
import { execSync } from 'child_process'
import { readdirSync, statSync } from 'fs'
import { join } from 'path'
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid shell quoting pitfalls; use spawnSync with args instead of execSync with a string.

Prevents issues if paths contain spaces/quotes and removes reliance on a shell.

-import { execSync } from 'child_process'
+import { spawnSync } from 'child_process'
@@
-// Run all test files together with a specific pattern
-const testFilePatterns = testFiles.map((file) => `"${file}"`).join(' ')
-console.log(`Running all tests with: bun test ${testFilePatterns}`)
-
-try {
-  execSync(`bun test ${testFilePatterns}`, { stdio: 'inherit' })
-} catch (error) {
-  console.error('Some tests failed')
-  process.exit(1)
-}
+console.log('Running all tests with: bun test', testFiles.join(' '))
+const { status } = spawnSync('bun', ['test', ...testFiles], { stdio: 'inherit' })
+if (status !== 0) {
+  console.error('Some tests failed')
+  process.exit(status ?? 1)
+}

Also applies to: 65-74

@0xDEnYO 0xDEnYO added the WIP Work in progress label Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AuditNotRequired WIP Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants