test(httpapi): cover session json parity (#24682)

This commit is contained in:
Kit Langton
2026-04-27 19:48:57 -04:00
committed by GitHub
parent ce78a4265d
commit c103202ad5
3 changed files with 153 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
import { describe, expect, test } from "bun:test"
import { Schema } from "effect"
import { ProjectID } from "../../src/project/schema"
import { SessionID } from "../../src/session/schema"
import { MessageID, SessionID } from "../../src/session/schema"
import { Session } from "../../src/session/session"
const info = {
@@ -50,4 +50,27 @@ describe("Session schema", () => {
expect(Object.hasOwn(encoded, "parentID")).toBe(false)
expect(Object.hasOwn(encoded.project as Record<string, unknown>, "name")).toBe(false)
})
test("encodes nested undefined optional session fields as omitted keys", () => {
const encoded = Schema.encodeUnknownSync(Session.Info)({
...info,
summary: {
additions: 1,
deletions: 2,
files: 3,
diffs: undefined,
},
revert: {
messageID: MessageID.ascending(),
partID: undefined,
snapshot: undefined,
diff: undefined,
},
}) as Record<string, unknown>
expect(Object.hasOwn(encoded.summary as Record<string, unknown>, "diffs")).toBe(false)
for (const key of ["partID", "snapshot", "diff"]) {
expect(Object.hasOwn(encoded.revert as Record<string, unknown>, key)).toBe(false)
}
})
})