fix(transport): serialise the export content once and pack those bytes (review 2026-10-21 04/P8a)

This commit is contained in:
Joseph Doherty
2026-10-22 09:21:28 -04:00
parent 93fbd2e030
commit 56aa386784
3 changed files with 60 additions and 3 deletions
@@ -50,6 +50,38 @@ public sealed class BundleSerializerTests
Assert.Null(archive.GetEntry("content.enc"));
}
/// <summary>
/// Review 2026-10-21 04/P8a: the exporter serialises the content DTO once and packs
/// those bytes — the pre-serialised overload writes them verbatim as the plaintext
/// payload and they round-trip, encrypted or not.
/// </summary>
/// <param name="passphrase">Null for a plaintext bundle, otherwise the passphrase.</param>
[Theory]
[InlineData(null)]
[InlineData("pass")]
public void PackContentBytes_packs_preserialised_content_verbatim(string? passphrase)
{
var sut = new BundleSerializer();
var encryptor = new BundleSecretEncryptor();
var contentJson = sut.SerializeContentBytes(SampleContent());
var manifest = passphrase is null
? BuildManifestFor(contentJson)
: BuildManifestFor(contentJson, encryption: new EncryptionMetadata(
"AES-256-GCM", "PBKDF2-SHA256", TestIterations, string.Empty, string.Empty));
using var stream = sut.PackContentBytes(contentJson, manifest, passphrase, encryptor);
var readManifest = sut.ReadManifest(stream);
stream.Position = 0;
var payload = sut.ReadContentBytes(stream, readManifest);
if (passphrase is null)
{
Assert.Equal(contentJson, payload);
}
var unpacked = sut.UnpackContent(payload, readManifest, passphrase, encryptor);
Assert.Equal("util", Assert.Single(unpacked.SharedScripts).Name);
}
/// <summary>Verifies that packing with a passphrase emits a manifest and encrypted content.</summary>
[Fact]
public void Pack_emits_manifest_and_content_enc_when_passphrase_supplied()