Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/PRE_RELEASE_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

The original feature backlog (#47, #48, #54, #55) and the correctness/QA audit fixes (#63-65) are
merged. PRs #68-70 were reviewed and merged on 2026-10-26; the resulting `main` passed CI, security
scanning, and documentation deployment. This checklist tracks the 1.0.0 preparation, not proof that
RubyGems publication has happened. The preceding published gem is 0.0.1.
scanning, and documentation deployment. The 1.0.0 preparation and publication below are historical:
1.0.0 was published and verified in #71. Current main contains unreleased 1.1 development; these
old evidence counts are not the current suite or authorization to publish a new version.

## 1.0.0 preparation

Expand All @@ -29,16 +30,18 @@ refresh, and strict malformed-source diagnostics, plus both dependency-analysis

## Publication remains a separate approval

- [ ] Review and merge the preparation PR, then verify the full matrix on that exact `main` revision:
- [x] Review and merge the preparation PR, then verify the full matrix on that exact `main` revision:
supported Ruby versions, Windows/Linux, library-only coverage, lint, dogfooding, docs, packaging,
installed-gem checks, security, and the downstream RAG fixture.
- [ ] Confirm the changelog date at publication and explicitly authorize the trusted-publisher
- [x] Confirm the changelog date at publication and explicitly authorize the trusted-publisher
`Release` workflow for version `1.0.0` on `main`. Verify the RubyGems account and configured release
environment still belong to the intended maintainers. Never publish merely to run checks.
- [ ] Verify the published 1.0.0 gem and generated tag, install from RubyGems in a clean project,
- [x] Verify the published 1.0.0 gem and generated tag, install from RubyGems in a clean project,
and rerun passing/failing architecture examples before announcing availability.

CLI, richer semantic method/protocol rules, presets, and gradual-adoption baselines remain in #66.
Publication evidence: #71 (registry checksum, tag and clean-project acceptance verified).
CLI execution/diagnostics are now merged (#73, #88). Further baselines, presets, bounded semantic
evaluation and representative Linux performance studies are tracked by #89–92 under #66.
They are not prerequisites for the initial stable API baseline.

## Audit coverage added
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ jobs:
- name: Exercise cache-aware analysis diagnostics
run: bundle exec ruby scripts/check_analysis_diagnostics.rb

- name: Exercise explicit accepted-debt baselines
run: bundle exec ruby scripts/check_baselines.rb

- name: Exercise architecture presets
run: bundle exec ruby scripts/check_presets.rb

quality:
name: Quality and package — Ruby 4.0 on Ubuntu
runs-on: ubuntu-latest
Expand Down Expand Up @@ -164,6 +170,8 @@ jobs:
ruby scripts/check_rails_imports.rb
ruby scripts/check_source_exclusions.rb
ruby scripts/check_analysis_diagnostics.rb
ruby scripts/check_baselines.rb
ruby scripts/check_presets.rb
ruby scripts/check_cli.rb
ruby -e "
require 'json'
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/performance-study.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Representative performance study

on:
workflow_dispatch:
pull_request:
paths:
- 'benchmark/study/**'
- 'benchmark/semantic/**'
- 'spec/benchmark/performance_study_spec.rb'
- '.github/workflows/performance-study.yml'

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
study:
name: Oracle-checked Linux performance evidence
runs-on: ubuntu-latest
timeout-minutes: 15
defaults:
run:
working-directory: archunit/benchmark/study
steps:
- name: Check out candidate
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
path: archunit
persist-credentials: false

- name: Check out pinned Rails application as source only
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: discourse/discourse
ref: 2de9c9be4f89e392fe500dd27f928d6b1184bf09
path: corpus
persist-credentials: false
sparse-checkout-cone-mode: false
sparse-checkout: |
/lib/**/*.rb
/app/**/*.rb
/config/**/*.rb
/src/**/*.rb
/*.rb
/*.gemspec
/Gemfile
/.archignore
/LICENSE*
/README*
!/**/fixtures/**
!/**/spec/**
!/**/test/**
!/**/tests/**

- name: Set up isolated checksum-locked research dependencies
uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1
with:
ruby-version: '4.0'
bundler-cache: true
working-directory: archunit/benchmark/study

- name: Repeated alternating shared-policy trials and fresh startup
run: bundle exec ruby run.rb --archspec ../../pkg/study-linux.json
env:
STUDY_PAIRS: '100'
STUDY_TRIALS: '5'

- name: Reproduce bounded semantic comparison on Linux
run: bundle exec ruby ../semantic/probes.rb --archspec ../../pkg/semantic-linux.json

- name: Profile real pinned production source without booting it
run: bundle exec ruby real_project.rb ../../../corpus ../../pkg/discourse-linux.json

- name: Retain raw evidence and exact dependency lock
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: performance-study-${{ github.run_id }}
path: |
archunit/pkg/study-linux.json
archunit/pkg/semantic-linux.json
archunit/pkg/discourse-linux.json
archunit/benchmark/study/Gemfile.lock
if-no-files-found: warn
retention-days: 14
68 changes: 68 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,39 @@ the same file pair merge into one edge. Import-only edge evidence stays empty fo
`ArchUnit::Extraction.extract_imports` retains import call locations in both modes. The analysis
mode participates in graph-cache identity, and `clear_cache: true` rebuilds the symbol index.

## Architecture presets (unreleased 1.1)

Method-call restrictions, effective method/signature protocols, and semantic component selectors
are not provided by the current file graph or metric method facts. The bounded
[semantic evaluation](https://github.com/dragonsec-ai/ArchUnitRuby/blob/main/design/semantic-boundaries.md)
records exact comparator pins, executable probes and the compatibility/unknowns required before
adding such APIs. This is a technical evaluation, not a newly shipped semantic backend.

`ArchUnit.architecture_preset(name, options = nil)` returns an immutable Checkable `PresetRule`.
`ArchUnit::PresetOptions.new(project_locator: nil, folders: {})` is its options bag. Names are
`:layered`, `:hexagonal`, or `:rails`; unknown names and malformed/duplicate override layer keys fail
at construction. Each folder override is a non-empty String or Array of source globs; multiple
patterns are ORed within one layer. No project reads occur until check.

Layered maps presentation/application/persistence to `app/api/**`, `app/services/**`, `app/db/**`,
allowing only presentation→application and application→persistence across layers. Hexagonal maps
domain/application/adapters to `app/domain/**`, `app/application/**`, `app/adapters/**`, allowing
application→domain and adapters→application/domain. Rails maps controllers/services/models to
their `app/` folders, allowing controllers→services/models and services→models. Same-layer edges
are allowed; the innermost layer has no allowed outgoing cross-layer edge. All mappings are
overridable. Unmapped files/external modules are outside this policy, not excluded from extraction.

Presets construct `LayeredArchitecture` rules and use existing assertion code. The guard rejects
observed files matching multiple layers with UserError; empty layers use the normal
EmptyTestViolation defense unless explicitly permitted. CheckOptions controls analysis, exclusions,
cache and logging as usual; source parse errors remain fatal. `.because` and framework matchers
work normally. Rails conventions do not boot Rails or automatically turn on expanded/helper modes.
These presets are not complete architecture/cycle/protocol verification; compose more rules or
build arbitrary policies with `project_layers`.

Trusted CLI configurations have `architecture_preset(name, options = nil)`, defaulting the locator
to their selected project root. This preserves the public locator/auto-discovery distinction.

## CLI contract (unreleased 1.1 milestone)

The new executable is development-only until a 1.1 release; it is not included in 1.0.0. It wraps
Expand Down Expand Up @@ -381,6 +414,41 @@ actual work (zero repeated cold counters); diagnostic snapshots are separate fro

## Errors and support

### Explicit violation baselines (unreleased 1.1)

`archunit baseline --output FILE.json` evaluates every rule and atomically writes an explicitly
reviewable accepted-debt document. It refuses existing output without `--force`, non-JSON output
names, empty-selection violations, custom/unknown violation types, and unobserved scopes. No output
is written until all rules finish; parse/configuration failures never replace existing debt.
`archunit check --baseline FILE` remains read-only. All sources/rules are still checked; it returns
0 only when there are no new violations or stale entries. A run with accepted violations has
`status: accepted`, not `passed`. Baseline creation has `status: baseline_created`, not an
architecture pass. Without either flag/command normal strict checks are unchanged.

The document has `schema_version: 1`, `fingerprint_version: 1`, and `entries`. Each entry contains
`fingerprint` (SHA256 of canonical rule/type/data/context), positive occurrence `count`, `rule`,
`type`, structured `data`, and scope `context`. Input validates schema, duplicate fingerprints,
counts, fingerprint/data consistency, size (2 MB), nesting (32) and entry limit (10,000). Paths are
project-relative; regex source/options are data. Line evidence, formatter wording, object identity,
graph counters/cache state and checkout absolute paths are not identity. Actual source policies and
dependency-analysis settings are included, so a different mode/policy cannot silently reuse debt.
Deleted/renamed rules leave stale entries. Counts are matched one-to-one, not set membership.

Built-in file/external dependencies, patterns, simple directed cycles, layer/slice dependencies,
and numeric metric thresholds have explicit adapters. Metric predicates/zones, custom violations,
empty selectors and unsupported types are never auto-recorded; under an existing baseline they
remain new violations. There is no generic `inspect`/formatted-message fallback. Public Checkable
results are unchanged; this first delivery is CLI-only.

Schema-1 CLI output adds `baseline` metadata. During check it contains `status: checked`, `path`,
`accepted_count`, `new_count`, `stale_count` and `stale_entries`; every raw violation retains its
original type/message/details and adds `baseline.status` (`accepted` / `new`) and nullable
`baseline.fingerprint`. Per-rule status can be `accepted`. Existing summary violation counts remain
raw counts, not just new debt. Invalid input/IO/analysis exits 2, new/stale debt exits 1. Atomic
creation uses a same-directory hard link (unsupported filesystems fail closed); force replacement
uses rename after rejecting non-regular paths. Concurrent hostile filesystem mutation is outside
this library's isolation guarantees. Do not blindly regenerate baselines in CI.

Invalid API input raises `ArchUnit::UserError` or `ArgumentError`; library or environment failures
raise `ArchUnit::TechnicalError`. Rule failures remain violation data.

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 1.1.0 (unreleased)

- Compose layered, hexagonal and Rails folder presets from existing layer rules, with immutable
pattern overrides, CLI integration, overlap errors and unchanged empty/source-analysis defenses.

- Add explicit CLI accepted-debt baselines with versioned structured fingerprints, one-to-one
occurrence matching, stale-entry failures, strict JSON validation and safe explicit output.

- Expose additive CLI analysis scopes with source/uncertainty counts, truthful warm-cache reuse,
unavailable values for unperformed/failed analysis, and explicit static-analysis limitations.

Expand Down
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,33 @@ evaluate a target Gemfile/gemspec, install its dependencies, or boot Rails. Invo
still has Bundler's normal Gemfile behavior. RSpec/Minitest remain fully supported; the CLI composes
the same Checkable rules and is not a replacement for their integrations.

#### Gradual adoption with explicit accepted debt (unreleased 1.1)

```sh
# Evaluate all rules and explicitly record current supported violations; review this JSON in Git.
bundle exec archunit baseline --output .archunit-baseline.json
bundle exec archunit check --baseline .archunit-baseline.json
```

Every rule still runs over the same sources. The baseline accepts specific violations, not whole
files. New violations **and stale entries for fixed/removed violations** fail with exit 1; invalid
baseline/config/source errors exit 2. A fully accepted result exits 0 with status `accepted`, not a
clean `passed` result. Raw violations stay visible, with separate accepted/new/stale counts.
`check` never rewrites debt. Explicitly regenerate with `baseline --output ... --force` only after
reviewing changes; recording debt is not proof that the architecture passes.

Versioned fingerprints use rule names, structured violation data and analysis scope/settings, not
message prose, line numbers or absolute checkout paths. Line edits/relocation preserve identities;
changed rule names, policies or analysis modes can invalidate them. Duplicate occurrences match
one-for-one. Supported identities: built-in file/external dependencies, naming, simple directed
cycles, layer/slice dependencies and numeric metric thresholds. Empty-selection failures, custom
predicates/violations, metric zones and unknown types cannot be recorded silently. Baselines are
bounded JSON (2 MB / 10,000 entries), not executable configuration; symlinks and directories are
rejected. Creation requires a `.json` output and refuses overwrite unless `--force` is explicit.
Atomic output needs a filesystem supporting same-directory hard links; an unsupported filesystem
fails with exit 2, never falls back to overwriting. This is not a sandbox against concurrent hostile
filesystem changes. Review baseline diffs in CI as carefully as rule changes.

[ClickGems download analytics](https://clickgems.clickhouse.com/dashboard/archunit) show trends by
date, gem version, Ruby version, system, and country. Download totals count package fetches rather
than unique users, so repeated installs and automated clients may contribute to the total. The
Expand Down Expand Up @@ -167,6 +194,39 @@ is required:
run: bundle exec rspec spec/architecture_spec.rb
~~~

## Reusable architecture presets (unreleased 1.1)

Presets compose the existing named-layer rules, preserving CheckOptions, empty-selection failures,
RSpec/Minitest, CLI, and static-analysis limitations. Construction is lazy; no Rails app is booted.

~~~ruby
rule = ArchUnit.architecture_preset(
:hexagonal,
ArchUnit::PresetOptions.new(project_locator: '.', folders: { domain: 'lib/domain/**' })
).because('Keep the domain independent of infrastructure')
expect(rule).to pass
~~~

| Preset | Default layers / source patterns | Allowed cross-layer directions |
| --- | --- | --- |
| `:layered` | presentation `app/api/**`; application `app/services/**`; persistence `app/db/**` | presentation → application → persistence; no skipping |
| `:hexagonal` | domain `app/domain/**`; application `app/application/**`; adapters `app/adapters/**` | application → domain; adapters → application/domain |
| `:rails` | controllers `app/controllers/**`; services `app/services/**`; models `app/models/**` | controllers → services/models; services → models |

Dependencies within a layer are allowed; the innermost layer may not depend on another mapped layer.
Unmapped files and external modules are not constrained by this folder policy; source discovery is
not narrowed. Add file/layer/cycle rules for additional boundaries. Missing policy layers fail by
default; override patterns or consciously use `CheckOptions.new(allow_empty_tests: true)` if intended.
Overlapping observed membership raises UserError instead of choosing a layer silently. All source
patterns can be overridden with `PresetOptions.folders` (String or Array of source globs per layer).
Unknown/duplicate keys and empty patterns are errors. For arbitrary policies use `project_layers`.
The Rails preset is opinionated and expects a services layer; it is not full Rails/DDD verification
and does not automatically enable `rails_imports` or constant analysis.

In trusted CLI configuration use `rule('Core independent') { architecture_preset(:hexagonal) }`;
the helper defaults to the CLI's selected project root. Public `ArchUnit.architecture_preset` uses
normal project auto-discovery when no locator is supplied.

## 🎬 Demo

https://github.com/user-attachments/assets/9b7305a0-deee-454d-b99e-f8fac63d06ab
Expand Down
3 changes: 3 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Extraction performance benchmark

For repeated Linux shared-policy comparisons, fresh-process startup/memory, source changes and
pinned Rails production-source evidence, see the [representative study](study/README.md).

For pinned production-library compatibility checks, public passing/failing rule witnesses, and
real-world timing artifacts, see the [static canary guide](canary/README.md).

Expand Down
Loading