mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-27 09:21:35 +07:00
fix: replace stale canonical duplicate rows
This commit is contained in:
@@ -419,6 +419,34 @@ describe("gateway session utils", () => {
|
||||
expect(store["agent:main:Main"]).toBeUndefined();
|
||||
});
|
||||
|
||||
test("migrateAndPruneGatewaySessionStoreKey replaces a stale canonical row with a fresher duplicate", () => {
|
||||
const cfg = {
|
||||
session: { mainKey: "main" },
|
||||
agents: { list: [{ id: "main", default: true }] },
|
||||
} as OpenClawConfig;
|
||||
const store: Record<string, SessionEntry> = {
|
||||
"agent:main:main": {
|
||||
sessionId: "sess-stale",
|
||||
updatedAt: 1,
|
||||
} as SessionEntry,
|
||||
"agent:main:MAIN": {
|
||||
sessionId: "sess-fresh",
|
||||
updatedAt: 2,
|
||||
} as SessionEntry,
|
||||
};
|
||||
|
||||
const result = migrateAndPruneGatewaySessionStoreKey({
|
||||
cfg,
|
||||
key: "agent:main:main",
|
||||
store,
|
||||
});
|
||||
|
||||
expect(result.primaryKey).toBe("agent:main:main");
|
||||
expect(result.entry?.sessionId).toBe("sess-fresh");
|
||||
expect(store["agent:main:main"]?.sessionId).toBe("sess-fresh");
|
||||
expect(store["agent:main:MAIN"]).toBeUndefined();
|
||||
});
|
||||
|
||||
test("listAgentsForGateway rejects avatar symlink escapes outside workspace", () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "session-utils-avatar-outside-"));
|
||||
const workspace = path.join(root, "workspace");
|
||||
|
||||
@@ -482,12 +482,13 @@ export function migrateAndPruneGatewaySessionStoreKey(params: {
|
||||
store: params.store,
|
||||
});
|
||||
const primaryKey = target.canonicalKey;
|
||||
if (!params.store[primaryKey]) {
|
||||
const freshestMatch = resolveFreshestSessionStoreMatchFromStoreKeys(
|
||||
params.store,
|
||||
target.storeKeys,
|
||||
);
|
||||
if (freshestMatch) {
|
||||
const freshestMatch = resolveFreshestSessionStoreMatchFromStoreKeys(
|
||||
params.store,
|
||||
target.storeKeys,
|
||||
);
|
||||
if (freshestMatch) {
|
||||
const currentPrimary = params.store[primaryKey];
|
||||
if (!currentPrimary || (freshestMatch.entry.updatedAt ?? 0) > (currentPrimary.updatedAt ?? 0)) {
|
||||
params.store[primaryKey] = freshestMatch.entry;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user