Skip to content

Commit

Permalink
Enhacements related to test and deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
rrg92 committed Sep 17, 2024
1 parent 9ae69f5 commit cbd580f
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 2 deletions.
104 changes: 104 additions & 0 deletions util/TestPowershai.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
param(
[switch]$Basic
,$TestModels = $ENV:POWERSHAI_TEST_MODELS # provider/modelname,provider/modelname
,[switch]$Verbose
)

#
# Do Basic tests.
# TODO: Use Pester
#

$ErrorActionPreference = "Stop";

write-host "Starting PowershAI test script...";

try {
. (Join-Path "$PsScriptRoot" UtilLib.ps1)
CheckPowershaiRoot

import-module ./powershai -force;

$m = Get-module powershai;

if(!$m){
throw "MODULE_NOT_IMPORTED: $m";
}

$TestModelList = $TestModels -split ",";
write-host " Models to test: $($TestModelList.count)";

$ChatNum = 1;
foreach($TestExpr in $TestModelList){
$ChatNum++;
$Parts = $TestExpr -split "/",2
$Provider = $Parts[0];
$Model = $Parts[1];

try {
write-host "Testing provider: $provider";
Set-AiProvider $provider;

write-host "Testing model: $model";
Set-AiDefaultModel $model;

write-host "Test: Simple temporary default chat";
iat "Hi, this is a test from powershell ai module called Powershai";

1..5 | iat "write names of that numbers"

ia "gere 5 palavras em pt-BR"
ia -Lines "traduza os nomes para o inglês" | %{ "English: $_" }

# chat creation test!
write-host "Test: Creating new chat"
$Chat = New-PowershaiChat "Test-$ChatNum";

$SecretGuid = [Guid]::NewGuid().Guid;
write-host "Test: New chat sending data! SecretGuid: $SecretGuid"
ia (@(
"This is a secret data: $SecretGuid"
"I will ask about it later"
) -Join "`n")

write-host "Test: Getting data from current chat history"
$ReturnedSecret = @(ia -Lines "What is secret data? Return just secret data in first line");
if($ReturnedSecret){
$ReturnedSecret = @($ReturnedSecret)[0].trim();
}

write-host " SecretGuidReturned: ~$ReturnedSecret~"

if($ReturnedSecret -ne $SecretGuid){
throw "HISTORYTEST_POSITIVE_FAIL"
}

write-host " HISTORY TEST PASSED"

$ReturnedSecret2 = @(ia -Lines "What is secret data? If you dont know about scret, just answer that text: DONT_KNOW");

if($ReturnedSecret2){
$ReturnedSecret2 = $ReturnedSecret2 -Join "`n"
}

if($ReturnedSecret2 -like "*$SecretGuid*" -or $ReturnedSecret2 -NotLike "*DONT_KNOW*"){
throw "HISTORYTEST_NEGATIVE_FAIL"
}

write-host " TEMPORARY TEST PASSED";



} catch {
write-host "failed: $_";
}
}

} catch {
write-host "TEST-FAIL: $_"
write-host $_.Exception.ScriptStackTrace;
throw;
}



12 changes: 12 additions & 0 deletions util/publish-prepare.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# To run in GithubActions, to prepare environment to publish!
#
param()

if(-not(Get-Module -ListAvailable platyPS)){
write-host "Instaling PLatyPs module";
$m = Install-Module platyPS -force -PassThru
write-host " Installed: $($m.name) $($m.Version)"
}

& ./util/publish.ps1 @Args
26 changes: 24 additions & 2 deletions util/publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
param(
$ApiKey = $Env:PSGALERY_KEY
,[switch]$CompileDoc
,[switch]$Simulate
,[switch]$BasicTest
,[switch]$Publish
)

$ErrorActionPreference = "Stop";
. (Join-Path "$PsScriptRoot" UtilLib.ps1)
CheckPowershaiRoot

if(!$Global:POWERSHAI_PUBLISH_DATA){
$Global:POWERSHAI_PUBLISH_DATA = @{}
Expand All @@ -30,7 +35,7 @@ if($CompileDoc){
& $DocsScript $PlatyDir -SupportedLangs * -MaxAboutWidth 150
}

$ModuleRoot = Join-Path "$PsScriptRoot" powershai
$ModuleRoot = Resolve-Path powershai


# Current version!
Expand All @@ -45,6 +50,23 @@ if($TaggedVersion -ne $Mod.Version){
throw "POWERSHAI_PUBLISH_INCORRECT_VERSION: Module = $($Mod.Version) Git = $TaggedVersion";
}

if($BasicTest){
write-host "Starting tests..."
./util/TestPowershai.ps1 -Basic;
write-host " Test run!";
}

$PublishParams = @{
Path = $ModuleRoot
NuGetApiKey = $ApiKey
Force = $true
Verbose = $true;
}

if($Simulate){
$PublishParams.WhatIf = $true;
}

Publish-Module -Path $ModuleRoot -NuGetApiKey $ApiKey -Force -Verbose
if($Publish){
Publish-Module -Path $ModuleRoot -NuGetApiKey $ApiKey -Force -Verbose
}

0 comments on commit cbd580f

Please sign in to comment.