Skip to content

fix: resolve functionsDir relative to ruleset file, not process CWD. …#48

Merged
jeremnaf merged 1 commit into
mainfrom
Fix/RelativeFunctionsDir
Jun 17, 2026
Merged

fix: resolve functionsDir relative to ruleset file, not process CWD. …#48
jeremnaf merged 1 commit into
mainfrom
Fix/RelativeFunctionsDir

Conversation

@jeremnaf

Copy link
Copy Markdown
Collaborator

Closes #44

Related Issue

Closes #44


What does this PR do?

When a ruleset declares functionsDir: ./functions (a path relative to the ruleset file), Polychro was resolving it against the process working directory (CWD) instead of the ruleset file's parent directory. This caused custom JS functions to be silently skipped whenever --ruleset was passed as an absolute (or otherwise non-CWD-relative) path.

Root cause: RulesetValidatorFactory.create() correctly computed baseDir from the ruleset path, but never passed it to new RulesetValidator(ruleset, includeNonRecommended). Inside that constructor, Path.of(ruleset.functionsDir()) created a CWD-relative path that could not be resolved to the actual scripts.

Fix:

  • Add RulesetValidator(Ruleset, Path baseDir, boolean) constructor that resolves functionsDir against baseDir via baseDir.resolve(raw).normalize() when baseDir is non-null.
  • Keep the existing two-arg constructor as a delegate (baseDir = null) to preserve the current CWD-relative behaviour for inline-content rulesets.
  • RulesetValidatorFactory.create() now extracts baseDir from rulesetPath and forwards it to the new three-arg constructor; the content-only path continues to use the two-arg constructor.

Tests

Added FunctionsDirResolutionTest in polychro-ruleset-polyglot:

  • Writes a ruleset with functionsDir: ./functions to a JUnit @TempDir alongside a copy of unique-namespaces.js.
  • Loads the ruleset via its absolute path while the process CWD is a different directory (the @TempDir root, not the rules/ sub-directory).
  • Asserts that the custom JS function fires and produces a naftiko-unique-namespaces diagnostic.

This test was written first (RED), then the fix was applied (GREEN), confirming the regression. All 637 existing tests in polychro-api, polychro-ruleset, and polychro-ruleset-polyglot continue to pass.


Checklist

  • CI is green (build + tests)
  • Rebased on latest main
  • Small and focused — one concern per PR
  • Commit messages follow Conventional Commits
  • Apache 2.0 license header present on any new Java file

Agent Context (optional)

agent_name: GitHub Copilot
llm: Naftiko Claude Sonnet 4.6
tool: VS Code
confidence: high
source_event: issue #44
discovery_method: user_report
files_suspected:
  - polychro-ruleset/src/main/java/io/polychro/ruleset/RulesetValidatorFactory.java
  - polychro-ruleset/src/main/java/io/polychro/ruleset/RulesetValidator.java

@jeremnaf jeremnaf requested a review from eskenazit June 15, 2026 16:02
@jeremnaf jeremnaf force-pushed the Fix/RelativeFunctionsDir branch from 25f84fe to 124ece9 Compare June 15, 2026 16:19
@eskenazit eskenazit force-pushed the Fix/RelativeFunctionsDir branch from 124ece9 to 97b35f9 Compare June 16, 2026 14:57

@eskenazit eskenazit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good fix overall — the core logic in RulesetValidator and RulesetValidatorFactory is correct and well-tested. One observation on the regression test (1).

@jeremnaf jeremnaf force-pushed the Fix/RelativeFunctionsDir branch from 97b35f9 to 2abcd35 Compare June 17, 2026 09:19
@eskenazit eskenazit force-pushed the Fix/RelativeFunctionsDir branch from 2abcd35 to f1ad2a8 Compare June 17, 2026 09:31

@eskenazit eskenazit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@jeremnaf jeremnaf merged commit 9829e23 into main Jun 17, 2026
2 checks passed
@jeremnaf jeremnaf deleted the Fix/RelativeFunctionsDir branch June 17, 2026 12:13
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.

fix(rulesets): resolve functionsDir relative to the ruleset file, not the process CWD

2 participants