Skip to content

fix: select the nearest enclosing config, not the first filename's - #4

Merged
TomChv merged 1 commit into
mainfrom
fix/find-config-dirs-order
Jul 21, 2026
Merged

TomChv merged 1 commit into
mainfrom
fix/find-config-dirs-order

Conversation

@TomChv

@TomChv TomChv commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

Fixes #2.

Problem

parentConfigDir reduced with acc ?? ws.findUp(name, "."), so the first filename that matched anywhere up the tree won — regardless of how far up it was. With ["deno.json", "deno.jsonc"] and:

parent/
├── deno.json
└── child/
    ├── deno.jsonc
    └── nested/   # cwd

findConfigDirs returned ["../.."] (parent) instead of [".."] (parent/child).

The same order-dependence produced the second symptom from the issue comment: standing exactly at child, walk-down added . while find-up independently added the farther ancestor, yielding [".", ".."] where the local config should shadow it.

Downstream consumers hit this too — dagger/ruff#1 (pyproject.toml before ruff.toml) and dagger/pytest#19 (pytest.ini before pyproject.toml).

Fix

Search every filename and keep the deepest hit. Every findUp(name, ".") result lies on the cwd's own ancestor chain, so the deepest directory is the nearest project — no path comparison, no prefix matching.

let hit = filenames.reduce(null) { acc, name =>
  let found = ws.findUp(name, ".")
  if (hitRank(found) > hitRank(acc)) { found } else { acc }
}

hitRank is 0 for no hit and depth + 1 otherwise, so a hit at the workspace root still outranks nothing. configDirOf and depthOf are extracted from what parentConfigDir and ancestorRelPath were already doing inline.

The cwd-shadowing case falls out for free: the cwd's own config is now the deepest hit, so it's the one compared against cwd and dropped.

Tests

New fixture fixtures/find-config-dirs/nearest/ plus two checks:

check asserts
nearestMixedFilenameCheck from child/nested → [".."], and it resolves back to child's deno.jsonc
mixedFilenameShadowCheck from child → ["."], the ancestor does not come back

Verified against v1.0.0-beta.7. With the fix, all 16 checks pass. With workspace.dang reverted and only the tests applied, the two new checks fail with exactly the reported numbers:

✘ nearest-mixed-filename-check  from child/nested: got [../..], want [..]
✘ mixed-filename-shadow-check   from child: got [.., .], want [.]

Fixture-based rather than the withNewFile form of the repro commit, to match how the file's other checks read after #3 — thanks @grouville for the reproduction.

Follow-up

Consumers pinning polyfill need repinning once this lands: dagger/ruff, dagger/pytest, dagger/python-sdk#9, dagger/typescript-sdk#11.

parentConfigDir kept the first non-null findUp across filenames, so a farther
ancestor won whenever its config filename was searched first. From
parent/child/nested, with parent/deno.json and parent/child/deno.jsonc, the
result was ../.. instead of ..

Search every filename and keep the deepest hit. All hits lie on the cwd's own
ancestor chain, so the deepest one is the nearest project — no path comparison
needed. This also fixes the case where the cwd holds a config under a later
filename: that hit is now the deepest, equals the cwd, and is dropped, so the
result no longer contains both "." and a farther ancestor.

Fixes #2

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv

TomChv commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

CI isn't enabled yet on polyfill, I tested locally and it worked

@TomChv
TomChv merged commit e90bbfc into main Jul 21, 2026
grouville added a commit to grouville/pytest that referenced this pull request Jul 21, 2026
Polyfill previously selected the first config filename found while walking
up, allowing a farther pytest.ini to shadow a nearer pyproject.toml.

Pin the merged dagger/polyfill#4 revision so Pytest discovery consistently
uses the nearest enclosing project. Keep the distance logic in the shared
discovery implementation instead of duplicating it in this adapter.

Signed-off-by: Guillaume de Rouville <[email protected]>
grouville added a commit to grouville/ruff that referenced this pull request Jul 21, 2026
Polyfill previously selected the first config filename found while walking
up, allowing a farther pyproject.toml to shadow a nearer ruff.toml.

Pin the merged dagger/polyfill#4 revision so Ruff discovery consistently uses
the nearest enclosing project. Keep the distance logic in the shared
discovery implementation instead of duplicating it in this adapter.

Signed-off-by: Guillaume de Rouville <[email protected]>
grouville added a commit to grouville/python-sdk that referenced this pull request Jul 21, 2026
Polyfill previously selected the first config filename found while walking
up, so mixed dagger.json and dagger-module.toml layouts could resolve to the
farther module based on filename order.

Pin the merged dagger/polyfill#4 revision for shared module discovery. The
explicit mod lookup continues to perform its own nearest-config validation;
the shared modules path now has the same behavior without another workaround.

Signed-off-by: Guillaume de Rouville <[email protected]>
grouville added a commit to grouville/pytest that referenced this pull request Jul 21, 2026
Polyfill previously selected the first config filename found while walking
up, allowing a farther pytest.ini to shadow a nearer pyproject.toml.

Pin the merged dagger/polyfill#4 revision so Pytest discovery consistently
uses the nearest enclosing project. Keep the distance logic in the shared
discovery implementation instead of duplicating it in this adapter.

Signed-off-by: Guillaume de Rouville <[email protected]>
grouville added a commit to grouville/ruff that referenced this pull request Jul 21, 2026
Polyfill previously selected the first config filename found while walking
up, allowing a farther pyproject.toml to shadow a nearer ruff.toml.

Pin the merged dagger/polyfill#4 revision so Ruff discovery consistently uses
the nearest enclosing project. Keep the distance logic in the shared
discovery implementation instead of duplicating it in this adapter.

Signed-off-by: Guillaume de Rouville <[email protected]>
grouville added a commit to grouville/python-sdk that referenced this pull request Jul 21, 2026
Polyfill previously selected the first config filename found while walking
up, so mixed dagger.json and dagger-module.toml layouts could resolve to the
farther module based on filename order.

Pin the merged dagger/polyfill#4 revision for shared module discovery. The
explicit mod lookup continues to perform its own nearest-config validation;
the shared modules path now has the same behavior without another workaround.

Signed-off-by: Guillaume de Rouville <[email protected]>
grouville added a commit to grouville/python-sdk that referenced this pull request Jul 21, 2026
Polyfill previously selected the first config filename found while walking
up, so mixed dagger.json and dagger-module.toml layouts could resolve to the
farther module based on filename order.

Pin the merged dagger/polyfill#4 revision for shared module discovery. The
explicit mod lookup continues to perform its own nearest-config validation;
the shared modules path now has the same behavior without another workaround.

Signed-off-by: Guillaume de Rouville <[email protected]>
grouville added a commit to dagger/pytest that referenced this pull request Jul 21, 2026
* feat: make Pytest discovery cwd-aware

* chore: pick up nearest-config polyfill fix

Polyfill previously selected the first config filename found while walking
up, allowing a farther pytest.ini to shadow a nearer pyproject.toml.

Pin the merged dagger/polyfill#4 revision so Pytest discovery consistently
uses the nearest enclosing project. Keep the distance logic in the shared
discovery implementation instead of duplicating it in this adapter.

Signed-off-by: Guillaume de Rouville <[email protected]>

---------

Signed-off-by: Guillaume de Rouville <[email protected]>
grouville added a commit to grouville/python-sdk that referenced this pull request Jul 21, 2026
Polyfill previously selected the first config filename found while walking
up, so mixed dagger.json and dagger-module.toml layouts could resolve to the
farther module based on filename order.

Pin the merged dagger/polyfill#4 revision for shared module discovery. The
explicit mod lookup continues to perform its own nearest-config validation;
the shared modules path now has the same behavior without another workaround.

Signed-off-by: Guillaume de Rouville <[email protected]>
grouville added a commit to grouville/python-sdk that referenced this pull request Jul 21, 2026
Polyfill previously selected the first config filename found while walking up,
so mixed dagger.json and dagger-module.toml layouts could resolve to a farther
module based on filename order.

Pin the dagger/polyfill#4 fix and cover a managed Python module whose nearby
dagger.json is nested below an ancestor dagger-module.toml. Discovery from two
levels inside the module must select the nearby module and return "../..".

Signed-off-by: Guillaume de Rouville <[email protected]>
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.

findConfigDirs selects enclosing config by filename order instead of distance

1 participant