Skip to content

Add browser CI workflow - #136

Merged
kawanet merged 9 commits into
kawanet:mainfrom
kawanet-bot:feature/browser-ci
Aug 31, 2026
Merged

Add browser CI workflow#136
kawanet merged 9 commits into
kawanet:mainfrom
kawanet-bot:feature/browser-ci

Conversation

@kawanet-bot

Copy link
Copy Markdown
Contributor

Summary

  • add a Browser CI workflow for pushes to main and manual runs, byte-identical to the sibling packages' workflow, with the shared tests.cli.mjs runner (also byte-identical): completion is reported through window.mochaStats, an unfinished page times out, and an empty run fails with "Mocha ran no tests"
  • new browser/ harness: the test bundle externalizes assert and ../index and is rewired to the page globals, so the browser suite exercises the shipped dist/msgpack.min.js rather than a re-bundled copy of the sources
  • Buffer and assert come as prebuilt IIFE shims bundled from the npm packages into page-scope const bindings — no window pollution, and no Node globals assumed
  • the suites drop the __filename-derived titles and the window.msgpack || require(...) dance for literal titles and a plain require("../index"), which the bundle rewiring maps to the dist global in browsers
  • .npmrc (omit=optional) is replaced by "allowScripts": { "msgpackr-extract": false }: the omit existed to keep msgpackr's optional native accelerator out, but it also dropped rollup's platform-specific binaries and broke the browser build on a fresh install. The allowScripts entry keeps the accelerator's install script blocked and the install warning-free, while optional dependencies come back
  • "type": "commonjs" becomes explicit, so the .mjs runner and the .js sources are both unambiguous

Verification

  • make -C browser install && make -C browser test — 177 tests / 177 passes in headless Chromium, against dist/msgpack.min.js
  • npm test — 191 passing (Node; the stream/compat suites stay Node-only)

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

kawanet-bot and others added 2 commits August 31, 2026 20:15
browser/Makefile bundles node_modules/assert/assert.js, which so far
arrived only transitively through browserify. Pin the same major
explicitly so the shim survives a future toolchain change.

Co-authored-by: Claude <noreply@anthropic.com>
The runner exited silently on success; one line from the stats the
page already publishes makes the run legible in CI logs and locally,
and still prints before a failing verdict throws.

Co-authored-by: Claude <noreply@anthropic.com>
@kawanet
kawanet requested a balanced review from Copilot August 31, 2026 11:24
@kawanet

kawanet commented Aug 31, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a428cf544

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread package.json
Comment on lines +6 to +8
"allowScripts": {
"msgpackr-extract": false
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Actually block the optional dependency's install script

On regular installs such as the Node CI workflow's npm install, npm does not enforce this allowScripts metadata, so removing .npmrc causes the optional msgpackr-extract lifecycle script to run again. I confirmed this behavior with npm 11.4.2—the version bundled with the workflow's Node 24 toolchain—where a dependency's install script still executed despite an allowScripts: {dep: false} entry; npm's documented mechanism for suppressing lifecycle scripts is ignore-scripts. Use an enforcement mechanism that npm actually recognizes so the native installer remains blocked as intended.

Useful? React with 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It reworks build tooling (fragile perl-based rollup rewiring, transitive buffer reliance) and dependency-resolution behavior (omit=optional → npm-v12-only allowScripts) whose effects span multiple environments, warranting a human's final review even though no outright bug was found.

Pull request overview

This PR adds a browser CI pipeline for msgpack-lite, running the existing Mocha suite against the shipped dist/msgpack.min.js in headless Chromium via Playwright. It introduces a self-contained browser/ harness (Makefile + Playwright runner + HTML page) that rollup-bundles the test files, externalizes assert and ../index, and rewires them to page globals (with prebuilt Buffer/assert IIFE shims). It also refactors the test files to drop the old window.msgpack || require(...) browser-detection dance in favor of plain require("../index") and literal titles, and adjusts dependency handling so the browser build works on a clean install.

Changes:

  • New Browser CI workflow plus a browser/ harness (Makefile, tests.cli.mjs, tests.html) that runs the suite against dist/msgpack.min.js.
  • Mechanical refactor of 21 test files: literal TITLE strings replace __filename, and require("../index") replaces the isBrowser/window.msgpack branch.
  • Dependency/config updates: .npmrc (omit=optional) replaced by allowScripts in package.json, explicit "type": "commonjs", and rollup/plugins/assert added as devDependencies.
File summaries
File Description
.github/workflows/browser.yml New Browser CI workflow (push to main + manual), consistent with existing @v7 actions.
browser/Makefile Builds the test/shim bundles via rollup and installs/runs Playwright.
browser/tests.cli.mjs Playwright runner that waits on window.mochaStats and fails on errors/no-tests.
browser/tests.html Loads mocha, dist bundle, shims, and bundled tests in the correct order.
package.json Adds allowScripts, rollup/plugin/assert devDeps, explicit type: commonjs.
.npmrc Removes omit=optional so platform binaries return for the browser build.
.gitignore Ignores generated browser/tests/, keeps browser/tests.cli.mjs tracked.
test/10–27, 61, 62, 64, 30, 50 *.js Literal titles + plain require("../index"); browser-detection removed.

I verified that all isBrowser/window.msgpack/__filename usages were removed consistently (no stragglers), each literal TITLE matches its filename, the dist global name (msgpack) matches the perl rewiring, 64.decode-limit.js's exclusion from the browser glob is justified (it uses the Node-only process.memoryUsage()), and the allowScripts package.json field is a genuine npm v12 feature. I did not find concrete defects to comment on.

Review details
  • Files reviewed: 27/28 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

kawanet-bot and others added 2 commits August 31, 2026 20:42
tests.html exercises the shipped minified bundle, which nothing in the
browser flow rebuilt: a source change without a dist refresh would be
tested against the old code. Delegate to the root Makefile's file
target, which stays the owner of whether a rebuild is due.

Co-authored-by: Claude <noreply@anthropic.com>
tests.html needs the shipped bundle whether the suite runs headless or
is opened by hand in a browser, so the freshness check belongs to the
target that prepares the page, not to the CLI run.

Co-authored-by: Claude <noreply@anthropic.com>
@kawanet

kawanet commented Aug 31, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 270bfe355f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread browser/Makefile

PLAYWRIGHT_VERSION := 1.62.1

TEST_SRC := ../test/[12]*.js ../test/6[12]*.js

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Provide the Node global expected by bundled tests

Bundling the 1* and 2* suites into a plain browser IIFE includes test/21.ext.js and test/22.typedarray.js, which evaluate expressions such as global[name]. Chromium does not define the Node global identifier, and none of the loaded shims creates it, so bundled.js raises a ReferenceError while registering tests and the new browser job fails on every run. Replace those lookups with globalThis/window or provide an explicit browser global shim.

Useful? React with 👍 / 👎.

Comment thread package.json
Comment on lines +6 to +8
"allowScripts": {
"msgpackr-extract": false
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the optional-dependency script protection

When developers or the existing Node.js CI run plain npm install, this allowScripts object is ignored by npm, so deleting .npmrc's omit=optional causes msgpackr-extract to be installed and its lifecycle script to run again. This was reproducible with npm 11.4.2, and older npm versions in the Node 18/20/22 matrix also do not enforce this field; retain an npm-supported restriction such as omitting optional dependencies or using --ignore-scripts at every install site.

Useful? React with 👍 / 👎.

Comment on lines +3 to +6
on:
push:
branches: [main]
workflow_dispatch:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Run browser CI on pull requests

This workflow only runs after a commit reaches main (or when manually dispatched), so browser-only regressions introduced by a pull request cannot be detected before merge; the existing Node workflow does not execute make -C browser test. Add a pull_request trigger so this new suite can serve as a pre-merge CI check.

Useful? React with 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new Browser CI workflow is missing an npm install step needed for the Makefile-driven dist/test bundling, and the Playwright runner currently hides captured page errors when the run times out.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

browser/tests.cli.mjs:25

  • pageErrors are only surfaced after waitForFunction succeeds. If the page throws during load and window.mochaStats is never set, the run will time out and the collected pageerrors won’t be included, which makes CI failures much harder to debug.
        await page.waitForFunction(() => window.mochaStats !== undefined, null, {timeout: 60_000})
        const {tests, passes, pending, failures, duration} = await page.evaluate(() => window.mochaStats)
        console.log(`${passes} passing, ${failures} failing, ${pending} pending (${tests} tests, ${duration}ms)`)

        if (pageErrors.length) {
  • Files reviewed: 27/28 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread .github/workflows/browser.yml
@kawanet
kawanet merged commit a3177d1 into kawanet:main Aug 31, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants