0
0
Fork 0
Codesys-MCP-SP21-plus/tests
Karstein Phobic Nyvold Kvistad 0f8981d6bd fix(rename_object): rewrite \bOldName\b refs in every POU/DUT/GVL by default
Empirical failure: rename_object Application/ST_Sample -> ST_SampleRenamed updated the struct's own TYPE header but Application/PLC_PRG kept 's : ST_Sample;' -- the old name -- breaking the project.
Root cause: scriptengine.ScriptObject.rename()/set_name() is a node-local rename only; the IDE's project-wide Rename refactor lives above the scripting layer (no documented find_references() / refactor variant).
Fix: after the local rename succeeds, walk every text-bearing object (textual_declaration / textual_implementation), word-boundary regex-replace \bOldName\b -> NewName via a callback (so backslashes in NewName don't get interpreted as backrefs), set_text the changed nodes, save once. New optional updateReferences param defaults to true; pass false for the legacy minimal-rename behaviour.
Docs: https://content.helpme-codesys.com/en/ScriptingEngine/ScriptObject.html

Risk: false positives in comments / string literals are theoretically
possible but rare for IEC identifiers. Documented in the tool description.

The target node itself is skipped during the references walk (matched by
get_id()) so the rename's already-updated TYPE/FUNCTION_BLOCK/PROGRAM
header isn't double-rewritten.

Two new vitest e2e checks added: assert UPDATE_REFERENCES=1 renders the
re.escape + word-boundary regex, and UPDATE_REFERENCES=0 still produces
a fully-substituted script with no leftover placeholders.

### Manual smoke test
1. Open a project with: a DUT 'ST_Sample', a POU 'PLC_PRG' with
   'VAR s : ST_Sample; END_VAR', and a third POU referencing 'ST_Sample.foo'.
2. mcp__codesys__rename_object objectPath=Application/ST_Sample
   newName=ST_SampleRenamed.
3. Expect SCRIPT_SUCCESS with 'References Updated In: 2 node(s)'.
4. mcp__codesys__compile_project should succeed (no unresolved-symbol
   errors for ST_Sample).
5. With updateReferences=false, the same rename should leave PLC_PRG
   stale and compile_project should fail -- validates the opt-out.
6. Word-boundary check: rename 'Foo' -> 'Bar' must NOT touch 'FooBar'
   or 'BarFoo' anywhere.
2026-04-28 20:58:45 +02:00
..
integration fix(rename_object): rewrite \bOldName\b refs in every POU/DUT/GVL by default 2026-04-28 20:58:45 +02:00
unit feat(open_project): pre-flight profile-mismatch check using offline .project inspection 2026-04-27 22:32:53 +02:00
bench-results-v5.json test(bench): v5 sweep -- fix set_pou_code params, all 10 cases pass 2026-04-26 19:30:48 +02:00
bench-results.json fix: 4 broken-tool fixes (compile json long, connect_to_device LoginMode, 2026-04-26 16:53:25 +02:00
bench.mjs test(bench): v5 sweep -- fix set_pou_code params, all 10 cases pass 2026-04-26 19:30:48 +02:00
mock_watcher.py Initial release: MCP server for CODESYS with persistent UI instance 2026-02-08 18:59:16 +10:00
test-fixes.mjs fix(create_folder): try project.create_folder(name, SV_POU) first; drop ScriptManager cache 2026-04-26 17:16:44 +02:00
TEST_OVERVIEW.md rename: Codesys-MCP-SP22+ -> Codesys-MCP-SP21+ + multi-install README + missing tools 2026-04-26 22:02:46 +02:00