import { afterAll, describe, expect, it } from "vitest"; import { detectProtocol } from "@govlab/docs/core/analyzers/orchestration.analyzer.ts"; import { programFor } from "./program.fixture.ts"; const fixture = programFor({ "pay.ts": [ "declare const gateway: { charge(): Promise };", "declare const vault: { store(): Promise };", "export async function processPayment(): Promise {", " await gateway.charge();", " await vault.store();", " await gateway.charge();", "}", "export async function thin(): Promise {", " await vault.store();", "}", ].join("\n"), }); afterAll(() => { fixture.dispose(); }); describe("detectProtocol", () => { it("picks the function with the most distinct awaited collaborator calls", () => { expect(detectProtocol(fixture.analysis)).toStrictEqual({ messages: [ { async: true, text: "charge", to: "gateway" }, { async: true, text: "store", to: "vault" }, ], participants: ["gateway", "vault"], self: "processPayment", }); }); });