0
0
Fork 0
Codesys-MCP-SP21-plus/tests/integration
phobicdotno 05d0e37e21
feat(remove_library): new MCP tool wrapping ScriptLibManObject.remove_library (#5)
Adds remove_library as the symmetric counterpart to add_library.

Script (src/scripts/remove_library.py):
- IronPython 2.7 / ASCII-only; no f-strings, no KeyboardInterrupt in
  except-Exception clauses.
- Placeholder substitution: LIBRARY_NAME (bare) and LIBRARY_FQN_OR_NAME
  (bare or "Name, Version (Company)").
- Locates the project Library Manager via the same three-step discovery
  used in add_library.py: has_library_manager/get_library_manager on the
  project, first-level child walk, then find("Library Manager") fallback.
- Pre-check: walks lm.references using _ref_name_matches logic (handles
  placeholder "#Name" and managed "Name, Version (Company)" forms).
  If the library is not referenced the script exits SCRIPT_SUCCESS with
  the "Library Not Present:" marker -- idempotent, same convention as
  add_library's dedup no-op branch.
- If found: calls lm.remove_library(existing_name) per the SP22 stub
  (ScriptLibManObject.pyi: remove_library(name: str)), confirms removal
  from lm.references, then project.save().
- Emits SCRIPT_SUCCESS or SCRIPT_ERROR with traceback on exception.

Server (src/server.ts):
- Tool registered immediately after add_library (~line 2067).
- Reads "Library Not Present:" marker to pick idempotent vs removed
  wording -- same marker-driven pattern as add_library's dedup wording.
- Thin surface: projectFilePath + libraryName (required) +
  libraryFqnOrName (optional, for multi-version disambiguation).

Tests (tests/integration/e2e.test.ts):
- Template-prep test asserts: no leftover {PLACEHOLDER}s, substituted
  values present, remove_library call present, references walk present,
  "Library Not Present" marker present, SCRIPT_SUCCESS/SCRIPT_ERROR
  markers present.
- All 22 tests pass.

References:
- helpme-codesys.com scripting engine > ScriptLibManObject
- SP22 stub: Stubs/scriptengine/ScriptLibManObject.pyi (remove_library
  at line 455, references property at line 464)

Co-authored-by: Karstein Phobic Nyvold Kvistad <karstein.kvistad@maritimerobotics.com>
2026-04-29 10:17:03 +02:00
..
e2e.test.ts feat(remove_library): new MCP tool wrapping ScriptLibManObject.remove_library (#5) 2026-04-29 10:17:03 +02:00
README.md Initial release: MCP server for CODESYS with persistent UI instance 2026-02-08 18:59:16 +10:00

Manual CODESYS Integration Tests

These tests require a real CODESYS installation and cannot run in CI.

Prerequisites

  • CODESYS 3.5 SP19 or SP21 installed
  • No other CODESYS instances running
  • Node.js 18+

Steps

1. Build the package

npm run build

2. Test persistent mode

node dist/bin.js \
  --codesys-path "C:\path\to\CODESYS.exe" \
  --codesys-profile "CODESYS V3.5 SP21 Patch 3" \
  --mode persistent \
  --verbose

Verify:

  • CODESYS UI opens
  • Console shows "CODESYS watcher is ready"
  • The MCP server accepts connections

3. Test headless fallback

node dist/bin.js \
  --codesys-path "C:\path\to\CODESYS.exe" \
  --codesys-profile "CODESYS V3.5 SP21 Patch 3" \
  --mode headless

4. Test --detect flag

node dist/bin.js --detect

Verify: Lists installed CODESYS versions.

5. Ctrl+C shutdown

  • Press Ctrl+C during persistent mode
  • Verify CODESYS shuts down cleanly