Files
tutti/packages/agent/gui/agentActivityRuntime.origin.spec.tsx
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

68 lines
2.0 KiB
TypeScript

import { cleanup, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it } from "vitest";
import {
AgentGUIRuntimeProvider,
resetAgentGUIRuntimeForTests,
useAgentGUIRuntime,
type AgentGUIRuntime
} from "./agentActivityRuntime";
function createRuntime(origin: string): AgentGUIRuntime {
return { origin } as unknown as AgentGUIRuntime;
}
function RuntimeIdentity({ testId }: { testId: string }) {
const runtime = useAgentGUIRuntime();
return <div data-testid={testId}>{runtime.origin}</div>;
}
afterEach(() => {
cleanup();
resetAgentGUIRuntimeForTests();
});
describe("AgentGUIRuntimeProvider identity isolation", () => {
it("resolves coexisting runtimes only from the nearest provider", () => {
render(
<>
<AgentGUIRuntimeProvider runtime={createRuntime("origin-local")}>
<RuntimeIdentity testId="local-runtime" />
</AgentGUIRuntimeProvider>
<AgentGUIRuntimeProvider runtime={createRuntime("origin-shared")}>
<RuntimeIdentity testId="shared-runtime" />
</AgentGUIRuntimeProvider>
</>
);
expect(screen.getByTestId("local-runtime")).toHaveTextContent(
"origin-local"
);
expect(screen.getByTestId("shared-runtime")).toHaveTextContent(
"origin-shared"
);
});
it("does not let a later sibling provider replace an existing consumer", () => {
const view = render(
<AgentGUIRuntimeProvider runtime={createRuntime("origin-local")}>
<RuntimeIdentity testId="local-runtime" />
</AgentGUIRuntimeProvider>
);
view.rerender(
<>
<AgentGUIRuntimeProvider runtime={createRuntime("origin-local")}>
<RuntimeIdentity testId="local-runtime" />
</AgentGUIRuntimeProvider>
<AgentGUIRuntimeProvider runtime={createRuntime("origin-shared")}>
<RuntimeIdentity testId="shared-runtime" />
</AgentGUIRuntimeProvider>
</>
);
expect(screen.getByTestId("local-runtime")).toHaveTextContent(
"origin-local"
);
});
});