From 24f3531a3c277924fcaabba83236bd62baf8cb95 Mon Sep 17 00:00:00 2001 From: Shahovalov MIkhail Date: Wed, 27 May 2026 23:28:34 +0300 Subject: [PATCH] =?UTF-8?q?review(drawing):=20=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?(Codex=20+=20pi/glm-5.1=20+=20pi/kimi-k2.6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - K1 (kimi, Major): спайк подтвердил — для User КОМПАС САМ выводит VerticalOrientation из W/H (игнорирует флаг, W/H не свопает); read-back корректен, правка не нужна — задокументировано комментарием + тесты на Landscape (500×300→альбомная, 300×500→книжная) - K2: ValidateFormatDimensions называет точный нарушивший параметр (width/height) - тесты: A1 в Parse (C3), A4 landscape со свопом 297×210 (G2), sheetNumber=0 (C2/G3) - отклонено (нит): алиасы в описании (G4), сообщение NaN (G5), тип исключения standard (K5) 308 тестов зелёных, сборка Release чистая. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../Drawings/DrawingService.cs | 4 +- .../Drawings/DrawingValidation.cs | 11 +++-- .../Integration/DrawingSheetFormatTests.cs | 47 ++++++++++++++++++- tests/Kompas.Mcp.Tests/PaperFormatsTests.cs | 1 + 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/Kompas.Mcp.Core/Drawings/DrawingService.cs b/src/Kompas.Mcp.Core/Drawings/DrawingService.cs index faa94ec..bbacfa3 100644 --- a/src/Kompas.Mcp.Core/Drawings/DrawingService.cs +++ b/src/Kompas.Mcp.Core/Drawings/DrawingService.cs @@ -118,7 +118,9 @@ public sealed class DrawingService fmt.Format = PaperFormats.ToKompas(format); if (format == PaperFormat.User) { - // Для пользовательского ориентация задаётся соотношением width/height — VerticalOrientation не трогаем. + // Для пользовательского КОМПАС САМ выводит VerticalOrientation из соотношения width/height + // (W>H → альбомная, H>W → книжная) и игнорирует заданный флаг, W/H не свопает — проверено + // спайком. Поэтому VerticalOrientation не трогаем; read-back ниже даёт верную ориентацию. fmt.FormatWidth = width; fmt.FormatHeight = height; } diff --git a/src/Kompas.Mcp.Core/Drawings/DrawingValidation.cs b/src/Kompas.Mcp.Core/Drawings/DrawingValidation.cs index ab4108c..d7b176e 100644 --- a/src/Kompas.Mcp.Core/Drawings/DrawingValidation.cs +++ b/src/Kompas.Mcp.Core/Drawings/DrawingValidation.cs @@ -63,15 +63,20 @@ public static class DrawingValidation { if (format == PaperFormat.User) { - if (!double.IsFinite(width) || width <= 0 || !double.IsFinite(height) || height <= 0) + if (!double.IsFinite(width) || width <= 0) throw new ArgumentOutOfRangeException(nameof(width), - "Для format=user ширина и высота должны быть конечными и > 0."); + "Для format=user ширина должна быть конечной и > 0."); + if (!double.IsFinite(height) || height <= 0) + throw new ArgumentOutOfRangeException(nameof(height), + "Для format=user высота должна быть конечной и > 0."); } else if (width != 0 || height != 0) { + // Точное имя нарушившего параметра (а не всегда width). + var offender = width != 0 ? nameof(width) : nameof(height); throw new ArgumentException( "Ширина/высота задаются только для format=user; для стандартного формата размеры авто (передайте 0).", - nameof(width)); + offender); } } diff --git a/tests/Kompas.Mcp.Tests/Integration/DrawingSheetFormatTests.cs b/tests/Kompas.Mcp.Tests/Integration/DrawingSheetFormatTests.cs index f5a3b66..4edf39a 100644 --- a/tests/Kompas.Mcp.Tests/Integration/DrawingSheetFormatTests.cs +++ b/tests/Kompas.Mcp.Tests/Integration/DrawingSheetFormatTests.cs @@ -48,15 +48,48 @@ public sealed class DrawingSheetFormatTests : IntegrationTestBase } [Fact] - public async Task User_format_with_dimensions() + public async Task A4_landscape_swaps_dimensions() { await _docs.CreateAsync(KompasDocumentType.Drawing); try { + var r = await _drawing.SetSheetFormatAsync(PaperFormat.A4, landscape: true, width: 0, height: 0); + Assert.Equal("A4", r.Format); + Assert.InRange(r.Width, 296.5, 297.5); // своп: альбомная A4 = 297×210 + Assert.InRange(r.Height, 209.5, 210.5); + Assert.True(r.Landscape); + } + finally { await _docs.CloseAsync(save: false); } + } + + [Fact] + public async Task User_landscape_dimensions_derive_orientation() + { + await _docs.CreateAsync(KompasDocumentType.Drawing); + try + { + // 500×300 (W>H) → КОМПАС выводит альбомную ориентацию (Landscape=true), W/H литеральны. var r = await _drawing.SetSheetFormatAsync(PaperFormat.User, landscape: false, width: 500, height: 300); Assert.Equal("User", r.Format); Assert.InRange(r.Width, 499.5, 500.5); Assert.InRange(r.Height, 299.5, 300.5); + Assert.True(r.Landscape); // ориентация выведена из соотношения сторон (не из флага landscape=false) + } + finally { await _docs.CloseAsync(save: false); } + } + + [Fact] + public async Task User_portrait_dimensions_derive_orientation() + { + await _docs.CreateAsync(KompasDocumentType.Drawing); + try + { + // 300×500 (H>W) → книжная (Landscape=false). + var r = await _drawing.SetSheetFormatAsync(PaperFormat.User, landscape: true, width: 300, height: 500); + Assert.Equal("User", r.Format); + Assert.InRange(r.Width, 299.5, 300.5); + Assert.InRange(r.Height, 499.5, 500.5); + Assert.False(r.Landscape); // landscape=true проигнорирован — ориентация из сторон } finally { await _docs.CloseAsync(save: false); } } @@ -97,6 +130,18 @@ public sealed class DrawingSheetFormatTests : IntegrationTestBase finally { await _docs.CloseAsync(save: false); } } + [Fact] + public async Task Nonpositive_sheet_number_throws() + { + await _docs.CreateAsync(KompasDocumentType.Drawing); + try + { + await Assert.ThrowsAsync(() => + _drawing.SetSheetFormatAsync(PaperFormat.A4, landscape: false, width: 0, height: 0, sheetNumber: 0)); + } + finally { await _docs.CloseAsync(save: false); } + } + [Fact] public async Task Active_document_not_drawing_throws() { diff --git a/tests/Kompas.Mcp.Tests/PaperFormatsTests.cs b/tests/Kompas.Mcp.Tests/PaperFormatsTests.cs index db232fc..8195575 100644 --- a/tests/Kompas.Mcp.Tests/PaperFormatsTests.cs +++ b/tests/Kompas.Mcp.Tests/PaperFormatsTests.cs @@ -10,6 +10,7 @@ public sealed class PaperFormatsTests [InlineData("a3", PaperFormat.A3)] [InlineData(" A2 ", PaperFormat.A2)] [InlineData("a0", PaperFormat.A0)] + [InlineData("A1", PaperFormat.A1)] [InlineData("A5", PaperFormat.A5)] [InlineData("user", PaperFormat.User)] [InlineData("USER", PaperFormat.User)]