Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

9.2 KB
Raw Blame
const test = require("node:test");
const assert = require("node:assert/strict");

const load = () => import("../../src/utils/llmTranscript.ts");

const t = (key, options) => {
  if (key === "notes.speaker.label") return `Speaker ${options.n}`;
  if (key === "notes.speaker.them") return "Them";
  if (key === "notes.speaker.you") return "You";
  return key;
};

const attendee = (email, displayName, self = false) => ({
  email,
  displayName,
  responseStatus: null,
  self,
});

test("mic segments carry the note owner's label", async () => {
  const { resolveLlmSpeakerLabel } = await load();
  assert.equal(
    resolveLlmSpeakerLabel({ source: "mic", text: "hi" }, {}, "Gabriel Stein", t),
    "Gabriel Stein"
  );
  assert.equal(
    resolveLlmSpeakerLabel(
      { source: "system", speaker: "you", text: "hi" },
      {},
      "Gabriel Stein",
      t
    ),
    "Gabriel Stein"
  );
});

test("manual speaker corrections override the microphone's assumed note owner", async () => {
  const { resolveLlmSpeakerLabel } = await load();
  for (const speaker of ["speaker_0", "you"]) {
    const segment = {
      source: "mic",
      speaker,
      speakerName: "Ravi Patel",
      speakerLocked: true,
      speakerStatus: "locked",
      speakerLockSource: "user",
      speakerIsPlaceholder: false,
      text: "I will send the proposal.",
    };
    assert.equal(
      resolveLlmSpeakerLabel(segment, { [speaker]: "Old name" }, "Casey", t),
      "Ravi Patel"
    );
  }
});

test("a renamed microphone cluster reaches note generation without per-segment names", async () => {
  const { buildLlmTranscript } = await load();
  const segment = {
    source: "mic",
    speaker: "speaker_0",
    timestamp: 123,
    speakerStatus: "confirmed",
    speakerIsPlaceholder: false,
    speakerLocked: false,
    text: "I will send the proposal.",
  };
  assert.equal(
    buildLlmTranscript([segment], { speaker_0: "Ravi Patel" }, "Casey", t),
    "Ravi Patel: I will send the proposal."
  );
  assert.equal(
    buildLlmTranscript([segment], {}, "Casey", t),
    "Speaker 1: I will send the proposal."
  );
  assert.equal(
    buildLlmTranscript([segment], { speaker_0: " you " }, "Casey", t),
    "Casey: I will send the proposal."
  );
});

test("an in-person meeting's diarized mic clusters keep their speaker numbers", async () => {
  const { buildLlmTranscript, resolveLlmSpeakerLabel } = await load();
  const segments = [
    { source: "mic", speaker: "speaker_0", text: "Can you send the proposal?" },
    { source: "mic", speaker: "speaker_1", text: "I will send it today." },
    { source: "mic", speaker: "you", text: "Thanks." },
    { source: "mic", text: "Before diarization." },
  ];
  assert.equal(
    buildLlmTranscript(segments, {}, "Casey", t),
    [
      "Speaker 1: Can you send the proposal?",
      "Speaker 2: I will send it today.",
      "Casey: Thanks.",
      "Casey: Before diarization.",
    ].join("\n")
  );
  assert.equal(
    resolveLlmSpeakerLabel(segments[1], { speaker_1: "Ravi Patel" }, "Casey", t),
    "Ravi Patel"
  );
});

test("system segments resolve name → mapping → Speaker N → Them", async () => {
  const { resolveLlmSpeakerLabel } = await load();
  const locked = {
    source: "system",
    speaker: "speaker_0",
    speakerName: "Michael",
    speakerLocked: true,
    text: "hi",
  };
  assert.equal(resolveLlmSpeakerLabel(locked, { speaker_0: "Wrong" }, "You", t), "Michael");
  assert.equal(
    resolveLlmSpeakerLabel(
      { source: "system", speaker: "speaker_1", text: "hi" },
      { speaker_1: "Sean" },
      "You",
      t
    ),
    "Sean"
  );
  assert.equal(
    resolveLlmSpeakerLabel({ source: "system", speaker: "speaker_2", text: "hi" }, {}, "You", t),
    "Speaker 3"
  );
  assert.equal(resolveLlmSpeakerLabel({ source: "system", text: "hi" }, {}, "You", t), "Them");
});

test("buildLlmTranscript prefixes every line with the resolved label", async () => {
  const { buildLlmTranscript } = await load();
  const segments = [
    { source: "mic", text: "Morning everyone" },
    { source: "system", speaker: "speaker_0", text: "Morning" },
  ];
  assert.equal(
    buildLlmTranscript(segments, { speaker_0: "Michael" }, "Gabriel", t),
    "Gabriel: Morning everyone\nMichael: Morning"
  );
});

test("buildMeetingContext names the owner and invited participants", async () => {
  const { buildMeetingContext } = await load();
  const identity = {
    selfName: "Gabriel Stein",
    selfEmail: "[email protected]",
    participants: [
      attendee("[email protected]", "Gabriel Stein", true),
      attendee("[email protected]", "Michael Chen"),
      attendee("[email protected]", null),
    ],
  };
  assert.equal(
    buildMeetingContext(identity, "Gabriel Stein"),
    [
      "## Meeting Context",
      'The user taking these notes ("Gabriel Stein" in the transcript) is Gabriel Stein <[email protected]>.',
      "Invited participants: Michael Chen <[email protected]>, [email protected].",
    ].join("\n")
  );
});

test("buildMeetingContext omits what it does not know", async () => {
  const { buildMeetingContext } = await load();
  assert.equal(
    buildMeetingContext({ selfName: null, selfEmail: null, participants: [] }, "You"),
    ""
  );
  assert.equal(
    buildMeetingContext(
      { selfName: null, selfEmail: null, participants: [attendee("[email protected]", "Ada")] },
      "You"
    ),
    "## Meeting Context\nInvited participants: Ada <[email protected]>."
  );
});

test("collectKnownPeople merges owner, participants, mappings, and named segments", async () => {
  const { collectKnownPeople } = await load();
  const people = collectKnownPeople(
    {
      selfName: "Gabriel Stein",
      selfEmail: "[email protected]",
      participants: [
        attendee("[email protected]", "Gabriel Stein", true),
        attendee("[email protected]", "Michael Chen"),
        attendee("[email protected]", null),
      ],
    },
    { speaker_0: "Michael Chen", speaker_1: "Priya" },
    [{ source: "system", speaker: "speaker_2", speakerName: "Ada", text: "hi" }]
  );
  assert.deepEqual(people, [
    { name: "Gabriel Stein", email: "[email protected]" },
    { name: "Michael Chen", email: "[email protected]" },
    { name: "sean", email: "[email protected]" },
    { name: "Priya", email: null },
    { name: "Ada", email: null },
  ]);
});

test("collectKnownPeople keeps same-name attendees with different email identities", async () => {
  const { collectKnownPeople } = await load();
  const participants = [
    attendee("[email protected]", "Alex Morgan"),
    attendee("[email protected]", "Alex Morgan"),
    attendee("[email protected]", "Alex Morgan"),
  ];
  const people = collectKnownPeople(
    { selfName: "Casey", selfEmail: "[email protected]", participants },
    { speaker_0: "Alex Morgan" },
    [{ source: "system", speakerName: "Alex Morgan", text: "I will send the proposal." }]
  );
  assert.deepEqual(people, [
    { name: "Casey", email: "[email protected]" },
    { name: "Alex Morgan", email: "[email protected]" },
    { name: "Alex Morgan", email: "[email protected]" },
  ]);
});

test("first-name owners resolve to a unique attendee while explicit short labels retain their identity", async () => {
  const { collectKnownPeople } = await load();
  const { tagActionItemOwners } = await import("../../src/utils/mentionMarkdown.ts");
  const identity = {
    selfName: null,
    selfEmail: null,
    participants: [attendee("[email protected]", "Ravi Patel")],
  };
  const line = "- [ ] Send the proposal — Ravi";
  assert.equal(
    tagActionItemOwners(line, collectKnownPeople(identity, { speaker_0: "Ravi Patel" }, [])),
    "- [ ] Send the proposal — [@Ravi Patel](mention:ravi%40example.test)"
  );
  assert.equal(
    tagActionItemOwners(line, collectKnownPeople(identity, { speaker_0: " Ravi  Patel " }, [])),
    "- [ ] Send the proposal — [@Ravi Patel](mention:ravi%40example.test)"
  );
  // A name-only label is not evidence that it belongs to the similarly named invitee.
  assert.equal(
    tagActionItemOwners(line, collectKnownPeople(identity, { speaker_0: "Ravi" }, [])),
    "- [ ] Send the proposal — [@Ravi](mention:Ravi)"
  );
});

test("an owner without an email stays distinct from a same-name invitee", async () => {
  const { collectKnownPeople } = await load();
  const { tagActionItemOwners } = await import("../../src/utils/mentionMarkdown.ts");
  const people = collectKnownPeople(
    {
      selfName: "Alex Morgan",
      selfEmail: null,
      participants: [attendee("[email protected]", "Alex Morgan")],
    },
    {},
    []
  );
  assert.deepEqual(people, [
    { name: "Alex Morgan", email: null },
    { name: "Alex Morgan", email: "[email protected]" },
  ]);
  const line = "- [ ] Send the proposal — Alex Morgan";
  assert.equal(tagActionItemOwners(line, people), line);
});

test("a You saved in another UI language still labels the note owner", async () => {
  const { resolveLlmSpeakerLabel } = await load();
  const german = (key, options) => (key === "notes.speaker.you" ? "Du" : t(key, options));
  const segment = { source: "mic", speaker: "speaker_0", text: "hi" };
  assert.equal(resolveLlmSpeakerLabel(segment, { speaker_0: "You" }, "Casey", german), "Casey");
  assert.equal(resolveLlmSpeakerLabel(segment, { speaker_0: "Du" }, "Casey", german), "Casey");
});