mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 21:08:17 +00:00
🗂️ feat: Choose Conversation Checkout Mode (#16679)
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Waiting to run
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Blocked by required conditions
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Waiting to run
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Blocked by required conditions
* feat: Choose the conversation checkout mode * fix: Preserve checkout choices across submission and recovery * test: Match checkout policy defaults and share mode enum * fix: Offer shared checkout and require deliberate transition modes * fix: Retain explicit mode when changing repository selection * test: Match repository menu accessible labels
This commit is contained in:
parent
bb0543fd15
commit
35a2bee409
20 changed files with 888 additions and 66 deletions
|
|
@ -452,6 +452,75 @@ describe('resolveCodeExecutionWorkspaceContext', () => {
|
|||
expect(resolved.codeWorkspace?.environment).toEqual(environment);
|
||||
});
|
||||
|
||||
it.each(['source', 'isolated'] as const)(
|
||||
'honors an explicit %s checkout choice',
|
||||
async (checkout) => {
|
||||
jest
|
||||
.spyOn(globalThis, 'fetch')
|
||||
.mockResolvedValue(
|
||||
workspaceStatus([{ id: 'worktree', workspaceInstances: ['git_worktree'] }]),
|
||||
);
|
||||
const resolved = await resolveCodeExecutionWorkspaceContext({
|
||||
context: {
|
||||
...context,
|
||||
conversationWorkspaceInstanceId: 'c'.repeat(64),
|
||||
codeEnvironmentConfigSchema: { workspaces: { allowCheckoutSelection: true } },
|
||||
},
|
||||
requestedSelections: [{ environmentId: 'personal', workspaceId: 'worktree', checkout }],
|
||||
environments,
|
||||
getAppConfig,
|
||||
});
|
||||
expect(resolved.codeWorkspace?.checkout).toBe(checkout);
|
||||
expect(resolved.codeWorkspace?.workspaceInstanceId).toBe(
|
||||
checkout === 'isolated' ? 'c'.repeat(64) : undefined,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{ enabled: false, capable: true, instance: 'c'.repeat(64) },
|
||||
{ enabled: true, capable: false, instance: 'c'.repeat(64) },
|
||||
{ enabled: true, capable: true, instance: undefined },
|
||||
])(
|
||||
'refuses unsupported isolation instead of executing in the source: %j',
|
||||
async ({ enabled, capable, instance }) => {
|
||||
jest
|
||||
.spyOn(globalThis, 'fetch')
|
||||
.mockResolvedValue(
|
||||
workspaceStatus([
|
||||
{ id: 'worktree', ...(capable ? { workspaceInstances: ['git_worktree'] } : {}) },
|
||||
]),
|
||||
);
|
||||
await expect(
|
||||
resolveCodeExecutionWorkspaceContext({
|
||||
context: {
|
||||
...context,
|
||||
conversationWorkspaceInstanceId: instance,
|
||||
codeEnvironmentConfigSchema: { workspaces: { allowCheckoutSelection: enabled } },
|
||||
},
|
||||
requestedSelections: [
|
||||
{ environmentId: 'personal', workspaceId: 'worktree', checkout: 'isolated' },
|
||||
],
|
||||
environments,
|
||||
getAppConfig,
|
||||
}),
|
||||
).rejects.toMatchObject({ reason: 'unsupported' });
|
||||
},
|
||||
);
|
||||
|
||||
it('refuses a checkout choice that changes the sealed decision', async () => {
|
||||
const selection = { environmentId: 'personal', workspaceId: 'worktree' };
|
||||
await expect(
|
||||
resolveCodeExecutionWorkspaceContext({
|
||||
context,
|
||||
persistedSelections: [{ ...selection, checkout: 'isolated' }],
|
||||
requestedSelections: [{ ...selection, checkout: 'source' }],
|
||||
environments,
|
||||
getAppConfig,
|
||||
}),
|
||||
).rejects.toMatchObject({ reason: 'locked' });
|
||||
});
|
||||
|
||||
it('activates a server-derived instance only when the worker advertises worktree support', async () => {
|
||||
const workspaceInstanceId = 'c'.repeat(64);
|
||||
jest
|
||||
|
|
@ -496,7 +565,9 @@ describe('resolveCodeExecutionWorkspaceContext', () => {
|
|||
resolveCodeExecutionWorkspaceContext({
|
||||
context: {
|
||||
...context,
|
||||
codeEnvironmentConfigSchema: { workspaces: { linkedWorktrees } },
|
||||
codeEnvironmentConfigSchema: {
|
||||
workspaces: { linkedWorktrees, allowCheckoutSelection: false },
|
||||
},
|
||||
...(instanceId ? { conversationWorkspaceInstanceId: instanceId } : {}),
|
||||
},
|
||||
requestedSelections: [{ environmentId: 'personal', workspaceId }],
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { logger } from '@librechat/data-schemas';
|
|||
import {
|
||||
isCodeWorkspaceSelections,
|
||||
canonicalizeCodeWorkspaceSelections,
|
||||
isCodeWorkspaceCheckoutAvailable,
|
||||
} from 'librechat-data-provider';
|
||||
import type { CodeWorkspaceSelection } from 'librechat-data-provider';
|
||||
import type { CodeEnvironmentConfig, CodeExecutionContext } from '~/agents/execution';
|
||||
|
|
@ -141,21 +142,28 @@ export async function resolveCodeExecutionWorkspaceContext({
|
|||
if (!workspace) {
|
||||
throw new CodeWorkspaceSelectionError('missing');
|
||||
}
|
||||
const supportsIsolation = workspace.workspaceInstances?.includes('git_worktree') === true;
|
||||
if (
|
||||
!isCodeWorkspaceCheckoutAvailable(
|
||||
selection,
|
||||
workspace,
|
||||
context.codeEnvironmentConfigSchema?.workspaces?.allowCheckoutSelection === true,
|
||||
) ||
|
||||
(selection.checkout === 'isolated' && !context.conversationWorkspaceInstanceId)
|
||||
) {
|
||||
throw new CodeWorkspaceSelectionError('unsupported');
|
||||
}
|
||||
const usesIsolation =
|
||||
selection.checkout !== 'source' && supportsIsolation && context.conversationWorkspaceInstanceId;
|
||||
return {
|
||||
...context,
|
||||
codeWorkspace: {
|
||||
...selection,
|
||||
operations: [...(workspace.operations ?? status.operations)],
|
||||
...(context.conversationWorkspaceInstanceId &&
|
||||
workspace.workspaceInstances?.includes('git_worktree')
|
||||
? { workspaceInstanceId: context.conversationWorkspaceInstanceId }
|
||||
: {}),
|
||||
...(usesIsolation ? { workspaceInstanceId: context.conversationWorkspaceInstanceId } : {}),
|
||||
...(context.codeEnvironmentConfigSchema?.workspaces?.linkedWorktrees === true &&
|
||||
workspace.workspaceScopes?.includes('git_linked_worktree') &&
|
||||
!(
|
||||
context.conversationWorkspaceInstanceId &&
|
||||
workspace.workspaceInstances?.includes('git_worktree')
|
||||
)
|
||||
!usesIsolation
|
||||
? { linkedWorktrees: true }
|
||||
: {}),
|
||||
...(status.maxCommandTimeoutMs == null
|
||||
|
|
|
|||
|
|
@ -1546,6 +1546,7 @@ describe('moving a sealed conversation code-environment decision', () => {
|
|||
|
||||
function setup({
|
||||
movesEnabled = true,
|
||||
checkoutEnabled = false,
|
||||
allowAttachDetach = true,
|
||||
stored = {
|
||||
conversationId: 'conversation-1',
|
||||
|
|
@ -1557,6 +1558,7 @@ describe('moving a sealed conversation code-environment decision', () => {
|
|||
fetchImpl = jest.fn().mockImplementation(async () => workerStatusResponse()),
|
||||
}: {
|
||||
movesEnabled?: boolean;
|
||||
checkoutEnabled?: boolean;
|
||||
allowAttachDetach?: boolean;
|
||||
stored?: StoredDecision;
|
||||
job?: CodeEnvironmentGenerationJob;
|
||||
|
|
@ -1607,7 +1609,12 @@ describe('moving a sealed conversation code-environment decision', () => {
|
|||
endpoints: {
|
||||
[EModelEndpoint.agents]: {
|
||||
statefulCodeSessions: {
|
||||
environments: [controlPlane],
|
||||
environments: [
|
||||
{
|
||||
...controlPlane,
|
||||
configSchema: { workspaces: { allowCheckoutSelection: checkoutEnabled } },
|
||||
},
|
||||
],
|
||||
conversationMoves: { enabled: movesEnabled, allowAttachDetach },
|
||||
},
|
||||
},
|
||||
|
|
@ -1673,6 +1680,39 @@ describe('moving a sealed conversation code-environment decision', () => {
|
|||
};
|
||||
}
|
||||
|
||||
test.each([
|
||||
{ checkout: 'source', enabled: false, capable: true, accepted: false },
|
||||
{ checkout: 'isolated', enabled: true, capable: false, accepted: false },
|
||||
{ checkout: 'isolated', enabled: false, capable: true, accepted: false },
|
||||
{ checkout: 'source', enabled: true, capable: false, accepted: true },
|
||||
{ checkout: 'isolated', enabled: true, capable: true, accepted: true },
|
||||
] as const)(
|
||||
'validates checkout before persisting a move: %j',
|
||||
async ({ checkout, enabled, capable, accepted }) => {
|
||||
const { move, replaceDecision } = setup({
|
||||
checkoutEnabled: enabled,
|
||||
fetchImpl: jest.fn(async () =>
|
||||
workerStatusResponse({
|
||||
workspaces: [
|
||||
{ id: vm.workspaceId, ...(capable ? { workspaceInstances: ['git_worktree'] } : {}) },
|
||||
],
|
||||
}),
|
||||
),
|
||||
});
|
||||
const to = [{ ...vm, checkout }];
|
||||
const res = await move({ from: [mac], to });
|
||||
expect(res.statusCode).toBe(accepted ? 200 : 409);
|
||||
if (accepted) {
|
||||
expect(replaceDecision).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ codeWorkspaces: to }),
|
||||
);
|
||||
} else {
|
||||
expect(res.body).toEqual(expect.objectContaining({ reason: 'unsupported' }));
|
||||
expect(replaceDecision).not.toHaveBeenCalled();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test('moves a sealed decision onto a workspace the new machine registers', async () => {
|
||||
const { move, conversations, fetchImpl } = setup();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { nanoid } from 'nanoid';
|
||||
import { EModelEndpoint } from 'librechat-data-provider';
|
||||
import { logger, type AppConfig } from '@librechat/data-schemas';
|
||||
import { EModelEndpoint, isCodeWorkspaceCheckoutAvailable } from 'librechat-data-provider';
|
||||
import type { CodeEnvironmentMode, CodeWorkspaceSelection } from 'librechat-data-provider';
|
||||
import type { Response } from 'express';
|
||||
import type {
|
||||
|
|
@ -363,9 +363,23 @@ export function createCodeEnvironmentHttpHandlers(deps: CodeEnvironmentHttpDeps)
|
|||
if (!current.workspaces || !current.operations) {
|
||||
throw new CodeWorkspaceSelectionError('unsupported');
|
||||
}
|
||||
if (!current.workspaces.some(({ id }) => id === selection.workspaceId)) {
|
||||
const workspace = current.workspaces.find(({ id }) => id === selection.workspaceId);
|
||||
if (workspace == null) {
|
||||
throw new CodeWorkspaceSelectionError('missing');
|
||||
}
|
||||
const configuration = policy.configurations.find(({ id }) => id === selection.environmentId);
|
||||
const effectiveEnvironment = configuration
|
||||
? configuredAttachedControlPlane(policy.effectiveConfig, configuration.controlPlaneId ?? '')
|
||||
: configuredControlPlane(policy.effectiveConfig, selection.environmentId);
|
||||
if (
|
||||
!isCodeWorkspaceCheckoutAvailable(
|
||||
selection,
|
||||
workspace,
|
||||
effectiveEnvironment?.configSchema?.workspaces?.allowCheckoutSelection === true,
|
||||
)
|
||||
) {
|
||||
throw new CodeWorkspaceSelectionError('unsupported');
|
||||
}
|
||||
if (
|
||||
previousWorkspaceId != null &&
|
||||
previousWorkspaceId !== selection.workspaceId &&
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue