archunit 1.0.0 → 1.1.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.
- checksums.yaml +4 -4
- data/API.md +213 -5
- data/CHANGELOG.md +41 -1
- data/CODE_OF_CONDUCT.md +40 -0
- data/CONTRIBUTING.md +75 -0
- data/GUIDE.md +804 -0
- data/README.md +198 -562
- data/SECURITY.md +64 -0
- data/SUPPORT.md +23 -0
- data/exe/archunit +7 -0
- data/lib/archunit/cli/analysis_report.rb +62 -0
- data/lib/archunit/cli/analysis_text.rb +25 -0
- data/lib/archunit/cli/baseline_context.rb +42 -0
- data/lib/archunit/cli/baseline_document.rb +58 -0
- data/lib/archunit/cli/baseline_fingerprint.rb +36 -0
- data/lib/archunit/cli/baseline_identity.rb +85 -0
- data/lib/archunit/cli/baseline_ledger.rb +38 -0
- data/lib/archunit/cli/baseline_object.rb +15 -0
- data/lib/archunit/cli/baseline_options.rb +48 -0
- data/lib/archunit/cli/baseline_run.rb +85 -0
- data/lib/archunit/cli/baseline_schema.rb +53 -0
- data/lib/archunit/cli/baseline_text.rb +31 -0
- data/lib/archunit/cli/configuration.rb +93 -0
- data/lib/archunit/cli/options.rb +117 -0
- data/lib/archunit/cli/report.rb +121 -0
- data/lib/archunit/cli/runner.rb +108 -0
- data/lib/archunit/cli.rb +15 -0
- data/lib/archunit/common/extraction/import_kind.rb +3 -1
- data/lib/archunit/common/extraction/source_exclusions.rb +43 -0
- data/lib/archunit/common/fluentapi/check_options.rb +13 -3
- data/lib/archunit/extraction/analysis_observer.rb +24 -0
- data/lib/archunit/extraction/analysis_profile.rb +30 -0
- data/lib/archunit/extraction/analysis_snapshot.rb +51 -0
- data/lib/archunit/extraction/constant_visitor.rb +8 -0
- data/lib/archunit/extraction/dependency_context.rb +30 -0
- data/lib/archunit/extraction/enumerate_source_files.rb +17 -5
- data/lib/archunit/extraction/extract_dependencies.rb +5 -14
- data/lib/archunit/extraction/extract_graph.rb +45 -55
- data/lib/archunit/extraction/extract_imports.rb +11 -14
- data/lib/archunit/extraction/graph_assembly.rb +32 -0
- data/lib/archunit/extraction/graph_cache_key.rb +27 -0
- data/lib/archunit/extraction/import_calls.rb +93 -0
- data/lib/archunit/extraction/import_resolver.rb +11 -2
- data/lib/archunit/extraction/import_source_policy.rb +123 -0
- data/lib/archunit/extraction/import_visitor.rb +31 -46
- data/lib/archunit/extraction/load_arguments.rb +34 -0
- data/lib/archunit/extraction/local_string_tracker.rb +4 -3
- data/lib/archunit/extraction/resolve_load_paths.rb +5 -0
- data/lib/archunit/extraction/source_analysis.rb +26 -0
- data/lib/archunit/extraction/static_import_path.rb +111 -0
- data/lib/archunit/layers/fluentapi/architecture_preset.rb +49 -0
- data/lib/archunit/layers/fluentapi/preset_definitions.rb +39 -0
- data/lib/archunit/layers/fluentapi/preset_options.rb +69 -0
- data/lib/archunit/layers/fluentapi/preset_rule.rb +45 -0
- data/lib/archunit/metrics/extraction/extract_distance_info.rb +1 -1
- data/lib/archunit/metrics/extraction/extract_project_info.rb +8 -4
- data/lib/archunit/metrics/fluentapi/metric_report_builder.rb +4 -3
- data/lib/archunit/metrics/fluentapi/metrics_builder.rb +3 -3
- data/lib/archunit/metrics/reporting/metrics_export_options.rb +6 -2
- data/lib/archunit/version.rb +1 -1
- data/lib/archunit.rb +2 -0
- metadata +48 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2a48d64d371405af4f585562e9e0681d55057b0f49b538752bd48b5e8a3424a8
|
|
4
|
+
data.tar.gz: 9f757d0013a3c7aad7c8ae65614daeeaf1fa97fce26ef3d7ad12c7d1171254c2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eff71dc5e9470b205772ad8fb8c39a0c4898c612cddbe3b86034bdbca57897565e96d5a25fb689ba721233dea9a0f4a96b08fec51cbd441f77aeb99641cc7433
|
|
7
|
+
data.tar.gz: a959a6f1bf867076901ebaff0515a552d2e0d5579280d4e9036ada93bd8e51ba3f00af09ec61eecd412faa917b99e23085e24e5e182dbe9963fe56ab37637c64
|
data/API.md
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
# ArchUnitRuby API Guide
|
|
2
2
|
|
|
3
3
|
This guide is the stable map of ArchUnitRuby's public fluent API. The
|
|
4
|
-
[class and method reference](class_list.html)
|
|
4
|
+
[class and method reference](https://dragonsec-ai.github.io/ArchUnitRuby/class_list.html)
|
|
5
|
+
is generated from the source, while this page explains
|
|
5
6
|
which entry point to choose and how the stages fit together.
|
|
6
7
|
|
|
7
8
|
All rule builders are immutable and lazy. Constructing a rule does not read the project; `check`,
|
|
8
9
|
`measure`, `snapshot`, and export methods are the terminals that perform work.
|
|
9
10
|
|
|
11
|
+
This reference follows `main` and documents the 1.x API. Additions requiring 1.1 are labeled;
|
|
12
|
+
see [release status](README.md#availability) and check your installed version before copying them.
|
|
13
|
+
For recipes use the [user guide](GUIDE.md); for a first rule use the [quickstart](README.md#quickstart).
|
|
14
|
+
|
|
15
|
+
[1.x compatibility contract](#compatibility) · [Common rule shape](#grammar) · [File rules](#file-rules) · [Layer rules](#layer-rules) · [Slices and diagrams](#slices) · [Dependency graph reports](#graph-reports) · [Metrics](#metrics) · [Checking and test frameworks](#frameworks) · [Check options and logging](#check-options) · [Architecture presets (1.1+)](#presets) · [CLI contract (1.1+)](#cli) · [Errors and support](#errors)
|
|
16
|
+
|
|
17
|
+
<a id="compatibility"></a>
|
|
18
|
+
|
|
10
19
|
## 1.x compatibility contract
|
|
11
20
|
|
|
12
|
-
This guide defines the supported 1.
|
|
21
|
+
This guide defines the supported 1.x public surface: documented entry points, fluent methods,
|
|
13
22
|
options, public data/error types, and report formats. Additive capabilities can arrive in minor
|
|
14
23
|
versions; incompatible public API changes require a major version and migration notes. Private
|
|
15
24
|
helpers and classes marked as implementation details are not part of that compatibility promise.
|
|
@@ -19,7 +28,9 @@ dependencies or misleading clean results.
|
|
|
19
28
|
Static extraction remains bounded and does not execute the target application's source or gemspecs.
|
|
20
29
|
Import-only is the default; expanded constant analysis is explicit opt-in. The documented unresolved
|
|
21
30
|
lookup cases, project source/exclusion policy, strict parser failures, and explicit cache-clearing
|
|
22
|
-
behavior remain important when upgrading. See the
|
|
31
|
+
behavior remain important when upgrading. See the [migration guide](GUIDE.md#migration) for changes from 0.0.1.
|
|
32
|
+
|
|
33
|
+
<a id="grammar"></a>
|
|
23
34
|
|
|
24
35
|
## Common rule shape
|
|
25
36
|
|
|
@@ -48,6 +59,8 @@ are accepted by all pattern selectors except the exact `in_file` selector.
|
|
|
48
59
|
Every pattern selector accepts `except:`. Pass a pattern, an array of patterns, or explicit selector
|
|
49
60
|
keys such as `{ in_folder: 'generated', with_name: '*_spec.rb' }`.
|
|
50
61
|
|
|
62
|
+
<a id="file-rules"></a>
|
|
63
|
+
|
|
51
64
|
## File rules
|
|
52
65
|
|
|
53
66
|
Every completed rule implementing `ArchUnit::Checkable` supports `.because(reason)`. Append it
|
|
@@ -77,6 +90,16 @@ Changing source contents still requires explicit cache clearing. Reads are bound
|
|
|
77
90
|
BOMs are accepted and invalid bytes replaced. Symlinks (including project-local ones), non-regular
|
|
78
91
|
files, negation, NUL characters, and a bare `/` are rejected. No Ruby or gemspec code is evaluated.
|
|
79
92
|
|
|
93
|
+
Since 1.1, `CheckOptions.new(source_exclusions: ['lib/templates/migration.rb'])` adds
|
|
94
|
+
immutable caller-owned globs without changing the target repository. These combine with defaults
|
|
95
|
+
and repository policy; legacy `exclude_patterns: []` still disables only defaults. The effective
|
|
96
|
+
normalized set determines graph-cache identity, including when API and legacy inputs express the
|
|
97
|
+
same policy. Source selectors do not narrow the discovery universe. Included invalid Ruby remains
|
|
98
|
+
fatal; no template directories are implicitly skipped. CLI uses repeatable `--exclude-source GLOB`.
|
|
99
|
+
Globs are project-relative (optional leading `/`); negation, traversal, drive/UNC paths, NUL/newlines
|
|
100
|
+
and empty/root-only patterns are rejected. Counts/cohesion/distance accept the same check options.
|
|
101
|
+
For metric HTML, pass `MetricsExportOptions.new(check_options: options)` to `export_as_html`.
|
|
102
|
+
|
|
80
103
|
| Scope or predicate | Purpose |
|
|
81
104
|
| --- | --- |
|
|
82
105
|
| `with_name(pattern)` | Select or require a filename pattern |
|
|
@@ -109,6 +132,8 @@ Cycle projection uses iterative strongly-connected-component and elementary-cycl
|
|
|
109
132
|
long dependency chains do not consume Ruby's call stack. It still enumerates all elementary cycles;
|
|
110
133
|
dense graphs can have exponentially many results. Scope cycle rules to meaningful components.
|
|
111
134
|
|
|
135
|
+
<a id="layer-rules"></a>
|
|
136
|
+
|
|
112
137
|
## Layer rules
|
|
113
138
|
|
|
114
139
|
Use `ArchUnit.project_layers(project_locator = nil)` to name architectural layers and then declare
|
|
@@ -128,6 +153,8 @@ rule = ArchUnit.project_layers
|
|
|
128
153
|
`may_not_depend_on_layers` creates a blocklist and requires at least one target. Dependencies inside
|
|
129
154
|
one layer are allowed; edges with an unassigned endpoint are ignored.
|
|
130
155
|
|
|
156
|
+
<a id="slices"></a>
|
|
157
|
+
|
|
131
158
|
## Slices and diagrams
|
|
132
159
|
|
|
133
160
|
Use `ArchUnit.project_slices(project_locator = nil)` to capture one segment from project paths.
|
|
@@ -149,6 +176,8 @@ slices.export_as_plantuml('reports/architecture.puml')
|
|
|
149
176
|
`adhere_to_diagram` accepts inline PlantUML. The supported subset includes components, directed
|
|
150
177
|
dependencies, comments, `@startuml`, and `@enduml`.
|
|
151
178
|
|
|
179
|
+
<a id="graph-reports"></a>
|
|
180
|
+
|
|
152
181
|
## Dependency graph reports
|
|
153
182
|
|
|
154
183
|
Use `ArchUnit.project_graph(project_locator = nil)` for queryable snapshots and reports.
|
|
@@ -171,6 +200,8 @@ Query modifiers are `focus_on(pattern, depth)`, `reachable_from(pattern)`, and
|
|
|
171
200
|
`collapse_by_pattern(pattern, replacement)`. Formats are DOT, Mermaid, D2, CSV, JSON, and
|
|
172
201
|
self-contained HTML; each provides both `to_<format>` and `export_as_<format>`.
|
|
173
202
|
|
|
203
|
+
<a id="metrics"></a>
|
|
204
|
+
|
|
174
205
|
## Metrics
|
|
175
206
|
|
|
176
207
|
Start with `ArchUnit.metrics(project_locator = nil)`. Select files with the standard file selectors
|
|
@@ -200,6 +231,8 @@ Thresholds use exactly `should_be_below`, `should_be_above`, `should_be`,
|
|
|
200
231
|
for a calculation over `ClassInfo`; zone guards are `not_in_zone_of_pain` and
|
|
201
232
|
`not_in_zone_of_uselessness`.
|
|
202
233
|
|
|
234
|
+
<a id="frameworks"></a>
|
|
235
|
+
|
|
203
236
|
## Checking and test frameworks
|
|
204
237
|
|
|
205
238
|
Every architecture rule includes `ArchUnit::Checkable` and exposes `check(options = nil)`. It returns
|
|
@@ -217,6 +250,8 @@ ArchUnit.assert_passes(rule) # Framework-neutral
|
|
|
217
250
|
Use `ArchUnit.format_violations` or `ArchUnit::ResultFactory` when integrating with another test
|
|
218
251
|
framework or command-line interface.
|
|
219
252
|
|
|
253
|
+
<a id="check-options"></a>
|
|
254
|
+
|
|
220
255
|
## Check options and logging
|
|
221
256
|
|
|
222
257
|
`ArchUnit::CheckOptions` keeps optional execution behavior out of the fluent sentence:
|
|
@@ -247,6 +282,21 @@ gemspecs or running application code.
|
|
|
247
282
|
literal-string assignments in supported straight-line scopes. Aliases, mutation/escape, closures,
|
|
248
283
|
reflection, and unsupported control flow invalidate inferred values; runtime paths are not guessed.
|
|
249
284
|
|
|
285
|
+
Since 1.1, the bounded file-relative whitelist also accepts `__FILE__`, implicit `__dir__`, literal/static
|
|
286
|
+
string `+`, `File.dirname(absolute_expression)` and `File.expand_path(path, absolute_base)`
|
|
287
|
+
(also `::File`, or one absolute operand for `expand_path`). Operands cannot contain local-variable
|
|
288
|
+
reads or arbitrary calls; the completed result may be assigned to a local. No source is evaluated.
|
|
289
|
+
Source-local core overrides/reflection disable affected inference; arbitrary cross-file core
|
|
290
|
+
monkey-patching is not modeled. See the [resolution guide](GUIDE.md#analysis) for exact limits.
|
|
291
|
+
|
|
292
|
+
Since 1.1, `rails_imports: true` separately opts into implicit/`self.require_dependency`
|
|
293
|
+
calls. Accepted paths use the same literal/local/static contract, and edges use
|
|
294
|
+
`:require_dependency`. Explicit `load_paths` are searched first for this helper only; ordinary
|
|
295
|
+
`require` resolution is unchanged. Custom receivers are ignored; local helper overrides/reflection
|
|
296
|
+
and unknown operands remain unresolved. No Rails boot or automatic autoload-root discovery occurs.
|
|
297
|
+
The option is immutable, validated and part of graph-cache identity; it composes with either
|
|
298
|
+
dependency-analysis mode. Cross-file method replacement and dynamic Rails/glob values are not modeled.
|
|
299
|
+
|
|
250
300
|
For autoloaded projects, opt into known project constant references alongside imports:
|
|
251
301
|
|
|
252
302
|
~~~ruby
|
|
@@ -273,6 +323,164 @@ the same file pair merge into one edge. Import-only edge evidence stays empty fo
|
|
|
273
323
|
`ArchUnit::Extraction.extract_imports` retains import call locations in both modes. The analysis
|
|
274
324
|
mode participates in graph-cache identity, and `clear_cache: true` rebuilds the symbol index.
|
|
275
325
|
|
|
326
|
+
### Semantic boundaries
|
|
327
|
+
|
|
328
|
+
Method-call restrictions, effective method/signature protocols, and semantic component selectors
|
|
329
|
+
are not provided by the current file graph or metric method facts. The bounded
|
|
330
|
+
[semantic evaluation](https://github.com/dragonsec-ai/ArchUnitRuby/blob/main/design/semantic-boundaries.md)
|
|
331
|
+
records exact comparator pins, executable probes and the compatibility/unknowns required before
|
|
332
|
+
adding such APIs. This is a technical evaluation, not a newly shipped semantic backend.
|
|
333
|
+
|
|
334
|
+
<a id="presets"></a>
|
|
335
|
+
|
|
336
|
+
## Architecture presets (1.1+)
|
|
337
|
+
|
|
338
|
+
`ArchUnit.architecture_preset(name, options = nil)` returns an immutable Checkable `PresetRule`.
|
|
339
|
+
`ArchUnit::PresetOptions.new(project_locator: nil, folders: {})` is its options bag. Names are
|
|
340
|
+
`:layered`, `:hexagonal`, or `:rails`; unknown names and malformed/duplicate override layer keys fail
|
|
341
|
+
at construction. Each folder override is a non-empty String or Array of source globs; multiple
|
|
342
|
+
patterns are ORed within one layer. No project reads occur until check.
|
|
343
|
+
|
|
344
|
+
Layered maps presentation/application/persistence to `app/api/**`, `app/services/**`, `app/db/**`,
|
|
345
|
+
allowing only presentation→application and application→persistence across layers. Hexagonal maps
|
|
346
|
+
domain/application/adapters to `app/domain/**`, `app/application/**`, `app/adapters/**`, allowing
|
|
347
|
+
application→domain and adapters→application/domain. Rails maps controllers/services/models to
|
|
348
|
+
their `app/` folders, allowing controllers→services/models and services→models. Same-layer edges
|
|
349
|
+
are allowed; the innermost layer has no allowed outgoing cross-layer edge. All mappings are
|
|
350
|
+
overridable. Unmapped files/external modules are outside this policy, not excluded from extraction.
|
|
351
|
+
|
|
352
|
+
Presets construct `LayeredArchitecture` rules and use existing assertion code. The guard rejects
|
|
353
|
+
observed files matching multiple layers with UserError; empty layers use the normal
|
|
354
|
+
EmptyTestViolation defense unless explicitly permitted. CheckOptions controls analysis, exclusions,
|
|
355
|
+
cache and logging as usual; source parse errors remain fatal. `.because` and framework matchers
|
|
356
|
+
work normally. Rails conventions do not boot Rails or automatically turn on expanded/helper modes.
|
|
357
|
+
These presets are not complete architecture/cycle/protocol verification; compose more rules or
|
|
358
|
+
build arbitrary policies with `project_layers`.
|
|
359
|
+
|
|
360
|
+
Trusted CLI configurations have `architecture_preset(name, options = nil)`, defaulting the locator
|
|
361
|
+
to their selected project root. This preserves the public locator/auto-discovery distinction.
|
|
362
|
+
|
|
363
|
+
<a id="cli"></a>
|
|
364
|
+
|
|
365
|
+
## CLI contract (1.1+)
|
|
366
|
+
|
|
367
|
+
The executable requires 1.1 or newer; it is not included in 1.0.0. It wraps
|
|
368
|
+
Checkable rules without changing RSpec/Minitest or the library's default analysis mode.
|
|
369
|
+
|
|
370
|
+
~~~sh
|
|
371
|
+
archunit init --project .
|
|
372
|
+
archunit check --project . --format json
|
|
373
|
+
archunit check --dependency-analysis imports_and_constants
|
|
374
|
+
archunit check --rails-imports --load-path app/models --load-path app/services
|
|
375
|
+
archunit explain --config ./trusted-architecture.rb
|
|
376
|
+
~~~
|
|
377
|
+
|
|
378
|
+
`init` checks the filesystem entry itself and uses exclusive creation to reject existing paths,
|
|
379
|
+
including dangling symlinks on Windows. This is not a sandbox against a hostile process concurrently
|
|
380
|
+
replacing filesystem entries. The default configuration is
|
|
381
|
+
`PROJECT/.archunit.rb`; an explicit `--config` path is relative to the invocation directory. The
|
|
382
|
+
project defaults to that working directory. Named declarations are
|
|
383
|
+
`rule('unique name') { completed_checkable }`; the configuration helpers `project_files` / `files`,
|
|
384
|
+
`project_layers` / `layers`, `project_slices`, and `metrics` use the selected root. Rules must be
|
|
385
|
+
non-empty and uniquely named. Every `check` command starts with a fresh graph cache, then shares
|
|
386
|
+
that cache across its rules.
|
|
387
|
+
|
|
388
|
+
Configuration is trusted executable Ruby, not an isolation boundary. `explain` loads the same Ruby
|
|
389
|
+
configuration but never calls its rules' `check` methods. It reports `configured` and per-rule
|
|
390
|
+
`not_checked`, not an architecture pass. It lists rule names/rationale and settings, not a full
|
|
391
|
+
semantic explanation or focused-path report. Avoid stdout writes in configuration when requesting
|
|
392
|
+
machine-readable output. No target source, Gemfile, or gemspec is automatically executed by the CLI;
|
|
393
|
+
the caller's own Bundler/configuration code retains its normal Ruby behavior.
|
|
394
|
+
|
|
395
|
+
Exit codes: **0** for a successful informational/init/explain command or all checked rules passing;
|
|
396
|
+
**1** for architecture violations; **2** for argument/configuration/analysis errors. Empty selectors
|
|
397
|
+
remain violations. Text errors go to stderr; JSON diagnostics go to stdout without color. The
|
|
398
|
+
format option applies to init/check/explain and errors; help/version remain plain text.
|
|
399
|
+
|
|
400
|
+
`--format json` produces one document with `schema_version: 1`, `archunit_version`, `command`,
|
|
401
|
+
`project_root`, `config_path`, `dependency_analysis`, `rails_imports`, `load_paths`, `source_exclusions`,
|
|
402
|
+
`status`, `rules`, `analysis`, and `summary`. The new settings/diagnostics are additive schema-1 fields.
|
|
403
|
+
Rule entries carry `name`, nullable `rationale`, `status`, `analysis`, and `violations`;
|
|
404
|
+
each violation carries its `type`,
|
|
405
|
+
shared formatter `message`, and `details`. Summary counts describe completed/listed rules and their
|
|
406
|
+
violations; an analysis error may stop later rules, so a partial summary is never a pass. An error
|
|
407
|
+
adds `error.type`, `error.message`, and nullable `error.rule_name`; a `SourceParseError` also adds
|
|
408
|
+
`error.diagnostics` with path, one-based line/column, and message. Messages/details are for people,
|
|
409
|
+
not stable violation fingerprints. The CLI implementation classes are not a new fluent API.
|
|
410
|
+
|
|
411
|
+
### Analysis diagnostics
|
|
412
|
+
|
|
413
|
+
`analysis` contains `status` (`available`, `partial`, or `unavailable`), `scopes`, and a limitations
|
|
414
|
+
`notice`. Each scope contains:
|
|
415
|
+
|
|
416
|
+
- `id`, `project_root`, `kind` (`dependency_graph` or `source_metrics`), and `status`
|
|
417
|
+
(`analyzed` or `error`). IDs are local to one invocation, not stable fingerprints.
|
|
418
|
+
- The actual `dependency_analysis`, `rails_imports`, explicit `load_paths`, and sorted
|
|
419
|
+
`effective_source_exclusions` (defaults + repository policy + caller exclusions).
|
|
420
|
+
Dependency settings are null for source-only metrics, which do not construct a dependency graph.
|
|
421
|
+
- `counters`: `source_files`, `imports`, `unresolved_imports`, `unresolved_constant_references`,
|
|
422
|
+
and `ambiguous_constant_references`. Constant counters are null in imports-only mode;
|
|
423
|
+
all counts are null when extraction fails, rather than presenting a partial parse as success.
|
|
424
|
+
- `observations`, `cache_hits`, and the `rule_names` using that snapshot. Cached graphs retain their
|
|
425
|
+
original measured counts, even if first extracted without a timing profile. Refreshed graphs
|
|
426
|
+
become separate snapshots; roots, policies, and modes are not conflated.
|
|
427
|
+
|
|
428
|
+
Each rule's `analysis` contains an availability `status` and its `scope_ids`. `explain`, `init`,
|
|
429
|
+
and custom checks doing no built-in extraction have unavailable diagnostics, not zero counts.
|
|
430
|
+
Mixed measured/unobserved rules produce partial availability. Analysis scopes are not summed:
|
|
431
|
+
multiple roots can overlap, and a metric pass and a graph pass can inspect the same files.
|
|
432
|
+
`source_files` counts all included sources before fluent selectors, not matched rule subjects.
|
|
433
|
+
Scopes describe synchronous built-in extraction in the current check, not arbitrary user work
|
|
434
|
+
started in other threads/fibers.
|
|
435
|
+
|
|
436
|
+
`imports` counts accepted static import expressions, including external imports.
|
|
437
|
+
Unresolved imports count unsupported/dynamic import expressions; literal external gem imports are
|
|
438
|
+
not counted as unresolved expressions. Unresolved/ambiguous constant observations can include
|
|
439
|
+
external symbols, unsupported Ruby lookup, or definitions reopened across files. They are neither
|
|
440
|
+
proven missed internal dependencies nor a semantic-completeness percentage. They do not change
|
|
441
|
+
exit status; included parse failures remain errors. A passing policy only describes the statically
|
|
442
|
+
resolved graph, not proof of complete runtime architecture. Warm timing profiles still measure
|
|
443
|
+
actual work (zero repeated cold counters); diagnostic snapshots are separate from those profiles.
|
|
444
|
+
|
|
445
|
+
<a id="baselines"></a>
|
|
446
|
+
|
|
447
|
+
### Explicit violation baselines (1.1+)
|
|
448
|
+
|
|
449
|
+
`archunit baseline --output FILE.json` evaluates every rule and atomically writes an explicitly
|
|
450
|
+
reviewable accepted-debt document. It refuses existing output without `--force`, non-JSON output
|
|
451
|
+
names, empty-selection violations, custom/unknown violation types, and unobserved scopes. No output
|
|
452
|
+
is written until all rules finish; parse/configuration failures never replace existing debt.
|
|
453
|
+
`archunit check --baseline FILE` remains read-only. All sources/rules are still checked; it returns
|
|
454
|
+
0 only when there are no new violations or stale entries. A run with accepted violations has
|
|
455
|
+
`status: accepted`, not `passed`. Baseline creation has `status: baseline_created`, not an
|
|
456
|
+
architecture pass. Without either flag/command normal strict checks are unchanged.
|
|
457
|
+
|
|
458
|
+
The document has `schema_version: 1`, `fingerprint_version: 1`, and `entries`. Each entry contains
|
|
459
|
+
`fingerprint` (SHA256 of canonical rule/type/data/context), positive occurrence `count`, `rule`,
|
|
460
|
+
`type`, structured `data`, and scope `context`. Input validates schema, duplicate fingerprints,
|
|
461
|
+
counts, fingerprint/data consistency, size (2 MB), nesting (32) and entry limit (10,000). Paths are
|
|
462
|
+
project-relative; regex source/options are data. Line evidence, formatter wording, object identity,
|
|
463
|
+
graph counters/cache state and checkout absolute paths are not identity. Actual source policies and
|
|
464
|
+
dependency-analysis settings are included, so a different mode/policy cannot silently reuse debt.
|
|
465
|
+
Deleted/renamed rules leave stale entries. Counts are matched one-to-one, not set membership.
|
|
466
|
+
|
|
467
|
+
Built-in file/external dependencies, patterns, simple directed cycles, layer/slice dependencies,
|
|
468
|
+
and numeric metric thresholds have explicit adapters. Metric predicates/zones, custom violations,
|
|
469
|
+
empty selectors and unsupported types are never auto-recorded; under an existing baseline they
|
|
470
|
+
remain new violations. There is no generic `inspect`/formatted-message fallback. Public Checkable
|
|
471
|
+
results are unchanged; this first delivery is CLI-only.
|
|
472
|
+
|
|
473
|
+
Schema-1 CLI output adds `baseline` metadata. During check it contains `status: checked`, `path`,
|
|
474
|
+
`accepted_count`, `new_count`, `stale_count` and `stale_entries`; every raw violation retains its
|
|
475
|
+
original type/message/details and adds `baseline.status` (`accepted` / `new`) and nullable
|
|
476
|
+
`baseline.fingerprint`. Per-rule status can be `accepted`. Existing summary violation counts remain
|
|
477
|
+
raw counts, not just new debt. Invalid input/IO/analysis exits 2, new/stale debt exits 1. Atomic
|
|
478
|
+
creation uses a same-directory hard link (unsupported filesystems fail closed); force replacement
|
|
479
|
+
uses rename after rejecting non-regular paths. Concurrent hostile filesystem mutation is outside
|
|
480
|
+
this library's isolation guarantees. Do not blindly regenerate baselines in CI.
|
|
481
|
+
|
|
482
|
+
<a id="errors"></a>
|
|
483
|
+
|
|
276
484
|
## Errors and support
|
|
277
485
|
|
|
278
486
|
Invalid API input raises `ArchUnit::UserError` or `ArgumentError`; library or environment failures
|
|
@@ -285,6 +493,6 @@ each value supports `to_h`. RSpec/Minitest assertions propagate this technical f
|
|
|
285
493
|
reporting a pass or an ordinary architecture violation. Excluded files are not parsed. The profile's
|
|
286
494
|
`malformed_files` counter records a rejected file; existing cache-clearing rules still apply.
|
|
287
495
|
|
|
288
|
-
See the [
|
|
289
|
-
for help, and [SECURITY.md](https://github.com/
|
|
496
|
+
See the [quickstart](README.md#quickstart) and [user guide](GUIDE.md) for complete examples, [SUPPORT.md](https://github.com/dragonsec-ai/ArchUnitRuby/blob/main/SUPPORT.md)
|
|
497
|
+
for help, and [SECURITY.md](https://github.com/dragonsec-ai/ArchUnitRuby/blob/main/SECURITY.md) for
|
|
290
498
|
responsible vulnerability reporting.
|
data/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,49 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.0 - 2026-11-23
|
|
4
|
+
|
|
5
|
+
Additive release over 1.0.0. Import-only analysis remains the default; the CLI and Rails helpers
|
|
6
|
+
are opt-in. Existing RSpec/Minitest rules keep the 1.x API contract. Correctness fixes can reveal
|
|
7
|
+
previously missed dependencies, so review newly detected violations rather than suppressing them.
|
|
8
|
+
|
|
9
|
+
- Rework getting-started documentation with a concise README, preserved user guide, explicit
|
|
10
|
+
published/development availability, canonical organization URLs and executable example/link checks.
|
|
11
|
+
|
|
12
|
+
- Compose layered, hexagonal and Rails folder presets from existing layer rules, with immutable
|
|
13
|
+
pattern overrides, CLI integration, overlap errors and unchanged empty/source-analysis defenses.
|
|
14
|
+
|
|
15
|
+
- Add explicit CLI accepted-debt baselines with versioned structured fingerprints, one-to-one
|
|
16
|
+
occurrence matching, stale-entry failures, strict JSON validation and safe explicit output.
|
|
17
|
+
|
|
18
|
+
- Expose additive CLI analysis scopes with source/uncertainty counts, truthful warm-cache reuse,
|
|
19
|
+
unavailable values for unperformed/failed analysis, and explicit static-analysis limitations.
|
|
20
|
+
|
|
21
|
+
- Add immutable caller-owned source exclusions and CLI `--exclude-source`, applied consistently
|
|
22
|
+
to graphs, source/coupling metrics and reports without editing target repositories.
|
|
23
|
+
|
|
24
|
+
- Add explicit static Rails `require_dependency` imports, separate helper search-root priority,
|
|
25
|
+
and CLI `--rails-imports` / repeatable `--load-path` options without booting Rails.
|
|
26
|
+
|
|
27
|
+
- Fold a bounded, source-aware whitelist of file-relative import expressions without evaluating
|
|
28
|
+
source, including RestClient-style `File.dirname(__FILE__) + '/feature'` imports.
|
|
29
|
+
|
|
30
|
+
- Record namespace-owner dependencies in qualified class/module declarations and constant writes
|
|
31
|
+
in expanded analysis, preserving lexical lookup, ambiguity handling, and source evidence.
|
|
32
|
+
|
|
33
|
+
- Recognize `load(path, wrap)` dependencies and count dynamic/variadic wrapped paths as unresolved,
|
|
34
|
+
without reusing stale local strings across effectful wrap expressions or block conversions.
|
|
35
|
+
|
|
36
|
+
- Add an opt-in `archunit` executable with non-destructive configuration initialization, named
|
|
37
|
+
Checkable rules, check/explain commands, text or versioned JSON diagnostics, and explicit
|
|
38
|
+
success/violation/error exit codes.
|
|
39
|
+
|
|
40
|
+
- Add isolated Linux performance studies and a bounded semantic evaluation for maintainers;
|
|
41
|
+
these do not add a runtime analyzer dependency or claim full method/protocol semantics.
|
|
42
|
+
|
|
3
43
|
## 1.0.0 - 2026-10-26
|
|
4
44
|
|
|
5
45
|
First stable API baseline. The previously unreleased 0.0.2 development work is included here;
|
|
6
|
-
0.0.1 remains the preceding published version. See the
|
|
46
|
+
0.0.1 remains the preceding published version. See the user guide's migration notes before upgrading.
|
|
7
47
|
|
|
8
48
|
- Fail closed on malformed included Ruby in dependency graphs and AST metrics, with structured
|
|
9
49
|
source diagnostics and profile counters instead of silently treating incomplete analysis as clean.
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our pledge
|
|
4
|
+
|
|
5
|
+
We pledge to make participation in this project a harassment-free experience for everyone,
|
|
6
|
+
regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics,
|
|
7
|
+
gender identity and expression, level of experience, education, socioeconomic status, nationality,
|
|
8
|
+
personal appearance, race, caste, color, religion, or sexual identity and orientation.
|
|
9
|
+
|
|
10
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive,
|
|
11
|
+
and healthy community.
|
|
12
|
+
|
|
13
|
+
## Our standards
|
|
14
|
+
|
|
15
|
+
Examples of behavior that contributes to a positive environment include demonstrating empathy,
|
|
16
|
+
respecting differing viewpoints, giving and accepting constructive feedback, taking responsibility
|
|
17
|
+
for mistakes, and focusing on what is best for the community.
|
|
18
|
+
|
|
19
|
+
Unacceptable behavior includes sexualized language or attention, trolling or insulting comments,
|
|
20
|
+
harassment, publishing another person's private information without permission, and other conduct
|
|
21
|
+
that could reasonably be considered inappropriate in a professional setting.
|
|
22
|
+
|
|
23
|
+
## Enforcement responsibilities
|
|
24
|
+
|
|
25
|
+
Project maintainers may clarify and enforce these standards and may remove, edit, or reject
|
|
26
|
+
comments, commits, code, issues, and other contributions that do not align with this Code of
|
|
27
|
+
Conduct. Moderation decisions should explain the reason when appropriate.
|
|
28
|
+
|
|
29
|
+
## Scope and reporting
|
|
30
|
+
|
|
31
|
+
This Code applies in project spaces and when someone officially represents the project. Report
|
|
32
|
+
abusive or harassing GitHub content through GitHub's reporting tools and contact a maintainer
|
|
33
|
+
privately through the contact options on their GitHub profile. Reports will be reviewed promptly and
|
|
34
|
+
handled with appropriate confidentiality.
|
|
35
|
+
|
|
36
|
+
## Attribution
|
|
37
|
+
|
|
38
|
+
This Code of Conduct is adapted from the
|
|
39
|
+
[Contributor Covenant, version 2.1](https://www.contributor-covenant.org/version/2/1/code_of_conduct.html).
|
|
40
|
+
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Contributing to ArchUnitRuby
|
|
2
|
+
|
|
3
|
+
Thank you for helping improve the Ruby member of the ArchUnitEverything family. Small, focused
|
|
4
|
+
changes with tests are easiest to review.
|
|
5
|
+
|
|
6
|
+
## Before opening a change
|
|
7
|
+
|
|
8
|
+
- Search the [existing issues](https://github.com/dragonsec-ai/ArchUnitRuby/issues).
|
|
9
|
+
- Use an issue for behavior changes or larger additions so the Ruby API can stay aligned with the
|
|
10
|
+
sibling implementations.
|
|
11
|
+
- Read [AGENTS.md](AGENTS.md) for architecture, naming, and fluent-API conventions.
|
|
12
|
+
- Never include credentials, private project source, or customer data in an issue or fixture.
|
|
13
|
+
|
|
14
|
+
## Development setup
|
|
15
|
+
|
|
16
|
+
ArchUnitRuby requires Ruby 3.3 or newer.
|
|
17
|
+
|
|
18
|
+
~~~bash
|
|
19
|
+
git clone https://github.com/dragonsec-ai/ArchUnitRuby.git
|
|
20
|
+
cd ArchUnitRuby
|
|
21
|
+
bundle install
|
|
22
|
+
bundle exec rake
|
|
23
|
+
~~~
|
|
24
|
+
|
|
25
|
+
`bundle exec rake` validates development release metadata, then runs the randomized RSpec suite and
|
|
26
|
+
RuboCop. Before submitting documentation or
|
|
27
|
+
public API changes, also run:
|
|
28
|
+
|
|
29
|
+
~~~bash
|
|
30
|
+
COVERAGE=true bundle exec rspec
|
|
31
|
+
bundle exec rake docs
|
|
32
|
+
gem build archunit.gemspec --strict
|
|
33
|
+
~~~
|
|
34
|
+
|
|
35
|
+
The coverage suite enforces at least 98% line and 90% branch coverage on every `lib/**/*.rb` runtime
|
|
36
|
+
file, including unloaded files. Specs, benchmarks, and development scripts do not contribute to
|
|
37
|
+
the enforced denominator. A subprocess regression test verifies the actual filtered report and
|
|
38
|
+
thresholds without merging its partial probe execution into the full suite. Native symlink tests
|
|
39
|
+
may be skipped on Windows accounts without link privileges; Linux CI exercises those scenarios.
|
|
40
|
+
The documentation task builds
|
|
41
|
+
the complete site, checks the public API guide, rejects unrendered Markdown, and validates internal
|
|
42
|
+
links.
|
|
43
|
+
|
|
44
|
+
Run `bundle exec rake security` separately to refresh advisories and scan the locked development
|
|
45
|
+
and runtime dependencies. See [SECURITY.md](SECURITY.md) for report locations and offline usage.
|
|
46
|
+
The normal test suite uses a synthetic local advisory and never fetches vulnerability data.
|
|
47
|
+
|
|
48
|
+
For a stable release, follow the [pre-release checklist](.github/PRE_RELEASE_CHECKLIST.md) and
|
|
49
|
+
[publishing guide](.github/RELEASING.md). Development allows an unreleased changelog heading and
|
|
50
|
+
installation instructions for the published gem. The separate `--release` metadata check requires
|
|
51
|
+
a valid dated heading and an installation example targeting the version being published.
|
|
52
|
+
|
|
53
|
+
## Design expectations
|
|
54
|
+
|
|
55
|
+
- Write the fluent sentence first and read it aloud.
|
|
56
|
+
- Prefer idiomatic Ruby when a sibling convention conflicts with the language.
|
|
57
|
+
- Keep builders immutable and lazy; only terminals perform analysis.
|
|
58
|
+
- Return structured violations for architecture disagreements—do not raise until the assertion
|
|
59
|
+
boundary.
|
|
60
|
+
- Add a focused unit test and an end-to-end fluent API test for behavior changes.
|
|
61
|
+
- Keep `# frozen_string_literal: true` in Ruby files and leave RuboCop clean.
|
|
62
|
+
- Keep `README.md` as a concise starting point; put full workflows in `GUIDE.md` and exact
|
|
63
|
+
semantics in `API.md`. Label unreleased features and update `CHANGELOG.md` for behavior changes.
|
|
64
|
+
- Mark runnable README snippets with `example:` comments and extend the documentation-example
|
|
65
|
+
acceptance checks when adding or changing them.
|
|
66
|
+
|
|
67
|
+
## Pull requests
|
|
68
|
+
|
|
69
|
+
A useful pull request explains the user-facing problem, the chosen behavior, any deliberate
|
|
70
|
+
cross-language difference, and how it was tested. Please keep unrelated formatting or refactors out
|
|
71
|
+
of the same change.
|
|
72
|
+
|
|
73
|
+
By participating, you agree to follow the [Code of Conduct](CODE_OF_CONDUCT.md). Security reports
|
|
74
|
+
must follow [SECURITY.md](SECURITY.md), not a public issue.
|
|
75
|
+
|