LibreChat/packages/data-provider/specs/createPayload.spec.ts
Danny Avila 1163045cef
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: Seal Code Environment Choices Per Conversation (#15868)
* feat: lock code environments per conversation

* style: Sort code environment imports

* fix: Harden code environment decisions

* fix: Preserve code environment rollout compatibility

* fix: Harden code environment boundaries

* refactor: Centralize code environment policy

* test: Restore partial disconnect policy mock

* fix: Close code environment edge paths

* fix: Preserve implicit stateful code routes

* fix: Stabilize implicit code routing

* test: Align remote workspace contract

* chore: Sort code route import
2026-09-12 20:45:00 -04:00

95 lines
3.6 KiB
TypeScript

import type { TSubmission } from '../src/types';
import { EModelEndpoint } from '../src/schemas';
import { EndpointURLs } from '../src/config';
import createPayload from '../src/createPayload';
const agentsChatRoot = EndpointURLs[EModelEndpoint.agents];
const makeSubmission = (endpoint: string): TSubmission =>
({
conversation: { conversationId: 'convo-1', endpoint },
userMessage: { text: 'hello' },
endpointOption: { endpoint },
}) as unknown as TSubmission;
describe('createPayload server URL', () => {
it('builds the chat URL from a plain custom endpoint name', () => {
const { server } = createPayload(makeSubmission('OpenRouter'));
expect(server).toBe(`${agentsChatRoot}/OpenRouter`);
});
it('percent-encodes a slash so the name stays a single path segment', () => {
/** A raw `/` would split into an extra path segment and miss the server's
* `/:endpoint` route, which answers with a generic 404 "Endpoint not found"
* (danny-avila/LibreChat#15270). */
const { server } = createPayload(makeSubmission('Company/API'));
expect(server).toBe(`${agentsChatRoot}/Company%2FAPI`);
expect(server.slice(agentsChatRoot.length + 1)).not.toContain('/');
});
it('round-trips the encoded name back to the configured value', () => {
const { server } = createPayload(makeSubmission('Company/API'));
expect(decodeURIComponent(server.slice(agentsChatRoot.length + 1))).toBe('Company/API');
});
it('encodes other characters that are unsafe in a path segment', () => {
const { server } = createPayload(makeSubmission('Team A?v=1#x'));
expect(server).toBe(`${agentsChatRoot}/Team%20A%3Fv%3D1%23x`);
});
it('leaves the endpoint name itself untouched in the payload body', () => {
const { payload } = createPayload(makeSubmission('Company/API'));
expect(payload.endpoint).toBe('Company/API');
});
it('forwards the conversation-selected code workspace to agents', () => {
const submission = makeSubmission('agents');
submission.codeEnvironmentMode = 'attached';
submission.codeWorkspaces = [{ environmentId: 'personal-vm', workspaceId: 'project-a' }];
expect(createPayload(submission).payload.codeEnvironmentMode).toBe('attached');
expect(createPayload(submission).payload.codeWorkspaces).toEqual([
{ environmentId: 'personal-vm', workspaceId: 'project-a' },
]);
});
it('does not touch the assistants URL, which carries no endpoint segment', () => {
const { server } = createPayload(makeSubmission(EModelEndpoint.assistants));
expect(server).toBe(EndpointURLs[EModelEndpoint.assistants]);
});
});
describe('createPayload compaction', () => {
const compactionSubmission = (compact: boolean): TSubmission =>
({
conversation: { conversationId: 'convo-1', endpoint: 'openAI' },
userMessage: { messageId: 'leaf', text: '' },
endpointOption: { endpoint: 'openAI' },
isRegenerate: true,
...(compact ? { compact: true } : {}),
}) as unknown as TSubmission;
it('sends a compaction as such, never as a regenerated user turn', () => {
/** The regenerate shape is a client-side rendering choice (no new user
* bubble); the server keying off `isRegenerate` would rewrite the leaf
* as a user message. */
const { payload } = createPayload(compactionSubmission(true));
expect(payload.compact).toBe(true);
expect(payload.isRegenerate).toBeUndefined();
expect(payload.text).toBe('');
});
it('leaves an ordinary regenerate untouched', () => {
const { payload } = createPayload(compactionSubmission(false));
expect(payload.isRegenerate).toBe(true);
expect('compact' in payload).toBe(false);
});
});