From 7fb63a9f6f3aedde3ab67823ad4207474ddbd742 Mon Sep 17 00:00:00 2001 From: ZacxDev Date: Sun, 4 Oct 2026 00:47:01 -0500 Subject: [PATCH 1/4] feat(validate): mirror the three app_unlock rules the schema will not express MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `civitai app validate` ACCEPTED every manifest the paid-app path can get wrong, and the server rejected all three at submit. Measured end-to-end with the binary built from origin/main against the binary built from this branch, on four real manifests derived from the civitai-block-starter: fixture origin/main this branch app_unlock, no justification ACCEPTED rc=0 REJECTED rc=1 app_unlock priced 7777 ACCEPTED rc=0 REJECTED rc=1 two app_unlock goods ACCEPTED rc=0 REJECTED rc=1 a CORRECT app_unlock (control) ACCEPTED rc=0 ACCEPTED rc=0 The control is the point: the probe discriminates rather than rejecting everything that mentions app_unlock. WHY THESE THREE BELONG HERE AND THE GENERAL PRICE RANGE DOES NOT `goodsChecks` already ports the goods rules JSON Schema cannot express, and the app_unlock rules pass that same test — the vendored schema does not reject any of them and deliberately will not. Its `priceBuzz.maximum` stays 50000 for every kind with the narrow bound in a prose `description` that names the server validator authoritative; `justification` is absent from `required` and could not be there, because the requirement is conditional on `kind`; and arity is a whole-array property a per-item subschema cannot state. Values mirrored from block-goods.constants.ts (:117, :183, :459) with the server's message text. `blockGoodMinPriceBuzz`/`blockGoodMaxPriceBuzz` are deliberately NOT checks — the schema's minimum/maximum own the general range and re-checking it here would be the duplicated-predicate mistake this file warns about twice. They exist so the message can name the real ceiling, and so the app_unlock check can be scoped to exactly the window where the schema passes (2..50000). Above 50000 this stays SILENT rather than reporting twice what the server reports once. The price message names the KIND'S ceiling, verbatim including the ` for an app_unlock good` suffix. The server's own comment is explicit about why: for an app_unlock that string is the only machine-delivered statement of the real limit, so getting it wrong tells a developer at 5001 to stay "between 2 and 50000" — the bound they just satisfied. ORDER AND ARITY, THE TWO CONTRACTS THAT ARE EASY TO BREAK Checks are inserted at the server's own positions, each ending the entry, because the server is a forEach whose every rejection returns — emitting two findings for one entry would make the local output a different SET from the 400 it predicts. Arity is the exception and is ADDITIVE, at path `goods` rather than `goods[i]`, mirroring the server pushing it and falling through. Arity counts only entries that SURVIVED, mirroring the server's parsed-goods array. That subtlety cost a test round and is now pinned: three unlocks where two fail produce no arity finding at all. The stated limit is that the server also enforces rules this package leaves to the schema, so an entry failing one of those is dropped from its count and cannot be dropped from ours — on a manifest already failing the schema we can report an arity violation the server would not. Same bounded trade the duplicate-id note above already documents. Also updated: the `### Docs` section of the AGENTS.md the CLI writes had ZERO references to goods, earning, unlock or justification, so an agent following it had no route to the rules at all. It now points at apps/guide/earning.md and names the three. Its golden in agent_setup_docs_test.go is updated in the same commit, as that guard's own failure message instructs. VERIFICATION - 22 new subtests, every `want` spelled out rather than built from the code, since these strings are a contract with the server's 400. - 10 mutants, ALL KILLED, each verified to have applied AND compiled before its test result was read: price ceiling 5000->50000; arity 1->2; both comparisons > -> >=; delete the required-justification arm; key it on `good` instead; message names the general ceiling; drop the kind suffix; never count a surviving unlock; drop the TrimSpace. Run under -count=1 so Go's test cache cannot serve a stale pass. ⚠ The first harness scored a false KILL: inline Python lost its quoting, the file was emptied, the BUILD failed, and rc=1 read as a dead mutant with zero failing tests. Rewritten to a file that asserts a unique anchor and refuses on 0 or >1 matches, and the runner now separates "does not compile" from "killed". - Full suite at -count=1: failing-test NAME SET byte-identical to origin/main (6 lines: the 3 container-dependent TestOracle* tests and their subtests, red at base too). Attributable delta zero. gofmt clean, go vet clean. --- internal/cmd/agent_setup_docs_test.go | 7 + internal/cmd/templates/agents-app.md | 7 + internal/validate/semantic.go | 125 +++++++++++++- internal/validate/semantic_test.go | 226 ++++++++++++++++++++++++++ 4 files changed, 363 insertions(+), 2 deletions(-) diff --git a/internal/cmd/agent_setup_docs_test.go b/internal/cmd/agent_setup_docs_test.go index e2008ab3..d87f371e 100644 --- a/internal/cmd/agent_setup_docs_test.go +++ b/internal/cmd/agent_setup_docs_test.go @@ -68,6 +68,13 @@ the manifest fields and the scopes are documented on the docs site, and the - Reference (manifest, scopes, hooks, message bridge, CLI): https://developer.civitai.com/apps/reference/ - Guide: https://developer.civitai.com/apps/guide/ +- **` + "`https://developer.civitai.com/apps/guide/earning.md`" + `** — the three money + rails, and the ONLY place the rules for charging are written out. Fetch it + before declaring a ` + "`goods`" + ` catalog. A paid-for-access app + (` + "`kind: \"app_unlock\"`" + `) carries three rules the JSON Schema does not express, + so a manifest can pass ` + "`civitai app validate`" + ` on an older CLI and still be + rejected at submit: a 5000 Buzz price ceiling rather than the general 50000, + at most one unlock per manifest, and a mandatory ` + "`justification`" + `. - Example apps you can read end-to-end: https://developer.civitai.com/apps/examples - Full doc index for agents: https://developer.civitai.com/llms.txt diff --git a/internal/cmd/templates/agents-app.md b/internal/cmd/templates/agents-app.md index 0f5eefa1..3158ed34 100644 --- a/internal/cmd/templates/agents-app.md +++ b/internal/cmd/templates/agents-app.md @@ -17,6 +17,13 @@ the manifest fields and the scopes are documented on the docs site, and the - Reference (manifest, scopes, hooks, message bridge, CLI): https://developer.civitai.com/apps/reference/ - Guide: https://developer.civitai.com/apps/guide/ +- **`https://developer.civitai.com/apps/guide/earning.md`** — the three money + rails, and the ONLY place the rules for charging are written out. Fetch it + before declaring a `goods` catalog. A paid-for-access app + (`kind: "app_unlock"`) carries three rules the JSON Schema does not express, + so a manifest can pass `civitai app validate` on an older CLI and still be + rejected at submit: a 5000 Buzz price ceiling rather than the general 50000, + at most one unlock per manifest, and a mandatory `justification`. - Example apps you can read end-to-end: https://developer.civitai.com/apps/examples - Full doc index for agents: https://developer.civitai.com/llms.txt diff --git a/internal/validate/semantic.go b/internal/validate/semantic.go index 8881ec5e..136fd13e 100644 --- a/internal/validate/semantic.go +++ b/internal/validate/semantic.go @@ -11,8 +11,7 @@ import ( // block-goods.constants.ts. It is here rather than read out of the vendored // schema because the schema does not contain it and cannot: this bounds the // LENGTH OF THE JSON ENCODING of an opaque object, which JSON Schema has no -// vocabulary for. That makes it the one goods number this package legitimately -// holds a copy of. +// vocabulary for. // // ⚠ The server measures `new TextEncoder().encode(JSON.stringify(payload))`, // i.e. UTF-8 bytes of the compact encoding. Go's `json.Marshal` also emits @@ -21,6 +20,39 @@ import ( // bound is where to look if they ever disagree. const blockGoodPayloadMaxBytes = 2048 +// The `app_unlock` bounds, mirrored from the same server module +// (BLOCK_APP_UNLOCK_MAX_PRICE_BUZZ, BLOCK_APP_UNLOCK_MAX_PER_MANIFEST). +// +// 🔴 THESE QUALIFY UNDER THE SAME TEST AS THE PAYLOAD BOUND ABOVE — the schema +// does not contain them and, here, deliberately will not. The published +// `priceBuzz.maximum` is still 50000 for every kind and the narrow bound lives +// only in a prose `description` that declares the server validator +// authoritative; the arity rule is a whole-array property the per-item subschema +// cannot state at all. So an `app_unlock` priced at 5001, and a second +// `app_unlock` in one manifest, BOTH validate against the vendored schema and +// are rejected at submit. That gap is the reason these are here. +// +// `blockGoodMinPriceBuzz`/`blockGoodMaxPriceBuzz` are NOT checks — the schema's +// `minimum`/`maximum` already own the general range and re-checking it here +// would be the duplicated-predicate mistake this file warns about twice. They +// exist only so the mirrored message can name the real ceiling, and so the +// `app_unlock` check can be scoped to exactly the window where the schema is +// silent (2..50000, where it passes). +const ( + blockGoodMinPriceBuzz = 2 + blockGoodMaxPriceBuzz = 50_000 + blockAppUnlockMaxPriceBuzz = 5_000 + blockAppUnlockMaxPerManifest = 1 +) + +// The two `kind` values, mirroring BLOCK_GOOD_KINDS / BLOCK_GOOD_DEFAULT_KIND. +// `app_unlock` is the one carrying extra rules; `good` is the default an absent +// `kind` resolves to. +const ( + blockGoodDefaultKind = "good" + blockGoodKindAppUnlock = "app_unlock" +) + // semantic.go ports the *semantic* manifest rules the server runs at approve // time in BlockManifestValidator // (civitai/civitai → src/server/services/block-manifest-validator.service.ts). @@ -185,6 +217,7 @@ func goodsChecks(generic map[string]any) []Finding { var out []Finding seen := make(map[string]struct{}, len(raw)) + appUnlockCount := 0 for i, entry := range raw { e, ok := entry.(map[string]any) if !ok { @@ -211,6 +244,66 @@ func goodsChecks(generic map[string]any) []Finding { continue } + // Resolve the kind exactly as the server does: absent or unset means the + // default. A kind that is PRESENT but not a member is the schema's enum to + // reject, and the server `return`s on it — so the entry's kind-specific + // rules below are unreachable for it here too. + kind := blockGoodDefaultKind + if raw, present := e["kind"]; present { + k, isString := raw.(string) + if !isString || (k != blockGoodDefaultKind && k != blockGoodKindAppUnlock) { + continue // `kind must be one of good, app_unlock` — schema-covered. + } + kind = k + } + + // The `app_unlock` price ceiling. Scoped to exactly the window where the + // vendored schema PASSES — a whole number in 2..50000 — because outside it + // the schema's own `minimum`/`maximum`/`type` already reject, and firing + // there too would report twice what the server reports once. + // + // 🔴 The message names the KIND'S ceiling, not the general one, mirroring + // the server verbatim including its ` for an app_unlock good` suffix. The + // server's own comment is explicit that for an `app_unlock` this string is + // the only machine-delivered statement of the real limit: get it wrong and + // a developer at 5001 is told to stay "between 2 and 50000", the bound they + // just satisfied. + if kind == blockGoodKindAppUnlock { + if price, isNumber := toNumber(e["priceBuzz"]); isNumber && + price == float64(int64(price)) && + price >= blockGoodMinPriceBuzz && + price <= blockGoodMaxPriceBuzz && + price > blockAppUnlockMaxPriceBuzz { + out = append(out, newFinding(at+".priceBuzz", fmt.Sprintf( + "%s.priceBuzz must be a whole number between %d and %d Buzz for an %s good", + at, blockGoodMinPriceBuzz, blockAppUnlockMaxPriceBuzz, blockGoodKindAppUnlock))) + continue + } + } + + // `justification`. Shape-checked for ANY good so a developer who explains an + // ordinary item is not rejected for it; REQUIRED only for `app_unlock`. + // + // Only the two rules the schema cannot express are here. The schema already + // carries `minLength: 1` and `maxLength: 500`, and it measures the RAW + // string while the server measures the TRIMMED one — which makes the schema + // never MORE permissive, so its length bound cannot pass something the + // server's rejects. What it CANNOT see is whitespace-only (`" "` satisfies + // `minLength: 1`), and absence (`justification` is not in the schema's + // `required`, and could not be: the requirement is conditional on `kind`). + if raw, present := e["justification"]; present { + if s, isString := raw.(string); !isString || strings.TrimSpace(s) == "" { + out = append(out, newFinding(at+".justification", fmt.Sprintf( + "%s.justification must be a non-empty string", at))) + continue + } + } else if kind == blockGoodKindAppUnlock { + out = append(out, newFinding(at+".justification", fmt.Sprintf( + "%s.justification is required for an %s good — it makes the app paid, so a moderator must be told why", + at, blockGoodKindAppUnlock))) + continue + } + if payload, present := e["payload"]; present { p, ok := payload.(map[string]any) if !ok { @@ -230,7 +323,35 @@ func goodsChecks(generic map[string]any) []Finding { continue } } + + // Reached only by an entry that survived every check above — which is what + // the server's parsed `goods` array holds, and what its arity check counts. + if kind == blockGoodKindAppUnlock { + appUnlockCount++ + } } + + // ARITY, a whole-array property: at most one `app_unlock` per manifest, so + // "is this viewer admitted?" has exactly one answer. Unlike every check in the + // loop this one is ADDITIVE rather than entry-terminating — the server pushes + // it and falls through to return, so it can accompany a per-entry finding. + // Its path is `goods`, not `goods[i]`. + // + // ⚠ THE LIMIT, STATED: the server counts only goods that PARSED, and it + // enforces rules this package deliberately leaves to the schema (the `id` + // pattern and length, `title` length, `description`, the `kind` enum, the + // general price range). An entry failing one of those is dropped from the + // server's count and cannot be dropped from this one, so on a manifest that is + // ALREADY failing the schema the CLI can report an arity violation the server + // would not. Same bounded-and-cosmetic trade as the duplicate-id note above, + // and the same reason: re-implementing the schema's rules here to close it + // would put schema content in a second place. + if appUnlockCount > blockAppUnlockMaxPerManifest { + out = append(out, newFinding("goods", fmt.Sprintf( + "goods may declare at most %d %s good (found %d) — app access is one question with one answer", + blockAppUnlockMaxPerManifest, blockGoodKindAppUnlock, appUnlockCount))) + } + return out } diff --git a/internal/validate/semantic_test.go b/internal/validate/semantic_test.go index 84585be9..dfbd66bc 100644 --- a/internal/validate/semantic_test.go +++ b/internal/validate/semantic_test.go @@ -513,6 +513,232 @@ func TestGoodsChecksMirrorTheServerRulesJSONSchemaCannotExpress(t *testing.T) { } } +// TestAppUnlockGoodsChecksMirrorTheServerRulesTheSchemaWontExpress pins the +// three rules a `kind: "app_unlock"` good carries and an ordinary one does not. +// +// 🔴 WHY THESE BELONG IN THE CLI AT ALL. Unlike the general price range, the +// vendored schema does not reject any of them and deliberately will not: its +// `priceBuzz.maximum` stays 50000 for every kind with the narrow bound in a +// prose `description`, `justification` is absent from `required` (the +// requirement is conditional on `kind`, which a per-item subschema cannot +// state), and arity is a whole-array property. So before this, an `app_unlock` +// priced at 5001 — or a second one, or one with no justification — passed +// `civitai app validate` and was rejected at submit. A clean local verdict for a +// manifest the server refuses is the failure this closes. +// +// Every `want` is spelled out, never built from the code under test, for the +// same reason as the sibling table above: these strings are a contract with the +// server's 400. +func TestAppUnlockGoodsChecksMirrorTheServerRulesTheSchemaWontExpress(t *testing.T) { + // 7_777 and 5_001: neither equals a bound nor is a multiple of one, so a + // mutant hardcoding 5000 — or substituting the general 50000 ceiling — cannot + // survive on them. 4_999/5_000 pin the boundary from below and exactly on it. + unlock := func(id string, priceBuzz int, extra map[string]any) map[string]any { + e := map[string]any{"id": id, "title": "Full access", "priceBuzz": float64(priceBuzz), "kind": "app_unlock"} + for k, v := range extra { + e[k] = v + } + return e + } + justified := map[string]any{"justification": "reviewed: unlocks the editor"} + + cases := []struct { + name string + in map[string]any + want []string + }{ + // ---- justification: required only for app_unlock ---- + { + name: "app_unlock with NO justification → the server's required message", + in: map[string]any{"goods": []any{unlock("access", 500, nil)}}, + want: []string{"goods[0].justification is required for an app_unlock good — it makes the app paid, so a moderator must be told why"}, + }, + { + name: "an ORDINARY good with no justification → nothing (the rule is kind-keyed)", + in: map[string]any{"goods": []any{map[string]any{"id": "credits", "title": "Credits", "priceBuzz": float64(500)}}}, + want: nil, + }, + { + name: "kind omitted entirely resolves to `good` → still nothing", + in: map[string]any{"goods": []any{map[string]any{"id": "credits", "title": "Credits", "priceBuzz": float64(7777)}}}, + want: nil, + }, + { + name: "app_unlock WITH a justification → nothing", + in: map[string]any{"goods": []any{unlock("access", 500, justified)}}, + want: nil, + }, + { + name: "whitespace-only justification → non-empty message, NOT the required one (schema minLength:1 accepts it)", + in: map[string]any{"goods": []any{unlock("access", 500, map[string]any{"justification": " "})}}, + want: []string{"goods[0].justification must be a non-empty string"}, + }, + { + name: "an ORDINARY good's justification is shape-checked too (explaining an item must not be punished, but an empty explanation is still wrong)", + in: map[string]any{"goods": []any{map[string]any{ + "id": "credits", "title": "Credits", "priceBuzz": float64(500), "justification": ""}}}, + want: []string{"goods[0].justification must be a non-empty string"}, + }, + + // ---- priceBuzz: the kind's own ceiling, named in the message ---- + { + name: "app_unlock at 5001 → the message names 5000, the bound it broke, not 50000", + in: map[string]any{"goods": []any{unlock("access", 5001, justified)}}, + want: []string{"goods[0].priceBuzz must be a whole number between 2 and 5000 Buzz for an app_unlock good"}, + }, + { + name: "app_unlock at 7777 → same message (a mutant using the general ceiling passes 7777)", + in: map[string]any{"goods": []any{unlock("access", 7777, justified)}}, + want: []string{"goods[0].priceBuzz must be a whole number between 2 and 5000 Buzz for an app_unlock good"}, + }, + { + name: "app_unlock exactly AT 5000 → nothing (the bound is inclusive)", + in: map[string]any{"goods": []any{unlock("access", 5000, justified)}}, + want: nil, + }, + { + name: "app_unlock at 4999 → nothing", + in: map[string]any{"goods": []any{unlock("access", 4999, justified)}}, + want: nil, + }, + { + name: "an ORDINARY good at 20000 → nothing; the general ceiling is the schema's business", + in: map[string]any{"goods": []any{map[string]any{ + "id": "credits", "title": "Credits", "priceBuzz": float64(20000)}}}, + want: nil, + }, + { + name: "app_unlock at 60000 → NOTHING from here: above the general ceiling the schema already rejects, and reporting too would double what the server reports once", + in: map[string]any{"goods": []any{unlock("access", 60000, justified)}}, + want: nil, + }, + + // ---- the order contract: first hit ends the entry ---- + { + name: "app_unlock over-priced AND unjustified → ONLY the price finding, because the server returns there", + in: map[string]any{"goods": []any{unlock("access", 7777, nil)}}, + want: []string{"goods[0].priceBuzz must be a whole number between 2 and 5000 Buzz for an app_unlock good"}, + }, + { + name: "a whitespace title beats both, mirroring the server's earlier return", + in: map[string]any{"goods": []any{map[string]any{ + "id": "access", "title": " ", "priceBuzz": float64(7777), "kind": "app_unlock"}}}, + want: []string{"goods[0].title must be a non-empty string"}, + }, + + // ---- arity: a whole-array property, path `goods`, additive ---- + { + name: "two app_unlock goods → the arity message, at path `goods`", + in: map[string]any{"goods": []any{unlock("a", 500, justified), unlock("b", 500, justified)}}, + want: []string{"goods may declare at most 1 app_unlock good (found 2) — app access is one question with one answer"}, + }, + { + name: "three app_unlock goods → the count reported is 3 (a mutant hardcoding 2 dies here)", + in: map[string]any{"goods": []any{ + unlock("a", 500, justified), unlock("b", 500, justified), unlock("c", 500, justified)}}, + want: []string{"goods may declare at most 1 app_unlock good (found 3) — app access is one question with one answer"}, + }, + { + name: "one app_unlock beside several ordinary goods → nothing; only unlocks are counted", + in: map[string]any{"goods": []any{ + map[string]any{"id": "c1", "title": "C1", "priceBuzz": float64(500)}, + unlock("access", 500, justified), + map[string]any{"id": "c2", "title": "C2", "priceBuzz": float64(500)}, + }}, + want: nil, + }, + { + name: "arity is ADDITIVE, not entry-terminating: a per-entry finding and the arity finding both appear", + in: map[string]any{"goods": []any{ + unlock("a", 500, justified), + unlock("b", 500, justified), + unlock("c", 7777, justified), + }}, + want: []string{ + "goods[2].priceBuzz must be a whole number between 2 and 5000 Buzz for an app_unlock good", + "goods may declare at most 1 app_unlock good (found 2) — app access is one question with one answer", + }, + }, + { + name: "an entry that FAILED is not counted toward arity, mirroring the server's parsed-goods array", + in: map[string]any{"goods": []any{ + unlock("a", 500, justified), + unlock("b", 7777, justified), // fails on price, so it never counts + }}, + want: []string{"goods[1].priceBuzz must be a whole number between 2 and 5000 Buzz for an app_unlock good"}, + }, + + // ---- an invalid kind is the schema's enum to reject ---- + { + name: "kind present but not a member → skipped here, so no app_unlock rule is applied to it", + in: map[string]any{"goods": []any{map[string]any{ + "id": "access", "title": "Access", "priceBuzz": float64(7777), "kind": "app_subscription"}}}, + want: nil, + }, + } + + produced := 0 + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + got := goodsChecks(tc.in) + produced += len(got) + if len(got) != len(tc.want) { + t.Fatalf("got %d finding(s), want %d\n got: %v\n want: %v", + len(got), len(tc.want), got, tc.want) + } + for i := range tc.want { + if got[i].Message != tc.want[i] { + t.Errorf("finding %d message mismatch\n got: %q\n want: %q", + i, got[i].Message, tc.want[i]) + } + } + }) + } + + // A table whose rows mostly expect nil passes against a goodsChecks wired to + // nothing, so assert the table did make it speak. + if produced == 0 { + t.Fatal("no case produced a finding — the app_unlock checks may be unreachable and every nil row would still pass") + } +} + +// TestAppUnlockFindingsCarryTheOffendingFieldPath pins the Field. The arity +// finding is the interesting one: it is the only goods finding whose path is the +// ARRAY rather than an element, because the rule is a property of the whole +// catalog and there is no single entry to blame. +// +// It also pins the subtlety that cost this test a round: TWO entries must +// SURVIVE for arity to fire, because a failing entry is excluded from the count +// (mirroring the server's parsed-goods array). A fixture of three unlocks where +// two of them fail produces no arity finding at all. +func TestAppUnlockFindingsCarryTheOffendingFieldPath(t *testing.T) { + justified := map[string]any{"justification": "reviewed"} + unlock := func(id string, price int, extra map[string]any) map[string]any { + e := map[string]any{"id": id, "title": "T", "priceBuzz": float64(price), "kind": "app_unlock"} + for k, v := range extra { + e[k] = v + } + return e + } + + got := goodsChecks(map[string]any{"goods": []any{ + unlock("a", 500, justified), // survives → counted + unlock("b", 500, nil), // missing justification → NOT counted + unlock("c", 500, justified), // survives → counted, so the count reaches 2 + unlock("d", 7777, justified), // over the unlock ceiling → NOT counted + }}) + + want := []string{"goods[1].justification", "goods[3].priceBuzz", "goods"} + if len(got) != len(want) { + t.Fatalf("got %d finding(s), want %d: %v", len(got), len(want), got) + } + for i := range want { + if got[i].Field != want[i] { + t.Errorf("finding %d field: got %q, want %q", i, got[i].Field, want[i]) + } + } +} + // TestGoodsFindingsCarryTheOffendingFieldPath pins the Field, not the Message. // The two are separate claims: `--json` consumers key on Field, and a finding // whose text names goods[1] while its Field says something else sends a tool to From 001e5726ddac528a8c6d8be0e4802caf39e1959c Mon Sep 17 00:00:00 2001 From: ZacxDev Date: Sun, 4 Oct 2026 02:27:31 -0500 Subject: [PATCH 2/4] fix(validate): the price clamp named a bound 10x too high; and two audit findings answered, one rejected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Round 0 on this PR found four defects in it. Three are fixed, one is REJECTED with its evidence, and the reasoning that produced the worst of them is replaced rather than patched. D1 — ACCEPTED, and it was the real one. The price check was clamped to the window where the vendored schema passes (2..50000) "so as not to report twice what the server reports once". Measured consequence: an app_unlock at 60000 got ONLY the schema's `maximum: got 60,000, want 50,000` — ten times the real ceiling — so a developer is told to come down to 50000, does, and is rejected again with a different number. Verified against both binaries: priceBuzz 60000 before: `maximum: got 60,000, want 50,000` (alone) after: `must be a whole number between 2 and 5000 Buzz for an app_unlock good`, beside the schema's priceBuzz 5000 before: silent after: silent (the control) 🔴 AND THE RATIONALE WAS FALSE, WHICH IS WHY THE COMMENT IS REWRITTEN AND NOT JUST THE CODE. "Never report twice" is not an invariant this file holds: a goods entry with no `title` already emits both `goods[0].title must be a non-empty string` here AND `goods[0]: missing property 'title'` from the schema, and did so before any of this landed. The clamp bought consistency with a rule that never existed, at the cost of naming the wrong bound. The constant block now states the rule the file ACTUALLY holds — mirror the server's sentence, and accept that the schema may fire alongside it — so the next reader does not re-derive the clamp. The check now mirrors the server's own condition for the kind: whole number, 2 to 5000, unclamped above. `blockGoodMaxPriceBuzz` existed only for the clamp and is deleted. D4 — ACCEPTED. The stated justification, "JSON Schema cannot express these", is false: the dialect is draft/2020-12, where `if`/`then` + `required` expresses the conditional justification, `contains` + `maxContains: 1` the arity, and `if`/`then` + `maximum` the kind's ceiling. The upstream constants file says so itself — "a conditional if/then on kind there is more surface than this one property is worth" — i.e. considered and DECLINED, not impossible. The honest reason is ownership: the vendored schema is an auto-revendored byte-mirror this repo may not unilaterally edit. The comment now says that, and says plainly that declaring the rules upstream would be the better fix because it would cover the SDK, the docs site and every third-party validator — which the false version foreclosed by making it look unavailable. D5 — ACCEPTED. The AGENTS.md bullet called earning.md "the ONLY place the rules for charging are written out". Measured: that page is HTTP 200, 33,805 B, and contains `app_unlock` once in a table cell, zero occurrences of 5000, no arity statement and no goods-justification rule — live AND at civitai-developer-docs@origin/main, so not deploy lag. It is the sibling docs PR, unmerged. The claim is removed; the three rules stay stated inline, which is what an agent can act on regardless of what the page says. D3 — REJECTED, with the evidence, and pinned so it is not re-raised. The audit read the invalid-`kind` skip as suppressing the payload byte-size finding, the one goods rule JSON Schema provably cannot express. It does suppress it — and so does the SERVER: its kind check returns at block-goods.constants.ts:385-387, before its own payload check at :464. Mirroring that is this file's entire contract, so "fixing" it would be the divergence. Two new cases pin both arms: an invalid kind suppresses the payload finding, and the SAME oversized payload under a valid kind still reports it — the control proving the case is about `kind` and not about payload detection going blind. D2 — not taken, and the reason is D1. The `!isString` half of the justification check does double-report with the schema's `type`. With the clamp gone that is no longer an inconsistency but the file's stated rule, applied uniformly: the author gets the server's own sentence either way. Also: "22 new subtests" in the previous commit message was an overstatement, reachable only by counting the two top-level funcs as subtests. Measured: 25 table rows + 2 funcs. The PR body carries a visible correction. VERIFICATION - 27 PASS / 0 FAIL on the app_unlock tests (25 rows + 2 funcs), including a regression guard whose name records the defect, and the two D3 control cases. - Six mutants re-run against the REWRITTEN check, ALL KILLED, each verified to have applied and compiled first, under -count=1: ceiling 5000->50000; RE-ADDING the clamp that caused the defect; `>` -> `>=`; dropping the whole-number arm; dropping the floor arm; arity 1->2. The clamp mutant is the one that matters — the guard catches a reintroduction. - Full suite -count=1: failing-test NAME SET still byte-identical to origin/main (the 6 container-dependent TestOracle* lines). Attributable delta zero. gofmt clean, go vet clean on ./internal/... --- internal/cmd/agent_setup_docs_test.go | 12 ++-- internal/cmd/templates/agents-app.md | 12 ++-- internal/validate/semantic.go | 98 +++++++++++++++++++-------- internal/validate/semantic_test.go | 51 +++++++++++++- 4 files changed, 131 insertions(+), 42 deletions(-) diff --git a/internal/cmd/agent_setup_docs_test.go b/internal/cmd/agent_setup_docs_test.go index d87f371e..70b6643f 100644 --- a/internal/cmd/agent_setup_docs_test.go +++ b/internal/cmd/agent_setup_docs_test.go @@ -69,12 +69,12 @@ the manifest fields and the scopes are documented on the docs site, and the https://developer.civitai.com/apps/reference/ - Guide: https://developer.civitai.com/apps/guide/ - **` + "`https://developer.civitai.com/apps/guide/earning.md`" + `** — the three money - rails, and the ONLY place the rules for charging are written out. Fetch it - before declaring a ` + "`goods`" + ` catalog. A paid-for-access app - (` + "`kind: \"app_unlock\"`" + `) carries three rules the JSON Schema does not express, - so a manifest can pass ` + "`civitai app validate`" + ` on an older CLI and still be - rejected at submit: a 5000 Buzz price ceiling rather than the general 50000, - at most one unlock per manifest, and a mandatory ` + "`justification`" + `. + rails. Fetch it before declaring a ` + "`goods`" + ` catalog. The three rules below are + stated here too, because they are the ones a manifest can break while passing + an older ` + "`civitai app validate`" + `: a paid-for-access app (` + "`kind: \"app_unlock\"`" + `) + is capped at **5000** Buzz rather than the general 50000, may declare **at + most one** unlock per manifest, and MUST carry a ` + "`justification`" + `. All three are + enforced at submit; the published JSON Schema does not declare them. - Example apps you can read end-to-end: https://developer.civitai.com/apps/examples - Full doc index for agents: https://developer.civitai.com/llms.txt diff --git a/internal/cmd/templates/agents-app.md b/internal/cmd/templates/agents-app.md index 3158ed34..3252fffc 100644 --- a/internal/cmd/templates/agents-app.md +++ b/internal/cmd/templates/agents-app.md @@ -18,12 +18,12 @@ the manifest fields and the scopes are documented on the docs site, and the https://developer.civitai.com/apps/reference/ - Guide: https://developer.civitai.com/apps/guide/ - **`https://developer.civitai.com/apps/guide/earning.md`** — the three money - rails, and the ONLY place the rules for charging are written out. Fetch it - before declaring a `goods` catalog. A paid-for-access app - (`kind: "app_unlock"`) carries three rules the JSON Schema does not express, - so a manifest can pass `civitai app validate` on an older CLI and still be - rejected at submit: a 5000 Buzz price ceiling rather than the general 50000, - at most one unlock per manifest, and a mandatory `justification`. + rails. Fetch it before declaring a `goods` catalog. The three rules below are + stated here too, because they are the ones a manifest can break while passing + an older `civitai app validate`: a paid-for-access app (`kind: "app_unlock"`) + is capped at **5000** Buzz rather than the general 50000, may declare **at + most one** unlock per manifest, and MUST carry a `justification`. All three are + enforced at submit; the published JSON Schema does not declare them. - Example apps you can read end-to-end: https://developer.civitai.com/apps/examples - Full doc index for agents: https://developer.civitai.com/llms.txt diff --git a/internal/validate/semantic.go b/internal/validate/semantic.go index 136fd13e..78453fc1 100644 --- a/internal/validate/semantic.go +++ b/internal/validate/semantic.go @@ -23,24 +23,50 @@ const blockGoodPayloadMaxBytes = 2048 // The `app_unlock` bounds, mirrored from the same server module // (BLOCK_APP_UNLOCK_MAX_PRICE_BUZZ, BLOCK_APP_UNLOCK_MAX_PER_MANIFEST). // -// 🔴 THESE QUALIFY UNDER THE SAME TEST AS THE PAYLOAD BOUND ABOVE — the schema -// does not contain them and, here, deliberately will not. The published -// `priceBuzz.maximum` is still 50000 for every kind and the narrow bound lives -// only in a prose `description` that declares the server validator -// authoritative; the arity rule is a whole-array property the per-item subschema -// cannot state at all. So an `app_unlock` priced at 5001, and a second -// `app_unlock` in one manifest, BOTH validate against the vendored schema and -// are rejected at submit. That gap is the reason these are here. +// 🔴 WHY THESE ARE HERE, STATED CORRECTLY — the first draft said "JSON Schema +// cannot express them" and that is FALSE, so do not re-derive it. The dialect is +// draft/2020-12, where all three ARE expressible: `if`/`then` + `required` for +// the conditional `justification`, `contains` + `maxContains: 1` for the arity, +// `if`/`then` + `maximum` for the kind's ceiling. The upstream constants file +// says so itself — *"a conditional `if/then` on `kind` there is more surface than +// this one property is worth"* — i.e. CONSIDERED AND DECLINED, not impossible. // -// `blockGoodMinPriceBuzz`/`blockGoodMaxPriceBuzz` are NOT checks — the schema's -// `minimum`/`maximum` already own the general range and re-checking it here -// would be the duplicated-predicate mistake this file warns about twice. They -// exist only so the mirrored message can name the real ceiling, and so the -// `app_unlock` check can be scoped to exactly the window where the schema is -// silent (2..50000, where it passes). +// The real reason is ownership: `schema/app-block.manifest.schema.json` is an +// auto-revendored BYTE-MIRROR of `civitai:public/schemas/app-block/v1.json`, and +// this repo may not unilaterally edit it — a local change would be reverted by +// the next re-vendor. So the Go port is the only layer the CLI controls. +// +// ⚠ THAT MAKES THIS A SECOND-BEST FIX, AND SAYING SO IS THE POINT: declaring the +// three rules upstream would cover the SDK, developer.civitai.com and every +// third-party validator, and would make most of this block redundant. The false +// "cannot express" version foreclosed that option by making it look unavailable. +// If you are reading this while touching these rules, the upstream change is the +// better one to argue for. +// +// Measured consequence of the current state: an `app_unlock` priced at 5001, and +// a second `app_unlock` in one manifest, BOTH validate against the vendored +// schema and are rejected at submit. +// +// `blockGoodMinPriceBuzz` is NOT a check — the schema's `minimum` owns the +// general floor. It exists so the mirrored message can state the real range. +// +// 🔴 THE RULE THIS FILE ACTUALLY HOLDS IS "MIRROR THE SERVER'S SENTENCE", NOT +// "NEVER REPORT TWICE" — and an earlier draft of this block asserted the latter, +// which is false about the code it sits in. A goods entry with no `title` already +// emits BOTH `goods[0].title must be a non-empty string` (here) and +// `goods[0]: missing property 'title'` (schema), and has since before this +// block existed. So a non-report rule was never the invariant. +// +// That mattered, because the false invariant bought a real defect: an earlier +// draft scoped the `app_unlock` price check to 2..50000 "so as not to report +// twice", and an `app_unlock` at 60000 then got ONLY the schema's +// `maximum: got 60,000, want 50,000` — 10x the real ceiling. A developer is told +// to come down to 50000, does, and is rejected again with a different number. +// 🔴 NAMING THE WRONG BOUND IS WORSE THAN NAMING IT TWICE. The check below is +// therefore unclamped above: for an `app_unlock` it fires on the server's own +// condition, and the schema may fire alongside it. const ( blockGoodMinPriceBuzz = 2 - blockGoodMaxPriceBuzz = 50_000 blockAppUnlockMaxPriceBuzz = 5_000 blockAppUnlockMaxPerManifest = 1 ) @@ -248,6 +274,17 @@ func goodsChecks(generic map[string]any) []Finding { // default. A kind that is PRESENT but not a member is the schema's enum to // reject, and the server `return`s on it — so the entry's kind-specific // rules below are unreachable for it here too. + // + // ⚠ AUDIT FINDING REJECTED, WITH THE EVIDENCE, SO IT IS NOT RE-RAISED: a + // round-0 pass read this `continue` as suppressing the `payload` byte-size + // finding — the one goods rule JSON Schema provably cannot express — for an + // entry whose `kind` is invalid. It does, and that is CORRECT: the server's + // kind check `return`s at block-goods.constants.ts:385-387, well before its + // own payload check at :464, so it suppresses the identical finding. Making + // the CLI continue to the payload check here would be a DIVERGENCE from the + // server, which is the one thing this file exists not to do. The cost is + // real but is the server's: an author with both defects learns about the + // kind first and the payload on the next run. kind := blockGoodDefaultKind if raw, present := e["kind"]; present { k, isString := raw.(string) @@ -257,23 +294,26 @@ func goodsChecks(generic map[string]any) []Finding { kind = k } - // The `app_unlock` price ceiling. Scoped to exactly the window where the - // vendored schema PASSES — a whole number in 2..50000 — because outside it - // the schema's own `minimum`/`maximum`/`type` already reject, and firing - // there too would report twice what the server reports once. + // The `app_unlock` price ceiling, mirroring the server's own condition for + // this kind: a whole number in 2..5000. Deliberately NOT clamped to the + // window where the vendored schema passes — see the constant block for why + // that clamp was a defect rather than a courtesy. Above 50000 the schema + // fires too; two findings naming the right bound beat one naming a bound + // 10x too high. + // + // A non-numeric `priceBuzz` is left to the schema's `type`: `toNumber` + // cannot evaluate the server's condition on it, so there is nothing to + // mirror. // - // 🔴 The message names the KIND'S ceiling, not the general one, mirroring - // the server verbatim including its ` for an app_unlock good` suffix. The - // server's own comment is explicit that for an `app_unlock` this string is - // the only machine-delivered statement of the real limit: get it wrong and - // a developer at 5001 is told to stay "between 2 and 50000", the bound they - // just satisfied. + // 🔴 The message names the KIND'S ceiling, not the general one, verbatim + // including the ` for an app_unlock good` suffix. The server's own comment + // is explicit that for an `app_unlock` this string is the only + // machine-delivered statement of the real limit. if kind == blockGoodKindAppUnlock { if price, isNumber := toNumber(e["priceBuzz"]); isNumber && - price == float64(int64(price)) && - price >= blockGoodMinPriceBuzz && - price <= blockGoodMaxPriceBuzz && - price > blockAppUnlockMaxPriceBuzz { + (price != float64(int64(price)) || + price < blockGoodMinPriceBuzz || + price > blockAppUnlockMaxPriceBuzz) { out = append(out, newFinding(at+".priceBuzz", fmt.Sprintf( "%s.priceBuzz must be a whole number between %d and %d Buzz for an %s good", at, blockGoodMinPriceBuzz, blockAppUnlockMaxPriceBuzz, blockGoodKindAppUnlock))) diff --git a/internal/validate/semantic_test.go b/internal/validate/semantic_test.go index dfbd66bc..ab04578d 100644 --- a/internal/validate/semantic_test.go +++ b/internal/validate/semantic_test.go @@ -608,8 +608,34 @@ func TestAppUnlockGoodsChecksMirrorTheServerRulesTheSchemaWontExpress(t *testing want: nil, }, { - name: "app_unlock at 60000 → NOTHING from here: above the general ceiling the schema already rejects, and reporting too would double what the server reports once", + // 🔴 REGRESSION GUARD for the defect a round-0 audit found. An earlier + // draft clamped this check to 2..50000 "so as not to double-report with + // the schema", so a 60000 unlock got ONLY the schema's + // `maximum: got 60,000, want 50,000` — 10x the real ceiling, telling a + // developer to come down to a bound they are still 55000 over. The + // schema fires here too; naming the right bound twice beats naming the + // wrong one once. + name: "app_unlock at 60000 → still names 5000, NOT the general 50000 the schema would quote", in: map[string]any{"goods": []any{unlock("access", 60000, justified)}}, + want: []string{"goods[0].priceBuzz must be a whole number between 2 and 5000 Buzz for an app_unlock good"}, + }, + { + name: "app_unlock at 1 → below the floor, and the message states the real range", + in: map[string]any{"goods": []any{unlock("access", 1, justified)}}, + want: []string{"goods[0].priceBuzz must be a whole number between 2 and 5000 Buzz for an app_unlock good"}, + }, + { + name: "app_unlock at a FRACTIONAL price → not a whole number, same message", + in: map[string]any{"goods": []any{map[string]any{ + "id": "access", "title": "T", "priceBuzz": 500.5, "kind": "app_unlock", + "justification": "reviewed"}}}, + want: []string{"goods[0].priceBuzz must be a whole number between 2 and 5000 Buzz for an app_unlock good"}, + }, + { + name: "a NON-NUMERIC priceBuzz is left to the schema's `type` — nothing to mirror", + in: map[string]any{"goods": []any{map[string]any{ + "id": "access", "title": "T", "priceBuzz": "500", "kind": "app_unlock", + "justification": "reviewed"}}}, want: nil, }, @@ -675,6 +701,29 @@ func TestAppUnlockGoodsChecksMirrorTheServerRulesTheSchemaWontExpress(t *testing "id": "access", "title": "Access", "priceBuzz": float64(7777), "kind": "app_subscription"}}}, want: nil, }, + { + // 🔴 PINS AN AUDIT FINDING THAT WAS **REJECTED**, so nobody "fixes" it + // into a divergence. A round-0 pass read the invalid-kind skip as + // suppressing the payload byte-size finding. It does — and the SERVER + // does the same: its kind check returns at + // block-goods.constants.ts:385-387, before its payload check at :464. + // Mirroring that is this file's contract. If this case ever starts + // reporting the payload finding, the CLI has diverged from the server. + name: "an invalid kind suppresses the payload finding, exactly as the server's early return does", + in: map[string]any{"goods": []any{map[string]any{ + "id": "access", "title": "T", "priceBuzz": float64(500), "kind": "nope", + "payload": map[string]any{"note": strings.Repeat("x", 4096)}}}, + }, + want: nil, + }, + { + name: "the SAME oversized payload under a VALID kind DOES report — the control proving the case above is about `kind`, not about payload detection", + in: map[string]any{"goods": []any{map[string]any{ + "id": "access", "title": "T", "priceBuzz": float64(500), "kind": "good", + "payload": map[string]any{"note": strings.Repeat("x", 4096)}}}, + }, + want: []string{"goods[0].payload must serialize to at most 2048 bytes"}, + }, } produced := 0 From 30fd72fa88b4cbc9ff5b9de1d1e625dd26bc1e54 Mon Sep 17 00:00:00 2001 From: ZacxDev Date: Sun, 4 Oct 2026 04:08:17 -0500 Subject: [PATCH 3/4] fix(validate): the round-1 fix made a constant a check and left the comment saying it was not MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Round 2 returned one 🟡 and two 🟢, all three about prose the round-1 fix wrote. No behaviour defect; no 🔴. The round also independently confirmed, at the server source, that round 1's REJECTION of the payload-suppression finding was correct. 🟡1 — the comment-as-claim defect, and it is the same class round 1 existed to cure. Round 1 deleted the clamp and left the sentence "`blockGoodMinPriceBuzz` is NOT a check — the schema's `minimum` owns the general floor". That was true WHILE the check was clamped and became false the moment the clamp came off: the new condition tests `price < blockGoodMinPriceBuzz`, so `{"kind":"app_unlock","priceBuzz":0}` emits the mirrored sentence AND the schema's `minimum: got 0, want 2`. A maintainer taking "NOT a check" at face value could delete the floor arm. 🔴 AND THE FIX IS NOT JUST TO SWAP THE WORD, BECAUSE THE FLOOR ARM'S JUSTIFICATION IS NOT THE CEILING'S. Round 1's argument — "naming the wrong bound is worse than naming it twice" — is CEILING-SPECIFIC: the floor is 2 in the schema, in the server and here, so on that arm the second message corrects no bound and is pure duplication. The arm is kept anyway, because it is what makes this a faithful copy of the server's single condition rather than a hand-picked subset, and the comment now says so — otherwise the next reader deletes it on exactly the "pure duplication" reasoning the old sentence invited. 🟢2 — AN UNADVERTISED BEHAVIOUR CHANGE, VERIFIED CORRECT AND NOW DOCUMENTED AND PINNED. Because the price check `continue`s, an over-cap unlock never reaches the arity counter, so two unlocks with one at 60000 report the price error ALONE where before the clamp came off they also reported arity. That is the server's behaviour, and reading its source turned up a SECOND consequence nobody had checked: block-goods.constants.ts:501-509 states "two unlocks where one is over-cap reports ONLY the price error, and two unlocks sharing an id report ONLY the duplicate error". Verified both hold here, and added a row for each — the duplicate-unlock case was previously untested in either direction. ⚠ Worth recording: the price arm of that mirror only became true when the clamp came off. While the check was scoped to 2..50000, a 60000 unlock did NOT `continue`, so it WAS counted and a second over-cap unlock reported an arity error the server would not have. Removing the clamp fixed a second mirror defect nobody had looked for, and the commit that did it did not know. 🟢3 — "The three rules below are stated here too" parses two ways, and the wrong reading ("earning.md states them as well") is the claim the previous commit removed as false. Now "repeated in this file deliberately". Template and golden in the same commit. VERIFICATION - 29 PASS / 0 FAIL on the app_unlock tests (was 27; two arity-mirror rows added). - Real binary, two unlocks with one at 60000: the price errors only, NO arity finding — the server's documented behaviour, reproduced rather than reasoned. - Full suite -count=1: failing-test NAME SET still byte-identical to origin/main. Attributable delta zero. gofmt clean, go vet clean, and the pinned `### Docs` golden plus the URL ledger both green. --- internal/cmd/agent_setup_docs_test.go | 4 ++-- internal/cmd/templates/agents-app.md | 4 ++-- internal/validate/semantic.go | 31 +++++++++++++++++++++++++-- internal/validate/semantic_test.go | 18 ++++++++++++++++ 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/internal/cmd/agent_setup_docs_test.go b/internal/cmd/agent_setup_docs_test.go index 70b6643f..bb677a10 100644 --- a/internal/cmd/agent_setup_docs_test.go +++ b/internal/cmd/agent_setup_docs_test.go @@ -70,8 +70,8 @@ the manifest fields and the scopes are documented on the docs site, and the - Guide: https://developer.civitai.com/apps/guide/ - **` + "`https://developer.civitai.com/apps/guide/earning.md`" + `** — the three money rails. Fetch it before declaring a ` + "`goods`" + ` catalog. The three rules below are - stated here too, because they are the ones a manifest can break while passing - an older ` + "`civitai app validate`" + `: a paid-for-access app (` + "`kind: \"app_unlock\"`" + `) + repeated in this file deliberately, because they are the ones a manifest can + break while passing an older ` + "`civitai app validate`" + `: a paid-for-access app (` + "`kind: \"app_unlock\"`" + `) is capped at **5000** Buzz rather than the general 50000, may declare **at most one** unlock per manifest, and MUST carry a ` + "`justification`" + `. All three are enforced at submit; the published JSON Schema does not declare them. diff --git a/internal/cmd/templates/agents-app.md b/internal/cmd/templates/agents-app.md index 3252fffc..8e1f4af2 100644 --- a/internal/cmd/templates/agents-app.md +++ b/internal/cmd/templates/agents-app.md @@ -19,8 +19,8 @@ the manifest fields and the scopes are documented on the docs site, and the - Guide: https://developer.civitai.com/apps/guide/ - **`https://developer.civitai.com/apps/guide/earning.md`** — the three money rails. Fetch it before declaring a `goods` catalog. The three rules below are - stated here too, because they are the ones a manifest can break while passing - an older `civitai app validate`: a paid-for-access app (`kind: "app_unlock"`) + repeated in this file deliberately, because they are the ones a manifest can + break while passing an older `civitai app validate`: a paid-for-access app (`kind: "app_unlock"`) is capped at **5000** Buzz rather than the general 50000, may declare **at most one** unlock per manifest, and MUST carry a `justification`. All three are enforced at submit; the published JSON Schema does not declare them. diff --git a/internal/validate/semantic.go b/internal/validate/semantic.go index 78453fc1..1b187928 100644 --- a/internal/validate/semantic.go +++ b/internal/validate/semantic.go @@ -47,8 +47,21 @@ const blockGoodPayloadMaxBytes = 2048 // a second `app_unlock` in one manifest, BOTH validate against the vendored // schema and are rejected at submit. // -// `blockGoodMinPriceBuzz` is NOT a check — the schema's `minimum` owns the -// general floor. It exists so the mirrored message can state the real range. +// ⚠ `blockGoodMinPriceBuzz` IS part of a check, and an earlier draft of this +// very block said it was not — "NOT a check; the schema's `minimum` owns the +// general floor". That was true while the price check was clamped and became +// false the moment the clamp came off: the condition below tests +// `price < blockGoodMinPriceBuzz`, so `{"kind":"app_unlock","priceBuzz":0}` +// emits the mirrored sentence AND the schema's `minimum: got 0, want 2`. +// +// 🔴 AND THE FLOOR ARM'S JUSTIFICATION IS NOT THE CEILING'S — do not collapse +// them. The wrong-bound argument below is CEILING-SPECIFIC: the floor is 2 in +// the schema, in the server and here, so on that arm the second message corrects +// no bound and is pure duplication. It is kept anyway, because the arm is how +// the mirror stays a faithful copy of the server's single condition rather than +// a hand-picked subset of it — and because a reader who deletes it on the +// "pure duplication" reasoning silently drops a server rule. The `app_unlock at +// 1` test row is what catches that deletion. // // 🔴 THE RULE THIS FILE ACTUALLY HOLDS IS "MIRROR THE SERVER'S SENTENCE", NOT // "NEVER REPORT TWICE" — and an earlier draft of this block asserted the latter, @@ -377,6 +390,20 @@ func goodsChecks(generic map[string]any) []Finding { // it and falls through to return, so it can accompany a per-entry finding. // Its path is `goods`, not `goods[i]`. // + // ⚠ AN EARLIER PER-ENTRY FINDING SUPPRESSES THIS ONE, and that is the server's + // behaviour rather than a side effect worth removing. Every per-entry check + // above `continue`s, so a failing entry never reaches the counter. The server + // states the same two consequences in its own words at + // block-goods.constants.ts:501-509 — "two unlocks where one is over-cap + // reports ONLY the price error, and two unlocks sharing an id report ONLY the + // duplicate error" — and both now hold here, each pinned by its own row below. + // + // Note the price arm of that only became true when the clamp came off: while + // the check was scoped to 2..50000, an unlock at 60000 did NOT `continue`, so + // it was counted and a second over-cap unlock reported the arity error the + // server would not have reported. Removing the clamp fixed a mirror defect + // nobody had looked for. + // // ⚠ THE LIMIT, STATED: the server counts only goods that PARSED, and it // enforces rules this package deliberately leaves to the schema (the `id` // pattern and length, `title` length, `description`, the `kind` enum, the diff --git a/internal/validate/semantic_test.go b/internal/validate/semantic_test.go index ab04578d..dc433f91 100644 --- a/internal/validate/semantic_test.go +++ b/internal/validate/semantic_test.go @@ -685,6 +685,24 @@ func TestAppUnlockGoodsChecksMirrorTheServerRulesTheSchemaWontExpress(t *testing "goods may declare at most 1 app_unlock good (found 2) — app access is one question with one answer", }, }, + { + // The server's SECOND stated arity consequence + // (block-goods.constants.ts:501-509): "two unlocks sharing an id report + // ONLY the duplicate error (the duplicate is dropped before the count, + // so it never reaches the arity rule at all)". + name: "two unlocks sharing an id → ONLY the duplicate error, never the arity one", + in: map[string]any{"goods": []any{unlock("access", 500, justified), unlock("access", 600, justified)}}, + want: []string{`goods[1].id duplicates an earlier good id ("access")`}, + }, + { + // The server's FIRST stated consequence, at a price ABOVE the general + // ceiling — the case the removed clamp got wrong. While the check was + // scoped to 2..50000 this entry did not `continue`, so it WAS counted + // and the arity error fired where the server's would not have. + name: "two unlocks, one at 60000 → ONLY the price error; the over-cap entry never reaches the counter", + in: map[string]any{"goods": []any{unlock("a", 500, justified), unlock("b", 60000, justified)}}, + want: []string{"goods[1].priceBuzz must be a whole number between 2 and 5000 Buzz for an app_unlock good"}, + }, { name: "an entry that FAILED is not counted toward arity, mirroring the server's parsed-goods array", in: map[string]any{"goods": []any{ From 8c1cdec8c9dbcabec02e221cd726bf633996ecb3 Mon Sep 17 00:00:00 2001 From: ZacxDev Date: Sun, 4 Oct 2026 12:16:59 -0500 Subject: [PATCH 4/4] docs(validate): the arity headline said "suppresses", which is false and contradicted the line above it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Round 3 returned exactly one finding and it is this: round 2's new paragraph opened "AN EARLIER PER-ENTRY FINDING SUPPRESSES THIS ONE". That is false, and it contradicted BOTH the paragraph three lines above it — "Unlike every check in the loop this one is ADDITIVE rather than entry-terminating" — and a test row named after that paragraph, `arity is ADDITIVE, not entry-terminating`, which has existed since 7fb63a9. Measured with the real binary, three unlocks with one over-cap (500, 500, 7777): BOTH the arity finding and the price finding appear. A failing entry is excluded from the COUNT, so the arity finding disappears only when what SURVIVES is one unlock or fewer. Both server consequences the paragraph quotes are 2-unlock cases, where the surviving count happens to fall to 1 — which is exactly why the wrong headline read plausibly over correct examples. The paragraph now states the narrow, true version, and carries a line telling the next writer not to restate it the wrong way, because this is the third time in this ladder that a fix round's own PROSE was the next finding. No test added: the three-unlock case is already pinned by the `arity is ADDITIVE` row, which round 3 confirmed would catch the edit the false headline invited. 🔴 THIS ENDS THE LADDER ON THE ATTRIBUTION GATE, NOT ON A CLEAN ROUND. Round 3 changed 35 payload lines at file level but ZERO executable lines — `semantic.go`'s delta was 100% comments, proven by comment-stripped comparison. This round is comment-only too, by the same proof (stripped source byte-identical to 30fd72f). That is two consecutive rounds whose fixes changed no executable line, which is the unit the two-consecutive-zeros stop rule is written in: the ladder is now auditing its own prose rather than the PR. Stopping here deliberately, with the reason recorded, rather than running a fourth round. VERIFICATION - 29 PASS / 0 FAIL on the app_unlock tests; build, vet and gofmt clean. - Comment-stripped `semantic.go` is byte-identical to 30fd72f, so there is no behaviour change in this commit and round 3's measurements still stand. - Round 3 independently reproduced BOTH payload figures the assembler could not read (35 for round 2, 110 for round 1) from a checkout holding both ends, and re-verified the cross-repo line references :385-387, :464 and :501-509. --- internal/validate/semantic.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/internal/validate/semantic.go b/internal/validate/semantic.go index 1b187928..24960bdc 100644 --- a/internal/validate/semantic.go +++ b/internal/validate/semantic.go @@ -390,13 +390,24 @@ func goodsChecks(generic map[string]any) []Finding { // it and falls through to return, so it can accompany a per-entry finding. // Its path is `goods`, not `goods[i]`. // - // ⚠ AN EARLIER PER-ENTRY FINDING SUPPRESSES THIS ONE, and that is the server's - // behaviour rather than a side effect worth removing. Every per-entry check - // above `continue`s, so a failing entry never reaches the counter. The server - // states the same two consequences in its own words at + // ⚠ A FAILING ENTRY IS NOT COUNTED, WHICH CAN TAKE THE SURVIVING COUNT BELOW + // THE LIMIT — it does not suppress this check in general. Every per-entry + // check above `continue`s, so a failing entry never reaches the counter; the + // arity finding then disappears only when what SURVIVES is one unlock or + // fewer. With three unlocks and one over-cap, two survive and BOTH findings + // appear — which is the ADDITIVE property stated directly above, and is + // pinned by the `arity is ADDITIVE` row below. + // + // ⚠ Do not restate this as "an earlier finding suppresses the arity one". An + // earlier draft of this paragraph did, and it was false while reading + // plausibly, because BOTH server consequences quoted next are 2-unlock cases + // where the surviving count happens to fall to 1. It also contradicted the + // paragraph three lines above it and a test row named after that paragraph. + // + // The two consequences, in the server's own words at // block-goods.constants.ts:501-509 — "two unlocks where one is over-cap // reports ONLY the price error, and two unlocks sharing an id report ONLY the - // duplicate error" — and both now hold here, each pinned by its own row below. + // duplicate error" — both hold here, each pinned by its own row below. // // Note the price arm of that only became true when the clamp came off: while // the check was scoped to 2..50000, an unlock at 60000 did NOT `continue`, so