41 lines
2.3 KiB
JavaScript
41 lines
2.3 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { INTERNAL_TOOL_DEFINITIONS, TOOL_DEFINITIONS } from "../src/tool-definitions.js";
|
|
|
|
test("the internal tools are the four operations, with no session to open or name", () => {
|
|
assert.deepEqual(INTERNAL_TOOL_DEFINITIONS.map((tool) => tool.name),
|
|
["postgres_query", "postgres_execute", "postgres_list_tables", "postgres_describe_table"]);
|
|
for (const tool of INTERNAL_TOOL_DEFINITIONS) {
|
|
assert.ok(!("postgresSessionId" in tool.inputSchema.properties), tool.name);
|
|
assert.ok(!tool.inputSchema.required.includes("postgresSessionId"), tool.name);
|
|
assert.equal(tool.inputSchema.additionalProperties, false);
|
|
}
|
|
});
|
|
|
|
test("in the external mode the model gives the credentials, never where to connect nor which database", () => {
|
|
const open = TOOL_DEFINITIONS.find((tool) => tool.name === "postgres_open_session");
|
|
assert.deepEqual(Object.keys(open.inputSchema.properties), ["user", "password", "sslmode"]);
|
|
assert.deepEqual(open.inputSchema.required, ["user", "password"]);
|
|
assert.match(open.description, /host, port and database are already fixed/);
|
|
});
|
|
|
|
test("the external tools open and close a session and name it in every operation", () => {
|
|
const names = TOOL_DEFINITIONS.map((tool) => tool.name);
|
|
assert.deepEqual(names.slice(0, 2), ["postgres_open_session", "postgres_close_session"]);
|
|
for (const tool of TOOL_DEFINITIONS.slice(2)) {
|
|
assert.ok(tool.inputSchema.required.includes("postgresSessionId"), tool.name);
|
|
}
|
|
});
|
|
|
|
// A small model has only these words to go on: it must be told to bind values, to look before it writes,
|
|
// and what a truncated answer means.
|
|
test("the descriptions tell a model how to use them", () => {
|
|
const byName = Object.fromEntries(INTERNAL_TOOL_DEFINITIONS.map((tool) => [tool.name, tool]));
|
|
assert.match(byName.postgres_query.inputSchema.properties.statement.description, /\$1, \$2/);
|
|
assert.match(byName.postgres_query.inputSchema.properties.statement.description, /never put a value into the text/);
|
|
assert.match(byName.postgres_query.description, /truncated/);
|
|
assert.match(byName.postgres_list_tables.description, /first/);
|
|
assert.match(byName.postgres_execute.description, /CREATE TABLE/);
|
|
assert.match(byName.postgres_query.description, /^In this execution's own database/);
|
|
});
|