Cotton code
32 lines · 1.7 KB · TypeScriptRaw
// RULE: The iPhone suite's native stack fixture (CoreHandleStackTests// testADeepDefinitionReadsThroughTheRealHandle) is stamped at the store's own// SCHEMA_VERSION. Stamped lower, the core refuses it as "written by an earlier// version of the app" (database_not_held), and only the ios job, on a Mac,// a day later, says so: 6b28731477 (148), 54ac05cbfc (151), and swift-main// 17187 at 152 (24 Nov 2026). This says it at the schema rise, on Linux.// Fix: `pnpm gen:stack-probe`.import { readFileSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import { inflateSync } from "node:zlib";import { describe, expect, it } from "vitest";const ROOT = join(__dirname, "..", "..");describe("the native stack fixture", () => {  it("is stamped at the store's SCHEMA_VERSION (else: pnpm gen:stack-probe)", async () => {    const { DatabaseSync } = await import("node:sqlite");    const ddl = readFileSync(join(ROOT, "crates/cotton-store/src/schema/ddl.rs"), "utf8");    const version = Number(/pub const SCHEMA_VERSION: u32 = (\d+)/.exec(ddl)![1]);    const file = join(tmpdir(), `stack-probe-${process.pid}-${Date.now()}.sqlite`);    writeFileSync(file, inflateSync(readFileSync(join(ROOT, "apps/cotton/Tests/CottonKitTests/Fixtures/StackProbe.sqlite.zlib"))));    try {      const db = new DatabaseSync(file, { readOnly: true });      const row = db.prepare("SELECT schema_version FROM _meta").get() as { schema_version: number };      db.close();      expect(row.schema_version, "StackProbe.sqlite.zlib is stale: run pnpm gen:stack-probe").toBe(version);    } finally {      rmSync(file, { force: true });    }  });});