mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 21:27:21 +00:00
Fixed the Agenda Planner and ERI Server assistants losing parts of your input (#1142)
This commit is contained in:
1 parent
8a4443ab4b
commit
652d3a509f
19 files changed
+1161
-339
No files matched your search
@@ -0,0 +1,78 @@
|
||||
using AIStudio.Tests.Models.Generation;
|
||||
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
using SourceCodeRules.UsageAnalyzers;
|
||||
|
||||
namespace AIStudio.Tests.Analyzers;
|
||||
|
||||
/// <summary>
|
||||
/// Checks that a string which names a member in braces without being interpolated is refused while compiling.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The Agenda Planner asked the model for an activity at '{this.inputLocation}', word for word, because a $
|
||||
/// was missing in front of the string. Nothing at runtime gives such a string away, so MWAIS0014 turns it into
|
||||
/// a build error, and these tests say which strings it recognizes and which it leaves alone.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class MissingInterpolationAnalyzerTests
|
||||
{
|
||||
[TestCase(""" "at '{this.location}'" """, TestName = "A regular string")]
|
||||
[TestCase(""" @"at '{this.location}'" """, TestName = "A verbatim string")]
|
||||
[TestCase("""" """at '{this.location}'""" """", TestName = "A raw string")]
|
||||
[TestCase("""" $$"""at '{this.location}'""" """", TestName = "A raw string with two dollar signs and one pair of braces")]
|
||||
[TestCase(""" $"at '{{this.location}}'" """, TestName = "An interpolated string with escaped braces")]
|
||||
public async Task AMemberInBracesWhichStaysTextIsRefused(string expression)
|
||||
{
|
||||
var reported = await AnalyzeAsync(expression);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(reported, Has.Count.EqualTo(1));
|
||||
Assert.That(reported.FirstOrDefault()?.Id, Is.EqualTo("MWAIS0014"));
|
||||
Assert.That(reported.FirstOrDefault()?.GetMessage(), Does.Contain("\"{this.location}\""));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AMultiLineRawStringIsRefused()
|
||||
{
|
||||
var reported = await AnalyzeAsync(
|
||||
""""
|
||||
"""
|
||||
The participants meet at '{this.location}'.
|
||||
"""
|
||||
"""");
|
||||
|
||||
Assert.That(reported, Has.Count.EqualTo(1));
|
||||
}
|
||||
|
||||
[TestCase(""" $"at '{this.location}'" """, TestName = "An interpolated string")]
|
||||
[TestCase("""" $$"""at '{{this.location}}'""" """", TestName = "A raw string with two dollar signs and two pairs of braces")]
|
||||
[TestCase(""" string.Format("at '{0}'", this.location) """, TestName = "A placeholder for string.Format")]
|
||||
[TestCase(""" "the {this} keyword" """, TestName = "The keyword in braces")]
|
||||
[TestCase(""" "at this.location" """, TestName = "A member without braces")]
|
||||
public async Task TextWhichIsNoForgottenInterpolationIsLeftAlone(string expression)
|
||||
{
|
||||
var reported = await AnalyzeAsync(expression);
|
||||
|
||||
Assert.That(reported, Is.Empty);
|
||||
}
|
||||
|
||||
private static async Task<IReadOnlyList<Diagnostic>> AnalyzeAsync(string expression)
|
||||
{
|
||||
var source =
|
||||
$$"""
|
||||
namespace Sample;
|
||||
|
||||
public sealed class Meeting
|
||||
{
|
||||
private readonly string location = "Cologne";
|
||||
|
||||
public string Describe() => {{expression}};
|
||||
}
|
||||
""";
|
||||
|
||||
return await CompilationHarness.AnalyzeAsync(source, new MissingInterpolationAnalyzer());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user