feat(sdk)!: Provider.Test、模型探测和失败的视频任务返回 error - #66
Merged
Merged
Conversation
HoneyBBQ
added this pull request to stack #67
September 28, 2026 13:17
HoneyBBQ
force-pushed
the
feat/errors-probe
branch
from
September 28, 2026 19:55
55eeaf8 to
4ce5124
Compare
HoneyBBQ
force-pushed
the
feat/errors-probe
branch
from
September 29, 2026 06:53
4ce5124 to
606f200
Compare
HoneyBBQ
force-pushed
the
feat/errors-probe
branch
2 times, most recently
from
September 29, 2026 11:45
73f0ca7 to
0a288a2
Compare
HoneyBBQ
force-pushed
the
feat/errors-probe
branch
from
September 29, 2026 11:55
0a288a2 to
0c4ed4f
Compare
HoneyBBQ
force-pushed
the
feat/errors-probe
branch
from
September 29, 2026 21:07
0c4ed4f to
27031a1
Compare
HoneyBBQ
force-pushed
the
feat/errors-probe
branch
from
September 29, 2026 21:58
27031a1 to
63215e9
Compare
HoneyBBQ
force-pushed
the
feat/errors-probe
branch
from
September 29, 2026 22:11
63215e9 to
b171f5e
Compare
Provider.Test now returns error: nil when the provider is reachable and accepts the credentials, a *APIError when it rejected the check, and the wrapped transport error otherwise. ProviderTestResult, ProviderStatus and its constants are removed; callers read KindOf(err) instead of matching the message text. ClassifyProbeStatus(int) becomes ClassifyProbe(err). utils.ProbeStatus becomes utils.Probe, which returns *APIError for non-2xx responses, so a 401 from the TestModel probe keeps its Kind. GenerateVideo returns a failed job as a *APIError with StatusCode 0 and the job's Code, Message and Kind, and wraps the context error when polling ends early. VideoProvider gains Name(), VideoError gains Kind, Ark task failures keep their code, and download failures are *APIError. BREAKING CHANGE: Provider.Test returns error; ProviderTestResult, ProviderStatus and ClassifyProbeStatus are removed; VideoProvider requires Name().
HoneyBBQ
force-pushed
the
feat/errors-probe
branch
from
September 30, 2026 06:53
b171f5e to
2720ae5
Compare
HoneyBBQ
marked this pull request as ready for review
September 30, 2026 06:54
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
问题
Provider.Test返回的ProviderTestResult只有一个状态枚举和一段 message,底层错误被丢掉了。调用方要区分 key 无效和主机不可达,只能匹配Message,Memoh 目前就是匹配"authentication failed"。TestModel的探测用ProbeStatus,只保留了状态码。GenerateVideo把失败的任务返回成格式化字符串。轮询被 context 提前中断时,context 的错误也会丢失。改动
Provider.Test(ctx)改为返回error。provider 可达且接受凭据时返回 nil,provider 拒绝检查时返回*sdk.APIError,其他情况返回包装后的传输错误。OpenCode Go 的检查请求公开的模型列表端点,nil 只说明端点可达,凭据要用TestModel验证。删除ProviderTestResult、ProviderStatus及其常量。ClassifyProbeStatus(int)改为ClassifyProbe(err)。错误为 nil 或状态码为 400、422、429 时,判定模型受支持;404 判定为模型不存在。其他错误原样返回,所以 401 会保留它的Kind。utils.ProbeStatus改为utils.Probe,非 2xx 响应返回*sdk.APIError。GenerateVideo把失败的任务返回成*sdk.APIError,StatusCode为 0,带上任务的 code、message 和Kind。轮询提前结束时包装ctx.Err()。方舟任务失败时保留错误码,下载失败返回*sdk.APIError。VideoProvider新增必须实现的Name(),VideoError新增Kind字段。验证
go build ./...、go vet ./...、go test ./... -short -count=1 -race和golangci-lint run ./...均通过,go mod tidy无 diff。Test检查三种情况:主机可达、key 被拒(*sdk.APIError,Kind 为KindAuthentication)、主机不可达。模型探测用 400、422、429、404 和 key 被拒几种响应检查。Test有httptest用例,公开模型列表可达时返回 nil。ClassifyProbe有表格测试,覆盖 nil、每个判定为受支持的状态码、404、其他 API 错误和非 API 错误。GenerateVideo有任务失败、超时和 context 取消的测试。每个视频包都测试了任务失败和下载返回非 2xx。