Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/source-architecture-budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"src/lib/name-validation.ts": 19,
"src/lib/onboard/gateway-binding.ts": 53,
"src/lib/runner.ts": 85,
"src/lib/security/redact.ts": 53,
"src/lib/security/redact.ts": 52,
"src/lib/state/mcp-lifecycle-lock.ts": 21,
"src/lib/state/onboard-session.ts": 35,
"src/lib/state/registry.ts": 97,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/messaging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ await planner.buildChannelAddPlanFromSandboxEntry({
```ts
MessagingSetupApplier.writePlanToEnv(plan);

MessagingSetupApplier.applyCredentialsAtOpenShell(plan, credentialOptions);
await MessagingSetupApplier.applyCredentialsAtOpenShell(plan, credentialOptions);
MessagingSetupApplier.applyPolicyAtOpenShell(plan, policyOptions);
await MessagingSetupApplier.applyPreEnableChecks(plan, hookOptions);
await MessagingSetupApplier.applyAgentConfigAtOpenShell(plan, configOptions);
Expand Down
167 changes: 167 additions & 0 deletions src/lib/messaging/applier/openshell-provider.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { describe, expect, it, vi } from "vitest";

import type { OpenShellProviderAdapter } from "../../adapters/openshell/provider-adapter";
import type { SandboxMessagingPlan } from "../manifest";
import { applyCredentialsAtOpenShell } from "./openshell-provider";

const TELEGRAM_PROVIDER = "demo-telegram-bridge";
const TELEGRAM_TOKEN = "123456:telegram-token";

function telegramPlan(): SandboxMessagingPlan {
return {
schemaVersion: 1,
sandboxName: "demo",
agent: "openclaw",
workflow: "onboard",
channels: [
{
channelId: "telegram",
displayName: "Telegram",
authMode: "token-paste",
active: true,
selected: true,
configured: true,
disabled: false,
inputs: [],
hooks: [],
},
],
disabledChannels: [],
credentialBindings: [
{
channelId: "telegram",
credentialId: "telegram-bot-token",
sourceInput: "bot-token",
providerName: TELEGRAM_PROVIDER,
providerEnvKey: "TELEGRAM_BOT_TOKEN",
placeholder: "openshell:resolve:env:TELEGRAM_BOT_TOKEN",
credentialAvailable: true,
},
],
networkPolicy: { presets: [], entries: [] },
agentRender: [],
buildSteps: [],
stateUpdates: [],
healthChecks: [],
};
}

describe("messaging OpenShell provider application", () => {
it.each([
{
label: "string output",
output: JSON.stringify({
id: "nemoclaw-mcp-v1",
credentials: [],
endpoints: [],
binaries: [],
inference_capable: false,
}),
},
{
label: "stdio array output",
output: [
null,
JSON.stringify({
id: "nemoclaw-mcp-v1",
credentials: [],
endpoints: [],
binaries: [],
inference_capable: false,
}),
"",
],
},
])("accepts a valid profile from legacy $label (#9806)", async ({ output }) => {
const result = await applyCredentialsAtOpenShell(telegramPlan(), {
env: {},
runOpenshell: (args) =>
args[1] === "profile"
? { status: 0, output }
: { status: 1, output: `provider '${TELEGRAM_PROVIDER}' not found` },
});

expect(result.missing).toEqual([expect.objectContaining({ providerName: TELEGRAM_PROVIDER })]);
});

it("makes provider decisions from typed adapter results (#9806)", async () => {
const getProvider = vi
.fn<OpenShellProviderAdapter["getProvider"]>()
.mockResolvedValueOnce({
ok: false,
error: {
kind: "command",
reason: "not_found",
message: "OpenShell provider was not found.",
},
})
.mockResolvedValueOnce({
ok: true,
value: {
name: TELEGRAM_PROVIDER,
type: "nemoclaw-mcp-v1",
credentialKeys: ["TELEGRAM_BOT_TOKEN"],
configKeys: [],
},
});
const createProvider = vi.fn<OpenShellProviderAdapter["createProvider"]>(async () => ({
ok: true,
value: { state: "created" },
}));
const providerAdapter = {
ensureEndpointlessProviderProfile: vi.fn(async () => ({
ok: true as const,
value: { state: "ready" as const },
})),
getProvider,
createProvider,
} as unknown as OpenShellProviderAdapter;

const result = await applyCredentialsAtOpenShell(telegramPlan(), {
env: { TELEGRAM_BOT_TOKEN: TELEGRAM_TOKEN },
providerAdapter,
});

expect(createProvider).toHaveBeenCalledWith({
target: { kind: "selected" },
name: TELEGRAM_PROVIDER,
type: "nemoclaw-mcp-v1",
credentials: [{ name: "TELEGRAM_BOT_TOKEN", value: TELEGRAM_TOKEN }],
config: [],
fromExisting: false,
});
expect(result.upserted).toEqual([
expect.objectContaining({ action: "create", providerName: TELEGRAM_PROVIDER }),
]);
expect(JSON.stringify(result)).not.toContain(TELEGRAM_TOKEN);
});

it("does not expose a rejected CLI runner through the typed boundary (#9806)", async () => {
const result = applyCredentialsAtOpenShell(telegramPlan(), {
env: { TELEGRAM_BOT_TOKEN: TELEGRAM_TOKEN },
runOpenshell: (args) =>
args[1] === "profile"
? {
status: 0,
stdout: JSON.stringify({
id: "nemoclaw-mcp-v1",
credentials: [],
endpoints: [],
binaries: [],
inference_capable: false,
}),
}
: (() => {
throw new Error(`untrusted runner diagnostic with ${TELEGRAM_TOKEN}`);
})(),
});

await expect(result).rejects.toThrow(
`Could not inspect messaging provider '${TELEGRAM_PROVIDER}'.`,
);
await expect(result).rejects.not.toThrow(/telegram-token/u);
});
});
Loading
Loading