fix(FN-2316): harden pi session message normalization

This commit is contained in:
Fusion
2026-04-23 23:38:05 -07:00
committed by gsxdsm
parent 49a5605454
commit 9c47ed07d7
3 changed files with 4 additions and 5 deletions

View File

@@ -598,13 +598,11 @@ describe("MissionStore", () => {
expect(events.events[0]).toEqual(event);
});
it("getMissionEvents supports pagination, filtering, and newest-first ordering", async () => {
it("getMissionEvents supports pagination, filtering, and newest-first ordering", () => {
const mission = store.createMission({ title: "Events mission" });
const first = store.logMissionEvent(mission.id, "mission_started", "first");
await new Promise((resolve) => setTimeout(resolve, 5));
const second = store.logMissionEvent(mission.id, "warning", "second warning");
await new Promise((resolve) => setTimeout(resolve, 5));
const third = store.logMissionEvent(mission.id, "error", "third error");
const pageOne = store.getMissionEvents(mission.id, { limit: 2, offset: 0 });

View File

@@ -937,7 +937,7 @@ export class MissionStore extends EventEmitter<MissionStoreEvents> {
SELECT *
FROM mission_events
WHERE ${whereSql}
ORDER BY timestamp DESC, id DESC
ORDER BY COALESCE(seq, 0) DESC, timestamp DESC, id DESC
LIMIT ? OFFSET ?
`).all(...params, limit, offset) as unknown as MissionEventRow[];

View File

@@ -9,6 +9,7 @@
* - Error isolation (plugin crashes don't crash the loader)
*/
import { randomUUID } from "node:crypto";
import { copyFile, unlink } from "node:fs/promises";
import { isAbsolute, parse, resolve } from "node:path";
import { pathToFileURL } from "node:url";
@@ -278,7 +279,7 @@ export class PluginLoader extends EventEmitter<{
const parsed = parse(path);
tempPath = resolve(
parsed.dir,
`${parsed.name}.fusion-import-${process.pid}-${++this.importNonce}${parsed.ext || ".js"}`,
`${parsed.name}.fusion-import-${process.pid}-${++this.importNonce}-${randomUUID()}${parsed.ext || ".js"}`,
);
await copyFile(path, tempPath);
importPath = tempPath;