Skip to content

fix(core): prefer current repo when resolving amber home path#4263

Open
carloea2 wants to merge 2 commits intoapache:mainfrom
carloea2:fix/amber_home_path
Open

fix(core): prefer current repo when resolving amber home path#4263
carloea2 wants to merge 2 commits intoapache:mainfrom
carloea2:fix/amber_home_path

Conversation

@carloea2
Copy link
Contributor

@carloea2 carloea2 commented Mar 7, 2026

What changes were proposed in this PR?

This PR fixes an issue in amberHomePath resolution where the previous implementation could select the wrong repo when multiple sibling directories under the same parent satisfied isAmberHomePath(...).

lazy val amberHomePath: Path = {
val currentWorkingDirectory = Paths.get(".").toRealPath()
// check if the current directory is the amber home path
if (isAmberHomePath(currentWorkingDirectory)) {
currentWorkingDirectory
} else {
// from current path's parent directory, search its children to find amber home path
// current max depth is set to 2 (current path's siblings and direct children)
val searchChildren = Files
.walk(currentWorkingDirectory.getParent, 2)
.filter((path: Path) => isAmberHomePath(path))
.findAny
if (searchChildren.isPresent) {
searchChildren.get
} else {
throw new RuntimeException(
"Finding texera home path failed. Current working directory is " + currentWorkingDirectory
)
}
}
}

Previously, if the current working directory was not itself recognized as the Amber home path, the code would walk the parent directory and return findAny() from matching paths. In environments with multiple Texera/Amber repos under the same parent, this could resolve to an unrelated sibling repo instead of the repo the process was launched from.

This PR changes the logic to:

  • keep returning the current working directory immediately when it is already a valid Amber home path
  • guard against searching from filesystem root when there is no parent
  • prefer the closest valid match associated with the current working directory
  • fall back to any valid match only when no closer candidate is found
  • normalize returned paths with toRealPath()
  • close Files.walk(...) safely using Using.resource(...)

This makes Amber home path detection more deterministic and prevents accidentally selecting the wrong engine/repo in multi-repo local setups.

Any related issues, documentation, discussions?

Closes #4262

How was this PR tested?

Manually tested with a local directory layout where multiple sibling repos satisfy isAmberHomePath(...).

Example setup:

E:\texera\
  ├─ texera\
  └─ a\

Was this PR authored or co-authored using generative AI tooling?

No.

@carloea2
Copy link
Contributor Author

carloea2 commented Mar 7, 2026

@chenlica Can you assign a reviewer? Thanks.

@chenlica
Copy link
Contributor

chenlica commented Mar 7, 2026

@aglinxinyuan @Xiao-zhen-Liu Please review this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Amber home path detection may select the wrong repo when sibling repos exist

2 participants