Repository navigation
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.upwalks fromstartupwards, so it yields the nearest directory first.mergeConfigConcatArraysis 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.
Activity