Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep a real `order` when migration 269 converts a half-converted grid (#4133)
Adam Eivy49cf6b70a89f
diff --git a/scripts/migrations/269-dashboard-grid-order.js b/scripts/migrations/269-dashboard-grid-order.jsindex c5022a4b03..6ddbd3aa67 100644--- a/scripts/migrations/269-dashboard-grid-order.js+++ b/scripts/migrations/269-dashboard-grid-order.js@@ -35,13 +35,31 @@ const intOr = (v, fallback) => (Number.isFinite(v) ? Math.floor(v) : fallback);const isConverted = (grid) =>grid.every((g) => g && typeof g === 'object' && Number.isFinite(g.order) && g.y === undefined);-// Reading order — top-to-bottom, then left-to-right — is the order the-// renderer already packed these cells in, so replaying it preserves the-// layout the user last saw.+// Resolve the sequence, probing the SHAPE exactly the way+// `sequenceGrid` in `server/services/dashboardLayouts.js` does — the two must+// agree, or a file converted here would read back in a different order than+// the same file read before conversion:+// - Fully legacy: reading order — top-to-bottom, then left-to-right — is+// the order the renderer already packed these cells in, so replaying it+// preserves the layout the user last saw.+// - Any entry carrying `order`: that's the sequence. Entries without one go+// last in file order (where a widget-seeding migration means to append).+// Sorting a half-converted grid by `y` instead would discard a real+// sequence and scramble the layout.function toOrderedGrid(grid) {+ const anyOrder = grid.some((g) => Number.isFinite(g.order));return grid- .map((g, idx) => ({ g, idx, y: intOr(g?.y, 0), x: intOr(g?.x, 0) }))- .sort((a, b) => a.y - b.y || a.x - b.x || a.idx - b.idx)+ .map((g, idx) => ({+ g,+ idx,+ rank: anyOrder+ ? (Number.isFinite(g.order) ? Math.floor(g.order) : Number.MAX_SAFE_INTEGER)+ : intOr(g.y, 0),+ // Ties in legacy grids are side-by-side cells: column decides. Ties in+ // the new shape are corrupt data: file order decides.+ tie: anyOrder ? idx : intOr(g.x, 0),+ }))+ .sort((a, b) => a.rank - b.rank || a.tie - b.tie || a.idx - b.idx).map(({ g }, order) => {const next = { id: g.id, x: intOr(g.x, 0), w: intOr(g.w, 1), order };if (Number.isFinite(g.h)) next.h = Math.floor(g.h);diff --git a/scripts/migrations/269-dashboard-grid-order.test.js b/scripts/migrations/269-dashboard-grid-order.test.jsindex 22777900f7..8cc7263c6b 100644--- a/scripts/migrations/269-dashboard-grid-order.test.js+++ b/scripts/migrations/269-dashboard-grid-order.test.js@@ -106,6 +106,30 @@ describe('migration 269 — convert dashboard grids to the order-only shape', ()expect(grid.map((g) => g.order)).toEqual([0, 1]);});+ // The read path in `sequenceGrid` treats any grid carrying `order` as+ // new-shape. The migration has to probe the same way, or converting a file+ // would reorder it relative to how the server was already serving it.+ it('keeps a real `order` when a stale `y` disagrees with it', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'default',+ layouts: [{+ id: 'default', name: 'Everything', builtIn: true, widgets: ['alpha', 'beta', 'gamma'],+ grid: [+ // y says gamma is on top; order says it is last. order wins.+ { id: 'gamma', x: 0, y: 0, w: 12, order: 2, h: 3 },+ { id: 'alpha', x: 0, y: 9, w: 6, order: 0, h: 4 },+ // No sequence of its own — appended by a legacy seeding migration.+ { id: 'beta', x: 6, y: 0, w: 6, h: 2 },+ ],+ }],+ });++ expect((await migration.up({ rootDir })).updated).toBe(1);+ const grid = readJson(layoutsPath).layouts[0].grid;+ expect(grid.map((g) => g.id)).toEqual(['alpha', 'gamma', 'beta']);+ expect(grid.map((g) => g.order)).toEqual([0, 1, 2]);+ });+it('converts every layout in the file, and leaves empty grids alone', async () => {writeJson(layoutsPath, {activeLayoutId: 'focus',