feat(attachments): data layer for task file attachments
TaskAttachmentEntity (+config, cascade FK), TaskAttachmentRepository, and an AttachmentStore that writes files under ~/.todo-app/attachments/<taskId>/ with a path-traversal guard and a 5 MB cap. TaskPromptComposer gains an optional read-only 'Reference files' section. Migration AddTaskAttachments.
This commit is contained in:
@@ -42,4 +42,44 @@ public class TaskPromptComposerTests
|
||||
{
|
||||
Assert.Equal("Just a title", TaskPromptComposer.Compose("Just a title", null, System.Array.Empty<(string, bool)>()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Attachment_section_present_when_paths_given()
|
||||
{
|
||||
var result = TaskPromptComposer.Compose(
|
||||
"Title", null, System.Array.Empty<(string, bool)>(),
|
||||
new[] { "/a/b/file1.txt", "/a/b/file2.txt" });
|
||||
|
||||
Assert.Contains("## Reference files", result);
|
||||
Assert.Contains("- /a/b/file1.txt", result);
|
||||
Assert.Contains("- /a/b/file2.txt", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Attachment_section_absent_when_null()
|
||||
{
|
||||
var result = TaskPromptComposer.Compose("Title", null, System.Array.Empty<(string, bool)>(), null);
|
||||
Assert.DoesNotContain("Reference files", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Attachment_section_absent_when_empty()
|
||||
{
|
||||
var result = TaskPromptComposer.Compose("Title", null, System.Array.Empty<(string, bool)>(),
|
||||
System.Array.Empty<string>());
|
||||
Assert.DoesNotContain("Reference files", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Attachment_paths_order_preserved()
|
||||
{
|
||||
var paths = new[] { "/z/last.txt", "/a/first.txt", "/m/middle.txt" };
|
||||
var result = TaskPromptComposer.Compose("Title", null, System.Array.Empty<(string, bool)>(), paths);
|
||||
|
||||
var idxZ = result.IndexOf("/z/last.txt", StringComparison.Ordinal);
|
||||
var idxA = result.IndexOf("/a/first.txt", StringComparison.Ordinal);
|
||||
var idxM = result.IndexOf("/m/middle.txt", StringComparison.Ordinal);
|
||||
|
||||
Assert.True(idxZ < idxA && idxA < idxM, "Paths should appear in the original order.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user