|
| 1 | +/** |
| 2 | + * Verify octi-web's FileShareInfo decoder can consume what octi-desktop publishes. |
| 3 | + * |
| 4 | + * Wire-shape differences vs web's own fixtures: desktop emits plain UUID strings for |
| 5 | + * `SharedFile.blobKey` (via `UUID.randomUUID().toString()`) rather than the |
| 6 | + * `sha256:<hex>` form web/android use. The connector IDs are desktop-flavoured |
| 7 | + * (`kserver-prod...77777777-...`). Long size handling: same 8e9-byte `files-large` |
| 8 | + * vector as web's own producer, exceeds Int.MAX_VALUE — JS Number handles it exactly |
| 9 | + * through 2^53. |
| 10 | + */ |
| 11 | +import { describe, expect, it } from "vitest"; |
| 12 | + |
| 13 | +import { |
| 14 | + type InteropPublishedModuleFixture, |
| 15 | + type InteropPublishedVector, |
| 16 | + loadInteropJson, |
| 17 | + verifyVectorIntegrity, |
| 18 | +} from "./fixture-loader"; |
| 19 | +import { deserializeFileShareInfo, FILES_MODULE_ID } from "../modules/files"; |
| 20 | + |
| 21 | +const SOURCE = "d4rken-org/octi-desktop"; |
| 22 | +const FIXTURE_FILE = "octi-desktop-files.json"; |
| 23 | + |
| 24 | +const PROD_CONNECTOR = |
| 25 | + "kserver-prod.kserver.octi.darken.eu-77777777-8888-9999-aaaa-bbbbbbbbbbbb"; |
| 26 | +const BETA_CONNECTOR = |
| 27 | + "kserver-beta.kserver.octi.darken.eu-cccccccc-1111-2222-3333-444444444444"; |
| 28 | + |
| 29 | +const fixture = loadInteropJson<InteropPublishedModuleFixture>(FIXTURE_FILE, SOURCE); |
| 30 | + |
| 31 | +function vector(name: string): InteropPublishedVector { |
| 32 | + const v = fixture.vectors.find((x) => x.name === name); |
| 33 | + if (!v) throw new Error(`vector '${name}' missing in ${fixture.module}`); |
| 34 | + verifyVectorIntegrity(v); |
| 35 | + return v; |
| 36 | +} |
| 37 | + |
| 38 | +function decode(v: InteropPublishedVector) { |
| 39 | + return deserializeFileShareInfo(new TextEncoder().encode(v.payloadJson)); |
| 40 | +} |
| 41 | + |
| 42 | +describe("desktop files interop", () => { |
| 43 | + it("fixture schema sanity", () => { |
| 44 | + expect(fixture.schemaVersion).toBe(1); |
| 45 | + expect(fixture.module).toBe(FILES_MODULE_ID); |
| 46 | + expect(fixture.producer).toBe(SOURCE); |
| 47 | + expect(fixture.vectors.map((v) => v.name)).toEqual([ |
| 48 | + "empty", |
| 49 | + "single-file", |
| 50 | + "with-multiple-files", |
| 51 | + "with-delete-requests", |
| 52 | + "multi-connector", |
| 53 | + "files-large", |
| 54 | + ]); |
| 55 | + }); |
| 56 | + |
| 57 | + it("'empty' vector decodes to empty lists", () => { |
| 58 | + const info = decode(vector("empty")); |
| 59 | + expect(info.files).toEqual([]); |
| 60 | + expect(info.deleteRequests).toEqual([]); |
| 61 | + }); |
| 62 | + |
| 63 | + it("'single-file' vector decodes one SharedFile with UUID blobKey", () => { |
| 64 | + const info = decode(vector("single-file")); |
| 65 | + expect(info.files.length).toBe(1); |
| 66 | + expect(info.deleteRequests).toEqual([]); |
| 67 | + |
| 68 | + const f = info.files[0]; |
| 69 | + expect(f.name).toBe("notes.txt"); |
| 70 | + expect(f.mimeType).toBe("text/plain"); |
| 71 | + expect(f.size).toBe(1234); |
| 72 | + expect(f.blobKey).toBe("00000000-0000-0000-0000-000000000001"); |
| 73 | + expect(f.checksum).toBe("11".repeat(32)); |
| 74 | + expect(f.sharedAt).toBe("2026-05-01T12:00:00Z"); |
| 75 | + expect(f.expiresAt).toBe("2026-05-31T12:00:00Z"); |
| 76 | + expect(f.availableOn).toEqual([PROD_CONNECTOR]); |
| 77 | + expect(f.connectorRefs).toEqual({ [PROD_CONNECTOR]: "blob-id-aaaa" }); |
| 78 | + }); |
| 79 | + |
| 80 | + it("'with-multiple-files' vector decodes both entries field-by-field", () => { |
| 81 | + const info = decode(vector("with-multiple-files")); |
| 82 | + expect(info.files.length).toBe(2); |
| 83 | + expect(info.deleteRequests).toEqual([]); |
| 84 | + |
| 85 | + const alpha = info.files[0]; |
| 86 | + expect(alpha.name).toBe("alpha.bin"); |
| 87 | + expect(alpha.mimeType).toBe("application/octet-stream"); |
| 88 | + expect(alpha.size).toBe(256); |
| 89 | + expect(alpha.blobKey).toBe("00000000-0000-0000-0000-000000000002"); |
| 90 | + expect(alpha.checksum).toBe("22".repeat(32)); |
| 91 | + expect(alpha.sharedAt).toBe("2026-05-01T12:00:00Z"); |
| 92 | + expect(alpha.expiresAt).toBe("2026-05-31T12:00:00Z"); |
| 93 | + expect(alpha.availableOn).toEqual([PROD_CONNECTOR]); |
| 94 | + expect(alpha.connectorRefs).toEqual({ [PROD_CONNECTOR]: "blob-id-bbbb" }); |
| 95 | + |
| 96 | + const beta = info.files[1]; |
| 97 | + expect(beta.name).toBe("beta.pdf"); |
| 98 | + expect(beta.mimeType).toBe("application/pdf"); |
| 99 | + expect(beta.size).toBe(4096); |
| 100 | + expect(beta.blobKey).toBe("00000000-0000-0000-0000-000000000003"); |
| 101 | + expect(beta.checksum).toBe("33".repeat(32)); |
| 102 | + expect(beta.sharedAt).toBe("2026-05-01T13:00:00Z"); |
| 103 | + expect(beta.expiresAt).toBe("2026-05-31T13:00:00Z"); |
| 104 | + expect(beta.availableOn).toEqual([PROD_CONNECTOR]); |
| 105 | + expect(beta.connectorRefs).toEqual({ [PROD_CONNECTOR]: "blob-id-cccc" }); |
| 106 | + }); |
| 107 | + |
| 108 | + it("'with-delete-requests' vector decodes the deleteRequests branch field-by-field", () => { |
| 109 | + const info = decode(vector("with-delete-requests")); |
| 110 | + expect(info.files.length).toBe(1); |
| 111 | + expect(info.deleteRequests.length).toBe(1); |
| 112 | + |
| 113 | + const f = info.files[0]; |
| 114 | + expect(f.name).toBe("shared.txt"); |
| 115 | + expect(f.mimeType).toBe("text/plain"); |
| 116 | + expect(f.size).toBe(100); |
| 117 | + expect(f.blobKey).toBe("00000000-0000-0000-0000-000000000004"); |
| 118 | + expect(f.checksum).toBe("44".repeat(32)); |
| 119 | + expect(f.sharedAt).toBe("2026-05-01T12:00:00Z"); |
| 120 | + expect(f.expiresAt).toBe("2026-05-31T12:00:00Z"); |
| 121 | + expect(f.availableOn).toEqual([PROD_CONNECTOR]); |
| 122 | + expect(f.connectorRefs).toEqual({ [PROD_CONNECTOR]: "blob-id-dddd" }); |
| 123 | + |
| 124 | + const req = info.deleteRequests[0]; |
| 125 | + expect(req.targetDeviceId).toBe("99999999-8888-7777-6666-555555555555"); |
| 126 | + expect(req.blobKey).toBe("00000000-0000-0000-0000-000000000005"); |
| 127 | + expect(req.requestedAt).toBe("2026-05-10T00:00:00Z"); |
| 128 | + expect(req.retainUntil).toBe("2026-05-17T00:00:00Z"); |
| 129 | + }); |
| 130 | + |
| 131 | + it("'multi-connector' vector decodes both connectorRefs entries field-by-field", () => { |
| 132 | + const info = decode(vector("multi-connector")); |
| 133 | + expect(info.files.length).toBe(1); |
| 134 | + expect(info.deleteRequests).toEqual([]); |
| 135 | + |
| 136 | + const f = info.files[0]; |
| 137 | + expect(f.name).toBe("shared-across.bin"); |
| 138 | + expect(f.mimeType).toBe("application/octet-stream"); |
| 139 | + expect(f.size).toBe(512); |
| 140 | + expect(f.blobKey).toBe("00000000-0000-0000-0000-000000000007"); |
| 141 | + expect(f.checksum).toBe("77".repeat(32)); |
| 142 | + expect(f.sharedAt).toBe("2026-05-01T12:00:00Z"); |
| 143 | + expect(f.expiresAt).toBe("2026-05-31T12:00:00Z"); |
| 144 | + expect(new Set(f.availableOn)).toEqual(new Set([PROD_CONNECTOR, BETA_CONNECTOR])); |
| 145 | + expect(f.connectorRefs).toEqual({ |
| 146 | + [PROD_CONNECTOR]: "blob-id-prod-7777", |
| 147 | + [BETA_CONNECTOR]: "blob-id-beta-7777", |
| 148 | + }); |
| 149 | + }); |
| 150 | + |
| 151 | + it("'files-large' vector decodes size larger than Int.MAX_VALUE", () => { |
| 152 | + // Pins large-number handling on the JS consumer. JS Number is double-precision so |
| 153 | + // 8e9 is exactly representable; the test still asserts equality to catch a |
| 154 | + // hypothetical type-erasure-to-string regression. |
| 155 | + const info = decode(vector("files-large")); |
| 156 | + expect(info.files.length).toBe(1); |
| 157 | + expect(info.deleteRequests).toEqual([]); |
| 158 | + |
| 159 | + const f = info.files[0]; |
| 160 | + expect(f.name).toBe("big.iso"); |
| 161 | + expect(f.mimeType).toBe("application/octet-stream"); |
| 162 | + expect(f.size).toBe(8_000_000_000); |
| 163 | + expect(f.size).toBeGreaterThan(2 ** 31 - 1); |
| 164 | + expect(f.blobKey).toBe("00000000-0000-0000-0000-000000000006"); |
| 165 | + expect(f.checksum).toBe("66".repeat(32)); |
| 166 | + expect(f.sharedAt).toBe("2026-05-01T12:00:00Z"); |
| 167 | + expect(f.expiresAt).toBe("2026-05-31T12:00:00Z"); |
| 168 | + expect(f.availableOn).toEqual([PROD_CONNECTOR]); |
| 169 | + expect(f.connectorRefs).toEqual({ [PROD_CONNECTOR]: "blob-id-eeee" }); |
| 170 | + }); |
| 171 | +}); |
0 commit comments