-
-
Notifications
You must be signed in to change notification settings - Fork 158
test: cover compilePackages RegExp dispatch on macOS #8995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
proggeramlug
merged 2 commits into
PerryTS:main
from
proggeramlug:fix/8905-regexp-package-prototype
Aug 29, 2026
+163
−2
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Compiled packages retain RegExp method behavior when they receive a regular | ||
| expression created by application code, including on macOS allocations below | ||
| 2 TB. This covers schema-library paths such as zod regex and datetime checks | ||
| when compiling with the full prebuilt stdlib. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
crates/perry/tests/issue_8905_regexp_package_boundary.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| //! Regression test for #8905: a RegExp passed into a `compilePackages` | ||
| //! dependency must retain RegExp method behavior when the dependency reads it | ||
| //! back through an object property. | ||
|
|
||
| use std::path::PathBuf; | ||
| use std::process::Command; | ||
| use std::sync::Once; | ||
|
|
||
| fn perry_bin() -> PathBuf { | ||
| PathBuf::from(env!("CARGO_BIN_EXE_perry")) | ||
| } | ||
|
|
||
| fn workspace_root() -> PathBuf { | ||
| PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| .join("../..") | ||
| .canonicalize() | ||
| .expect("canonicalize workspace root") | ||
| } | ||
|
|
||
| fn target_debug_dir() -> PathBuf { | ||
| let target = std::env::var_os("CARGO_TARGET_DIR") | ||
| .map(PathBuf::from) | ||
| .unwrap_or_else(|| workspace_root().join("target")); | ||
| if cfg!(windows) { | ||
| target.join("x86_64-pc-windows-msvc").join("debug") | ||
| } else { | ||
| target.join("debug") | ||
| } | ||
| } | ||
|
|
||
| fn ensure_runtime_archives() { | ||
| static BUILD_RUNTIME: Once = Once::new(); | ||
| BUILD_RUNTIME.call_once(|| { | ||
| let cargo = std::env::var_os("CARGO").unwrap_or_else(|| "cargo".into()); | ||
| let mut command = Command::new(cargo); | ||
| command | ||
| .current_dir(workspace_root()) | ||
| .arg("build") | ||
| .arg("-p") | ||
| .arg("perry-runtime-static") | ||
| .arg("-p") | ||
| .arg("perry-stdlib-static"); | ||
| if cfg!(windows) { | ||
| command.arg("--target").arg("x86_64-pc-windows-msvc"); | ||
| } | ||
| let build = command.output().expect("build static runtime archives"); | ||
| assert!( | ||
| build.status.success(), | ||
| "runtime archive build failed\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&build.stdout), | ||
| String::from_utf8_lossy(&build.stderr) | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn regexp_methods_survive_the_compiled_package_boundary() { | ||
| let dir = tempfile::tempdir().expect("tempdir"); | ||
| let root = dir.path(); | ||
|
|
||
| std::fs::write( | ||
| root.join("package.json"), | ||
| r#"{ | ||
| "name": "regexp-package-boundary", | ||
| "private": true, | ||
| "type": "module", | ||
| "perry": { | ||
| "compilePackages": ["regex-consumer"], | ||
| "allow": { "compilePackages": ["regex-consumer"] } | ||
| } | ||
| }"#, | ||
| ) | ||
| .expect("write consumer package.json"); | ||
|
|
||
| let package = root.join("node_modules/regex-consumer"); | ||
| std::fs::create_dir_all(&package).expect("mkdir regex-consumer"); | ||
| std::fs::write( | ||
| package.join("package.json"), | ||
| r#"{ | ||
| "name": "regex-consumer", | ||
| "version": "1.0.0", | ||
| "type": "module", | ||
| "exports": "./index.js" | ||
| }"#, | ||
| ) | ||
| .expect("write dependency package.json"); | ||
| std::fs::write( | ||
| package.join("index.js"), | ||
| r#" | ||
| import { randomUUID } from "node:crypto"; | ||
|
|
||
| export function makeRegexCheck(def) { | ||
| return (value) => { | ||
| def.pattern.lastIndex = 0; | ||
| return def.pattern.test(value); | ||
| }; | ||
| } | ||
|
|
||
| export function stdlibMarker() { | ||
| return typeof randomUUID; | ||
| } | ||
| "#, | ||
| ) | ||
| .expect("write compiled dependency"); | ||
|
|
||
| let entry = root.join("main.ts"); | ||
| std::fs::write( | ||
| &entry, | ||
| r#" | ||
| import { makeRegexCheck, stdlibMarker } from "regex-consumer"; | ||
|
|
||
| const check = makeRegexCheck({ pattern: /^a+$/ }); | ||
| console.log(stdlibMarker(), check("aaa"), check("bbb")); | ||
| "#, | ||
| ) | ||
| .expect("write entry"); | ||
|
|
||
| // The node:crypto import forces the full-stdlib link used by the reporter. | ||
| // With PERRY_NO_AUTO_OPTIMIZE that can put a second statically linked | ||
| // runtime on the compiled-package side of this RegExp method call. | ||
| ensure_runtime_archives(); | ||
| let output = root.join("main_bin"); | ||
| let compile = Command::new(perry_bin()) | ||
| .current_dir(root) | ||
| .arg("compile") | ||
| .arg(&entry) | ||
| .arg("-o") | ||
| .arg(&output) | ||
| .arg("--no-cache") | ||
| .env("PERRY_NO_AUTO_OPTIMIZE", "1") | ||
| .env("PERRY_RUNTIME_DIR", target_debug_dir()) | ||
| .output() | ||
| .expect("run perry compile"); | ||
| assert!( | ||
| compile.status.success(), | ||
| "perry compile failed\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&compile.stdout), | ||
| String::from_utf8_lossy(&compile.stderr) | ||
| ); | ||
|
|
||
| let run = Command::new(&output).output().expect("run compiled binary"); | ||
| assert!( | ||
| run.status.success(), | ||
| "compiled binary failed\nstatus: {:?}\nstdout:\n{}\nstderr:\n{}", | ||
| run.status, | ||
| String::from_utf8_lossy(&run.stdout), | ||
| String::from_utf8_lossy(&run.stderr) | ||
| ); | ||
| assert_eq!( | ||
| String::from_utf8_lossy(&run.stdout), | ||
| "function true false\n" | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50370
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50371
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 28264
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 475
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 42936
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 8419
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 9209
Resolve relative
CARGO_TARGET_DIRagainstworkspace_root.If
CARGO_TARGET_DIR=target,target_debug_dir()passestarget/debugtoPERRY_RUNTIME_DIR.perry compileruns from the temporary fixture directory, and the runtime lookup tests this relative path there instead of underworkspace_root(). Resolve relative target paths againstworkspace_root().🤖 Prompt for AI Agents