download_lesson_attachment deckte bisher nur die Leserichtung ab, der Nutzer legt Arbeitsblätter aber tatsächlich über die Anhang-Funktion an Einzelstunden ab. Neues Write-Tool nimmt Dateiname + Base64-Inhalt entgegen, validiert vor der Bestätigungsnachfrage (leer/ungültig/zu groß) und lädt erst nach Bestätigung hoch. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,9 +28,9 @@ public sealed class McpToolsTests
|
||||
Assert.Equal(
|
||||
new[]
|
||||
{
|
||||
"add_lesson_phase", "create_grade_entry", "create_lesson", "create_time_entry",
|
||||
"create_unit", "remove_lesson_phase", "update_lesson", "update_lesson_phase",
|
||||
"update_student_group_assignment", "update_unit",
|
||||
"add_lesson_attachment", "add_lesson_phase", "create_grade_entry", "create_lesson",
|
||||
"create_time_entry", "create_unit", "remove_lesson_phase", "update_lesson",
|
||||
"update_lesson_phase", "update_student_group_assignment", "update_unit",
|
||||
},
|
||||
McpToolScope.AllowedWriteTools.OrderBy(n => n, StringComparer.Ordinal));
|
||||
}
|
||||
@@ -400,6 +400,69 @@ public sealed class McpToolsTests
|
||||
Assert.Throws<InvalidOperationException>(() => tool.DownloadLessonAttachment(lesson.Id, "big"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddLessonAttachment_NutzerBestaetigt_LaedtHochUndHaengtAn()
|
||||
{
|
||||
var lesson = new Lesson { Topic = "Brechung" };
|
||||
var lessons = new FakeLessons();
|
||||
lessons.Add(lesson);
|
||||
var storage = new FakeAttachmentStorage();
|
||||
var tool = BuildLessonPlanTools(lessons: lessons, attachments: storage);
|
||||
var content = Convert.ToBase64String("Arbeitsblatt-Inhalt"u8.ToArray());
|
||||
|
||||
var result = await tool.AddLessonAttachment(lesson.Id, "arbeitsblatt.pdf", content);
|
||||
|
||||
Assert.True(result.Applied);
|
||||
var attachment = Assert.Single(lessons.GetById(lesson.Id)!.Attachments);
|
||||
Assert.Equal("arbeitsblatt.pdf", attachment.FileName);
|
||||
using var stream = storage.OpenRead(attachment.StorageId)!;
|
||||
using var reader = new StreamReader(stream);
|
||||
Assert.Equal("Arbeitsblatt-Inhalt", reader.ReadToEnd());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddLessonAttachment_NutzerLehntAb_SpeichertNichts()
|
||||
{
|
||||
var lesson = new Lesson { Topic = "Brechung" };
|
||||
var lessons = new FakeLessons();
|
||||
lessons.Add(lesson);
|
||||
var confirmation = new FakeMcpConfirmation { Response = false };
|
||||
var tool = BuildLessonPlanTools(lessons: lessons, confirmation: confirmation);
|
||||
var content = Convert.ToBase64String("Inhalt"u8.ToArray());
|
||||
|
||||
var result = await tool.AddLessonAttachment(lesson.Id, "arbeitsblatt.pdf", content);
|
||||
|
||||
Assert.False(result.Applied);
|
||||
Assert.Empty(lessons.GetById(lesson.Id)!.Attachments);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddLessonAttachment_UngueltigesBase64_LiefertFehlerOhneNachfrage()
|
||||
{
|
||||
var lesson = new Lesson { Topic = "Brechung" };
|
||||
var lessons = new FakeLessons();
|
||||
lessons.Add(lesson);
|
||||
var confirmation = new FakeMcpConfirmation();
|
||||
var tool = BuildLessonPlanTools(lessons: lessons, confirmation: confirmation);
|
||||
|
||||
var result = await tool.AddLessonAttachment(lesson.Id, "arbeitsblatt.pdf", "nicht-base64!!!");
|
||||
|
||||
Assert.False(result.Applied);
|
||||
Assert.Equal(0, confirmation.CallCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddLessonAttachment_UnbekannteStunde_LiefertFehlerOhneNachfrage()
|
||||
{
|
||||
var confirmation = new FakeMcpConfirmation();
|
||||
var tool = BuildLessonPlanTools(confirmation: confirmation);
|
||||
|
||||
var result = await tool.AddLessonAttachment(Guid.NewGuid(), "x.pdf", Convert.ToBase64String("x"u8.ToArray()));
|
||||
|
||||
Assert.False(result.Applied);
|
||||
Assert.Equal(0, confirmation.CallCount);
|
||||
}
|
||||
|
||||
// ── GroupMembershipTools ─────────────────────────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user