mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:10:45 +00:00
test(matrix): share onboarding env shortcut helpers
This commit is contained in:
@@ -90,6 +90,15 @@ export function createMatrixWizardPrompter(params: {
|
||||
} as unknown as WizardPrompter;
|
||||
}
|
||||
|
||||
export function installMatrixScopedEnvShortcut() {
|
||||
process.env.MATRIX_HOMESERVER = "https://matrix.env.example.org";
|
||||
process.env.MATRIX_USER_ID = "@env:example.org";
|
||||
process.env.MATRIX_PASSWORD = "env-password"; // pragma: allowlist secret
|
||||
process.env.MATRIX_ACCESS_TOKEN = "";
|
||||
process.env.MATRIX_OPS_HOMESERVER = "https://matrix.ops.env.example.org";
|
||||
process.env.MATRIX_OPS_ACCESS_TOKEN = "ops-env-token";
|
||||
}
|
||||
|
||||
export async function runMatrixInteractiveConfigure(params: {
|
||||
cfg: CoreConfig;
|
||||
prompter: WizardPrompter;
|
||||
@@ -206,6 +215,29 @@ export function createMatrixTokenAddAccountPrompter(params?: {
|
||||
});
|
||||
}
|
||||
|
||||
export function createMatrixEnvShortcutAddAccountPrompter(params?: {
|
||||
notes?: string[];
|
||||
select?: Record<string, string>;
|
||||
text?: Record<string, string>;
|
||||
confirm?: Record<string, boolean>;
|
||||
onConfirm?: PromptHandler<boolean | Promise<boolean>>;
|
||||
}) {
|
||||
return createMatrixWizardPrompter({
|
||||
...(params?.notes ? { notes: params.notes } : {}),
|
||||
select: {
|
||||
"Matrix already configured. What do you want to do?": "add-account",
|
||||
"Matrix auth method": "token",
|
||||
...params?.select,
|
||||
},
|
||||
text: {
|
||||
"Matrix account name": "ops",
|
||||
...params?.text,
|
||||
},
|
||||
...(params?.confirm ? { confirm: params.confirm } : {}),
|
||||
...(params?.onConfirm ? { onConfirm: params.onConfirm } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
export function createConfiguredMatrixTopLevelConfig(params?: {
|
||||
homeserver?: string;
|
||||
accessToken?: string | { source: "env"; provider: "default"; id: string };
|
||||
|
||||
@@ -3,8 +3,10 @@ import { matrixOnboardingAdapter } from "./onboarding.js";
|
||||
import {
|
||||
createConfiguredMatrixDefaultAccountConfig,
|
||||
createConfiguredMatrixTopLevelConfig,
|
||||
createMatrixEnvShortcutAddAccountPrompter,
|
||||
createMatrixNamedAccountsConfig,
|
||||
createLegacyMatrixTopLevelConfig,
|
||||
installMatrixScopedEnvShortcut,
|
||||
createMatrixTokenAddAccountPrompter,
|
||||
createMatrixUpdateKeepCredentialsPrompter,
|
||||
installMatrixOnboardingEnvRestoreHooks,
|
||||
@@ -25,23 +27,10 @@ describe("matrix onboarding", () => {
|
||||
|
||||
it("offers env shortcut for non-default account when scoped env vars are present", async () => {
|
||||
installMatrixTestRuntime();
|
||||
|
||||
process.env.MATRIX_HOMESERVER = "https://matrix.env.example.org";
|
||||
process.env.MATRIX_USER_ID = "@env:example.org";
|
||||
process.env.MATRIX_PASSWORD = "env-password"; // pragma: allowlist secret
|
||||
process.env.MATRIX_ACCESS_TOKEN = "";
|
||||
process.env.MATRIX_OPS_HOMESERVER = "https://matrix.ops.env.example.org";
|
||||
process.env.MATRIX_OPS_ACCESS_TOKEN = "ops-env-token";
|
||||
installMatrixScopedEnvShortcut();
|
||||
|
||||
const confirmMessages: string[] = [];
|
||||
const prompter = createMatrixWizardPrompter({
|
||||
select: {
|
||||
"Matrix already configured. What do you want to do?": "add-account",
|
||||
"Matrix auth method": "token",
|
||||
},
|
||||
text: {
|
||||
"Matrix account name": "ops",
|
||||
},
|
||||
const prompter = createMatrixEnvShortcutAddAccountPrompter({
|
||||
onConfirm: (message) => {
|
||||
confirmMessages.push(message);
|
||||
return message.startsWith("Matrix env vars detected");
|
||||
@@ -82,24 +71,16 @@ describe("matrix onboarding", () => {
|
||||
|
||||
it("routes env-shortcut add-account flow through Matrix invite auto-join setup", async () => {
|
||||
installMatrixTestRuntime();
|
||||
|
||||
process.env.MATRIX_HOMESERVER = "https://matrix.env.example.org";
|
||||
process.env.MATRIX_USER_ID = "@env:example.org";
|
||||
process.env.MATRIX_PASSWORD = "env-password"; // pragma: allowlist secret
|
||||
process.env.MATRIX_ACCESS_TOKEN = "";
|
||||
process.env.MATRIX_OPS_HOMESERVER = "https://matrix.ops.env.example.org";
|
||||
process.env.MATRIX_OPS_ACCESS_TOKEN = "ops-env-token";
|
||||
installMatrixScopedEnvShortcut();
|
||||
|
||||
const notes: string[] = [];
|
||||
const prompter = createMatrixWizardPrompter({
|
||||
const prompter = createMatrixEnvShortcutAddAccountPrompter({
|
||||
notes,
|
||||
select: {
|
||||
"Matrix already configured. What do you want to do?": "add-account",
|
||||
"Matrix rooms access": "allowlist",
|
||||
"Matrix invite auto-join": "allowlist",
|
||||
},
|
||||
text: {
|
||||
"Matrix account name": "ops",
|
||||
"Matrix rooms allowlist (comma-separated)": "!ops-room:example.org",
|
||||
"Matrix invite auto-join allowlist (comma-separated)": "#ops-invites:example.org",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user