import { readFileSync } from "node:fs"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; import { linkIdFor } from "../lib/link-id.mjs"; /** * The scripts' port of `link_id_for` derives the id the Rust store derives for * the same edge. Both read the same vectors (the Rust half is * `link_id_for_matches_the_shared_vectors` in derived_id_tests.rs), so a * port that drifts fails by the vector's name. */ interface Vector { what: string; from_kind: string; from_id: string; to_kind: string; to_id: string; to_database: string | null; own_file: string; id: string; } const VECTORS: Vector[] = JSON.parse( readFileSync(join(__dirname, "../../crates/cotton-store/tests/fixtures/link-id-vectors.json"), "utf8"), ); describe("linkIdFor", () => { it("has vectors to check", () => { expect(VECTORS.length).toBeGreaterThan(0); }); for (const vector of VECTORS) { it(vector.what, () => { const id = linkIdFor( { fromKind: vector.from_kind, fromId: vector.from_id, toKind: vector.to_kind, toId: vector.to_id, toDatabase: vector.to_database, }, vector.own_file, ); expect(id).toBe(vector.id); }); } });