Skip to content

Fixes #macOS-tests-failing. Deep-clone hard-coded config cache values at initialization to prevent mutation corruption#4847

Merged
tig merged 2 commits intov2_developfrom
copilot/fix-macos-tests-failing
Mar 23, 2026
Merged

Fixes #macOS-tests-failing. Deep-clone hard-coded config cache values at initialization to prevent mutation corruption#4847
tig merged 2 commits intov2_developfrom
copilot/fix-macos-tests-failing

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 23, 2026

ConfigurationManager._hardCodedConfigPropertyCache stored a shared reference to Application.DefaultKeyBindings (a Dictionary<Command, PlatformKeyBinding>). In-place mutations like Application.DefaultKeyBindings![Command.Quit] = Bind.All(Key.X.WithCtrl) silently corrupted the "hard-coded default" cache, since both pointed to the same object. On macOS, test ordering caused Load_And_Apply_HardCoded to run before any Disable(true)Apply() call that would have created a new dictionary and broken the shared reference — producing Actual: Ctrl+X where Expected: Esc.

Proposed Changes/Todos

  • In ConfigurationManager.Initialize(), deep-clone each PropertyValue immediately after UpdateToCurrentValue(), before marking the cache entry Immutable = true:
hardCodedProperty.Value.Immutable = false;
hardCodedProperty.Value.UpdateToCurrentValue ();
hardCodedProperty.Value.PropertyValue = DeepCloner.DeepClone (hardCodedProperty.Value.PropertyValue);
hardCodedProperty.Value.Immutable = true;

This ensures the cache stores independent copies of reference-type values so in-place mutations to static properties (e.g. Application.DefaultKeyBindings![cmd] = ...) cannot corrupt the hard-coded defaults regardless of test execution order.

Pull Request checklist:

  • I've named my PR in the form of "Fixes #issue. Terse description."
  • My code follows the style guidelines of Terminal.Gui - if you use Visual Studio, hit CTRL-K-D to automatically reformat your files before committing.
  • My code follows the Terminal.Gui library design guidelines
  • I ran dotnet test before commit
  • I have made corresponding changes to the API documentation (using /// style comments)
  • My changes generate no new warnings
  • I have checked my code and corrected any poor grammar or misspellings
  • I conducted basic QA to assure all features are working
Original prompt

This section details on the original issue you should resolve

<issue_title>macOS tests failing</issue_title>
<issue_description>This is likely due to some test incorrectly setting global keybindings state.

2026-03-23T14:14:33.4081250Z ##[group]Run dotnet test
2026-03-23T14:14:33.4081590Z �[36;1mdotnet test \�[0m
2026-03-23T14:14:33.4081850Z �[36;1m --project Tests/UnitTests.NonParallelizable \�[0m
2026-03-23T14:14:33.4082160Z �[36;1m --no-build \�[0m
2026-03-23T14:14:33.4082320Z �[36;1m --verbosity normal \�[0m
2026-03-23T14:14:33.4082640Z �[36;1m --diagnostic --diagnostic-output-directory logs/UnitTests.NonParallelizable/macOS�[0m
2026-03-23T14:14:33.4116490Z shell: /bin/bash --noprofile --norc -e -o pipefail {0}
2026-03-23T14:14:33.4116710Z env:
2026-03-23T14:14:33.4116910Z DisableRealDriverIO: 1
2026-03-23T14:14:33.4117130Z DOTNET_ROOT: /Users/runner/.dotnet
2026-03-23T14:14:33.4117300Z ##[endgroup]
2026-03-23T14:14:33.9793930Z Running tests from /Users/runner/work/Terminal.Gui/Terminal.Gui/Tests/UnitTests.NonParallelizable/bin/Debug/net10.0/UnitTests.NonParallelizable.dll (net10.0|arm64)
2026-03-23T14:14:34.5257770Z �[31mfailed�[m UnitTests.NonParallelizable.ConfigurationTests.ConfigurationMangerTests.Load_And_Apply_HardCoded �[90m(30ms)�[m
2026-03-23T14:14:34.5258920Z Assert.Equal() Failure: Values differ
2026-03-23T14:14:34.5261050Z Expected: Esc
2026-03-23T14:14:34.5261530Z Actual: Ctrl+X
2026-03-23T14:14:34.5262400Z from /Users/runner/work/Terminal.Gui/Terminal.Gui/Tests/UnitTests.NonParallelizable/bin/Debug/net10.0/UnitTests.NonParallelizable.dll (net10.0|arm64)
2026-03-23T14:14:34.5263250Z �[31m Assert.Equal() Failure: Values differ
2026-03-23T14:14:34.5263530Z Expected: Esc
2026-03-23T14:14:34.5263730Z Actual: Ctrl+X
2026-03-23T14:14:34.5264890Z �[m�[90m at UnitTests.NonParallelizable.ConfigurationTests.ConfigurationMangerTests.Load_And_Apply_HardCoded() in /Users/runner/work/Terminal.Gui/Terminal.Gui/Tests/UnitTests.NonParallelizable/Configuration/ConfigurationMangerTests.cs:951�[90m
2026-03-23T14:14:34.5265950Z at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
2026-03-23T14:14:34.5266580Z at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
2026-03-23T14:14:34.5407920Z �[m�[31mfailed�[m UnitTests.NonParallelizable.ConfigurationTests.ConfigurationMangerTests.ResetToHardCodedDefaults_and_Load_LibraryResourcesOnly_are_same �[90m(17ms)�[m
2026-03-23T14:14:34.5408690Z Assert.Equal() Failure: Values differ
2026-03-23T14:14:34.</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

… prevent mutation corruption

When ConfigurationManager.Initialize() builds _hardCodedConfigPropertyCache, it calls
UpdateToCurrentValue() which stored the SAME reference to mutable objects like
Application.DefaultKeyBindings (a Dictionary). In-place mutations to that dictionary
(e.g., Application.DefaultKeyBindings![Command.Quit] = ...) then silently corrupted
the cached "hard-coded default".

On macOS, test ordering caused Load_And_Apply_HardCoded to run before any Disable(true)
call that would break the shared reference, making the cache contain Ctrl+X instead of
Esc, failing the assertion.

Fix: deep-clone each PropertyValue immediately after UpdateToCurrentValue() in Initialize(),
ensuring the cache stores independent copies of reference-type values.

Co-authored-by: tig <585482+tig@users.noreply.github.com>
Agent-Logs-Url: https://github.com/gui-cs/Terminal.Gui/sessions/a68bc920-92d0-4813-8c67-03a18439a0ea
Copilot AI changed the title [WIP] Fix macOS tests failing due to incorrect global keybindings Fixes #macOS-tests-failing. Deep-clone hard-coded config cache values at initialization to prevent mutation corruption Mar 23, 2026
Copilot AI requested a review from tig March 23, 2026 14:40
Copilot finished work on behalf of tig March 23, 2026 14:40
@tig tig marked this pull request as ready for review March 23, 2026 16:42
@tig tig merged commit 7caa276 into v2_develop Mar 23, 2026
11 checks passed
@tig tig deleted the copilot/fix-macos-tests-failing branch March 23, 2026 16:42
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.

macOS tests failing

2 participants