Repository navigation
refactor(workqueue): centralize assignment receipt projections #67649
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 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cf91190
refactor(workqueue): share assignment receipt projections
pelikhan 9cb0ff4
docs(adr): add draft ADR for work-queue receipt projections
github-actions[bot] ac80e6f
docs(workqueue): clarify receipt projection contracts
pelikhan b62bef0
Merge remote-tracking branch 'origin/main' into pelikhan-work-queue-r…
Copilot 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
Next
Next commit
refactor(workqueue): share assignment receipt projections
Centralize payload-free identity projections in workqueue and retain CLI receipt aliases and captured lifecycle enrichment. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Loading branch information
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package workqueue | ||
|
|
||
| // AssignmentReceipt describes assignment identity and captured lifecycle facts | ||
| // without carrying work payloads, result descriptors, or actor credentials. | ||
| type AssignmentReceipt struct { | ||
| DispatchID string `json:"dispatch_id"` | ||
| RequestID string `json:"request_id"` | ||
| CommitID string `json:"commit_id"` | ||
| State string `json:"state"` | ||
| Released bool `json:"released"` | ||
| Claims []ClaimReceipt `json:"claims"` | ||
| } | ||
|
|
||
| type ClaimReceipt struct { | ||
| Handle string `json:"claim_handle"` | ||
| ClaimID string `json:"claim_id"` | ||
| WorkID string `json:"work_id"` | ||
| State string `json:"state"` | ||
| Barrier string `json:"delivery_barrier"` | ||
| } | ||
|
|
||
| // ToReceipt projects immutable identity only. Callers must validate the | ||
| // assignment and populate lifecycle facts from their captured projection. | ||
| func (assignment Assignment) ToReceipt() AssignmentReceipt { | ||
| receipt := AssignmentReceipt{ | ||
| DispatchID: assignment.DispatchID, | ||
| RequestID: assignment.RequestID, | ||
| CommitID: assignment.CommitID, | ||
| } | ||
| if assignment.Claims != nil { | ||
| receipt.Claims = make([]ClaimReceipt, 0, len(assignment.Claims)) | ||
| for _, claim := range assignment.Claims { | ||
| receipt.Claims = append(receipt.Claims, claim.ToReceipt()) | ||
| } | ||
| } | ||
| return receipt | ||
| } | ||
|
|
||
| // ToReceipt omits work payloads and result references; lifecycle fields are | ||
| // populated separately from the captured projection. | ||
| func (claim AssignmentClaim) ToReceipt() ClaimReceipt { | ||
| return ClaimReceipt{ | ||
| Handle: claim.Handle, | ||
| ClaimID: claim.ClaimID, | ||
| WorkID: claim.WorkID, | ||
| } | ||
| } |
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 @@ | ||
| package workqueue | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestAssignmentToReceipt(t *testing.T) { | ||
| t.Parallel() | ||
| assignment := Assignment{ | ||
| Version: 3, DispatchID: "dispatch", RequestID: "request", CommitID: "commit", | ||
| PolicyEpoch: "epoch", Pool: "pool", WorkerProfile: "profile", | ||
| Claims: []AssignmentClaim{ | ||
| {Handle: "h2", ClaimID: "c2", WorkID: "w2", Work: json.RawMessage(`{"private":"payload"}`), | ||
| ResultRefs: []ResultReference{{WorkID: "parent", ResultCommitID: "result", | ||
| Descriptor: json.RawMessage(`{"private":"descriptor"}`)}}}, | ||
| {Handle: "h1", ClaimID: "c1", WorkID: "w1"}, | ||
| }, | ||
| } | ||
| receipt := assignment.ToReceipt() | ||
| assert.Equal(t, AssignmentReceipt{ | ||
| DispatchID: "dispatch", RequestID: "request", CommitID: "commit", | ||
| Claims: []ClaimReceipt{ | ||
| {Handle: "h2", ClaimID: "c2", WorkID: "w2"}, | ||
| {Handle: "h1", ClaimID: "c1", WorkID: "w1"}, | ||
| }, | ||
| }, receipt) | ||
| data, err := json.Marshal(receipt) | ||
| require.NoError(t, err) | ||
| assert.JSONEq(t, `{ | ||
| "dispatch_id":"dispatch","request_id":"request","commit_id":"commit","state":"","released":false, | ||
| "claims":[ | ||
| {"claim_handle":"h2","claim_id":"c2","work_id":"w2","state":"","delivery_barrier":""}, | ||
| {"claim_handle":"h1","claim_id":"c1","work_id":"w1","state":"","delivery_barrier":""} | ||
| ] | ||
| }`, string(data)) | ||
| receipt.Claims[0].Handle = "changed" | ||
| assert.Equal(t, "h2", assignment.Claims[0].Handle, "receipts must not alias assignment claims") | ||
| } | ||
|
|
||
| func TestAssignmentToReceiptPreservesClaimsShape(t *testing.T) { | ||
| t.Parallel() | ||
| for _, test := range []struct { | ||
| name string | ||
| claims []AssignmentClaim | ||
| want string | ||
| }{ | ||
| {name: "nil", want: "null"}, | ||
| {name: "empty", claims: []AssignmentClaim{}, want: "[]"}, | ||
| } { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| receipt := (Assignment{Claims: test.claims}).ToReceipt() | ||
| data, err := json.Marshal(receipt) | ||
| require.NoError(t, err) | ||
| assert.JSONEq(t, `{"dispatch_id":"","request_id":"","commit_id":"","state":"","released":false,"claims":`+test.want+`}`, string(data)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestAssignmentClaimToReceipt(t *testing.T) { | ||
| t.Parallel() | ||
| claim := AssignmentClaim{ | ||
| Handle: "handle", ClaimID: "claim", WorkID: "work", | ||
| Work: json.RawMessage(`{"private":"payload"}`), | ||
| ResultRefs: []ResultReference{{Descriptor: json.RawMessage(`{"private":"descriptor"}`)}}, | ||
| } | ||
| receipt := claim.ToReceipt() | ||
| assert.Equal(t, ClaimReceipt{Handle: "handle", ClaimID: "claim", WorkID: "work"}, receipt) | ||
| data, err := json.Marshal(receipt) | ||
| require.NoError(t, err) | ||
| assert.JSONEq(t, `{"claim_handle":"handle","claim_id":"claim","work_id":"work","state":"","delivery_barrier":""}`, string(data)) | ||
| assert.Equal(t, ClaimReceipt{}, (AssignmentClaim{}).ToReceipt()) | ||
| } |
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.