-
Notifications
You must be signed in to change notification settings - Fork 303
refactor: extract shared buildSessionConfig to delete the SESSION_CONFIG drift point #712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { buildSessionConfig } from "./sandbox-env"; | ||
|
|
||
| const baseInput = { | ||
| sessionId: "session-123", | ||
| repoOwner: "testowner", | ||
| repoName: "testrepo", | ||
| provider: "anthropic", | ||
| model: "anthropic/claude-sonnet-4-5", | ||
| }; | ||
|
|
||
| describe("buildSessionConfig", () => { | ||
| it("maps provider inputs to the snake_case runtime contract", () => { | ||
| const mcpServers = [{ id: "mcp-1", name: "Tool", type: "local" as const, enabled: true }]; | ||
|
|
||
| expect(buildSessionConfig({ ...baseInput, branch: "feature/x", mcpServers })).toEqual({ | ||
| session_id: "session-123", | ||
| repo_owner: "testowner", | ||
| repo_name: "testrepo", | ||
| provider: "anthropic", | ||
| model: "anthropic/claude-sonnet-4-5", | ||
| mcp_servers: mcpServers, | ||
| branch: "feature/x", | ||
| }); | ||
| }); | ||
|
|
||
| it("omits branch when not provided", () => { | ||
| expect(buildSessionConfig(baseInput)).not.toHaveProperty("branch"); | ||
| }); | ||
|
|
||
| it("serializes to a SESSION_CONFIG that omits undefined mcp_servers", () => { | ||
| // With no MCP servers configured, the key must not appear in the serialized | ||
| // payload — the runtime treats an absent key and an empty list identically. | ||
| const parsed = JSON.parse(JSON.stringify(buildSessionConfig(baseInput))); | ||
|
|
||
| expect(parsed).toEqual({ | ||
| session_id: "session-123", | ||
| repo_owner: "testowner", | ||
| repo_name: "testrepo", | ||
| provider: "anthropic", | ||
| model: "anthropic/claude-sonnet-4-5", | ||
| }); | ||
| expect(parsed).not.toHaveProperty("mcp_servers"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import type { McpServerConfig } from "@open-inspect/shared"; | ||
|
|
||
| /** | ||
| * Shared assembly for the sandbox environment contract. | ||
| * | ||
| * The runtime decodes the `SESSION_CONFIG` env var into a single canonical | ||
| * shape (see the Python `SessionConfig` in | ||
| * `packages/sandbox-runtime/src/sandbox_runtime/types.py`). Every provider used | ||
| * to hand-roll that object independently, which let fields silently diverge — | ||
| * the Daytona provider dropped `mcp_servers` entirely because its local copy | ||
| * never added the key. This module is the single source of truth for the shape | ||
| * so providers serialize it instead of reassembling ad-hoc objects. | ||
| * | ||
| * The runtime reads `session_id`, `branch`, `provider`, `model`, and | ||
| * `mcp_servers` from this payload; `repo_owner` / `repo_name` are included to | ||
| * mirror the full contract. | ||
| */ | ||
|
|
||
| /** Canonical `SESSION_CONFIG` payload handed to the sandbox runtime. */ | ||
| export interface SessionConfigPayload { | ||
| session_id: string; | ||
| repo_owner: string; | ||
| repo_name: string; | ||
| provider: string; | ||
| model: string; | ||
| /** Omitted from the serialized payload when undefined. */ | ||
| mcp_servers?: McpServerConfig[]; | ||
| /** Omitted from the serialized payload when undefined. */ | ||
| branch?: string; | ||
| } | ||
|
|
||
| /** Provider-agnostic inputs needed to assemble a {@link SessionConfigPayload}. */ | ||
| export interface SessionConfigInput { | ||
| sessionId: string; | ||
| repoOwner: string; | ||
| repoName: string; | ||
| provider: string; | ||
| model: string; | ||
| mcpServers?: McpServerConfig[]; | ||
| branch?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Build the canonical `SESSION_CONFIG` payload from provider inputs. | ||
| * | ||
| * `mcp_servers` is always set (left undefined when absent) so `JSON.stringify` | ||
| * omits it — matching how the runtime treats an absent key and an empty list | ||
| * identically. `branch` is only set when provided. | ||
| */ | ||
| export function buildSessionConfig(input: SessionConfigInput): SessionConfigPayload { | ||
| const payload: SessionConfigPayload = { | ||
| session_id: input.sessionId, | ||
| repo_owner: input.repoOwner, | ||
| repo_name: input.repoName, | ||
| provider: input.provider, | ||
| model: input.model, | ||
| mcp_servers: input.mcpServers, | ||
| }; | ||
| if (input.branch) { | ||
| payload.branch = input.branch; | ||
| } | ||
| return payload; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.