feat(agent): add asset management tools and CLI commands (#387)

* feat(agent): add asset management tools and CLI commands

* fix(core): resolve code review findings for reparenting cycles, agent deniedTools update, and CLI folder delete
This commit is contained in:
Yiling-J
2026-09-06 17:15:58 +08:00
committed by GitHub
parent b087bf73ae
commit 8c1e59d131
28 changed files with 1300 additions and 10 deletions
+33
View File
@@ -626,6 +626,39 @@ describe('AssetService', () => {
).rejects.toThrow('Can only move one file at a time into a version stack')
})
it('rejects reparenting a folder into itself', async () => {
const { user, assets } = await setupBasicAssets()
await expect(
assetService.reparentAssets({
assetIds: [assets.folderA.id],
newParentId: assets.folderA.id,
creatorId: user.id,
}),
).rejects.toThrow('Cannot move an asset into itself or its own descendant')
})
it('rejects reparenting a folder into its own descendant', async () => {
const { user, assets, project } = await setupBasicAssets()
const subfolder = await prisma.asset.create({
data: {
name: 'subfolderA',
type: AssetType.folder,
projectId: project.id,
parentId: assets.folderA.id,
creatorId: user.id,
status: 'uploaded',
},
})
await expect(
assetService.reparentAssets({
assetIds: [assets.folderA.id],
newParentId: subfolder.id,
creatorId: user.id,
}),
).rejects.toThrow('Cannot move an asset into itself or its own descendant')
})
describe('fileCount verification', () => {
it('createAsset should increment parent fileCount', async () => {
const { user, assets, project } = await setupBasicAssets()
+14
View File
@@ -223,6 +223,20 @@ export class AssetService {
if (assetsToMove.length === 0) return
// Check if newParentId is equal to or a descendant of any asset being moved
const ancestors = await tx.$queryRaw<{ id: string }[]>`
WITH RECURSIVE ancestor AS (
SELECT id, parent_id FROM assets WHERE id = ${newParent.id}
UNION ALL
SELECT a.id, a.parent_id FROM assets a
INNER JOIN ancestor d ON a.id = d.parent_id
)
SELECT id FROM ancestor WHERE id IN (${Prisma.join(req.assetIds)}) LIMIT 1;
`
if (ancestors.length > 0) {
throw new Error('Cannot move an asset into itself or its own descendant')
}
if (newParent.type === AssetType.version_stack) {
for (const a of assetsToMove) {
if (a.type !== AssetType.file) {