Skip to content

feat(prices): a price source contract, and Scryfall's prices through it (#364) - #413

Merged
plainprogrammer merged 28 commits into
mainfrom
085-price-source-contract
Nov 13, 2026
Merged

plainprogrammer merged 28 commits into
mainfrom
085-price-source-contract

Conversation

@plainprogrammer

Copy link
Copy Markdown
Owner

Closes #364

What this adds

A collectible's extension now supplies market prices through a documented contract, and Scryfall supplies them for Magic cards (spec 085, prices.md).

  • The contract is Prices::Sources (app/models/prices/sources.rb): a source states its key, title, attribution, whether a hosted instance with paid plans may show it, and its series, and yields Quotes (the source's id for the printing, finish, currency, kind, whole cents, the day reported) or Malformeds from #each_quote(path, languages:). Its comment is the one place the contract is written. Prices.sources is the registry, as Catalog.sources is for the catalog.
  • The Scryfall source is MTG::Scryfall::PriceQuotes. It streams the bulk file the catalog refresh reads and yields a quote for usd, usd_foil, usd_etched, eur, eur_foil and eur_etched (research 083 found no etched EUR today; it is read anyway). tix is not stored. Prices become cents from their digits, never a float. The day reported comes from the file's name. It stores what the file carries, including the EUR a non-English printing copies from its English twin (ruling 41); the twin rule is a display rule for A card's market price on its page and in the collection #369.
  • An unreadable price is not an absence. A Malformed carries the price's series, so Prices refresh once a day, and each change is recorded once #365's refresh can tell a price it failed to parse from one the file left empty, and must not delete the former. The reason is in the contract's comment and in prices.md.
  • Rows for sources and series are written by PriceSource.sync! and PriceSeries.ensure! from the source's own declaration: idempotent, race-safe through the unique indexes, never deleted, no migration seed.
  • A guard (spec/price_source_core_spec.rb) keeps the core files free of any collectible name.

Scope

No refresh, no download of the file, no model for current prices, price changes or runs (#365, #366), no page or twin lookup (#369), no migration, and no change to db/prices_structure.sql.

Rulings and review

  • hosted_paid_allowed? is true for Scryfall (the maintainer, 2026-11-13, on rulings 27, 37 and 38). The value is written in one place (MTG::Scryfall::PriceQuotes.hosted_paid_allowed?) with its own example. Issue Ask Scryfall in writing about recording prices and showing their history #362 (the written question to Scryfall) is still open and its answer may change it. Nothing reads the flag yet: the refusal the design describes needs a setting for the kind of instance, which hosted mode (Hosted mode: one operator setting #392) adds.
  • Reviews: spec, two Fable 5.2 rounds; plan, two Fable 5.2 rounds; implementation review (Opus 5.5, read-only) SPEC-ALIGNED (verification.md). Its one minor finding (a line with invalid UTF-8 would stop the whole read) is fixed test-first.
  • Test-first exception: T2.3's four examples check behaviour T2.2 already built, so each was proved by a mutation (the code broken, the named example shown failing, the code restored); the results are in commit 14a321b9's body. It was accepted at Gate B, under the maintainer's delegation.

Owed to the maintainer

Verification

Pushed 23a32348; the pre-push hook ran the full bin/ci and passed. The suite has 4829 examples (bin/rspec --dry-run); this feature adds 47 across its six spec files (3, 14, 18, 4, 6 and 2) (the timing example, :timing, is excluded by default, and SCANNER_TIMING=1 measured 300,000 quotes from 50,000 cards in 1.2 s). bin/ci checks (RuboCop, YARD, the comment ratchet, Brakeman, audits) passes.

🤖 Generated with Claude Code

plainprogrammer and others added 28 commits November 13, 2026 12:31
…rices (#364)

Draft v1.0.2 after two Mode A review rounds (Fable 5.2).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
)

hosted_paid_allowed? is true for Scryfall (2026-11-13); #362 stays open.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Two plan review rounds (Fable 5.2), all findings applied.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
T1.1: The guard, the fake source and the registry

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
T1.2: Series, Quote, Malformed and the errors

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
T1.3: verify!

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…its file (#364)

T2.1: The declaration and the day

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…le (#364)

T2.2: Reading prices as quotes

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
#364)

T2.3: The catalog's file, the twin, streaming and a timing

Failing-first does not apply (plan exception): these examples check
behaviour T2.2 already implements. Mutation proof, each run with only
its named example (-e), then restored (git diff clean):

1. `date = reported_on(path)` -> `date = Date.new(2026, 11, 13)`
   Examples: "refuses a file with no date before it yields anything"
   and "takes each quote's day from the file's name".
   Failed: expected [Thu, 12 Nov 2026], got [Fri, 13 Nov 2026]; and
   "expected IntegrityError but nothing was raised" (yielded not empty).
2. `gzip.each_line` -> `gzip.read.each_line`
   Example: "reads the file as a stream".
   Failed: expected ["first"], got [] (yielded stays empty).
3. `external_key: id` -> `external_key: id.upcase` in each_price_record
   Example: "reads the file the catalog reads".
   Failed: expected ["card-1", "card-2"], got ["CARD-1", "CARD-2"].
4. `return unless card["lang"] == "en"` after the Hash guard
   Example: "yields a non-English printing".
   Failed: expected [["nonfoil", "EUR", 50]], got []; records.size
   expected 3, got 2.

Timing (SCANNER_TIMING=1, "reads 50,000 cards"):
price quotes: 300000 quotes from 50,000 cards in 1.2 s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
)

T2.4: The hosted flag, and the registration

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
T3.1: PriceSeries

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
T3.2: PriceSource, and PricesRecord's comment

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…364)

T4.1: The area doc. Scope, glossary, invariants (the contract's comment, absence,
no network, date and cents rules, twins, sync rows, models, the hosted flag),
named constants (SERIES_BY_KEY, PRICE, FILE_STAMP, CURRENCY, KEY), decisions not
in an ADR and sources, each with its spec 085 decision, ruling or issue.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
T4.2: CLAUDE.md's status paragraph says the contract exists, the roadmap marks
#364 done as it does #361, and the 083 row of the specs index records that the
prices area doc took ruling 41.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…nd of the read (#364)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…s fields (#364)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ED (#364)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ontract and the area doc (#364)

A refresh that deletes a price on its absence must not delete one the
source failed to parse. Maintainer request at the digest.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
One memory (mutation proof in place of failing-first) and three lessons
(absent is not unreadable, no contract member named name, a flag's
polarity from its false). Approved at the digest.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The prices area doc carries the contract, the models, the sync and the
constants; its log, the area map and the specs index say so.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Conflicts in CLAUDE.md (the prices sentence kept on top of main's current
paragraph) and docs/specs/README.md (rows 083 and 085 kept with main's
084 and 087).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
One conflict, the specs index: row 085 kept beside main's retired 087 row.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@plainprogrammer
plainprogrammer marked this pull request as ready for review November 13, 2026 21:26
@plainprogrammer plainprogrammer self-assigned this Nov 13, 2026
@plainprogrammer
plainprogrammer merged commit 6048212 into main Nov 13, 2026
9 checks passed
@plainprogrammer
plainprogrammer deleted the 085-price-source-contract branch November 13, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A price source contract, and Scryfall's prices through it

1 participant