Pin the tail refusal on CultNet replication, the provider command and the CDN manifest; held-nowhere is asserted
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
50a8ead871
commit
e6bd81adcb
4 changed files with 47 additions and 1 deletions
|
|
@ -975,8 +975,11 @@ test("every bytes-after vector is refused by the one owner, by count, on the cod
|
|||
await assertBytesAfterRefused(file, tail, () => cache.pullAllBackingStores(), surface.type);
|
||||
|
||||
// The put path: an envelope arriving with the tail is refused and held nowhere.
|
||||
const held = CultCache.builder().withDocumentType(surface).withGenericStore(memoryStore([])).build();
|
||||
const written: CultCacheEnvelope[] = [];
|
||||
const held = CultCache.builder().withDocumentType(surface).withGenericStore(memoryStore(written)).build();
|
||||
await assertBytesAfterRefused(file, tail, () => held.putEnvelope(surface, envelopeOf(bytes)), surface.type);
|
||||
assert.equal(written.length, 0, `${file}: nothing reached the store`);
|
||||
assert.equal(held.get(surface, "surface"), undefined, `${file}: nothing is held in memory`);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -83,3 +83,16 @@ test("a provider command that is not a map, or lacks a required field, is refuse
|
|||
(error: Error) => error.message === "CultMesh provider command must be a MessagePack map.",
|
||||
);
|
||||
});
|
||||
|
||||
test("a provider command payload with bytes after its first value is refused by count, without echoing the tail", () => {
|
||||
const command = { commandId: "c1", commandKind: "k", providerId: "p", serviceInstanceId: "s", payload: { n: 1 } };
|
||||
const whole = documentPayloadBytes(encodeDocumentPayload(providerCommandDocument, command));
|
||||
const tailed = documentPayloadFromBytes(Uint8Array.from([...whole, ...Buffer.from("canary-tail-8c1f")]));
|
||||
assert.throws(
|
||||
() => decodeProviderCommandDocument({
|
||||
schemaId: cultMeshProviderSessionSchemas.command, recordKey: "p/s/c1", storedAt: "2026-10-11T00:00:00Z",
|
||||
payloadEncoding: "messagepack" as const, payload: tailed,
|
||||
}),
|
||||
(error: Error) => error.message.includes("16 bytes after its first MessagePack value") && !error.message.includes("canary-tail-8c1f"),
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -392,6 +392,13 @@ test("decodeManifest accepts and refuses exactly what the reference does, and re
|
|||
}
|
||||
});
|
||||
|
||||
test("a manifest with bytes after its first value is refused by count, whatever the tail is", () => {
|
||||
const whole = encodeManifest(manifestOf());
|
||||
for (const tail of [[0xc0], [0xc1, 0xc1], [0x90]]) {
|
||||
assert.throws(() => decodeManifest(Uint8Array.from([...whole, ...tail])), new RegExp(`${tail.length} bytes after its first MessagePack value`));
|
||||
}
|
||||
});
|
||||
|
||||
test("a manifest written as a map names the manifest, not a field inside it", () => {
|
||||
assert.throws(() => decodeManifest(encode({ 0: "a", 9: { k: "v" } })), /field 'manifest' has the wrong type/);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import {
|
|||
SchemaConflictError,
|
||||
SingleFileMessagePackBackingStore,
|
||||
defineDocumentType,
|
||||
documentPayloadBytes,
|
||||
documentPayloadFromBytes,
|
||||
schemaIdentityOf,
|
||||
} from "@gamecult/cultcache-ts";
|
||||
|
||||
|
|
@ -3140,3 +3142,24 @@ test("CultNet registry names the canonical schema id of a compatible alias, and
|
|||
assert.equal(registry.canonicalSchemaId("p3.nobody"), undefined);
|
||||
assert.equal(registry.canonicalSchemaId("p3.shared"), undefined, "an id several bindings claim resolves to none");
|
||||
});
|
||||
|
||||
test("a replicated record with bytes after its first MessagePack value is refused by count and held nowhere", async () => {
|
||||
const definition = defineDocumentType({ type: "tails.note", schemaId: "tails.note.v1", schema: z.object({ body: z.string() }) });
|
||||
const registry = new CultNetDocumentRegistry([defineCultNetDocumentBinding({ definition })]);
|
||||
const origin = CultCache.builder().withDocumentType(definition).build();
|
||||
await origin.put(definition, "k", { body: "x" });
|
||||
const document = registry.createRawSnapshotResponse(origin, "tails").documents[0]!;
|
||||
const whole = documentPayloadBytes(document.payload);
|
||||
const target = CultCache.builder().withDocumentType(definition).build();
|
||||
await assert.rejects(
|
||||
registry.applyRawDocumentPutMessage(target, {
|
||||
schemaVersion: "cultnet.document_put_raw.v0",
|
||||
messageId: "tails",
|
||||
document: { ...document, payload: documentPayloadFromBytes(Uint8Array.from([...whole, 0xc0, 0xc1])) },
|
||||
}),
|
||||
(error: Error) => error.message.includes('document type "tails.note" payload has 2 bytes after its first MessagePack value'),
|
||||
);
|
||||
assert.deepEqual(target.snapshot(), []);
|
||||
await registry.applyRawDocumentPutMessage(target, { schemaVersion: "cultnet.document_put_raw.v0", messageId: "whole", document });
|
||||
assert.deepEqual(target.getRequired(definition, "k"), { body: "x" });
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue