Skip to content

fix: reject two source files that share a name (port files collide) - #726

Open
SahilKumar965 wants to merge 1 commit into
ControlCore-Project:devfrom
SahilKumar965:fix/port-stem-collision
Open

SahilKumar965 wants to merge 1 commit into
ControlCore-Project:devfrom
SahilKumar965:fix/port-stem-collision

Conversation

@SahilKumar965

@SahilKumar965 SahilKumar965 commented Nov 29, 2026 •

Copy link
Copy Markdown

mkconcore names each node's port files after its source file stem (mkconcore.py:837), so CZ:controller.py and PZ:controller.m both write src/controller.iport / .oport. The second write wins and both nodes copy the same file, so the controller silently gets the plant's ports. concore validate said the workflow was valid and the build succeeded. Dockerfiles, docker build folders and image names use the same stem, so docker builds clash too.

concore add-node made this easy to hit: concore init + add-node --lang octave gave script.py + script.m.

Repro (before this PR):

mkdir -p /tmp/pc/src
cp demo/controller.py /tmp/pc/src/
cp demo/pm.py /tmp/pc/src/controller.m
sed 's/PZ:pm.py/PZ:controller.m/' demo/sample.graphml > /tmp/pc/col.graphml
cd /tmp/pc
concore validate col.graphml --source src   # "valid"
concore build col.graphml --source src --output out
cat out/src/controller.iport                 # {'CU': 1}, the plant's ports

After: validate fails with Source files share the name 'controller': controller.m, controller.py (rename one of them) and mkconcore exits with the same message.

Change

  • validate and mkconcore reject two different source files with the same stem. The check is case-insensitive, since script.iport and Script.iport are one file on Windows/macOS.
  • One source shared by several nodes (e.g. demo/gencon2.graphml, PZ:pm.py + PS:pm.py) is still accepted.
  • add-node and the init -i wizard now pick a free stem (script.py, script2.m, Script3.java). The helper lives in init.py and replaces add_node._pick_filename, and the Java class is still renamed to match the file.

Tests

  • New tests in test_duplicate_container_names.py: reject same stem (validate + mkconcore), reject stems that differ only in case, accept one source shared by two nodes.
  • test_add_node_command.py: updated the two tests that expected script.cpp / Script.java next to script.py; added a wizard test (python + octave + java) and made the "still validates" test add an octave node.
  • 6 of these fail without the fix. The full suite passes locally (525 passed) and ruff is clean.

Notes

  • Behaviour change: in a fresh concore init project, the first added C++/Octave/Java node is now script2.cpp / script2.m / Script2.java.
  • Not in this PR: nodes that share one source also share one port-file pair, so a script reading concore.iport['NAME'] would see the other node's names (the demos read ports by number, so they work). Fixing that means naming port files per node, which touches the generated scripts and docker images. I can do it as a follow-up if you'd like that approach.
  • Tested on Linux only.

mkconcore names port files, Dockerfiles and docker images after the
source stem, so CZ:controller.py and PZ:controller.m both write
src/controller.iport and one node silently gets the other's ports.

validate and mkconcore now reject different sources with the same
stem (case-insensitive). One source shared by several nodes still
works. add-node and the init wizard pick a free stem instead of
script.py + script.m.
@github-actions

Copy link
Copy Markdown

🎉 Welcome aboard, @SahilKumar965! Thank you for your first pull request in concore.

Please ensure that you are contributing to the dev branch.

Your contribution means a lot to us. We'll review it shortly.

Please ensure you have reviewed our:

If you have any questions, feel free to ask. Happy coding!

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.

1 participant