fix: tighten session entry slot cleanup checks

This commit is contained in:
Eva
2026-05-01 23:08:31 +07:00
committed by Josh Lehman
parent 9d4633c460
commit 870babd252
3 changed files with 23 additions and 5 deletions

View File

@@ -162,8 +162,11 @@ describe("plugin session extension SessionEntry projection", () => {
}),
).resolves.toMatchObject({ ok: true });
expect(
(loadSessionStore(storePath, { skipCache: true })["agent:main:main"] as never)
.approvalSnapshot,
(
loadSessionStore(storePath, { skipCache: true })[
"agent:main:main"
] as unknown as Record<string, unknown>
).approvalSnapshot,
).toEqual({ state: "ready" });
await expect(
@@ -195,8 +198,11 @@ describe("plugin session extension SessionEntry projection", () => {
}),
).resolves.toMatchObject({ ok: true });
expect(
(loadSessionStore(storePath, { skipCache: true })["agent:main:main"] as never)
.approvalSnapshot,
(
loadSessionStore(storePath, { skipCache: true })[
"agent:main:main"
] as unknown as Record<string, unknown>
).approvalSnapshot,
).toEqual({ state: "ready-again" });
await expect(

View File

@@ -159,7 +159,11 @@ function collectSessionEntrySlotKeys(
if (!shouldCleanPlugin(registration.pluginId, pluginId)) {
continue;
}
const normalized = normalizeSessionEntrySlotKey(registration.extension.sessionEntrySlotKey);
const slotKey = registration.extension.sessionEntrySlotKey;
if (slotKey === undefined) {
continue;
}
const normalized = normalizeSessionEntrySlotKey(slotKey);
if (normalized.ok) {
slotKeys.add(normalized.key);
}

View File

@@ -103,6 +103,14 @@ const SESSION_ENTRY_RESERVED_SLOT_KEY_LIST = [
"acp",
] as const satisfies ReadonlyArray<keyof SessionEntry | "__proto__" | "constructor" | "prototype">;
type ReservedSessionEntrySlotKey = Extract<
(typeof SESSION_ENTRY_RESERVED_SLOT_KEY_LIST)[number],
keyof SessionEntry
>;
type MissingSessionEntryReservedSlotKeys = Exclude<keyof SessionEntry, ReservedSessionEntrySlotKey>;
type AssertNever<T extends never> = T;
type _AssertAllSessionEntryKeysAreReserved = AssertNever<MissingSessionEntryReservedSlotKeys>;
const SESSION_ENTRY_RESERVED_SLOT_KEYS = new Set<string>(SESSION_ENTRY_RESERVED_SLOT_KEY_LIST);
const SESSION_ENTRY_SLOT_KEY_RE = /^[A-Za-z][A-Za-z0-9_]*$/u;