Skip to content

Commit 9386ac0

Browse files
fix(msteams): dedupe poll vote selections before maxSelections truncation (#123070)
* fix(msteams): dedupe poll vote selections before maxSelections truncation normalizeMSTeamsPollSelections truncated the raw selections to maxSelections before deduplicating, so a duplicated choice (e.g. an Adaptive Card posting "0,0,1") consumed multiple slots and starved later distinct choices: with maxSelections=2 the stored vote became ["0"] and choice "1" was silently dropped. Deduplicate first, then truncate. * fix(msteams): simplify poll selection normalization --------- Co-authored-by: ClawSweeper <[email protected]>
1 parent 59533cb commit 9386ac0

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎extensions/msteams/src/polls.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,29 @@ describe("msteams polls", () => {
7171
}
7272
expect(stored.votes["user-1"]).toEqual(["0"]);
7373
});
74+
75+
it("deduplicates selections before enforcing maxSelections", async () => {
76+
const home = await fs.promises.mkdtemp(path.join(os.tmpdir(), "openclaw-msteams-polls-"));
77+
const store = createMSTeamsPollStoreState({ homedir: () => home });
78+
await store.createPoll({
79+
id: "poll-dedupe",
80+
question: "Pick two",
81+
options: ["A", "B", "C"],
82+
maxSelections: 2,
83+
createdAt: new Date().toISOString(),
84+
votes: {},
85+
});
86+
await store.recordVote({
87+
pollId: "poll-dedupe",
88+
voterId: "user-1",
89+
selections: ["0", "0", "1"],
90+
});
91+
const stored = await store.getPoll("poll-dedupe");
92+
if (!stored) {
93+
throw new Error("expected stored poll after recordVote");
94+
}
95+
expect(stored.votes["user-1"]).toEqual(["0", "1"]);
96+
});
7497
});
7598

7699
describe("state poll store", () => {

‎extensions/msteams/src/polls.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ function normalizeMSTeamsPollSelections(poll: MSTeamsPoll, selections: string[])
298298
.filter((value): value is number => value !== undefined)
299299
.filter((value) => value >= 0 && value < poll.options.length)
300300
.map((value) => String(value));
301-
const limited = maxSelections > 1 ? mapped.slice(0, maxSelections) : mapped.slice(0, 1);
302-
return uniqueStrings(limited);
301+
// Deduplicate first so repeats do not consume selection slots.
302+
return uniqueStrings(mapped).slice(0, maxSelections);
303303
}
304304

305305
export function splitMSTeamsPoll(poll: MSTeamsPoll): {

0 commit comments

Comments
 (0)