diff --git a/src/ApiService/ApiService/OneFuzzTypes/Enums.cs b/src/ApiService/ApiService/OneFuzzTypes/Enums.cs index 0d05ba0150..7019d3e9cb 100644 --- a/src/ApiService/ApiService/OneFuzzTypes/Enums.cs +++ b/src/ApiService/ApiService/OneFuzzTypes/Enums.cs @@ -331,8 +331,14 @@ private static readonly IReadOnlySet _readyForReset } +/// Select how nodes should be disposed of after they complete a WorkSet public enum NodeDisposalStrategy { + /// Re-images the node (which resets its state), then either it can pick up more work + /// or auto scale will reap it if no work is queued ScaleIn, + + /// Skips re-imaging the node, the node will no longer pick up new work. It will only be + /// scaled in by auto scale. Decommission } diff --git a/src/ApiService/ApiService/onefuzzlib/notifications/JinjaTemplateAdapter.cs b/src/ApiService/ApiService/onefuzzlib/notifications/JinjaTemplateAdapter.cs new file mode 100644 index 0000000000..48ef27a446 --- /dev/null +++ b/src/ApiService/ApiService/onefuzzlib/notifications/JinjaTemplateAdapter.cs @@ -0,0 +1,14 @@ +namespace Microsoft.OneFuzz.Service; + +public class JinjaTemplateAdapter { + public static bool IsJinjaTemplate(string jinjaTemplate) { + return jinjaTemplate.Contains("{% endfor %}") + || jinjaTemplate.Contains("{% endif %}"); + } + public static string AdaptForScriban(string jinjaTemplate) { + return jinjaTemplate.Replace("endfor", "end") + .Replace("endif", "end") + .Replace("{%", "{{") + .Replace("%}", "}}"); + } +} diff --git a/src/ApiService/ApiService/onefuzzlib/notifications/NotificationsBase.cs b/src/ApiService/ApiService/onefuzzlib/notifications/NotificationsBase.cs index 5454513229..696cd2b57b 100644 --- a/src/ApiService/ApiService/onefuzzlib/notifications/NotificationsBase.cs +++ b/src/ApiService/ApiService/onefuzzlib/notifications/NotificationsBase.cs @@ -97,6 +97,7 @@ public Renderer( // implementation doesn't have that so I'm trying to match it. // We should probably propagate any errors up public async Async.Task Render(string templateString, Uri instanceUrl) { + templateString = JinjaTemplateAdapter.IsJinjaTemplate(templateString) ? JinjaTemplateAdapter.AdaptForScriban(templateString) : templateString; var template = Template.Parse(templateString); if (template != null) { return await template.RenderAsync(new { diff --git a/src/ApiService/Tests/TemplateTests.cs b/src/ApiService/Tests/TemplateTests.cs index d3b07e7d2c..0eb43efe72 100644 --- a/src/ApiService/Tests/TemplateTests.cs +++ b/src/ApiService/Tests/TemplateTests.cs @@ -15,6 +15,7 @@ public class TemplateTests { private static readonly string _defaultTemplate = "This input caused the fuzz target {{ report.executable }} to crash. The faulting input SHA256 hash is {{ report.input_sha256 }}
"; // Original python template: "This is the call stack as determined by heuristics. You may wish to confirm this stack trace with a debugger via repro: " + private static readonly string _jinjaForLoop = "This is the call stack as determined by heuristics. You may wish to confirm this stack trace with a debugger via repro: "; // Changes for dotnet: // * Change "endfor" in python to "end" // * Change "{% ... %}" in python to "{{ ... }}" @@ -24,12 +25,14 @@ public class TemplateTests { private static readonly string _testString2 = "The OneFuzz job {{ task.job_id }} found a crash in {{ report.executable }} with input {{ report.input_sha256 }}. ASan log:

{{ report.asan_log }}"; // Original python template: "The fuzzing target ({{ job.project }} {{ job.name }} {{ job.build }}) reported a crash.
{%if report.asan_log %} AddressSanitizer reported the following details:
 {{ report.asan_log }} 
{% else %} Faulting call stack:
{% endif %} You can reproduce the issue remotely in OneFuzz by running the following command:
 {{ repro_cmd }} 
" + private static readonly string _jinjaComplex = "The fuzzing target ({{ job.project }} {{ job.name }} {{ job.build }}) reported a crash.
{% if report.asan_log %} AddressSanitizer reported the following details:
 {{ report.asan_log }} 
{% else %} Faulting call stack:
{% endif %} You can reproduce the issue remotely in OneFuzz by running the following command:
 {{ repro_cmd }} 
"; // Changes for dotnet: // * Change "endfor" in python to "end" // * Change "endif" in python for "end" // * Change "{% ... %}" in python to "{{ ... }}" - // * Change job.project -> job.config.project (same for job.name, job.build). This is actually a bug, it shouldn't work in python either - private static readonly string _testString3 = "The fuzzing target ({{ job.config.project }} {{ job.config.name }} {{ job.config.build }}) reported a crash.
{{ if report.asan_log }} AddressSanitizer reported the following details:
 {{ report.asan_log }} 
{{ else }} Faulting call stack:
{{ end }} You can reproduce the issue remotely in OneFuzz by running the following command:
 {{ repro_cmd }} 
"; + private static readonly string _testString3 = "The fuzzing target ({{ job.project }} {{ job.name }} {{ job.build }}) reported a crash.
{{ if report.asan_log }} AddressSanitizer reported the following details:
 {{ report.asan_log }} 
{{ else }} Faulting call stack:
{{ end }} You can reproduce the issue remotely in OneFuzz by running the following command:
 {{ repro_cmd }} 
"; + + private static readonly string _jinjaIfStatement = "{% if report.asan_log %} AddressSanitizer reported the following details:
 {{ report.asan_log }} 
{% else %} Faulting call stack: