feat(data): store a nest's job number apart from the customer

Job numbers were going into Customer ("GM / 4980-88R"), which breaks
sorting, searching and grouping by customer. A nest now has its own
Job # field: one or several jobs separated by commas, normalized to
"a, b". It is saved in nest.json and the server (schema v21), edited
beside Customer in Edit Nest (WinForms and Avalonia), shown as a
sortable, searchable column in the Open list, and printed on the nest
report and in MCP output.

Deploy the server before the desktop: the open overlay takes the
server's job number, and an older server has none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-12-03 10:21:04 -05:00
1 parent 857b88a2c7
commit bfdfefeb9e
40 files changed
+304 -44

No files matched your search

@@ -23,7 +23,7 @@ public sealed class DrawingLibraryDatabaseTests
using (var database = new NestDatabase(factory.DatabasePath, pooling: false))
Assert.Empty(database.QueryDrawings(new DrawingLibraryQuery { IncludeArchived = true }).Items);
Assert.Equal(before, NestDigest(factory.DatabasePath));
Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
}
using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false);
@@ -44,7 +44,7 @@ public sealed class DrawingLibraryDatabaseTests
using (var database = new NestDatabase(factory.DatabasePath, pooling: false))
{
Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(before, NestDigest(factory.DatabasePath));
// Two distinct blobs across four revisions: the bracket's notes edit and the
// plate both reuse the bracket's first package.
@@ -81,7 +81,7 @@ public sealed class DrawingLibraryDatabaseTests
{
using var factory = new ServerFactory();
using (new NestDatabase(factory.DatabasePath, pooling: false)) { }
Execute(factory.DatabasePath, "PRAGMA user_version=21");
Execute(factory.DatabasePath, "PRAGMA user_version=22");
Assert.Throws<InvalidOperationException>(() => new NestDatabase(factory.DatabasePath, pooling: false));
}
@@ -106,7 +106,7 @@ public sealed class DrawingLibraryDatabaseTests
""");
using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false);
Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(-3, upgraded.GetDrawing(record.Id)!.Settings.Priority);
Assert.Equal(-3, Assert.Single(upgraded.DrawingHistory(record.Id, 0, 100)!.Items).Settings.Priority);
Assert.Equal(int.MaxValue, upgraded.GetDrawing(other.Id)!.Settings.Priority);
@@ -23,7 +23,7 @@ public sealed class DrawingSetDatabaseTests
using (var database = new NestDatabase(factory.DatabasePath, pooling: false))
Assert.Empty(database.QueryDrawingSets(new DrawingSetQuery { IncludeArchived = true }).Items);
Assert.Equal(before, Digest(factory.DatabasePath));
Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
}
using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false);
@@ -48,7 +48,7 @@ public sealed class DrawingSetDatabaseTests
Assert.Equal(before, Digest(factory.DatabasePath));
Execute(factory.DatabasePath, "DROP TABLE ix_drawing_set_members_drawing");
using var database = new NestDatabase(factory.DatabasePath, pooling: false);
Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
}
[Fact]
+1 -1
View File
@@ -25,7 +25,7 @@ public sealed class MaterialListTests
using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false);
Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Empty(upgraded.ListMaterials());
Assert.Equal((" Stainless ", "304"), (upgraded.Get(nest)!.Material, upgraded.Get(nest)!.MaterialGrade));
Assert.Equal(drawing.MaterialName, upgraded.GetDrawing(drawing.Id)!.MaterialName);
@@ -0,0 +1,77 @@
using OpenNest.Data;
using static OpenNest.Server.Tests.TestDatabase;
namespace OpenNest.Server.Tests;
public sealed class NestJobNumberTests
{
[Fact]
public void JobNumber_RoundTripsThroughInsertUpdateAndHistory()
{
using var factory = new ServerFactory();
using var database = new NestDatabase(factory.DatabasePath, pooling: false);
var id = Guid.NewGuid();
var created = database.Insert(id, Record("Job", "4980-88R"), [1]);
Assert.Equal("4980-88R", created.JobNumber);
var unchanged = database.UpdateMetadata(id, Record("Job", "4980-88R"), created.Revision)!;
Assert.Equal(created.Revision, unchanged.Revision);
var updated = database.UpdateMetadata(id, Record("Job", "4980-88R,4981-02"), created.Revision)!;
Assert.Equal("4980-88R, 4981-02", updated.JobNumber);
Assert.Equal(created.Revision + 1, updated.Revision);
var history = database.History(id, 0, 10)!;
Assert.Equal(["4980-88R, 4981-02", "4980-88R"], history.Items.Select(r => r.JobNumber));
}
[Fact]
public void Query_SearchesAndSortsByJobNumber()
{
using var factory = new ServerFactory();
using var database = new NestDatabase(factory.DatabasePath, pooling: false);
database.Insert(Guid.NewGuid(), Record("A", "4981-02"), [1]);
database.Insert(Guid.NewGuid(), Record("B", "4980-88R, 4156"), [1]);
database.Insert(Guid.NewGuid(), Record("C", ""), [1]);
var found = database.Query(new NestQuery { Search = "4156" });
Assert.Equal("B", Assert.Single(found.Items).Name);
var sorted = database.Query(new NestQuery { Sort = NestSortField.JobNumber, Descending = false });
Assert.Equal(["C", "B", "A"], sorted.Items.Select(r => r.Name));
}
[Fact]
public void Version20Database_GainsBlankJobNumbersAndKeepsRecords()
{
using var factory = new ServerFactory();
var id = Guid.NewGuid();
using (var database = new NestDatabase(factory.DatabasePath, pooling: false))
database.Insert(id, Record("Legacy", "4980-88R"), [1]);
Execute(factory.DatabasePath, """
ALTER TABLE nests DROP COLUMN jobNumber;
ALTER TABLE nest_revisions DROP COLUMN jobNumber;
PRAGMA user_version=20;
""");
using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false);
var record = upgraded.Get(id)!;
Assert.Equal("GM", record.Customer);
Assert.Equal("", record.JobNumber);
Assert.Equal("", Assert.Single(upgraded.History(id, 0, 10)!.Items).JobNumber);
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
}
private static NestRecord Record(string name, string jobNumber) => new()
{
Name = name,
Customer = "GM",
JobNumber = jobNumber,
Material = "Mild Steel",
Thickness = 0.135,
DateCreated = new DateTime(2026, 1, 1),
DateModified = new DateTime(2026, 1, 2),
};
}
@@ -75,7 +75,7 @@ public sealed class NestMaterialGradeTests
Assert.Equal("Stainless", record.Material);
Assert.Equal("", record.MaterialGrade);
Assert.Equal("", Assert.Single(upgraded.History(id, 0, 10)!.Items).MaterialGrade);
Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
}
private static NestRecord Record(string name, string material, string grade) => new()
+2
View File
@@ -370,6 +370,7 @@ public sealed class NestQueryTests : IDisposable
DateModified = new DateTime(2026, 1, 2 + index % 27, 9, 0, 0, DateTimeKind.Unspecified),
Material = index % 3 == 0 ? "Synthetic steel" : "Synthetic alloy",
MaterialGrade = index % 4 == 0 ? "" : $"Grade {index % 5}",
JobNumber = index % 3 == 0 ? "" : $"{4980 + index % 4}-{(index % 2 == 0 ? "r" : "R")}",
Thickness = 0.25 + index % 3 * 0.125,
Status = statuses[index % statuses.Length],
PlateCount = 1 + index % 4,
@@ -412,6 +413,7 @@ public sealed class NestQueryTests : IDisposable
NestSortField.Comments => Text(r => r.Comments),
NestSortField.FileSize => (a, b) => a.FileSize.CompareTo(b.FileSize),
NestSortField.MaterialGrade => Text(r => r.MaterialGrade),
NestSortField.JobNumber => Text(r => r.JobNumber),
_ => throw new ArgumentOutOfRangeException(nameof(field)),
};
var sorted = records.ToList();
+1 -1
View File
@@ -119,7 +119,7 @@ public sealed class NestStockCodesTests
database.SetDeleted(deleted, false, record.Revision);
Assert.Equal(["SHEET-1", "SHEET-2"], database.StockCodesInUse(null).Select(u => u.ItemCode));
}
Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
}
private static Nest Nest(string name, NestStatus status, params string[][] plateCodes)
@@ -58,7 +58,7 @@ public sealed class NestThicknessNameTests
Assert.Equal(0.135, record.Thickness);
Assert.Equal("", record.ThicknessName);
Assert.Equal("", Assert.Single(upgraded.History(id, 0, 10)!.Items).ThicknessName);
Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
}
private static NestRecord Record(string name, string thicknessName) => new()
+1 -1
View File
@@ -77,7 +77,7 @@ public sealed class NestUnitsTests
Assert.Equal([Units.Millimeters, Units.Millimeters], upgraded.History(metric, 0, 10)!.Items.Select(r => r.Units));
Assert.Equal(Units.Inches, upgraded.Get(inch)!.Units);
Assert.Equal(Units.Inches, upgraded.Get(unreadable)!.Units);
Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
}
private static NestRecord Record(string name, Units units) => new()
@@ -152,7 +152,7 @@ public sealed class SetReleaseDrawingTests
using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false);
Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
var kept = upgraded.GetRelease(releaseId)!;
Assert.Empty(kept.Drawings);
Assert.Equal(((Guid?)kit.Id, drawing, 2), (kept.Nests[0].Items.Single().SetId, kept.Nests[0].Items.Single().DrawingId, kept.Nests[0].Items.Single().Quantity));
+1 -1
View File
@@ -295,7 +295,7 @@ public sealed class SetReleaseTests
using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false);
Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(0L, Scalar(factory.DatabasePath, "SELECT COUNT(*) FROM sqlite_master WHERE name LIKE 'set_release%' OR name LIKE 'ix_set_release%'"));
var release = upgraded.GetRelease(releaseId)!;
Assert.Equal(("Legacy notes", "Legacy operator", false), (release.Notes, release.ReleasedBy, release.IsUndone));
+1 -1
View File
@@ -101,7 +101,7 @@ public sealed class SharedSettingsTests
using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false);
Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
Assert.Empty(upgraded.ListSharedSettings());
}