fix(cv): preserve rewrite language and qualify responsive document controls

This commit is contained in:
cesnimda
2026-10-25 22:55:22 +01:00
parent 2bfaf6c14b
commit 8948c988e2
12 changed files with 822 additions and 5 deletions
+27 -1
View File
@@ -197,10 +197,36 @@ public sealed class AiWorkspaceTests
Assert.DoesNotContain("Hidden Corp", ai.LastText);
Assert.Contains("CURRENT DOCUMENT TO REVISE", ai.LastText);
Assert.Contains("Existing manual draft", ai.LastText);
Assert.Contains("Norwegian Bokmål", ai.LastInstruction);
Assert.Contains("Preserve the source language and meaning; do not translate.", ai.LastInstruction);
Assert.Contains("Shorten the current cover letter", ai.LastInstruction);
}
[Theory]
[InlineData("improve", "en", true)]
[InlineData("improve", "nb-NO", true)]
[InlineData("grammar", "en", true)]
[InlineData("grammar", "nb-NO", true)]
[InlineData("shorten", "en", true)]
[InlineData("shorten", "nb-NO", true)]
[InlineData("generate", "en", false)]
[InlineData("generate", "nb-NO", false)]
[InlineData("regenerate", "en", false)]
[InlineData("regenerate", "nb-NO", false)]
public async Task Letter_prompt_preserves_source_language_for_rewrites_only(string action, string language, bool preserve)
{
var (db, svc, ai) = New("user-1");
await using var _ = db;
var jobId = await SeedJobAsync(db, "user-1");
await SeedLinkedProfileAsync(db, jobId);
await svc.GenerateAsync("user-1", jobId, "unused fallback", "Ada", new("cover-letter", "professional", null, language, "Existing factual letter", action), "p", default);
if (preserve)
{
Assert.Contains("Preserve the source language and meaning; do not translate.", ai.LastInstruction);
Assert.DoesNotContain("Write in natural, professional", ai.LastInstruction);
}
else Assert.Contains(language == "nb-NO" ? "Write in natural, professional Norwegian" : "Write in natural, professional English.", ai.LastInstruction);
}
[Fact]
public async Task History_is_newest_first_and_filters_by_module()
{
+24
View File
@@ -97,6 +97,30 @@ public sealed class CvAiReadinessTests
Assert.Equal("ai:" + action, (await fixture.Db.CvVariantVersions.OrderBy(value => value.Version).LastAsync()).Source);
}
[Theory]
[InlineData("improve", "en", true)]
[InlineData("improve", "nb-NO", true)]
[InlineData("grammar", "en", true)]
[InlineData("grammar", "nb-NO", true)]
[InlineData("shorten", "en", true)]
[InlineData("shorten", "nb-NO", true)]
[InlineData("suggest", "en", false)]
[InlineData("suggest", "nb-NO", false)]
public async Task Contextual_prompt_preserves_source_language_for_rewrites_only(string action, string language, bool preserve)
{
await using var fixture = new Fixture(); await fixture.Open();
var response = await fixture.Controller().AiAssist(new(action, Source, null, null, language, fixture.Cv.Id, 1, "section:summary"), default);
Assert.IsType<OkObjectResult>(response.Result);
var instruction = Assert.IsType<string>(fixture.Ai.Invocations.Single(call => call.Method.Name == "GenerateSectionWithMetadataAsync").Arguments[0]);
if (preserve)
{
Assert.Contains("Preserve the source language; this action is not translation.", instruction);
Assert.DoesNotContain("Write in ", instruction);
}
else Assert.Contains($"Write in {language}.", instruction);
await fixture.AssertUnchanged();
}
[Theory]
[InlineData(Paraphrase)]
[InlineData("Maintained internal web applications.")]