LibreChat/e2e/specs/mock/deployment-skills.spec.ts
Joseph Licata f25242df98
🦘 feat: Share Run-Scoped Files With Subagents (#15848)
* feat: add run-scoped file sharing for subagents

Delegate current-message files through authorized execution catalogs and publish selected immutable code-output versions through the existing file pipeline.

Requires the companion agents SDK context adapter before the dependency can be released and pinned.

* fix: preserve child tool artifacts and verify file-sharing lifecycle

Keep citations and other non-sandbox artifacts on their existing delivery path while retaining private code outputs and inspected images until publication.

Cover native and text delivery, nested and sibling authorization, concurrent runs, cancellation cleanup, and checkpoint recovery through the browser harness.

* test: align file-sharing fixtures and integration cleanup

* test: repair LibreOffice conversion fixtures

* test: verify deployment skill bytes across checkout formats

* fix: align subagent file budgets and refresh boundaries

* chore: update agents SDK to 3.8.6

* refactor: move code output processing into API workspace

* fix: enforce shared file budgets for parents and teams

* fix: declare the shared file encoder interface
2026-09-12 20:14:22 -04:00

228 lines
6 KiB
TypeScript

import fs from 'node:fs';
import path from 'node:path';
import { expect, test } from '@playwright/test';
import type { Page } from '@playwright/test';
import { NEW_CHAT_PATH } from './helpers';
const DEPLOYMENT_SKILL_NAME = 'e2e-deployment-skill';
const DEPLOYMENT_SKILL_DESCRIPTION =
'Use this deployment skill to verify shared skills load during Playwright startup.';
type RefreshTokenBody = {
token?: string;
};
type SkillSummary = {
_id: string;
name: string;
description: string;
source?: string;
sourceMetadata?: Record<string, unknown>;
fileCount?: number;
alwaysApply?: boolean;
isPublic?: boolean;
};
type SkillDetail = SkillSummary & {
body: string;
frontmatter?: Record<string, unknown>;
};
type SkillFile = {
_id: string;
skillId: string;
relativePath: string;
file_id: string;
filename: string;
filepath: string;
source: string;
mimeType: string;
bytes: number;
category: string;
isExecutable: boolean;
author: string;
createdAt: string;
updatedAt: string;
content?: string;
};
type SkillFileContent = Pick<
SkillFile,
'relativePath' | 'filename' | 'mimeType' | 'bytes' | 'content'
> & {
isBinary?: boolean;
};
type ApiResult<T> = {
ok: boolean;
status: number;
text: string;
json: T | null;
};
async function getAccessToken(page: Page): Promise<string> {
const result = await page.evaluate(async () => {
const response = await fetch('/api/auth/refresh', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({}),
});
const text = await response.text();
let json: unknown = null;
try {
json = text ? JSON.parse(text) : null;
} catch {
json = null;
}
return { ok: response.ok, status: response.status, text, json };
});
if (!result.ok) {
throw new Error(
`Expected /api/auth/refresh to return 2xx, got ${result.status}: ${result.text}`,
);
}
const body = result.json as RefreshTokenBody | null;
if (!body?.token) {
throw new Error(`Expected /api/auth/refresh to return a token, got: ${result.text}`);
}
return body.token;
}
async function apiJson<T>(
page: Page,
path: string,
token: string,
init: { method?: string; body?: unknown } = {},
): Promise<ApiResult<T>> {
return page.evaluate(
async ({ accessToken, body, method, urlPath }) => {
const headers: Record<string, string> = { Authorization: `Bearer ${accessToken}` };
if (body !== undefined) {
headers['Content-Type'] = 'application/json';
}
const response = await fetch(urlPath, {
method,
credentials: 'include',
headers,
body: body === undefined ? undefined : JSON.stringify(body),
});
const text = await response.text();
let json: unknown = null;
try {
json = text ? JSON.parse(text) : null;
} catch {
json = null;
}
return { ok: response.ok, status: response.status, text, json };
},
{
accessToken: token,
body: init.body,
method: init.method,
urlPath: path,
},
) as Promise<ApiResult<T>>;
}
async function fetchJson<T>(page: Page, path: string, token: string): Promise<T> {
const result = await apiJson<T>(page, path, token);
if (!result.ok) {
throw new Error(`Expected ${path} to return 2xx, got ${result.status}: ${result.text}`);
}
return result.json as T;
}
test.describe('deployment skills', () => {
test('loads configured deployment skills for every authenticated user as read-only', async ({
page,
}) => {
const fixture = fs.readFileSync(
path.resolve(
__dirname,
'../../fixtures/deployment-skills',
DEPLOYMENT_SKILL_NAME,
'guide.txt',
),
);
await page.goto(NEW_CHAT_PATH, { timeout: 10000 });
const token = await getAccessToken(page);
const list = await fetchJson<{ skills?: SkillSummary[] }>(
page,
`/api/skills?search=${encodeURIComponent(DEPLOYMENT_SKILL_NAME)}&limit=10`,
token,
);
const skill = list.skills?.find((item) => item.name === DEPLOYMENT_SKILL_NAME);
expect(skill).toMatchObject({
name: DEPLOYMENT_SKILL_NAME,
description: DEPLOYMENT_SKILL_DESCRIPTION,
source: 'deployment',
sourceMetadata: { deployment: true },
fileCount: 1,
alwaysApply: true,
isPublic: true,
});
const detail = await fetchJson<SkillDetail>(
page,
`/api/skills/${encodeURIComponent(skill!._id)}`,
token,
);
expect(detail.body).toContain('E2E deployment skill loaded through Playwright');
expect(detail.frontmatter).toMatchObject({
name: DEPLOYMENT_SKILL_NAME,
description: DEPLOYMENT_SKILL_DESCRIPTION,
'always-apply': true,
});
const files = await fetchJson<{ files?: SkillFile[] }>(
page,
`/api/skills/${encodeURIComponent(skill!._id)}/files`,
token,
);
expect(files.files).toHaveLength(1);
expect(files.files?.[0]).toMatchObject({
skillId: skill!._id,
relativePath: 'guide.txt',
filename: 'guide.txt',
source: 'deployment',
mimeType: 'text/plain',
bytes: fixture.length,
category: 'other',
isExecutable: false,
});
expect(files.files?.[0]).not.toHaveProperty('content');
const downloaded = await fetchJson<SkillFileContent>(
page,
`/api/skills/${encodeURIComponent(skill!._id)}/files/guide.txt`,
token,
);
expect(downloaded).toMatchObject({
relativePath: 'guide.txt',
filename: 'guide.txt',
mimeType: 'text/plain',
bytes: fixture.length,
isBinary: false,
content: fixture.toString('utf8'),
});
const patch = await apiJson<{ message?: string }>(
page,
`/api/skills/${encodeURIComponent(skill!._id)}`,
token,
{
method: 'PATCH',
body: {
description: 'Deployment skills should stay read-only.',
},
},
);
expect(patch.status).toBe(403);
expect(patch.json).toMatchObject({ message: 'Deployment skills are read-only' });
});
});