Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite2db31a

Browse files
committed
Merge branch 'main' into mafredri/feat-coderd-tasks-logs
2 parents4d618c5 +252f430 commite2db31a

File tree

47 files changed

+3180
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3180
-81
lines changed

‎.github/workflows/typos.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[default]
22
extend-ignore-identifiers-re = ["gho_.*"]
3+
extend-ignore-re = ["(#|//)\\s*spellchecker:ignore-next-line\\n.*"]
34

45
[default.extend-identifiers]
56
alog ="alog"

‎Makefile‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,10 @@ TAILNETTEST_MOCKS := \
635635
tailnet/tailnettest/workspaceupdatesprovidermock.go\
636636
tailnet/tailnettest/subscriptionmock.go
637637

638+
AIBRIDGED_MOCKS :=\
639+
enterprise/x/aibridged/aibridgedmock/clientmock.go\
640+
enterprise/x/aibridged/aibridgedmock/poolmock.go
641+
638642
GEN_FILES :=\
639643
tailnet/proto/tailnet.pb.go\
640644
agent/proto/agent.pb.go\
@@ -660,7 +664,8 @@ GEN_FILES := \
660664
agent/agentcontainers/acmock/acmock.go\
661665
agent/agentcontainers/dcspec/dcspec_gen.go\
662666
coderd/httpmw/loggermw/loggermock/loggermock.go\
663-
codersdk/workspacesdk/agentconnmock/agentconnmock.go
667+
codersdk/workspacesdk/agentconnmock/agentconnmock.go\
668+
$(AIBRIDGED_MOCKS)
664669

665670
# all gen targets should be added here and to gen/mark-fresh
666671
gen: gen/db gen/golden-files$(GEN_FILES)
@@ -713,6 +718,7 @@ gen/mark-fresh:
713718
agent/agentcontainers/dcspec/dcspec_gen.go\
714719
coderd/httpmw/loggermw/loggermock/loggermock.go\
715720
codersdk/workspacesdk/agentconnmock/agentconnmock.go\
721+
$(AIBRIDGED_MOCKS)\
716722
"
717723

718724
for file in $$files; do
@@ -760,6 +766,10 @@ codersdk/workspacesdk/agentconnmock/agentconnmock.go: codersdk/workspacesdk/agen
760766
go generate ./codersdk/workspacesdk/agentconnmock/
761767
touch"$@"
762768

769+
$(AIBRIDGED_MOCKS): enterprise/x/aibridged/client.go enterprise/x/aibridged/pool.go
770+
go generate ./enterprise/x/aibridged/aibridgedmock/
771+
touch"$@"
772+
763773
agent/agentcontainers/dcspec/dcspec_gen.go:\
764774
node_modules/.installed\
765775
agent/agentcontainers/dcspec/devContainer.base.schema.json\

‎cli/exp_task.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func (r *RootCmd) tasksCommand() *serpent.Command {
1717
r.taskCreate(),
1818
r.taskStatus(),
1919
r.taskDelete(),
20+
r.taskSend(),
2021
},
2122
}
2223
returncmd

‎cli/exp_task_send.go‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package cli
2+
3+
import (
4+
"io"
5+
6+
"github.com/google/uuid"
7+
"golang.org/x/xerrors"
8+
9+
"github.com/coder/coder/v2/codersdk"
10+
"github.com/coder/serpent"
11+
)
12+
13+
func (r*RootCmd)taskSend()*serpent.Command {
14+
varstdinbool
15+
16+
cmd:=&serpent.Command{
17+
Use:"send <task> [<input> | --stdin]",
18+
Short:"Send input to a task",
19+
Middleware:serpent.RequireRangeArgs(1,2),
20+
Options: serpent.OptionSet{
21+
{
22+
Name:"stdin",
23+
Flag:"stdin",
24+
Description:"Reads the input from stdin.",
25+
Value:serpent.BoolOf(&stdin),
26+
},
27+
},
28+
Handler:func(inv*serpent.Invocation)error {
29+
client,err:=r.InitClient(inv)
30+
iferr!=nil {
31+
returnerr
32+
}
33+
34+
var (
35+
ctx=inv.Context()
36+
exp=codersdk.NewExperimentalClient(client)
37+
task=inv.Args[0]
38+
39+
taskInputstring
40+
taskID uuid.UUID
41+
)
42+
43+
ifstdin {
44+
bytes,err:=io.ReadAll(inv.Stdin)
45+
iferr!=nil {
46+
returnxerrors.Errorf("reading stdio: %w",err)
47+
}
48+
49+
taskInput=string(bytes)
50+
}else {
51+
iflen(inv.Args)!=2 {
52+
returnxerrors.Errorf("expected an input for the task")
53+
}
54+
55+
taskInput=inv.Args[1]
56+
}
57+
58+
ifid,err:=uuid.Parse(task);err==nil {
59+
taskID=id
60+
}else {
61+
ws,err:=namedWorkspace(ctx,client,task)
62+
iferr!=nil {
63+
returnxerrors.Errorf("resolve task: %w",err)
64+
}
65+
66+
taskID=ws.ID
67+
}
68+
69+
iferr=exp.TaskSend(ctx,codersdk.Me,taskID, codersdk.TaskSendRequest{Input:taskInput});err!=nil {
70+
returnxerrors.Errorf("send input to task: %w",err)
71+
}
72+
73+
returnnil
74+
},
75+
}
76+
77+
returncmd
78+
}

‎cli/exp_task_send_test.go‎

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
package cli_test
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
"net/http/httptest"
8+
"strings"
9+
"testing"
10+
11+
"github.com/google/uuid"
12+
"github.com/stretchr/testify/assert"
13+
14+
"github.com/coder/coder/v2/cli/clitest"
15+
"github.com/coder/coder/v2/coderd/httpapi"
16+
"github.com/coder/coder/v2/codersdk"
17+
"github.com/coder/coder/v2/testutil"
18+
)
19+
20+
funcTest_TaskSend(t*testing.T) {
21+
t.Parallel()
22+
23+
var (
24+
taskName="task-workspace"
25+
taskID=uuid.MustParse("11111111-1111-1111-1111-111111111111")
26+
)
27+
28+
tests:= []struct {
29+
args []string
30+
stdinstring
31+
expectErrorstring
32+
handlerfunc(t*testing.T,ctx context.Context) http.HandlerFunc
33+
}{
34+
{
35+
args: []string{taskName,"carry on with the task"},
36+
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
37+
returnfunc(w http.ResponseWriter,r*http.Request) {
38+
switchr.URL.Path {
39+
casefmt.Sprintf("/api/v2/users/me/workspace/%s",taskName):
40+
httpapi.Write(ctx,w,http.StatusOK, codersdk.Workspace{
41+
ID:taskID,
42+
})
43+
casefmt.Sprintf("/api/experimental/tasks/me/%s/send",taskID.String()):
44+
varreq codersdk.TaskSendRequest
45+
if!httpapi.Read(ctx,w,r,&req) {
46+
return
47+
}
48+
49+
assert.Equal(t,"carry on with the task",req.Input)
50+
51+
httpapi.Write(ctx,w,http.StatusNoContent,nil)
52+
default:
53+
t.Errorf("unexpected path: %s",r.URL.Path)
54+
}
55+
}
56+
},
57+
},
58+
{
59+
args: []string{taskID.String(),"carry on with the task"},
60+
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
61+
returnfunc(w http.ResponseWriter,r*http.Request) {
62+
switchr.URL.Path {
63+
casefmt.Sprintf("/api/experimental/tasks/me/%s/send",taskID.String()):
64+
varreq codersdk.TaskSendRequest
65+
if!httpapi.Read(ctx,w,r,&req) {
66+
return
67+
}
68+
69+
assert.Equal(t,"carry on with the task",req.Input)
70+
71+
httpapi.Write(ctx,w,http.StatusNoContent,nil)
72+
default:
73+
t.Errorf("unexpected path: %s",r.URL.Path)
74+
}
75+
}
76+
},
77+
},
78+
{
79+
args: []string{taskName,"--stdin"},
80+
stdin:"carry on with the task",
81+
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
82+
returnfunc(w http.ResponseWriter,r*http.Request) {
83+
switchr.URL.Path {
84+
casefmt.Sprintf("/api/v2/users/me/workspace/%s",taskName):
85+
httpapi.Write(ctx,w,http.StatusOK, codersdk.Workspace{
86+
ID:taskID,
87+
})
88+
casefmt.Sprintf("/api/experimental/tasks/me/%s/send",taskID.String()):
89+
varreq codersdk.TaskSendRequest
90+
if!httpapi.Read(ctx,w,r,&req) {
91+
return
92+
}
93+
94+
assert.Equal(t,"carry on with the task",req.Input)
95+
96+
httpapi.Write(ctx,w,http.StatusNoContent,nil)
97+
default:
98+
t.Errorf("unexpected path: %s",r.URL.Path)
99+
}
100+
}
101+
},
102+
},
103+
{
104+
args: []string{"doesnotexist","some task input"},
105+
expectError:httpapi.ResourceNotFoundResponse.Message,
106+
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
107+
returnfunc(w http.ResponseWriter,r*http.Request) {
108+
switchr.URL.Path {
109+
case"/api/v2/users/me/workspace/doesnotexist":
110+
httpapi.ResourceNotFound(w)
111+
default:
112+
t.Errorf("unexpected path: %s",r.URL.Path)
113+
}
114+
}
115+
},
116+
},
117+
{
118+
args: []string{uuid.Nil.String(),"some task input"},
119+
expectError:httpapi.ResourceNotFoundResponse.Message,
120+
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
121+
returnfunc(w http.ResponseWriter,r*http.Request) {
122+
switchr.URL.Path {
123+
casefmt.Sprintf("/api/experimental/tasks/me/%s/send",uuid.Nil.String()):
124+
httpapi.ResourceNotFound(w)
125+
default:
126+
t.Errorf("unexpected path: %s",r.URL.Path)
127+
}
128+
}
129+
},
130+
},
131+
{
132+
args: []string{uuid.Nil.String(),"some task input"},
133+
expectError:assert.AnError.Error(),
134+
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
135+
returnfunc(w http.ResponseWriter,r*http.Request) {
136+
switchr.URL.Path {
137+
casefmt.Sprintf("/api/experimental/tasks/me/%s/send",uuid.Nil.String()):
138+
httpapi.InternalServerError(w,assert.AnError)
139+
default:
140+
t.Errorf("unexpected path: %s",r.URL.Path)
141+
}
142+
}
143+
},
144+
},
145+
}
146+
147+
for_,tt:=rangetests {
148+
t.Run(strings.Join(tt.args,","),func(t*testing.T) {
149+
t.Parallel()
150+
151+
var (
152+
ctx=testutil.Context(t,testutil.WaitShort)
153+
srv=httptest.NewServer(tt.handler(t,ctx))
154+
client=codersdk.New(testutil.MustURL(t,srv.URL))
155+
args= []string{"exp","task","send"}
156+
errerror
157+
)
158+
159+
t.Cleanup(srv.Close)
160+
161+
inv,root:=clitest.New(t,append(args,tt.args...)...)
162+
inv.Stdin=strings.NewReader(tt.stdin)
163+
clitest.SetupConfig(t,client,root)
164+
165+
err=inv.WithContext(ctx).Run()
166+
iftt.expectError=="" {
167+
assert.NoError(t,err)
168+
}else {
169+
assert.ErrorContains(t,err,tt.expectError)
170+
}
171+
})
172+
}
173+
}

‎coderd/aitasks.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ func (api *API) taskSend(rw http.ResponseWriter, r *http.Request) {
675675
})
676676
}
677677

678-
ifv,ok:=respBody["status"].(string);!ok||v!="ok" {
678+
ifv,ok:=respBody["ok"].(bool);!ok||!v {
679679
returnhttperror.NewResponseError(http.StatusBadGateway, codersdk.Response{
680680
Message:"Task app rejected the message.",
681681
Detail:fmt.Sprintf("Upstream response: %v",respBody),

‎coderd/aitasks_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ func TestTasks(t *testing.T) {
449449
assert.Equal(t,`{"content":"Hello, Agent!","type":"user"}`,string(b),"expected message content")
450450

451451
w.WriteHeader(http.StatusOK)
452-
io.WriteString(w,`{"status":"ok"}`)
452+
io.WriteString(w,`{"ok":true}`)
453453
return
454454
}
455455
w.WriteHeader(http.StatusInternalServerError)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp