Skip to content

Commit

Permalink
fix(InputArgumentValidator): only validate ProjectFolder type of JobP…
Browse files Browse the repository at this point in the history
…athArgument
  • Loading branch information
MingboPeng committed May 11, 2023
1 parent 0a2cfb5 commit bbf258c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
19 changes: 10 additions & 9 deletions src/PollinationSDK.Tests/Api/JobsApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,21 @@ private JobInfo CreateTestJobInfo()
}

[Test]
public void CreateJobFromJobInfoTest()
public void TestPathArg()
{
//var jsonFile = @"D:\Dev\Pollination\rhino-plugin\src\bin\jobInfo.json";
//var json = System.IO.File.ReadAllText(jsonFile);
//var job = PollinationSDK.Wrapper.JobInfo.FromJson(json);

//job.CheckArgumentsWithHandlers("rhino", "csharp");

//var dir = @"C:\Users\mingo\simulation\ttt";
//job.SetLocalJob(dir, 2);
var jobInfo = CreateTestJobInfo();
var model = Path.GetFullPath(@"../../../TestSample/two_rooms.hbjson");
var pathArg = jobInfo.Job.Arguments.First().FirstOrDefault().Obj as JobPathArgument;
Assert.AreEqual(((pathArg.Source.Obj) as ProjectFolder).Path, model);
}

[Test]
public void CreateJobFromJobInfoTest()
{
// create JobInfo
var jobInfo = CreateTestJobInfo();
var dup = jobInfo.Duplicate();

Assert.AreEqual(jobInfo.Job.Source, dup.Job.Source);
Assert.AreEqual(jobInfo.Job.Arguments.Count, dup.Job.Arguments.Count);
Assert.AreEqual(jobInfo.Recipe.Source, dup.Recipe.Source);
Expand Down
4 changes: 3 additions & 1 deletion src/PollinationSDK/Wrapper/InputArgumentValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public static object CheckAndValidate(PollinationSDK.Interface.Io.Inputs.IDag da
public object CheckAndValidate(object value, HandlerChecker handlerChecker)
{
if (value == null) return null;

if (this.DagInputAlias == null) return null;

// validate Alias input
if (!this.ValidateWithAliasSpec(value)) return null;

// convert with handlers
var obj = this.CheckInputWithHandler(value, handlerChecker);
// validate input specs
Expand Down
13 changes: 11 additions & 2 deletions src/PollinationSDK/Wrapper/JobInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ public JobInfo Duplicate()
if (isPath)
{
var pathArg = args.OfType<JobPathArgument>().FirstOrDefault(_ => _.Name == item.Name);
currentArg = pathArg;
currentValue = pathArg?.Source;

// only validate if a path is ProjectFolder type, there is no way to validate HTTPS or S3 link
if (pathArg?.Source?.Obj is ProjectFolder pf)
{
currentArg = pathArg;
currentValue = pf.Path;
}
}
else
{
Expand All @@ -124,6 +129,10 @@ public JobInfo Duplicate()
currentValue = valueArg?.Value;
}

if (currentArg == null)
continue;


var processedData = InputArgumentValidator.CheckAndValidate(item, platform, currentValue, handlerChecker);
if (processedData == null)
{
Expand Down

0 comments on commit bbf258c

Please sign in to comment.