@@ -21,6 +21,7 @@ type FakeProjectsService struct {
2121 ListFunc func (ctx context.Context , query kernel.ProjectListParams , opts ... option.RequestOption ) (* pagination.OffsetPagination [kernel.Project ], error )
2222 NewFunc func (ctx context.Context , body kernel.ProjectNewParams , opts ... option.RequestOption ) (* kernel.Project , error )
2323 GetFunc func (ctx context.Context , id string , opts ... option.RequestOption ) (* kernel.Project , error )
24+ UpdateFunc func (ctx context.Context , id string , body kernel.ProjectUpdateParams , opts ... option.RequestOption ) (* kernel.Project , error )
2425 DeleteFunc func (ctx context.Context , id string , opts ... option.RequestOption ) error
2526}
2627
@@ -45,6 +46,13 @@ func (f *FakeProjectsService) Get(ctx context.Context, id string, opts ...option
4546 return & kernel.Project {ID : id , Name : "default" }, nil
4647}
4748
49+ func (f * FakeProjectsService ) Update (ctx context.Context , id string , body kernel.ProjectUpdateParams , opts ... option.RequestOption ) (* kernel.Project , error ) {
50+ if f .UpdateFunc != nil {
51+ return f .UpdateFunc (ctx , id , body , opts ... )
52+ }
53+ return & kernel.Project {ID : id , Name : body .UpdateProjectRequest .Name .Value }, nil
54+ }
55+
4856func (f * FakeProjectsService ) Delete (ctx context.Context , id string , opts ... option.RequestOption ) error {
4957 if f .DeleteFunc != nil {
5058 return f .DeleteFunc (ctx , id , opts ... )
@@ -146,6 +154,116 @@ func TestProjectsGet_InvalidOutput(t *testing.T) {
146154 assert .Contains (t , err .Error (), "unsupported --output value" )
147155}
148156
157+ func TestProjectsUpdate_Success (t * testing.T ) {
158+ buf := capturePtermOutput (t )
159+ c := ProjectsCmd {
160+ projects : & FakeProjectsService {
161+ UpdateFunc : func (ctx context.Context , id string , body kernel.ProjectUpdateParams , opts ... option.RequestOption ) (* kernel.Project , error ) {
162+ assert .Equal (t , "a12345678901234567890123" , id )
163+ assert .True (t , body .UpdateProjectRequest .Name .Valid ())
164+ assert .Equal (t , "Renamed" , body .UpdateProjectRequest .Name .Value )
165+ return & kernel.Project {ID : id , Name : body .UpdateProjectRequest .Name .Value }, nil
166+ },
167+ },
168+ }
169+
170+ err := c .Update (context .Background (), ProjectsUpdateInput {
171+ Identifier : "a12345678901234567890123" ,
172+ Name : "Renamed" ,
173+ })
174+
175+ require .NoError (t , err )
176+ out := buf .String ()
177+ assert .Contains (t , out , "Updated project: Renamed" )
178+ assert .Contains (t , out , "a12345678901234567890123" )
179+ }
180+
181+ func TestProjectsUpdate_JSONOutput (t * testing.T ) {
182+ project := mustProject (t , `{"id":"a12345678901234567890123","name":"Renamed","status":"active","created_at":"2026-05-29T12:00:00Z","updated_at":"2026-05-29T12:30:00Z"}` )
183+ c := ProjectsCmd {
184+ projects : & FakeProjectsService {
185+ UpdateFunc : func (ctx context.Context , id string , body kernel.ProjectUpdateParams , opts ... option.RequestOption ) (* kernel.Project , error ) {
186+ assert .Equal (t , "a12345678901234567890123" , id )
187+ assert .True (t , body .UpdateProjectRequest .Name .Valid ())
188+ assert .Equal (t , "Renamed" , body .UpdateProjectRequest .Name .Value )
189+ return & project , nil
190+ },
191+ },
192+ }
193+
194+ var err error
195+ out := captureStdout (t , func () {
196+ err = c .Update (context .Background (), ProjectsUpdateInput {
197+ Identifier : "a12345678901234567890123" ,
198+ Name : "Renamed" ,
199+ Output : "json" ,
200+ })
201+ })
202+
203+ require .NoError (t , err )
204+ assert .JSONEq (t , `{"id":"a12345678901234567890123","name":"Renamed","status":"active","created_at":"2026-05-29T12:00:00Z","updated_at":"2026-05-29T12:30:00Z"}` , out )
205+ }
206+
207+ func TestProjectsUpdate_ResolvesName (t * testing.T ) {
208+ c := ProjectsCmd {
209+ projects : & FakeProjectsService {
210+ ListFunc : func (ctx context.Context , query kernel.ProjectListParams , opts ... option.RequestOption ) (* pagination.OffsetPagination [kernel.Project ], error ) {
211+ return & pagination.OffsetPagination [kernel.Project ]{
212+ Items : []kernel.Project {{ID : "a12345678901234567890123" , Name : "Default" }},
213+ }, nil
214+ },
215+ UpdateFunc : func (ctx context.Context , id string , body kernel.ProjectUpdateParams , opts ... option.RequestOption ) (* kernel.Project , error ) {
216+ assert .Equal (t , "a12345678901234567890123" , id )
217+ return & kernel.Project {ID : id , Name : body .UpdateProjectRequest .Name .Value }, nil
218+ },
219+ },
220+ }
221+
222+ err := c .Update (context .Background (), ProjectsUpdateInput {
223+ Identifier : "default" ,
224+ Name : "Renamed" ,
225+ })
226+
227+ require .NoError (t , err )
228+ }
229+
230+ func TestProjectsUpdate_RequiresName (t * testing.T ) {
231+ c := ProjectsCmd {
232+ projects : & FakeProjectsService {
233+ UpdateFunc : func (ctx context.Context , id string , body kernel.ProjectUpdateParams , opts ... option.RequestOption ) (* kernel.Project , error ) {
234+ t .Fatal ("Update should not be called" )
235+ return nil , nil
236+ },
237+ },
238+ }
239+
240+ err := c .Update (context .Background (), ProjectsUpdateInput {Identifier : "a12345678901234567890123" })
241+
242+ require .Error (t , err )
243+ assert .Contains (t , err .Error (), "--name is required" )
244+ assert .Contains (t , err .Error (), "add --name <name>" )
245+ }
246+
247+ func TestProjectsUpdate_InvalidOutput (t * testing.T ) {
248+ c := ProjectsCmd {
249+ projects : & FakeProjectsService {
250+ UpdateFunc : func (ctx context.Context , id string , body kernel.ProjectUpdateParams , opts ... option.RequestOption ) (* kernel.Project , error ) {
251+ t .Fatal ("Update should not be called" )
252+ return nil , nil
253+ },
254+ },
255+ }
256+
257+ err := c .Update (context .Background (), ProjectsUpdateInput {
258+ Identifier : "a12345678901234567890123" ,
259+ Name : "Renamed" ,
260+ Output : "yaml" ,
261+ })
262+
263+ require .Error (t , err )
264+ assert .Contains (t , err .Error (), "unsupported --output value" )
265+ }
266+
149267func TestProjectsLimitsGet_DefaultOutput (t * testing.T ) {
150268 buf := capturePtermOutput (t )
151269 limits := & kernel.ProjectLimits {
0 commit comments