diff --git a/tests/OpenCode.Sdk.Tests/Config/ConfigDeclaredErrors.cs b/tests/OpenCode.Sdk.Tests/Config/ConfigDeclaredErrors.cs index e144d93f..e8ff2902 100644 --- a/tests/OpenCode.Sdk.Tests/Config/ConfigDeclaredErrors.cs +++ b/tests/OpenCode.Sdk.Tests/Config/ConfigDeclaredErrors.cs @@ -7,16 +7,26 @@ namespace OpenCode.Sdk.Tests.Config; public static class ConfigDeclaredErrors { + private static readonly DeclaredErrorDoor GetShellsDoor = new( + nameof(ConfigClient.GetShellsAsync), + "config.shells", + "get", + "/api/config/shell", + static async (client, options) => await client.Config.GetShellsAsync(options)); + + private static readonly DeclaredErrorDoor UpdateConfigDoor = new( + nameof(ExperimentalClient.UpdateConfigAsync), + "experimental.config.update", + "patch", + "/api/experimental/config", + static async (client, options) => await client.Experimental.UpdateConfigAsync( + new ExperimentalConfigUpdateRequest { Shell = null, }, options)); + public static IEnumerable> Rows() => [ static () => new( "config.shells:400:InvalidRequestError", - new DeclaredErrorDoor( - nameof(ConfigClient.GetShellsAsync), - "config.shells", - "get", - "/api/config/shell", - static async (client, options) => await client.Config.GetShellsAsync(options)), + GetShellsDoor, HttpStatusCode.BadRequest, WireBodyData.InvalidRequestError, "InvalidRequestError", @@ -24,12 +34,7 @@ static async (client, options) => await client.Config.GetShellsAsync(options)), "#/paths/~1api~1config~1shell/get/responses/400/content/application~1json/schema"), static () => new( "config.shells:401:UnauthorizedError", - new DeclaredErrorDoor( - nameof(ConfigClient.GetShellsAsync), - "config.shells", - "get", - "/api/config/shell", - static async (client, options) => await client.Config.GetShellsAsync(options)), + GetShellsDoor, HttpStatusCode.Unauthorized, WireBodyData.UnauthorizedError, "UnauthorizedError", @@ -37,13 +42,7 @@ static async (client, options) => await client.Config.GetShellsAsync(options)), "#/paths/~1api~1config~1shell/get/responses/401/content/application~1json/schema"), static () => new( "experimental.config.update:400:InvalidRequestError", - new DeclaredErrorDoor( - nameof(ExperimentalClient.UpdateConfigAsync), - "experimental.config.update", - "patch", - "/api/experimental/config", - static async (client, options) => await client.Experimental.UpdateConfigAsync( - new ExperimentalConfigUpdateRequest { Shell = null, }, options)), + UpdateConfigDoor, HttpStatusCode.BadRequest, WireBodyData.InvalidRequestError, "InvalidRequestError", @@ -51,13 +50,7 @@ static async (client, options) => await client.Experimental.UpdateConfigAsync( "#/paths/~1api~1experimental~1config/patch/responses/400/content/application~1json/schema"), static () => new( "experimental.config.update:401:UnauthorizedError", - new DeclaredErrorDoor( - nameof(ExperimentalClient.UpdateConfigAsync), - "experimental.config.update", - "patch", - "/api/experimental/config", - static async (client, options) => await client.Experimental.UpdateConfigAsync( - new ExperimentalConfigUpdateRequest { Shell = null, }, options)), + UpdateConfigDoor, HttpStatusCode.Unauthorized, WireBodyData.UnauthorizedError, "UnauthorizedError", diff --git a/tests/OpenCode.Sdk.Tests/Credentials/CredentialsDeclaredErrors.cs b/tests/OpenCode.Sdk.Tests/Credentials/CredentialsDeclaredErrors.cs index 173e2219..b1949c5e 100644 --- a/tests/OpenCode.Sdk.Tests/Credentials/CredentialsDeclaredErrors.cs +++ b/tests/OpenCode.Sdk.Tests/Credentials/CredentialsDeclaredErrors.cs @@ -7,22 +7,38 @@ namespace OpenCode.Sdk.Tests.Credentials; public static class CredentialsDeclaredErrors { + private static readonly DeclaredErrorDoor CreateCredentialDoor = new( + nameof(CredentialsClient.CreateCredentialAsync), + "credential.create", + "post", + "/api/credential", + static async (client, options) => await client.Credentials.CreateCredentialAsync( + new CredentialCreateRequest + { + Id = "cred_1", + IntegrationId = "openai", + Value = new CredentialKey { Key = "sk-test" }, + }, options)); + + private static readonly DeclaredErrorDoor ListCredentialsDoor = new( + nameof(CredentialsClient.ListCredentialsAsync), + "credential.list", + "get", + "/api/credential", + static async (client, options) => await client.Credentials.ListCredentialsAsync(options)); + + private static readonly DeclaredErrorDoor ActivateCredentialDoor = new( + nameof(CredentialsClient.ActivateCredentialAsync), + "credential.activate", + "post", + "/api/credential/{credentialID}/activate", + static async (client, options) => await client.Credentials.ActivateCredentialAsync("cred_1", options)); + public static IEnumerable> Rows() => [ static () => new( "credential.create:409:ConflictError", - new DeclaredErrorDoor( - nameof(CredentialsClient.CreateCredentialAsync), - "credential.create", - "post", - "/api/credential", - static async (client, options) => await client.Credentials.CreateCredentialAsync( - new CredentialCreateRequest - { - Id = "cred_1", - IntegrationId = "openai", - Value = new CredentialKey { Key = "sk-test" }, - }, options)), + CreateCredentialDoor, HttpStatusCode.Conflict, WireBodyData.ConflictError, "ConflictError", @@ -30,12 +46,7 @@ static async (client, options) => await client.Credentials.CreateCredentialAsync "#/paths/~1api~1credential/post/responses/409/content/application~1json/schema"), static () => new( "credential.list:401:UnauthorizedError", - new DeclaredErrorDoor( - nameof(CredentialsClient.ListCredentialsAsync), - "credential.list", - "get", - "/api/credential", - static async (client, options) => await client.Credentials.ListCredentialsAsync(options)), + ListCredentialsDoor, HttpStatusCode.Unauthorized, WireBodyData.UnauthorizedError, "UnauthorizedError", @@ -43,12 +54,7 @@ static async (client, options) => await client.Credentials.ListCredentialsAsync( "#/paths/~1api~1credential/get/responses/401/content/application~1json/schema"), static () => new( "credential.activate:400:InvalidRequestError", - new DeclaredErrorDoor( - nameof(CredentialsClient.ActivateCredentialAsync), - "credential.activate", - "post", - "/api/credential/{credentialID}/activate", - static async (client, options) => await client.Credentials.ActivateCredentialAsync("cred_1", options)), + ActivateCredentialDoor, HttpStatusCode.BadRequest, WireBodyData.InvalidRequestError, "InvalidRequestError", @@ -56,12 +62,7 @@ static async (client, options) => await client.Credentials.ActivateCredentialAsy "#/paths/~1api~1credential~1{credentialID}~1activate/post/responses/400/content/application~1json/schema"), static () => new( "credential.activate:401:UnauthorizedError", - new DeclaredErrorDoor( - nameof(CredentialsClient.ActivateCredentialAsync), - "credential.activate", - "post", - "/api/credential/{credentialID}/activate", - static async (client, options) => await client.Credentials.ActivateCredentialAsync("cred_1", options)), + ActivateCredentialDoor, HttpStatusCode.Unauthorized, WireBodyData.UnauthorizedError, "UnauthorizedError", diff --git a/tests/OpenCode.Sdk.Tests/Debug/DebugDeclaredErrors.cs b/tests/OpenCode.Sdk.Tests/Debug/DebugDeclaredErrors.cs index 5a003e7e..d89fc508 100644 --- a/tests/OpenCode.Sdk.Tests/Debug/DebugDeclaredErrors.cs +++ b/tests/OpenCode.Sdk.Tests/Debug/DebugDeclaredErrors.cs @@ -7,16 +7,18 @@ namespace OpenCode.Sdk.Tests.Debug; public static class DebugDeclaredErrors { + private static readonly DeclaredErrorDoor ListLocationsDoor = new( + nameof(DebugClient.ListLocationsAsync), + "debug.location.list", + "get", + "/api/debug/location", + static async (client, options) => await client.Debug.ListLocationsAsync(requestOptions: options)); + public static IEnumerable> Rows() => [ static () => new( "debug.location.list:400:InvalidRequestError", - new DeclaredErrorDoor( - nameof(DebugClient.ListLocationsAsync), - "debug.location.list", - "get", - "/api/debug/location", - static async (client, options) => await client.Debug.ListLocationsAsync(requestOptions: options)), + ListLocationsDoor, HttpStatusCode.BadRequest, WireBodyData.InvalidRequestError, "InvalidRequestError", @@ -24,12 +26,7 @@ static async (client, options) => await client.Debug.ListLocationsAsync(requestO "#/paths/~1api~1debug~1location/get/responses/400/content/application~1json/schema"), static () => new( "debug.location.list:401:UnauthorizedError", - new DeclaredErrorDoor( - nameof(DebugClient.ListLocationsAsync), - "debug.location.list", - "get", - "/api/debug/location", - static async (client, options) => await client.Debug.ListLocationsAsync(requestOptions: options)), + ListLocationsDoor, HttpStatusCode.Unauthorized, WireBodyData.UnauthorizedError, "UnauthorizedError", diff --git a/tests/OpenCode.Sdk.Tests/Experimental/ExperimentalDeclaredErrors.cs b/tests/OpenCode.Sdk.Tests/Experimental/ExperimentalDeclaredErrors.cs index 4029f738..d83db32f 100644 --- a/tests/OpenCode.Sdk.Tests/Experimental/ExperimentalDeclaredErrors.cs +++ b/tests/OpenCode.Sdk.Tests/Experimental/ExperimentalDeclaredErrors.cs @@ -7,21 +7,23 @@ namespace OpenCode.Sdk.Tests.Experimental; public static class ExperimentalDeclaredErrors { + private static readonly DeclaredErrorDoor WriteFileDoor = new( + nameof(ExperimentalClient.WriteFileAsync), + "experimental.fs.write", + "post", + "/api/experimental/fs/write", + static async (client, options) => + { + using var content = new MemoryStream([0x01]); + return await client.Experimental.WriteFileAsync( + new ExperimentalFsWriteRequest { Path = "a.bin" }, content, options); + }); + public static IEnumerable> Rows() => [ static () => new( "experimental.fs.write:400:InvalidRequestError", - new DeclaredErrorDoor( - nameof(ExperimentalClient.WriteFileAsync), - "experimental.fs.write", - "post", - "/api/experimental/fs/write", - static async (client, options) => - { - using var content = new MemoryStream([0x01]); - return await client.Experimental.WriteFileAsync( - new ExperimentalFsWriteRequest { Path = "a.bin" }, content, options); - }), + WriteFileDoor, HttpStatusCode.BadRequest, WireBodyData.InvalidRequestError, "InvalidRequestError", diff --git a/tests/OpenCode.Sdk.Tests/Forms/FormsDeclaredErrors.cs b/tests/OpenCode.Sdk.Tests/Forms/FormsDeclaredErrors.cs index 6635d4a8..827a03ff 100644 --- a/tests/OpenCode.Sdk.Tests/Forms/FormsDeclaredErrors.cs +++ b/tests/OpenCode.Sdk.Tests/Forms/FormsDeclaredErrors.cs @@ -7,16 +7,18 @@ namespace OpenCode.Sdk.Tests.Forms; public static class FormsDeclaredErrors { + private static readonly DeclaredErrorDoor ListFormsDoor = new( + nameof(FormsClient.ListFormsAsync), + "form.list", + "get", + "/api/form", + static async (client, options) => await client.Forms.ListFormsAsync(requestOptions: options)); + public static IEnumerable> Rows() => [ static () => new( "form.list:400:InvalidRequestError", - new DeclaredErrorDoor( - nameof(FormsClient.ListFormsAsync), - "form.list", - "get", - "/api/form", - static async (client, options) => await client.Forms.ListFormsAsync(requestOptions: options)), + ListFormsDoor, HttpStatusCode.BadRequest, WireBodyData.InvalidRequestError, "InvalidRequestError", @@ -24,12 +26,7 @@ static async (client, options) => await client.Forms.ListFormsAsync(requestOptio "#/paths/~1api~1form/get/responses/400/content/application~1json/schema"), static () => new( "form.list:401:UnauthorizedError", - new DeclaredErrorDoor( - nameof(FormsClient.ListFormsAsync), - "form.list", - "get", - "/api/form", - static async (client, options) => await client.Forms.ListFormsAsync(requestOptions: options)), + ListFormsDoor, HttpStatusCode.Unauthorized, WireBodyData.UnauthorizedError, "UnauthorizedError", diff --git a/tests/OpenCode.Sdk.Tests/Worktrees/WorktreesDeclaredErrors.cs b/tests/OpenCode.Sdk.Tests/Worktrees/WorktreesDeclaredErrors.cs index 4132ce3f..69ca07da 100644 --- a/tests/OpenCode.Sdk.Tests/Worktrees/WorktreesDeclaredErrors.cs +++ b/tests/OpenCode.Sdk.Tests/Worktrees/WorktreesDeclaredErrors.cs @@ -7,17 +7,19 @@ namespace OpenCode.Sdk.Tests.Worktrees; public static class WorktreesDeclaredErrors { + private static readonly DeclaredErrorDoor CreateWorktreeDoor = new( + nameof(WorktreesClient.CreateWorktreeAsync), + "worktree.create", + "post", + "/api/worktree", + static async (client, options) => await client.Worktrees.CreateWorktreeAsync( + new WorktreeCreateRequest { ProjectId = "prj_1", Directory = "/repo/feature" }, options)); + public static IEnumerable> Rows() => [ static () => new( "worktree.create:400:InvalidRequestError", - new DeclaredErrorDoor( - nameof(WorktreesClient.CreateWorktreeAsync), - "worktree.create", - "post", - "/api/worktree", - static async (client, options) => await client.Worktrees.CreateWorktreeAsync( - new WorktreeCreateRequest { ProjectId = "prj_1", Directory = "/repo/feature" }, options)), + CreateWorktreeDoor, HttpStatusCode.BadRequest, WireBodyData.InvalidRequestError, "InvalidRequestError",