-
Notifications
You must be signed in to change notification settings - Fork 0
chore: #134 run Playwright E2E in CI, expand tests, and harden CI/CD deploy #137
Conversation
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.
Thanks, this is a big step up. CI is green on 9198784. The E2E job is set up carefully: it uses a socket-only throwaway cluster, picks ephemeral ports with --strictPort, and has an if: always() cleanup. The new tests cover the paths that were missing.
Request changes
-
The rollback trap is installed too late. In "Deploy the API…",
trap on_exit EXITcomes after thecrate-api.service,server/and.gitchecks and afterPREV_SHA=…. If any of those fail,set -eexits before the trap exists. The new frontend from the previous step then stays live against the old API, andproject2.previs left behind. Please moveAPI_TOUCHED=0,DEPLOY_OK=0and the trap to the top of the step, before the first check.rollbackalready handlesAPI_TOUCHED=0. -
Migrations and the import can't be rolled back.
server/drizzle/*.sqlonly goes forward, anddb:import:musicbrainzchanges the catalog in place. If the restart or the smoke checks fail afterdb:migrate, the rollback puts the old code back on the new schema. That works for additive migrations, but not for a rename or a dropped column. Please either:- write the rule down: migrations must stay compatible with the previous release (expand first, contract in a later PR), or
- skip the API rollback and fail loudly when
server/drizzle/changed betweenPREV_SHAandGITHUB_SHA.
Please also change "rolls back both frontend and API" in the description to say that the database is not rolled back.
Should fix
-
Concurrency can cancel a deploy halfway.
cancel-in-progress: truealso applies tomain. A second push while a deploy is running cancels it. The trap does fire on SIGTERM, but the runner kills the job a few seconds later, which is in the middle ofpnpm install/build. Suggestcancel-in-progress: ${{ github.event_name == 'pull_request' }}. -
A failed rollback looks like a normal failure.
rollbackruns withset +e, and thenexit "${status}"reports only the original error. If the rollback build orwait_for_apifails, the API may be down, and the only sign is a line in the log. Please add::error::Rollback failed, crate-api may be downwhenwait_for_apifails insiderollback. -
The self-hosted runner trust boundary.
contents: readis correct, and deploy still works with it.git fetchin~/T19-Project-2uses that clone's own credentials, notGITHUB_TOKEN. But it only limits the token. PR jobs run as the same OS user that deploys, so PR code can read~/T19-Project-2/.env(the productionDATABASE_URL), write to/var/www/html/project2and runsudo systemctl restart crate-api. The new E2E job also starts servers and a browser on the production VM. I know the docs part is planned for #133/#135. But the wording there right now ("so untrusted code cannot modify the repository or deployment state") is too strong. It should say that PR checks run with the deploy user's access, so only group members should open PRs. Better still, run PR jobs on a second runner under a separate user with no sudo and no access to.env.
Non-blocking
- Pinned SHAs check out.
actions/checkout08eba0bis v4.3.0, andactions/setup-node49933eais v4.4.0, on both github.com and the git.ntnu.no mirror (GHES 3.19.17). The mirror has no checkout v4.4.0, so going down to v4.3.0 in9198784was the right fix.pnpm/action-setupisn't mirrored, so it comes from github.com. There,b906affis v4.3.0, which is also whatv4points to now. The YAML comments are correct, but the description says "full v4.4.0 commit SHAs". Please change it to v4.3.0/v4.4.0. - Flaky patterns. These don't matter in CI, where the database is fresh. They do matter when running against a reused database:
if (await leftover.isVisible())in the review test doesn't wait, so it can run before the review loads.- The
while (count() > 0)cleanup loops incrate.spec.tsanda11y.spec.tscan click the same button twice while the mutation is still running. - Waiting for the item count to drop, or deleting leftovers through GraphQL in a
beforeEach, would be more robust. retries: 1in CI will also hide flakes. It's worth checking the log for "flaky" from time to time.
- Failure output is deleted. Cleanup removes
e2e-api.logandtest-results(wheretrace: retain-on-failurewrites). After a red Playwright run there's nothing left to look at. Suggest printingtail -50of the API and client logs before deleting them when the job failed. - Disk. One shared
~/.cache/ms-playwrightis good. But every Playwright bump downloads a new Chromium and the old one stays. Afind ~/.cache/ms-playwright -maxdepth 1 -name 'chromium_headless_shell-*'step that keeps only the newest would fix that. - Ports. CI is fine. The local
webServeruses port 3001 withreuseExistingServer: !CI. Runningpnpm test:e2eon the VM withoutE2E_BASE_URLwould reuse the livecrate-apiand write test data to the production database. Maybe add a comment, or refuse whenHOSTNAMEisit2810-19. - Order of steps. The frontend is swapped before the API is built, migrated and restarted. That's several minutes of new frontend against the old API. Deploying the API first and swapping the frontend last would make that gap shorter and the rollback simpler. "Atomically" also isn't quite right, since it's two
mvs with a short 404 in between. - Merge conflict with #140. #140 adds a "Confirm delete" step. The review test here then needs
Confirm deleteafter bothDelete reviewclicks, andsearch.spec.tswill have a small conflict.
9198784 to
1e96a5c
Compare
|
Thanks for the thorough review, @evenkkl! Rebased onto Request changes
Should fix
Non-blocking improvements
|
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.
Thanks, all of it checks out. Approving.
- Runner note: now says plainly that
contents: readonly limits the token on GitHub, and that PR jobs run as the deploy user with access to.env, the web root andsystemctl restart. Good. Note that #137 isn't merged yet, so thepermissions:block isn't onmainuntil it is. - NODE_ENV: the "supported since #129 / PR #136" note is correct. #136 is merged, and
mainhas theisProductioncheck. theme-init.jscaching: theFilesMatchregex is right, the quoted heredoc keeps the backslashes, and the expected output now lists it.- CSP check: the DevTools /
Report-Onlynote is what I was after. - Hero markup: the plain
src+ mobilesourceis correct now, and the tests check thatsrcset/sizes/typeare gone. - Favicon: it's same-origin, so
img-src 'self'covers it, and it removes the/favicon.ico404.
The mobile crop and the image preload from last time are still open, but both were non-blocking. Fine as follow-ups if Lighthouse shows they matter.
…harden deploy rollback
|
Rebased
Verified locally against the full integrated |
1e96a5c to
356e22b
Compare
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.
Re-reviewed at 356e22b after the rebase onto main. CI is green, including E2E. The deploy rollback, the migration handling and the E2E cleanup all look good. The rebase conflicts are resolved correctly, including Confirm delete and #140's crate button labels. Approving.
Closes #134
What was done
CI/CD & lint hardening
package.json"lint"toeslint . --max-warnings 0(matchesAGENTS.md).e2ejob to.github/workflows/ci.ymlrunning on PRs and pushes tomain(gatingdeployalongsidequalityandintegration):db:seed.crate-api.serviceon port 3001) andvite previewproxying/graphqlviaVITE_API_PROXY_TARGET.~/.cache/ms-playwrightinstall withplaywright install chromium --only-shell, prunes olderchromium_headless_shell-*builds so Playwright upgrades do not fill the VM's disk, prints the last 50 lines ofe2e-api.logande2e-client.logon failure (if: failure()), and removes temp DBs/logs/test-results/playwright-reportinif: always().permissions: { contents: read }and pinnedactions/checkout,pnpm/action-setup, andactions/setup-nodeto full v4.3.0/v4.4.0 commit SHAs with version comments.contents: readlimitsGITHUB_TOKENon GitHub only. Because PR jobs currently run onit2810-19under the same OS user that deploys (with access to~/T19-Project-2/.env,/var/www/html/project2, andsudo systemctl restart crate-api), only trusted group members should open PRs; moving PR checks to a separate unprivileged runner user would isolate this further.cancel-in-progress: ${{ github.event_name == 'pull_request' }}so superseded PR runs cancel, while pushes tomainnever cancel an in-progress deploy halfway.EXITtrap and initializes state flags (API_TOUCHED,MIGRATIONS_CHANGED,MIGRATIONS_APPLIED,FRONTEND_SWAPPED,DEPLOY_OK) at the very top of the deploy step before the first prerequisite check so early failures never leave.new/.prevbehind..new/.prevsibling directories with aRUNNER_TEMPcopy fallback if/var/www/htmlis not writable — not strictly atomic since twomvs leave a brief window).server/drizzle/*.sqlmigrations and the in-place MusicBrainz import are forward-only (expand first, contract in a later PR). Ifserver/drizzle/changed betweenPREV_SHAandGITHUB_SHAand migrations were already applied before a failure, automatic API code rollback is skipped with a loud::error::annotation for manual intervention (while still rolling back the frontend if swapped).::error::Rollback failed, crate-api may be downif rebuilding, restarting, or waiting for/graphqlfails during API rollback.Real PostgreSQL integration tests
server/src/reviews.postgres.test.tscoveringsaveReview(upsertReview),removeReview(deleteReview), cross-user delete protection, DBreview_refresh_album_average_rating&review_set_updated_attriggers,reviewsForAlbumkeyset cursor pagination across timestamp ties, bad cursor rejection, and GraphQL Yoga execution.server/src/crate.postgres.test.tswith idempotentaddToCrate/removeFromCratemutation tests, DataLoader priming, missing-album rejection, and cross-user isolation.src/reviews.postgres.test.tsinserver/scripts/assert-postgres-tests.mjsand added localpnpm test:integration(server/scripts/run-postgres-tests.mjs).Expanded Playwright E2E & jsdom accessibility tests
e2e/tests/crate.spec.ts(add to crate ->/crate-> reload -> remove -> reload) and expandede2e/tests/search.spec.ts(search history keyboard selection,Load morepagination against 24 seeded albums inserver/src/db/seed.ts, review validation & editing, shared multi-filter URL restoration).e2e/tests/cleanup.tsto clear fixed E2E users' leftover reviews, crate items, and search history deterministically via GraphQL before running, avoiding UI cleanup races against a reused database.e2e/tests/a11y.spec.tswith real-browseraxe-coreWCAG 2.1 A/AA scans for/crate(empty & populated), dark mode (colorScheme: 'dark'), mobile viewport (390x844), open search-history combobox, andReviewFormvalidation error state.webServerconfiguration ine2e/playwright.config.tswhenE2E_BASE_URLis unset, refusing to start/reuse localwebServeronit2810-19withoutE2E_BASE_URLso livecrate-apion port 3001 is never touched.client/src/a11y.test.tsx(AlbumDetailPage,CratePagepopulated & empty, openRecentSearchescombobox with active option,ReviewFormvalidation & mutation error states) and clearedlocalStorage/sessionStoragearound each test inclient/src/test/setup.ts.What was tested
pnpm format:check && pnpm lint && pnpm typecheck && pnpm test && pnpm build— all passed (0 lint warnings;client/src/generatedclean).TEST_DATABASE_URL=... pnpm test:integrationagainst a throwaway local PostgreSQL cluster — 17/17 server test files, 217/217 tests passed;assert-postgres-tests.mjsconfirmed all 7 database-backed test files executed.CI=1 E2E_BASE_URL=... pnpm test:e2eagainst a throwaway migrated + seeded PostgreSQL cluster, built API, andvite preview— 20/20 Playwright tests passed on a fresh DB and 20/20 passed again after injecting leftover reviews and crate items into the reused DB.