Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/functions/slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,21 @@ async function seedDefaults(kv: StateKV): Promise<void> {
for (const tmpl of DEFAULT_SLOTS) {
const target = scopeKv(tmpl.scope);
const existing = await kv.get<MemorySlot>(target, tmpl.label);
if (existing) continue;
if (existing) {
if (existing.pinned !== tmpl.pinned) {
await kv.set(target, tmpl.label, {
...existing,
pinned: tmpl.pinned,
updatedAt: ts,
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
await recordAudit(kv, "slot_seed_reconcile", "seedDefaults", [tmpl.label], {
scope: tmpl.scope,
fromPinned: existing.pinned,
toPinned: tmpl.pinned,
});
}
continue;
}
const slot: MemorySlot = {
...tmpl,
createdAt: ts,
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ export interface AuditEntry {
| "slot_replace"
| "slot_create"
| "slot_delete"
| "slot_reflect";
| "slot_reflect"
| "slot_seed_reconcile";
userId?: string;
functionId: string;
targetIds: string[];
Expand Down
56 changes: 56 additions & 0 deletions test/slots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,59 @@ describe("slots — reflect", () => {
expect(patterns.slot.content).toMatch(/errors: 2/);
});
});


describe("slots — seedDefaults reconciles pinned on existing default-label slots", () => {
function wireWith(kv: ReturnType<typeof mockKV>) {
const handlers: Record<string, (d: Record<string, unknown>) => Promise<Record<string, unknown>>> = {};
const sdk = {
registerFunction: vi.fn((id: string, cb) => {
handlers[id] = cb;
}),
} as unknown as import("iii-sdk").ISdk;
registerSlotsFunctions(sdk, kv as never);
return handlers;
}

it("re-pins a default-label slot that was stored with pinned:false, preserving content", async () => {
const kv = mockKV();
await kv.set(KV.globalSlots, "persona", {
label: "persona",
content: "senior engineer persona",
sizeLimit: 1000,
description: "old description",
pinned: false,
readOnly: false,
scope: "global",
createdAt: "2026-01-01T00:00:00.000Z",
updatedAt: "2026-01-01T00:00:00.000Z",
});
wireWith(kv);
await waitForSeed(kv);
const persona = (await kv.get(KV.globalSlots, "persona")) as {
pinned: boolean;
content: string;
};
expect(persona.pinned).toBe(true);
expect(persona.content).toBe("senior engineer persona");
});

it("leaves a non-default custom slot untouched", async () => {
const kv = mockKV();
await kv.set(KV.slots, "my_custom", {
label: "my_custom",
content: "custom",
sizeLimit: 2000,
description: "",
pinned: false,
readOnly: false,
scope: "project",
createdAt: "2026-01-01T00:00:00.000Z",
updatedAt: "2026-01-01T00:00:00.000Z",
});
wireWith(kv);
await waitForSeed(kv);
const custom = (await kv.get(KV.slots, "my_custom")) as { pinned: boolean };
expect(custom.pinned).toBe(false);
});
});