@iyowei/rim 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +74 -2
- package/README.zh-CN.md +75 -0
- package/dist/baseline.d.ts +47 -0
- package/dist/bridge-command.d.ts +25 -0
- package/dist/bridge.d.ts +18 -0
- package/dist/cdp.d.ts +41 -0
- package/dist/chrome.d.ts +51 -0
- package/dist/config-validate-sections.d.ts +18 -0
- package/dist/config-validate.d.ts +4 -0
- package/dist/config.d.ts +27 -0
- package/dist/doctor.d.ts +15 -0
- package/dist/errors.d.ts +10 -0
- package/dist/gate-pipeline.d.ts +34 -0
- package/dist/gate.d.ts +3 -0
- package/dist/html-report.d.ts +14 -0
- package/dist/html-scan.d.ts +32 -0
- package/dist/http-gate.d.ts +11 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +10234 -0
- package/dist/lighthouse-extract.d.ts +20 -0
- package/dist/lighthouse-gate.d.ts +35 -0
- package/dist/locale.d.ts +14 -0
- package/dist/manifest.json +8 -0
- package/dist/probe-h2h3.d.ts +39 -0
- package/dist/probe-load-adapters.d.ts +38 -0
- package/dist/probe-load-builtin.d.ts +16 -0
- package/dist/probe-load-h2.d.ts +41 -0
- package/dist/probe-load.d.ts +28 -0
- package/dist/probe-perf.d.ts +36 -0
- package/dist/probe-proto-checks.d.ts +58 -0
- package/dist/probe-proto-helpers.d.ts +77 -0
- package/dist/probe-proto.d.ts +55 -0
- package/dist/probe-quality-adapters.d.ts +42 -0
- package/dist/probe-quality-axe.d.ts +57 -0
- package/dist/probe-quality-link-eval.d.ts +46 -0
- package/dist/probe-quality-links.d.ts +23 -0
- package/dist/probe-quality.d.ts +53 -0
- package/dist/probe-sec-csp.d.ts +21 -0
- package/dist/probe-sec-testssl.d.ts +22 -0
- package/dist/probe-sec-tls-eval.d.ts +34 -0
- package/dist/probe-sec-tls.d.ts +18 -0
- package/dist/probe-sec.d.ts +42 -0
- package/dist/runtime.d.ts +45 -0
- package/dist/security-ip.d.ts +42 -0
- package/dist/security.d.ts +43 -0
- package/dist/smoke-gate.d.ts +14 -0
- package/dist/static-server.d.ts +19 -0
- package/dist/types-config.d.ts +339 -0
- package/dist/types.d.ts +352 -0
- package/dist/verdict-lighthouse.d.ts +14 -0
- package/dist/verdict.d.ts +21 -0
- package/dist/waivers.d.ts +10 -0
- package/package.json +66 -4
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { LighthousePreset, LighthousePresetSummary, WaiverRule } from './types.js';
|
|
2
|
+
export declare const LIGHTHOUSE_CATEGORIES: readonly ['performance', 'accessibility', 'best-practices', 'seo'];
|
|
3
|
+
/** 构造 Mobile / Desktop 档位 Lighthouse 配置 (纯函数) */
|
|
4
|
+
export declare function buildLighthouseConfig(preset: LighthousePreset, cpuSlowdown: number | null): Record<string, unknown>;
|
|
5
|
+
/** 将路由路径规整为安全报告文件名前缀片段 (如 '/en' -> 'en', '/bridge/' -> 'bridge') */
|
|
6
|
+
export declare function toRouteReportSlug(route: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* 单趟轻量提取 Lighthouse LHR 摘要 (纯函数, 0 深拷贝)。
|
|
9
|
+
* 严格保留缺失类别得分为 `null`, 确保 `--strict` 绝不会把缺失得分误判为通过。
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractLighthouseSummary(input: {
|
|
12
|
+
lhr: Record<string, unknown>;
|
|
13
|
+
preset: LighthousePreset;
|
|
14
|
+
route?: string;
|
|
15
|
+
url?: string;
|
|
16
|
+
elapsedMs: number;
|
|
17
|
+
htmlPath?: string;
|
|
18
|
+
jsonPath?: string;
|
|
19
|
+
waivers?: readonly WaiverRule[];
|
|
20
|
+
}): LighthousePresetSummary;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { buildLighthouseConfig, extractLighthouseSummary, toRouteReportSlug } from './lighthouse-extract.js';
|
|
2
|
+
import { type RimLocale } from './locale.js';
|
|
3
|
+
import type { LighthousePreset, LighthousePresetSummary, LighthouseRunnerInput, LighthouseRunnerOutput, WaiverRule } from './types.js';
|
|
4
|
+
export { buildLighthouseConfig, extractLighthouseSummary, toRouteReportSlug };
|
|
5
|
+
type ProgrammaticLighthouseFn = (url: string, flags?: Record<string, unknown>, config?: Record<string, unknown>) => Promise<{
|
|
6
|
+
lhr: Record<string, unknown>;
|
|
7
|
+
report: string | string[];
|
|
8
|
+
} | undefined>;
|
|
9
|
+
/** 探测内置/项目可编程 lighthouse 包版本与落盘路径 (供 `rim doctor` 只读体检) */
|
|
10
|
+
export declare function probeLighthousePackage(cwd?: string): {
|
|
11
|
+
available: boolean;
|
|
12
|
+
version: string | null;
|
|
13
|
+
resolvedPath: string | null;
|
|
14
|
+
error?: string;
|
|
15
|
+
};
|
|
16
|
+
/** 懒加载并缓存官方可编程 `lighthouse` 模块 (同进程多档位仅加载 1 次) */
|
|
17
|
+
export declare function loadLighthouseFn(cwd: string, locale: RimLocale): Promise<ProgrammaticLighthouseFn>;
|
|
18
|
+
/** 默认进程内可编程 Lighthouse 执行器 */
|
|
19
|
+
export declare function defaultLighthouseRunner(input: LighthouseRunnerInput, cwd: string): Promise<LighthouseRunnerOutput>;
|
|
20
|
+
/** 执行单个档位 Lighthouse 审计并按需写入 HTML/JSON 报告 */
|
|
21
|
+
export declare function runLighthousePresetAudit(options: {
|
|
22
|
+
url: string;
|
|
23
|
+
route?: string;
|
|
24
|
+
multiRoute?: boolean;
|
|
25
|
+
port: number;
|
|
26
|
+
preset: LighthousePreset;
|
|
27
|
+
cpuSlowdown: number | null;
|
|
28
|
+
outDir: string;
|
|
29
|
+
writeReports: boolean;
|
|
30
|
+
cwd: string;
|
|
31
|
+
locale: RimLocale;
|
|
32
|
+
waivers?: readonly WaiverRule[];
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
runner?: (input: LighthouseRunnerInput) => Promise<LighthouseRunnerOutput>;
|
|
35
|
+
}): Promise<LighthousePresetSummary>;
|
package/dist/locale.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@iyowei/rim` 零依赖原生双语原语与强终端/控制序列净化 (对齐 ADR 0031)。
|
|
3
|
+
* 剥离 7-bit ESC (CSI / OSC / DCS / APC / PM / SOS)、8-bit C1 控制序列与双向文本覆写符。
|
|
4
|
+
*/
|
|
5
|
+
export type RimLocale = 'zh' | 'en';
|
|
6
|
+
/** 规范化语言标记, 缺省回退中文 */
|
|
7
|
+
export declare function pickLocale(locale?: RimLocale): RimLocale;
|
|
8
|
+
/** 轻量双语文本选择 */
|
|
9
|
+
export declare function rimT(locale: RimLocale | undefined, zh: string, en: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* 剥离 ANSI/OSC/DCS/APC/PM/SOS、8-bit C1 控制序列、不可见控制字符与 Bidi 覆写符,
|
|
12
|
+
* 防止恶意站点响应头/页面日志注入终端转义或欺骗输出 (纯可见文本走零分配快路径)。
|
|
13
|
+
*/
|
|
14
|
+
export declare function sanitizeLine(input: string): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
import type { ChromeSession } from './types.js';
|
|
3
|
+
export interface ProtocolRunStats {
|
|
4
|
+
readonly mode: 'h2' | 'h3';
|
|
5
|
+
readonly completed: boolean;
|
|
6
|
+
readonly durationMs: number;
|
|
7
|
+
readonly totalRequests: number;
|
|
8
|
+
readonly finishedCount: number;
|
|
9
|
+
readonly failedCount: number;
|
|
10
|
+
readonly stalledCount: number;
|
|
11
|
+
readonly totalEncodedBytes: number;
|
|
12
|
+
readonly protocols: readonly string[];
|
|
13
|
+
readonly mainProtocol: string | null;
|
|
14
|
+
readonly failedSamples: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
export interface H2H3ComparisonResult {
|
|
17
|
+
readonly status: 'PASS' | 'WARN' | 'FAIL' | 'SKIP';
|
|
18
|
+
readonly reason?: string;
|
|
19
|
+
readonly h2?: ProtocolRunStats;
|
|
20
|
+
readonly h3?: ProtocolRunStats;
|
|
21
|
+
readonly h3Negotiated?: boolean;
|
|
22
|
+
readonly mtuBlackholeSuspected?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** 对比目标 HTTPS 站点的 HTTP/2 与 HTTP/3 (QUIC) 全资产加载表现并检测路径 MTU 黑洞 */
|
|
25
|
+
export declare function runH2H3MtuProbe(options: {
|
|
26
|
+
readonly targetUrl: string;
|
|
27
|
+
readonly chromePath: string | null;
|
|
28
|
+
readonly timeoutMs?: number;
|
|
29
|
+
readonly locale: RimLocale;
|
|
30
|
+
readonly signal?: AbortSignal;
|
|
31
|
+
readonly launchChromeFn?: (opts: {
|
|
32
|
+
chromePath: string;
|
|
33
|
+
coldGpu: boolean;
|
|
34
|
+
timeoutMs: number;
|
|
35
|
+
locale: RimLocale;
|
|
36
|
+
extraFlags?: readonly string[];
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
}) => Promise<ChromeSession>;
|
|
39
|
+
}): Promise<H2H3ComparisonResult>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { RimLocale } from './locale.js';
|
|
2
|
+
export interface LoadLatencyStats {
|
|
3
|
+
readonly minMs: number;
|
|
4
|
+
readonly p50Ms: number;
|
|
5
|
+
readonly p95Ms: number;
|
|
6
|
+
readonly p99Ms: number;
|
|
7
|
+
readonly maxMs: number;
|
|
8
|
+
}
|
|
9
|
+
export interface LoadRunMetrics {
|
|
10
|
+
readonly totalRequests: number;
|
|
11
|
+
readonly successCount: number;
|
|
12
|
+
readonly errorCount: number;
|
|
13
|
+
readonly rps: number;
|
|
14
|
+
readonly latency: LoadLatencyStats;
|
|
15
|
+
readonly statusCounts: Record<string, number>;
|
|
16
|
+
}
|
|
17
|
+
/** 解析 `h2load` 文本输出为统一压测结果 (纯函数, 便于单测校验) */
|
|
18
|
+
export declare function parseH2loadOutput(stdout: string): LoadRunMetrics | null;
|
|
19
|
+
/** 运行绝对 PATH 下的 `oha` 受控压测适配器 */
|
|
20
|
+
export declare function runOhaAdapter(options: {
|
|
21
|
+
readonly binPath: string;
|
|
22
|
+
readonly targetUrl: string;
|
|
23
|
+
readonly concurrency: number;
|
|
24
|
+
readonly maxRequests: number;
|
|
25
|
+
readonly timeoutMs: number;
|
|
26
|
+
readonly locale: RimLocale;
|
|
27
|
+
readonly signal?: AbortSignal;
|
|
28
|
+
}): Promise<LoadRunMetrics | null>;
|
|
29
|
+
/** 运行绝对 PATH 下的 `h2load` 受控压测适配器 */
|
|
30
|
+
export declare function runH2loadAdapter(options: {
|
|
31
|
+
readonly binPath: string;
|
|
32
|
+
readonly targetUrl: string;
|
|
33
|
+
readonly concurrency: number;
|
|
34
|
+
readonly maxRequests: number;
|
|
35
|
+
readonly timeoutMs: number;
|
|
36
|
+
readonly locale: RimLocale;
|
|
37
|
+
readonly signal?: AbortSignal;
|
|
38
|
+
}): Promise<LoadRunMetrics | null>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
import { type BuiltinLoadOutcome, computeLatencyStats, probeHttpsAlpn } from './probe-load-h2.js';
|
|
3
|
+
import type { ResolvedHostPin } from './security.js';
|
|
4
|
+
export { type BuiltinLoadOutcome, computeLatencyStats, probeHttpsAlpn };
|
|
5
|
+
/** 执行内置自动协商 HTTP/2 多路复用 + HTTP/1.1 Keep-Alive 连接池压测 */
|
|
6
|
+
export declare function runBuiltinPooledLoad(options: {
|
|
7
|
+
readonly targetUrl: string;
|
|
8
|
+
readonly pin: ResolvedHostPin;
|
|
9
|
+
readonly concurrency: number;
|
|
10
|
+
readonly durationMs: number;
|
|
11
|
+
readonly maxRequests: number;
|
|
12
|
+
readonly preferProtocol?: 'auto' | 'h2' | 'h1';
|
|
13
|
+
readonly ca?: string | Buffer;
|
|
14
|
+
readonly locale: RimLocale;
|
|
15
|
+
readonly signal?: AbortSignal;
|
|
16
|
+
}): Promise<BuiltinLoadOutcome>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
import type { LoadLatencyStats, LoadRunMetrics } from './probe-load-adapters.js';
|
|
3
|
+
import type { ResolvedHostPin } from './security.js';
|
|
4
|
+
export declare const MAX_LOAD_WIRE_BYTES: number;
|
|
5
|
+
export interface BuiltinLoadOutcome extends LoadRunMetrics {
|
|
6
|
+
readonly runnerUsed: 'builtin-h2' | 'builtin-h1';
|
|
7
|
+
readonly protocol: 'h2' | 'http/1.1';
|
|
8
|
+
readonly elapsedMs: number;
|
|
9
|
+
readonly ttfbLatency: LoadLatencyStats;
|
|
10
|
+
readonly totalBytes: number;
|
|
11
|
+
readonly throughputBytesPerSec: number;
|
|
12
|
+
}
|
|
13
|
+
export interface SingleLoadSample {
|
|
14
|
+
readonly status: number;
|
|
15
|
+
readonly ok: boolean;
|
|
16
|
+
readonly ttfbMs: number;
|
|
17
|
+
readonly totalMs: number;
|
|
18
|
+
readonly bytes: number;
|
|
19
|
+
}
|
|
20
|
+
/** 计算排序延迟样本的最小/中位/p95/p99/最大毫秒值 (纯函数) */
|
|
21
|
+
export declare function computeLatencyStats(samplesMs: readonly number[]): LoadLatencyStats;
|
|
22
|
+
export declare function resolveLoadPort(parsedUrl: URL): number;
|
|
23
|
+
/** 通过 SSRF IP 钉选 TLS 握手探测服务端是否协商 HTTP/2 (`h2`) ALPN */
|
|
24
|
+
export declare function probeHttpsAlpn(options: {
|
|
25
|
+
readonly pin: ResolvedHostPin;
|
|
26
|
+
readonly parsedUrl: URL;
|
|
27
|
+
readonly ca?: string | Buffer;
|
|
28
|
+
readonly timeoutMs: number;
|
|
29
|
+
readonly signal?: AbortSignal;
|
|
30
|
+
}): Promise<string | null>;
|
|
31
|
+
/** 运行池化 `node:http2` 并发多路复用受控压测 */
|
|
32
|
+
export declare function runBuiltinH2Load(options: {
|
|
33
|
+
readonly parsedUrl: URL;
|
|
34
|
+
readonly pin: ResolvedHostPin;
|
|
35
|
+
readonly concurrency: number;
|
|
36
|
+
readonly durationMs: number;
|
|
37
|
+
readonly maxRequests: number;
|
|
38
|
+
readonly ca?: string | Buffer;
|
|
39
|
+
readonly locale: RimLocale;
|
|
40
|
+
readonly signal?: AbortSignal;
|
|
41
|
+
}): Promise<BuiltinLoadOutcome | null>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
import { type LoadLatencyStats, parseH2loadOutput } from './probe-load-adapters.js';
|
|
3
|
+
import type { LoadProbeConfig, ProbeResult, WaiverRule } from './types.js';
|
|
4
|
+
export { type LoadLatencyStats, parseH2loadOutput };
|
|
5
|
+
/** 硬编码并发安全上限 */
|
|
6
|
+
export declare const MAX_LOAD_CONCURRENCY = 20;
|
|
7
|
+
/** 硬编码压测时长安全上限 (15s) */
|
|
8
|
+
export declare const MAX_LOAD_DURATION_MS = 15000;
|
|
9
|
+
/** 硬编码总请求数安全上限 */
|
|
10
|
+
export declare const MAX_LOAD_REQUESTS = 500;
|
|
11
|
+
/** 计算排序延迟样本的最小/中位/p95/p99/最大毫秒值 (纯函数) */
|
|
12
|
+
export declare function computeLatencyPercentiles(samplesMs: readonly number[]): LoadLatencyStats;
|
|
13
|
+
/** 运行受控短时并发压测探针 (`load`) */
|
|
14
|
+
export declare function runLoadProbe(options: {
|
|
15
|
+
readonly targetUrl: string;
|
|
16
|
+
readonly allowLoad: boolean;
|
|
17
|
+
readonly loadConfig?: LoadProbeConfig;
|
|
18
|
+
readonly waivers?: readonly WaiverRule[];
|
|
19
|
+
readonly timeoutMs: number;
|
|
20
|
+
readonly locale: RimLocale;
|
|
21
|
+
readonly signal?: AbortSignal;
|
|
22
|
+
readonly fetchFn?: typeof fetch;
|
|
23
|
+
readonly lookupFn?: (hostname: string) => Promise<ReadonlyArray<{
|
|
24
|
+
readonly address: string;
|
|
25
|
+
readonly family: number;
|
|
26
|
+
}>>;
|
|
27
|
+
readonly resolveAdapterBin?: (names: readonly string[]) => string | null;
|
|
28
|
+
}): Promise<ProbeResult>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
import type { ChromeSession, DeviceMode, LighthousePresetSummary, LighthouseRunnerInput, LighthouseRunnerOutput, LighthouseThresholds, PerfRunnerAdapter, ProbeResult, RunRimOptions, WaiverRule } from './types.js';
|
|
3
|
+
export interface PerfProbeOutput {
|
|
4
|
+
readonly probe: ProbeResult;
|
|
5
|
+
readonly status: 'pass' | 'warn' | 'fail' | 'skip';
|
|
6
|
+
readonly reason?: string;
|
|
7
|
+
readonly summaries: readonly LighthousePresetSummary[];
|
|
8
|
+
}
|
|
9
|
+
/** 运行统一 `perf` 探针 (跨路由 × 设备档位执行 Lighthouse 或可插拔 PerfRunnerAdapter) */
|
|
10
|
+
export declare function runPerfProbe(options: {
|
|
11
|
+
readonly targetUrl: string;
|
|
12
|
+
readonly routes: readonly string[];
|
|
13
|
+
readonly devices: readonly DeviceMode[];
|
|
14
|
+
readonly projectRoot: string;
|
|
15
|
+
readonly chromePath: string;
|
|
16
|
+
readonly coldGpu: boolean;
|
|
17
|
+
readonly cpuSlowdown: number | null;
|
|
18
|
+
readonly outDir: string;
|
|
19
|
+
readonly writeReports: boolean;
|
|
20
|
+
readonly thresholds: LighthouseThresholds;
|
|
21
|
+
readonly waivers?: readonly WaiverRule[];
|
|
22
|
+
readonly timeoutMs: number;
|
|
23
|
+
readonly locale: RimLocale;
|
|
24
|
+
readonly signal?: AbortSignal;
|
|
25
|
+
readonly onProgress?: RunRimOptions['onProgress'];
|
|
26
|
+
readonly launchChromeFn?: (opts: {
|
|
27
|
+
chromePath: string;
|
|
28
|
+
coldGpu: boolean;
|
|
29
|
+
timeoutMs: number;
|
|
30
|
+
locale: RimLocale;
|
|
31
|
+
extraFlags?: readonly string[];
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
}) => Promise<ChromeSession>;
|
|
34
|
+
readonly lighthouseRunner?: (input: LighthouseRunnerInput) => Promise<LighthouseRunnerOutput>;
|
|
35
|
+
readonly perfAdapter?: PerfRunnerAdapter;
|
|
36
|
+
}): Promise<PerfProbeOutput>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `proto` 探针主响应状态/压缩校验、缓存与 304 验证及 H2/H3 阶段收集器 (`probe-proto-checks.ts`)。
|
|
3
|
+
*/
|
|
4
|
+
import { type RimLocale } from './locale.js';
|
|
5
|
+
import { type H2H3ComparisonResult } from './probe-h2h3.js';
|
|
6
|
+
import { type EncodingSample } from './probe-proto-helpers.js';
|
|
7
|
+
import type { PinnedHttpResponse } from './security.js';
|
|
8
|
+
import type { ChromeSession, HttpGateConfig, ProbeFinding } from './types.js';
|
|
9
|
+
export declare function evaluatePrimaryStatusAndCompression(options: {
|
|
10
|
+
readonly primary: PinnedHttpResponse;
|
|
11
|
+
readonly encodings: Record<'br' | 'gzip' | 'raw', EncodingSample | null>;
|
|
12
|
+
readonly httpCfg: HttpGateConfig;
|
|
13
|
+
readonly pathname: string;
|
|
14
|
+
readonly locale: RimLocale;
|
|
15
|
+
readonly findings: ProbeFinding[];
|
|
16
|
+
}): {
|
|
17
|
+
primaryReasons: string[];
|
|
18
|
+
effectiveEnc: string | null;
|
|
19
|
+
};
|
|
20
|
+
export declare function checkCachingAnd304(options: {
|
|
21
|
+
readonly targetUrl: string;
|
|
22
|
+
readonly primary: PinnedHttpResponse;
|
|
23
|
+
readonly effectiveEnc: string | null;
|
|
24
|
+
readonly allowLoopback: boolean;
|
|
25
|
+
readonly check304: boolean;
|
|
26
|
+
readonly timeoutMs: number;
|
|
27
|
+
readonly locale: RimLocale;
|
|
28
|
+
readonly signal?: AbortSignal;
|
|
29
|
+
readonly fetchFn?: typeof fetch;
|
|
30
|
+
readonly findings: ProbeFinding[];
|
|
31
|
+
}): Promise<{
|
|
32
|
+
vary: string;
|
|
33
|
+
hasVaryAcceptEncoding: boolean;
|
|
34
|
+
etag: string | null;
|
|
35
|
+
lastModified: string | null;
|
|
36
|
+
htmlCacheControl: string | null;
|
|
37
|
+
revalidation304: {
|
|
38
|
+
tested: boolean;
|
|
39
|
+
status: number | null;
|
|
40
|
+
passed: boolean;
|
|
41
|
+
};
|
|
42
|
+
}>;
|
|
43
|
+
export declare function runH2H3Stage(options: {
|
|
44
|
+
readonly targetUrl: string;
|
|
45
|
+
readonly chromePath: string | null;
|
|
46
|
+
readonly timeoutMs: number;
|
|
47
|
+
readonly locale: RimLocale;
|
|
48
|
+
readonly signal?: AbortSignal;
|
|
49
|
+
readonly launchChromeFn?: (opts: {
|
|
50
|
+
chromePath: string;
|
|
51
|
+
coldGpu: boolean;
|
|
52
|
+
timeoutMs: number;
|
|
53
|
+
locale: RimLocale;
|
|
54
|
+
extraFlags?: readonly string[];
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
}) => Promise<ChromeSession>;
|
|
57
|
+
readonly findings: ProbeFinding[];
|
|
58
|
+
}): Promise<H2H3ComparisonResult>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
import { type PinnedHttpResponse } from './security.js';
|
|
3
|
+
import type { BudgetsConfig, HttpGateConfig, HttpRouteProbeResult, ProbeFinding } from './types.js';
|
|
4
|
+
/** QUIC 首趟初始窗口建议上限 (12 KB) */
|
|
5
|
+
export declare const QUIC_FIRST_PACKET_BYTES: number;
|
|
6
|
+
/** TCP IW10 首趟初始窗口建议上限 (~14.6 KB) */
|
|
7
|
+
export declare const TCP_IW10_FIRST_PACKET_BYTES = 14950;
|
|
8
|
+
export interface EncodingSample {
|
|
9
|
+
readonly encodingRequested: 'identity' | 'gzip' | 'br';
|
|
10
|
+
readonly contentEncoding: string | null;
|
|
11
|
+
readonly status: number;
|
|
12
|
+
readonly wireBytes: number;
|
|
13
|
+
readonly ttfbMs: number;
|
|
14
|
+
}
|
|
15
|
+
export interface PreloadAssetMeasure {
|
|
16
|
+
readonly url: string;
|
|
17
|
+
readonly rawHref: string;
|
|
18
|
+
readonly source: 'html' | 'header';
|
|
19
|
+
readonly status: number;
|
|
20
|
+
readonly contentEncoding: string | null;
|
|
21
|
+
readonly wireBytes: number;
|
|
22
|
+
readonly cacheControl: string | null;
|
|
23
|
+
readonly fingerprinted: boolean;
|
|
24
|
+
readonly immutable: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function checkEncodingMatch(actual: string | null, expected: 'br' | 'gzip' | 'any' | undefined): boolean;
|
|
27
|
+
export declare function safeProtoRequest(options: {
|
|
28
|
+
readonly url: string;
|
|
29
|
+
readonly method?: 'GET' | 'HEAD';
|
|
30
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
31
|
+
readonly allowLoopback: boolean;
|
|
32
|
+
readonly followRedirects?: boolean;
|
|
33
|
+
readonly timeoutMs: number;
|
|
34
|
+
readonly readBody?: boolean;
|
|
35
|
+
readonly locale: RimLocale;
|
|
36
|
+
readonly signal?: AbortSignal;
|
|
37
|
+
readonly fetchFn?: typeof fetch;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
ok: true;
|
|
40
|
+
res: PinnedHttpResponse;
|
|
41
|
+
} | {
|
|
42
|
+
ok: false;
|
|
43
|
+
error: string;
|
|
44
|
+
}>;
|
|
45
|
+
export declare function evaluateFirstPacketBudget(options: {
|
|
46
|
+
readonly htmlBrBytes: number;
|
|
47
|
+
readonly budgets?: BudgetsConfig;
|
|
48
|
+
readonly locale: RimLocale;
|
|
49
|
+
readonly findings: ProbeFinding[];
|
|
50
|
+
}): void;
|
|
51
|
+
export declare function measurePreloadedAssets(options: {
|
|
52
|
+
readonly primaryHtml: string;
|
|
53
|
+
readonly finalUrl: string;
|
|
54
|
+
readonly targetOrigin: string;
|
|
55
|
+
readonly linkHeaders: readonly string[];
|
|
56
|
+
readonly allowLoopback: boolean;
|
|
57
|
+
readonly budgets?: BudgetsConfig;
|
|
58
|
+
readonly timeoutMs: number;
|
|
59
|
+
readonly locale: RimLocale;
|
|
60
|
+
readonly signal?: AbortSignal;
|
|
61
|
+
readonly fetchFn?: typeof fetch;
|
|
62
|
+
readonly findings: ProbeFinding[];
|
|
63
|
+
}): Promise<{
|
|
64
|
+
assets: PreloadAssetMeasure[];
|
|
65
|
+
totalCriticalBrBytes: number;
|
|
66
|
+
}>;
|
|
67
|
+
export declare function probeExtraHttpRoutes(options: {
|
|
68
|
+
readonly targetUrl: string;
|
|
69
|
+
readonly targetOrigin: string;
|
|
70
|
+
readonly routes: NonNullable<HttpGateConfig['routes']>;
|
|
71
|
+
readonly allowLoopback: boolean;
|
|
72
|
+
readonly timeoutMs: number;
|
|
73
|
+
readonly locale: RimLocale;
|
|
74
|
+
readonly signal?: AbortSignal;
|
|
75
|
+
readonly fetchFn?: typeof fetch;
|
|
76
|
+
readonly findings: ProbeFinding[];
|
|
77
|
+
}): Promise<HttpRouteProbeResult[]>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `proto` 传输协议、压缩编码、缓存与首包预算统一探针 (`probe-proto.ts`)。
|
|
3
|
+
*/
|
|
4
|
+
import { type RimLocale } from './locale.js';
|
|
5
|
+
import { type EncodingSample, type PreloadAssetMeasure, QUIC_FIRST_PACKET_BYTES, TCP_IW10_FIRST_PACKET_BYTES } from './probe-proto-helpers.js';
|
|
6
|
+
import type { BudgetsConfig, ChromeSession, HttpGateConfig, HttpRouteProbeResult, ProbeResult, ProtoProbeConfig, WaiverRule } from './types.js';
|
|
7
|
+
export { type EncodingSample, type PreloadAssetMeasure, QUIC_FIRST_PACKET_BYTES, TCP_IW10_FIRST_PACKET_BYTES, };
|
|
8
|
+
export interface ProtoProbeOutput {
|
|
9
|
+
readonly probe: ProbeResult;
|
|
10
|
+
readonly primaryHeaders: Readonly<Record<string, string>>;
|
|
11
|
+
readonly primaryHtml: string;
|
|
12
|
+
readonly primaryLinkHeaders: readonly string[];
|
|
13
|
+
readonly routeProbeResults: readonly HttpRouteProbeResult[];
|
|
14
|
+
}
|
|
15
|
+
/** 运行统一 `proto` 探针 (零外部依赖 + 可选 HTTPS CDP H2/H3 对比) */
|
|
16
|
+
export declare function runProtoProbe(options: {
|
|
17
|
+
readonly targetUrl: string;
|
|
18
|
+
readonly allowLoopback: boolean;
|
|
19
|
+
readonly httpConfig?: HttpGateConfig;
|
|
20
|
+
readonly protoConfig?: ProtoProbeConfig;
|
|
21
|
+
readonly budgets?: BudgetsConfig;
|
|
22
|
+
readonly waivers?: readonly WaiverRule[];
|
|
23
|
+
readonly runH2H3?: boolean;
|
|
24
|
+
readonly chromePath?: string | null;
|
|
25
|
+
readonly timeoutMs: number;
|
|
26
|
+
readonly locale: RimLocale;
|
|
27
|
+
readonly signal?: AbortSignal;
|
|
28
|
+
readonly fetchFn?: typeof fetch;
|
|
29
|
+
readonly launchChromeFn?: (opts: {
|
|
30
|
+
chromePath: string;
|
|
31
|
+
coldGpu: boolean;
|
|
32
|
+
timeoutMs: number;
|
|
33
|
+
locale: RimLocale;
|
|
34
|
+
extraFlags?: readonly string[];
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}) => Promise<ChromeSession>;
|
|
37
|
+
}): Promise<ProtoProbeOutput>;
|
|
38
|
+
/** 在无并发浏览器争抢后独立追加 H2/H3 对比阶段至已有 `proto` 探针结果 */
|
|
39
|
+
export declare function attachH2H3ToProtoOutput(options: {
|
|
40
|
+
readonly protoOut: ProtoProbeOutput;
|
|
41
|
+
readonly targetUrl: string;
|
|
42
|
+
readonly chromePath: string | null;
|
|
43
|
+
readonly timeoutMs: number;
|
|
44
|
+
readonly waivers?: readonly WaiverRule[];
|
|
45
|
+
readonly locale: RimLocale;
|
|
46
|
+
readonly signal?: AbortSignal;
|
|
47
|
+
readonly launchChromeFn?: (opts: {
|
|
48
|
+
chromePath: string;
|
|
49
|
+
coldGpu: boolean;
|
|
50
|
+
timeoutMs: number;
|
|
51
|
+
locale: RimLocale;
|
|
52
|
+
extraFlags?: readonly string[];
|
|
53
|
+
signal?: AbortSignal;
|
|
54
|
+
}) => Promise<ChromeSession>;
|
|
55
|
+
}): Promise<ProtoProbeOutput>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
import type { ProbeFinding } from './types.js';
|
|
3
|
+
export declare function runExternalJsonTool(options: {
|
|
4
|
+
readonly binPath: string;
|
|
5
|
+
readonly args: readonly string[];
|
|
6
|
+
readonly timeoutMs: number;
|
|
7
|
+
readonly locale: RimLocale;
|
|
8
|
+
readonly signal?: AbortSignal;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
ok: boolean;
|
|
11
|
+
code: number | null;
|
|
12
|
+
stdout: string;
|
|
13
|
+
stderr: string;
|
|
14
|
+
}>;
|
|
15
|
+
export declare function runExternalAxeCliAdapter(options: {
|
|
16
|
+
readonly axeBin: string;
|
|
17
|
+
readonly targetUrl: string;
|
|
18
|
+
readonly timeoutMs: number;
|
|
19
|
+
readonly locale: RimLocale;
|
|
20
|
+
readonly signal?: AbortSignal;
|
|
21
|
+
readonly findings: ProbeFinding[];
|
|
22
|
+
}): Promise<Record<string, unknown>>;
|
|
23
|
+
export declare function runExternalLycheeAdapter(options: {
|
|
24
|
+
readonly lycheeBin: string;
|
|
25
|
+
readonly targetUrl: string;
|
|
26
|
+
readonly timeoutMs: number;
|
|
27
|
+
readonly locale: RimLocale;
|
|
28
|
+
readonly signal?: AbortSignal;
|
|
29
|
+
readonly findings: ProbeFinding[];
|
|
30
|
+
}): Promise<Record<string, unknown>>;
|
|
31
|
+
/** 执行显式开启的外部质量适配器 (`lychee` / 外部 `axe` CLI) */
|
|
32
|
+
export declare function runOptionalExternalQualityAdapters(options: {
|
|
33
|
+
readonly targetUrl: string;
|
|
34
|
+
readonly runLychee: boolean;
|
|
35
|
+
readonly runExternalAxeCli: boolean;
|
|
36
|
+
readonly resolvedAxeBin?: string | null;
|
|
37
|
+
readonly timeoutMs: number;
|
|
38
|
+
readonly locale: RimLocale;
|
|
39
|
+
readonly signal?: AbortSignal;
|
|
40
|
+
readonly resolveAdapterBin?: (names: readonly string[]) => string | null;
|
|
41
|
+
readonly findings: ProbeFinding[];
|
|
42
|
+
}): Promise<Record<string, unknown>>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { CdpClient } from './cdp.js';
|
|
2
|
+
import { type RimLocale } from './locale.js';
|
|
3
|
+
import type { AxeViolationSummary, BuiltinAxeAuditResult, ChromeSession, ProbeFinding } from './types.js';
|
|
4
|
+
export type { AxeViolationSummary, BuiltinAxeAuditResult };
|
|
5
|
+
/** 将随包 `axe-core` 无障碍审计结果映射为可豁免的 `ProbeFinding[]` */
|
|
6
|
+
export declare function appendBuiltinAxeFindings(axe: BuiltinAxeAuditResult, locale: RimLocale, findings: ProbeFinding[]): void;
|
|
7
|
+
export interface AxeRawPayload {
|
|
8
|
+
readonly version?: unknown;
|
|
9
|
+
readonly violations?: unknown;
|
|
10
|
+
readonly incompleteCount?: unknown;
|
|
11
|
+
readonly passCount?: unknown;
|
|
12
|
+
}
|
|
13
|
+
/** 只读探测内置 `axe-core` 包版本与落盘路径 (供 `rim doctor` 使用) */
|
|
14
|
+
export declare function probeAxePackage(cwd?: string): {
|
|
15
|
+
available: boolean;
|
|
16
|
+
version: string | null;
|
|
17
|
+
resolvedPath: string | null;
|
|
18
|
+
error?: string;
|
|
19
|
+
};
|
|
20
|
+
/** 懒加载并内存缓存随包 `axe-core/axe.min.js` 脚本源码 */
|
|
21
|
+
export declare function loadAxeSource(cwd: string, locale: RimLocale): string;
|
|
22
|
+
/** 纯函数: 将 `axe.run()` 精简原始返回归一化为强类型审计摘要 */
|
|
23
|
+
export declare function parseAxeRawResult(raw: AxeRawPayload | null | undefined, durationMs: number): BuiltinAxeAuditResult;
|
|
24
|
+
/** 在已连接的原生 CDP 会话上注入并执行 `axe-core` 全量无障碍审计 */
|
|
25
|
+
export declare function runAxeOnCdpClient(options: {
|
|
26
|
+
readonly cdp: CdpClient;
|
|
27
|
+
readonly cwd: string;
|
|
28
|
+
readonly axeTags?: readonly string[];
|
|
29
|
+
readonly timeoutMs: number;
|
|
30
|
+
readonly locale: RimLocale;
|
|
31
|
+
readonly signal?: AbortSignal;
|
|
32
|
+
}): Promise<BuiltinAxeAuditResult>;
|
|
33
|
+
/** 独立启动无头 Chrome 执行随包 `axe-core` 审计 (支持离线测试注入 `axeRunner`) */
|
|
34
|
+
export declare function runBuiltinAxeAudit(options: {
|
|
35
|
+
readonly targetUrl: string;
|
|
36
|
+
readonly chromePath: string | null;
|
|
37
|
+
readonly cwd: string;
|
|
38
|
+
readonly axeTags?: readonly string[];
|
|
39
|
+
readonly timeoutMs: number;
|
|
40
|
+
readonly locale: RimLocale;
|
|
41
|
+
readonly signal?: AbortSignal;
|
|
42
|
+
readonly launchChromeFn?: (input: {
|
|
43
|
+
chromePath: string;
|
|
44
|
+
coldGpu: boolean;
|
|
45
|
+
timeoutMs: number;
|
|
46
|
+
locale: RimLocale;
|
|
47
|
+
extraFlags?: readonly string[];
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
}) => Promise<ChromeSession>;
|
|
50
|
+
readonly axeRunner?: (input: {
|
|
51
|
+
targetUrl: string;
|
|
52
|
+
axeTags?: readonly string[];
|
|
53
|
+
timeoutMs: number;
|
|
54
|
+
locale: RimLocale;
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
}) => Promise<BuiltinAxeAuditResult>;
|
|
57
|
+
}): Promise<BuiltinAxeAuditResult>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 链接扫描纯函数分区与结果摘要模块 (`probe-quality-link-eval.ts`)。
|
|
3
|
+
*/
|
|
4
|
+
import type { HtmlScanResult } from './html-scan.js';
|
|
5
|
+
import { type RimLocale } from './locale.js';
|
|
6
|
+
import type { ProbeFinding, QualityProbeConfig } from './types.js';
|
|
7
|
+
export interface LinkCheckRecord {
|
|
8
|
+
readonly url: string;
|
|
9
|
+
readonly kind: string;
|
|
10
|
+
readonly scope: 'same-origin' | 'external';
|
|
11
|
+
readonly status: number;
|
|
12
|
+
readonly redirectHops: number;
|
|
13
|
+
readonly ok: boolean;
|
|
14
|
+
readonly rateLimited?: boolean;
|
|
15
|
+
readonly reason?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SameOriginTarget {
|
|
18
|
+
readonly url: string;
|
|
19
|
+
readonly kind: string;
|
|
20
|
+
readonly hashes: string[];
|
|
21
|
+
}
|
|
22
|
+
export declare function hasDomAnchor(domIds: ReadonlySet<string>, anchor: string): boolean;
|
|
23
|
+
export declare function partitionScannedLinks(options: {
|
|
24
|
+
readonly scan: HtmlScanResult;
|
|
25
|
+
readonly targetUrl: string;
|
|
26
|
+
readonly qualityConfig: QualityProbeConfig;
|
|
27
|
+
readonly seenInPageAnchors: Set<string>;
|
|
28
|
+
readonly brokenAnchors: string[];
|
|
29
|
+
}): {
|
|
30
|
+
sameOriginTargets: SameOriginTarget[];
|
|
31
|
+
externalTargets: Array<{
|
|
32
|
+
url: string;
|
|
33
|
+
kind: string;
|
|
34
|
+
}>;
|
|
35
|
+
};
|
|
36
|
+
export declare function appendLinkSummaries(options: {
|
|
37
|
+
readonly linkChecks: readonly LinkCheckRecord[];
|
|
38
|
+
readonly externalLinkChecks: readonly LinkCheckRecord[];
|
|
39
|
+
readonly brokenAnchors: readonly string[];
|
|
40
|
+
readonly seenInPageAnchorCount: number;
|
|
41
|
+
readonly checkedCrossPageAnchorCount?: number;
|
|
42
|
+
readonly checkLinks: boolean;
|
|
43
|
+
readonly checkAnchors: boolean;
|
|
44
|
+
readonly locale: RimLocale;
|
|
45
|
+
readonly findings: ProbeFinding[];
|
|
46
|
+
}): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type RimLocale } from './locale.js';
|
|
2
|
+
import { runExternalJsonTool } from './probe-quality-adapters.js';
|
|
3
|
+
import { type LinkCheckRecord } from './probe-quality-link-eval.js';
|
|
4
|
+
import type { ProbeFinding, QualityProbeConfig } from './types.js';
|
|
5
|
+
export { type LinkCheckRecord, runExternalJsonTool };
|
|
6
|
+
/** 扫描 HTML 中的页内/跨页锚点、同源资源与可选跨源外链可用性 (零外依内置引擎) */
|
|
7
|
+
export declare function scanAndVerifyHtmlLinks(options: {
|
|
8
|
+
readonly html: string;
|
|
9
|
+
readonly targetUrl: string;
|
|
10
|
+
readonly linkHeaders: readonly string[];
|
|
11
|
+
readonly allowLoopback: boolean;
|
|
12
|
+
readonly qualityConfig: QualityProbeConfig;
|
|
13
|
+
readonly checkExternalLinks?: boolean;
|
|
14
|
+
readonly timeoutMs: number;
|
|
15
|
+
readonly locale: RimLocale;
|
|
16
|
+
readonly signal?: AbortSignal;
|
|
17
|
+
readonly fetchFn?: typeof fetch;
|
|
18
|
+
readonly findings: ProbeFinding[];
|
|
19
|
+
}): Promise<{
|
|
20
|
+
linkChecks: LinkCheckRecord[];
|
|
21
|
+
externalLinkChecks: LinkCheckRecord[];
|
|
22
|
+
brokenAnchors: string[];
|
|
23
|
+
}>;
|