Repository navigation
Stop publishing contributor emails in prompts.csv; squash HF history on sync #1401
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
4 commits
Select commit
Hold shift + click to select a range
2603ca4
Export usernames instead of emails in prompts.csv
cursoragent a0dc2a1
Never publish contributor emails from generate-contributors
cursoragent a8029d2
Guard against emails and squash Hugging Face history on sync
cursoragent c3a2c19
Replace contributor emails in prompts.csv with usernames
cursoragent 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,65 @@ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
| import { GET } from "@/app/prompts.csv/route"; | ||
| import { buildContributorField } from "@/lib/prompts-csv"; | ||
| import { db } from "@/lib/db"; | ||
|
|
||
| vi.mock("@/lib/db", () => ({ | ||
| db: { | ||
| prompt: { | ||
| findMany: vi.fn(), | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| const EMAIL_RE = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/; | ||
|
|
||
| function user(username: string, githubUsername: string | null = null) { | ||
| return { username, githubUsername }; | ||
| } | ||
|
|
||
| describe("buildContributorField", () => { | ||
| it("prefers the GitHub handle and falls back to the prompts.chat username", () => { | ||
| expect(buildContributorField(user("alice", "alice-gh"), [user("bob")])).toBe("alice-gh,bob"); | ||
| }); | ||
|
|
||
| it("dedupes, excludes the author and sorts co-contributors deterministically", () => { | ||
| const contributors = [user("zed"), user("amy"), user("zed"), user("alice", "alice-gh")]; | ||
| const field = buildContributorField(user("alice", "alice-gh"), contributors); | ||
| expect(field).toBe("alice-gh,amy,zed"); | ||
| expect(buildContributorField(user("alice", "alice-gh"), [...contributors].reverse())).toBe(field); | ||
| }); | ||
| }); | ||
|
|
||
| describe("GET /prompts.csv", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("never selects or emits email addresses", async () => { | ||
| vi.mocked(db.prompt.findMany).mockResolvedValue([ | ||
| { | ||
| title: "Linux Terminal", | ||
| content: "Act as a terminal", | ||
| structuredFormat: null, | ||
| category: { slug: "coding" }, | ||
| author: user("googleuser"), | ||
| contributors: [user("unclaimed_one"), user("ghuser", "GhUser")], | ||
| }, | ||
| ] as never); | ||
|
|
||
| const response = await GET(); | ||
| const body = await response.text(); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(body).toBe( | ||
| 'act,prompt,for_devs,type,contributor\nLinux Terminal,Act as a terminal,TRUE,TEXT,"googleuser,GhUser,unclaimed_one"' | ||
| ); | ||
| expect(body).not.toMatch(EMAIL_RE); | ||
|
|
||
| const args = vi.mocked(db.prompt.findMany).mock.calls[0][0] as { | ||
| select: { author: { select: Record<string, boolean> }; contributors: { select: Record<string, boolean> } }; | ||
| }; | ||
| expect(args.select.author.select).not.toHaveProperty("email"); | ||
| expect(args.select.contributors.select).not.toHaveProperty("email"); | ||
| }); | ||
| }); |
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,19 @@ | ||
| export interface CSVUser { | ||
| username: string; | ||
| githubUsername: string | null; | ||
| } | ||
|
|
||
| // The export is published (GitHub, Hugging Face), so it must never contain emails. | ||
| export function getUserIdentifier(user: CSVUser): string { | ||
| return user.githubUsername || user.username; | ||
| } | ||
|
|
||
| // Author first, then co-contributors deduplicated and sorted so the field is | ||
| // byte-stable across runs regardless of the order the database returns them in. | ||
| export function buildContributorField(author: CSVUser, contributors: CSVUser[]): string { | ||
| const authorId = getUserIdentifier(author); | ||
| const contributorIds = [...new Set(contributors.map(getUserIdentifier))] | ||
| .filter((id) => id && id !== authorId) | ||
| .sort(); | ||
| return [authorId, ...contributorIds].join(","); | ||
| } | ||
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.
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.
Keep email addresses out of the public contributor export.
getUserIdentifierreturnsusernamewhengithubUsernameis null. Account creation does not block@inusernameon every path. The OIDC and OAuth providers can setusernamefrompreferred_usernameornicknamewithout validation. The admin contributor import creates users from raw CSV strings without validation. An email-valuedusernamein any of these paths reaches/prompts.csvthroughbuildContributorField. The export does not filter it.escapeCSVFielddoes not remove@.The public export must not contain contributor emails. The sync-workflow guard does not cover this endpoint. Apply the rule at the export or at each account write path. Also clean up existing rows that already contain
@. Choose the handling policy for those rows explicitly.