From bb787889d99a10465112ca105049260d5f32f35a Mon Sep 17 00:00:00 2001 From: JSONbored <49853598+JSONbored@users.noreply.github.com> Date: Thu, 25 Jun 2026 02:03:08 -0700 Subject: [PATCH] refactor(content-lane): retire the dead legacy candidate model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The metagraphed candidate-file model is fully superseded by the live surface model (#1340) and has zero src callers — only tests referenced it. Remove it: - the legacy scope classifier: classifyPrScope, isDirectSubmissionScope, PrScope, ScopeResult (superseded by classifyRegistryPrScope / RegistryPrScope / RegistryScopeResult); - the legacy validator assessCandidateDocument; - the now-dead patterns CANDIDATE_PATTERN, PROVIDER_PATTERN, PROVIDER_ANY_PATTERN; - the dead candidate dedup helpers candidateRegistryKey, registryDedupKeys, registryUrls; - their index.ts re-exports and 34 now-orphaned tests. KEPT (shared with the live surface validators): CandidateLike, Assessment, fail, ARTIFACT_PATTERN (used by METAGRAPHED_LANE_SPEC), and the secret/kind/url/observed-state checks. Verified no orphaned internal helpers and zero remaining references repo-wide. ~430 lines of dead code removed; no behaviour change. Follows #1340. --- src/review/content-lane/index.ts | 11 - src/review/content-lane/registry-logic.ts | 181 +----------- test/unit/content-lane-registry-logic.test.ts | 259 ------------------ 3 files changed, 11 insertions(+), 440 deletions(-) diff --git a/src/review/content-lane/index.ts b/src/review/content-lane/index.ts index a168179b53..1138ae8a0d 100644 --- a/src/review/content-lane/index.ts +++ b/src/review/content-lane/index.ts @@ -71,12 +71,10 @@ export { // metagraphed (registry) primitives export { - assessCandidateDocument, assessProviderDocument, assessSurfaceEntry, assessSubnetDocument, assessFreshness, - classifyPrScope, classifyRegistryPrScope, isRegistrySubmissionScope, METAGRAPHED_LANE_SPEC, @@ -87,25 +85,18 @@ export { type RegistryScopeResult, computeGrounding, containsSecretLikeText, - candidateRegistryKey, deriveRegistryIdentityTokens, functionalRequired, isAllowedChain, isBaseLayerKind, - isDirectSubmissionScope, isInternalAutomationBranch, isNonEmptyStructuredBody, netuidGroundingRegex, normalizePublicUrl, probeFunctionalSurface, registrableDomain, - registryDedupKeys, - registryUrls, surfaceMatchesRegistryIdentity, toCoreVerdict, - CANDIDATE_PATTERN, - PROVIDER_PATTERN, - PROVIDER_ANY_PATTERN, ARTIFACT_PATTERN, DEFAULT_PUBLIC_API_BASE, STALE_REPO_DAYS, @@ -114,10 +105,8 @@ export { type FreshnessSignals, type GroundingSignals, type MetaVerdict, - type PrScope, type ProviderAssessment, type ProviderLike, - type ScopeResult, type Verdict, } from "./registry-logic"; export { runSurfaceReview, diffAppendedSurfaceEntry, type SurfaceReviewInput, type SurfaceReviewResult } from "./orchestrator"; diff --git a/src/review/content-lane/registry-logic.ts b/src/review/content-lane/registry-logic.ts index c4f2d06742..0cbb1d3605 100644 --- a/src/review/content-lane/registry-logic.ts +++ b/src/review/content-lane/registry-logic.ts @@ -26,11 +26,7 @@ export function isInternalAutomationBranch(ref: string | undefined): boolean { return AUTOMATION_BRANCH_PREFIXES.some((prefix) => branch.startsWith(prefix)); } -export const CANDIDATE_PATTERN = /^registry\/candidates\/community\/[a-z0-9][a-z0-9-]*\.json$/; -export const PROVIDER_PATTERN = /^registry\/providers\/community\/[a-z0-9][a-z0-9-]*\.json$/; -/** A provider registration anywhere under registry/providers — an allowed companion in a candidate PR. */ -export const PROVIDER_ANY_PATTERN = /^registry\/providers\/(?:community\/)?[a-z0-9][a-z0-9-]*\.json$/; -/** Generated registry artifacts a valid candidate/provider PR must regenerate — allowed companions. */ +/** Generated registry artifacts a valid PR must regenerate — allowed companions of a registry submission. */ export const ARTIFACT_PATTERN = /^public\/metagraph\/[a-z0-9/_-]+\.json$/i; export const DEFAULT_PUBLIC_API_BASE = "https://api.metagraph.sh/api/v1"; @@ -453,38 +449,6 @@ export function assessFreshness( return { known: true, archived, pushedAt, ageDays, stale, reason }; } -/** Duplicate key netuid|kind|normalizedUrl (primary `url` field). */ -export function candidateRegistryKey(value: CandidateLike | null | undefined): string | null { - const normalizedUrl = normalizePublicUrl(value?.url); - if (!Number.isInteger(Number(value?.netuid)) || !value?.kind || !normalizedUrl) return null; - return [Number(value.netuid), String(value.kind), normalizedUrl].join("|"); -} - -/** ALL dedup keys a candidate OR registry surface can collide on: netuid|kind per normalized URL field - * it carries (`url` AND `schema_url`) — so a candidate's `url` equal to a verified surface's - * `schema_url` is still caught. */ -export function registryDedupKeys(value: CandidateLike | null | undefined): Set { - const keys = new Set(); - const netuid = Number(value?.netuid); - if (!Number.isInteger(netuid) || !value?.kind) return keys; - for (const field of [value?.url, (value as { schema_url?: unknown } | null | undefined)?.schema_url]) { - const normalized = normalizePublicUrl(field); - if (normalized) keys.add([netuid, String(value.kind), normalized].join("|")); - } - return keys; -} - -/** The normalized public URLs a candidate/surface carries (`url` + `schema_url`), KIND-AGNOSTIC — used - * to detect a same-URL-DIFFERENT-KIND collision (a mislabel/duplicate the kind-scoped key can't see). */ -export function registryUrls(value: CandidateLike | null | undefined): Set { - const urls = new Set(); - for (const field of [value?.url, (value as { schema_url?: unknown } | null | undefined)?.schema_url]) { - const normalized = normalizePublicUrl(field); - if (normalized) urls.add(normalized); - } - return urls; -} - function fail(reason: string, summary: string, candidate: CandidateLike | null = null): Assessment { return { /* v8 ignore next -- every fail() call site passes a REVIEWER_CLOSE_REASONS member, so the "manual-review" alternative is unreachable; kept so a future non-close reason degrades to manual rather than closing. */ @@ -495,92 +459,12 @@ function fail(reason: string, summary: string, candidate: CandidateLike | null = }; } -/** Deterministic candidate shape/safety gate. The security checks (secret scan, public-URL safety) are - * gated by the agent's feature toggles, defaulting ON so callers that pass nothing keep strict behavior. */ -export function assessCandidateDocument( - document: unknown, - opts: { secretsScan?: boolean; sourceUrlValidation?: boolean } = {}, -): Assessment { - const { secretsScan = true, sourceUrlValidation = true } = opts; - const doc = document as { candidates?: unknown; candidate?: unknown } | null; - const candidates: CandidateLike[] = Array.isArray(doc?.candidates) - ? (doc?.candidates as CandidateLike[]) - : doc?.candidate - ? [doc.candidate as CandidateLike] - : []; - if (candidates.length !== 1) { - return fail("unsupported-shape", "Candidate PR must contain exactly one candidate entry."); - } - const candidate = candidates[0] as CandidateLike; - if (secretsScan && containsSecretLikeText(JSON.stringify(candidate))) { - return fail( - "secret-or-credential", - "Candidate appears to include secret, wallet, PAT, or private-key material.", - candidate, - ); - } - // Observed-state claim (health/uptime/latency/status): probe-derived only — a submission can never assert it. - const observedKey = Object.keys(candidate as Record).find((k) => - OBSERVED_STATE_KEYS.has(k.toLowerCase()), - ); - if (observedKey) { - return fail( - "observed-state-claim", - `Candidate asserts observed runtime state (\`${observedKey}\`). Health / uptime / latency / status are probe-derived only and can never be part of a submission — remove the field and resubmit.`, - candidate, - ); - } - if (!Number.isInteger(Number(candidate.netuid))) { - return fail("unsupported-shape", "Candidate netuid must be an integer.", candidate); - } - const baseLayer = isBaseLayerKind(candidate.kind); - if (!REVIEWER_SAFE_KINDS.has(String(candidate.kind)) && !baseLayer) { - return fail("unsupported-shape", "Candidate kind is not supported by the reviewer.", candidate); - } - if (sourceUrlValidation) { - // Base-layer chain endpoints may be wss/ws (probed via JSON-RPC); content kinds must be HTTPS. - const urlSafe = baseLayer - ? isSafeEndpointUrl(String(candidate.url ?? "")) - : isSafeHttpUrl(String(candidate.url ?? "")); - if (!urlSafe) { - return fail( - "unsafe-url", - baseLayer ? "Candidate URL must be a public HTTPS or WSS endpoint." : "Candidate URL must be a public HTTPS URL.", - candidate, - ); - } - const sourceUrl = (candidate.source_url as string) || (candidate.source_urls as string[] | undefined)?.[0]; - if (!isSafeHttpUrl(String(sourceUrl ?? ""))) { - return fail("unsafe-url", "Candidate source URL must be a public HTTPS URL.", candidate); - } - } - // One-shot: incomplete/credentialed submissions are declined (resubmit clean), not queued. - if (candidate.public_safe !== true) { - return { - verdict: "closed", - summary: - "Candidate is not marked public_safe=true — declined. Resubmit with public_safe=true if the endpoint is genuinely public.", - candidate, - }; - } - if (candidate.auth_required === true) { - // Authenticated interface: NOT auto-closed — escalate to confirm the auth scheme is documented publicly. - return { - verdict: "manual-review", - summary: - "Authenticated interface — routing to review to confirm the declared auth scheme is documented publicly (verifiable without any secret) before it can be accepted.", - candidate, - }; - } - return { verdict: "merged", candidate }; -} - /** - * Surface model (the candidate-file model's successor): a contribution appends ONE entry to `surfaces[]` of a - * `registry/subnets/.json`, whose `netuid` lives at the file ROOT (not on each entry). These two - * deterministic validators are the per-entry and whole-document analogues of assessCandidateDocument — gittensory - * is the sole adjudicator; no AI (surfaces are structured data). They take the appended entry / parsed document as - * arguments; resolving "exactly one appended entry" from a head-vs-base diff is the orchestrator's job (a follow-up). + * Surface validators: a contribution appends ONE entry to `surfaces[]` of a `registry/subnets/.json`, whose + * `netuid` lives at the file ROOT (not on each entry). These two deterministic validators (per-entry + + * whole-document) make gittensory the sole adjudicator; no AI (surfaces are structured data). They take the + * appended entry / parsed document as arguments; the orchestrator resolves "exactly one appended entry" from a + * head-vs-base diff. */ export function assessSurfaceEntry( entry: unknown, @@ -765,56 +649,13 @@ export function probeFunctionalSurface( return { served: true, detail: "n/a" }; } -export type PrScope = "direct-candidate" | "direct-provider" | "mixed-files" | "not-direct-submission"; - -export interface ScopeResult { - scope: PrScope; - directFile: string | null; - isProvider: boolean; -} - -/** - * In-scope when the PR reviews exactly ONE candidate (or, candidate-free, one provider) submission. - * A valid candidate PR must also regenerate the public/metagraph artifacts and may register its - * provider — those are ALLOWED COMPANIONS; any other file makes it out-of-scope. The reviewed - * `directFile` is the candidate (else the provider). - */ -export function classifyPrScope(changedFiles: string[]): ScopeResult { - const files = (changedFiles ?? []).map((f) => String(f || "").trim()).filter(Boolean); - const candidateFiles = files.filter((f) => CANDIDATE_PATTERN.test(f)); - const providerFiles = files.filter((f) => PROVIDER_ANY_PATTERN.test(f)); - const isCandidatePr = candidateFiles.length === 1; - const isProviderPr = candidateFiles.length === 0 && providerFiles.length === 1; - if (!isCandidatePr && !isProviderPr) { - return { scope: "not-direct-submission", directFile: null, isProvider: false }; - } - // Allowed companions: provider registrations + generated public/metagraph artifacts. - const forbidden = files.filter( - (f) => !CANDIDATE_PATTERN.test(f) && !PROVIDER_ANY_PATTERN.test(f) && !ARTIFACT_PATTERN.test(f), - ); - if (forbidden.length > 0) return { scope: "mixed-files", directFile: null, isProvider: false }; - // isProviderPr ⇒ providerFiles.length === 1 and isCandidatePr ⇒ candidateFiles.length === 1 (guarded - // by the early return above), so [0] is always defined here; the `?? null` fallbacks exist only to - // satisfy noUncheckedIndexedAccess and can never fire at runtime. - /* v8 ignore start */ - return isProviderPr - ? { scope: "direct-provider", directFile: providerFiles[0] ?? null, isProvider: true } - : { scope: "direct-candidate", directFile: candidateFiles[0] ?? null, isProvider: false }; - /* v8 ignore stop */ -} - -export function isDirectSubmissionScope(scope: PrScope): boolean { - return scope === "direct-candidate" || scope === "direct-provider"; -} - // ── Surface model (generic registry content-lane) ───────────────────────────────────────────────── // -// The candidate-file model above is metagraphed's RETIRED lane. The current model: a community contribution -// appends entries to an array field of ONE registry "entry file" (e.g. registry/subnets/.json::surfaces[]), -// optionally with one flat companion provider file. To stay MODULAR — many maintainers will install gittensory -// over wildly different registries — the engine is parameterized by a RegistryLaneSpec rather than hard-coding -// metagraphed's paths; metagraphed is just the FIRST spec, and a spec can later be loaded from per-repo -// .gittensory.yml config so a new registry needs config, not a gittensory code change. +// A community contribution appends entries to an array field of ONE registry "entry file" (e.g. +// registry/subnets/.json::surfaces[]), optionally with one flat companion provider file. To stay MODULAR — +// many maintainers will install gittensory over wildly different registries — the engine is parameterized by a +// RegistryLaneSpec rather than hard-coding metagraphed's paths; metagraphed is just the FIRST spec, and a spec can +// later be loaded from per-repo .gittensory.yml config so a new registry needs config, not a code change. /** Describes where a registry keeps its community-editable entry files + allowed companions. */ export interface RegistryLaneSpec { diff --git a/test/unit/content-lane-registry-logic.test.ts b/test/unit/content-lane-registry-logic.test.ts index b24086dc7e..4907703401 100644 --- a/test/unit/content-lane-registry-logic.test.ts +++ b/test/unit/content-lane-registry-logic.test.ts @@ -1,12 +1,9 @@ import { describe, expect, it } from "vitest"; import { - assessCandidateDocument, assessSurfaceEntry, assessSubnetDocument, assessFreshness, assessProviderDocument, - candidateRegistryKey, - classifyPrScope, classifyRegistryPrScope, isRegistrySubmissionScope, METAGRAPHED_LANE_SPEC, @@ -17,15 +14,12 @@ import { functionalRequired, isAllowedChain, isBaseLayerKind, - isDirectSubmissionScope, isInternalAutomationBranch, isNonEmptyStructuredBody, netuidGroundingRegex, normalizePublicUrl, probeFunctionalSurface, registrableDomain, - registryDedupKeys, - registryUrls, surfaceMatchesRegistryIdentity, toCoreVerdict, } from "../../src/review/content-lane/registry-logic"; @@ -107,54 +101,6 @@ describe("computeGrounding", () => { }); }); -describe("assessCandidateDocument", () => { - const ok = { - candidate: { netuid: 14, kind: "subnet-api", url: "https://api.cacheon.ai", source_url: "https://github.com/cacheon/x", public_safe: true }, - }; - - it("merges a clean public candidate", () => { - expect(assessCandidateDocument(ok).verdict).toBe("merged"); - }); - - it("closes when not exactly one candidate", () => { - expect(assessCandidateDocument({ candidates: [] }).verdict).toBe("closed"); - }); - - it("closes a secret-bearing candidate", () => { - const r = assessCandidateDocument({ candidate: { ...ok.candidate, note: "ghp_" + "a".repeat(25) } }); - expect(r.verdict).toBe("closed"); - expect(r.reason).toBe("secret-or-credential"); - }); - - it("closes an observed-state claim", () => { - const r = assessCandidateDocument({ candidate: { ...ok.candidate, uptime: "99.9%" } }); - expect(r.reason).toBe("observed-state-claim"); - }); - - it("closes a non-public_safe candidate", () => { - const r = assessCandidateDocument({ candidate: { ...ok.candidate, public_safe: false } }); - expect(r.verdict).toBe("closed"); - }); - - it("routes an auth_required candidate to manual-review", () => { - const r = assessCandidateDocument({ candidate: { ...ok.candidate, auth_required: true } }); - expect(r.verdict).toBe("manual-review"); - }); - - it("closes an unsafe (private/loopback) candidate URL", () => { - const r = assessCandidateDocument({ candidate: { ...ok.candidate, url: "https://127.0.0.1" } }); - expect(r.reason).toBe("unsafe-url"); - }); - - it("can skip security checks when toggles are off", () => { - const r = assessCandidateDocument( - { candidate: { netuid: 14, kind: "website", url: "http://insecure.example", public_safe: true } }, - { sourceUrlValidation: false }, - ); - expect(r.verdict).toBe("merged"); - }); -}); - describe("assessSurfaceEntry (surface model — netuid supplied from the document root)", () => { // A surface entry OMITS netuid (it lives at the subnet-document root); the validator receives it as a param. const ok = { kind: "subnet-api", url: "https://api.example.ai", source_url: "https://github.com/x/y", public_safe: true }; @@ -273,17 +219,6 @@ describe("assessProviderDocument", () => { }); }); -describe("dedup keys + cross-kind urls", () => { - it("keys on netuid|kind per url AND schema_url", () => { - const keys = registryDedupKeys({ netuid: 14, kind: "openapi", url: "https://a/swagger", schema_url: "https://a/swagger-json" }); - expect(keys.size).toBe(2); - }); - it("registryUrls is kind-agnostic", () => { - const urls = registryUrls({ netuid: 1, kind: "openapi", url: "https://a/x", schema_url: "https://a/y" }); - expect(urls.size).toBe(2); - }); -}); - describe("freshness", () => { it("flags an archived or very stale repo", () => { const now = Date.parse("2026-06-22T00:00:00Z"); @@ -329,26 +264,6 @@ describe("probeFunctionalSurface", () => { }); }); -describe("classifyPrScope", () => { - it("recognizes a direct candidate PR with allowed companions", () => { - const r = classifyPrScope(["registry/candidates/community/foo.json", "public/metagraph/index.json"]); - expect(r.scope).toBe("direct-candidate"); - expect(r.directFile).toBe("registry/candidates/community/foo.json"); - }); - it("recognizes a direct provider PR", () => { - const r = classifyPrScope(["registry/providers/community/acme.json"]); - expect(r.scope).toBe("direct-provider"); - expect(r.isProvider).toBe(true); - }); - it("flags out-of-scope code files as mixed", () => { - const r = classifyPrScope(["registry/candidates/community/foo.json", "src/index.ts"]); - expect(r.scope).toBe("mixed-files"); - }); - it("is not-direct when no submission file is present", () => { - expect(classifyPrScope(["README.md"]).scope).toBe("not-direct-submission"); - }); -}); - describe("classifyRegistryPrScope (generic surface model, metagraphed spec)", () => { const spec = METAGRAPHED_LANE_SPEC; it("recognizes a subnet entry-submission with an allowed generated-artifact companion", () => { @@ -469,15 +384,6 @@ describe("functionalRequired + isAllowedChain", () => { }); }); -describe("isDirectSubmissionScope", () => { - it("is true only for the direct candidate/provider scopes", () => { - expect(isDirectSubmissionScope("direct-candidate")).toBe(true); - expect(isDirectSubmissionScope("direct-provider")).toBe(true); - expect(isDirectSubmissionScope("mixed-files")).toBe(false); - expect(isDirectSubmissionScope("not-direct-submission")).toBe(false); - }); -}); - describe("registry-logic edge branches (additional coverage)", () => { it("computeGrounding grounds via huggingface owner tokens + host-referenced-in-source", () => { // ownerTokens huggingface branch (datasets/models/spaces prefix stripped) + sourceText.includes(targetHost) @@ -547,63 +453,6 @@ describe("registry-logic edge branches (additional coverage)", () => { expect(a).toBe(b); }); - it("assessCandidateDocument closes a non-integer netuid as unsupported-shape", () => { - const r = assessCandidateDocument({ - candidate: { netuid: "abc", kind: "website", url: "https://x.example", source_url: "https://github.com/a/b", public_safe: true }, - }); - expect(r.verdict).toBe("closed"); - expect(r.reason).toBe("unsupported-shape"); - expect(r.summary).toContain("integer"); - }); - - it("assessCandidateDocument closes an unsupported kind", () => { - const r = assessCandidateDocument({ - candidate: { netuid: 14, kind: "totally-made-up", url: "https://x.example", source_url: "https://github.com/a/b", public_safe: true }, - }); - expect(r.verdict).toBe("closed"); - expect(r.reason).toBe("unsupported-shape"); - expect(r.summary).toContain("not supported"); - }); - - it("assessCandidateDocument closes an unsafe source URL even when the surface URL is fine", () => { - const r = assessCandidateDocument({ - candidate: { netuid: 14, kind: "website", url: "https://x.example", source_url: "http://127.0.0.1/x", public_safe: true }, - }); - expect(r.reason).toBe("unsafe-url"); - expect(r.summary).toContain("source URL"); - }); - - it("assessCandidateDocument validates a base-layer kind URL via the endpoint (wss) check", () => { - const r = assessCandidateDocument({ - candidate: { netuid: 14, kind: "subtensor-wss", url: "wss://entrypoint.example/ws", source_url: "https://github.com/a/b", public_safe: true }, - }); - expect(r.verdict).toBe("merged"); - }); - - it("assessCandidateDocument closes a base-layer kind with an unsafe (non-wss/https) endpoint", () => { - const r = assessCandidateDocument({ - candidate: { netuid: 14, kind: "archive", url: "ws://127.0.0.1/ws", source_url: "https://github.com/a/b", public_safe: true }, - }); - expect(r.reason).toBe("unsafe-url"); - expect(r.summary).toContain("HTTPS or WSS"); - }); - - it("candidateRegistryKey builds netuid|kind|normalizedUrl, null on missing parts", () => { - expect(candidateRegistryKey({ netuid: 14, kind: "openapi", url: "https://www.A.example/x/" })).toBe( - "14|openapi|https://a.example/x", - ); - expect(candidateRegistryKey({ netuid: "x", kind: "openapi", url: "https://a.example" })).toBeNull(); - expect(candidateRegistryKey({ netuid: 14, url: "https://a.example" })).toBeNull(); // no kind - expect(candidateRegistryKey({ netuid: 14, kind: "openapi", url: "not-a-url" })).toBeNull(); - expect(candidateRegistryKey(null)).toBeNull(); - }); - - it("registryDedupKeys / registryUrls return empty for an invalid candidate", () => { - expect(registryDedupKeys({ netuid: "x", kind: "openapi", url: "https://a.example" }).size).toBe(0); - expect(registryDedupKeys(null).size).toBe(0); - expect(registryUrls({ url: "not-a-url" }).size).toBe(0); - }); - it("normalizePublicUrl keeps ws/wss endpoints and strips the wss default port", () => { expect(normalizePublicUrl("wss://node.example:443/ws")).toBe("wss://node.example/ws"); expect(normalizePublicUrl("ws://node.example:80/ws")).toBe("ws://node.example/ws"); @@ -805,47 +654,6 @@ describe("registry-logic branch coverage (gap-filling)", () => { expect(r.ok).toBe(true); // secret not scanned → accepted }); - // ── assessCandidateDocument untested branches ───────────────────────────── - it("assessCandidateDocument reads the array `candidates` form (single entry merges)", () => { - const r = assessCandidateDocument({ - candidates: [{ netuid: 14, kind: "website", url: "https://x.example", source_url: "https://github.com/a/b", public_safe: true }], - }); - expect(r.verdict).toBe("merged"); - }); - it("assessCandidateDocument closes when there are MULTIPLE candidates", () => { - const c = { netuid: 14, kind: "website", url: "https://x.example", source_url: "https://github.com/a/b", public_safe: true }; - const r = assessCandidateDocument({ candidates: [c, c] }); - expect(r.verdict).toBe("closed"); // unsupported-shape IS a reviewer-close reason - expect(r.reason).toBe("unsupported-shape"); - }); - it("assessCandidateDocument can skip the secret scan via the toggle", () => { - const r = assessCandidateDocument( - { candidate: { netuid: 14, kind: "website", url: "https://x.example", source_url: "https://github.com/a/b", public_safe: true, note: "ghp_" + "k".repeat(25) } }, - { secretsScan: false }, - ); - expect(r.verdict).toBe("merged"); // secret not scanned - }); - it("assessCandidateDocument with a null document closes as unsupported-shape (zero candidates)", () => { - const r = assessCandidateDocument(null); - expect(r.reason).toBe("unsupported-shape"); - }); - it("assessCandidateDocument closes a base-layer kind with an unsafe HTTP url message", () => { - // baseLayer true → unsafe-url uses the "HTTPS or WSS" message branch. - const r = assessCandidateDocument({ - candidate: { netuid: 1, kind: "subtensor-rpc", url: "http://127.0.0.1", source_url: "https://github.com/a/b", public_safe: true }, - }); - expect(r.reason).toBe("unsafe-url"); - expect(r.summary).toContain("HTTPS or WSS"); - }); - it("assessCandidateDocument closes a non-base-layer kind with the plain HTTPS message", () => { - const r = assessCandidateDocument({ - candidate: { netuid: 1, kind: "website", url: "http://plain.example", source_url: "https://github.com/a/b", public_safe: true }, - }); - expect(r.reason).toBe("unsafe-url"); - expect(r.summary).toContain("public HTTPS URL"); - expect(r.summary).not.toContain("WSS"); - }); - // ── probeFunctionalSurface untested branches ────────────────────────────── it("probeFunctionalSurface: openapi version key but paths beyond the window", () => { const r = probeFunctionalSurface("openapi", "application/json", '{"openapi":"3.0.0"'); @@ -883,35 +691,6 @@ describe("registry-logic branch coverage (gap-filling)", () => { expect(isBaseLayerKind(null)).toBe(false); }); - // ── classifyPrScope untested branches ───────────────────────────────────── - it("classifyPrScope: empty/whitespace-only entries are filtered before classification", () => { - // null changedFiles (?? []), blank entries filtered → not-direct-submission. - expect(classifyPrScope(["", " "]).scope).toBe("not-direct-submission"); - expect(classifyPrScope(null as unknown as string[]).scope).toBe("not-direct-submission"); - }); - it("classifyPrScope: a provider PR with a forbidden companion is mixed-files", () => { - const r = classifyPrScope(["registry/providers/community/acme.json", "docs/readme.md"]); - expect(r.scope).toBe("mixed-files"); - expect(r.directFile).toBeNull(); - expect(r.isProvider).toBe(false); - }); - it("classifyPrScope: a candidate PR may register its provider as an allowed companion", () => { - const r = classifyPrScope([ - "registry/candidates/community/foo.json", - "registry/providers/community/foo.json", - "public/metagraph/index.json", - ]); - expect(r.scope).toBe("direct-candidate"); - expect(r.isProvider).toBe(false); - }); - it("classifyPrScope: two candidate files (not exactly one) is not a direct submission", () => { - const r = classifyPrScope([ - "registry/candidates/community/a.json", - "registry/candidates/community/b.json", - ]); - expect(r.scope).toBe("not-direct-submission"); - }); - // ── surfaceMatchesRegistryIdentity domain-label match branch ─────────────── it("surfaceMatchesRegistryIdentity matches directly on the domain label (not just owner tokens)", () => { // domainLabel(cacheon.ai) === "cacheon" which is in the want set → early-return true. @@ -989,44 +768,6 @@ describe("registry-logic branch coverage (second pass)", () => { expect(tokens).toContain("byzantium"); }); - // ── registryDedupKeys: a field that does not normalize is skipped (line 471) ─ - it("registryDedupKeys skips a non-normalizable field but keeps the valid one", () => { - // url normalizes (added); schema_url is junk → normalizePublicUrl null → `if(normalized)` false branch. - const keys = registryDedupKeys({ netuid: 1, kind: "website", url: "https://a.com/x", schema_url: "not-a-url" }); - expect([...keys]).toEqual(["1|website|https://a.com/x"]); - }); - - // ── assessCandidateDocument: url ?? "" fallbacks (lines 541, 542) ────────── - it("assessCandidateDocument treats a missing base-layer url as unsafe (url ?? '' fallback)", () => { - // baseLayer true (subtensor-rpc) + url undefined → String(undefined ?? "") === "" → isSafeEndpointUrl false. - const r = assessCandidateDocument({ candidate: { netuid: 1, kind: "subtensor-rpc", source_url: "https://github.com/a/b" } }); - expect(r.reason).toBe("unsafe-url"); - expect(r.summary).toContain("HTTPS or WSS"); - }); - it("assessCandidateDocument treats a missing content-kind url as unsafe (url ?? '' fallback)", () => { - // baseLayer false (website) + url undefined → String(undefined ?? "") === "" → isSafeHttpUrl false. - const r = assessCandidateDocument({ candidate: { netuid: 1, kind: "website", source_url: "https://github.com/a/b" } }); - expect(r.reason).toBe("unsafe-url"); - expect(r.summary).toContain("public HTTPS URL"); - }); - - // ── assessCandidateDocument: source_url || source_urls?.[0] right side (550) ─ - it("assessCandidateDocument falls back to source_urls[0] when source_url is absent", () => { - // source_url falsy → the `|| source_urls?.[0]` right side supplies the source URL. - const r = assessCandidateDocument({ - candidate: { netuid: 1, kind: "website", url: "https://x.example", source_urls: ["https://github.com/a/b"], public_safe: true }, - }); - expect(r.verdict).toBe("merged"); - }); - - // ── assessCandidateDocument: sourceUrl ?? "" fallback when no source at all (551) ─ - it("assessCandidateDocument with NO source url is unsafe (sourceUrl ?? '' fallback)", () => { - // source_url and source_urls both absent → sourceUrl undefined → String(undefined ?? "") === "" → unsafe. - const r = assessCandidateDocument({ candidate: { netuid: 1, kind: "website", url: "https://x.example", public_safe: true } }); - expect(r.reason).toBe("unsafe-url"); - expect(r.summary).toContain("source URL"); - }); - // ── assessProviderDocument: website_url ?? "" fallback (line 618) ────────── it("assessProviderDocument with a missing website_url is unsafe-url (website_url ?? '' fallback)", () => { // website_url undefined → String(undefined ?? "") === "" → isSafeHttpUrl false.