-
Notifications
You must be signed in to change notification settings - Fork 11
feat(challenges): {success, error, reason, comment?, commentUpdate?} result shape (#88) #99
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
10 commits
Select commit
Hold shift + click to select a range
8569a79
feat(challenges): {success, error, reason, comment?, commentUpdate?} …
Rinse12 1ca4925
test(migration): bump expected DB version to 40 in v29/v36 migration …
Rinse12 370266f
test(challenges): pending-approval + commentUpdate.reason from challenge
Rinse12 3784bc5
test(signer): challenge-supplied reason survives sign + roundtrip to …
Rinse12 523540c
test(pending-approval): e2e author-side roundtrip of commentUpdate.re…
Rinse12 d5f4b4b
refactor(challenges): drop success-side `reason` from ChallengeResult…
Rinse12 aec803d
fix(challenges): omit unset aggregated keys from success return
Rinse12 20df244
test(challenges): document RPC-skip rationale on new suites
Rinse12 df823f9
feat(challenges): allow author.community extras via path-aware guard
Rinse12 d5fedd2
docs+test(challenges): clarify author.community allowed-keys note; sh…
Rinse12 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
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
76 changes: 76 additions & 0 deletions
76
src/runtime/node/community/challenges/validate-challenge-result.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,76 @@ | ||
| import { CommentSignedPropertyNames, CommentUpdateChallengeReservedFieldNames } from "../../../../publications/comment/schema.js"; | ||
| import { CommunityAuthorChallengeReservedFieldNames } from "../../../../schema/schema.js"; | ||
| import { PKCError } from "../../../../pkc-error.js"; | ||
| import type { ChallengeResult } from "../../../../community/types.js"; | ||
|
|
||
| // Throws when a challenge result tries to set a key that the protocol owns. | ||
| // - comment.<key>: forbidden if key is in CommentSignedPropertyNames (would invalidate the author's | ||
| // signature on CommentIpfs, since challenge fields are spread last into the IPFS-bound literal). | ||
| // - commentUpdate.<key>: forbidden if key is in CommentUpdateChallengeReservedFieldNames | ||
| // (community-computed fields: counts, cid, signature, updatedAt, etc.). | ||
| // - commentUpdate.author.<key>: only `community` is permitted (rest of author is signed identity). | ||
| // - commentUpdate.author.community.<key>: forbidden if key is in CommunityAuthorChallengeReservedFieldNames | ||
| // (computed scores/timestamps and mod-settable fields; mods own those via commentModeration). | ||
| export function validateChallengeResultExtras({ | ||
| challengeResult, | ||
| challengeIndex | ||
| }: { | ||
| challengeResult: ChallengeResult; | ||
| challengeIndex: number; | ||
| }): void { | ||
| if (!("success" in challengeResult) || challengeResult.success !== true) return; | ||
| if (challengeResult.comment) { | ||
| for (const key of Object.keys(challengeResult.comment)) { | ||
| if ((CommentSignedPropertyNames as readonly string[]).includes(key)) { | ||
| throw new PKCError("ERR_CHALLENGE_RESULT_OVERRIDES_COMMENT_SIGNED_FIELD", { | ||
| challengeIndex, | ||
| offendingKey: key | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| if (challengeResult.commentUpdate) { | ||
| for (const key of Object.keys(challengeResult.commentUpdate)) { | ||
| if ((CommentUpdateChallengeReservedFieldNames as readonly string[]).includes(key)) { | ||
| throw new PKCError("ERR_CHALLENGE_RESULT_OVERRIDES_RESERVED_COMMENT_UPDATE_FIELD", { | ||
| challengeIndex, | ||
| offendingKey: key | ||
| }); | ||
| } | ||
| } | ||
| const author = (challengeResult.commentUpdate as { author?: unknown }).author; | ||
| if (author !== undefined) { | ||
| if (typeof author !== "object" || author === null || Array.isArray(author)) { | ||
| throw new PKCError("ERR_CHALLENGE_RESULT_OVERRIDES_NON_COMMUNITY_AUTHOR_KEY", { | ||
| challengeIndex, | ||
| offendingKey: "author" | ||
| }); | ||
| } | ||
| for (const authorKey of Object.keys(author as Record<string, unknown>)) { | ||
| if (authorKey !== "community") { | ||
| throw new PKCError("ERR_CHALLENGE_RESULT_OVERRIDES_NON_COMMUNITY_AUTHOR_KEY", { | ||
| challengeIndex, | ||
| offendingKey: `author.${authorKey}` | ||
| }); | ||
| } | ||
| } | ||
| const community = (author as { community?: unknown }).community; | ||
| if (community !== undefined) { | ||
| if (typeof community !== "object" || community === null || Array.isArray(community)) { | ||
| throw new PKCError("ERR_CHALLENGE_RESULT_OVERRIDES_RESERVED_COMMUNITY_AUTHOR_FIELD", { | ||
| challengeIndex, | ||
| offendingKey: "author.community" | ||
| }); | ||
| } | ||
| for (const communityKey of Object.keys(community as Record<string, unknown>)) { | ||
| if ((CommunityAuthorChallengeReservedFieldNames as readonly string[]).includes(communityKey)) { | ||
| throw new PKCError("ERR_CHALLENGE_RESULT_OVERRIDES_RESERVED_COMMUNITY_AUTHOR_FIELD", { | ||
| challengeIndex, | ||
| offendingKey: `author.community.${communityKey}` | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
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.
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.
Preserve empty-string
reasonvalues during aggregation.Using truthy checks drops valid
reason: ""values. Use explicit!== undefinedchecks so all schema-valid reasons propagate consistently.Suggested fix
Also applies to: 807-810
🤖 Prompt for AI Agents