From 19c3a270fa3921c0a0a17ddfdfbf1c19696114c8 Mon Sep 17 00:00:00 2001 From: Yichen Jiang Date: Sun, 30 Aug 2026 12:08:52 +0800 Subject: [PATCH] test(agent-presets): key mounted-row assertions by entry id The loader's entry store is a plain object, so an auto-generated all-digit id is reordered ahead of its siblings by integer-key semantics and the previous ordered assertion flipped on roughly one in fifteen runs. Row ordering belongs to loader.entries(), not to this projection; the spec now asserts each row by its id. --- .../tests/composition-inventory.spec.ts | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/preset/agent-presets/tests/composition-inventory.spec.ts b/packages/preset/agent-presets/tests/composition-inventory.spec.ts index 9204503d05..fa6cdf596a 100644 --- a/packages/preset/agent-presets/tests/composition-inventory.spec.ts +++ b/packages/preset/agent-presets/tests/composition-inventory.spec.ts @@ -177,17 +177,24 @@ describe('mountedCompositionRows', () => { }) await ctx.loader.create({ name: 'cordis:active', group: true }) - expect(mountedCompositionRows(ctx.loader)).toEqual([ - { entryId: activeId, moduleName: 'cordis:active', enabled: true, fiberState: FiberState.ACTIVE }, - { entryId: disabledId, moduleName: 'cordis:active', enabled: false }, - { - entryId: evaluatedId, - moduleName: 'cordis:active', - enabled: true, - condition: 'false', - fiberState: FiberState.ACTIVE, - }, - ]) + // Keyed rather than ordered: rows follow `loader.entries()`, whose plain + // object store reorders an auto-generated all-digit id ahead of its + // siblings by integer-key semantics — ordering is the store's contract, + // not this projection's. + const rows = mountedCompositionRows(ctx.loader) + const byId = new Map(rows.map(row => [row.entryId, row])) + expect(rows).toHaveLength(3) + expect(byId.get(activeId)).toEqual( + { entryId: activeId, moduleName: 'cordis:active', enabled: true, fiberState: FiberState.ACTIVE }) + expect(byId.get(disabledId)).toEqual( + { entryId: disabledId, moduleName: 'cordis:active', enabled: false }) + expect(byId.get(evaluatedId)).toEqual({ + entryId: evaluatedId, + moduleName: 'cordis:active', + enabled: true, + condition: 'false', + fiberState: FiberState.ACTIVE, + }) }) })