feat(worker): adopt canonical public URL
Все проверки выполнены успешно
CI / test (push) Successful in 10m15s
Docker / Build and publish worker image (push) Successful in 34m59s

Этот коммит содержится в:
Gleb Tv
2026-08-12 20:48:01 +03:00
родитель a1ccd50aaf
Коммит cb23f123ae
19 изменённых файлов: 804 добавлений и 74 удалений

Просмотреть файл

@@ -1149,3 +1149,59 @@ func TestApplyInitStoresURLInMemory(t *testing.T) {
assert.Equal(t, "", r.URL(),
"URL() must return empty after applyInit with empty URL")
}
// TestApplyInitPrefersPublicURLOverLegacyURL verifies the bounded-migration
// precedence on the init/config frame: PublicURL (canonical) wins whenever
// it is non-empty, and the legacy URL field remains the fallback for old
// control planes.
func TestApplyInitPrefersPublicURLOverLegacyURL(t *testing.T) {
executor := func(payload interface{}) interface{} {
return []wire.CheckResultReport{}
}
r := newTestRunner(t, 4, 1, executor)
r.applyInit(&wire.WorkerInit{
WorkerID: "w-1",
Concurrency: 2,
PublicURL: "https://canonical.example.com",
URL: "https://legacy.example.com",
})
assert.Equal(t, "https://canonical.example.com", r.URL(),
"PublicURL must win over the legacy URL field")
r.applyInit(&wire.WorkerInit{
WorkerID: "w-1",
Concurrency: 2,
URL: "https://legacy.example.com",
})
assert.Equal(t, "https://legacy.example.com", r.URL(),
"legacy URL field must be used when PublicURL is empty")
}
// TestApplyInitInvalidAcceptedURLKeepsPrior verifies the safe-fallback
// behavior when the control plane supplies an unusable advertised URL:
// the previous accepted value is kept (never regressed to a garbage
// endpoint), while a valid empty init still clears it.
func TestApplyInitInvalidAcceptedURLKeepsPrior(t *testing.T) {
executor := func(payload interface{}) interface{} {
return []wire.CheckResultReport{}
}
r := newTestRunner(t, 4, 1, executor)
r.applyInit(&wire.WorkerInit{WorkerID: "w-1", Concurrency: 2, PublicURL: "https://worker.example.com"})
assert.Equal(t, "https://worker.example.com", r.URL())
// Invalid value: keep the previous accepted URL.
r.applyInit(&wire.WorkerInit{WorkerID: "w-1", Concurrency: 2, PublicURL: "https://:27401"})
assert.Equal(t, "https://worker.example.com", r.URL(),
"invalid accepted URL must not replace the stored value")
r.applyInit(&wire.WorkerInit{WorkerID: "w-1", Concurrency: 2, URL: "not a url"})
assert.Equal(t, "https://worker.example.com", r.URL(),
"invalid legacy url field must not replace the stored value")
// Valid empty init clears, as before.
r.applyInit(&wire.WorkerInit{WorkerID: "w-1", Concurrency: 2})
assert.Equal(t, "", r.URL(),
"valid empty init must clear the stored URL")
}