Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a2b8a95c1 |
@@ -5,7 +5,6 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||
<DefaultItemExcludes>$(DefaultItemExcludes);PdfBrowserStub/**</DefaultItemExcludes>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -25,19 +24,14 @@
|
||||
<ProjectReference Include="..\JobTrackerApi\JobTrackerApi.csproj" />
|
||||
<!-- Build the fixture, but only our explicit subdirectory copy owns its output.
|
||||
The Linux apphost has no .exe suffix and collides with that directory if copied to root. -->
|
||||
<ProjectReference Include="PdfBrowserStub/PdfBrowserStub.csproj" ReferenceOutputAssembly="false" Private="false" OutputItemType="PdfBrowserStubAssembly" />
|
||||
<ProjectReference Include="PdfBrowserStub/PdfBrowserStub.csproj" ReferenceOutputAssembly="false" Private="false" />
|
||||
<Compile Remove="PdfBrowserStub/**/*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyPdfBrowserStub" AfterTargets="Build">
|
||||
<Error Condition="'@(PdfBrowserStubAssembly)' == ''" Text="The PDF browser stub project returned no output assembly." />
|
||||
<PropertyGroup>
|
||||
<PdfBrowserStubOutput>@(PdfBrowserStubAssembly->'%(RootDir)%(Directory)%(Filename)')</PdfBrowserStubOutput>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PdfBrowserFiles Include="$(PdfBrowserStubOutput).*" />
|
||||
<!-- The Unix apphost is the only fixture file without an extension. -->
|
||||
<PdfBrowserFiles Include="$(PdfBrowserStubOutput)" Condition="$([System.IO.File]::Exists('$(PdfBrowserStubOutput)'))" />
|
||||
<PdfBrowserFiles Include="PdfBrowserStub/bin/$(Configuration)/net9.0/*" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(PdfBrowserFiles)" DestinationFolder="$(TargetDir)PdfBrowserStub" SkipUnchangedFiles="true" />
|
||||
<Copy SourceFiles="@(PdfBrowserFiles)" DestinationFolder="$(TargetDir)PdfBrowserStub" />
|
||||
</Target>
|
||||
</Project>
|
||||
|
||||
@@ -934,6 +934,32 @@ public sealed class ProfileCvControllerTests
|
||||
Assert.Contains("42", json, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Expérience", "Expe\u0301rience", "## Éducation")]
|
||||
[InlineData("Γλώσσες", "Γλώσσες", "## Εκπαίδευση")]
|
||||
[InlineData("Språk", "Languages", "## Utdanning")]
|
||||
[InlineData("Portfolio – 2026", "Portfolio – 2026", "## Certificates")]
|
||||
[InlineData("Expérience", "Expérience", "Projets supplémentaires")]
|
||||
[InlineData("Språk", "Languages", "Utdanning:")]
|
||||
public async Task Rewrite_preview_replaces_only_the_selected_document_section(string heading, string selected, string nextHeading)
|
||||
{
|
||||
var source = $"## {heading}\r\n\r\nTravail en équipe\r\nOriginal work.\r\n{nextHeading}\r\nKeep this content.";
|
||||
var user = new ApplicationUser { Id = "user-1", ProfileCvText = source };
|
||||
var users = CreateUserManager();
|
||||
users.Setup(x => x.GetUserAsync(It.IsAny<ClaimsPrincipal>())).ReturnsAsync(user);
|
||||
var ai = new Mock<ISummarizerService>();
|
||||
ai.Setup(x => x.SummarizeSectionAsync(It.IsAny<string>(), It.IsAny<string>(), 900, 180))
|
||||
.ReturnsAsync("Updated work.");
|
||||
await using var db = CreateDb();
|
||||
var controller = CreateController(users.Object, ai.Object, db, CreatePaths());
|
||||
var action = await controller.BuildRewritePreview(new ProfileCvController.RewriteSectionRequest { SectionName = selected });
|
||||
var preview = Assert.IsType<ProfileCvPreviewDto>(Assert.IsType<OkObjectResult>(action.Result).Value);
|
||||
|
||||
Assert.Equal($"## {heading}\nUpdated work.\n\n{nextHeading}\nKeep this content.", preview.FullText.ReplaceLineEndings("\n"));
|
||||
ai.Verify(x => x.SummarizeSectionAsync(It.IsAny<string>(), It.Is<string>(text => text.Contains("Original work.") && !text.Contains("Keep this content.")), 900, 180), Times.Once);
|
||||
Assert.Equal(source, user.ProfileCvText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Parse_returns_structured_cv_and_persists_it()
|
||||
{
|
||||
|
||||
@@ -581,6 +581,9 @@ public sealed partial class ProfileCvController : ControllerBase
|
||||
: string.Join("\n\n", structuredCv.Sections.Select(section => $"## {section.Name}\n{section.Content}"));
|
||||
}
|
||||
|
||||
if (sourceText is not null && FindRewriteSection(sourceText, sectionName) is { } range)
|
||||
return sourceText[range.Start..range.End].Trim();
|
||||
|
||||
var matchingSection = structuredCv.Sections.FirstOrDefault(section => string.Equals(section.Name, sectionName, StringComparison.OrdinalIgnoreCase));
|
||||
if (matchingSection is not null && !string.IsNullOrWhiteSpace(matchingSection.Content))
|
||||
{
|
||||
@@ -618,6 +621,33 @@ public sealed partial class ProfileCvController : ControllerBase
|
||||
return null;
|
||||
}
|
||||
|
||||
private static readonly Regex RewriteHeading = new(
|
||||
@"^(?:(?<marker>#{1,2})[ \t]+(?<name>[^\r\n]+?)|(?<name>[\p{Lu}\p{Lt}][\p{L}\p{M} &/]+?))(?<colon>:)?[ \t]*\r?$",
|
||||
RegexOptions.Multiline | RegexOptions.CultureInvariant);
|
||||
|
||||
private static (int Start, int End, string Name)? FindRewriteSection(string text, string sectionName)
|
||||
{
|
||||
var target = NormalizeRewriteSectionName(sectionName.Normalize());
|
||||
foreach (Match heading in RewriteHeading.Matches(text))
|
||||
{
|
||||
var name = heading.Groups["name"].Value.Trim();
|
||||
if (!string.Equals(NormalizeRewriteSectionName(name.Normalize()), target, StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
var next = heading.NextMatch();
|
||||
if (heading.Groups["marker"].Success && next.Success &&
|
||||
!next.Groups["marker"].Success && !next.Groups["colon"].Success &&
|
||||
!SectionAliases.ContainsKey(next.Groups["name"].Value.Trim()))
|
||||
{
|
||||
// The first unmarked line may be prose. Preserve later legacy headings even without a blank separator.
|
||||
var bodyStart = heading.Index + heading.Length;
|
||||
if (text.AsSpan(bodyStart, next.Index - bodyStart).Trim().IsEmpty)
|
||||
next = next.NextMatch();
|
||||
}
|
||||
return (heading.Index, next.Success ? next.Index : text.Length, name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string ReplaceOrAppendCvSection(string source, string sectionName, string sectionDraft)
|
||||
{
|
||||
var trimmedSource = (source ?? string.Empty).Trim();
|
||||
@@ -625,20 +655,14 @@ public sealed partial class ProfileCvController : ControllerBase
|
||||
if (string.IsNullOrWhiteSpace(trimmedDraft)) return trimmedSource;
|
||||
if (string.IsNullOrWhiteSpace(trimmedSource)) return $"## {sectionName}\n{trimmedDraft}";
|
||||
|
||||
var normalizedHeading = sectionName.Trim().ToLowerInvariant();
|
||||
var headingPattern = new Regex(@"^(##\s+|#\s+)?(?<name>[A-Z][A-Za-z &/]+):?\s*$", RegexOptions.Multiline);
|
||||
var matches = headingPattern.Matches(trimmedSource).ToList();
|
||||
var targetIndex = matches.FindIndex(match => string.Equals(match.Groups["name"].Value.Trim(), normalizedHeading, StringComparison.OrdinalIgnoreCase));
|
||||
if (targetIndex < 0)
|
||||
if (FindRewriteSection(trimmedSource, sectionName) is not { } range)
|
||||
{
|
||||
return $"{trimmedSource}\n\n## {sectionName}\n{trimmedDraft}".Trim();
|
||||
}
|
||||
|
||||
var start = matches[targetIndex].Index;
|
||||
var end = targetIndex + 1 < matches.Count ? matches[targetIndex + 1].Index : trimmedSource.Length;
|
||||
var before = trimmedSource[..start].TrimEnd();
|
||||
var after = trimmedSource[end..].TrimStart();
|
||||
return string.Join("\n\n", new[] { before, $"## {sectionName}\n{trimmedDraft}", after }.Where(part => !string.IsNullOrWhiteSpace(part))).Trim();
|
||||
var before = trimmedSource[..range.Start].TrimEnd();
|
||||
var after = trimmedSource[range.End..].TrimStart();
|
||||
return string.Join("\n\n", new[] { before, $"## {range.Name}\n{trimmedDraft}", after }.Where(part => !string.IsNullOrWhiteSpace(part))).Trim();
|
||||
}
|
||||
|
||||
private static IReadOnlyList<CvTemplateDescriptor> GetCvTemplateDescriptors()
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
# PDF admission test fixture
|
||||
|
||||
Verified on Windows x64 with SDK 9.0.317, VSTest 17.14.1 and a locked restore from the local NuGet package cache. The source baseline was `245f2feaa8bee2db8f5da0797b3e33f6ef8b056e`.
|
||||
|
||||
| Build | Test selection | Result |
|
||||
| --- | --- | --- |
|
||||
| Before fix, Release with a fresh `--artifacts-path` | `Default_limit_refuses_second_actual_browser_until_first_exits` | FAILED. The SDK built the stub in the requested location. The test output lacked the stub and the exporter reported that no browser was available. |
|
||||
| After fix, Release with a fresh `--artifacts-path` | `PdfRenderAdmissionTests` | PASSED, 22 of 22. |
|
||||
| After fix, Debug with the conventional output directory | `PdfRenderAdmissionTests` | PASSED, the same 22 of 22. |
|
||||
|
||||
Both successful runs built and launched the fixture through `dotnet test`. In each output layout the fixture directory contained exactly the apphost, assembly, symbols, dependency manifest and runtime configuration. All five SHA-256 hashes matched the corresponding stub project output. The conventional stub project's `bin` and `obj` directories already existed during the final relocated run and were excluded from the test content.
|
||||
|
||||
To repeat with restored dependencies, use `dotnet test JobTrackerApi.Tests/JobTrackerApi.Tests.csproj -c Debug --filter FullyQualifiedName~PdfRenderAdmissionTests`. For the relocated case, use `-c Release` and add `--artifacts-path <fresh-directory>`.
|
||||
|
||||
These tests exercise local process admission, cancellation and cleanup with the synthetic browser. Linux execution, visual PDF acceptance and production rendering remain separate qualifications.
|
||||
Reference in New Issue
Block a user