Skip to content

Conversation

@NathanFlurry
Copy link
Member

No description provided.

@vercel
Copy link

vercel bot commented Nov 21, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
rivetkit-serverless Ready Ready Preview Comment Nov 21, 2025 9:23am
3 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
rivet-cloud Ignored Ignored Nov 21, 2025 9:23am
rivet-inspector Ignored Ignored Preview Nov 21, 2025 9:23am
rivet-site Ignored Ignored Preview Nov 21, 2025 9:23am

Copy link
Member Author


How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link

claude bot commented Nov 21, 2025

Code Review

Summary

This PR removes the dependency on Node.js's node:assert module from the generated TypeScript code in the runner-protocol SDK. The solution implements a custom assert function directly in the generated code, making it environment-agnostic and suitable for non-Node.js runtimes (browsers, edge workers, etc.).

Positive Aspects ✅

  1. Clear Problem Definition: Removes Node.js-specific dependency from generated code, improving portability
  2. Simple Solution: The custom assert implementation is straightforward and functionally equivalent
  3. Build-Time Processing: Smart approach to post-process generated code in the build script
  4. Proper Placement: Assert function is added at the end of the file where it won't conflict with generated code

Issues and Concerns 🔍

1. String Replacement Fragility (Medium Priority)

let content = content.replace("import assert from \"node:assert\"\n", "");

Issue: This exact string match is brittle and could fail if:

  • The bare-ts generator changes formatting (spaces, quotes, semicolons)
  • Multiple imports are on the same line
  • Import uses different quote styles (' vs ")

Suggestion: Use a regex pattern for more robust matching:

use regex::Regex;

let assert_import_regex = Regex::new(r#"import\s+assert\s+from\s+['\"]node:assert['\"];?\s*\n?"\#)
    .expect("Failed to compile regex");
let content = assert_import_regex.replace(&content, "").to_string();

2. Formatting Issue (Low Priority)

let content = format\!("{}\n{}", content, assert_function);

This adds an extra blank line between the last generated code and the assert function. Consider:

let content = format\!("{}{}", content, assert_function);

The assert_function raw string already includes a leading \n.

3. Missing Error Context (Low Priority)

The panics in post_process_typescript could be more descriptive:

fs::read_to_string(file_path)
    .unwrap_or_else(|e| panic\!("Failed to read generated TypeScript file at {}: {}", file_path.display(), e))

fs::write(file_path, content)
    .unwrap_or_else(|e| panic\!("Failed to write post-processed TypeScript file at {}: {}", file_path.display(), e))

4. Verification (Medium Priority)

Consider verifying that the replacement actually occurred:

if content.contains("node:assert") {
    eprintln\!(
        "cargo:warning=Failed to remove node:assert import from {}. Manual review required.",
        file_path.display()
    );
}

5. TypeScript Type Safety (Low Priority)

The custom assert function is well-typed with the asserts condition return type, which is correct. However, you might want to add JSDoc for better IDE support:

/**
 * Asserts that a condition is true, throwing an error if false.
 * @param condition - The condition to assert
 * @param message - Optional error message
 * @throws {Error} If condition is false
 */
function assert(condition: boolean, message?: string): asserts condition {
    if (\!condition) throw new Error(message ?? "Assertion failed")
}

Testing Recommendations 🧪

This PR appears to lack test coverage. Consider adding:

  1. Build Script Tests: Test that the post-processing works correctly
  2. Generated Code Tests: Verify the generated TypeScript compiles and runs
  3. Runtime Tests: Ensure assert function behaves correctly in both Node.js and browser environments

Example test structure:

cd engine/sdks/typescript/runner-protocol
pnpm run build && pnpm run check-types

Security Considerations 🔒

No security concerns identified. The change is purely about dependency management and doesn't introduce attack vectors.

Performance Considerations ⚡

  • Build Time: Minimal impact - single file read/write operation
  • Runtime: The custom assert is functionally identical to Node's assert (both throw errors)
  • Bundle Size: Negligible - actually reduces dependencies

Recommendations

Before Merge:

  1. Test the generated TypeScript builds successfully: cd engine/sdks/typescript/runner-protocol && pnpm build
  2. Test dependent packages (runner SDK) still work correctly
  3. Consider making the string replacement more robust with regex

Future Improvements:

  1. Add integration tests that verify generated code works in multiple environments
  2. Consider contributing upstream to bare-ts to make the assert import configurable

Verdict

✅ Approve with minor suggestions

The core change is sound and solves a real portability issue. The suggestions above are mostly about making the solution more robust and maintainable. The PR is safe to merge after verifying the build works correctly.


Review generated by Claude Code

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 21, 2025

More templates

@rivetkit/cloudflare-workers

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/cloudflare-workers@3521

@rivetkit/db

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/db@3521

@rivetkit/framework-base

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/framework-base@3521

@rivetkit/next-js

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/next-js@3521

@rivetkit/react

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/react@3521

rivetkit

pnpm add https://pkg.pr.new/rivet-dev/rivet/rivetkit@3521

@rivetkit/sql-loader

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/sql-loader@3521

@rivetkit/engine-runner

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner@3521

@rivetkit/engine-runner-protocol

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner-protocol@3521

commit: d899197

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