mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-22 15:07:38 +08: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.
60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
/**
|
|
* Merge the per-platform SDK coverage shards written by the puter.js API
|
|
* test runners (src/puter-js/coverage/shards/coverage-<platform>.json)
|
|
* into the final reports in src/puter-js/coverage:
|
|
*
|
|
* coverage-final.json / coverage-summary.json — consumed by the PR
|
|
* coverage comment action (same files the backend coverage job emits),
|
|
* lcov.info for external tooling, text (and html locally) for humans.
|
|
*
|
|
* Run via `npm run test:puterjs:coverage`, which builds the instrumented
|
|
* bundle, runs all three runners with PUTER_COVERAGE=1, then this script.
|
|
*/
|
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import libCoverage from 'istanbul-lib-coverage';
|
|
import libReport from 'istanbul-lib-report';
|
|
import reports from 'istanbul-reports';
|
|
|
|
const repoRoot = path.resolve(
|
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
'..',
|
|
);
|
|
const coverageDir = path.join(repoRoot, 'src/puter-js/coverage');
|
|
const shardsDir = path.join(coverageDir, 'shards');
|
|
|
|
const shardFiles = existsSync(shardsDir)
|
|
? readdirSync(shardsDir).filter((f) => f.endsWith('.json'))
|
|
: [];
|
|
if (shardFiles.length === 0) {
|
|
console.error(
|
|
`No coverage shards found in ${shardsDir}.\n` +
|
|
'Run the suites in coverage mode first: npm run test:puterjs:coverage',
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
const coverageMap = libCoverage.createCoverageMap({});
|
|
for (const file of shardFiles) {
|
|
coverageMap.merge(
|
|
JSON.parse(readFileSync(path.join(shardsDir, file), 'utf8')),
|
|
);
|
|
}
|
|
|
|
const context = libReport.createContext({
|
|
dir: coverageDir,
|
|
coverageMap,
|
|
});
|
|
|
|
const isCi = process.env.CI === 'true';
|
|
const reporters = ['json', 'json-summary', 'lcov', 'text'];
|
|
if (!isCi) reporters.push('html');
|
|
for (const reporter of reporters) {
|
|
reports.create(reporter).execute(context);
|
|
}
|
|
|
|
// One per runner and one per unit test file.
|
|
console.log(`\nMerged ${shardFiles.length} shard(s).`);
|
|
console.log(`Reports written to ${coverageDir}`);
|