Repository navigation
fix(store): refuse duplicate variable names from the variables code view (DOPE-616) - #1088
Conversation
… (DOPE-616) The table validated names per row; the text paths (code view commit, reconcile) replaced the list verbatim, so a duplicate reached the table and failed only at compile time. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (6)
Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review. WalkthroughShared utilities now detect case-insensitive duplicate variable names. Code-mode reconciliation and both variable editors reject duplicates. Direct POU and global list replacement accepts incoming lists as-is. Tests cover both behaviors. ChangesDuplicate variable validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to Code-view commits now reject duplicate variable names case-insensitively without changing stored variables, while restore and reclassification paths can retain existing duplicate-containing projects. The change is ready to merge. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Code Review — DOPE-616Verdict: request changes — one placement issue, everything else is clean. Small, well-targeted fix. Validating the parsed list in the store, where every text path converges, is the right instinct — better than patching each editor. Both files are byte-identical with the mirror, CI is fully green including all four The problem is where the guard sits, not what it does. 🔴 The guard was added to generic setters, but four of six call sites ignore the failure
Note what the input to those four is: not user-typed text, but already-stored state round-tripped through The undo/redo pair is the sharp one. Your own doc comment states the intent exactly: "Text paths (code view commit, reconcile) skip the table's per-row validation, so the list is checked whole." Agreed — but Suggested: keep the guard on the text boundary only — 🟢 Minor
✅ What is solid
To approve: move the guard off the generic setters, or make the four internal call sites explicit about it. Everything else here is ready. |
…616) Undo/redo and reclassification restore through setPouVariables and setGlobalVariables and never read the response, so a stored duplicate would have left globals unrestored. The check now runs where text is parsed: the two code-view commits and reconcileVariablesText. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Thanks — the call-site table is exactly right, and the undo/redo case is the one that mattered: a project that already carries a duplicate would have come back from an undo with its POU variables and body restored but its globals silently left behind. Took your first option. Guard moved to the text boundary, setters unconditional again:
On the minor: the helper now lives next to the parser ( Both files byte-identical with the mirror; store + utils suites green locally in both repos. |
Fixes DOPE-616.
Mirror of https://github.com/Autonomy-Logic/openplc-web/pull/737
Problem
Declaring an already-taken variable name in the variables code view and switching back to the table was accepted: two rows with the same name, both written on save, failing only at compile time (
strucpp: Symbol 'MOTOR' already defined in scope 'MAIN'). The table's own create/update refuse the same duplicate. Pre-existing onmain— the text path never validated names.Fix
Validate the parsed list in the store, where every text path converges, instead of in each editor:
findDuplicateVariableName— first name declared twice, case-insensitive (IEC identifiers are case-insensitive, same rule ascheckIfVariableExists).setPouVariables,setGlobalVariables(code view → table for POU variables and resource globals) andreconcileVariablesText(row edit / Ctrl+S while the code view is open) returnfail('"<name>" is declared more than once…', 'Variable already exists')before touching state.commitCodeand the globals editor already turn a non-ok response into the "Syntax error" toast and keep the code view open, so no component change.Tests
project-slice.test.ts: duplicate and case-only duplicate refused bysetPouVariables(table untouched), duplicate refused bysetGlobalVariables, reconcile path refused viacreateVariableon a code-mode buffer withMotor/motor.Shared surface:
src/frontend/**only, byte-identical with the sibling PR.🤖 Generated with Claude Code
Summary by CodeRabbit