Repository navigation
Ignore unknown dismissed message names when loading application state #20865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,9 +13,6 @@ using namespace winrt::Microsoft::Terminal::Settings::Model; | |
|
|
||
| namespace SettingsModelUnitTests | ||
| { | ||
| // Covers the workspace-persistence APIs added to ApplicationState: | ||
| // SaveWorkspace / RemoveWorkspace / RenameWorkspace / TakeWorkspace / | ||
| // AllPersistedWorkspaces. | ||
| // All tests operate on a throw-away ApplicationState instance pointed at | ||
| // a temp directory, so they don't touch the real user state. | ||
| class ApplicationStateTests | ||
|
|
@@ -29,6 +26,7 @@ namespace SettingsModelUnitTests | |
| TEST_METHOD(RenameWorkspaceNoOpForMissingEntry); | ||
| TEST_METHOD(TakeWorkspaceRemovesAndReturns); | ||
| TEST_METHOD(TakeWorkspaceReturnsNullWhenMissing); | ||
| TEST_METHOD(IgnoreUnknownDismissedMessages); | ||
|
|
||
| private: | ||
| static std::filesystem::path _tempRoot() | ||
|
|
@@ -56,6 +54,47 @@ namespace SettingsModelUnitTests | |
| } | ||
| }; | ||
|
|
||
| void ApplicationStateTests::IgnoreUnknownDismissedMessages() | ||
| { | ||
| Log::Comment(L"GH #16874 - Unknown dismissed message names must not terminate state loading"); | ||
|
|
||
| Json::Value json{ Json::objectValue }; | ||
| json["settingsHash"] = "test-hash"; | ||
| json["dismissedMessages"] = Json::Value{ Json::arrayValue }; | ||
| for (const auto name : { "futureMessage", "closeOnExitInfo", "removedMessage", "keyboardServiceWarning", "setAsDefault", "" }) | ||
| { | ||
| json["dismissedMessages"].append(name); | ||
| } | ||
| json["allowedCommandlines"] = Json::Value{ Json::arrayValue }; | ||
| json["allowedCommandlines"].append("test-command"); | ||
|
|
||
| auto state = _make(); | ||
| state->FromJson(json, implementation::FileSource::Shared | implementation::FileSource::Local); | ||
|
|
||
| const auto messages = state->DismissedMessages(); | ||
| VERIFY_IS_NOT_NULL(messages); | ||
| VERIFY_ARE_EQUAL(6u, messages.Size()); | ||
| VERIFY_ARE_EQUAL(InfoBarMessage::IgnoredDeprecatedEntry, messages.GetAt(0)); | ||
| VERIFY_ARE_EQUAL(InfoBarMessage::CloseOnExitInfo, messages.GetAt(1)); | ||
| for (uint32_t i = 2; i < messages.Size(); ++i) | ||
| { | ||
| VERIFY_ARE_EQUAL(InfoBarMessage::IgnoredDeprecatedEntry, messages.GetAt(i)); | ||
| } | ||
|
|
||
| // Invalid names must not prevent fields before or after this one from loading. | ||
| VERIFY_ARE_EQUAL(L"test-hash", state->SettingsHash()); | ||
| VERIFY_ARE_EQUAL(1u, state->AllowedCommandlines().Size()); | ||
| VERIFY_ARE_EQUAL(L"test-command", state->AllowedCommandlines().GetAt(0)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you shrink the tests to just spot check the core issue to protect against future regressions? (You got to really reign in your LLM when it comes to tests - they always tend to write overly defensive / broad tests. 😅)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha, yeah 😅 I'll fix the tests and keep them focused on the bug. Thanks! |
||
|
|
||
| const auto serialized = state->ToJson(implementation::FileSource::Shared); | ||
| VERIFY_ARE_EQUAL(6u, serialized["dismissedMessages"].size()); | ||
| VERIFY_ARE_EQUAL("closeOnExitInfo", serialized["dismissedMessages"][1].asString()); | ||
| for (const auto i : { 0, 2, 3, 4, 5 }) | ||
| { | ||
| VERIFY_ARE_EQUAL("deprecated", serialized["dismissedMessages"][i].asString()); | ||
| } | ||
| } | ||
|
|
||
| void ApplicationStateTests::SaveAndLookupWorkspace() | ||
| { | ||
| auto state = _make(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the deserializer. What about
ToJson? We should be able to prevent serializingIgnoredDeprecatedEntryaltogether.