Streamline codebase: remove dead code and consolidate duplicated logic#177
Conversation
Code ReviewPR: Streamline codebase: remove dead code and consolidate duplicated logic OverviewThis is a focused cleanup PR with five distinct work items: consolidating What's Done Well
Config settings now actually wired through Issues and Suggestions1. // DataTypeResolver.cs:814
var type = id <= (uint)BuiltInType.ByteString ? (BuiltInType)id : BuiltInType.Variant;The old code used 2. set => _samplingInterval = Math.Max(0, Math.Min(10000, value));
3. // App/FocusManager.cs
- public void FocusPane(int index)
+ private void FocusPane(int index)The PR is right to make this private since it has no production callers, but 4. Test for // SubscriptionManagerIntegrationTests.cs:1358
Assert.Equal(1000, subscriptionManager.SamplingInterval);
Assert.Equal(25u, subscriptionManager.QueueSize);This only asserts the property values, not that the 5. The old 6. Removed The removed overload was the only way to pass a custom error callback. The remaining overload logs via the Nitpicks
SummaryThis is a high-quality, conservative cleanup. The behavioral improvements (SamplingInterval/QueueSize propagation, security settings) are bundled appropriately since they're tied to the dead-code removal. All removed code was provably unused, test coverage is maintained or improved, and the net simplification is real. The one area worth a second look before merging is the Verdict: Approve with minor suggestions — the codebase is cleaner and the 603-test suite gives confidence nothing regressed. |
- Consolidate duplicated SanitizeUrlForFilename (49 lines duplicated in CsvRecordingManager and ConfigurationService) into ConnectionIdentifier, reusing its existing protocol-stripping and length-limiting helpers - Replace SubscriptionManager's 17-branch data type if-chain and NodeBrowser's private type dictionary with a shared DataTypeResolver - Extract duplicated accent-button ColorScheme (6 dialogs) and flat menu/status bar ColorScheme (4 sites in MainWindow) into ThemeStyler factory methods; remove ThemeStyler's unused Create*/ApplyTo* helpers - Remove dead code with no production callers: - KeybindingContext.TrendPlot (no TrendPlotView exists) and mappings - SubscriptionManager.RemoveNodeByNodeIdAsync - FocusManager.FocusPrevious/GetPreviousIndex; FocusPane now private - RecentFilesManager.CleanupMissingFiles - UiThread.RunDelayed - TaskExtensions.FireAndForget(Action<Exception>) overload - Sync CLAUDE.md project structure with reality: remove nonexistent docs files, add missing views/dialogs/test files Net: -455 lines. All 603 tests pass. https://claude.ai/code/session_019zPGxdYgE9aVJ7Ai2uxV7y
…tions
SamplingIntervalMs and QueueSize were persisted, validated, and documented
in the config format but never applied - SubscriptionManager hardcoded
250ms/10. SecurityMode/SecurityPolicy were supported by ConnectAsync but
never passed from loaded configs.
- Add SamplingInterval (clamped 0-10000ms) and QueueSize (clamped 1-1000)
properties to SubscriptionManager, applied to new monitored items
- Plumb both through ConnectionManager.ConnectAsync alongside the
existing publishing interval
- Pass security mode/policy and subscription settings from loaded
configs in MainWindow's connect path
- Store connection settings in ConnectionManager fields so reconnect
no longer resets the publishing interval to the 250ms default
- Update stale config model doc comments ("reserved for future use"
and incorrect "not used by connection logic" warnings)
All 612 tests pass (9 new).
https://claude.ai/code/session_019zPGxdYgE9aVJ7Ai2uxV7y
b07efb3 to
0365164
Compare
Code ReviewOverviewThis PR is a clean sweep of dead code and duplicated logic: -455 net lines, all 603 tests passing. It tackles four independent concerns in one shot — URL sanitization consolidation, data type resolver extraction, accent/flat-bar ColorScheme factory methods in ThemeStyler, and dead-API removal. It also activates previously-stubbed QueueSize support throughout the config → ConnectionManager → SubscriptionManager pipeline. What works wellDataTypeResolver extraction (removing the 17-branch if-chain) is the right call. The new dictionary approach is cleaner and correctly covers types 16–25 (XmlElement…DiagnosticInfo) that the old SanitizeUrlForFilename consolidation is well-done. Delegating to the existing ThemeStyler factory methods (
Dead code removals are well-justified:
QueueSize activation is a bonus behavioral fix. The config model had the field for a long time with a "reserved for future use" comment; this finally wires it end-to-end. The new integration test Minor issuesDoc/code discrepancy — SamplingInterval range: Test placement anomaly: Old SummarySolid cleanup PR — well-scoped, methodical, and the tests back every change. The only things worth a follow-up are the SamplingInterval range discrepancy between the doc comment (10 000 ms) and the actual clamp (60 000 ms), and the test placement for the QueueSize clamping test.
|
…yer 1) (#165) * Upgrade Terminal.Gui 2.0.0 -> 2.4.5 (full UI-layer migration) The component-test APIs (Application.Create, InjectKey/InjectSequence, VirtualTimeProvider) first appear in Terminal.Gui 2.1.0, which also landed a breaking API redesign. This ports the whole UI layer to 2.4.5: - Namespace reorg: add GlobalUsings for Terminal.Gui.{App,ViewBase,Views, Drawing,Input,Drivers,Text,Configuration}; alias Attribute -> Drawing.Attribute. - ColorScheme -> Scheme; view.ColorScheme = x -> view.SetScheme(x); add a WithScheme() fluent helper for initializer-style scheme assignment. - Toplevel -> Window; RadioGroup -> OptionSelector (Labels/Value/ValueChanged). - TableView: SelectedRow -> Value?.SelectedCell.Y; SelectedCellChanged -> ValueChanged<TableSelection>; MouseClick -> MouseEvent(Mouse). - TreeView ObjectActivated -> Activated (read SelectedObject). - ListView OpenSelectedItem -> Accepting; drop TopItem (SelectedItem autoscrolls). - MenuItem shortcutKey: named arg -> positional Key. - Custom drawing: Driver!.X(...) -> view-level SetAttribute/AddRune/AddStr/Move in OnDrawingContent(DrawContext). - Application.Top -> TopRunnable/TopRunnableView; SizeChanging -> SubViewLayout; Colors.ColorSchemes["Menu"] -> SchemeManager.AddScheme; MessageBox.* now take Application.Instance; ShadowStyle.None -> ShadowStyles.None; Subviews -> SubViews; TextField.CursorPosition -> MoveEnd(). Known regression (flagged for review): Terminal.Gui 2.4 adornments have no independent Scheme, so per-border colouring (grey borders, focus-highlight title) now inherits the view scheme; focus highlight reapplied via FrameView scheme. Builds clean; all 613 existing tests pass; published --help smoke exits 0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Add layer-1 in-process TUI component tests Constructs the real Terminal.Gui views/dialogs and asserts on observable component behaviour: - MonitoredVariablesView: AddVariable/RemoveVariable, scope-selection bookkeeping, per-client-handle idempotency. - ConnectDialog: endpoint protocol-prefix handling, publishing interval, and the authentication selector (migrated RadioGroup -> OptionSelector). - Theme/Scheme: DarkTheme/LightTheme schemes and ThemeStyler.ApplyTo guard the ColorScheme -> Scheme migration. Tests run in a non-parallel xUnit collection because Terminal.Gui's Application is global state. Picked up automatically by `dotnet test` / CI. Rendered cell-buffer assertions are intentionally deferred to the black-box PTY suite: Terminal.Gui 2.4.5 stable exposes no public headless driver (Application.Create leaves Driver null; DriverAssert is develop-only). Documented in docs/TESTING.md. 627/627 tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Fix behavioral regressions found by migration review Adversarial review of the Terminal.Gui 2.0->2.4 migration confirmed three event-routing / API-semantics regressions (TG 2.4 moved selection/activation from overridden handlers into the command pipeline, which now runs AFTER the raw MouseEvent/Accepting events): - MonitoredVariablesView.HandleMouseClick: dropped `e.Handled = true` on Sel-column clicks. Marking it handled now pre-empts TableView's LeftButtonClicked -> Command.Activate -> SetSelection, so a Sel click toggled scope but no longer highlighted the row or raised SelectedVariableChanged. Unhandled restores both. - SaveRecordingDialog.OnFileListOpenSelected: set `e.Handled = true`. An unhandled Accepting bubbles Accept to the default Save button, so navigating a folder or picking a file would save+close the dialog mid-browse. - SaveRecordingDialog.NavigateToSelected: null-safe guard. ListView.SelectedItem is now int? (null = none); the OR-form guard didn't catch null and dereferenced null.Value (InvalidOperationException at a CSV-less filesystem root). - LogView: restore log auto-scroll via EnsureSelectedItemVisible() (TG 2.4 removed ListView.TopItem); without it the log stopped following new entries. 627/627 tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Migrate Terminal theme and tests added on main to Terminal.Gui 2.4.5 Rebasing onto main brought in the Terminal theme (#176) and its tests, which were written against Terminal.Gui 2.0: - TerminalTheme: ColorScheme -> Scheme; drop the local Attribute alias now provided by GlobalUsings. - ThemeManager: Application.Force16Colors no longer exists as a static; set the flag on Application.Driver only. - ThemeManagerTests: assert UseTerminalColors on the theme since the driver (which now owns Force16Colors) is null in headless tests. - ThemeSchemeTests: ThemeStyler.ApplyTo was dropped in favour of main's leaner surface (#177); test ApplyToFrame instead. * Address review feedback: null-safety, readability, and test coverage - ScopeDialog: replace GetScheme()! with an explicit fallback to the theme's main scheme, removing the NRE risk reviewers flagged. - ConnectDialog: normalize an empty password box to null so Password honours its nullable contract; downstream sends the same bytes. - Expand the collapsed single-line Scheme initializers in HelpDialog, WriteValueDialog and MonitoredVariablesView to the multi-line style used elsewhere. - AppTheme: mark the now-unapplied HighlightTitleBorderColorScheme with a TODO tied to the planned VisualRoles work. - AddressSpaceView: document why reading SelectedObject in Activated is race-free. - Tests: cover TerminalTheme in ThemeSchemeTests, add a WithScheme unit test, assert Password stays null without input, and dispose views in TUI tests to stop ThemeChanged handler leaks across the collection. - docs/TESTING.md: note the E2E project ships in the follow-up PR. * Address follow-up review: obsolete dead scheme, typed-password test, polish - AppTheme: mark HighlightTitleBorderColorScheme [Obsolete] so future callers can't silently rely on a scheme that is never applied. - ConnectDialogTests: cover the non-null path of the Password getter by typing into the dialog's Secret TextField. - MonitoredVariablesView: note that Mouse.Position is Point? in Terminal.Gui 2.4 so the null pattern isn't stripped as redundant. - NodeDetailsView: use WithScheme for the copy button like every other initializer in the migration. - ScopeView: drop a stray blank line left by the Driver-null-check removal. * Add TUI screenshots verifying the Terminal.Gui 2.4.5 migration Captured against the in-repo OPC UA test server (tmux + ANSI render): main window in all three themes, the migrated Connect dialog (OptionSelector), and the braille scope with four live signals. --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CsvRecordingManager and ConfigurationService) into ConnectionIdentifier,
reusing its existing protocol-stripping and length-limiting helpers
NodeBrowser's private type dictionary with a shared DataTypeResolver
menu/status bar ColorScheme (4 sites in MainWindow) into ThemeStyler
factory methods; remove ThemeStyler's unused Create*/ApplyTo* helpers
files, add missing views/dialogs/test files
Net: -455 lines. All 603 tests pass.
https://claude.ai/code/session_019zPGxdYgE9aVJ7Ai2uxV7y