mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-23 14:17:06 +00:00
* refactor(push): the database and key names are written once for the page and both workers pushNames.js holds the puter-push database name, its stores, key prefixes and the subscription-changed message. pushStore.js re-exports them. push-sw.js and the GUI's sw.js are served as they are (push-sw.js also from npm's src/), so neither can import the module. Each carries a block generated from pushNames.js by tools/pushWorkerNames.mjs. The puter.js webpack build and the GUI build fail while either block is stale, and a test compares the names in both worker sources with the page module's. * refactor(push): the desktop reads the confirmed endpoint and the mark through puter.js puter.js now records the endpoint the server confirmed, and clears the subscription-changed mark, inside the Puter GUI as on a website. Three internal methods give the desktop what it kept itself: _webPushRecord() reads both, _noteWebPushSynced() records an endpoint a status check confirmed, and _dropRemovedWebPush() ends a removed subscription and forgets its receipt and the mark. webPushClient.js no longer opens the puter-push database or keeps its own localStorage record. An endpoint an earlier build kept there is read while puter.js has none, and removed once puter.js records one, so an already synced browser keeps its status without registering again. With a puter.js that lacks the methods, the client reads nothing from it and keeps the old record. * refactor(push): one-line comments on the push names and the record methods * fix(push): the worker names check reads CRLF checkouts, lives in tools/ and runs in PR CI The block helper moves to tools/pushNamesBlock.mjs, so it isn't part of the published puter.js sources. It compares and rewrites on LF text and writes back the file's own line endings. Both workers are pinned to LF in .gitattributes. The puter.js tests run when the GUI's sw.js or its build changes, and the GUI build checks sw.js before anything else. * fix(push): the desktop keeps a removed browser off with a puter.js that has no push record The desktop loads puter.js from its own URL, so it can run one without _webPushRecord(). The client then uses pushStore.js's helpers itself: it reads and clears the subscription-changed mark, ends a removed subscription and forgets its receipt and the mark, clears the mark after enable(), and keeps the confirmed endpoint in localStorage as before. _noteWebPushSynced() resolves whether it recorded the endpoint, and the localStorage endpoint is removed only after puter.js has it. A cached status reads only the mark before answering. The accessors carry JSDoc types. * fix(push): the removed-elsewhere check also asks about the endpoint in localStorage When loads alternate between puter.js versions, localStorage can hold a newer confirmed endpoint than puter.js does. The background check now asks about both, with the mark's old endpoint, before registering. * fix(push): with an older puter.js the desktop also asks about the endpoint puter.js recorded Once puter.js has recorded the confirmed endpoint, the desktop drops its localStorage copy. A later load that runs an older puter.js then read neither, so a browser that lost its subscription after being removed in Puter could register again. The fallback now reads puter.js's record from the store directly. * refactor(puter-js): the push record reads use try/catch instead of .catch() --------- Co-authored-by: Daniel Salazar <daniel.salazar@puter.com>
226 lines
7.9 KiB
YAML
226 lines
7.9 KiB
YAML
name: Puter.js API Tests
|
|
|
|
# Always triggers so it can be a required PR check; the `changes` job below
|
|
# decides whether puter.js-relevant paths actually changed (the suites live
|
|
# in src/puter-js/tests, so test-only changes are covered by the same glob,
|
|
# plus the pieces the runners depend on: the worker preamble, the in-memory
|
|
# test env in testUtil, and the backend vitest config the API-tests config
|
|
# extends), and every other job is skipped — not absent — when they didn't,
|
|
# which still satisfies a required check. Backend and extension changes run
|
|
# backend-tests.yaml instead.
|
|
on:
|
|
pull_request:
|
|
types: [opened, synchronize, reopened]
|
|
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
changes:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
puterjs: ${{ steps.filter.outputs.puterjs }}
|
|
steps:
|
|
- uses: actions/checkout@v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
- uses: dorny/paths-filter@v4.0.3
|
|
id: filter
|
|
with:
|
|
filters: |
|
|
puterjs:
|
|
- 'src/puter-js/**'
|
|
- 'src/worker/**'
|
|
- 'src/backend/testUtil.ts'
|
|
- 'src/backend/vitest.config.ts'
|
|
- 'src/gui/src/sw.js'
|
|
- 'src/gui/utils.js'
|
|
- 'tools/**'
|
|
- 'package.json'
|
|
- 'package-lock.json'
|
|
- '.github/workflows/puterjs-tests.yaml'
|
|
|
|
# The JSDoc in src/puter-js/src is the source of truth for the SDK's public
|
|
# types. The declarations shipped to npm are generated from it at build time
|
|
# and never committed, so what needs guarding is the JSDoc itself: this
|
|
# generates the declarations and type-checks the published surface without
|
|
# skipLibCheck, which is how broken re-exports used to go unnoticed.
|
|
#
|
|
# Its own job rather than a step in `test`: that one builds bundles and
|
|
# installs a browser, and this needs neither.
|
|
types:
|
|
needs: changes
|
|
if: needs.changes.outputs.puterjs == 'true'
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v7.1.0
|
|
with:
|
|
node-version: '26'
|
|
cache: 'npm'
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Check the puter.js JSDoc produces declarations that type-check
|
|
run: npm run check:puterjs:types
|
|
|
|
test:
|
|
needs: changes
|
|
if: needs.changes.outputs.puterjs == 'true'
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v7.1.0
|
|
with:
|
|
node-version: '26'
|
|
cache: 'npm'
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
# The runners exercise the built artifacts: the SDK bundle
|
|
# (src/puter-js/dist) for node + browser, and the worker preamble
|
|
# (src/worker/dist) for workerd.
|
|
- name: Build puter.js SDK and worker preamble
|
|
run: npm run build:workerLib
|
|
|
|
- name: Install Playwright chromium
|
|
run: npx playwright install --with-deps chromium
|
|
|
|
- name: Run puter.js API tests (node, browser, workerd)
|
|
run: npm run test:puterjs
|
|
env:
|
|
CI: 'true'
|
|
|
|
# SDK coverage on both refs, reported as a PR comment — same shape as
|
|
# backend-tests.yaml. This run uses the istanbul-instrumented bundle
|
|
# (the `test` job above keeps exercising the production build).
|
|
# `needs.changes` gates the steps below, not this job, on purpose: a
|
|
# job-level `if` on a matrix job skips the whole job as one unexpanded
|
|
# check ("coverage (${{ matrix.artifact }})", literally, since there's no
|
|
# matrix context to fill it in) instead of two real per-artifact checks —
|
|
# confusing to read, and unusable if this ever gets pinned as a required
|
|
# check. Letting the matrix always expand keeps the check names stable.
|
|
coverage:
|
|
needs: changes
|
|
# Overrides the default matrix naming, which would otherwise bake the
|
|
# base/head branch name (matrix.ref) into the check name — making it a
|
|
# different string on every PR and impossible to pin as a required check.
|
|
name: coverage (${{ matrix.artifact }})
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
# The base branch lives in this repo; for a fork PR, the head
|
|
# repo's copy of it can be arbitrarily stale.
|
|
- ref: ${{ github.base_ref }}
|
|
repository: ${{ github.repository }}
|
|
artifact: base
|
|
- ref: ${{ github.head_ref }}
|
|
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
|
artifact: pr
|
|
|
|
steps:
|
|
- name: Checkout ${{ matrix.ref }}
|
|
if: needs.changes.outputs.puterjs == 'true'
|
|
uses: actions/checkout@v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
ref: ${{ matrix.ref }}
|
|
repository: ${{ matrix.repository }}
|
|
|
|
- name: Set up Node.js
|
|
if: needs.changes.outputs.puterjs == 'true'
|
|
uses: actions/setup-node@v7.1.0
|
|
with:
|
|
node-version: '26'
|
|
cache: 'npm'
|
|
|
|
- name: Install dependencies
|
|
if: needs.changes.outputs.puterjs == 'true'
|
|
run: npm ci
|
|
|
|
- name: Install Playwright chromium
|
|
if: needs.changes.outputs.puterjs == 'true'
|
|
run: npx playwright install --with-deps chromium
|
|
|
|
# The base leg is best-effort — it only enriches the PR comment with
|
|
# a comparison, and the base ref may predate the coverage script.
|
|
- name: Run puter.js API tests with coverage
|
|
if: needs.changes.outputs.puterjs == 'true'
|
|
continue-on-error: ${{ matrix.artifact == 'base' }}
|
|
run: npm run test:puterjs:coverage
|
|
env:
|
|
CI: 'true'
|
|
|
|
- name: Upload coverage artifact
|
|
if: needs.changes.outputs.puterjs == 'true' && !cancelled()
|
|
uses: actions/upload-artifact@v7.0.2
|
|
with:
|
|
name: puterjs-coverage-${{ matrix.artifact }}
|
|
path: src/puter-js/coverage/coverage-*.json
|
|
retention-days: 14
|
|
if-no-files-found: ignore
|
|
|
|
report-coverage:
|
|
needs: [changes, coverage]
|
|
if: always() && needs.changes.outputs.puterjs == 'true'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
|
|
# Missing when the PR leg failed; `coverage (pr)` already reports that.
|
|
- name: Download PR coverage
|
|
id: pr-coverage
|
|
continue-on-error: true
|
|
uses: actions/download-artifact@v8.0.2
|
|
with:
|
|
name: puterjs-coverage-pr
|
|
path: src/puter-js/coverage
|
|
|
|
# May not exist (base ref without the coverage script, or a failed
|
|
# base run) — then report without the comparison column.
|
|
- name: Download base coverage
|
|
id: base-coverage
|
|
if: steps.pr-coverage.outcome == 'success'
|
|
continue-on-error: true
|
|
uses: actions/download-artifact@v8.0.2
|
|
with:
|
|
name: puterjs-coverage-base
|
|
path: coverage-base
|
|
|
|
- name: Report coverage on PR
|
|
if: steps.pr-coverage.outcome == 'success' && steps.base-coverage.outcome == 'success'
|
|
uses: davelosert/vitest-coverage-report-action@v2.13.2
|
|
with:
|
|
name: puter.js SDK
|
|
json-summary-path: src/puter-js/coverage/coverage-summary.json
|
|
json-final-path: src/puter-js/coverage/coverage-final.json
|
|
json-summary-compare-path: coverage-base/coverage-summary.json
|
|
|
|
- name: Report coverage on PR (no base comparison)
|
|
if: steps.pr-coverage.outcome == 'success' && steps.base-coverage.outcome != 'success'
|
|
uses: davelosert/vitest-coverage-report-action@v2.13.2
|
|
with:
|
|
name: puter.js SDK
|
|
json-summary-path: src/puter-js/coverage/coverage-summary.json
|
|
json-final-path: src/puter-js/coverage/coverage-final.json
|