feat: add MCP-guided browser login

This commit is contained in:
nac
2026-08-20 04:09:07 +00:00
parent c7e62d1d6d
commit 7cc521938f
17 changed files with 638 additions and 88 deletions
+52
View File
@@ -19,6 +19,9 @@ test("package, manifest, and runtime versions agree with commit-pinned installat
assert.equal(manifest.distribution.releaseRef, undefined);
assert.equal(manifest.installation.temporarySourceArchiveBuild, true);
assert.equal(manifest.installation.fallbackToRelease, false);
assert.equal(manifest.entrypoints.guidedCommand, "client-config");
assert.equal(manifest.entrypoints.mcpLoginTool, "nocobase_login");
assert.equal(manifest.entrypoints.mcpLoginStatusTool, "nocobase_login_status");
assert.deepEqual(packageJson.dependencies, undefined);
assert.equal(manifest.runtime.runtimeNpmDependencies, 0);
});
@@ -34,8 +37,11 @@ test("installation protocol resolves main once and never falls back to an old Re
assert.match(guide, /archive\/<commit-sha>\.tar\.gz/);
assert.match(guide, /Windows 使用 `.zip`/);
assert.match(guide, /不得.*退回旧 Release/);
assert.match(guide, /client-config --json/);
assert.match(guide, /nocobase_login\(\{\}\)/);
assert.ok(guide.includes(installUrl));
assert.ok(readme.includes(installUrl));
assert.match(readme, /nocobase_login/);
assert.doesNotMatch(guide, /下载本文件所在的同一固定 Release/);
assert.doesNotMatch(readme, /<main 分支的 INSTALL\.md 链接>/);
});
@@ -64,6 +70,52 @@ test("manual Key fallback refuses a non-TTY before creating credential files", a
}
});
test("setup rejects a missing explicit config before starting browser authorization", async () => {
const directory = mkdtempSync(join(tmpdir(), "nocobase-mcp-setup-preflight-"));
const credentials = join(directory, "credentials.json");
const missingConfig = join(directory, "missing-config.json");
const previousCredentials = process.env.NOCOBASE_MCP_CREDENTIALS;
process.env.NOCOBASE_MCP_CREDENTIALS = credentials;
try {
await assert.rejects(
runCli(["setup", "--config", missingConfig, "--no-browser", "--json"]),
/Config file does not exist/,
);
assert.equal(existsSync(credentials), false);
} finally {
if (previousCredentials === undefined) delete process.env.NOCOBASE_MCP_CREDENTIALS;
else process.env.NOCOBASE_MCP_CREDENTIALS = previousCredentials;
}
});
test("client-config prepares the bundled default config before login", async () => {
const directory = mkdtempSync(join(tmpdir(), "nocobase-mcp-client-config-"));
const credentials = join(directory, "credentials.json");
const config = join(directory, "config.json");
const previousCredentials = process.env.NOCOBASE_MCP_CREDENTIALS;
const previousConfig = process.env.NOCOBASE_MCP_CONFIG;
const originalWrite = process.stdout.write;
let output = "";
process.env.NOCOBASE_MCP_CREDENTIALS = credentials;
delete process.env.NOCOBASE_MCP_CONFIG;
process.stdout.write = ((chunk: string | Uint8Array) => {
output += String(chunk);
return true;
}) as typeof process.stdout.write;
try {
await runCli(["client-config", "--json"]);
assert.equal(existsSync(config), true);
assert.equal(existsSync(credentials), false);
assert.equal(JSON.parse(output).mcpServers["nocobase-crm"].args.includes("--config"), true);
} finally {
process.stdout.write = originalWrite;
if (previousCredentials === undefined) delete process.env.NOCOBASE_MCP_CREDENTIALS;
else process.env.NOCOBASE_MCP_CREDENTIALS = previousCredentials;
if (previousConfig === undefined) delete process.env.NOCOBASE_MCP_CONFIG;
else process.env.NOCOBASE_MCP_CONFIG = previousConfig;
}
});
test("setup rejects API endpoint overrides", async () => {
await assert.rejects(
runCli(["setup", "--api-base-url", "https://other.example"]),