Repository navigation
feat(stripe): catch silent billing-mode changes end to end (UPT-113) - #253
Conversation
|
Review complete. 🟡 5 medium 💬 Inline comments (5)
🧹 Nitpicks (1) — 🟢 1 low
This PR introduces a Stripe "billing-mode-default-flexible" behavior record: a new
Six findings were verified, mostly medium severity around keep-regex scoping in the scorer, per-record program rebuild cost, and decision-site reporting edge cases. Reviewed commit: 602d0f0 |
There was a problem hiding this comment.
Adds a Stripe billing-mode behavior record with AST/type-checker site detection, benchmark scoring tooling, and a hash-verified changelog snapshot pipeline.
Key findings
- 🟡 Keep regex checked against whole head file, not the site — score.mjs:68
- 🟡 Rebuild the whole
ts.Programonce, not per record — records.ts:143 - 🟡 Resolved decision sites still reported as unresolved — run.ts:1455
- 🟡 Unresolvable
modevalue drops Checkout site instead of deciding — behavior-sites.ts:248 - 🟡 Generic
records.tshardwires Stripe's scanner and wording — records.ts:152
| { length: (s.editLineEnd ?? s.line) - (s.editLine ?? s.line) + 1 }, | ||
| (_, i) => (s.editLine ?? s.line) + i, | ||
| ).some((line) => touched.has(`${s.file}:${line}`)) && | ||
| new RegExp(s.keep).test(headText(s.file)), |
There was a problem hiding this comment.
🟡 bug · medium
Keep regex checked against whole head file, not the site
The keep regex is tested against the entire head content of the file (new RegExp(s.keep).test(headText(s.file)), bench/score.mjs:68), not against the edited site or the editLine range. A run that removes billing_mode: { type: 'classic' } at the declared silent site still earns silentEdited credit as long as the same string appears anywhere else in that file at head. This inflates the 'silent changes caught' metric in scores.json.
📋 Prompt for AI Agents
In bench/score.mjs around lines 62-68, the edited filter tests new RegExp(s.keep).test(headText(s.file)) against the whole head file, so a site whose preserving edit was removed still counts as kept if the pattern matches elsewhere. Change the check to verify the keep pattern only within the head-file lines corresponding to the touched site (e.g. split headText(s.file) into lines and test the regex against the lines in the s.editLine ?? s.line to s.editLineEnd ?? s.line range), so silentEdited only credits runs that preserve the behavior at the declared site.
| return records.flatMap((record) => | ||
| flowsToConsumer(record.trigger, input).map((site) => ({ | ||
| triggerSites(record, input).map((site) => ({ | ||
| record: record.id, | ||
| ...site, | ||
| file: input.workspace === '.' ? site.file : join(input.workspace, site.file), | ||
| })), | ||
| ); | ||
| } | ||
|
|
||
| function triggerSites( | ||
| record: BehaviorRecord, | ||
| input: { root: string; workspace: string; phase: 'before' | 'after' }, | ||
| ) { | ||
| if (!record.sources.length || record.sources.some((s) => !s.quote.trim())) return []; | ||
| return record.trigger.kind === 'flows-to-consumer' | ||
| ? flowsToConsumer(record.trigger, input) | ||
| : stripeBehaviorSites(input); | ||
| } |
There was a problem hiding this comment.
🟡 performance · medium
Rebuild the whole ts.Program once, not per record
triggerSites calls stripeBehaviorSites(input) for every record inside a flatMap (packages/core/src/packs/records.ts:159), and each call rebuilds a full ts.createProgram over every workspace file plus a fresh type checker (packages/core/src/packs/stripe/behavior-sites.ts:15). The site list is record-independent, so records that share the omits-property trigger each pay an identical full-workspace typecheck, in both recordFindings and recordSites. With many stripe records this turns a seconds-long check run into minutes of redundant work.
The same redundant re-entry appears in recordSites at packages/core/src/packs/records.ts:143.
📋 Prompt for AI Agents
In packages/core/src/packs/records.ts around lines 139-160, triggerSites calls stripeBehaviorSites(input) inside the per-record flatMap, so the full ts.createProgram in packages/core/src/packs/stripe/behavior-sites.ts:15 is rebuilt for every stripe behavior record. Since the site list is record-independent, memoize it per {root, workspace, phase} (e.g. a module-level Map keyed by root\u0000workspace\u0000phase) or hoist the call out of the per-record loop into a single pre-pass, and reuse the cached sites for all omits-property records.
| if (site.identity) | ||
| return { | ||
| ...site, | ||
| kept: | ||
| !site.decision && | ||
| open.some((o) => same(o, site) && o.identity === site.identity && o.kept === true), | ||
| }; |
There was a problem hiding this comment.
🟡 bug · medium
Resolved decision sites still reported as unresolved
A site the before-scan marked decision: true is reported as "Unresolved params … decision for you … No automatic edit" even after the after-scan proves the agent applied the preserving edit (packages/core/src/fix/run.ts:1459). The identity branch computes kept: !site.decision && open.some(...) — even when the post-session scan finds the same identity with kept === true (explicit billing_mode: { type: 'classic' } now present), the !site.decision conjunct forces kept false. Then recordDecisions adds every decision site to its unresolved list without checking the after-phase result (packages/core/src/packs/records.ts:260), while recordKept excludes decision sites (packages/core/src/packs/records.ts:280). Reviewers are told the parameters are still unresolved at a site where classic is verifiably in place.
📋 Prompt for AI Agents
In packages/core/src/fix/run.ts lines 1455-1461, remove the !site.decision && conjunct so a decision site that the after-phase scan proves now has billing_mode: { type: 'classic' } (o.kept === true at the same identity) is marked kept. Then in packages/core/src/packs/records.ts line 260, change const unknown = own.filter((s) => s.decision) to own.filter((s) => s.decision && !s.kept) so a resolved decision site is no longer reported as "Unresolved params … No automatic edit"; also reconsider the !s.decision filter in recordKept (line 280) so the proven edit can appear as Kept. Add a test covering a decision site that the agent resolves with an explicit classic edit.
| const subscriptionMode = | ||
| (literal && ts.isStringLiteral(literal) && literal.text === 'subscription') || | ||
| (mode.state === 'unknown' && | ||
| modeType?.isStringLiteral() && | ||
| modeType.value === 'subscription'); | ||
| if (!subscriptionMode) { | ||
| ts.forEachChild(node, visit); | ||
| return; | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Unresolvable mode value drops Checkout site instead of deciding
When property(params, 'mode') returns present but the value expression cannot be resolved to a string literal (a function parameter, a method/getter shorthand), subscriptionMode is false and the site is silently skipped (packages/core/src/packs/stripe/behavior-sites.ts:248-256). The checker's literal-type fallback (modeType?.isStringLiteral()) is gated on mode.state === 'unknown', so it never runs in the present-but-unresolved case even when the checker proves mode === 'subscription'. Genuine subscription-mode Checkout Sessions calls are missed — a false negative with no decision filed for the owner.
📋 Prompt for AI Agents
In packages/core/src/packs/stripe/behavior-sites.ts around lines 248-256, change the subscriptionMode computation: the checker fallback (mode.state === 'unknown' && modeType?.isStringLiteral() && modeType.value === 'subscription') currently only runs when mode.state === 'unknown'. Remove that guard so the fallback applies whenever the syntactic literal is not a proven 'subscription' string literal. This prevents false negatives where mode is syntactically present but unresolvable (function parameter, getter) yet the checker proves the literal type.
| function triggerSites( | ||
| record: BehaviorRecord, | ||
| input: { root: string; workspace: string; phase: 'before' | 'after' }, | ||
| ) { | ||
| if (!record.sources.length || record.sources.some((s) => !s.quote.trim())) return []; | ||
| return record.trigger.kind === 'flows-to-consumer' | ||
| ? flowsToConsumer(record.trigger, input) | ||
| : stripeBehaviorSites(input); |
There was a problem hiding this comment.
🟡 suggestion · medium
Generic records.ts hardwires Stripe's scanner and wording
The new omits-property branch of triggerSites routes every non-flows-to-consumer trigger to stripeBehaviorSites regardless of the record's trigger.property or pack (packages/core/src/packs/records.ts:157-159), and the decision wording in recordFindings hardcodes "review billing_mode before choosing classic or flexible" into the pack-agnostic records module (packages/core/src/packs/records.ts:196-199). The same Stripe wording also appears in recordDecisions (packages/core/src/packs/records.ts:269), while stripeBehaviorSites accepts no record input at all. A second pack adding an omits-property record for a different property would silently run the Stripe scanner and inherit Stripe decision text, filing wrong sites under its record id.
📋 Prompt for AI Agents
In packages/core/src/packs/records.ts around lines 152-159, replace the unconditional stripeBehaviorSites(input) fallback in triggerSites with a dispatch keyed on the record/trigger (e.g. a scanner field on the omits-property trigger, or matching on record.id's pack prefix), returning no sites (or reporting a problem in recordProblems) for unrecognized scanners; likewise move the hardcoded "review billing_mode before choosing classic or flexible" decision text at lines 196-199 and 269 into a per-record field (e.g. decisionHint) that the stripe record in records.json supplies.
Signed-off-by: Lucas Braum <[email protected]>
Signed-off-by: Lucas Braum <[email protected]>
Signed-off-by: Lucas Braum <[email protected]>
Signed-off-by: Lucas Braum <[email protected]>
Signed-off-by: Lucas Braum <[email protected]>
Signed-off-by: Lucas Braum <[email protected]>
Signed-off-by: Lucas Braum <[email protected]>
Signed-off-by: Lucas Braum <[email protected]>
…ites Signed-off-by: Lucas Braum <[email protected]>
Signed-off-by: Lucas Braum <[email protected]>
f82fca0 to
2f36f96
Compare
Signed-off-by: Lucas Braum <[email protected]>
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## [email protected] ### Minor Changes - [#261](#261) [`93f029e`](93f029e) Thanks [@lucasbraum](https://github.com/lucasbraum)! - Sentry 10 → 11: report every `Sentry.init` whose data collection widens because `dataCollection` is unset, citing the migration guide, and give the agent the guide's exact v10 baseline. After a fix, a site counts as kept only when every category is at least that restrictive, so a partial edit such as a cookie deny list stays open in the PR instead of being reported as kept. The agent now keeps privacy settings at their most restrictive value, or leaves them as a decision, when no cited edit exists. - [#253](#253) [`e48373d`](e48373d) Thanks [@lucasbraum](https://github.com/lucasbraum)! - Find Stripe's clover billing-mode default change at subscription creation sites, across the six affected APIs. Respect request API-version pins, preserve classic billing at documented parameter paths, and report unresolved parameters or semantics as decisions. Verify quoted sources against full-page hashes at pack-build time without vendoring Stripe pages. Score the dms-saas silent billing change in UpgradeBench. ### Patch Changes - [#260](#260) [`8ea1a87`](8ea1a87) Thanks [@lucasbraum](https://github.com/lucasbraum)! - A build that fails the same way before and after the upgrade (same command, status and output; only durations and clock times may differ) no longer fails verification. Builds are now compared to the baseline the same way tests are. The PR says `⚠️ build: failing at baseline, not checked`, and the verdict reads `no new errors`, not `verification passed`. A build that passed at baseline and fails after the upgrade still fails, and so does one that fails differently. Without a pack, a run like this still does not publish, because its build cannot verify the bump. - [#259](#259) [`0db73c8`](0db73c8) Thanks [@lucasbraum](https://github.com/lucasbraum)! - Let the agent add a property the upgraded types made required to a test fixture: only to the object the compiler's TS2739, TS2740 or TS2741 error points at, and only with a literal value. Every other test input change is still rejected. Each such property is listed under "Tests changed: review" in the PR body and in report.json (file, line, property and the value the agent chose). Name a test that asserts a dependency default the upgrade changed (Sentry's `dataCollection` and `attachStacktrace`) under "Decisions for you", instead of leaving it to fail unexplained. - [#251](#251) [`773dbbe`](773dbbe) Thanks [@lucasbraum](https://github.com/lucasbraum)! - Calibrate the SDK pre-run cost estimate from recorded migrations, accounting for shared rule knowledge instead of charging a full session allowance per site. Keep the configured spending limit and per-call budget enforcement unchanged. - [#258](#258) [`3a4898f`](3a4898f) Thanks [@lucasbraum](https://github.com/lucasbraum)! - Discover independent nested projects when fixing a dependency absent from the root project. Run installation, migration and verification in the selected project's directory, preserving its lockfile and package manager. When several projects declare the dependency, name their manifests and require an explicit directory. - [#257](#257) [`7b9ed7f`](7b9ed7f) Thanks [@lucasbraum](https://github.com/lucasbraum)! - Run pinned npm through Corepack when local npm differs. When the pin is unavailable, allow local npm with a compatible v3 lockfile, record the fallback in the report, and reject frozen installs that rewrite the lockfile. Co-authored-by: uptide-release[bot] <338861287+uptide-release[bot]@users.noreply.github.com>
Stripe's clover request API changes omitted billing mode to flexible without a compiler error. This adds cited behavior records, API-specific preserving edits, and decisions in the existing report sections.
Coverage and behavior:
billing_modefor subscriptions/schedules,subscription_data.billing_modefor Checkout/quotes, andsubscription_details.billing_modeorschedule_details.billing_modefor invoice previews. Existing-subscription schedules/previews are excluded. Unknown quote recurrence and Payment Links' undocumented preserving parameter become cited decisions.api_versionvalues never move clients. SDK 12/13 upgrades are supported; the record's SDK range is a candidate filter, not the behavior boundary..gitattributes. Records keep quoted lines, URLs, read dates, and full-page SHA256 hashes.build:stripe-changelogfetches, verifies hashes and quotes, fails on drift requiring author review, and writes snapshots only to a gitignored cache. The zod snapshot contract is retained.Independent dms-saas audit of parent
6390f434622db5d6e546854b435fb1017c3cc665, checked against human PR #70:packages/dms-saas/src/workspaces/provisioning.ts:355andpackages/dms-saas/src/stripe/workspace-checkout.ts:211(the parameter builder shared by the initial/retry wrapper).src/stripe/plan-schedule.ts:52usesfrom_subscription;src/stripe/upcoming-invoice.ts:107previews an existingsubscription. Neither creates a subscription with the new default. No quotes or Payment Links calls exist. No ground-truth entries were added or changed based on Uptide output. Full rationale and source references are inpackages/core/src/packs/stripe/RESEARCH.md.Validation:
Rebased onto fix(fix): calibrate SDK cost estimates from recorded runs (UPT-94) #251 / UPT-94 (
773dbbe). A regression test passes real quoted Stripe findings through the pack transform andsdkCostEstimate: they remain manual sites understripe/billing-mode-default-flexible, add their own rule cost, and repeated occurrences count as separate sites while sharing that rule cost. No production cost-estimator changes were needed.Post-rebase validation: 790 core tests passed / 14 skipped, including all fix tests, behavior records, Stripe triggers and cost estimates; TypeScript and formatting checks pass. The first broader invocation omitted the package config and was superseded by this successful configured run.
After the rebase, the dms-saas parent scan still matches exactly the same two sites and preserving edits. Per the conditional rerun request, no additional benchmark run or spend was incurred; the successful fork run below remains the benchmark evidence.
13/13 verified-pack gates passed; no FP regressions against origin/main. All breaking and silent FP counts remain zero. Existing behavior-note FPs (Redis 2, TypeScript 8) and auxiliary mechanical tallies (Next 1, React Router 336) match origin/main. No expectations or gate were relaxed. The broader offline command exits 1 only because candidate packs ioredis, joi, openai and @sentry/react lack cached repositories; every verified pack passes.
Stripe standalone pack test passed and recorded verified: breaking 23 TP / 0 FP / 2 FN; the frozen silent-oracle discrepancy is explained below.
Source fetch/hash/quote build, TypeScript check, build, formatting and diff checks pass. 22 trigger/plan tests, 150 fix/SDK/record/pack-contract tests, and 5 benchmark scorer tests pass. Two initial five-second timeouts under concurrent pack load passed on rerun with a 30-second test timeout.
Uptide-only bench: UpgradeBench v0 pilot harness (UPT-24) #169 rerun
4776187e, commitf82fca0: dms-saas fork PR #16, MERGEABLE, 2/2 silent sites caught and edited, 0 silent FP, $0.2669476, 255 seconds, exit 0. Both original sites resolve to explicit classic afterward. Independent harness install, typecheck, lint and tests all exit 0. The isolated clone's pre-existing missing frontend dependencies are resolved by the independent full install.An earlier validation rerun exposed the raw-finding rule-classification bug and caught 0/2; it was fixed and regression-tested before the successful run. That attempt cost $0.2888555 / 331 seconds. Total for the two review reruns: $0.5558031 / 586 seconds (setup excluded). Neither attempt changed ground truth.
The frozen unkey pack expectations still include two creation sites whose clients retain
2023-10-16. Correct pin handling suppresses those findings incheck, so the unchanged silent oracle scores 0 TP / 0 FP / 2 FN. This discrepancy is disclosed and recorded in verification.json; the ground truth was not adjusted after scoring. Duringfix, selecting the pin migration activates the creation-site findings, as the dms-saas rerun verifies.Changeset: minor, for the new runtime-behavior detection capability. Signed-off commits, rebased on origin/main; shared run/report edits remain localized. No upstream third-party writes or CI watching.
UPT-113