Files
OpenNest/OpenNest.Server.Tests/TestNests.cs
T
ajandClaude Opus 5.5 64e24fc6c8 feat(server): take nest record counts, material and thickness from the archive
The server stored whatever plate count, part count, material and
thickness the client claimed, so a record could disagree with its own
archive, and a bulk importer had to read each written .nest back in full
just to describe it (about a quarter of the PEP archive import's time).

Uploads (POST and PUT /file) now read only the archive's nest.json -
never programs or geometry, and without referencing OpenNest.IO - and
overwrite those fields, following NestReader's fallbacks for thickness,
material, parts with a missing drawing and the trailing new-plate slot.
A file without a readable nest.json is 400 and stores nothing, so the
server can guarantee the record describes the bytes; nest.json
decompression stops at 64 MB. A metadata-only PUT keeps the stored
counts because the archive is unchanged; material and thickness stay
editable there, since the desktop applies the record's values on open.

Server tests that uploaded placeholder bytes now upload small
deterministic archives, and the container smoke's near-limit probe is a
padded real archive. New tests pin the server's values to a full
NestReader read of the same archive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 07:14:06 -04:00

33 lines
1.2 KiB
C#

using System.IO.Compression;
using System.Text;
namespace OpenNest.Server.Tests;
/// <summary>
/// Smallest archives the server accepts as nests. The tag names the nest, so different tags
/// give different bytes, and fixed entry times make the same tag give identical bytes; tests
/// compare stored archives exactly, as they did with arbitrary byte payloads.
/// </summary>
internal static class TestNests
{
private static readonly DateTimeOffset EntryTime = new(2026, 1, 1, 0, 0, 0, TimeSpan.Zero);
public static byte[] Archive(params byte[] tag) =>
Zip("nest.json", $$"""{"version":2,"name":"tag {{Convert.ToHexString(tag)}}","drawings":[],"plates":[]}""");
/// <summary>A valid ZIP holding <paramref name="name"/>; not necessarily a nest.</summary>
public static byte[] Zip(string name, string content)
{
using var stream = new MemoryStream();
using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: true))
{
var entry = archive.CreateEntry(name);
entry.LastWriteTime = EntryTime;
using var writer = new StreamWriter(entry.Open(), Encoding.UTF8);
writer.Write(content);
}
return stream.ToArray();
}
}