-
Notifications
You must be signed in to change notification settings - Fork 1
test: golden valuation fixture shared with recoupable/api #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sweetmantech
wants to merge
1
commit into
main
Choose a base branch
from
test/valuation-golden-fixture
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| { | ||
| "description": "Golden valuation-band cases shared verbatim between recoupable/api (lib/catalog/computeValuationBand.ts) and recoupable/marketing (lib/valuation/computeCatalogValuation.ts). The two copies of this file must stay byte-identical, and each repo has a test asserting its implementation reproduces every case to the cent. If a test fails, the implementations have diverged: fix the code or update this fixture in BOTH repos in the same change. Formula: annualGross = (totalStreams / catalogAgeYears) * 0.0035; band = annualGross * grossUp{1.25,1.4,1.6} * (1 - 0.15) * (1 - 0.25) * multiple{10,13,16}; catalogAgeYears = round(msSince(earliestReleaseDate) / 365.25d) clamped to >= 1, defaulting to 5 when earliestReleaseDate is null. Band keys here are low/mid/high; marketing names the middle value 'central'.", | ||
| "cases": [ | ||
| { | ||
| "name": "large catalog with unknown release date falls back to the 5y default age", | ||
| "input": { | ||
| "totalStreams": 16308837441, | ||
| "earliestReleaseDate": null, | ||
| "now": "2026-07-06T00:00:00.000Z" | ||
| }, | ||
| "expected": { | ||
| "catalogAgeYears": 5, | ||
| "low": 90972733.85, | ||
| "mid": 132456300.49, | ||
| "high": 186312158.93 | ||
| } | ||
| }, | ||
| { | ||
| "name": "zero streams yields a zero band", | ||
| "input": { | ||
| "totalStreams": 0, | ||
| "earliestReleaseDate": "2020-01-01T00:00:00.000Z", | ||
| "now": "2026-07-06T00:00:00.000Z" | ||
| }, | ||
| "expected": { | ||
| "catalogAgeYears": 7, | ||
| "low": 0, | ||
| "mid": 0, | ||
| "high": 0 | ||
| } | ||
| }, | ||
| { | ||
| "name": "ten-year catalog ages from its earliest release date", | ||
| "input": { | ||
| "totalStreams": 100000000, | ||
| "earliestReleaseDate": "2016-07-01T00:00:00.000Z", | ||
| "now": "2026-07-01T00:00:00.000Z" | ||
| }, | ||
| "expected": { | ||
| "catalogAgeYears": 10, | ||
| "low": 278906.25, | ||
| "mid": 406087.5, | ||
| "high": 571200 | ||
| } | ||
| }, | ||
| { | ||
| "name": "months-old catalog clamps age to one year", | ||
| "input": { | ||
| "totalStreams": 1000000, | ||
| "earliestReleaseDate": "2026-05-01T00:00:00.000Z", | ||
| "now": "2026-07-06T00:00:00.000Z" | ||
| }, | ||
| "expected": { | ||
| "catalogAgeYears": 1, | ||
| "low": 27890.63, | ||
| "mid": 40608.75, | ||
| "high": 57120 | ||
| } | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { computeCatalogValuation } from "../computeCatalogValuation"; | ||
| import fixture from "./fixtures/valuation-golden.json"; | ||
|
|
||
| /** | ||
| * Cross-repo divergence guard (recoupable/chat#1850): the valuation model is | ||
| * implemented twice — here and in recoupable/api | ||
| * (lib/catalog/computeValuationBand.ts). This fixture's twin lives at | ||
| * api/lib/catalog/__tests__/fixtures/valuation-golden.json and the two JSON | ||
| * files must stay byte-identical. If this test fails, the marketing model has | ||
| * drifted from the shared formula: fix the code, or change the fixture in | ||
| * BOTH repos in the same coordinated change. The fixture's `mid` maps to this | ||
| * repo's `central` band key. | ||
| */ | ||
| describe("computeCatalogValuation golden fixture", () => { | ||
| it.each(fixture.cases)("$name", ({ input, expected }) => { | ||
| const { valueBand, catalogAgeYears } = computeCatalogValuation({ | ||
| totalStreams: input.totalStreams, | ||
| earliestReleaseDate: input.earliestReleaseDate, | ||
| now: new Date(input.now), | ||
| }); | ||
|
|
||
| expect(catalogAgeYears).toBe(expected.catalogAgeYears); | ||
| // Fixture values are rounded to the cent; assert to within one cent. | ||
| expect(Math.abs(valueBand.low - expected.low)).toBeLessThanOrEqual(0.01); | ||
| expect(Math.abs(valueBand.central - expected.mid)).toBeLessThanOrEqual(0.01); | ||
| expect(Math.abs(valueBand.high - expected.high)).toBeLessThanOrEqual(0.01); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: The formula description's
msSince(earliestReleaseDate) / 365.25dnotation skips the ms‑to‑days conversion factor (86400000). Since this fixture is the canonical reference shared verbatim across two repos, a reader re‑implementing from the description alone could mis‑compute the age. SuggestmsSince(earliestReleaseDate) / (365.25 * 86400000)(ordaysSince(…) / 365.25) to make the unit conversion explicit.Prompt for AI agents