feat: extract versioned YouTube service adapter

Wire pure Player parsing and strict qualification planning through a compiled-in kind/version registry. Fail closed before discovery requests when the required module is absent or mismatched.

Require sealed module-bound v2 evidence for new writes while preserving fresh trusted v1 apply eligibility and historical rollback. Keep legacy SOCKS5h routing, separate suffix/asset policy and public configuration unchanged; generic controller cutover and field acceptance remain pending.

Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
ZeusinaandGPT-6 Bot committed 2026-10-15 16:23:54 +03:00
1 parent d324b4137b
commit f4853173b3
21 files changed
+1176 -74

No files matched your search

+104
View File
@@ -695,3 +695,107 @@ Root-private proof references (retained reports, not logs copied into this doc):
readiness, transactional generic apply/profile-journal migration, immutable
rotation and noninterrupting search remain outside this producer acceptance;
the later bounded apply/replay gates are recorded separately above.
## Internal YouTube adapter slice (local; field acceptance pending)
`internal/adapter` is a small closed compiled-in contract (`Binding`, ephemeral
`Resource`/`Plan`, `Module`); `internal/adapter/youtube` implements `youtube/1`.
The explicit kind/version registry in `service_adapters.go` has no init hooks,
dynamic loading, public configuration, HTTP fallback or module privileges.
Player media parsing (`playerMediaResource`) and owned native qualification
(`verifyGooglevideo`) actually call it. Discovery retry/rotation/cancellation and
representative selection remain in the legacy controller; signed MP4 freshness
and the host/TLS qualification plan are pure service semantics in the module.
Core origin/TLS validation, shared image/media transfer code, bounded worker
lifecycle and post-cleanup/join sealing remain authoritative. Legacy media and
metadata routing retains SOCKS5h with the owned encrypted-resolver guard and
exact origin/SNI/certificate/redirect checks. It does **not** use public generic
`runResourceProtocol`'s all-A/AAAA approval and connect-to IP pinning. That inherited
ceiling is unchanged, not a pinning guarantee: full request-policy capabilities
(including future metadata POST) and parity are prerequisites to generic cutover.
No new DNS/IP routing policy is introduced by this extraction. Both TLS
versions must learn separately, then each has three measured MP4 samples per
representative host, minimum 1024 bytes (not an exact 64 KiB requirement).
Measured endpoints do not authorize a suffix: existing exact/suffix/experimental
policy and independent thumbnail/avatar qualification are unchanged. The module
cannot manufacture evidence, request wildcard apply or claim YouTube READY.
New adaptive proof **v2** includes adapter kind/version/immutable policy SHA256
inside the producer seal. Public JSON cannot recreate that seal. Missing or
mismatched binding/version/digest fails closed; v1 with v2 fields is rejected.
Historical proof **v1** explicitly uses the pinned legacy YouTube v1 contract,
including historical freshness-independent journal reconstruction. Its config
bytes/hash and journal refs remain stable. Fresh stored trusted v1 proofs retain
their original apply/qualification eligibility, including unchanged attestation
freshness and media gates. Expired v1 can reconstruct but cannot authorize fresh
apply. Only **new production/persistence** requires sealed, module-bound v2;
neither sealed-new-v1 nor public unsealed v1/v2 DTOs can publish new evidence.
Cold v1 evidence, SQL schema 7, native arguments,
public GET/HEAD v1/v2, state keys and HMAC formats are unchanged.
This slice is not full generic-controller migration, native-engine runtime
acceptance, a security sandbox (including against same-UID actors), or a fix for
unresolved avatars/legacy exit 78. No legacy path is deleted. Local tests and
archived baseline parity are recorded separately; no remote validation or commit
is part of this extraction review.
Discovery preflight resolves the required module identity and policy digest
before any Player/WWW/avatar/front/media requests, including injected callbacks,
legacy proposal discovery and managed discovery hooks. Missing/mismatched modules
produce a fixed private sentinel wrapped as a fatal configuration failure, not
retryable unavailable inventory, a transfer-negative or genuine no-strategy pause.
The compiled production registry remains fixed; synchronized test replacement
does not add public runtime module configuration or loading.
### Local verification for this extraction (2026-10-15)
- Fresh serial `go test -json -p 1 ./... -parallel 1 -count=1 -timeout 600s`:
399 top-level / 1737 including subtest PASS events, zero failures.
- Affected serial race run (`-race -p 1 -parallel 1 -count=1`) covers adapters,
Player/discovery, owned qualification/proof gates, historical journal parity,
independent assets and generic resource core: 61 top-level / 307 including
subtest PASS events, zero failures. Full regex and logs are retained at
`/tmp/opencode/youtube-adapter-fixes/{full,race}.json`.
- Archived `d324b4137b2e95f1c5f4d6c8240470e3f8749f0c` and current builds each
passed 275 affected test/subtest events. The portable legacy parser/journal
corpus ran **unmodified** on both: file SHA256
`7b8eea9c9bbcdd8f0fadde3f78596d41e9d032a0a4f7b2ca90d1223d106584d5`.
Both reconstructed historical config SHA256
`172c7377388334e4baa2dc1009270478dc271a7b2f00d28cfada631f44a35364`,
retaining journal bytes/refs after reconcile and ActiveCandidates validation.
An additional unchanged portable v1 corpus passed 2 top-level / 8 including
subtest events on **each** build: fresh stored v1 shortlist/apply eligibility,
expired fresh-apply refusal, and staged/backup/prepared/replaced/reloaded/healthy
crash rollback with expired historical proofs. Backup/config bytes and hashes
are stable; pre-prepare journal bytes are unchanged and post-prepare generation/
reload/ref transitions follow the original contract. Corpus SHA256:
`6df53b12af5d80d164ea3201a614a5fd5723561dc7b2d6bc2d2aa37f845f053d`.
New negative tests separately reject even internally sealed NEW v1 writes and
public unsealed DTOs; missing/changed module identity/policy makes zero Player,
WWW/avatar/media/front/worker calls and does not become a two-hour absence.
- All four `python3 deploy/managed-target/check_{static,config,startup_diagnostics,supervision}.py`
checks passed serially; supervision was bounded with `timeout 600s`, no retry.
`go vet ./...`, `CGO_ENABLED=0 go build`, `sh -n` on all three entrypoint/
supervision scripts, and `git diff --check` passed. Build SHA256:
`8327faf86098145bb41306b3de895cdd622aeccdcda90f8ec73e19a759c8f98a`.
- Ownership-sensitive final runs used `sudo -n` EUID 0 **inside the existing
user namespace**, mapping UID 0 to parent/host UID 100000, not initial-host
root. The initial extra single-UID `unshare -Ur` run failed ownership fixtures
(`chown: invalid argument` / `invalid private qualification data`); a stale
test assertion also expected newly produced proof v1 and was updated to v2.
Those prior extraction failures are retained in
`/tmp/opencode/youtube-adapter-review/go-full.json`, not reported as passes. Vet's
initial unkeyed shared-DTO literals were fixed before final successful checks.
Reproduction commands (run serially; root is only for offline ownership fixtures):
```sh
pattern='Test(YoutubeLegacy|ManagedGooglevideo|ManagedAdaptive|ExperimentalPromotion|Googlevideo|Resource(Core|Discovery|Contract)|Player|Discover|ManagedAsset|Asset)'
sudo -n env GOPROXY=off GOTOOLCHAIN=local GOMODCACHE="$(go env GOMODCACHE)" "$(command -v go)" test -json -p 1 ./... -parallel 1 -count=1 -timeout 600s
sudo -n env GOPROXY=off GOTOOLCHAIN=local GOMODCACHE="$(go env GOMODCACHE)" "$(command -v go)" test -race -json -p 1 ./internal/adapter/... ./cmd/zapret-autotune -parallel 1 -run "${pattern}|Test(ServiceAdapter|LegacyYoutubeV1|QualificationPlan|SignedSample|DiscoverResponse)" -count=1 -timeout 600s
# Baseline/current parity: the same $pattern, without -race, on both trees.
# Baseline tree: git archive d324b4137b2e95f1c5f4d6c8240470e3f8749f0c;
# add identical youtube_legacy_parity_test.go and youtube_legacy_apply_parity_test.go.
# The additional portable v1 corpus runs separately with -run '^TestLegacyYoutubeV1'.
```