🏠 fix: Preserve Stateful Deployment Default (#15719)

This commit is contained in:
Danny Avila 2026-09-07 22:50:32 -04:00 • committed by GitHub
parent 5ca1093ed9
commit 6a4d227ca3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 80 additions and 29 deletions

View file

@ -54,7 +54,11 @@ describe('mergeAccessibleCodeEnvironments', () => {
expect(result).not.toBe(appConfig);
expect(result.endpoints?.agents?.statefulCodeSessions?.environments).toEqual([
expect.objectContaining({ id: 'deployment-vm', baseURL: 'https://deployment.example' }),
expect.objectContaining({
id: 'deployment-vm',
baseURL: 'https://deployment.example',
default: true,
}),
expect.objectContaining({ id: 'personal-vm', baseURL: 'https://deployment.example' }),
]);
expect(appConfig.endpoints?.agents?.statefulCodeSessions?.environments).toHaveLength(1);
@ -348,7 +352,16 @@ describe('mergeAccessibleCodeEnvironments', () => {
]);
});
test('defaults to an executable principal environment after a pairing-only control plane', async () => {
test.each([
['preserves the configured stateful deployment', 'https://stateful.example/v1', undefined],
['uses the principal environment without a stateful deployment', undefined, true],
])('%s after a pairing-only control plane', async (_name, statefulURL, expectedDefault) => {
const originalStatefulURL = process.env.LIBRECHAT_CODE_BASEURL_STATEFUL;
if (statefulURL == null) {
delete process.env.LIBRECHAT_CODE_BASEURL_STATEFUL;
} else {
process.env.LIBRECHAT_CODE_BASEURL_STATEFUL = statefulURL;
}
const pairingOnly = {
id: 'self-service',
name: 'Self-service',
@ -366,32 +379,40 @@ describe('mergeAccessibleCodeEnvironments', () => {
},
} as unknown as AppConfig;
const result = await mergeAccessibleCodeEnvironments({
appConfig,
deploymentConfig: appConfig,
actor: { userId: '68b2f0c498f24c1e78fa0001', role: 'USER', idOnTheSource: null },
registry: {
listRegisteredIds: jest.fn().mockResolvedValue(['personal-vm']),
listAccessibleConfigurations: jest.fn().mockResolvedValue([
{
id: 'personal-vm',
name: 'Personal VM',
type: 'attached',
baseURL: 'https://persisted.example',
controlPlaneId: 'self-service',
owner: 'principal',
workerId: 'personal-worker',
},
]),
},
});
try {
const result = await mergeAccessibleCodeEnvironments({
appConfig,
deploymentConfig: appConfig,
actor: { userId: '68b2f0c498f24c1e78fa0001', role: 'USER', idOnTheSource: null },
registry: {
listRegisteredIds: jest.fn().mockResolvedValue(['personal-vm']),
listAccessibleConfigurations: jest.fn().mockResolvedValue([
{
id: 'personal-vm',
name: 'Personal VM',
type: 'attached',
baseURL: 'https://persisted.example',
controlPlaneId: 'self-service',
owner: 'principal',
workerId: 'personal-worker',
},
]),
},
});
const environments = result.endpoints?.agents?.statefulCodeSessions?.environments;
expect(environments?.find((environment) => environment.id === 'self-service')?.default).toBe(
false,
);
expect(environments?.find((environment) => environment.id === 'personal-vm')?.default).toBe(
true,
);
const environments = result.endpoints?.agents?.statefulCodeSessions?.environments;
expect(environments?.find((environment) => environment.id === 'self-service')?.default).toBe(
false,
);
expect(environments?.find((environment) => environment.id === 'personal-vm')?.default).toBe(
expectedDefault,
);
} finally {
if (originalStatefulURL == null) {
delete process.env.LIBRECHAT_CODE_BASEURL_STATEFUL;
} else {
process.env.LIBRECHAT_CODE_BASEURL_STATEFUL = originalStatefulURL;
}
}
});
});

View file

@ -161,7 +161,11 @@ export async function mergeAccessibleCodeEnvironments({
environment.default === true,
)
) {
const defaultIndex = mergedEnvironments.findIndex(isExecutableCodeEnvironment);
const defaultIndex = mergedEnvironments.findIndex(
(environment) =>
isExecutableCodeEnvironment(environment) &&
(environment.owner !== 'principal' || !process.env.LIBRECHAT_CODE_BASEURL_STATEFUL?.trim()),
);
if (defaultIndex >= 0) {
mergedEnvironments = mergedEnvironments.map((environment, index) =>
index === defaultIndex ? { ...environment, default: true as const } : environment,