-
Notifications
You must be signed in to change notification settings - Fork 672
feat: allow read-only shares to read A2A tasks #2191
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
EItanya
merged 4 commits into
kagent-dev:main
from
QuentinBisson:feat/a2a-readonly-share-reads
Jul 21, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4ffd86b
feat: allow read-only shares to read A2A tasks
QuentinBisson 8e8bda1
Merge branch 'main' into feat/a2a-readonly-share-reads
EItanya 8b2b377
Merge branch 'main' into feat/a2a-readonly-share-reads
QuentinBisson b5cb525
Merge branch 'main' into feat/a2a-readonly-share-reads
QuentinBisson 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package a2a | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| a2atype "github.com/a2aproject/a2a-go/v2/a2a" | ||
| pkgauth "github.com/kagent-dev/kagent/go/core/pkg/auth" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func ctxWithShare(userID string, readOnly bool) context.Context { | ||
| return pkgauth.ShareContextTo(ctxWithUser(userID), &pkgauth.ShareContext{ | ||
| Token: "tok", | ||
| SessionID: "sess-1", | ||
| UserID: "owner-id", | ||
| ReadOnly: readOnly, | ||
| }) | ||
| } | ||
|
|
||
| func TestRequireWritableShare(t *testing.T) { | ||
| require.NoError(t, requireWritableShare(context.Background()), "no share token: allowed") | ||
| require.NoError(t, requireWritableShare(ctxWithShare("caller", false)), "read-write share: allowed") | ||
| require.Error(t, requireWritableShare(ctxWithShare("caller", true)), "read-only share: rejected") | ||
| } | ||
|
|
||
| // A read-only share must not reach the upstream client on any mutating method. | ||
| // The handler is built with a nil client on purpose: the guard has to return | ||
| // before any client call, so a nil dereference would mean the guard is missing. | ||
| func TestReadOnlyShareRejectsWrites(t *testing.T) { | ||
| h := &PassthroughRequestHandler{} | ||
| ctx := ctxWithShare("caller", true) | ||
|
|
||
| _, err := h.CancelTask(ctx, &a2atype.CancelTaskRequest{}) | ||
| require.Error(t, err, "CancelTask") | ||
|
|
||
| _, err = h.SendMessage(ctx, &a2atype.SendMessageRequest{}) | ||
| require.Error(t, err, "SendMessage") | ||
|
|
||
| _, err = h.CreateTaskPushConfig(ctx, &a2atype.PushConfig{}) | ||
| require.Error(t, err, "CreateTaskPushConfig") | ||
|
|
||
| err = h.DeleteTaskPushConfig(ctx, &a2atype.DeleteTaskPushConfigRequest{}) | ||
| require.Error(t, err, "DeleteTaskPushConfig") | ||
|
|
||
| var streamErr error | ||
| for _, e := range h.SendStreamingMessage(ctx, &a2atype.SendMessageRequest{}) { | ||
| streamErr = e | ||
| break | ||
| } | ||
| require.Error(t, streamErr, "SendStreamingMessage") | ||
| } |
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.
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.
Why not return an error here like the other functions?
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.
SendStreamingMessagereturnsiter.Seq2[a2atype.Event, error], not(result, error), so there's no error return to hand back here.With this interface the only way to surface the error to the caller is to yield it from the sequence, which is what the closure does.