mirror of
https://github.com/callstack/agent-device.git
synced 2026-09-14 20:06:34 +08:00
e832325e87
* refactor: split generic host mechanics into @agent-device/host-kit (#2082 W1) The shared src/utils closure that blocked the platform-family moves lands on declared owners: generic host mechanics form a new private @agent-device/host-kit package between kernel and capture-kit, and capture-kit keeps capture, snapshot, and recording behavior, depending on host-kit for the mechanics it needs. tar-stream and yauzl move with the archive code. Every seam's exported subpaths are pinned in package-boundaries.test.ts, the layering model ranks the new zone, R13's allow-list names it, and each seam carries an exact eager-closure row. ADR-0019's substrate amendment describes the layout. Tests that mocked two of the moved modules separately became duplicate same-seam vi.mock factories, where the second silently replaced the first; those are merged, and the mocks that production code reaches past are pinned at their injection points instead. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH * refactor(host-kit): one narrow capability port per export The four technical barrels (exec/fs/values/request) grouped by category rather than by capability, so a consumer needing one mechanic evaluated unrelated ones. Each export is now a single capability over the host machine: command, process, diagnostics, retry, archive, file, request, version. A port re-exports only what a consumer of that capability uses, and every port carries its own eager-closure row. Most of the old values barrel was never host mechanics. Pure record readers, config-source values, result text, memoization, async scoping, coordinate validation, and device-scope parsing touch no process, file, or environment, so they join kernel's other primitives instead. Closures fall accordingly: capture-kit's png-worker-client from 20 to 10, png-resize from 28 to 18, session-teardown from 79 to 68, and the CLI from 386 to 380. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH * chore: drop the migration inventories and trim the touched comments Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH * docs: trim the touched host-kit and mutation-lane comments Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH * docs: keep tool directives only in the touched files Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH * docs: keep tool directives only across the touched tree Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH * fix: point the Swift parity comment at the real TS twin and test The W1 move rewrote this citation to packages/contracts/src/mobile-snapshot-semantics.ts, which does not exist: the module went to capture-kit while isTapPointInsideViewport itself went to packages/contracts/src/snapshot-visibility.ts. The TS test line was left pointing at the pre-move path. Both now resolve. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH * fix: repoint comment citations at the homes this refactor moved them to The W1 move left ~20 comment citations pointing at src/utils/*.ts and src/request/*.ts paths that no longer exist. Each now names the capability port that owns the symbol, which survives further file moves: exec -> host-kit/command host-process, owner-identity -> host-kit/process diagnostics -> host-kit/diagnostics atomic-file, process-lock -> host-kit/file retry -> host-kit/retry request progress/cancel -> host-kit/request version -> host-kit/version ttl-memo, source-value, parsing, device-isolation, keyed-lock, success-text -> kernel subpaths Comment-only; no closure, budget, or behavior change. ADR citations are left as written, being dated records of the decision rather than live references. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH --------- Co-authored-by: Claude <noreply@anthropic.com>
107 lines
3.9 KiB
TypeScript
107 lines
3.9 KiB
TypeScript
// Entry point for the changed-line coverage gate (#1418):
|
|
// `pnpm check:coverage-changed [--base <ref>]`.
|
|
//
|
|
// Reuses the lcov report that `pnpm test:coverage` already produced (never runs
|
|
// coverage a second time), joins it with `git diff --unified=0 <base>...HEAD`,
|
|
// and fails when changed-line coverage is below the threshold. A PR carrying
|
|
// the `coverage-waiver` label skips the failure but still prints every number.
|
|
// The same markdown report goes to stdout and to the GitHub job summary; it
|
|
// includes changed-branch coverage and the count of changed executable lines
|
|
// excluded from coverage, both non-gating.
|
|
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { pathToFileURL } from 'node:url';
|
|
import { runCmdSync } from '@agent-device/host-kit/command';
|
|
import { parseScriptArgs } from '../lib/cli-args.ts';
|
|
import {
|
|
computeChangedCoverage,
|
|
parseLcov,
|
|
parseUnifiedDiff,
|
|
type ChangedCoverageResult,
|
|
} from './model.ts';
|
|
|
|
const USAGE = 'Usage: pnpm check:coverage-changed [--base <ref>]\n';
|
|
const LCOV_PATH = 'coverage/lcov.info';
|
|
const GIT_DIFF_MAX_BUFFER_BYTES = 16 * 1024 * 1024;
|
|
|
|
function fmtPct(pct: number | null): string {
|
|
return pct === null ? 'n/a' : `${pct.toFixed(2)}%`;
|
|
}
|
|
|
|
function render(result: ChangedCoverageResult): string {
|
|
const verdict = result.waived
|
|
? 'WAIVED (`coverage-waiver` label)'
|
|
: result.passed
|
|
? 'PASS'
|
|
: 'FAIL';
|
|
const lines = [
|
|
`## Changed-line coverage gate: ${verdict}`,
|
|
'',
|
|
'| Metric | Value |',
|
|
'| --- | --- |',
|
|
`| Changed-line coverage (gating, threshold ${result.threshold}%) | ${result.coveredLines}/${result.totalLines} (${fmtPct(result.pct)}) |`,
|
|
`| Changed-branch coverage (non-gating) | ${result.branch.covered}/${result.branch.total} (${fmtPct(result.branch.pct)}) |`,
|
|
`| Changed executable lines excluded (non-gating) | ${result.excluded.totalLines} |`,
|
|
];
|
|
for (const file of result.excluded.files) {
|
|
lines.push(`- excluded \`${file.path}\` [${file.reason}]: ${file.lines.join(', ')}`);
|
|
}
|
|
if (result.offenders.length > 0) {
|
|
lines.push('', 'Uncovered changed lines:');
|
|
for (const file of result.offenders) {
|
|
lines.push(`- \`${file.path}\`: ${file.uncoveredLines.join(', ')}`);
|
|
}
|
|
}
|
|
return `${lines.join('\n')}\n`;
|
|
}
|
|
|
|
export function run(argv: readonly string[], cwd?: string): number {
|
|
const values = parseScriptArgs(argv, USAGE, {
|
|
base: { type: 'string', default: 'origin/main' },
|
|
});
|
|
const base = values.base ?? 'origin/main';
|
|
// The `coverage-waiver` PR label sets this env var in CI (and locally).
|
|
const waived = /^(1|true)$/i.test(process.env.AGENT_DEVICE_COVERAGE_WAIVER ?? '');
|
|
const root = cwd ?? runCmdSync('git', ['rev-parse', '--show-toplevel']).stdout.trim();
|
|
const lcovPath = path.resolve(root, LCOV_PATH);
|
|
if (!fs.existsSync(lcovPath)) {
|
|
process.stderr.write(
|
|
`check:coverage-changed: no lcov report at ${lcovPath}. Run \`pnpm test:coverage\` first.\n`,
|
|
);
|
|
return 1;
|
|
}
|
|
|
|
const diff = runCmdSync('git', ['diff', '--unified=0', '--no-color', `${base}...HEAD`], {
|
|
cwd: root,
|
|
maxBuffer: GIT_DIFF_MAX_BUFFER_BYTES,
|
|
}).stdout;
|
|
const result = computeChangedCoverage({
|
|
diffs: parseUnifiedDiff(diff),
|
|
coverage: parseLcov(fs.readFileSync(lcovPath, 'utf8'), root),
|
|
waived,
|
|
fileLines: (relPath) => {
|
|
const abs = path.join(root, relPath);
|
|
return fs.existsSync(abs) ? fs.readFileSync(abs, 'utf8').split('\n') : null;
|
|
},
|
|
});
|
|
|
|
const report = render(result);
|
|
process.stdout.write(report);
|
|
const summaryPath = process.env.GITHUB_STEP_SUMMARY;
|
|
if (summaryPath) fs.appendFileSync(summaryPath, report);
|
|
|
|
return result.passed ? 0 : 1;
|
|
}
|
|
|
|
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
try {
|
|
process.exit(run(process.argv.slice(2)));
|
|
} catch (error: unknown) {
|
|
process.stderr.write(
|
|
`check:coverage-changed: ${error instanceof Error ? error.message : String(error)}\n`,
|
|
);
|
|
process.exit(1);
|
|
}
|
|
}
|