mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-23 14:17:06 +00:00
* feat(bench): backend benchmarks that fail a PR for waterfalled or uncached I/O A scenario runs a request against the in-memory backend and records every SQL, key-value, Redis and object-storage round trip on a modeled clock, then reports round trips per destination, serial stages and modeled latency. tools/bench.mjs runs the scenarios on a base commit and on the head and fails on a regression the pull request description does not accept; benchmarks.yaml runs that on every pull request. Also adds npm run check (lint, type check, related tests and the benchmark comparison for the files a branch changed) and describes the distributed deployment in AGENTS.md. * test(bench): scenarios for fs, kv, auth, apps, permissions, sharing and hosted sites * test(puter-js): count the SDK unit tests in the coverage report Only the bundle the API runners load was instrumented, so the unit tests next to the SDK source never counted. In coverage mode the vitest config now instruments SDK source for them and writes one shard per test file. * test(puter-js): unit tests for ui messaging, dialogs, components, uploads, peer and smaller modules * test(backend): cover fs, permission, app, worker, sharing, broadcast and user edge cases * fix(backend): fs write flags are stored as booleans, app stats weeks are ISO weeks - A write's boolean flags reach the store only once read as booleans; any positive number reads as true. - App open stats grouped by week use ISO 8601 weeks for both the buckets and their labels on every database engine, so the two agree across a year boundary. * fix(puter-js): dialog token source, legacy upload cancel, submenu state, typed-array views - The sign-in dialog takes the token only from the popup it opened, and stops listening when it leaves the page. - Cancelling a legacy upload rejects with `upload_aborted` and no longer runs the `error` callback. - A context menu's submenu stays in step with its parent when the parent item is pressed or the submenu closes itself. - The FileReader polyfill reads a typed-array view through its own offset and length. * ci(bench): benchmark a pull request as merged into its base The comparison ran the branch's own head against the tip of the base branch, so a branch behind its base was charged for (or credited with) what the base gained since. The head side is now the merge commit and the base side its first parent. Shards also get a 15 minute timeout. * test(broadcast): shutdown drain tests send boot's own events first Boot queues cache updates that flush 10 ms later. A test body that started after that flush counted it as its own request, which failed 'bounds a hung flush in onServerShutdown' on a slow runner.
107 lines
3.3 KiB
JavaScript
107 lines
3.3 KiB
JavaScript
#!/usr/bin/env node
|
|
// Runs the checks CI applies to a change, scoped to the files it touched:
|
|
// lint, type check, the tests that import those files, and the benchmark
|
|
// comparison.
|
|
//
|
|
// node tools/check.mjs [<git ref>] [--no-bench]
|
|
//
|
|
// The ref is the commit to compare with (default: the merge base with
|
|
// origin/main). Every step runs even when an earlier one fails; exits 1 if any
|
|
// did.
|
|
|
|
import { spawnSync } from 'node:child_process';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const repoRoot = path.resolve(
|
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
'..',
|
|
);
|
|
const args = process.argv.slice(2);
|
|
const skipBench = args.includes('--no-bench');
|
|
const ref = args.find((arg) => !arg.startsWith('--'));
|
|
|
|
const git = (...gitArgs) => {
|
|
const result = spawnSync('git', gitArgs, {
|
|
cwd: repoRoot,
|
|
encoding: 'utf8',
|
|
});
|
|
if (result.status !== 0) {
|
|
console.error(`git ${gitArgs.join(' ')} failed:\n${result.stderr}`);
|
|
process.exit(2);
|
|
}
|
|
return result.stdout.trim();
|
|
};
|
|
|
|
const base = ref ?? git('merge-base', 'HEAD', 'origin/main');
|
|
// Committed, staged, unstaged and untracked; deleted files have nothing to check.
|
|
const changed = [
|
|
...git('diff', '--name-only', '--diff-filter=ACMR', base).split('\n'),
|
|
...git('ls-files', '--others', '--exclude-standard').split('\n'),
|
|
].filter(Boolean);
|
|
|
|
const backend = changed.filter((file) =>
|
|
/^(src\/backend|extensions)\/.*\.(js|mjs|cjs|ts)$/.test(file),
|
|
);
|
|
const sdk = changed.filter((file) => file.startsWith('src/puter-js/'));
|
|
|
|
const results = [];
|
|
const step = (name, command, commandArgs) => {
|
|
console.log(`\n── ${name} ──`);
|
|
const { status } = spawnSync(command, commandArgs, {
|
|
cwd: repoRoot,
|
|
stdio: 'inherit',
|
|
shell: process.platform === 'win32',
|
|
});
|
|
results.push({ name, ok: status === 0 });
|
|
return status === 0;
|
|
};
|
|
const npx = (name, ...commandArgs) => step(name, 'npx', commandArgs);
|
|
const npm = (name, script) => step(name, 'npm', ['run', script]);
|
|
|
|
// The backend loads the built worker library, and the SDK tests the built SDK.
|
|
const built =
|
|
(backend.length || sdk.length) &&
|
|
npm('extension setup', 'setupExtensions') &&
|
|
npm('SDK and worker library build', 'build:workerLib');
|
|
|
|
if (backend.length) {
|
|
npx('lint', 'eslint', '--no-warn-ignored', ...backend);
|
|
npm('type check', 'typecheck');
|
|
if (built) {
|
|
npx(
|
|
'backend tests that import the changed files',
|
|
'vitest',
|
|
'related',
|
|
...backend,
|
|
'--run',
|
|
'--passWithNoTests',
|
|
'--config',
|
|
'src/backend/vitest.config.ts',
|
|
);
|
|
if (!skipBench) {
|
|
step('benchmarks against the base commit', process.execPath, [
|
|
'tools/bench.mjs',
|
|
'against',
|
|
base,
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (sdk.length) {
|
|
if (built) npm('SDK tests', 'test:puterjs');
|
|
npm('SDK types', 'check:puterjs:types');
|
|
}
|
|
|
|
if (!results.length) {
|
|
console.log('No backend or SDK files changed; nothing to check.');
|
|
process.exit(0);
|
|
}
|
|
|
|
console.log('');
|
|
for (const { name, ok } of results) {
|
|
console.log(`${ok ? 'ok ' : 'FAILED'} ${name}`);
|
|
}
|
|
process.exit(results.every(({ ok }) => ok) ? 0 : 1);
|