Skip to content

Commit 17ebf86

Browse files
kaizenccgithub-actions
andauthored
fix(cli): acknowledge produces duplicate entries (#793)
Fixes #767 --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license --------- Signed-off-by: github-actions <[email protected]> Co-authored-by: github-actions <[email protected]>
1 parent 409f8e7 commit 17ebf86

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

packages/aws-cdk/lib/cli/cdk-toolkit.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ export class CdkToolkit {
206206
}
207207

208208
public async acknowledge(noticeId: string) {
209-
const acks = this.props.configuration.context.get('acknowledged-issue-numbers') ?? [];
210-
acks.push(Number(noticeId));
211-
this.props.configuration.context.set('acknowledged-issue-numbers', acks);
209+
const acks = new Set(this.props.configuration.context.get('acknowledged-issue-numbers') ?? []);
210+
acks.add(Number(noticeId));
211+
this.props.configuration.context.set('acknowledged-issue-numbers', Array.from(acks));
212212
await this.props.configuration.saveContext();
213213
}
214214

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { CdkToolkit } from '../../lib/cli/cdk-toolkit';
2+
import { CliIoHost } from '../../lib/cli/io-host';
3+
import { Configuration } from '../../lib/cli/user-configuration';
4+
5+
const ioHost = CliIoHost.instance({}, true);
6+
const ioHelper = ioHost.asIoHelper();
7+
8+
describe('acknowledge command', () => {
9+
let configuration: Configuration;
10+
let toolkit: CdkToolkit;
11+
12+
beforeEach(async () => {
13+
configuration = await Configuration.fromArgs(ioHelper);
14+
toolkit = new CdkToolkit({
15+
ioHost,
16+
configuration,
17+
sdkProvider: {} as any,
18+
cloudExecutable: {} as any,
19+
deployments: {} as any,
20+
});
21+
jest.clearAllMocks();
22+
});
23+
24+
test('acknowledge same ID twice', async () => {
25+
// WHEN
26+
await toolkit.acknowledge('12345');
27+
await toolkit.acknowledge('12345');
28+
29+
// THEN
30+
expect(configuration.context.get('acknowledged-issue-numbers')).toEqual([12345]);
31+
});
32+
});

0 commit comments

Comments
 (0)