Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,49 @@ Run `npm run format` from the repository root before submitting changes. `npm ru

## Complete compatibility units only

New compatibility implementations must be completed before merge or release unless an explicitly authorized release exception applies. A useful subset, a working framework demo, or passing tests for selected methods does not establish whole-module completion. Release exceptions cover [the current PR #72 candidate](#pr-72-scoped-release-exception) and existing implementations in [0.1.0 Preview and its explicitly authorized 0.1.1, 0.1.2, 0.1.3 and 0.1.4 follow-ups](#010-preview-exception).
Product release readiness follows the remote-first application gate below.
Whole-module completion remains a separate claim: a working application or selected
method tests must never promote an incomplete module to **Complete**.

For Node.js compatibility, the acceptance unit is a module, including its Workers
For Node.js compatibility, the completion unit is a module, including its Workers
exports, subpaths and observable behavior. For a binding or Web API, define the
named API unit before implementation. Do not redefine the unit around the methods
that happen to work. Large units may be developed in several commits or draft PRs,
but incomplete implementation PRs must not be merged into main unless covered by
an explicitly authorized release exception.
named API unit before implementation. Do not redefine it around methods that work.

## Remote-first application release gate

The primary supported workflow builds an existing Workers application into a
mobile app while executing server requests on its deployed Worker. The maintainer
has authorized this release policy starting with 0.1.7. Existing incomplete local
compatibility implementations may ship with their **In progress**, **Unverified**
or **Not implemented** status retained. Full Node parity is not a product release
prerequisite. Historical version exceptions below describe earlier releases.

A release requires all of the following:

- The declared framework profiles build through public Vite/esbuild tooling and
an independently installed npm tarball. Remote-only server dependencies and
secrets stay outside client bundles and source maps; the Cloudflare build is
preserved.
- Remote selection happens before application execution. Unknown or unsupported
server graphs may remain wholly remote. Never retry a failed local mutation on
the server, or silently queue/retry a remote mutation after a transport failure.
- Required application scenarios pass on iOS simulator and Android emulator,
covering the applicable navigation/forms, remote data assertions, sessions,
streaming, cancellation and lifecycle contracts. Physical devices are not a
release prerequisite. State the tested versions and host-specific boundaries.
- The candidate passes existing regression, public types/imports, package,
native embedding and required CI checks. Known failures in required scenarios
must be fixed, not renamed as unfinished work. Evidence must match the candidate.
- Manager and independent acceptance reviews have no required changes. Record
evidence in the PR/generated artifacts. Documentation provides matching npm,
SwiftPM and Maven dependencies, reproduction commands and known exclusions.
- Client initialization failures cannot be repaired by server dispatch. Keep
Better Auth origin restrictions, WebAuthn and unsupported HTTP upgrades visible;
no universal authentication, arbitrary framework-version or offline guarantee.

Use [build setup](docs/build-setup.md), [framework limits](docs/compatibility.md)
and [native dependency setup](docs/native-embedding.md#dependency-setup) to define
supported profiles. API completion work continues independently of releases.

The target is Cloudflare Workers, not every API available in a Node.js process.
Pin the workerd version, compatibility date and flags. An operation unsupported
Expand All @@ -35,7 +70,7 @@ CORS, headers, cookies, redirects, streaming and cancellation must not be exclud

## Acceptance gate

A compatibility implementation is ready to merge only when all of these are true:
A compatibility unit may be marked **Complete** only when all of these are true:

- The baseline's exports, subpaths, signatures and relevant prototype methods
have been inventoried, with no unresolved coverage decisions.
Expand Down Expand Up @@ -64,11 +99,10 @@ Only then may the inventory say **Complete**. Until then, use **In progress**,

## Work in progress

Except for an explicitly authorized release exception, keep incomplete compatibility work on a development branch or draft PR. Do not
activate it in a merged build alias, public export or default runtime path, and do
not ship it behind an experimental flag as a substitute for finishing it. Design
notes and reproducible experiments can be reviewed independently without adding
unfinished production behavior.
Keep unfinished new API work on a development branch or draft PR until its
claimed scenarios satisfy the release gate. Existing incomplete compatibility may
ship under the remote-first policy, with its limitations retained. An experimental
flag or successful namespace import does not establish behavioral completion.

### PR #72 scoped release exception

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Install the package in your web project, then follow the
[complete mobile setup](docs/integration.md#workflow):

```sh
npm install --save-exact cf-workers-native@0.1.5
npm install --save-exact cf-workers-native@0.1.7
```

Installation alone does not generate a mobile project. The guide covers adding
Expand All @@ -84,7 +84,7 @@ Open your application repository and give your assistant this prompt:

```text
Read https://github.com/rdlabo-dev/cf-workers-native/blob/main/docs/integration.md.
Add an iOS and Android version of this Workers web app using cf-workers-native@0.1.5
Add an iOS and Android version of this Workers web app using cf-workers-native@0.1.7
and Capacitor. Preserve the existing pages, backend and Cloudflare deployment configuration.
Use an existing test Worker for cloud-backed requests; ask before any cloud deployment.
Start by verifying one page, navigation and a form or data action on a simulator/emulator.
Expand Down
23 changes: 23 additions & 0 deletions demo/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ See their READMEs for commands, prerequisites and evidence limits.

## Capacitor native checks

### Remote-first release coverage

The product gate is defined in [CONTRIBUTING](../../CONTRIBUTING.md#remote-first-application-release-gate).
Use these existing suites together; no single smoke test certifies an application
or whole-module Node compatibility. Commands below run from `demo/` unless noted.

| Release contract | Verification entry |
| -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| Server-only dependency exclusion; pre-execution selection; failed mutations are not replayed | Root `npm test` (`execution-policy`, `remote-worker`, binding/build suites) |
| Public package imports, types and independent Vite/esbuild consumer | Root `npm run typecheck` and `npm run test:package` |
| Hono / Workers Express builds and page behavior | `npm run test:browser`, `npm run test:build-tools`; packaged native rendering below on both platforms |
| Void React Pages hydration, navigation and D1 action | `npm run test:void`, `npm run test:void:routes`; [Void native fixture](void/native.test.mjs) |
| OpenNext public assets, remote protocol/session/form behavior and lifecycle | `npm run test:opennext`, `npm run test:opennext:split`; [OpenNext fixture](upstream/opennext/README.md) |
| D1/R2 backed application operations | [0bin](upstream/0bin/README.md), [FlareDrive](upstream/flaredrive/README.md), and binding suites |
| Native cookies, redirects, streaming, cancellation and restart | Packaged native rendering and native networking procedures below |
| Standalone iOS / Android installation and lifecycle | Native embedding workflow and independent consumers above |

Record exact source/package revisions and platform results in generated artifacts
and the PR. Browser results do not replace native transport results. Local workerd
database assertions do not certify every deployed Cloudflare service. Keep upstream
authentication restrictions, passkeys, arbitrary version skew and unsupported
upgrade transport outside the supported profile until their own acceptance passes.

Prepare a test app in Capacitor's ordinary `dist/` directory, then sync and run:

```sh
Expand Down
33 changes: 32 additions & 1 deletion demo/tests/experiments/node-compat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ from individual case and socket deadlines.

`NODE_COMPAT_CASES=name,otherName` filters shared cases for diagnosis. It does not
filter native network rows, and a filtered run is not full acceptance. Native
`stage:complete` means all observations were collected; exact assertions run
filtered runs read the matching `targeted/expansion-contracts-workerd.json`;
run the public comparison with the same filter first. Every native case checks
the SHA-256 of its function source against the oracle record, so editing a case
requires regenerating its baseline.

Native `stage:complete` means all observations were collected; exact assertions run
subsequently and may still fail. Current TLS and WebSocket implementation gaps
remain failures, not skipped or accepted differences. The reports, generated
harness, compiled hash and workerd baseline live under
Expand All @@ -49,3 +54,29 @@ The narrowly approved attachment size-accounting boundary is documented in the
`node --test demo/tests/experiments/node-compat/websocket-attachment-boundary.probe.mjs`
to reproduce its pinned Workers observations. This reference probe does not
certify the candidate or exempt network failures from acceptance.

## API and test mapping

`api-test-operations.json` maps reviewed operation scenarios to named contracts
and execution targets. It distinguishes host-forwarding unit tests from shared
behavior and expected-rejection comparisons. It is test metadata, not a record
that a particular candidate passed. Keep execution logs and package/source hashes
in generated artifacts and PR evidence.

```sh
node demo/tests/experiments/node-compat/api-test-map.mjs --write
node --test demo/tests/experiments/node-compat/api-test-map.test.mjs
```

The generated `artifacts/validation/existing-api-coverage/api-test-map.json`
lists every pinned module/export and source references to adjacent cases and
fixtures. These token matches are navigation candidates, not verified behavioral
coverage: dynamic calls may lack a literal reference, while a namespace assertion
may contain an API name without calling it. Use the reviewed operation rows and
actual assertions to establish scope. The guard checks inventory retention,
named-case existence, shared-runner or unit-runner registration, API references
and target names. It cannot establish semantic coverage or replace review.

Missing APIs and documented engine/host boundaries remain separate from test
gaps. A passing finite scenario does not certify all options, states or the entire
module; retain the whole-module acceptance gate in `CONTRIBUTING.md`.
185 changes: 185 additions & 0 deletions demo/tests/experiments/node-compat/api-test-map.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import fs from "node:fs";
import path from "node:path";
import { parse } from "@babel/parser";
import { fileURLToPath } from "node:url";
const root = fileURLToPath(new URL("../../../..", import.meta.url));
const read = (file) => fs.readFileSync(path.resolve(root, file), "utf8");
const base = JSON.parse(
read("demo/tests/experiments/node-compat/exports.json"),
);
const types = JSON.parse(
read("demo/tests/experiments/node-compat/export-types.json"),
);
const reviewed = JSON.parse(
read("demo/tests/experiments/node-compat/api-test-operations.json"),
);
const gaps = JSON.parse(
read("demo/tests/experiments/node-compat/surface-gaps.json"),
);
const shared = read("src/tooling/shared.ts");
const entries = Object.fromEntries(
[
...shared
.slice(
shared.indexOf("const builtins:"),
shared.indexOf("function builtinAliases"),
)
.matchAll(/\[\s*"([^"]+)",\s*"([^"]+)"/g),
].map(([, name, entry]) => [
name.replace(/^node:/, ""),
"src/compat/" + entry.replace(/\.(c?js)$/, ".ts"),
]),
);
const inventory = {
modules: Object.keys(base.modules).map((module) => ({
module,
entry: entries[module],
})),
};
const walk = (d) =>
fs
.readdirSync(path.resolve(root, d), { withFileTypes: true })
.flatMap((x) =>
x.isDirectory() ? walk(path.join(d, x.name)) : [path.join(d, x.name)],
);
const cases = [];
for (const file of walk("src/compat").filter((x) =>
/\.(spec|fixture)\.[cm]?[jt]s$/.test(x),
)) {
const source = read(file),
tree = parse(source, {
sourceType: "module",
plugins: ["typescript", "explicitResourceManagement"],
});
const name = (n) => n?.key?.name ?? n?.key?.value ?? n?.id?.name;
const add = (id, node, kind) =>
cases.push({
id: file + "#" + id,
file,
name: id,
kind,
code: source.slice(node.start, node.end),
});
const visit = (n) => {
if (!n || typeof n !== "object") return;
if (
n.type === "ObjectProperty" &&
name(n) === "cases" &&
n.value.type === "ObjectExpression"
)
for (const p of n.value.properties)
if (name(p)) add(name(p), p, "contract");
if (
n.type === "VariableDeclarator" &&
n.init?.type === "ObjectExpression"
) {
if (/Cases$/.test(name(n))) {
for (const p of n.init.properties)
if (name(p)) add(name(p), p, "comparison");
} else if (n.init.properties.some((p) => name(p) === "test"))
add(name(n), n.init, "fixture");
}
if (
n.type === "CallExpression" &&
["test", "it"].includes(source.slice(n.callee.start, n.callee.end)) &&
n.arguments[0]?.type === "StringLiteral"
)
add(n.arguments[0].value, n, "unit");
for (const [k, v] of Object.entries(n))
if (k !== "loc") {
if (Array.isArray(v)) v.forEach(visit);
else if (v && typeof v === "object") visit(v);
}
};
visit(tree);
}
const special = {
"fs/promises": "fs",
"path/posix": "path",
"path/win32": "path",
"util/types": "util",
_tls_wrap: "tls",
_stream_wrap: "tls",
};
const inputName = {
fs: "fs",
crypto: "crypto",
zlib: "zlib",
util: "util",
sys: "sys",
"util/types": "types",
tls: "tls",
http: "http",
process: "process",
console: "console",
module: "module",
stream: "classicStreams",
"stream/web": "streams",
_http_common: "httpCommon",
_http_outgoing: "httpOutgoing",
_http_server: "httpServer",
};
const rows = [];
for (const m of inventory.modules) {
const owner = special[m.module]
? inventory.modules.find((x) => x.module === special[m.module])
: m;
const dir = path.dirname(owner.entry);
let selected = cases.filter((c) => c.file.startsWith(dir + "/"));
if (inputName[m.module])
selected.push(
...cases.filter(
(c) =>
c.file.includes("/expansion/") &&
new RegExp("\\b" + inputName[m.module] + "\\b").test(
c.code.slice(0, c.code.indexOf("})") + 2),
),
),
);
const entries = base.modules[m.module].map((exp) => {
const escaped = exp.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const matched = selected.filter((c) =>
new RegExp("\\b" + escaped + "\\b").test(c.code),
);
return {
name: exp,
type: types.modules[m.module][exp],
surfaceTest: "demo/tests/experiments/node-compat/local-surface.test.mjs",
missingInPinnedSurfaceAudit:
gaps.common[m.module]?.missing?.includes(exp) ?? false,
reviewedOperations: reviewed.operations
.filter(
(operation) =>
operation.modules.includes(m.module) &&
operation.apis.some(
(api) => api === exp || api.startsWith(exp + "."),
),
)
.map((operation) => operation.id),
cases: matched.map((c) => c.id),
};
});
rows.push({ module: m.module, entry: m.entry, exports: entries });
}
export const referenceIndex = {
scope:
"Source reference index, not behavioral coverage certification. Token matches are navigation candidates; reviewed operation rows are in api-test-operations.json. Every export also has the name/type inventory audit in local-surface.test.mjs.",
profile: base.profile,
modules: rows,
cases: cases.map(({ code, ...c }) => c),
};
if (process.argv.includes("--write")) {
fs.mkdirSync(
path.resolve(root, "artifacts/validation/existing-api-coverage"),
{
recursive: true,
},
);
fs.writeFileSync(
path.resolve(
root,
"artifacts/validation/existing-api-coverage/api-test-map.json",
),
JSON.stringify(referenceIndex, null, 2) + "\n",
);
}
Loading
Loading