Skip to content

A worktree-wide .openscience overrides the one in the directory you are working in #798

Closed

Description

What happens

Config.get() collects the project .openscience directories with Filesystem.up and then merges them in the order returned:

const projectDirectories = !Flag.OPENSCIENCE_DISABLE_PROJECT_CONFIG
  ? await Array.fromAsync(
      Filesystem.up({
        targets: [".openscience", ".synsc"],
        start: Instance.directory,
        stop: Instance.worktree,
      }),
    )
  : []
...
for (const dir of unique(directories)) {
  ...
  result = mergeConfigConcatArrays(result, config)   // later wins
}

Two facts collide here:

  • Filesystem.up walks from start upwards, so it yields the nearest directory first.
  • mergeConfigConcatArrays is later-wins.

Walking the list as returned therefore applies the farthest directory last, so the worktree-wide .openscience overrides the one written for the directory the run is in.

The project openscience.json block a few lines above already gets this right — for (const resolved of found.toReversed()) — which is why the two disagree with each other.

Why it is wrong

A repo can carry a shared .openscience/ at its root and a more specific one in a subtree. The subtree's settings are the ones a user writes to change behaviour for that part of the tree; they are silently ignored.

The most visible symptom is a model set for a subtree always reporting the repository default, so an experiment in src/tool/ runs against a different model than the one configured for it, with nothing in the output to say so.

Reproduction

worktree/.openscience/openscience.json      { "model": "model-from-the-worktree-root", "theme": "root-theme" }
worktree/src/tool/.openscience/openscience.json  { "model": "model-from-this-directory" }

Run in worktree/src/tool:

const config = await Config.get()
config.model   // "model-from-the-worktree-root"   (expected "model-from-this-directory")

Suggested fix

Reverse the collected list, matching what the CONFIG_FILES block above already does:

).toReversed()

Added as test/config/project-config-precedence.test.ts, which also asserts a key set only by the outer directory still comes through, and that the outer file still applies when there is no nested .openscience.

Note on pre-existing failures

test/config/config.test.ts has 4 failures on main in this checkout (loads agents from .openscience/agents (plural), the two loads commands from .openscience/command(s) cases, and resolves scoped npm plugins in config). They fail identically before and after this change — 58 pass / 4 fail either way — and appear to be Windows-specific. test/config/markdown.test.ts is likewise 22 pass / 15 fail on main.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions