-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathai.spec.ts
More file actions
33 lines (29 loc) · 1.18 KB
/
Copy pathai.spec.ts
File metadata and controls
33 lines (29 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { describe, expect, it, vi } from "vitest";
import { buildSystemPrompt, type AiContext } from "@/lib/ai";
// buildSystemPrompt switches copy by currentLocale(); pin it to English so the assertions below
// (which check the English prompt text) are stable regardless of the host locale.
vi.mock("@/i18n", async (importOriginal) => {
const actual = await importOriginal<typeof import("@/i18n")>();
return { ...actual, currentLocale: () => "en" };
});
function context(overrides: Partial<AiContext> = {}): AiContext {
return {
connectionId: "conn-1",
connectionName: "Postgres",
databaseType: "postgres",
database: "app",
currentSql: "",
tables: [],
truncated: false,
...overrides,
};
}
describe("AI SQL dialect prompt", () => {
it("pins identifier quoting to the active database type", () => {
const prompt = buildSystemPrompt("generate", context(), "ask");
expect(prompt).toContain("Database type: postgres");
expect(prompt).toContain("PostgreSQL/SQLite/Oracle");
expect(prompt).toContain('double quotes "name"');
expect(prompt).toContain("Do not switch dialects merely because the user mentions another database in prose.");
});
});