49 lines
2.1 KiB
TypeScript
49 lines
2.1 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { existsSync, mkdtempSync, readFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import test from "node:test";
|
|
import { clientConfig, runCli } from "../src/cli.js";
|
|
import { VERSION } from "../src/version.js";
|
|
|
|
test("package, manifest, and runtime versions agree with no runtime npm dependencies", () => {
|
|
const packageJson = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
const manifest = JSON.parse(readFileSync(new URL("../install-manifest.json", import.meta.url), "utf8"));
|
|
assert.equal(VERSION, "0.3.1");
|
|
assert.equal(packageJson.version, VERSION);
|
|
assert.equal(manifest.version, VERSION);
|
|
assert.deepEqual(packageJson.dependencies, undefined);
|
|
assert.equal(manifest.runtime.runtimeNpmDependencies, 0);
|
|
});
|
|
|
|
test("generated MCP config contains no Key, token, or environment secret", () => {
|
|
const config = clientConfig("/private/config.json", false);
|
|
const serialized = JSON.stringify(config);
|
|
assert.match(serialized, /nocobase-crm/);
|
|
assert.match(serialized, /config\.json/);
|
|
assert.doesNotMatch(serialized, /authorize|token|secret|password/i);
|
|
});
|
|
|
|
test("setup refuses a non-TTY before creating credential files", async () => {
|
|
if (process.stdin.isTTY || process.stderr.isTTY) return;
|
|
const directory = mkdtempSync(join(tmpdir(), "nocobase-mcp-nontty-"));
|
|
const path = join(directory, "credentials.json");
|
|
const previous = process.env.NOCOBASE_MCP_CREDENTIALS;
|
|
process.env.NOCOBASE_MCP_CREDENTIALS = path;
|
|
try {
|
|
await assert.rejects(runCli(["setup", "--json"]), /local terminal/);
|
|
assert.equal(existsSync(path), false);
|
|
assert.equal(existsSync(join(directory, "config.json")), false);
|
|
} finally {
|
|
if (previous === undefined) delete process.env.NOCOBASE_MCP_CREDENTIALS;
|
|
else process.env.NOCOBASE_MCP_CREDENTIALS = previous;
|
|
}
|
|
});
|
|
|
|
test("setup rejects API endpoint overrides", async () => {
|
|
await assert.rejects(
|
|
runCli(["setup", "--api-base-url", "https://other.example"]),
|
|
/Unknown option: --api-base-url/,
|
|
);
|
|
});
|