Repository navigation
feat: Watch expressions now survive domain reloads #2679
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f2c2b7c
feat: restore watch expressions after a domain reload
hatayama 460e806
fix: keep watch restore from contradicting the user and from stopping…
hatayama 015e954
test: cover cancellation that lands after a watch record compiled
hatayama eeb355b
fix: keep a watch whose compile threw in the persisted store
hatayama b670d63
fix: configure the watch restore awaits and return to the main thread
hatayama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| using NUnit.Framework; | ||
|
|
||
| using UnityEditor; | ||
|
|
||
| using io.github.hatayama.UnityCliLoop.FirstPartyTools; | ||
|
|
||
| namespace io.github.hatayama.UnityCliLoop.Tests.Editor | ||
| { | ||
| /// <summary> | ||
| /// Verifies watch expressions round-trip through SessionState and that unusable stored | ||
| /// content degrades to "no watches to restore" instead of failing Editor startup. | ||
| /// </summary> | ||
| [TestFixture] | ||
| public sealed class WatchSessionStateStoreTests | ||
| { | ||
| private const string RecordsKey = "io.github.hatayama.uloopmcp.watch.persistedRecords"; | ||
|
|
||
| private string _originalValue; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| _originalValue = SessionState.GetString(RecordsKey, string.Empty); | ||
| SessionState.EraseString(RecordsKey); | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() | ||
| { | ||
| SessionState.SetString(RecordsKey, _originalValue); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// What: expressions containing newlines, quotes, and non-ASCII survive the round trip byte for byte. | ||
| /// </summary> | ||
| [Test] | ||
| public void SaveThenLoad_WithAwkwardExpressionText_RoundTripsEveryField() | ||
| { | ||
| const string awkwardExpression = "\"quoted\" + \n\t'x' + \"\\u00e9\\u3042\""; | ||
| WatchSessionStateStore store = new(); | ||
|
|
||
| store.Save(new List<WatchPersistedRecord> | ||
| { | ||
| new() { Id = "first", Expression = awkwardExpression, MaxHistory = 7 }, | ||
| new() { Id = "second", Expression = "1 + 2", MaxHistory = 20 } | ||
| }); | ||
| IReadOnlyList<WatchPersistedRecord> loaded = store.Load(); | ||
|
|
||
| Assert.That(loaded, Has.Count.EqualTo(2)); | ||
| Assert.That(loaded[0].Id, Is.EqualTo("first")); | ||
| Assert.That(loaded[0].Expression, Is.EqualTo(awkwardExpression)); | ||
| Assert.That(loaded[0].MaxHistory, Is.EqualTo(7)); | ||
| Assert.That(loaded[1].Id, Is.EqualTo("second")); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// What: saving an empty list clears the store rather than leaving the previous records behind. | ||
| /// </summary> | ||
| [Test] | ||
| public void Save_WithEmptyList_LeavesNothingToRestore() | ||
| { | ||
| WatchSessionStateStore store = new(); | ||
| store.Save(new List<WatchPersistedRecord> | ||
| { | ||
| new() { Id = "first", Expression = "1 + 2", MaxHistory = 20 } | ||
| }); | ||
|
|
||
| store.Save(Array.Empty<WatchPersistedRecord>()); | ||
|
|
||
| Assert.That(store.Load(), Is.Empty); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// What: a record without an expression cannot be recompiled, so saving it is rejected. | ||
| /// </summary> | ||
| [Test] | ||
| public void Save_WithNullExpression_ThrowsBecauseTheRecordCouldNeverBeRestored() | ||
| { | ||
| WatchSessionStateStore store = new(); | ||
|
|
||
| Assert.That( | ||
| () => store.Save(new List<WatchPersistedRecord> | ||
| { | ||
| new() { Id = "first", Expression = null, MaxHistory = 20 } | ||
| }), | ||
| Throws.ArgumentException); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// What: an unset key means no watches were persisted, not an error. | ||
| /// </summary> | ||
| [Test] | ||
| public void Load_WhenKeyWasNeverWritten_ReturnsEmpty() | ||
| { | ||
| WatchSessionStateStore store = new(); | ||
|
|
||
| Assert.That(store.Load(), Is.Empty); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// What: content written by another uloop generation degrades to empty instead of throwing. | ||
| /// </summary> | ||
| [Test] | ||
| public void Load_WhenStoredJsonIsNotAWatchRecordList_ReturnsEmpty() | ||
| { | ||
| SessionState.SetString(RecordsKey, "{ this is not json"); | ||
| WatchSessionStateStore store = new(); | ||
|
|
||
| Assert.That(store.Load(), Is.Empty); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.