fix: recognize boolean and varied integer formats for guest exec exited status (#160)

* fix: recognize boolean and varied integer formats for guest exec exited status

The guest-agent schema declares 'exited' as a boolean, but the PVE API
may return it in different formats: as a JSON boolean true, or as integers
1/0, or string '1'/'0'. The cmdlet was only checking for long 1L, causing
it to timeout on any PVE build that passed a boolean true unchanged.

Add ApiValueHelper.IsExited() to normalize these values and recognize
true, 1L, 1, and '1' as exited. Update the polling loop to use it.

* test: add integration tests for ApiValueHelper with real JSON payloads

Add tests that feed JSON data through the actual JsonHelper.ToNative
parsing pipeline to verify ApiValueHelper.IsExited correctly recognizes
boolean true and numeric 1 values as they arrive from the PVE API.
These tests pin the contract between the JSON parsing layer and the
value-recognition logic, ensuring the fix for issue #141 works end-to-end
with real API response shapes.

* fix: restore correct IsExited implementation with type checks

The helper must handle boolean true, long/int 1, and string "1" as the
issue specifies. This restores the correct multi-type check that was
inadvertently reverted.

* fix: correct boolean value handling in IsExited

---------

Co-authored-by: goodolclint-claude[bot] <323206664+goodolclint-claude[bot]@users.noreply.github.com>
This commit is contained in:
goodolclint-claude[bot]
2026-09-02 17:32:09 +00:00
committed by GitHub
parent def8dc6b67
commit 8255e506a6
3 changed files with 92 additions and 1 deletions
@@ -0,0 +1,52 @@
using Newtonsoft.Json.Linq;
using PSProxmoxVE.Core.Utilities;
using Xunit;
namespace PSProxmoxVE.Core.Tests.Utilities
{
public class ApiValueHelperTests
{
[Theory]
[InlineData(true)]
[InlineData(1L)]
[InlineData(1)]
[InlineData("1")]
public void IsExited_TrueValues_ReturnsTrue(object value)
{
Assert.True(ApiValueHelper.IsExited(value));
}
[Theory]
[InlineData(false)]
[InlineData(0L)]
[InlineData(0)]
[InlineData("0")]
[InlineData(null)]
[InlineData("")]
[InlineData("true")]
[InlineData(2L)]
[InlineData(42)]
public void IsExited_FalseValues_ReturnsFalse(object? value)
{
Assert.False(ApiValueHelper.IsExited(value));
}
[Theory]
[InlineData("{\"data\":{\"exited\":true}}", true)]
[InlineData("{\"data\":{\"exited\":false}}", false)]
[InlineData("{\"data\":{\"exited\":1}}", true)]
[InlineData("{\"data\":{\"exited\":0}}", false)]
[InlineData("{\"data\":{\"exited\":\"1\"}}", true)]
[InlineData("{\"data\":{\"exited\":\"0\"}}", false)]
[InlineData("{\"data\":{\"exited\":null}}", false)]
[InlineData("{\"data\":{}}", false)]
public void IsExited_ApiJsonValues_ReturnExpectedCompletionState(string json, bool expected)
{
var data = (JObject)JObject.Parse(json)["data"]!;
var status = JsonHelper.ToDictionary(data);
var completed = status.TryGetValue("exited", out var exited) && ApiValueHelper.IsExited(exited);
Assert.Equal(expected, completed);
}
}
}