Repository navigation
fix(cdn): retry a failed Fastly TLS subscription with force - #304
Conversation
A subscription fails on a renewal while the certificate it issued earlier is still deployed, which Fastly calls an active domain, and Fastly refuses to edit such a subscription without force. The retry was sent without it and came back 400 "Subscription has active domains", so a domain whose renewal had failed once could never be retried. A retry keeps the domain and only asks for issuance again, so the deployed certificate keeps serving while the retry runs. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
| $this->assertSame('PATCH', $client->calls[1]['method']); | ||
| $this->assertSame('https://api.fastly.com/tls/subscriptions/sub_123?force=true', $client->calls[1]['url']); | ||
| $this->assertSame('retry', $client->calls[1]['body']['data']['attributes']['state']); |
There was a problem hiding this comment.
Tests mirror request construction
These assertions copy the exact HTTP method, configured API base, query string, and nested state=retry value from the implementation. The related exact call-count assertion also pins the current request sequence. This violates the repository directive to test observable behavior rather than mirror source code or configuration. Make the fake client accept the retry only when force=true is present, then assert the resulting provider behavior. This repository requirement must be satisfied before merging.
Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cdn/tests/Cdn/Certificates/Provider/FastlyTlsTest.php
Line: 107-109
Comment:
**Tests mirror request construction**
These assertions copy the exact HTTP method, configured API base, query string, and nested `state=retry` value from the implementation. The related exact call-count assertion also pins the current request sequence. This violates the repository directive to test observable behavior rather than mirror source code or configuration. Make the fake client accept the retry only when `force=true` is present, then assert the resulting provider behavior. This repository requirement must be satisfied before merging.
**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Drops the parts of this branch that #300 and #304 already landed on main, and keeps only what is still unique to it. Superseded, now taken from main: - `Exception\Certificate`: main's carries `Challenge` objects, `getWarnings()` and `isBlocked()` where this branch had a raw `getDnsRecords()` array. - `Status::BLOCKED` and the `Provider::getCertificateStatus()` `@throws`. - `FastlyTls::getCertificateStatus()` blocked-authorization reporting, the `tls_authorizations` include, and the ~210 lines of tests covering them. - The README paragraph describing the old `getDnsRecords()` shape. Kept from this branch: - `Fastly`: unlinked and classic-route domain ownership, `fqdn_match=exact` with a truncation guard, and `stdClass` response handling. - `FastlyTls`: the exclusive-ownership check before a `force=true` delete, and the `findSubscription()` hardening. `Fastly::issueCertificate()` now uses main's `catch (Certificate)` around `getCertificateStatus()` on the reassignment path, since that call throws on a blocked authorization rather than returning a status. `bin/monorepo check cdn` passes; 204 CDN tests pass. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Problem
Seen in production on a custom domain's certificate logs:
A subscription reaches
failedwhen a Fastly-side renewal does not complete, typically because the domain's DNS no longer reaches Fastly or a CAA record now excludes the CA. The certificate issued earlier is still deployed and serving, which Fastly calls an active domain. Fastly refuses to edit a subscription with active domains unless the request carriesforce=true; its docs describeforceas what lets you "edit and delete a subscription with active domains".FastlyTls::retrySubscriptionsent thePATCH state=retrywithout it, so once a renewal had failed the subscription could never be retried through this adapter. Every consumer attempt, maintenance renewals and re-verify alike, hit the same 400.Change
The retry
PATCHgoes to/tls/subscriptions/{id}?force=true, matching whatdeleteCertificatealready does. Fastly's warning aboutforceconcerns removing an active domain from a subscription; a retry keeps the domain and only asks for issuance again, so the deployed certificate keeps serving while the retry runs. Nothing else changes.What this does not fix
The retry succeeds only if whatever made the renewal fail is gone. If the DNS or CAA problem is still there, Fastly fails the retry again, and with #300 the rule's logs will carry Fastly's own reason and the challenge to fix it.
Tests
FastlyTlsTest.php: the existing retry test now asserts the URL carriesforce=trueand the body asks forretry; a new test scripts Fastly's 400 and asserts the exception carries Fastly's message and that nothing further is attempted.bin/monorepo check cdnpasses (Pint, PHPStan, Rector). Tests were not run locally.Independent of #300 and #303; touches only
FastlyTls.🤖 Generated with Claude Code