Skip to content

fix: resolve #[ScriptDir] to __DIR__ instead of baking the compile-time absolute path#136

Merged
koriym merged 1 commit into
ray-di:1.xfrom
NaokiTsuchiya:claude/ray-compiler-absolute-path-95addc
Jul 11, 2026
Merged

fix: resolve #[ScriptDir] to __DIR__ instead of baking the compile-time absolute path#136
koriym merged 1 commit into
ray-di:1.xfrom
NaokiTsuchiya:claude/ray-compiler-absolute-path-95addc

Conversation

@NaokiTsuchiya

@NaokiTsuchiya NaokiTsuchiya commented Jul 11, 2026

Copy link
Copy Markdown
Member

ScriptDir (and InjectorInterface, which requires it) was var_export()'d into generated scripts as a literal build-time path, breaking when the compiled directory is moved (immutable images, CI build path != runtime path, etc.).

Since scripts always run from inside scriptDir, emit __DIR__ instead of the baked path.

Added tests/ScriptDirRelocationTest.php: compiles, relocates the directory, and asserts ctor/setter/provider/AOP bindings + InjectorInterface all still resolve, and no generated script contains the old path. Confirmed the test fails without the fix.

Summary by CodeRabbit

  • Bug Fixes

    • Script directory injection now resolves to the generated script’s runtime location.
    • Generated scripts no longer embed compile-time absolute paths, improving portability when build output is moved.
    • Dependency injection remains functional for constructor, setter, provider, and interceptor-based integrations after relocation.
  • Tests

    • Added coverage validating relocated script directories, generated paths, and related dependency bindings.

…me path

Ray\Di\Annotation\ScriptDir and Ray\Di\InjectorInterface were bound via
CompilerModule::toInstance() with the compile-time absolute scriptDir,
so both got var_export()'d as a string literal into every generated
script that pulled either binding into the object graph (e.g. via
assisted injection or multibinding, which require InjectorInterface
internally). Moving the compiled scripts to a different absolute path
after compilation (immutable images, CI build vs. runtime path, etc.)
either threw ScriptDirNotReadable or silently resolved against a
stale path.

Since generated scripts always live inside scriptDir, __DIR__ at
require-time is always correct. Special-case the ScriptDir binding's
container key in InstanceScript::addArg() and Compiler::compile()'s
map() callback to emit __DIR__ instead of the baked path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f82a5fad-df32-4a43-8bd2-464c728ce652

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

ScriptDir dependencies now generate __DIR__-based scripts instead of compile-time paths. New test fixtures cover multiple injection modes, and relocation tests verify runtime directory resolution after moving compiled output.

Changes

ScriptDir Relocation

Layer / File(s) Summary
Runtime ScriptDir handling
src/InstanceScript.php, src/Compiler.php
Adds the RAY_DI_SCRIPT_DIR key, injects __DIR__ into generated scripts, and bypasses normal compilation for the special dependency.
ScriptDir injection fixtures
tests/Fake/FakeScriptDir*.php
Adds consumers, provider, interface, module bindings, and AOP wiring for constructor, setter, provider, and AOP injection paths.
Relocation validation
tests/ScriptDirRelocationTest.php
Compiles and relocates generated scripts, checks for baked build paths, and verifies ScriptDir-related bindings resolve to the runtime directory.

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

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant CompiledInjector
  participant GeneratedScript
  participant Consumer
  Test->>CompiledInjector: load relocated compiled output
  CompiledInjector->>GeneratedScript: resolve ScriptDir binding
  GeneratedScript-->>CompiledInjector: return __DIR__
  CompiledInjector->>Consumer: inject runtime directory
  Consumer-->>Test: return script directory
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely captures the main change: resolving #[ScriptDir] to __DIR__ instead of baking an absolute path.
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.

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9e3a2d0) to head (4e69a02).

Additional details and impacted files
@@             Coverage Diff             @@
##                 1.x      #136   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity        93        95    +2     
===========================================
  Files             11        11           
  Lines            232       238    +6     
===========================================
+ Hits             232       238    +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@koriym

koriym commented Jul 11, 2026

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@koriym
koriym merged commit c572dae into ray-di:1.x Jul 11, 2026
18 checks passed
@NaokiTsuchiya
NaokiTsuchiya deleted the claude/ray-compiler-absolute-path-95addc branch July 11, 2026 13:58
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