Files
OpenNest/OpenNest.Engine.Tests/Jobs/NestJobDocumentPriorityTests.cs
T
ajandClaude Opus 5.5 fbc23d6b64 feat(nesting): nest higher priority numbers first
Priority worked like a rank (lower first) with a default of 0, and the
Edit Drawing form stopped at 0, so moving one part ahead of the rest
meant renumbering every other drawing. Higher-first lets a user raise a
single part to 1 and leave everything else at the default.

Every engine, filler and candidate comparer now serves the highest tier
first. Stored values keep their order:
- .nest files add `nestPriority` and keep writing the negated value under
  `priority`, so older readers nest in the same order; files without
  `nestPriority` are negated on read. Drawing packages strip both, so
  package hashes are unchanged.
- Library settings send both keys the same way for older clients.
- Server schema v18 negates stored drawing priorities (an older server
  refuses the upgraded database).
- Job documents move to version 2; version 1 jobs are converted, and an
  older worker refuses version 2 instead of reversing the order.

The Edit Drawing form now accepts negative priorities and says higher
numbers nest first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 11:02:07 -05:00

46 lines
1.4 KiB
C#

using OpenNest.Engine.Jobs.Remote;
namespace OpenNest.Engine.Tests.Jobs;
/// <summary>
/// Version 2 job documents nest higher priority numbers first. Version 1 documents came from
/// desktops that nested lower numbers first and are converted when read, so a job queued before
/// an upgrade keeps its order.
/// </summary>
public class NestJobDocumentPriorityTests
{
[Fact]
public void CurrentVersionKeepsPriority()
{
var item = Assert.Single(Document(NestJobDocument.CurrentVersion, 3).ToRequest(Drawings()).Items);
Assert.Equal(3, item.Priority);
}
[Fact]
public void VersionOneConvertsLowerFirstPriority()
{
var json = Document(1, 3).ToJson();
var item = Assert.Single(NestJobDocument.FromJson(json).ToRequest(Drawings()).Items);
Assert.Equal(-3, item.Priority);
}
[Fact]
public void UnknownVersionIsRefused()
{
Assert.Throws<FormatException>(() => Document(NestJobDocument.CurrentVersion + 1, 0).ToRequest(Drawings()));
}
private static Drawing[] Drawings() => [new Drawing("a", TestDrawingFactory.Rectangle(10, 20))];
private static NestJobDocument Document(int version, int priority) => new()
{
Version = version,
EngineName = "Rectangles",
DrawingNames = ["a"],
Items = [new NestJobDocument.ItemJson { Drawing = 0, Quantity = 1, Priority = priority }],
};
}