-
Notifications
You must be signed in to change notification settings - Fork 1
fix: ungate anonymous Video Pack v0 emit on paste-URL #1612
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
apps/web/src/app/api/v1/video/pack/__tests__/route.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
| import { GOLDEN_IDENTITY_HASHES } from '@/lib/video-pack'; | ||
|
|
||
| const CANON_B = 'jNQXAC9IVRw'; | ||
|
|
||
| afterEach(() => { | ||
| vi.resetModules(); | ||
| vi.unstubAllGlobals(); | ||
| }); | ||
|
|
||
| function postRequest(body: unknown) { | ||
| return new Request('http://localhost:3000/api/v1/video/pack', { | ||
| method: 'POST', | ||
| headers: { 'content-type': 'application/json' }, | ||
| body: JSON.stringify(body), | ||
| }); | ||
| } | ||
|
|
||
| describe('POST /api/v1/video/pack', () => { | ||
| it('emits the same identity pack as /api/video/pack without a transcript', async () => { | ||
| const { POST } = await import('../route'); | ||
| const res = await POST( | ||
| postRequest({ url: 'https://www.youtube.com/watch?v=jNQXAC9IVRw' }), | ||
| ); | ||
| expect(res.status).toBe(200); | ||
| const body = (await res.json()) as { | ||
| status: string; | ||
| data: { | ||
| version: string; | ||
| video_id: string; | ||
| source_url: string; | ||
| transcript: { full_text: string; segments: unknown[] }; | ||
| provenance: { source_hash: string }; | ||
| }; | ||
| }; | ||
| expect(body.status).toBe('success'); | ||
| expect(body.data.version).toBe('v0'); | ||
| expect(body.data.video_id).toBe(CANON_B); | ||
| expect(body.data.source_url).toBe('https://www.youtube.com/watch?v=jNQXAC9IVRw'); | ||
| expect(body.data.provenance.source_hash).toBe(GOLDEN_IDENTITY_HASHES[CANON_B]); | ||
| expect(body.data.transcript.full_text).toBe(`cite:youtube:${CANON_B}`); | ||
| expect(body.data.transcript.segments).toEqual([]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { POST, runtime } from '../../../video/pack/route'; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { GOLDEN_IDENTITY_HASHES } from '@/lib/video-pack'; | ||
| import { identityPackJson, verifyIdentityPack } from '@/lib/emit-video-pack'; | ||
|
|
||
| const CANON = 'jNQXAC9IVRw'; | ||
| const SOURCE_URL = `https://www.youtube.com/watch?v=${CANON}`; | ||
| const HASH = GOLDEN_IDENTITY_HASHES[CANON]; | ||
|
|
||
| const VALID = { | ||
| status: 'success', | ||
| data: { | ||
| version: 'v0', | ||
| id: `vp:v0:${CANON}`, | ||
| video_id: CANON, | ||
| source_url: SOURCE_URL, | ||
| transcript: { full_text: `cite:youtube:${CANON}`, segments: [] }, | ||
| provenance: { source_hash: HASH }, | ||
| }, | ||
| }; | ||
|
|
||
| describe('verifyIdentityPack (CoS: fail closed)', () => { | ||
| it('accepts a v0 pack with source_url and source_hash', () => { | ||
| const citation = verifyIdentityPack(VALID); | ||
| expect(citation.sourceUrl).toBe(SOURCE_URL); | ||
| expect(citation.sourceHash).toBe(HASH); | ||
| expect(citation.videoId).toBe(CANON); | ||
| expect(citation.pack.source_url).toBe(SOURCE_URL); | ||
| expect(citation.pack.provenance.source_hash).toBe(HASH); | ||
| expect(identityPackJson(citation)).toContain(SOURCE_URL); | ||
| expect(identityPackJson(citation)).toContain(HASH); | ||
| }); | ||
|
|
||
| it('fails closed when source_url is missing', () => { | ||
| const { source_url: _omit, ...data } = VALID.data; | ||
| expect(() => verifyIdentityPack({ status: 'success', data })).toThrow(/source_url/i); | ||
| }); | ||
|
|
||
| it('fails closed when source_hash is missing', () => { | ||
| expect(() => | ||
| verifyIdentityPack({ | ||
| status: 'success', | ||
| data: { ...VALID.data, provenance: {} }, | ||
| }), | ||
| ).toThrow(/source_hash/i); | ||
| }); | ||
|
|
||
| it('fails closed on an empty or 401 payload', () => { | ||
| expect(() => verifyIdentityPack({ error: 'Authentication required' })).toThrow(/verif/i); | ||
| expect(() => verifyIdentityPack(null)).toThrow(/verif/i); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Re-exporting the
runtimeroute segment config from another module breaks the Next.js build