Skip to content

fix(runtime): preserve entry source in process argv - #8543

Open
proggeramlug wants to merge 2 commits into
PerryTS:mainfrom
proggeramlug:fix/direct-execution-guard
Open

fix(runtime): preserve entry source in process argv#8543
proggeramlug wants to merge 2 commits into
PerryTS:mainfrom
proggeramlug:fix/direct-execution-guard

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • seed compiled executables with the canonical TypeScript entry path
  • expose that path as process.argv[1] while preserving the executable at argv[0] and user arguments at argv[2+]
  • keep dylib initializers from modifying their host process argv
  • include the embedded entry path in the object-cache key
  • add IR-level and gap-suite regression coverage for the import.meta.url direct-execution guard

Root cause

Perry baked import.meta.url from the source module path, but constructed process.argv[1] by duplicating the executable path. The conventional Node/Bun direct-execution comparison therefore could never succeed in a native Perry executable.

Validation

  • cargo fmt --all -- --check
  • cargo check -p perry-runtime -p perry-codegen -p perry
  • cargo test -p perry-codegen --lib executable_seeds_process_argv_script_path_but_dylib_does_not
  • cargo test -p perry --bin perry key_changes_with_embedded_entry_source_path
  • compiled and ran the regression fixture with the rebuilt compiler/runtime; output matched Node byte-for-byte
  • verified the compiled executable still fires the guard when launched from a different working directory

Summary by CodeRabbit

  • Bug Fixes
    • Fixed compiled executables so process.argv[1] correctly identifies the TypeScript entry module.
    • Direct-execution checks using import.meta.url and process.argv[1] now work as expected under Node and Bun.
    • Preserved user-provided command-line arguments while improving entry-path detection.
    • Prevented library builds from incorrectly replacing the host process’s entry path.

@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 523d878f-5e5f-460b-8b35-6c1596b2b393

📥 Commits

Reviewing files that changed from the base of the PR and between 7c22189 and a3a8818.

📒 Files selected for processing (10)
  • changelog.d/8543-import-meta-direct-execution-guard.md
  • crates/perry-codegen/src/codegen/entry.rs
  • crates/perry-codegen/src/codegen/entry/tests.rs
  • crates/perry-codegen/src/codegen/opts.rs
  • crates/perry-codegen/src/runtime_decls/mod.rs
  • crates/perry-runtime/src/os.rs
  • crates/perry/src/commands/compile/object_cache.rs
  • crates/perry/src/commands/compile/object_cache/object_cache_tests.rs
  • crates/perry/src/commands/compile/run_pipeline.rs
  • test-files/test_gap_import_meta_direct_execution_guard.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

Compiled executables now seed process.argv[1] with the canonical TypeScript entry path. Runtime handling preserves arguments after index 1, libraries omit the seed, and object-cache keys include the path.

Changes

Process entry path propagation

Layer / File(s) Summary
Entry path metadata and compilation wiring
crates/perry-codegen/src/codegen/opts.rs, crates/perry/src/commands/compile/run_pipeline.rs, crates/perry/src/commands/compile/object_cache.rs, crates/perry/src/commands/compile/object_cache/object_cache_tests.rs
AppMetadata stores an optional entry source path. Executable entry compilation sets the path, and object-cache keys include it.
Executable entry path seeding
crates/perry-codegen/src/runtime_decls/mod.rs, crates/perry-codegen/src/codegen/entry.rs, crates/perry-runtime/src/os.rs
Executable entry code embeds the path and calls js_set_process_entry_path. Runtime code uses the seeded path for process.argv[1], with binary-path fallback.
Direct-execution regression coverage
crates/perry-codegen/src/codegen/entry/tests.rs, test-files/test_gap_import_meta_direct_execution_guard.ts, changelog.d/8543-import-meta-direct-execution-guard.md
IR tests verify executable and dylib behavior. The TypeScript fixture checks an import.meta.url and process.argv[1] direct-execution guard. The changelog records the fix.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to a3a88

This change corrects executable argument handling and cache identity while preserving dylib behavior, with targeted regression coverage and validation included. No actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: thehypnoo, jdalton

Sequence Diagram(s)

sequenceDiagram
  participant CompilePipeline
  participant EntryCodegen
  participant Runtime
  participant ProcessArgv
  CompilePipeline->>EntryCodegen: Provide entry_source_path
  EntryCodegen->>Runtime: Call js_set_process_entry_path
  Runtime->>ProcessArgv: Seed argv[1] with the entry source path
  ProcessArgv-->>CompilePipeline: Preserve seeded argv[1] and later arguments
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 72.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 9 files. (1 skipped: 1 unsupported.) Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main runtime fix: preserving the entry source path in process.argv.
Description check ✅ Passed The description clearly explains the changes, root cause, and validation, and it covers the required technical information despite omitting some template headings.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

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.

1 participant