mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-27 09:21:35 +07:00
fix: prefer freshest duplicate row promotion
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
listSessionsFromStore,
|
||||
loadCombinedSessionStoreForGateway,
|
||||
loadSessionEntry,
|
||||
migrateAndPruneGatewaySessionStoreKey,
|
||||
parseGroupKey,
|
||||
pruneLegacyStoreKeys,
|
||||
resolveGatewaySessionStoreTarget,
|
||||
@@ -389,6 +390,35 @@ describe("gateway session utils", () => {
|
||||
expect(Object.keys(store).toSorted()).toEqual(["agent:ops:work"]);
|
||||
});
|
||||
|
||||
test("migrateAndPruneGatewaySessionStoreKey promotes the freshest duplicate row", () => {
|
||||
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();
|
||||
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");
|
||||
|
||||
@@ -483,9 +483,12 @@ export function migrateAndPruneGatewaySessionStoreKey(params: {
|
||||
});
|
||||
const primaryKey = target.canonicalKey;
|
||||
if (!params.store[primaryKey]) {
|
||||
const existingKey = target.storeKeys.find((candidate) => Boolean(params.store[candidate]));
|
||||
if (existingKey) {
|
||||
params.store[primaryKey] = params.store[existingKey];
|
||||
const freshestMatch = resolveFreshestSessionStoreMatchFromStoreKeys(
|
||||
params.store,
|
||||
target.storeKeys,
|
||||
);
|
||||
if (freshestMatch) {
|
||||
params.store[primaryKey] = freshestMatch.entry;
|
||||
}
|
||||
}
|
||||
pruneLegacyStoreKeys({
|
||||
|
||||
Reference in New Issue
Block a user