Repository navigation
feat(renewals): enforce the renewal window and share its rule across the API and apps (REGBACKLOG-391) - #1964
severinbeauvais wants to merge 7 commits into
Conversation
…the API and apps (REGBACKLOG-391) (#1952) * feat(renewals): email listener import, todo task type and typecheck scripts (REGBACKLOG-391) - strr-email: import Any in email_listener.py. _normalize_and_deduplicate_emails is annotated with list[Any]; the deployed service runs on Python 3.14, which doesn't evaluate the annotation when the function is defined, but on 3.12 and 3.13, which pyproject.toml also allows, the module fails to import with NameError. - strr-base-web: the registration todo task field is detail, not details, matching what the API returns and what todoItems.ts already reads. - Platform and strata dashboards: only show a renewal draft or payment-pending todo when it has an application number. The ids are string | null, and were passed where a string is required. - Platform and strata: add a typecheck script (nuxi typecheck) and vue-tsc. The lockfiles only add vue-tsc and its dependencies. * refactor(base-web): skip renewal to-dos without an application number in one place (REGBACKLOG-391) getTodoRegistration now reports a draft or payment-pending renewal to-do only when it has an application number, so every app gets the rule from the base layer. Tested once in strr-base-web, replacing the near-identical platform and strata dashboard tests that the quality gate flagged as duplication. The dashboards keep their application-number checks so TypeScript knows the id isn't null. * feat(strr-api): shared renewal window rule for /todos (REGBACKLOG-391) - Add RenewalWindow (utils/renewal_window.py). The window opens at the start of the Vancouver day, 60 days before expiry for strata hotels and 40 days for everything else, and closes at the end of the Vancouver day three years after expiry. Stored times are UTC; days are counted in America/Vancouver. - /todos uses the rule for both ends of the window instead of comparing UTC dates, and returns a renewalWindow object (startDate, hasStarted) for the apps. - Renew is hidden only once a renewal has been submitted since the current window opened, replacing the moving "now - 1 year + 40/60 days" UTC cutoff. A declined renewal doesn't count, so the host can renew again; create_application's 409 check also accepts a new renewal after a declined one. - Tests: the window's boundaries in Vancouver time and its length by registration type, and /todos before and inside the window, including submissions just before and at the window start and declined renewals. Shared renewal test fixtures move to tests/unit/resources/conftest.py, so later renewal tests can use them without duplicating setup. * feat(renewals): refuse renewals outside the renewal window and explain why (REGBACKLOG-391) - strr-api: create_application returns 400 RENEWAL_WINDOW_NOT_OPEN when a new renewal is started before its registration's renewal window opens, even as a draft, or when a renewal is submitted before it opens. It returns 400 RENEWAL_WINDOW_CLOSED when a renewal is submitted after the window closes. The checks run before validation, saving or invoicing. An existing draft can still be saved outside the window. - strr-base-web: the application submit error modal shows "Renewal Period Not Started" and "Renewal Period Ended" for these errors, in English and French. - Tests: creating and submitting before, inside and after the window, including that nothing is saved or invoiced when refused, and the modal's mapping of the new error codes. Existing renewal tests that aren't about the window, including the 409 duplicate-renewal tests, now run with the window open (renewal_window_open fixture). * feat(host): "Expiring soon" from the API's renewal window (REGBACKLOG-391) - strr-base-web: getTodoRegistration passes on the renewalWindow object that /todos returns, typed as ApiRegistrationTodosResp. - strr-host-pm-web: the Registrations table shows "Expiring soon" from renewalWindow.hasStarted instead of its own copy of the 40/60-day rule, so the label agrees with when the API offers Renew. The table already calls /todos for each row, so there are no extra requests. If /todos fails for a row, it shows "Active", and Renew is hidden as before; "Expired" still comes from the expiry date. - Tests: getTodoRegistration with and without a renewal window, the renewal window passed to the table rows, and the table's "Expiring soon" and Renew states. * docs(oas): correct expiryDate examples and explain its meaning (REGBACKLOG-391) - The registration query examples showed expiryDate at midnight UTC on the start date's anniversary (eg 2027-01-15T00:00:00Z). Real values are 23:59:59 UTC on the day before (eg 2027-01-14T23:59:59Z), so the examples now match. - The expiryDate description now says it's the end of the registration's expiry day as stored, 23:59:59 UTC (4:59:59 pm Pacific); that clients should compare dates, not times; and that status tells whether a registration is valid, since it stays ACTIVE until the registration is marked EXPIRED after the expiry day. * docs(base-web): note that renewal to-dos always have an application number (REGBACKLOG-391) getTodoRegistration skips draft and payment to-dos without an application number. Say that this shouldn't happen, since application_number is required on Application and /todos always sends it, so nobody looks for a case that can't occur. * fix(base-web): simplify the renewal window error messages (REGBACKLOG-391) Per Liz, shorter titles and text for the submit errors shown outside the renewal window, in English and French * style(strr-api): sort imports in the renewal lifecycle tests (REGBACKLOG-391) isort removes an extra blank line between the imports and pytestmark in test_renewal_lifecycle_api.py. * feat(strr-api): refuse new renewals after the renewal window closes (REGBACKLOG-391) A new renewal, even as a draft, now gets 400 RENEWAL_WINDOW_CLOSED once the registration's renewal window has closed, as it already does with RENEWAL_WINDOW_NOT_OPEN before the window opens. Renew isn't offered then, so this only affects direct links or API calls, but it stops drafts being created that can never be submitted. An existing draft can still be saved; submitting it stays refused. Tests: a new draft after the window closes is refused, and the existing-draft test now covers both ends of the window. * chore: bump versions for the renewal window changes (REGBACKLOG-391)
…1954) (#1959) * ci: grant GITHUB_TOKEN permissions to CD and UI CI workflows (#1954) The org default token is now read-only, so every reusable bcregistry-sre workflow that asks for contents/id-token/pull-requests write fails at startup. Set the permissions on the calling jobs, same as sbc-pay#2720 and sbc-auth#3982. * fix(strr-api): delete leftover renewal drafts in Production (REGBACKLOG-494) (#1951) Add a migration that deletes the 6,399 leftover renewal drafts exported from Production on 2026-11-30, and the rows that reference them. * fix(web): declare zod 3 as a direct dependency (REGBACKLOG-499) (#1955) Since #1913 the web lockfiles hold zod 3.25.76 and 4.6.7. The apps import zod without declaring it, so they get whichever version pnpm hoists. Declare zod ^3.25.76 directly so app code always resolves the Zod 3 it is written for. --------- Co-authored-by: Séverin Beauvais <severinbeauvais@users.noreply.github.com>
…1960) * ci: grant GITHUB_TOKEN permissions to CD and UI CI workflows (#1954) The org default token is now read-only, so every reusable bcregistry-sre workflow that asks for contents/id-token/pull-requests write fails at startup. Set the permissions on the calling jobs, same as sbc-pay#2720 and sbc-auth#3982. * fix(strr-api): delete leftover renewal drafts in Production (REGBACKLOG-494) (#1951) Add a migration that deletes the 6,399 leftover renewal drafts exported from Production on 2026-11-30, and the rows that reference them. * fix(web): declare zod 3 as a direct dependency (REGBACKLOG-499) (#1955) Since #1913 the web lockfiles hold zod 3.25.76 and 4.6.7. The apps import zod without declaring it, so they get whichever version pnpm hoists. Declare zod ^3.25.76 directly so app code always resolves the Zod 3 it is written for. * fix(strr-api): print the REGBACKLOG-494 migration's result and recognise Production with the IAM connector (REGBACKLOG-494) (#1957) The migration job's logs only show stdout, so the logger.info result line never appeared. Print it instead, with the job's connection settings in the skipped line. The migration recognised Production only by DATABASE_UNIX_SOCKET. Migration jobs now connect through the Cloud SQL IAM connector, which sets CLOUDSQL_INSTANCE_CONNECTION_NAME and no socket, as the Dev job already does, so in Production it would have skipped. Accept either. * fix(strr-api): re-enable alembic loggers in the migration env (#1958) strr_api loads logging.conf at import with the default disable_existing_loggers=True, which disables alembic's loggers, so the migration jobs never logged alembic output (e.g. the REGBACKLOG-494 skip message). Turn just the alembic loggers back on in migrations/env.py, leaving the API's runtime logging unchanged. * chore(web): bump the web app versions above main's (REGBACKLOG-391) --------- Co-authored-by: Anish Patel <Anish.Patel@gov.bc.ca>
Merge pull request #1963 from severinbeauvais/REGBACKLOG-391-sync-main
|
Temporary Url for review: https://strr-platform-dev--pr-1964-gqct07f7.web.app |
|
Temporary Url for review: https://strr-strata-hotel-dev--pr-1964-8ggsdl2f.web.app |
|
Temporary Url for review: https://strr-hosts-dev--pr-1964-xbewfquq.web.app |
There was a problem hiding this comment.
🟡 Changes recommended
A critical draft-save loophole allows new renewals outside the permitted window, and the todos endpoint offers Renew for non-terminal renewals that block the action.
2 open issues
2 files not reviewed
strr-platform-web/pnpm-lock.yaml: Generated filestrr-strata-web/pnpm-lock.yaml: Generated file
What changed in this PR
Centralizes renewal eligibility in the API so renewal creation, submission, and app displays follow the same Vancouver-date window.
Changes:
- Enforces renewal boundaries and exposes window details through
/todos. - Updates renewal messages, dashboard labels, and application-number safeguards.
- Adds tests, typecheck tooling, expiry documentation, and an email import fix.
| File | Description |
|---|---|
strr-strata-web/pnpm-lock.yaml |
Locks typecheck dependencies. |
strr-strata-web/package.json |
Adds typecheck tooling; bumps version. |
strr-strata-web/app/pages/strata-hotel/dashboard/[applicationId].vue |
Guards todos against missing application numbers. |
strr-platform-web/pnpm-lock.yaml |
Locks typecheck dependencies. |
strr-platform-web/package.json |
Adds typecheck tooling; bumps version. |
strr-platform-web/app/pages/platform/dashboard.vue |
Guards todos against missing application numbers. |
strr-host-pm-web/tests/unit/dashboard-registrations-table.spec.ts |
Updates window-driven label tests. |
strr-host-pm-web/tests/unit/composable-use-renewals.spec.ts |
Tests renewal-window propagation. |
strr-host-pm-web/package.json |
Bumps version. |
strr-host-pm-web/app/interfaces/dashboard-tables.ts |
Adds renewal-window typing. |
strr-host-pm-web/app/composables/useRenewals.ts |
Passes window details to registrations. |
strr-host-pm-web/app/components/dashboard/RegistrationsTable.vue |
Uses API window for “Expiring soon.” |
strr-base-web/tests/unit/todo-registration-renewal.spec.ts |
Tests shared renewal-todo handling. |
strr-base-web/tests/unit/application-submit-error.spec.ts |
Tests renewal error messages. |
strr-base-web/package.json |
Bumps version. |
strr-base-web/i18n/locales/fr-CA.ts |
Adds French renewal messages. |
strr-base-web/i18n/locales/en-CA.ts |
Adds English renewal messages. |
strr-base-web/app/utils/todoItems.ts |
Centralizes todo safeguards and window propagation. |
strr-base-web/app/interfaces/strr-api.ts |
Corrects detail; types window responses. |
strr-base-web/app/composables/useStrrApi.ts |
Uses the updated todos response type. |
strr-base-web/app/components/modal/error/ApplicationSubmit.vue |
Handles renewal-window errors. |
strr-api/tests/unit/utils/test_renewal_window.py |
Tests window dates and boundaries. |
strr-api/tests/unit/resources/test_renewal_window_api.py |
Tests enforcement and draft saving. |
strr-api/tests/unit/resources/test_renewal_todos_api.py |
Tests window-dependent renewal todos. |
strr-api/tests/unit/resources/test_renewal_applications.py |
Applies open-window fixture. |
strr-api/tests/unit/resources/conftest.py |
Shares renewal fixtures. |
strr-api/tests/integration/resources/test_renewal_lifecycle_api.py |
Applies open-window fixture. |
strr-api/tests/integration/resources/test_applications_api.py |
Adapts renewal tests to enforcement. |
strr-api/tests/conftest.py |
Adds window-opening fixture. |
strr-api/src/strr_api/utils/renewal_window.py |
Defines shared Vancouver-date rules. |
strr-api/src/strr_api/resources/registrations.py |
Uses shared rules and returns window details. |
strr-api/src/strr_api/resources/application.py |
Enforces renewal creation and submission boundaries. |
strr-api/src/strr_api/enums/enum.py |
Adds renewal-window error messages. |
strr-api/pyproject.toml |
Bumps API version. |
queue_services/strr-email/src/strr_email/resources/email_listener.py |
Imports missing annotation type. |
queue_services/strr-email/pyproject.toml |
Bumps email service version. |
docs/oas/registration-query.yaml |
Clarifies expiry examples and date comparisons. |
Review effort: Balanced
| ] | ||
| ), | ||
| Application.application_date >= recent_submission_threshold, | ||
| Application.application_date >= renewal_window.start_utc, |
There was a problem hiding this comment.
Copilot's fix would make things worse.
What a query found in Production:
| Renewal status | Registration | Window open now | Renewals | Registrations |
|---|---|---|---|---|
| PROVISIONAL_REVIEW | ACTIVE | no | 12,112 | 11,976 |
| PROVISIONAL_REVIEW_NOC_EXPIRED | ACTIVE | no | 8 | 8 |
| NOC_EXPIRED | ACTIVE | no | 1 | 1 |
Almost all of these are PROVISIONAL_REVIEW, which the app shows hosts as "Approved – Provisional". The auto-approval sets it on a renewal when it renews the registration provisionally (provisional_extension_applied), and staff may review it later. So these renewals are effectively approved. They're submitted "before the window" only because the renewal moved the expiry, and with it the window, a year ahead. None was in a genuinely pending status, such as PAID, FULL_REVIEW or ADDITIONAL_INFO_REQUESTED.
Why that matters. APPLICATION_TERMINAL_STATES doesn't include PROVISIONAL_REVIEW, so the 409 check treats these renewals as still in progress. When their next windows open, it will refuse to start a new renewal. Their windows open soon:
| Next window opens | Registrations |
|---|---|
| Dec 2026 | 90 |
| Jan 2027 | 668 |
| Feb 2027 | 1,954 |
| Mar 2027 | 5,470 |
| Apr 2027 onward | about 3,800 |
This bug is already on main. It doesn't depend on #1964: Renew is offered, then fails with "renewal already in progress". It starts affecting about 90 hosts this month, and thousands from February.
Copilot's fix would hide Renew from all of them, which is consistent with the 409 check but worse: they couldn't renew at all, and nothing would tell them why.
There was a problem hiding this comment.
/todos only looked at renewals submitted in the current window, while the 409 check blocks on any renewal that isn't finished, whenever it was submitted. So /todos could offer Renew to a host whose submission would then get a 409.
Looking into it turned up a larger problem: the 409 check treated PROVISIONAL_REVIEW ("Approved – Provisional") as still in progress, even though that status has already extended the registration. Without a fix, those hosts couldn't renew in their next window.
#1969 fixes both. /todos and the 409 check now share one set of status lists, and a provisionally approved renewal, including its NOC statuses, counts as approved. #1969 merges into this feature branch, so this PR will include it.
…outside the window (REGBACKLOG-391)
The registration ID check now applies to POST as well as PUT on /applications/{number}, so an existing draft can only skip the renewal window and in-progress checks if it is already a renewal of the requested registration.
Addresses review feedback on #1964.
panish16
left a comment
There was a problem hiding this comment.
went through the rest of this since #1952, couple things:
-
#1965 looks right to me. running the registration id check for any existing application instead of just PUT closes it, and since only DRAFT apps can be edited at all there's no other way around it. nice that the test covers post + put on both ends of the window 👍
-
the PROVISIONAL_REVIEW one is a good find. checked and yeah
APPLICATION_TERMINAL_STATESon main doesn't have it, so the 409 check treats those renewals as still in progress. agree copilot's fix would be worse, hiding renew with no explanation is the worst option. since it's already on main and ~90 hosts hit it this month, I'd pull it out into its own ticket + PR so it can go out on its own and doesn't have to wait on this one. the fix probably needs to be making the 409 only block statuses that are actually still pending (payment due, paid, full review, info requested etc) rather than adding to the terminal list, but you know those statuses better than me -
heads up in case you didn't see it, jimmy's api cd to test/uat yesterday reused the dev image, which was this branch (4c8ec4e) at the time. so test and uat api are already on 391 from before #1965, draft loophole included. just flagging before anyone tests renewals in uat or a prod release picks up that image
holding off on approving till #1965 is in and we know what's happening with the PROVISIONAL_REVIEW fix, but the rest looks good
…outside the window (REGBACKLOG-391) Merge pull request #1965 from severinbeauvais/REGBACKLOG-391-renewal-convert-guard
|
|
Temporary Url for review: https://strr-platform-dev--pr-1964-gqct07f7.web.app |
|
Temporary Url for review: https://strr-hosts-dev--pr-1964-xbewfquq.web.app |
|
Temporary Url for review: https://strr-strata-hotel-dev--pr-1964-8ggsdl2f.web.app |
| error_code="RENEWAL_WINDOW_CLOSED", | ||
| ) | ||
|
|
||
| if application is None: |
There was a problem hiding this comment.
can we run the duplicate check when submitting a draft too? a draft can still create an invoice while another renewal is in progress. we'd need to skip the current draft in that check.
There was a problem hiding this comment.
Good point.
Yes, a renewal draft skipped the check when it was submitted, so it could get an invoice while another renewal was in progress. That's how H353013514 paid for two renewals on 2026-06-14, both from drafts started before the check went live (June 2026).
I checked Production: 52 registrations have a renewal draft beside another unfinished renewal (38 beside PAYMENT_DUE, 14 beside another DRAFT). All were created before the check went live on 2026-06-01, but any of them could still be submitted and paid.
The check now also runs when a renewal draft is submitted, leaving out the draft itself. Saving a draft still isn't checked, since that doesn't create an invoice. The web apps already show the right message for a 409 RENEWAL_ALREADY_IN_PROGRESS on submit. test_draft_is_submitted_only_while_no_other_renewal_is_in_progress covers it.
I put this in #1969 rather than #1964, since #1969 already changes this check.
…s submitted (REGBACKLOG-391) The 409 RENEWAL_ALREADY_IN_PROGRESS check ran only when a renewal was started, so submitting an existing draft created an invoice even while another renewal was in progress. That's how H353013514 paid for two renewals on 2026-06-14, from drafts started before the check went live. In Production, 52 registrations still have a renewal draft beside another unfinished renewal. - The check now also runs when a renewal draft is submitted. Saving a draft still isn't checked, since that creates no invoice. - find_non_terminal_renewal_for_payment_account takes an optional exclude_application_id, so the draft being submitted isn't its own conflict. - Adds test_draft_is_submitted_only_while_no_other_renewal_is_in_progress. Addresses review feedback on bcgov#1964.
There was a problem hiding this comment.
🟡 Changes recommended
Host and strata renewal guards close eligibility seven hours before the API’s Vancouver-day cutoff, hiding Renew while users are still eligible.
2 open issues
1 resolved since last review
2 files not reviewed
strr-platform-web/pnpm-lock.yaml: Generated filestrr-strata-web/pnpm-lock.yaml: Generated file
Review effort: Balanced
| "renewalWindow": { | ||
| "startDate": renewal_window.start_date.isoformat(), | ||
| "hasStarted": not renewal_window.is_not_yet_open, |





Issue:
Description of changes:
Merges
feature-REGBACKLOG-391-v2intomain. The renewal window, the period in which a registration can be renewed, becomes one shared rule in the API. The API enforces it when renewals are created and submitted, and the UI follows it. The window opens at the start of the Vancouver day, 60 days before expiry for strata hotels and 40 days for everything else. It closes at the end of the Vancouver day three years after expiry.The changes were reviewed in #1952, which describes each one in detail. In brief:
RenewalWindow(strr_api/utils/renewal_window.py), used by/todos, which now returns arenewalWindowobject (startDate,hasStarted).POST/PUT /applicationsreturns 400RENEWAL_WINDOW_NOT_OPENorRENEWAL_WINDOW_CLOSEDoutside the window. Nothing is saved or invoiced in those cases, and existing drafts can still be saved.renewalWindow.hasStarted. Renewal todos without an application number are handled once, instrr-base-web.strr-emailimports on Python 3.12 and 3.13. The todo task field isdetail. Platform and strata now havetypecheckscripts.expiryDateexamples, with guidance to compare dates, not times.The branch also includes #1959, #1960 and #1963, which bump versions above
main's and keep the branch up to date withmain. It is currently up to date withmain.Versions:
strr-api0.3.49,strr-base-web0.0.66,strr-host-pm-web1.3.42,strr-platform-web1.2.14,strr-strata-web1.2.17.Notes for reviewers:
renewalWindowfrom/todos; until the API sends it, the table shows "Active" instead of "Expiring soon".strr-base-webfrom GitHubmain, so the base-web changes take effect in the apps once this PR is merged.tzdata/pytz), REGBACKLOG-496 (storing expiries as the end of the Pacific day).How this was tested:
See #1952. In summary: the full API suite passed (863 passed, 6 skipped). All web unit suites passed (base 98, host 353, platform 48, strata 64, examiner 319). Lint was clean on the changed files, and duplication was about 1%. The
strr-emailtest suite wasn't run.Merging:
Once it's approved, use "Squash and merge" and keep the PR title as the commit message.