Compare commits
1 commit
d377756988
...
c26ebb0f27
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c26ebb0f27 |
2 changed files with 2 additions and 44 deletions
|
|
@ -2,7 +2,7 @@ import { existsSync, rmSync } from "node:fs";
|
||||||
import { mkdtemp } from "node:fs/promises";
|
import { mkdtemp } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
import { afterEach, describe, expect, test } from "vitest";
|
||||||
import { genericDashboardFixture } from "$lib/model/fixtures/generic";
|
import { genericDashboardFixture } from "$lib/model/fixtures/generic";
|
||||||
import type { DashboardDocument } from "$lib/model";
|
import type { DashboardDocument } from "$lib/model";
|
||||||
import {
|
import {
|
||||||
|
|
@ -15,7 +15,6 @@ const stores: DashboardStore[] = [];
|
||||||
const tempRoots: string[] = [];
|
const tempRoots: string[] = [];
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.useRealTimers();
|
|
||||||
stores.splice(0).forEach((store) => store.close());
|
stores.splice(0).forEach((store) => store.close());
|
||||||
tempRoots.splice(0).forEach((path) => rmSync(path, { force: true, recursive: true }));
|
tempRoots.splice(0).forEach((path) => rmSync(path, { force: true, recursive: true }));
|
||||||
});
|
});
|
||||||
|
|
@ -131,40 +130,6 @@ describe("dashboard persistence store", () => {
|
||||||
"seed",
|
"seed",
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("assigns monotonic revision timestamps for stable history ordering", async () => {
|
|
||||||
vi.useFakeTimers();
|
|
||||||
vi.setSystemTime(new Date("2026-06-18T12:00:00.000Z"));
|
|
||||||
const { store } = await createTestStore();
|
|
||||||
const seed = store.seedDashboardIfEmpty(genericDashboardFixture, {
|
|
||||||
actor: "test-seed",
|
|
||||||
});
|
|
||||||
const updated = cloneDashboard({
|
|
||||||
...genericDashboardFixture,
|
|
||||||
metadata: {
|
|
||||||
...genericDashboardFixture.metadata,
|
|
||||||
title: "Changed Dashboard",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const commit = store.commitDashboard(updated, { actor: "agent" });
|
|
||||||
const rollback = store.rollbackToRevision(seed.id, { actor: "operator" });
|
|
||||||
|
|
||||||
expect([
|
|
||||||
seed.createdAt.toISOString(),
|
|
||||||
commit.createdAt.toISOString(),
|
|
||||||
rollback.createdAt.toISOString(),
|
|
||||||
]).toEqual([
|
|
||||||
"2026-06-18T12:00:00.000Z",
|
|
||||||
"2026-06-18T12:00:00.001Z",
|
|
||||||
"2026-06-18T12:00:00.002Z",
|
|
||||||
]);
|
|
||||||
expect(store.listRevisions().map((item) => item.id)).toEqual([
|
|
||||||
rollback.id,
|
|
||||||
commit.id,
|
|
||||||
seed.id,
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
async function createTestStore() {
|
async function createTestStore() {
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ class SqliteDashboardStore implements DashboardStore {
|
||||||
throw new DashboardPersistenceValidationError(migration.failure);
|
throw new DashboardPersistenceValidationError(migration.failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = this.nextRevisionTimestamp();
|
const now = new Date();
|
||||||
const revision: DashboardRevision = {
|
const revision: DashboardRevision = {
|
||||||
id: randomUUID(),
|
id: randomUUID(),
|
||||||
dashboardId: this.dashboardId,
|
dashboardId: this.dashboardId,
|
||||||
|
|
@ -230,13 +230,6 @@ class SqliteDashboardStore implements DashboardStore {
|
||||||
|
|
||||||
return revision;
|
return revision;
|
||||||
}
|
}
|
||||||
|
|
||||||
private nextRevisionTimestamp(): Date {
|
|
||||||
const active = this.getActiveDashboard();
|
|
||||||
const activeUpdatedAtMs = active?.updatedAt.getTime() || 0;
|
|
||||||
|
|
||||||
return new Date(Math.max(Date.now(), activeUpdatedAtMs + 1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DashboardRevisionRow = typeof dashboardRevisions.$inferSelect;
|
type DashboardRevisionRow = typeof dashboardRevisions.$inferSelect;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue