downstream-regression

    Compare MoonBit downstream test results across pinned dependency versions

    downstream
    regression
    testing
    dependencies
    cli
    Download zip
    Version
    0.3.0
    License
    Apache-2.0
    Last updated
    33 minutes ago
    Downloads
    10

    #MoonBit 下游依赖回归检查器

    给库维护者一份升级前的下游报告。项目同时提供全目标纯 MoonBit 核心库(Sam-Hui-dot/downstream-regression)与命令行工具(cmd/main)。CLI 用同一个 moon 可执行文件,在两个独立目录分别解析指定依赖和运行 moon test,输出结构化 JSON 报告、人类可读 Markdown 报告(可直接用于 GitHub Actions Step Summary)、离线交互式 HTML 报告(report.html / batch.html)与完整原始日志,并内置原生 .mbti 公共 API 破坏性变更静态比对器(mbti-diff)。

    #安装与快速验证

    #1. 从 Mooncakes 安装 CLI

    moon update moon install Sam-Hui-dot/downstream-regression/cmd/main@0.3.0 main --help

    #2. 作为 MoonBit 库使用(支持 Wasm / WasmGC / JS / Native)

    根包 Sam-Hui-dot/downstream-regression 不依赖进程 IO,可在任意目标上导入使用(用于日志解析、moon tree 依赖漂移核对、moon.mod / moon.mod.json 依赖改写、.mbti 公共 API 破坏性变更静态分析、回归分类以及 Markdown / HTML 报告渲染):

    moon add Sam-Hui-dot/downstream-regression@0.3.0

    let counts = @downstream-regression.parse_test_counts("Total tests: 89, passed: 83, failed: 6.")
    let updated = @downstream-regression.rewrite_manifest_dependency(
    MoonModJson,
    manifest_text,
    "moonbitlang/async",
    "0.21.0",
    "0.22.0",
    )
    let api_diff = @downstream-regression.diff_mbti(old_mbti_text, new_mbti_text)
    let md = @downstream-regression.render_markdown_report(comparison)
    let html = @downstream-regression.render_html_report(comparison)

    #3. 零外部依赖运行自带单元测试

    在仓库根目录直接运行全目标单元测试(不依赖外部下游仓库):

    moon test --target wasm --deny-warn moon test --target wasm-gc --deny-warn moon test --target js --deny-warn moon test --target native --deny-warn

    #CLI 运行

    历史案例复验使用 Moon 0.1.20261104(moonc 0.10.20+65efd5b93)或支持相同命令与输出格式的版本。Windows 下建议给工具指定 moon.exe 和 git.exe 的绝对路径。

    moon run cmd/main --target wasm -- --help moon run cmd/main --target wasm -- snapshot moon git D:/src/moonback ccb19d7 moonback moonbitlang/async 0.21.0 0.22.0 wasm moon run cmd/main --target wasm -- --out ./evidence snapshot moon git D:/src/moonback ccb19d7 moonback moonbitlang/async 0.21.0 0.22.0 wasm

    • snapshot 接受本地 Git 仓库、提交和其中的模块路径(根模块用 .)。工具在隔离目录检出两份相同的已提交源码,自动识别 moon.mod 或 moon.mod.json,仅替换候选目录中唯一匹配的直接依赖版本,并通过 moon tree 核实精确解析结果。
    • 可选参数 --out <DIR> 将证据目录输出到指定路径(未指定时默认写入系统临时目录)。
    • 也可直接传入两个已准备好的模块目录进行对照:

    moon run cmd/main --target wasm -- moon moonbitlang/async D:/cases/moonback-old/moonback 0.21.0 D:/cases/moonback-candidate/moonback 0.22.0 wasm

    参数末尾指定下游测试目标,默认 wasm,可选 wasm、native、wasm-gc、js。CLI 自身支持 wasm 与 native 构建。由于正常的 Moon 构建和测试会执行下游项目代码,应在可信源码上运行。

    #.mbti 公共 API 破坏性变更分析

    mbti-diff 子命令直接解析两份 MoonBit 接口快照文件(pkg.generated.mbti),在运行下游测试之前即可静态识别删除/签名前后不一致的公开函数与方法、类型定义/可见性收窄、结构体字段/枚举构造器变更、trait 实现移除与新增公开符号:

    moon run cmd/main --target wasm -- mbti-diff old.mbti new.mbti --format markdown --fail-on-breaking moon run cmd/main --target wasm -- mbti-diff old.mbti new.mbti --format json --out api-diff.json

    • --format text|markdown|json:默认 text。
    • --fail-on-breaking:检测到破坏性变更(breaking_count > 0)时以退出码 1 退出,适合直接接入 CI 门禁。

    #批量核对

    以多个下游项目组成一份 JSON 清单。repo 以当前工作目录为基准,target 缺省为 wasm。批量模式依次执行每个案例,一个案例出错时记录原因并继续其余案例,最终在证据目录生成 batch.json(含各案例状态、基线/候选测试计数、新增失败数与编译错误数)、可直接写入 $GITHUB_STEP_SUMMARY 的 batch.md 汇总表,以及带即时过滤与状态筛选的离线单页 batch.html。

    moon run cmd/main --target wasm -- --out ./batch-evidence batch moon git examples/historical-plan.json

    示例使用 ../downstream-upgrade-study 中的历史项目。从本仓库根目录运行以下命令可准备源码并核对结果:

    git clone https://github.com/moonbitlang/moonback.git ../downstream-upgrade-study/moonback git clone https://github.com/moonbitlang/moonyacc.git ../downstream-upgrade-study/moonyacc pwsh -NoProfile -File examples/verify-historical.ps1

    #报告与退出码

    • 退出码 0:两轮测试均通过且测试统计可比较(pass)。
    • 退出码 1:新增测试失败(new_test_failure)、既有失败消息变化(failure_changed),或基线通过后候选版出现 MoonBit 编译诊断(candidate_compile_failure)。
    • 退出码 2:既有失败(candidate_failing / baseline_failing)、测试总数或跳过数变化(test_summary_changed)、诊断无法完整解析(baseline_inconclusive / candidate_inconclusive)或工具执行出错。

    单案例证据目录保存 report.json、report.md、report.html、toolchain.txt、baseline-tree.txt、candidate-tree.txt、baseline-test.txt 与 candidate-test.txt。report.json 包含 other_dependency_changes,列出目标依赖之外的解析变化。版本检查、依赖解析和单轮测试的时限分别为 30 秒、60 秒和 10 分钟;单份日志解析上限为 16 MiB,超出时保留完整原始日志并报错。当前以 moon test 的英文输出为输入。

    #历史案例与验证

    在 Windows 上使用 Moon 0.1.20261104 和 Wasm 测试目标,批量 CLI 实测如下(详见 docs/VALIDATION.md):

    下游依赖升级旧版 → 新版CLI 状态
    MoonBack ccb19d7async 0.21.0 → 0.22.089/89 → 83/89new_test_failure,列出 6 项失败
    moonyacc 0adc773async 0.20.3 → 0.22.474/74 → 74/74pass

    MoonBack 的新增失败中,4 项报 TaskCancelled,2 项超时,涉及连接复用、空闲连接取消和连接断开。维护者在 c4b5564 适配了取消语义,同一工具链手工复验修复提交通过 97/97 项测试。

    GitHub Actions 使用带 SHA-256 校验的官方 Windows 历史工具链和标准库,执行格式检查、四目标(Wasm / WasmGC / JS / Native)严格检查与单元测试、独立消费者库导入验证、Wasm 构建、上述两个历史下游用例以及 examples/compile-regression 编译回归检测,并将生成的 batch.md 与 report.md 渲染至 Actions Job Summary。

    StudyError

    pub(all) suberror StudyError {
    InvalidInput(String)
    ToolFailed(String)
    } derive(Eq,
    Debug
    )

    Errors raised for invalid user input or external tool failures.

    StudyError::equal

    fn StudyError::equal(StudyError, StudyError) -> Bool
    automatically derived

    StudyError::not_equal

    fn StudyError::not_equal(x : StudyError, y : StudyError) -> Bool
    automatically derived

    StudyError::to_repr

    automatically derived

    BatchCase

    pub(all) struct BatchCase {
    id : String
    repo : String
    revision : String
    module_dir : String
    dependency : String
    baseline : String
    candidate : String
    target : String
    } derive(Eq,
    Debug
    )

    A validated entry from a batch comparison JSON plan.

    BatchCase::equal

    fn BatchCase::equal(BatchCase, BatchCase) -> Bool
    automatically derived

    BatchCase::not_equal

    fn BatchCase::not_equal(x : BatchCase, y : BatchCase) -> Bool
    automatically derived

    BatchCase::to_repr

    automatically derived

    BatchOutcome

    pub(all) struct BatchOutcome {
    evidence : String
    cases : Array[CaseOutcome]
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Aggregated outcome of a batch comparison run.

    BatchOutcome::equal

    automatically derived

    BatchOutcome::not_equal

    fn BatchOutcome::not_equal(x : BatchOutcome, y : BatchOutcome) -> Bool
    automatically derived

    BatchOutcome::to_json

    automatically derived

    BatchOutcome::to_repr

    automatically derived

    CaseOutcome

    pub(all) struct CaseOutcome {
    id : String
    status : String?
    exit_code : Int
    baseline_counts : TestCounts?
    candidate_counts : TestCounts?
    new_failure_count : Int
    compiler_error_count : Int
    evidence : String
    error : String?
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Summary of a single case inside a batch run.

    CaseOutcome::equal

    fn CaseOutcome::equal(CaseOutcome, CaseOutcome) -> Bool
    automatically derived

    CaseOutcome::not_equal

    fn CaseOutcome::not_equal(x : CaseOutcome, y : CaseOutcome) -> Bool
    automatically derived

    CaseOutcome::to_json

    automatically derived

    CaseOutcome::to_repr

    automatically derived

    Comparison

    pub(all) struct Comparison {
    status : String
    baseline : Trial
    candidate : Trial
    new_failures : Map[String, String]
    fixed_failures : Map[String, String]
    changed_failure_messages : Map[String, String]
    other_dependency_changes : Array[ResolutionChange]
    target : String
    evidence : String
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Structured comparison result between a baseline trial and a candidate trial.

    Comparison::equal

    fn Comparison::equal(Comparison, Comparison) -> Bool
    automatically derived

    Comparison::not_equal

    fn Comparison::not_equal(x : Comparison, y : Comparison) -> Bool
    automatically derived

    Comparison::to_json

    automatically derived

    Comparison::to_repr

    automatically derived

    ManifestKind

    pub(all) enum ManifestKind {
    MoonMod
    MoonModJson
    } derive(Eq,
    Debug
    )

    Supported manifest formats for rewriting direct registry dependencies.

    ManifestKind::equal

    automatically derived

    ManifestKind::not_equal

    fn ManifestKind::not_equal(x : ManifestKind, y : ManifestKind) -> Bool
    automatically derived

    ManifestKind::to_repr

    automatically derived

    MbtiChange

    pub(all) struct MbtiChange {
    severity : String
    category : String
    symbol : String
    detail : String
    baseline : String?
    candidate : String?
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    A single API change entry produced by comparing two .mbti interfaces.

    MbtiChange::equal

    fn MbtiChange::equal(MbtiChange, MbtiChange) -> Bool
    automatically derived

    MbtiChange::not_equal

    fn MbtiChange::not_equal(x : MbtiChange, y : MbtiChange) -> Bool
    automatically derived

    MbtiChange::to_json

    automatically derived

    MbtiChange::to_repr

    automatically derived

    MbtiDiffReport

    pub(all) struct MbtiDiffReport {
    package_name : String
    compatible : Bool
    breaking_count : Int
    additive_count : Int
    changes : Array[MbtiChange]
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Structured static compatibility report between baseline and candidate .mbti interfaces.

    MbtiDiffReport::equal

    automatically derived

    MbtiDiffReport::not_equal

    fn MbtiDiffReport::not_equal(x : MbtiDiffReport, y : MbtiDiffReport) -> Bool
    automatically derived

    MbtiDiffReport::to_json

    automatically derived

    MbtiDiffReport::to_repr

    automatically derived

    MbtiInterface

    pub(all) struct MbtiInterface {
    package_name : String
    values : Map[String, String]
    types : Map[String, MbtiTypeDecl]
    methods : Map[String, String]
    impls : Array[String]
    type_aliases : Map[String, String]
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Parsed representation of a MoonBit pkg.generated.mbti public interface file.

    MbtiInterface::equal

    automatically derived

    MbtiInterface::not_equal

    fn MbtiInterface::not_equal(x : MbtiInterface, y : MbtiInterface) -> Bool
    automatically derived

    MbtiInterface::to_json

    automatically derived

    MbtiInterface::to_repr

    automatically derived

    MbtiTypeDecl

    pub(all) struct MbtiTypeDecl {
    name : String
    kind : String
    visibility : String
    header : String
    members : Array[String]
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Parsed declaration of a MoonBit public type/struct/enum/suberror/trait in a .mbti file.

    MbtiTypeDecl::equal

    automatically derived

    MbtiTypeDecl::not_equal

    fn MbtiTypeDecl::not_equal(x : MbtiTypeDecl, y : MbtiTypeDecl) -> Bool
    automatically derived

    MbtiTypeDecl::to_json

    automatically derived

    MbtiTypeDecl::to_repr

    automatically derived

    ResolutionChange

    pub(all) struct ResolutionChange {
    requested : String
    baseline : Array[String]
    candidate : Array[String]
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    A non-target dependency whose resolved coordinates differed between trials.

    ResolutionChange::equal

    automatically derived

    ResolutionChange::not_equal

    fn ResolutionChange::not_equal(x : ResolutionChange, y : ResolutionChange) -> Bool
    automatically derived

    ResolutionChange::to_json

    automatically derived

    ResolutionChange::to_repr

    automatically derived

    TestCounts

    pub(all) struct TestCounts {
    total : Int
    passed : Int
    failed : Int
    skipped : Int
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Parsed summary counts from a moon test invocation.

    TestCounts::equal

    fn TestCounts::equal(TestCounts, TestCounts) -> Bool
    automatically derived

    TestCounts::not_equal

    fn TestCounts::not_equal(x : TestCounts, y : TestCounts) -> Bool
    automatically derived

    TestCounts::to_json

    automatically derived

    TestCounts::to_repr

    automatically derived

    Trial

    pub(all) struct Trial {
    directory : String
    downstream : String
    dependency : String
    exit_code : Int
    counts : TestCounts?
    failures : Map[String, String]
    compiler_errors : Array[String]
    resolutions : Map[String, Array[String]]
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Observed dependency resolution, exit status, and test outcome for one variant.

    Trial::equal

    fn Trial::equal(Trial, Trial) -> Bool
    automatically derived

    Trial::not_equal

    fn Trial::not_equal(x : Trial, y : Trial) -> Bool
    automatically derived

    Trial::to_json

    automatically derived

    Trial::to_repr

    automatically derived

    compare_trials

    fn compare_trials(baseline : Trial, candidate : Trial, dependency : String, target : String, evidence : String) -> Comparison

    Compare baseline and candidate trials and classify the regression outcome.

    diff_mbti

    fn diff_mbti(baseline_text : String, candidate_text : String) -> MbtiDiffReport

    Statically compare two .mbti public interfaces and classify breaking vs additive API changes.

    diff_resolutions

    fn diff_resolutions(baseline : Map[String, Array[String]], candidate : Map[String, Array[String]], selected_dependency : String) -> Array[ResolutionChange]

    Compute non-target dependency resolution differences between two trials.

    error_message

    fn error_message(error : Error) -> String

    Convert any MoonBit error into a concise human-readable diagnostic message.

    exit_code_for_status

    fn exit_code_for_status(status : String) -> Int

    Map a comparison status string to the CLI exit code (0 pass, 1 regression, 2 inconclusive/error).

    extract_out_option

    fn extract_out_option(args : Array[String]) -> (String?, Array[String]) raise StudyError

    Extract an optional --out <DIR> flag from CLI arguments while preserving positional order.

    is_comparable

    fn is_comparable(trial : Trial) -> Bool

    Return true when a trial's exit code, test counts, and parsed failure map are mutually consistent.

    parse_batch_plan

    fn parse_batch_plan(raw :
    Json
    ) -> Array[BatchCase] raise StudyError

    Parse and validate a batch comparison JSON array into typed BatchCase entries.

    parse_compiler_errors

    fn parse_compiler_errors(log : String) -> Array[String]

    Extract MoonBit compiler diagnostic headers such as Error: [4021].

    parse_dependency_inventory

    fn parse_dependency_inventory(tree : String) -> Map[String, Array[String]]

    Collect all resolved dependency edges from moon tree, normalizing local paths.

    parse_direct_versions

    fn parse_direct_versions(tree : String, dependency : String) -> Array[String]

    List direct top-level resolved edges for a given dependency in moon tree output.

    parse_failure_records

    fn parse_failure_records(log : String) -> Map[String, String]

    Extract failing test records keyed by package / file / test_name.

    parse_mbti

    fn parse_mbti(text : String) -> MbtiInterface

    Parse a MoonBit .mbti interface file into structured values, types, methods, impls, and aliases.

    parse_test_counts

    fn parse_test_counts(log : String) -> TestCounts?

    Parse the final valid Total tests: summary line from a moon test log.

    parse_tree_root

    fn parse_tree_root(tree : String) -> String

    Identify the root module coordinate (name@version) from moon tree output.

    render_batch_html

    fn render_batch_html(outcome : BatchOutcome) -> String

    Render a self-contained offline interactive HTML summary table for a batch regression run.

    render_batch_markdown

    fn render_batch_markdown(outcome : BatchOutcome) -> String

    Render a Markdown summary table for a batch regression run (suitable for CI job summaries).

    render_html_report

    fn render_html_report(report : Comparison, toolchain? : String) -> String

    Render a self-contained offline interactive HTML report for a single downstream comparison.

    render_markdown_report

    fn render_markdown_report(report : Comparison, toolchain? : String) -> String

    Render a deterministic Markdown report for a single downstream comparison.

    render_mbti_diff_markdown

    fn render_mbti_diff_markdown(report : MbtiDiffReport) -> String

    Render an MbtiDiffReport as GitHub-flavored Markdown.

    render_mbti_diff_text

    fn render_mbti_diff_text(report : MbtiDiffReport) -> String

    Render an MbtiDiffReport as compact plain text.

    rewrite_manifest_dependency

    fn rewrite_manifest_dependency(kind : ManifestKind, content : String, dependency : String, baseline_version : String, candidate_version : String) -> String raise StudyError

    Rewrite a pinned direct registry dependency in a moon.mod or moon.mod.json manifest.

    The dependency must match baseline_version exactly once; zero or multiple occurrences raise StudyError::InvalidInput so unrelated lines are never edited.

    strip_ansi

    fn strip_ansi(text : String) -> String

    Strip ANSI CSI escape sequences (such as color codes) from captured tool logs.

    tool_failed

    fn tool_failed(message : String) -> StudyError

    Construct a StudyError::ToolFailed error with a diagnostic message.

    validate_module_dir

    fn validate_module_dir(module_dir : String) -> Unit raise StudyError

    Validate that a snapshot module path is repository-relative and free of traversal components.

    validate_target

    fn validate_target(target : String) -> String raise StudyError

    Validate that a MoonBit test target is one of the supported values.