Skip to content

Commit b5a3717

Browse files
fix(server): avoid deleting missing Slack trigger state
1 parent d67b1af commit b5a3717

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎apps/server/src/slack/SlackMentionTrigger.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,35 @@ it.effect("disable and account changes baseline historical mentions again", () =
189189
}).pipe(Effect.provide(KeyValueStore.layerMemory)),
190190
);
191191

192+
it.effect("disabled polling only removes durable state when it exists", () =>
193+
Effect.gen(function* () {
194+
const h = yield* harness;
195+
const backing = yield* KeyValueStore.KeyValueStore;
196+
let removals = 0;
197+
const trigger = yield* h.create.pipe(
198+
Effect.provideService(KeyValueStore.KeyValueStore, {
199+
...backing,
200+
remove: (key) => {
201+
removals++;
202+
return backing.remove(key);
203+
},
204+
}),
205+
);
206+
h.setSettings({ enabled: false });
207+
yield* trigger.pollOnce;
208+
yield* trigger.pollOnce;
209+
assert.strictEqual(removals, 0);
210+
h.setSettings({ enabled: true });
211+
yield* trigger.pollOnce;
212+
h.setSettings({ enabled: false });
213+
yield* trigger.pollOnce;
214+
yield* trigger.pollOnce;
215+
assert.strictEqual(removals, 1);
216+
assert.strictEqual(h.searches, 0);
217+
assert.strictEqual(h.launches.length, 0);
218+
}).pipe(Effect.provide(KeyValueStore.layerMemory)),
219+
);
220+
192221
it("matches explicit channel scope, optional DMs and literal whole-word keywords", () => {
193222
const config = {
194223
...DEFAULT_SERVER_SETTINGS.slackMentionTrigger,

‎apps/server/src/slack/SlackMentionTrigger.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export const make = Effect.gen(function* () {
160160
const projectId = settings.slackMentionTrigger.projectId;
161161
if (!isActive(settings) || projectId === null) {
162162
// Turning the trigger back on starts from that moment.
163-
yield* store.remove(STATE_KEY);
163+
if (yield* store.has(STATE_KEY)) yield* store.remove(STATE_KEY);
164164
return;
165165
}
166166
const account = yield* auth.account;

0 commit comments

Comments
 (0)