Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

promptLinks.test.ts

79 lines2.8 KB

1import {
2 ProviderDriverKind,
3 ProviderInstanceId,
4 type RepositoryIdentity,
5} from "@t3tools/contracts";
6import { describe, expect, it } from "vite-plus/test";
7​
8import { findPromptLinkProject, resolvePromptLinkModelSelection } from "./promptLinks.ts";
9​
10const identity = (canonicalKey: string, origin?: string): RepositoryIdentity => ({
11 canonicalKey,
12 locator: { source: "git-remote", remoteName: "origin", remoteUrl: `https://${canonicalKey}` },
13 ...(origin ? { origin: { canonicalKey: origin } } : {}),
14});
15​
16describe("findPromptLinkProject", () => {
17 it("takes the first exact match and never a fork of the repository", () => {
18 const projects = [
19 {
20 id: "fork",
21 repositoryIdentity: identity("github.com/pingdotgg/t3code", "github.com/me/t3code"),
22 },
23 { id: "none", repositoryIdentity: null },
24 { id: "recent", repositoryIdentity: identity("github.com/PingDotGG/T3Code") },
25 { id: "older", repositoryIdentity: identity("github.com/pingdotgg/t3code") },
26 ];
27 expect(findPromptLinkProject(projects, { owner: "pingdotgg", name: "t3code" })?.id).toBe(
28 "recent",
29 );
30 expect(findPromptLinkProject(projects, { owner: "me", name: "t3code" })?.id).toBe("fork");
31 expect(findPromptLinkProject(projects, { owner: "gitlab", name: "x" })).toBeUndefined();
32 });
33});
34​
35describe("resolvePromptLinkModelSelection", () => {
36 const provider = (
37 instanceId: string,
38 driver: string,
39 status: "ready" | "warning" | "error" | "disabled" = "ready",
40 ) => ({
41 instanceId: ProviderInstanceId.make(instanceId),
42 driver: ProviderDriverKind.make(driver),
43 enabled: true,
44 status,
45 models: [
46 { slug: "small", name: "Small" },
47 { slug: "big", name: "Big", aliases: ["opus"], isDefault: true },
48 ],
49 });
50​
51 it("maps the requested provider and model onto a usable instance", () => {
52 const providers = [provider("broken", "claudeAgent", "error"), provider("work", "claudeAgent")];
53 expect(
54 resolvePromptLinkModelSelection(providers, { provider: "claude", model: "small" }),
55 ).toEqual({
56 selection: { instanceId: "work", model: "small" },
57 exact: true,
58 });
59 expect(
60 resolvePromptLinkModelSelection(providers, { provider: "claudeagent", model: "opus" }),
61 ).toEqual({
62 selection: { instanceId: "work", model: "big" },
63 exact: true,
64 });
65 });
66​
67 it("uses the instance default for an unknown model, and nothing for a missing provider", () => {
68 const providers = [provider("codex", "codex")];
69 expect(
70 resolvePromptLinkModelSelection(providers, { provider: "codex", model: "nope" }),
71 ).toEqual({
72 selection: { instanceId: "codex", model: "big" },
73 exact: false,
74 });
75 expect(
76 resolvePromptLinkModelSelection(providers, { provider: "cursor", model: null }),
77 ).toBeNull();
78 });
79});