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
29 changes: 28 additions & 1 deletion src/server/lib/agentSession/__tests__/configSeeder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,32 @@ describe('configSeeder', () => {
expect(script).toContain('git config --global --add safe.directory "/workspace"');
});

it('marks every mounted repo as a safe git directory in multi-repo sessions', () => {
const script = generateRuntimeSeedScript({
workspaceRepos: [
{
repo: 'org/ui',
repoUrl: 'https://github.com/org/ui.git',
branch: 'feature/ui',
revision: null,
mountPath: '/workspace/repos/org/ui',
primary: true,
},
{
repo: 'org/api',
repoUrl: 'https://github.com/org/api.git',
branch: 'feature/api',
revision: null,
mountPath: '/workspace/repos/org/api',
primary: false,
},
],
});

expect(script).toContain('git config --global --add safe.directory "/workspace/repos/org/ui"');
expect(script).toContain('git config --global --add safe.directory "/workspace/repos/org/api"');
});

it('sets up pre-push branch protection hook', () => {
const script = generateRuntimeSeedScript(baseOpts);
expect(script).toContain('pre-push');
Expand All @@ -116,7 +142,7 @@ describe('configSeeder', () => {
repoUrl: 'https://github.com/org/ui.git',
branch: 'feature/ui',
revision: 'abc123',
mountPath: '/workspace',
mountPath: '/workspace/repos/org/ui',
primary: true,
},
{
Expand All @@ -133,6 +159,7 @@ describe('configSeeder', () => {
expect(script).toContain('git clone --progress --depth 50 --branch "feature/ui" --single-branch');
expect(script).toContain('git clone --progress --depth 50 --branch "feature/api" --single-branch');
expect(script).toContain('"/workspace/repos/org"');
expect(script).toContain('"/workspace/repos/org/ui"');
expect(script).toContain('"/workspace/repos/org/api"');
});

Expand Down
54 changes: 53 additions & 1 deletion src/server/lib/agentSession/__tests__/podFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ describe('podFactory', () => {
{ name: 'GIT_AUTHOR_EMAIL', value: 'sample-user@example.com' },
{ name: 'GIT_COMMITTER_NAME', value: 'Sample User' },
{ name: 'GIT_COMMITTER_EMAIL', value: 'sample-user@example.com' },
{ name: 'LIFECYCLE_SESSION_PRIMARY_REPO_PATH', value: '/workspace' },
])
);

Expand All @@ -701,6 +702,51 @@ describe('podFactory', () => {
);
});

it('mounts shared git config into the editor without changing its home directory', () => {
const pod = buildSessionWorkspacePodSpec(baseOpts);
const editor = getContainer(pod, 'editor');

expect(editor.env).toEqual(
expect.arrayContaining([
{ name: 'HOME', value: '/home/coder' },
{ name: 'GIT_CONFIG_GLOBAL', value: '/home/coder/.lifecycle-session/.gitconfig' },
{
name: 'GITHUB_TOKEN',
valueFrom: {
secretKeyRef: {
key: 'GITHUB_TOKEN',
name: 'agent-secret-abc123',
},
},
},
{
name: 'GH_TOKEN',
valueFrom: {
secretKeyRef: {
key: 'GITHUB_TOKEN',
name: 'agent-secret-abc123',
},
},
},
{ name: 'GIT_AUTHOR_NAME', value: 'Sample User' },
{ name: 'GIT_AUTHOR_EMAIL', value: 'sample-user@example.com' },
])
);

expect(editor.volumeMounts).toEqual(
expect.arrayContaining([
{
name: 'editor-home',
mountPath: '/home/coder',
},
{
name: SESSION_WORKSPACE_HOME_VOLUME_NAME,
mountPath: '/home/coder/.lifecycle-session',
},
])
);
});

it('passes the session-pod MCP config secret into the workspace gateway sidecar', () => {
const pod = buildSessionWorkspacePodSpec(baseOpts);
const workspaceGateway = getContainer(pod, 'workspace-gateway');
Expand Down Expand Up @@ -759,7 +805,7 @@ describe('podFactory', () => {
repoUrl: 'https://github.com/org/repo.git',
branch: 'feature/test',
revision: null,
mountPath: '/workspace',
mountPath: '/workspace/repos/org/repo',
primary: true,
},
{
Expand All @@ -784,9 +830,15 @@ describe('podFactory', () => {
})
);
expect(getInitContainer(pod, 'prepare-editor-workspace').command?.[2]).toContain('"name": "org/repo"');
expect(getInitContainer(pod, 'prepare-editor-workspace').command?.[2]).toContain(
'"path": "/workspace/repos/org/repo"'
);
expect(getInitContainer(pod, 'prepare-editor-workspace').command?.[2]).toContain(
'"path": "/workspace/repos/org/api"'
);
expect(getContainer(pod, 'workspace-gateway').env).toEqual(
expect.arrayContaining([{ name: 'LIFECYCLE_SESSION_PRIMARY_REPO_PATH', value: '/workspace/repos/org/repo' }])
);
});

it('still prepares the editor workspace when workspace bootstrap is skipped', () => {
Expand Down
57 changes: 44 additions & 13 deletions src/server/lib/agentSession/__tests__/servicePlan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,41 @@
*/

import { buildCombinedInstallCommand, resolveAgentSessionServicePlan } from '../servicePlan';
import { SESSION_WORKSPACE_ROOT } from '../workspace';
import { SESSION_WORKSPACE_REPOS_ROOT, SESSION_WORKSPACE_ROOT } from '../workspace';

describe('servicePlan', () => {
it('rewrites secondary repo service config against the mounted workspace path', () => {
it('keeps the primary repo at the workspace root for single-repo sessions', () => {
const plan = resolveAgentSessionServicePlan(
{
repoUrl: 'https://github.com/example-org/api.git',
branch: 'feature/api',
},
[
{
name: 'api',
deployId: 1,
repo: 'example-org/api',
branch: 'feature/api',
devConfig: {
image: 'node:20',
command: 'pnpm dev',
installCommand: 'pnpm install',
},
},
]
);

expect(plan.workspaceRepos).toEqual([
expect.objectContaining({
repo: 'example-org/api',
mountPath: SESSION_WORKSPACE_ROOT,
primary: true,
}),
]);
expect(buildCombinedInstallCommand(plan.services)).toBe('pnpm install');
});

it('rewrites multi-repo service config against sibling mounted workspace paths', () => {
const plan = resolveAgentSessionServicePlan({}, [
{
name: 'api',
Expand Down Expand Up @@ -51,12 +82,12 @@ describe('servicePlan', () => {
expect(plan.workspaceRepos).toEqual([
expect.objectContaining({
repo: 'example-org/api',
mountPath: SESSION_WORKSPACE_ROOT,
mountPath: `${SESSION_WORKSPACE_REPOS_ROOT}/example-org/api`,
primary: true,
}),
expect.objectContaining({
repo: 'example-org/web',
mountPath: '/workspace/repos/example-org/web',
mountPath: `${SESSION_WORKSPACE_REPOS_ROOT}/example-org/web`,
primary: false,
}),
]);
Expand All @@ -65,14 +96,14 @@ describe('servicePlan', () => {
expect.arrayContaining([
expect.objectContaining({
name: 'web',
workspacePath: '/workspace/repos/example-org/web',
workDir: '/workspace/repos/example-org/web/apps/web',
workspacePath: `${SESSION_WORKSPACE_REPOS_ROOT}/example-org/web`,
workDir: `${SESSION_WORKSPACE_REPOS_ROOT}/example-org/web/apps/web`,
devConfig: expect.objectContaining({
workDir: '/workspace/repos/example-org/web/apps/web',
command: 'pnpm --dir /workspace/repos/example-org/web/apps/web dev',
workDir: `${SESSION_WORKSPACE_REPOS_ROOT}/example-org/web/apps/web`,
command: `pnpm --dir ${SESSION_WORKSPACE_REPOS_ROOT}/example-org/web/apps/web dev`,
installCommand: 'pnpm install',
env: {
CONFIG_PATH: '/workspace/repos/example-org/web/config',
CONFIG_PATH: `${SESSION_WORKSPACE_REPOS_ROOT}/example-org/web/config`,
},
}),
}),
Expand All @@ -85,14 +116,14 @@ describe('servicePlan', () => {
name: 'web',
repo: 'example-org/web',
branch: 'feature/web',
workspacePath: '/workspace/repos/example-org/web',
workDir: '/workspace/repos/example-org/web/apps/web',
workspacePath: `${SESSION_WORKSPACE_REPOS_ROOT}/example-org/web`,
workDir: `${SESSION_WORKSPACE_REPOS_ROOT}/example-org/web/apps/web`,
}),
])
);
});

it('builds repo-aware install commands without duplicating primary repo cd steps', () => {
it('builds repo-aware install commands for every repo in multi-repo sessions', () => {
const plan = resolveAgentSessionServicePlan({}, [
{
name: 'api',
Expand All @@ -119,7 +150,7 @@ describe('servicePlan', () => {
]);

expect(buildCombinedInstallCommand(plan.services)).toBe(
'pnpm install\n\ncd "/workspace/repos/example-org/web"\npnpm install'
`cd "${SESSION_WORKSPACE_REPOS_ROOT}/example-org/api"\npnpm install\n\ncd "${SESSION_WORKSPACE_REPOS_ROOT}/example-org/web"\npnpm install`
);
});

Expand Down
82 changes: 82 additions & 0 deletions src/server/lib/agentSession/__tests__/workspace.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* Copyright 2026 GoodRx, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
buildSessionWorkspaceEditorContents,
buildSessionWorkspaceRepoMountPath,
normalizeSessionWorkspaceRepo,
SESSION_WORKSPACE_REPOS_ROOT,
SESSION_WORKSPACE_ROOT,
} from '../workspace';

describe('workspace', () => {
it('uses /workspace for the primary repo in single-repo sessions', () => {
expect(buildSessionWorkspaceRepoMountPath('example-org/api', true)).toBe(SESSION_WORKSPACE_ROOT);
});

it('uses sibling repo mounts for the primary repo in multi-repo sessions', () => {
expect(
buildSessionWorkspaceRepoMountPath('example-org/api', true, {
useWorkspaceRootForPrimary: false,
})
).toBe(`${SESSION_WORKSPACE_REPOS_ROOT}/example-org/api`);
});

it('normalizes multi-repo primary paths consistently', () => {
expect(
normalizeSessionWorkspaceRepo(
{
repo: 'example-org/api',
repoUrl: 'https://github.com/example-org/api.git',
branch: 'feature/api',
revision: null,
},
true,
{ useWorkspaceRootForPrimary: false }
)
).toEqual({
repo: 'example-org/api',
repoUrl: 'https://github.com/example-org/api.git',
branch: 'feature/api',
revision: null,
mountPath: `${SESSION_WORKSPACE_REPOS_ROOT}/example-org/api`,
primary: true,
});
});

it('writes editor workspace folders for sibling repo mounts', () => {
expect(
buildSessionWorkspaceEditorContents([
{
repo: 'example-org/api',
repoUrl: 'https://github.com/example-org/api.git',
branch: 'feature/api',
revision: null,
mountPath: `${SESSION_WORKSPACE_REPOS_ROOT}/example-org/api`,
primary: true,
},
{
repo: 'example-org/web',
repoUrl: 'https://github.com/example-org/web.git',
branch: 'feature/web',
revision: null,
mountPath: `${SESSION_WORKSPACE_REPOS_ROOT}/example-org/web`,
primary: false,
},
])
).toContain(`"path": "${SESSION_WORKSPACE_REPOS_ROOT}/example-org/api"`);
});
});
Loading
Loading