-
-
Notifications
You must be signed in to change notification settings - Fork 43
feat: add ErrorCode and RecommendedNextAction to pause point failure responses #2048
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
3 commits
Select commit
Hold shift + click to select a range
95cd6c2
feat: add ErrorCode and RecommendedNextAction to pause point failure …
hatayama 069ec01
docs: document pause point failure error codes and Debug-mode loss on…
hatayama f41b81a
test: serialize ErrorCode wire-name pin through production JSON settings
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
174 changes: 174 additions & 0 deletions
174
Assets/Tests/Editor/PausePointEnableFailureErrorCodeTests.cs
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,174 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| using Newtonsoft.Json; | ||
| using Newtonsoft.Json.Linq; | ||
| using NUnit.Framework; | ||
|
|
||
| using io.github.hatayama.UnityCliLoop.FirstPartyTools; | ||
| using io.github.hatayama.UnityCliLoop.Runtime; | ||
| using io.github.hatayama.UnityCliLoop.ToolContracts; | ||
|
|
||
| namespace io.github.hatayama.UnityCliLoop.Tests.Editor | ||
| { | ||
| /// <summary> | ||
| /// Verifies validation-failure responses carry machine-readable ErrorCode and RecommendedNextAction. | ||
| /// </summary> | ||
| [TestFixture] | ||
| public sealed class PausePointEnableFailureErrorCodeTests | ||
| { | ||
| private FakePausePointPauseController _pauseController; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| _pauseController = new FakePausePointPauseController(); | ||
| UloopPausePointRegistry.ConfigureForTests(_pauseController, () => DateTime.UtcNow); | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() | ||
| { | ||
| UloopPausePointRegistry.ResetForTests(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies a non-positive timeout returns INVALID_ARGUMENT with a non-empty next action. | ||
| /// </summary> | ||
| [Test] | ||
| public async Task Enable_WhenTimeoutSecondsIsZero_ReturnsInvalidArgumentErrorCode() | ||
| { | ||
| EnablePausePointTool tool = new(); | ||
| JObject parameters = new() | ||
| { | ||
| ["id"] = "jump", | ||
| ["timeoutSeconds"] = 0 | ||
| }; | ||
|
|
||
| PausePointResponse response = (PausePointResponse)await tool.ExecuteAsync(parameters, CancellationToken.None); | ||
|
|
||
| Assert.That(response.Success, Is.False); | ||
| Assert.That(response.ErrorCode, Is.EqualTo(SourcePausePointConstants.ErrorCodeInvalidArgument)); | ||
| Assert.That(response.RecommendedNextAction, Is.Not.Empty); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies specifying both id and file:line returns INVALID_ARGUMENT with a non-empty next action. | ||
| /// </summary> | ||
| [Test] | ||
| public async Task Enable_WhenIdAndFileLineAreBothSpecified_ReturnsInvalidArgumentErrorCode() | ||
| { | ||
| EnablePausePointTool tool = new(); | ||
| JObject parameters = new() | ||
| { | ||
| ["id"] = "jump", | ||
| ["file"] = "Assets/Tests/Editor/PausePointToolModeTests.cs", | ||
| ["line"] = 10, | ||
| ["timeoutSeconds"] = 30 | ||
| }; | ||
|
|
||
| PausePointResponse response = (PausePointResponse)await tool.ExecuteAsync(parameters, CancellationToken.None); | ||
|
|
||
| Assert.That(response.Success, Is.False); | ||
| Assert.That(response.ErrorCode, Is.EqualTo(SourcePausePointConstants.ErrorCodeInvalidArgument)); | ||
| Assert.That(response.RecommendedNextAction, Is.Not.Empty); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies an unknown capture mode returns INVALID_ARGUMENT with a non-empty next action. | ||
| /// </summary> | ||
| [Test] | ||
| public async Task Enable_WhenModeIsUnknown_ReturnsInvalidArgumentErrorCode() | ||
| { | ||
| EnablePausePointTool tool = new(); | ||
| JObject parameters = new() | ||
| { | ||
| ["id"] = "jump", | ||
| ["mode"] = "bogus-mode", | ||
| ["timeoutSeconds"] = 30 | ||
| }; | ||
|
|
||
| PausePointResponse response = (PausePointResponse)await tool.ExecuteAsync(parameters, CancellationToken.None); | ||
|
|
||
| Assert.That(response.Success, Is.False); | ||
| Assert.That(response.ErrorCode, Is.EqualTo(SourcePausePointConstants.ErrorCodeInvalidArgument)); | ||
| Assert.That(response.RecommendedNextAction, Is.Not.Empty); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies clear without id or --all returns INVALID_ARGUMENT with a non-empty next action. | ||
| /// </summary> | ||
| [Test] | ||
| public async Task Clear_WhenIdIsEmptyAndAllIsFalse_ReturnsInvalidArgumentErrorCode() | ||
| { | ||
| ClearPausePointTool tool = new(); | ||
| JObject parameters = new() | ||
| { | ||
| ["id"] = "", | ||
| ["all"] = false | ||
| }; | ||
|
|
||
| PausePointResponse response = (PausePointResponse)await tool.ExecuteAsync(parameters, CancellationToken.None); | ||
|
|
||
| Assert.That(response.Success, Is.False); | ||
| Assert.That(response.ErrorCode, Is.EqualTo(SourcePausePointConstants.ErrorCodeInvalidArgument)); | ||
| Assert.That(response.RecommendedNextAction, Is.Not.Empty); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies an unresolvable file:line returns PAUSE_POINT_RESOLVE_FAILED with a non-empty next action. | ||
| /// </summary> | ||
| [Test] | ||
| public async Task Enable_WhenFileDoesNotExist_ReturnsResolveFailedErrorCode() | ||
| { | ||
| EnablePausePointTool tool = new(); | ||
| JObject parameters = new() | ||
| { | ||
| ["file"] = "Assets/DoesNotExist/NoSuchScript.cs", | ||
| ["line"] = 10, | ||
| ["timeoutSeconds"] = 30 | ||
| }; | ||
|
|
||
| PausePointResponse response = (PausePointResponse)await tool.ExecuteAsync(parameters, CancellationToken.None); | ||
|
|
||
| Assert.That(response.Success, Is.False); | ||
| Assert.That(response.ErrorCode, Is.EqualTo(SourcePausePointConstants.ErrorCodeResolveFailed)); | ||
| Assert.That(response.RecommendedNextAction, Is.Not.Empty); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies ErrorCode serializes under the exact wire name callers will match. | ||
| /// </summary> | ||
| [Test] | ||
| public void PausePointResponse_WhenErrorCodeIsSet_SerializesErrorCodeWireName() | ||
| { | ||
| // Why production settings: JsonRpcResponseFactory uses these settings; a bare | ||
| // SerializeObject would miss ContractResolver renames and give false confidence. | ||
| string json = JsonConvert.SerializeObject( | ||
| new PausePointResponse { Success = false, ErrorCode = "X" }, | ||
| Formatting.None, | ||
| UnityCliLoopJsonResponseSerializerSettings.Settings); | ||
|
|
||
| Assert.That(json, Does.Contain("\"ErrorCode\":\"X\"")); | ||
| } | ||
|
|
||
| private sealed class FakePausePointPauseController : IUloopPausePointPauseController | ||
| { | ||
| public int PauseCount { get; private set; } | ||
| public bool IsPlaying => true; | ||
| public bool IsPaused => PauseCount > 0; | ||
|
|
||
| public void Pause() | ||
| { | ||
| PauseCount++; | ||
| } | ||
|
|
||
| public void Resume() | ||
| { | ||
| // Why zero: Unity's isPaused is a bool; Option B Resume must fully clear pause. | ||
| PauseCount = 0; | ||
| } | ||
| } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
Assets/Tests/Editor/PausePointEnableFailureErrorCodeTests.cs.meta
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.