mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-17 05:20:55 +00:00
feat: gate machine Skill deletion until cleanup rollout
This commit is contained in:
parent
5a17bc452c
commit
2a3c2dae04
6 changed files with 39 additions and 5 deletions
|
|
@ -180,6 +180,7 @@ describe('Agents OpenAPI actual HTTP contract', () => {
|
|||
endpoints: {
|
||||
agents: {
|
||||
managementApi: {
|
||||
skillDeletionEnabled: true,
|
||||
auth: {
|
||||
oidc: { enabled: true, issuer, audience, jwksUri: `${issuer}/jwks.json` },
|
||||
clients: [
|
||||
|
|
|
|||
|
|
@ -50,8 +50,11 @@ A stale version returns HTTP 409 with `error.code: "conflict"`; retrieve the cur
|
|||
retrying. Skill reads require VIEW access; updates require EDIT and the Skills USE/CREATE role
|
||||
permissions. Inaccessible and cross-tenant IDs return the same 404 envelope.
|
||||
|
||||
Whole-Skill deletion requires DELETE access and the same Skills USE/CREATE role permissions as
|
||||
other mutations. It returns `{ "id": "...", "deleted": true, "cleanupComplete": true }` on
|
||||
Whole-Skill deletion is disabled by default; set
|
||||
`endpoints.agents.managementApi.skillDeletionEnabled: true` only after the deletion cleanup
|
||||
implementation is deployed across all instances. It requires DELETE access and the same Skills
|
||||
USE/CREATE role permissions as other mutations. It returns
|
||||
`{ "id": "...", "deleted": true, "cleanupComplete": true }` on
|
||||
complete cleanup. If the existing deletion handler removes the Skill but cannot finish dependent
|
||||
cleanup, it returns `cleanupComplete: false`; that result does not promise an automatic retry.
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ let canManage: boolean;
|
|||
let authenticated: boolean;
|
||||
let saveFile: jest.MockedFunction<SkillManagementDeps['saveFile']>;
|
||||
let filters: FiltersConfig | undefined;
|
||||
let skillDeletionEnabled: boolean;
|
||||
let readSkill: jest.SpyInstance;
|
||||
let beforeList: jest.Mock;
|
||||
let uploadLimiter: jest.MockedFunction<RequestHandler>;
|
||||
|
|
@ -65,6 +66,7 @@ beforeEach(async () => {
|
|||
canManage = false;
|
||||
authenticated = true;
|
||||
filters = undefined;
|
||||
skillDeletionEnabled = true;
|
||||
readSkill = jest.spyOn(db, 'getSkillById');
|
||||
const { skill } = await inTenant(() =>
|
||||
db.createSkill({
|
||||
|
|
@ -122,7 +124,10 @@ beforeEach(async () => {
|
|||
app.use(express.json());
|
||||
app.use((req, _res, next) => {
|
||||
if (authenticated) req.user = user;
|
||||
(req as ServerRequest).config = { filters } as ServerRequest['config'];
|
||||
(req as ServerRequest).config = {
|
||||
filters,
|
||||
endpoints: { agents: { managementApi: { skillDeletionEnabled } } },
|
||||
} as ServerRequest['config'];
|
||||
tenantStorage.run({ tenantId }, next);
|
||||
});
|
||||
app.get('/skills', async (req, res) => {
|
||||
|
|
@ -203,6 +208,12 @@ it('deletes an inline Skill through the existing cleanup handler', async () => {
|
|||
expect(await inTenant(() => db.getSkillById(skillId))).toBeNull();
|
||||
await request(app).delete(`/skills/${skillId}`).expect(404);
|
||||
});
|
||||
it('keeps whole-Skill deletion disabled until explicitly enabled', async () => {
|
||||
skillDeletionEnabled = false;
|
||||
const response = await request(app).delete(`/skills/${skillId}`).expect(404);
|
||||
expect(response.body).toMatchObject({ error: { code: 'not_found' } });
|
||||
expect(await inTenant(() => db.getSkillById(skillId))).not.toBeNull();
|
||||
});
|
||||
it('requires DELETE access and hides missing or cross-tenant Skills', async () => {
|
||||
allowDelete = false;
|
||||
await request(app).delete(`/skills/${skillId}`).expect(404);
|
||||
|
|
|
|||
|
|
@ -384,7 +384,10 @@ export function createSkillManagementHandlers(
|
|||
),
|
||||
delete: wrap(
|
||||
PermissionBits.DELETE,
|
||||
(req, res) => {
|
||||
async (req, res) => {
|
||||
if (req.config?.endpoints?.agents?.managementApi?.skillDeletionEnabled !== true) {
|
||||
return sendError(res, 'not_found');
|
||||
}
|
||||
req.params.id = req.params.id.toLowerCase();
|
||||
return runHandler(req, res, deps.handlers.delete, (body) =>
|
||||
skillDeleteResponseSchema.parse(body),
|
||||
|
|
|
|||
|
|
@ -550,6 +550,17 @@ describe('Agent Management authentication config', () => {
|
|||
expect(result.data.endpoints?.agents?.managementApi?.auth?.clients).toEqual([
|
||||
{ ...binding, enabled: true },
|
||||
]);
|
||||
expect(result.data.endpoints?.agents?.managementApi?.skillDeletionEnabled).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts explicitly enabling Skill deletion', () => {
|
||||
const result = configSchema.safeParse({
|
||||
version: '1.0',
|
||||
endpoints: { agents: { managementApi: { skillDeletionEnabled: true } } },
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
if (!result.success) return;
|
||||
expect(result.data.endpoints?.agents?.managementApi?.skillDeletionEnabled).toBe(true);
|
||||
});
|
||||
|
||||
it('accepts a provider-specific token subject in a client binding', () => {
|
||||
|
|
|
|||
|
|
@ -1083,7 +1083,12 @@ const managementApiAuthSchema = z
|
|||
}
|
||||
});
|
||||
|
||||
const managementApiSchema = z.object({ auth: managementApiAuthSchema.optional() }).strict();
|
||||
const managementApiSchema = z
|
||||
.object({
|
||||
auth: managementApiAuthSchema.optional(),
|
||||
skillDeletionEnabled: z.boolean().default(false),
|
||||
})
|
||||
.strict();
|
||||
|
||||
/**
|
||||
* Permission mode applied to a tool call. Mirrors `@librechat/agents`'s
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue