From 92801ba14a787d3ef3c5e85ff125f02261363c89 Mon Sep 17 00:00:00 2001 From: yiling Date: Tue, 23 Jun 2026 10:02:01 +0800 Subject: [PATCH] fix(core): make version stack sort index lookup deterministic When creating a version stack, the sortIndex was previously extracted by taking files[0] from the database query result. Because findMany without orderBy is non-deterministic, this resulted in flakiness where the sortIndex would sometimes be null (from file2) instead of 'abc' (from file1), causing tests to fail. We now look up the first file specifically based on the ordered fileIds array parameter. --- packages/core/src/versionStack/versionStack.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/versionStack/versionStack.ts b/packages/core/src/versionStack/versionStack.ts index ab5fb746..259c7a84 100644 --- a/packages/core/src/versionStack/versionStack.ts +++ b/packages/core/src/versionStack/versionStack.ts @@ -58,7 +58,7 @@ export class VersionStackService { throw new Error('parent not found') } - const firstFile = files[0] + const firstFile = files.find((f) => f.id === fileIds[0]) const sortIndex = firstFile?.sortIndex || null const stack = await tx.asset.create({