Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 19 additions & 26 deletions tests/OpenCode.Sdk.Tests/Config/ConfigDeclaredErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,50 @@ 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<Func<DeclaredErrorCase>> 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",
typeof(InvalidRequestError),
"#/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",
typeof(UnauthorizedError),
"#/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",
typeof(InvalidRequestError),
"#/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",
Expand Down
61 changes: 31 additions & 30 deletions tests/OpenCode.Sdk.Tests/Credentials/CredentialsDeclaredErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,62 @@ 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<Func<DeclaredErrorCase>> 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",
typeof(ConflictError),
"#/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",
typeof(UnauthorizedError),
"#/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",
typeof(InvalidRequestError),
"#/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",
Expand Down
21 changes: 9 additions & 12 deletions tests/OpenCode.Sdk.Tests/Debug/DebugDeclaredErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,26 @@ 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<Func<DeclaredErrorCase>> 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",
typeof(InvalidRequestError),
"#/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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Func<DeclaredErrorCase>> 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",
Expand Down
21 changes: 9 additions & 12 deletions tests/OpenCode.Sdk.Tests/Forms/FormsDeclaredErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,26 @@ 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<Func<DeclaredErrorCase>> 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",
typeof(InvalidRequestError),
"#/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",
Expand Down
16 changes: 9 additions & 7 deletions tests/OpenCode.Sdk.Tests/Worktrees/WorktreesDeclaredErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Func<DeclaredErrorCase>> 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",
Expand Down
Loading