A static hermeticity auditor for MoonBit tests.
git clone https://github.com/kobe108/moonhermetic
cd moonhermetic
moon check
moon test
moon run cmd/main -- . --fail-on warningmoon add kobe108/moonhermeticmoon run cmd/main -- initmoon run cmd/main -- init subproject \
--config config/moonhermetic.json \
--baseline config/moonhermetic-baseline.jsonexamples/risky/checkout_test.mbt:20:18: error [HERM-NET] External network dependency
evidence: let response = fetch(endpoint)
fix: Use a fake transport or a deterministic local fixture instead of a live service.
MoonHermetic scanned 2 test file(s): 3 finding(s), 2 error(s), 1 warning(s).moonhermetic [options] [file-or-directory ...]
moonhermetic init [path] [options]
moonhermetic doctor [path] [options]
-f, --format <text|json|markdown|sarif>
--fail-on <never|warning|error>
--config <path>
--no-config
--diff <path>
--audit-suppressions
--fail-on-suppression
--baseline <path>
--write-baseline <path>
--summary-file <path>
--no-reachability
--exclude <text>
--rules
-h, --help
-V, --versiontest: request reads an ambient token
path: request reads an ambient token -> prepare_request -> read_ambient_tokenmoon run cmd/main -- doctor
moon run cmd/main -- doctor --format json --strict{
"version": 1,
"failOn": "error",
"exclude": ["vendor"],
"rules": {
"HERM-NET": "warning",
"HERM-FS": "off",
"HERM-SLEEP": "error"
}
}git diff --unified=0 "$BASE_SHA...HEAD" -- '*.mbt' > moonhermetic.diff
moon run cmd/main -- . --diff moonhermetic.diff --fail-on warningmoon run cmd/main -- . --write-baseline .moonhermetic-baseline.jsonmoon run cmd/main -- . \
--baseline .moonhermetic-baseline.json \
--fail-on warning| Rule | Default severity | Detects |
|---|---|---|
| HERM-CLOCK | warning | Wall-clock or local-time reads |
| HERM-RAND | warning | Randomness without an explicit seed |
| HERM-ENV | warning | Ambient process environment reads |
| HERM-NET | error | Live network or socket dependencies |
| HERM-PROC | warning | Child processes and shell execution |
| HERM-FS | warning | Files outside a managed fixture |
| HERM-SLEEP | error | Sleep- or elapsed-time-based synchronization |
sleep(20) // hermetic:ignore: timing service must expire the leasefetch("https://example.test") // hermetic:ignore HERM-NET owner=kobe108 expires=2026-12-31
sleep(10) // hermetic:ignore HERM-SLEEP,HERM-CLOCK owner=kobe108 expires=2026-12-31moon run cmd/main -- . --audit-suppressions
moon run cmd/main -- . --audit-suppressions --format jsonmoon run cmd/main -- . --fail-on-suppressionpermissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@v5
- name: MoonHermetic
id: hermetic
uses: kobe108/moonhermetic@v0.16.1
with:
path: .
format: sarif
fail-on: error
- name: Upload SARIF
if: always()
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: ${{ steps.hermetic.outputs.report-path }}moon run cmd/main -- . --summary-file moonhermetic-summary.md- name: Hermeticity audit
env:
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}
run: |
git diff --unified=0 "$BASE_SHA" "$GITHUB_SHA" -- '*.mbt' > moonhermetic.diff
moon run cmd/main -- . --diff moonhermetic.diff \
--format sarif \
--fail-on error > moonhermetic.sarif
- name: Upload SARIF
if: always()
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: moonhermetic.sarif
- name: Suppression governance
run: moon run cmd/main -- . --exclude examples --fail-on-suppressionlet findings = @moonhermetic.scan_source_with_options_and_date(
"billing_test.mbt",
source,
@moonhermetic.default_scan_options(),
"2026-11-05",
)
let report = @moonhermetic.make_report(1, findings)
println(@moonhermetic.render_markdown(report))
let audits = @moonhermetic.audit_suppressions(
"billing_test.mbt",
source,
"2026-11-05",
)
let governance = @moonhermetic.make_suppression_audit_report(
1,
"2026-11-05",
audits,
)
println(@moonhermetic.render_suppression_audit_json(governance))moon fmt
moon check
moon test
moon info
node --test tests/action-runner.test.mjspwsh scripts/run-precision.ps1pub(all) struct Baseline {
created_on : String
created_with : String
entries : Array[BaselineEntry]
}pub(all) struct BaselineEntry {
fingerprint : String
rule_id : String
path : String
evidence : String
count : Int
}pub(all) enum RuleKind {
Clock
Random
Environment
Network
Process
Filesystem
Sleep
}pub(all) enum Severity {
Warning
Error
}pub(all) struct SuppressionAudit {
path : String
line : Int
column : Int
directive : String
rules : Array[String]
owner : String?
expires : String?
reason : String?
status : SuppressionStatus
message : String
}pub(all) struct SuppressionAuditReport {
scanned_files : Int
today : String
audits : Array[SuppressionAudit]
}pub(all) enum SuppressionStatus {
Active
ExpiringSoon
Expired
Legacy
Invalid
}impl Eq for SuppressionStatusfn filter_with_baseline(findings : Array[Finding], baseline : Baseline, root : String) -> BaselineFilterResultfn make_baseline_report(scanned_files : Int, findings : Array[Finding], filtered_out : Int, baseline_suppressed : Int, baseline_stale : Int, baseline_path : String) -> ScanReportfn make_filtered_report(scanned_files : Int, findings : Array[Finding], filtered_out : Int) -> ScanReportfn make_suppression_audit_report(scanned_files : Int, today : String, audits : Array[SuppressionAudit]) -> SuppressionAuditReportfn rule_catalog_markdown() -> Stringfn scan_source_semantically_with_options_and_date(path : String, source : String, options : ScanOptions, today : String) -> Array[Finding]fn scan_source_with_options(path : String, source : String, options : ScanOptions) -> Array[Finding]fn scan_source_with_options_and_date(path : String, source : String, options : ScanOptions, today : String) -> Array[Finding]fn scan_sources_semantically_with_options_and_date(sources : Array[(String, String)], options : ScanOptions, today : String) -> Array[Finding]Install
Download zipA static hermeticity auditor for MoonBit tests.