testReceivedSignaturesFollowRenames

tcmts.cli.test.e2e.sync.testReceivedSignaturesFollowRenames · #miij6t7e · term

A received term's signature names a type as it's called now after a rename, though only its inferred type mentions it: receiving leaves type shapes out, and they're worked out for what the branch comes to name.

import { tempDir, withChildren } from "#codebase/tcmts/cli/test/e2e/harness";
import { codebase, startServer } from "#codebase/tcmts/cli/test/e2e/sync";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { DatabaseSync } from "node:sqlite";

export const testReceivedSignaturesFollowRenames = () =>
  withChildren(async (keep) => {
    const root = tempDir("sync renames");
    const server = codebase(root, "server");
    fs.rmSync(path.join(server.dir, "scratch.ts"));
    const url = await startServer(keep, server.dir, "tok");
    const a = codebase(root, "a");
    a.scratch(
      `// tcm: namespace lib\nexport interface Point { x: number; y: number }\nexport const makePoint = (x: number, y: number): Point => ({ x, y });\nexport const origin = () => makePoint(0, 0);\n`,
    );
    a.tcm("add");
    a.tcm("remote", "add", "origin", url, "--token", "tok");
    a.tcm("push");
    // its shape, worked out as the server's branch came to name it (no search has asked)
    const db = new DatabaseSync(path.join(server.dir, ".tcm", "codebase.sqlite"), {
      readOnly: true,
    });
    const shapes = db
      .prepare(
        "SELECT COUNT(*) AS n FROM metadata WHERE key = 'shape' AND hash IN (SELECT hash FROM names WHERE path IN ('lib.origin', 'lib.makePoint'))",
      )
      .get() as { n: number };
    db.close();
    assert.equal(shapes.n, 2);
    assert.match(server.tcm("ls", "lib"), /lib\.origin[^\n]*\(\) => Point/);
    server.tcm("mv", "lib.Point", "lib.Vec");
    assert.match(server.tcm("ls", "lib"), /lib\.origin[^\n]*\(\) => Vec/);
  })

uses