Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/commands/credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ describe("credentials oclif adapter source coverage", () => {
"tavily-hermes-v1",
"--from-existing",
],
["provider", "profile", "-g", "nemoclaw", "export", "tavily-hermes-v1", "--output", "json"],
]);
} finally {
log.mockRestore();
Expand Down
9 changes: 7 additions & 2 deletions src/lib/actions/sandbox/mcp-bridge-add-restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
waitForAttachedMcpCredential,
waitForDetachedMcpCredential,
} from "./mcp-bridge-provider";
import { createMcpProviderAdapterBoundary } from "./mcp-bridge-provider-inspection";
import {
assertNoAmbiguousMcpCredentialTarget,
assertNoAmbiguousMcpCredentialTargets,
Expand Down Expand Up @@ -900,7 +901,8 @@ async function addMcpBridgeUnlocked(
// supplied by a foreign attachment before opening its MCP route, then check
// again after provider creation to close the intervening race.
await assertNoProviderCredentialCollisions(sandboxName, [entry], providerRuntimeSelection);
await ensureMcpBridgeProviderProfile(providerRuntimeSelection);
const providerAdapter = createMcpProviderAdapterBoundary(providerRuntimeSelection).adapter;
await ensureMcpBridgeProviderProfile(providerRuntimeSelection, providerAdapter);
// Load the real protocol:mcp policy without a credential binding before
// provider mutation. OpenShell requires the endpointless provider to be
// attached before it accepts credential_binding.provider, and withholds
Expand All @@ -919,6 +921,7 @@ async function addMcpBridgeUnlocked(
allowExisting: recovery.resuming,
expectedProviderId: entry.providerId,
runtimeSelection: providerRuntimeSelection,
providerAdapter,
prepareMutation: async (action) => {
// A fresh create has no prior revision to compare. Observe only the
// bounded placeholder classification for an actual update, after the
Expand Down Expand Up @@ -950,7 +953,7 @@ async function addMcpBridgeUnlocked(
}
if (!recovery.attachmentPresent) {
providerAttachAttempted = true;
await attachProvider(sandboxName, entry, providerRuntimeSelection);
await attachProvider(sandboxName, entry, providerRuntimeSelection, providerAdapter);
}
if (recovery.policyState !== "bound") {
await applyGeneratedPolicy(sandboxName, entry, target, {
Expand Down Expand Up @@ -993,6 +996,7 @@ async function addMcpBridgeUnlocked(
expectedProviderId: entry.providerId,
requireExisting: true,
runtimeSelection: providerRuntimeSelection,
providerAdapter,
});
if (republished.action !== "updated") {
await refreshMcpProviderEnvironment(entry, providerRuntimeSelection);
Expand All @@ -1012,6 +1016,7 @@ async function addMcpBridgeUnlocked(
expectedProviderId: entry.providerId,
requireExisting: true,
runtimeSelection: providerRuntimeSelection,
providerAdapter,
});
credentialRevision = await waitForAttachedMcpCredential(
sandboxName,
Expand Down
19 changes: 16 additions & 3 deletions src/lib/actions/sandbox/mcp-bridge-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { buildMcpCredentialRevisionObservationCommand } from "./mcp-bridge";
import {
assertNoAttachedProviderCredentialCollisions,
assertNoRegisteredProviderCredentialCollisions,
createMcpProviderAdapterBoundary,
providerMatchesCredential,
providerMatchesManagedCredential,
} from "./mcp-bridge-provider-inspection";
Expand Down Expand Up @@ -194,7 +195,9 @@ describe("OpenShell MCP provider state", () => {
const commandFamilies = new Set<string>();
let providerExists = false;
let providerAttached = false;
let profileChanged = false;
let resourceVersion = 0;
const warn = vi.spyOn(console, "warn").mockImplementation(() => undefined);
const providerOutput = () =>
providerMetadataOutput(
"alpha-mcp-fake",
Expand Down Expand Up @@ -228,7 +231,7 @@ describe("OpenShell MCP provider state", () => {
commandFamilies.add("profile");
return {
status: 0,
stdout: profileOutput(args[3], args[3] === "openai"),
stdout: profileOutput(args[3], profileChanged),
stderr: "",
};
case "provider get alpha-mcp-fake":
Expand All @@ -239,6 +242,7 @@ describe("OpenShell MCP provider state", () => {
case "provider create --name":
commandFamilies.add("create");
providerExists = true;
profileChanged = true;
resourceVersion = 1;
return { status: 0, stdout: "Created", stderr: "" };
case "provider update alpha-mcp-fake":
Expand Down Expand Up @@ -284,11 +288,18 @@ describe("OpenShell MCP provider state", () => {
});
providerCommand.setProviderCommandRuntimeHooksForTest({ runOpenshell: runOpenshell as never });

await ensureMcpBridgeProviderProfile(runtimeSelection);
const providerAdapter = createMcpProviderAdapterBoundary(runtimeSelection).adapter;
await ensureMcpBridgeProviderProfile(runtimeSelection, providerAdapter);
const created = await upsertMcpProvider("alpha-mcp-fake", [{ name: "EXPECTED_TOKEN" }], {
allowExisting: false,
runtimeSelection,
providerAdapter,
});
expect(warn).toHaveBeenCalledOnce();
expect(warn.mock.calls[0]?.[0]).toContain(
"cannot confirm which definition was used at bind time",
);
expect(warn.mock.calls[0]?.[0]).not.toContain("host-only-secret");
const entry: McpSourceEntry = {
server: "fake",
agent: "openclaw",
Expand All @@ -299,7 +310,9 @@ describe("OpenShell MCP provider state", () => {
providerId: created.inspection.id ?? undefined,
policyName: "mcp-bridge-fake",
};
await attachProvider("alpha", entry, runtimeSelection);
await attachProvider("alpha", entry, runtimeSelection, providerAdapter);
expect(warn).toHaveBeenCalledTimes(2);
expect(warn.mock.calls[1]?.[0]).not.toContain("host-only-secret");
await refreshMcpProviderEnvironment(entry, runtimeSelection);
await expect(detachProvider("alpha", entry, { runtimeSelection })).resolves.toBe("detached");

Expand Down
6 changes: 4 additions & 2 deletions src/lib/actions/sandbox/mcp-bridge-restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
preflightMcpEntryTargets,
waitForAttachedMcpCredential,
} from "./mcp-bridge-provider";
import { createMcpProviderAdapterBoundary } from "./mcp-bridge-provider-inspection";
import {
assertMcpAdapterMutationRuntimeCapabilities,
assertMcpAdapterTeardownRuntimeCapabilities,
Expand Down Expand Up @@ -260,7 +261,8 @@ export async function restoreExistingMcpBridgeRuntime(
[entry],
providerRuntimeSelection,
);
await ensureMcpBridgeProviderProfile(providerRuntimeSelection);
const providerAdapter = createMcpProviderAdapterBoundary(providerRuntimeSelection).adapter;
await ensureMcpBridgeProviderProfile(providerRuntimeSelection, providerAdapter);
if (options.applyPolicy !== false) {
await applyGeneratedPolicy(
sandboxName,
Expand All @@ -272,7 +274,7 @@ export async function restoreExistingMcpBridgeRuntime(
},
);
}
await attachProvider(sandboxName, entry, providerRuntimeSelection);
await attachProvider(sandboxName, entry, providerRuntimeSelection, providerAdapter);
if (options.applyPolicy !== false) {
await applyGeneratedPolicy(
sandboxName,
Expand Down
Loading