process-compose icon indicating copy to clipboard operation
process-compose copied to clipboard

With several -f files that use `extends`, a later file's base is merged too early

Open aliassar opened this issue 2 weeks ago • 0 comments

Defect

  • [x] Included the relevant configuration snippet
  • [ ] Included the relevant process-compose log (log location: process-compose info)
  • [x] Included a [Minimal, Complete, and Verifiable example] (https://stackoverflow.com/help/mcve)

Version of process-compose:

main at 190d026 (after v1.124.0)

OS environment:

macOS (arm64). It's in the loader, so it shouldn't depend on the OS.

Steps or code to reproduce the issue:

# c.yaml
version: "0.5"
processes:
  p:
    command: "echo from-c"
# a.yaml
version: "0.5"
extends: c.yaml
processes:
  p:
    command: "echo from-a"
# d.yaml
version: "0.5"
processes:
  p:
    command: "echo from-d"
# b.yaml
version: "0.5"
extends: d.yaml
processes:
  q:
    command: "echo q"
process-compose -f a.yaml -f b.yaml -t=false --no-server

Expected result:

p prints from-d. The merge docs say -f files are merged in the order they're given, and that extends: base is the same as -f base -f file. So this should behave like -f c.yaml -f a.yaml -f d.yaml -f b.yaml with the extends lines taken out, and that prints from-d.

Actual result:

p prints from-a:

[p	] from-a

The files are merged as c, d, a, b instead of c, a, d, b, so a.yaml overrides d.yaml.

The cause is in Load in src/loader/loader.go: it passes the file's index in the -f list to loadExtendProject, which inserts the extended project at that index in opts.projects. Once an earlier file's extends has added a project, that index is too small, so the base ends up before the earlier files. #294 had the same two-extending-files setup, but 9d9e730 only fixed the "already specified" error there, not the position.

aliassar avatar Nov 19 '26 20:11 aliassar