Skip to content

Commit 55436f0

Browse files
committed
Add test, use new feature flag
1 parent 9fa9097 commit 55436f0

File tree

5 files changed

+68
-21
lines changed

5 files changed

+68
-21
lines changed

src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public WorkspaceModel CurrentSpace
211211
/// <summary>
212212
/// Controls if the the ML data ingestion pipeline is beta from feature flag
213213
/// </summary>
214+
[Obsolete("This flag is not needed anymore and will be removed in a future version of Dynamo. Use EnableDNADataIngestionPipeline instead")]
214215
internal bool IsDNADataIngestionPipelineinBeta
215216
{
216217
get
@@ -219,6 +220,17 @@ internal bool IsDNADataIngestionPipelineinBeta
219220
}
220221
}
221222

223+
/// <summary>
224+
/// Controls if the the ML data ingestion pipeline is enabled or not.
225+
/// </summary>
226+
internal bool EnableDNADataIngestionPipeline
227+
{
228+
get
229+
{
230+
return DynamoModel.FeatureFlags?.CheckFeatureFlag("EnableDNADataIngestionPipeline", false) ?? false;
231+
}
232+
}
233+
222234
/// <summary>
223235
/// Controls if the cluster node autocomplete placement feature is enabled from feature flag
224236
/// </summary>
@@ -3332,26 +3344,31 @@ private void CloseHomeWorkspace(object parameter)
33323344
// Upon closing a workspace, validate if the workspace is valid to be sent to the ML datapipeline and then send it.
33333345
if (!DynamoModel.IsTestMode && !HomeSpace.HasUnsavedChanges && (currentWorkspaceViewModel?.IsHomeSpace ?? true) && HomeSpace.HasRunWithoutCrash)
33343346
{
3335-
// Currently IsDNADataIngestionPipelineinBeta is set to true for debug builds and false for release builds. so we need to modify it here, when testing the pipeline in debug builds.
3336-
if (!IsDNADataIngestionPipelineinBeta && Model.CurrentWorkspace.IsValidForFDX && currentWorkspaceViewModel.Checksum != string.Empty)
3347+
if (preferencesViewModel.IsMLAutocompleteTOUApproved)
33373348
{
3338-
if (HasDifferentialCheckSum())
3349+
// Currently IsDNADataIngestionPipelineinBeta is set to true for debug builds and false for release builds. so we need to modify it here, when testing the pipeline in debug builds.
3350+
if (EnableDNADataIngestionPipeline && Model.CurrentWorkspace.IsValidForFDX && currentWorkspaceViewModel.Checksum != string.Empty)
33393351
{
3340-
Model.Logger.Log("This Workspace is being shared to train the Dynamo Machine Learning model.", LogLevel.File);
3341-
var workspacePath = model.CurrentWorkspace.FileName;
3342-
3343-
Task.Run(() =>
3352+
if (HasDifferentialCheckSum())
33443353
{
3345-
try
3346-
{
3347-
MLDataPipelineExtension.DynamoMLDataPipeline.SendWorkspaceLog(workspacePath);
3348-
}
3349-
catch (Exception ex)
3354+
Model.Logger.Log("This Workspace is being shared to train the Dynamo Machine Learning model.", LogLevel.File);
3355+
MLDataPipelineExtension.DynamoMLDataPipeline.isWorkspaceSharedWithML = true;
3356+
3357+
var workspacePath = model.CurrentWorkspace.FileName;
3358+
3359+
Task.Run(() =>
33503360
{
3351-
Model.Logger.Log("Failed to share this workspace with ML pipeline.", LogLevel.File);
3352-
Model.Logger.Log(ex.StackTrace, LogLevel.File);
3353-
}
3354-
});
3361+
try
3362+
{
3363+
MLDataPipelineExtension.DynamoMLDataPipeline.SendWorkspaceLog(workspacePath);
3364+
}
3365+
catch (Exception ex)
3366+
{
3367+
Model.Logger.Log("Failed to share this workspace with ML pipeline.", LogLevel.File);
3368+
Model.Logger.Log(ex.StackTrace, LogLevel.File);
3369+
}
3370+
});
3371+
}
33553372
}
33563373
}
33573374
}

src/DynamoMLDataPipeline/DynamoMLDataPipeline.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ internal string ProductionCollectionID
6161
// Points to the Dynamo version.
6262
internal Version DynamoVersion { get; set; }
6363

64+
internal bool isWorkspaceSharedWithML { get; set; }
65+
6466
// Id of the user sending the post request.
6567
private string GetUserId()
6668
{
@@ -296,11 +298,6 @@ void SendToMLDataPipeline(string filePath, RestClient client, string token)
296298

297299
public void SendWorkspaceLog(string filePath)
298300
{
299-
if (!DynamoModel.PreferenceSettings.IsMLAutocompleteTOUApproved)
300-
{
301-
throw new InvalidOperationException("User has opted out of data collection, this function shouldn't be called.");
302-
}
303-
304301
// Depending on whether we are using Stage or Prod, a token needs to be retrieved
305302
// using client and secret id from the app created in the respective environment.
306303
var token = GetAuthorizationToken();

src/DynamoMLDataPipeline/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
[assembly: Guid("f2fcfd49-84bc-4c0e-90c1-5a327d017c4e")]
1313

1414
[assembly: InternalsVisibleTo("DynamoCoreWpf")]
15+
[assembly: InternalsVisibleTo("DynamoCoreWpfTests")]
1516
// Version information for an assembly consists of the following four values:
1617
//
1718
// Major Version

test/DynamoCoreWpfTests/DynamoCoreWpfTests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@
178178
<Project>{1E92CDB0-644C-4EAA-8AB8-EFDD193A0484}</Project>
179179
<Name>GraphNodeManagerViewExtension</Name>
180180
</ProjectReference>
181+
<ProjectReference Include="..\..\src\DynamoMLDataPipeline\DynamoMLDataPipeline.csproj">
182+
<Project>{F2FCFD49-84BC-4C0E-90C1-5A327D017C4E}</Project>
183+
<Name>DynamoMLDataPipeline</Name>
184+
<Private>False</Private>
185+
</ProjectReference>
181186
<ProjectReference Include="..\DynamoCoreTests\DynamoCoreTests.csproj">
182187
<Project>{472084ed-1067-4b2c-8737-3839a6143eb2}</Project>
183188
<Name>DynamoCoreTests</Name>

test/DynamoCoreWpfTests/DynamoViewTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Dynamo.Wpf.ViewModels.Core;
1818
using Dynamo.Wpf.Views;
1919
using NUnit.Framework;
20+
using DynamoMLDataPipeline;
2021

2122

2223
namespace DynamoCoreWpfTests
@@ -203,5 +204,31 @@ public void TestToastNotificationClosingBehavior()
203204
bool isToastNotificationVisible = (bool)(ViewModel.MainGuideManager?.ExitTourPopupIsVisible);
204205
Assert.IsFalse(isToastNotificationVisible);
205206
}
207+
208+
// Terms of use test on workspace close event.
209+
[Test]
210+
public void TestTOUWorkspaceClose()
211+
{
212+
// Open workspace with test mode as false, to verify trust warning.
213+
DynamoModel.IsTestMode = false;
214+
Open(@"core\watch\WatchDictionary.dyn");
215+
ViewModel.PreferenceSettings.IsMLAutocompleteTOUApproved = false;
216+
217+
// Close workspace
218+
Assert.IsTrue(ViewModel.CloseHomeWorkspaceCommand.CanExecute(null));
219+
ViewModel.CloseHomeWorkspaceCommand.Execute(null);
220+
221+
Assert.IsFalse(ViewModel.MLDataPipelineExtension.DynamoMLDataPipeline.isWorkspaceSharedWithML);
222+
223+
//reopen
224+
Open(@"core\watch\WatchDictionary.dyn");
225+
ViewModel.PreferenceSettings.IsMLAutocompleteTOUApproved = true;
226+
227+
// Close workspace
228+
Assert.IsTrue(ViewModel.CloseHomeWorkspaceCommand.CanExecute(null));
229+
ViewModel.CloseHomeWorkspaceCommand.Execute(null);
230+
231+
Assert.IsTrue(ViewModel.MLDataPipelineExtension.DynamoMLDataPipeline.isWorkspaceSharedWithML);
232+
}
206233
}
207234
}

0 commit comments

Comments
 (0)