File size: 3,649 Bytes
8a29801 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | /// <reference types="bun-types" />
import {describe, expect, test} from "bun:test"
import {checkManifestVersions} from "../manifestVersionGate"
/**
* Manifest version acceptance gate — `checkManifestVersions`
* accepts/rejects manifests based on sdkVersion + minHostVersion.
* The helper is pure (no disk I/O, no React Native deps);
* AppRegistry's method delegates to it.
*/
describe("checkManifestVersions", () => {
const supportedSdkRange = "^0.3.0"
const hostVersion = "1.42.0"
test("manifest without version fields passes through (legacy)", () => {
const r = checkManifestVersions({}, {hostVersion, supportedSdkRange})
expect(r.ok).toBe(true)
})
test("null manifest passes through (no install record yet)", () => {
const r = checkManifestVersions(null, {hostVersion, supportedSdkRange})
expect(r.ok).toBe(true)
})
test("minHostVersion <= hostVersion is accepted", () => {
const r = checkManifestVersions(
{minHostVersion: "1.42.0"},
{hostVersion, supportedSdkRange},
)
expect(r.ok).toBe(true)
})
test("minHostVersion > hostVersion is rejected with a user-facing reason", () => {
const r = checkManifestVersions(
{minHostVersion: "1.45.0"},
{hostVersion, supportedSdkRange},
)
expect(r.ok).toBe(false)
if (!r.ok) {
expect(r.reason).toContain("Requires Mentra App 1.45.0")
expect(r.reason).toContain("host is 1.42.0")
}
})
test("sdkVersion within supported range is accepted", () => {
const r = checkManifestVersions(
{sdkVersion: "0.3.0"},
{hostVersion, supportedSdkRange},
)
expect(r.ok).toBe(true)
})
test("sdkVersion outside supported range is rejected", () => {
const r = checkManifestVersions(
{sdkVersion: "0.2.0"},
{hostVersion, supportedSdkRange},
)
expect(r.ok).toBe(false)
if (!r.ok) {
expect(r.reason).toContain("SDK 0.2.0")
expect(r.reason).toContain("^0.3.0")
}
})
test("both sdkVersion + minHostVersion checked; first failure wins", () => {
const r = checkManifestVersions(
{sdkVersion: "0.3.0", minHostVersion: "2.0.0"},
{hostVersion, supportedSdkRange},
)
expect(r.ok).toBe(false)
if (!r.ok) expect(r.reason).toContain("Mentra App")
})
test("semver-coerced shorthand versions are accepted (0.3 → 0.3.0)", () => {
const r = checkManifestVersions(
{sdkVersion: "0.3"},
{hostVersion, supportedSdkRange},
)
expect(r.ok).toBe(true)
})
test("rejects malformed compatibility fields from untrusted Store metadata", () => {
const sdk = checkManifestVersions({sdkVersion: "garbage"}, {hostVersion, supportedSdkRange})
expect(sdk).toEqual({ok: false, blocker: "sdk", reason: "Invalid Mentra Miniapp SDK version: garbage."})
const host = checkManifestVersions({minHostVersion: "latest"}, {hostVersion, supportedSdkRange})
expect(host).toEqual({ok: false, blocker: "host", reason: "Invalid minimum Mentra App version: latest."})
})
test("the Mentra App range accepts both SDK numbering schemes the bundled miniapps declare", () => {
for (const sdkVersion of ["0.3.0", "3.2.1", "3.3.0"]) {
expect(checkManifestVersions({sdkVersion}, {hostVersion, supportedSdkRange: ">=0.3.0 <4.0.0"}).ok).toBe(true)
}
expect(checkManifestVersions({sdkVersion: "4.0.0"}, {hostVersion, supportedSdkRange: ">=0.3.0 <4.0.0"})).toEqual({
ok: false,
blocker: "sdk",
reason: "Built for SDK 4.0.0; host supports >=0.3.0 <4.0.0.",
})
})
})
|