chore: checkpoint 第一版
ci / verify (push) Canceled after 0s

This commit is contained in:
Codex Local
2026-09-06 17:04:11 +08:00
parent a8cdec98d1
commit 0c2151ace9
659 changed files with 185855 additions and 554 deletions
+47
View File
@@ -56,6 +56,53 @@ func TestDeviceAuthDoesNotExposeCredentialFailure(t *testing.T) {
}
}
func TestRequireDeviceActivation(t *testing.T) {
next := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })
handler := RequireDeviceActivation([]string{"ACTIVE"}, next)
activeRequest := httptest.NewRequest(http.MethodPost, "/device/v3/agent-sessions", nil)
activeRequest = activeRequest.WithContext(deviceauth.WithIdentity(activeRequest.Context(), deviceauth.Identity{ActivationState: "ACTIVE"}))
activeRecorder := httptest.NewRecorder()
handler.ServeHTTP(activeRecorder, activeRequest)
if activeRecorder.Code != http.StatusNoContent {
t.Fatalf("active status = %d", activeRecorder.Code)
}
boundRequest := httptest.NewRequest(http.MethodPost, "/device/v3/agent-sessions", nil)
boundRequest = boundRequest.WithContext(deviceauth.WithIdentity(boundRequest.Context(), deviceauth.Identity{ActivationState: "BOUND"}))
boundRecorder := httptest.NewRecorder()
handler.ServeHTTP(boundRecorder, boundRequest)
if boundRecorder.Code != http.StatusConflict || !containsText(boundRecorder.Body.String(), "DEVICE_ACTIVATION_REQUIRED") {
t.Fatalf("bound response = %d %s", boundRecorder.Code, boundRecorder.Body.String())
}
}
func TestRequireHardwareLicense(t *testing.T) {
next := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })
handler := RequireHardwareLicense(next)
for _, testCase := range []struct {
name string
identity deviceauth.Identity
status int
code string
}{
{name: "hardware license active", identity: deviceauth.Identity{VoiceRuntime: "volc_hardware_agent", HardwareLicenseReady: true}, status: http.StatusNoContent},
{name: "hardware license missing", identity: deviceauth.Identity{VoiceRuntime: "volc_hardware_agent"}, status: http.StatusConflict, code: "HARDWARE_LICENSE_REQUIRED"},
{name: "legacy runtime unaffected", identity: deviceauth.Identity{VoiceRuntime: "legacy_voicechat"}, status: http.StatusNoContent},
} {
t.Run(testCase.name, func(t *testing.T) {
request := httptest.NewRequest(http.MethodPost, "/device/v3/agent-sessions", nil)
request = request.WithContext(deviceauth.WithIdentity(request.Context(), testCase.identity))
recorder := httptest.NewRecorder()
handler.ServeHTTP(recorder, request)
if recorder.Code != testCase.status || (testCase.code != "" && !containsText(recorder.Body.String(), testCase.code)) {
t.Fatalf("response = %d %s", recorder.Code, recorder.Body.String())
}
})
}
}
func containsText(value, part string) bool {
for index := 0; index+len(part) <= len(value); index++ {
if value[index:index+len(part)] == part {