Skip to content

Commit

Permalink
Fix validations for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
rrg92 committed Dec 12, 2024
1 parent 961edb7 commit 1334f68
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
24 changes: 21 additions & 3 deletions powershai/lib/util.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,15 @@ function Confirm-PowershaiObjectSchema {
$IsTypeValid = $true;
} else {
$ExpectedType = $KeySchema.type;
$IsTypeValid = $KeyValue -is $ExpectedType;
$ExpectedTypes = @($ExpectedType)

if($ExpectedType -eq [int]){
$ExpectedTypes += [int64];
}

[bool]$IsTypeValid = @( $ExpectedTypes | ?{ $KeyValue -is $_ }).count



if(!$IsTypeValid){

Expand All @@ -620,7 +628,7 @@ function Confirm-PowershaiObjectSchema {

$errors += @(
"InvalidType:$CurrenType"
"Expected:"+$ExpectedType.name
"Expected:"+(@($ExpectedType|%{$_.name}) -Join ",")
) -Join ","
}

Expand Down Expand Up @@ -711,6 +719,8 @@ function Enter-PowershaiRetry {
}
}

$CheckDetails = @{}

$MustRetry = $true;
$CurrentTry = 0;
while($CurrentTry -lt $Retries){
Expand Down Expand Up @@ -743,6 +753,8 @@ function Enter-PowershaiRetry {
$CheckScriptResult = $CheckScript.InvokeWithContext( $null, [psvariable]::new('_', $result)) | %{$_};
verbose "CheckScriptResult: $CheckScriptResult";

$CheckDetails.CheckScriptResult = $CheckScriptResult;

if($CheckScriptResult -is [bool]){
verbose "Result is bool!";
return $CheckScriptResult;
Expand All @@ -767,6 +779,7 @@ function Enter-PowershaiRetry {

$SchemaValidation = Confirm-PowershaiObjectSchema $ResultObject $CheckScriptResult

$CheckDetails.SchemaValidation = $SchemaValidation;
return $SchemaValidation.valid;
}

Expand All @@ -782,7 +795,12 @@ function Enter-PowershaiRetry {
}
}

throw "POWERSHAI_RETRY_MAXREACHED";

$error = New-PowershaiError POWERSHAI_RETRY_MAXREACHED -Props @{
details = $CheckDetails
}

throw $error;
}


Expand Down
4 changes: 4 additions & 0 deletions tests/pester/001-core/005-cmdlets.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Describe "Get-AiChat" -Tags "get-aichat" {
return $CustomMessaege
}

Mock -module powershai Get-AiModel {
return @{ tools = $false }
}

}


Expand Down

0 comments on commit 1334f68

Please sign in to comment.