Skip to content

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

@carloea2

Description

@carloea2

What happened?

When Texera/Amber is launched from a nested directory, the current amberHomePath detection can pick the wrong repository if the parent folder contains multiple sibling repos that also satisfy 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
)
}
}
}

For example, if the working directory is:

E:\texera\texera

the old logic moves up to:

E:\texera

and then scans children up to depth 2 using findAny(). If there are multiple valid matches under E:\texera, such as:

  • E:\texera\texera
  • E:\texera\a

the method may return a different matching repo instead of the one the process was launched from.

This causes Amber home path resolution to be nondeterministic / incorrect depending on directory layout.

How to reproduce?

  1. Create a parent directory containing multiple repos that satisfy isAmberHomePath(...), for example:

    • E:\texera\texera
    • E:\texera\a
  2. Launch Texera/Amber with the working directory set to E:\texera\texera.

  3. Trigger code that evaluates amberHomePath.

  4. Observe that the previous implementation may resolve the home path to E:\texera\a instead of E:\texera\texera.

Root cause
The previous implementation does this:

  • if current working directory is not already the Amber home path
  • walk the parent directory to depth 2
  • return .findAny() match

Because .findAny() does not prefer the current repo lineage, a sibling repo can be selected incorrectly.

Version

1.1.0-incubating (Pre-release/Master)

Commit Hash (Optional)

No response

What browsers are you seeing the problem on?

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    triagePending for triaging

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions