Repository navigation
feat(validate): mirror the three app_unlock rules the schema will not express - #782
Conversation
… express `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.
…dit findings answered, one rejected
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/...
Correction to this PR's description, and round-0 outcomesRound 0 found four defects in this PR. Posting rather than silently editing, since the body above has been readable for a while. 🔴 The description's verification section is now wrong in my own favour and I am striking it. It said "22 new subtests". Measured: 25 table rows + 2 top-level funcs — 22 was only reachable by counting the funcs as subtests. The count is now higher because the fix added cases, but the original figure was an overstatement when written, not an undercount. 🔴 And the body's central design claim was a defect, not a feature. It said, of staying silent above 50000: "Above 50000 this stays silent rather than reporting twice what the server reports once." That produced the worst finding in the round. Measured on the pre-fix head, an The rationale was also false. "Never report twice what the server reports once" is not an invariant this file holds: a goods entry with no Fixed in
The other three
Six mutants re-run against the rewritten check, all killed — including re-adding the clamp that caused the defect, so a reintroduction is caught. 🤖 Generated with Claude Code |
Round 1 claims — what
|
…omment saying it was not
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.
Round 2 claims — what
|
…and contradicted the line above it 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.
Round 3 fixed, and I am ENDING this ladder — on the ATTRIBUTION GATERound 3 found exactly one thing and it was mine: the headline was false. Measured with the real binary, three unlocks with one over-cap (500, 500, 7777) produce both the arity finding and the price finding. Fixed. Why the ladder ends here, and it is not because the round was cleanRound 3 changed 35 payload lines at file level but ZERO executable lines — 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 this PR, so it stops here deliberately rather than running a fourth round that would do the same again. What the ladder established, for the reader who arrives at the diff
⚠ CodeQL reads 🔴 Merge order still binds: 🤖 Generated with Claude Code |
…he table that omitted them (#150) The per-entry `goods` table documented six of the canonical schema's seven `goods.items` properties. The missing one was `justification`, which the submit-time validator REQUIRES for a `kind: "app_unlock"` good — so the documented path to authoring a paid app ended in a submit rejection the reference could not explain, and `civitai app validate` could not catch it either (that half is civitai/cli#782). Two further rules were undocumented and one made a published bound actively wrong: `priceBuzz` is capped at 5000 for an unlock, not the 50000 the table stated unqualified, and at most one unlock may be declared per manifest. All three come from `civitai:src/shared/constants/block-goods.constants.ts` (:117, :183, :459); the canonical schema's own property descriptions already carried them, which makes this a docs-side loss rather than a contract gap. - `apps/reference/manifest.md` — adds the `justification` row, makes `priceBuzz` kind-qualified, and replaces "leave it unset unless you intend that future behaviour" with the three rules plus the honest statement that selling an `app_unlock` does not paywall the app today. - `apps/guide/earning.md` — a "Charging for access to the app itself" section and the `self_purchase` precondition (owners cannot buy their own app's goods), with the unlock bounds deliberately NOT restated: the reference is the one place those numbers live. - `scripts/check-goods-item-parity.mjs` — pins the hand table's key set against `goods.items.properties` in both directions, riding the existing `appblocks-md-regions` job alongside `check:porting-hooks`. WHY A NEW GUARD: neither `check:md-regions` nor `check:manifest-parity` could see this, and both were green throughout — correctly. `<JsonSchemaTable />` renders top-level fields only, which is why the page carries a hand table at all, so a nested property addition moves no top-level field and `len(properties)` read 24 before and after. A cardinality check at the wrong depth is a confident green about a different question. The guard checks the KEY SET only and says so in its header — a wrong bound cell still passes. VERIFIED: guard RED at the merge-base and GREEN at head, three real-page mutants each failing for their own distinct reason, 8/8 detector fixtures, and the CI step confirmed to have executed rather than skipped. 16/16 checks green. Three adversarial audit rounds; every finding was prose, several written by the previous round's own fix. Round 0's deletion candidate D2 — generate the nested table and retire both the hand table and this guard — is deliberately NOT taken and is recorded on the PR as an operator decision. 🔴 KNOWN CONFLICT: PR #133 appends a different step after `check:porting-hooks` in the same workflow and a `"check:*"` line after it in `package.json`. Verified by `git merge-tree` exit code: conflicts in both files. Whoever merges #133 takes the resolution; both regions resolve by taking both sides.
The defect, measured end-to-end
civitai app validateaccepted every manifest the paid-app path can get wrong, and the server rejected all three at submit. Built the binary fromorigin/mainand from this branch, ran both over four manifests derived fromcivitai-block-starter:origin/mainapp_unlock, nojustificationrc=0rc=1goods[0].justification is required for an app_unlock good — it makes the app paid, so a moderator must be told whyapp_unlockpriced 7777rc=0rc=1goods[0].priceBuzz must be a whole number between 2 and 5000 Buzz for an app_unlock goodapp_unlockgoodsrc=0rc=1goods may declare at most 1 app_unlock good (found 2) — app access is one question with one answerapp_unlock(control)rc=0rc=0✓ is validThe control is the point — the probe discriminates rather than rejecting anything that mentions
app_unlock.Why these three belong here, and the general price range does not
goodsChecksalready ports the goods rules JSON Schema cannot express, and these pass the same test — the vendored schema does not reject any of them and deliberately will not:priceBuzz.maximumstays50000for every kind, with the narrow bound in a prosedescriptionthat names the server validator authoritative.justificationis absent fromrequiredand could not be there: the requirement is conditional onkind, which a per-item subschema cannot state.Values mirrored from
block-goods.constants.ts(:117,:183,:459) with the server's message text.blockGoodMinPriceBuzz/blockGoodMaxPriceBuzzare not checks — the schema'sminimum/maximumown the general range, and re-checking it here is the duplicated-predicate mistake this file warns about twice. They exist so the message can name the real ceiling, and so theapp_unlockcheck is 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 goodsuffix. The server's comment is explicit about why: for anapp_unlockthat 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
Checks sit at the server's own positions, each ending the entry, because the server is a
forEachwhose every rejectionreturns — two findings for one entry would make the local output a different set from the 400 it predicts. Arity is the exception: additive, at pathgoodsnotgoods[i], mirroring the server pushing it and falling through.Arity counts only entries that survived, mirroring the server's parsed-goods array. That cost a test round and is now pinned: three unlocks where two fail produce no arity finding. Stated limit — 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 already documents.
Also: the
AGENTS.mdthe CLI writesIts
### Docssection had zero references togoods,earning,unlockorjustification, so an agent following the file the onboarding prompt calls "the source of truth" had no route to these rules. It now points atapps/guide/earning.mdand names the three. The golden inagent_setup_docs_test.gois updated in the same commit, as that guard's own failure message instructs — it caught this correctly.Verification
wantspelled out rather than built from the code under test, since these strings are a contract with the server's 400.>→>=; delete the required-justification arm; key it ongoodinstead; message names the general ceiling; drop the kind suffix; never count a surviving unlock; drop theTrimSpace. Run under-count=1so Go's test cache cannot serve a stale pass.rc=1read as a dead mutant with zero failing tests. Rewritten to a file that asserts a unique anchor (refusing on 0 or >1 matches), and the runner now separates "does not compile" from "killed".-count=1: failing-test name set byte-identical toorigin/main— 6 lines, the 3 container-dependentTestOracle*tests plus subtests, red at base too. Attributable delta zero.gofmtclean,go vetclean.Context
Found while evaluating whether an agent following
civitai.com/agent-onboardingcan author a paid app. Sibling docs fix: civitai/civitai-developer-docs#150, which adds thejustificationrow the manifest reference omitted. This PR is the deterministic half — docs tell an author the rule, the validator enforces it.🤖 Generated with Claude Code