Files
AFFiNE/tools/parity-harness/scripts/socketio-reference.mjs
T
DarkSky 4a08e49642 feat(ci): add crates/ test harness workspace, shared frame audit and fast CI lanes
- crates/: standalone server-side Rust workspace (resolver 3, edition
  2024, own lock and toolchain 1.98.1)
  - frame-audit: the one serde-only FrameSnapshot schema and audit
    engine; native-playground's ui depends on it by path and re-exports
    it. The six structural rules keep their ids; evidence rules (first-
    line baseline, footer reverse wrap, divider placement, static cursor,
    overlay z-order via renderer hit-test probes, text truncation) report
    missing evidence instead of skipping, and concentric radii reject
    negative and step-limited radii. Old snapshots still load.
  - test-db-harness / affine-test-env: a marker-checked PostgreSQL test
    cluster (explicit URL or a reused machine-wide pgvector container),
    read-only migration-digest templates with Prisma bookkeeping,
    template clones under owner-token leases, and an orphan reaper. Clone,
    heartbeat, release and reap serialize per database on an advisory
    lock and re-check under it; every maintenance connection re-checks
    the cluster marker. Private Redis or a prefix-isolated URL. Images
    pinned to multi-arch digests; only private harness containers of the
    expected run, by full id, can be removed. run.json reports.
- scripts/ci/check-l0-tier-a.mjs: dependency-free gates for crates/
  layering and hygiene, a waitForTimeout/.skip ratchet with per-file
  ceilings, workflow references, pinned test images and .gitignore.
- native-playground.yml: resolve the change base to a commit SHA, call
  np-web-fast.yml (lint, typecheck, Node-only Vitest projects without
  Electron, browser or Rust-binary dependencies) when web sources
  change, and always run L0, the frozen server contract checks, crates/
  and the parity harness (fmt, clippy, tests against real services).
- Web lint and format: the frozen contract artifacts and
  blocksuite/native-playground (checked by its own lane) are ignored via
  .prettierignore, from which .oxlintrc.json is generated; the server
  contract and parity harness scripts are formatted and lint-clean.
- tools/parity-harness/rustfmt.toml keeps the default style there.
- Remove the copilot cron workflows and the skipped migration spec;
  ignore test-results/ and .artifacts/.
2026-11-23 13:58:04 +09:00

51 lines
1.5 KiB
JavaScript

import { createServer } from 'node:http';
import { workspaceRequire } from './socketio-driver.mjs';
const require = workspaceRequire();
const { Server } = require('socket.io');
const server = createServer((req, res) => {
res.setHeader('content-type', 'application/json');
if (req.url === '/login')
res.setHeader(
'set-cookie',
'sid=reference-session; Path=/; HttpOnly; SameSite=Lax'
);
res.end(JSON.stringify({ ok: true }));
});
const io = new Server(server, {
pingInterval: 15,
pingTimeout: 300,
transports: ['polling', 'websocket'],
});
io.use((socket, next) => {
if (socket.handshake.auth.reject) {
const error = new Error(
process.env.PARITY_REFERENCE_AUTH_MESSAGE ?? 'AuthenticationRequired'
);
error.data = { code: 'AUTHENTICATION_REQUIRED', status: 401 };
next(error);
} else next();
});
io.on('connection', socket => {
socket.emit('ready', {
cookie: socket.handshake.headers.cookie ?? null,
header: socket.handshake.headers['x-parity'] ?? null,
});
socket.on('echo', (payload, ack) => {
socket.emit('binary-push', { bytes: Buffer.from([0, 1, 2, 255]), payload });
ack({
payload,
bytes: Buffer.from([3, 4, 255]),
cookie: socket.handshake.headers.cookie ?? null,
});
});
socket.on('delayed', (payload, ack) =>
setTimeout(() => ack({ payload, alive: socket.connected }), 80)
);
});
server.listen(0, '127.0.0.1', () =>
process.stdout.write(
JSON.stringify({ url: `http://127.0.0.1:${server.address().port}` }) + '\n'
)
);