The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | import * as Schema from "effect/Schema"; |
| 3 | |
| 4 | import { withRecordIdTable } from "./orchestrationV2IdTable.ts"; |
| 5 | |
| 6 | const Page = withRecordIdTable( |
| 7 | Schema.Struct({ |
| 8 | rows: Schema.Array( |
| 9 | Schema.Struct({ |
| 10 | id: Schema.String, |
| 11 | count: Schema.Number, |
| 12 | parentIds: Schema.Array(Schema.String), |
| 13 | mergedId: Schema.optional(Schema.String), |
| 14 | item: Schema.Struct({ ownerId: Schema.NullOr(Schema.String), legacyId: Schema.Number }), |
| 15 | }), |
| 16 | ), |
| 17 | idTable: Schema.optionalKey(Schema.Literal(true)), |
| 18 | }), |
| 19 | () => null, |
| 20 | ); |
| 21 | const encode = Schema.encodeSync(Schema.toCodecJson(Page)); |
| 22 | const decode = Schema.decodeUnknownSync(Schema.toCodecJson(Page)); |
| 23 | |
| 24 | describe("record ID table", () => { |
| 25 | it("interns record ID slots and restores them exactly, numbers included", () => { |
| 26 | const value = { |
| 27 | rows: [ |
| 28 | { id: "row:a", count: 7, parentIds: ["row:b"], item: { ownerId: "row:b", legacyId: 3 } }, |
| 29 | { id: "row:b", count: 3, parentIds: [], item: { ownerId: null, legacyId: 0 } }, |
| 30 | ], |
| 31 | }; |
| 32 | const wire = JSON.parse(JSON.stringify(encode({ ...value, idTable: true }))); |
| 33 | |
| 34 | expect(wire).toEqual({ |
| 35 | rows: [ |
| 36 | { id: 0, count: 7, parentIds: [1], item: { ownerId: 1, legacyId: 2 } }, |
| 37 | { id: 1, count: 3, parentIds: [], item: { ownerId: null, legacyId: 3 } }, |
| 38 | ], |
| 39 | ids: ["row:a", "row:b", 3, 0], |
| 40 | }); |
| 41 | expect(decode(wire)).toEqual(value); |
| 42 | // The table is consumed, so a second decode of the same object cannot remap numbers. |
| 43 | expect(decode(wire)).toEqual(value); |
| 44 | }); |
| 45 | |
| 46 | it("rejects an index outside the table, even in an optional slot", () => { |
| 47 | const wire = { |
| 48 | rows: [{ id: 0, count: 1, parentIds: [], mergedId: 5, item: { ownerId: null, legacyId: 0 } }], |
| 49 | ids: ["row:a"], |
| 50 | }; |
| 51 | |
| 52 | expect(() => decode(wire)).toThrow(/mergedId/); |
| 53 | }); |
| 54 | |
| 55 | it("sends and reads the plain form without the marker", () => { |
| 56 | const value = { |
| 57 | rows: [{ id: "row:a", count: 1, parentIds: [], item: { ownerId: null, legacyId: 1 } }], |
| 58 | }; |
| 59 | |
| 60 | expect(encode(value)).toEqual(value); |
| 61 | expect(decode(value)).toEqual(value); |
| 62 | }); |
| 63 | }); |