Repository navigation
fix(social): verify weekly claims by uploaded artifact ID #716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,8 @@ describe('weekly social posts', () => { | |
|
|
||
| describe('posting identity', () => { | ||
| const credentials = { consumerKey: 'key', consumerSecret: 'secret', accessToken: 'token', accessSecret: 'token-secret' } | ||
| const claim = { id: 14861832971, name: 'skilld-weekly-discord-2026-11-23', expired: false, workflow_run: { id: 45264333491 } } | ||
| const expectedClaim = { artifactId: String(claim.id), name: claim.name, runId: String(claim.workflow_run.id) } | ||
| it('signs the RFC 5849 reference request', () => { | ||
| const header = oauthHeader('GET', 'http://photos.example.net/photos?file=vacation.jpg&size=original', { | ||
| consumerKey: 'dpf43f3p2l4k3l03', | ||
|
|
@@ -122,10 +124,11 @@ describe('posting identity', () => { | |
| await expect(verifySocialDestination({ _tag: 'discord', webhookUrl: 'https://discord.com/api/webhooks/1/token', channelId: '2' }, fetchImpl)).rejects.toThrow('Discord webhook belongs to another server or channel') | ||
| }) | ||
|
|
||
| it('publishes to the checked Discord channel and returns its confirmed message ID', async () => { | ||
| it('publishes with the uploaded claim and returns the checked Discord channel message ID', async () => { | ||
| const fetchImpl = vi.fn<typeof fetch>() | ||
| .mockResolvedValueOnce(Response.json({ guild_id: '931135234261532713', channel_id: '2' })) | ||
| .mockResolvedValueOnce(Response.json({ id: '123' })) | ||
| assertWeeklyClaim(claim, expectedClaim) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trivial (35/100): Publish test bypasses artifact lookup and claim enforcement The test calls assertWeeklyClaim with a hard-coded artifact, then calls publishWeeklySocial separately. It never exercises the publishing command that reads the upload output and fetches the artifact. The test would still pass if that command ignored the artifact ID, used the list endpoint, or skipped claim verification. Add a publish-entry-point test that verifies the artifact request and blocks the destination POST for a mismatched claim.
|
||
| const result = await publishWeeklySocial({ _tag: 'discord', webhookUrl: 'https://discord.com/api/webhooks/1/token', channelId: '2' }, buildWeeklySocial([skill], now), fetchImpl) | ||
| expect(result).toEqual({ _tag: 'sent', id: '123' }) | ||
| expect(fetchImpl.mock.calls[1]?.[0]).toBe('https://discord.com/api/webhooks/1/token?wait=true') | ||
|
|
@@ -140,9 +143,12 @@ describe('posting identity', () => { | |
| expect(fetchImpl).toHaveBeenCalledTimes(2) | ||
| }) | ||
|
|
||
| it('requires a persisted claim owned by this run before sending', () => { | ||
| expect(() => assertWeeklyClaim({ total_count: 0, artifacts: [] }, '42')).toThrow('This run does not own the weekly claim') | ||
| expect(() => assertWeeklyClaim({ total_count: 1, artifacts: [{ workflow_run: { id: 41 } }] }, '42')).toThrow('This run does not own the weekly claim') | ||
| assertWeeklyClaim({ total_count: 1, artifacts: [{ workflow_run: { id: 42 } }] }, '42') | ||
| it.each([ | ||
| { ...claim, id: 14861832972 }, | ||
| { ...claim, name: 'skilld-weekly-x-2026-11-23' }, | ||
| { ...claim, expired: true }, | ||
| { ...claim, workflow_run: { id: 45264333490 } }, | ||
| ])('rejects a claim that does not match the upload, week, destination, or run: %j', (artifact) => { | ||
| expect(() => assertWeeklyClaim(artifact, expectedClaim)).toThrow('This run does not own the weekly claim') | ||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor (78/100): A stale prepare lookup can allow duplicate weekly posts
If a queued or manually dispatched run gets a stale zero-count result from the prepare lookup after a prior run has sent, it can upload another artifact with the same destination and week. GitHub permits the same artifact name in separate runs. The destination lock serializes the jobs, but the new publish check accepts each run's own artifact and no longer requires a unique claim. Both runs can post publicly.
Require a fresh name lookup for prior claims before uploading under the existing destination lock, and keep the direct artifact check before sending.