Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion tests/fragment.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describe, expect, it } from "vitest";
import { decodeFragment, encodeEnvelope } from "@/lib/payload/fragment";
import { decodeFragment, decodeFragmentAsync, encodeEnvelope } from "@/lib/payload/fragment";
import type { PayloadEnvelope } from "@/lib/payload/schema";
import { packEnvelope } from "@/lib/payload/wire-format";
import { arxCompressBMP, getActiveDictVersion } from "@/lib/payload/arx-codec";

const envelope: PayloadEnvelope = {
v: 1,
Expand Down Expand Up @@ -180,4 +181,33 @@ describe("fragment payload transport", () => {

expect(parsed.code).toBe("decoded-too-large");
});

it("decodes a baseBMP-encoded arx fragment (sync path)", async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Misleading test name — says "sync path" but uses decodeFragmentAsync. The sync decodeFragment explicitly rejects arx codec (see src/lib/payload/fragment.ts:321).

Suggested change
it("decodes a baseBMP-encoded arx fragment (sync path)", async () => {
it("decodes a baseBMP-encoded arx fragment (async path)", async () => {

const arxEnvelope: PayloadEnvelope = { ...envelope, codec: "arx" };
const json = JSON.stringify(packEnvelope(arxEnvelope));
const encoded = await arxCompressBMP(json);
const hash = `#agent-render=v1.arx.${getActiveDictVersion()}.${encoded}`;

const parsed = await decodeFragmentAsync(hash);

expect(parsed.ok).toBe(true);
if (!parsed.ok) return;

expect(parsed.envelope.title).toBe("Test bundle");
});

it("decodes a baseBMP arx fragment when BMP chars are percent-escaped", async () => {
const arxEnvelope: PayloadEnvelope = { ...envelope, codec: "arx" };
const json = JSON.stringify(packEnvelope(arxEnvelope));
const encoded = await arxCompressBMP(json);
const hash = `#agent-render=v1.arx.${getActiveDictVersion()}.${encoded}`;
const escapedHash = hash.replace(/[^\x00-\x7F]/g, (ch) => encodeURIComponent(ch));

const parsed = await decodeFragmentAsync(escapedHash);

expect(parsed.ok).toBe(true);
if (!parsed.ok) return;

expect(parsed.envelope.title).toBe("Test bundle");
});
});
Loading