Files
AgentCompany/builtin-skills/software-engineer/clean-architecture/references/test-boundary-verification.md
T
ZacharyZhang-NY e74dafcd36 Silence render-disposed spam, unbreak bundled skills, drop board wake
Three independently ugly bugs that all fed the same log flood:

* Electron's `WebFrameMain.send` writes every "Render frame was disposed"
  to stderr via `console.error`. When the worker fans a second
  agent-event past a reloading renderer, we produced thousands of
  identical lines and stalled the main loop on stderr I/O. Added a
  `mainFrame.detached` guard so the send is short-circuited before
  Electron's own catch block fires, and installed a targeted filter in
  `suppress-warnings.ts` (now actually imported from the entry point)
  so the specific `console.error("Error sending from webFrameMain:"…)`
  noise never reaches the terminal. Any other payload still surfaces.

* `dispatchAgentMessage` accepted the human-reader sentinel as a wake
  target when an agent replied to `__board__` — `wakeAgentIfPossible`
  then called `db.getAgent("__board__")`, threw, and the dispatcher
  kept repeating on every send. Strip `HUMAN_SENDER_ID` at
  `resolveMessageWakeTargets`, and keep a defense-in-depth guard in the
  heartbeat so a stray caller (future automation fan-out) cannot
  reintroduce the crash.

* Pi's skills loader rejects any SKILL.md whose frontmatter `name`
  diverges from its parent directory. The four bundled `my-writing-style`
  copies declared `name: writing-style-skill`, so every install emitted
  a warning and dropped the skill. They also lived as orphan gitlinks
  (mode 160000 without .gitmodules), and the global `*.md` gitignore
  hid every other SKILL.md from version control. Fixed the frontmatter
  to match the dir, converted the dangling submodules to plain trees,
  and allowlisted `builtin-skills/**/*.md` so a fresh clone carries the
  catalogue instead of silently losing it.
2026-04-20 08:13:48 -04:00

107 lines
3.4 KiB
Markdown

---
title: Verify Architectural Boundaries with Tests
impact: LOW-MEDIUM
impactDescription: prevents boundary erosion, enforces dependency rules
tags: test, boundaries, architecture, enforcement
---
## Verify Architectural Boundaries with Tests
Use automated tests to enforce that dependency rules are followed. Architecture tests catch violations before they become entrenched patterns.
**Incorrect (no boundary verification):**
```java
// Over time, developers add shortcuts
// domain/Order.java
import org.springframework.stereotype.Component; // Framework in domain!
import javax.persistence.Entity; // JPA in domain!
// application/CreateOrderUseCase.java
import com.stripe.Stripe; // Direct payment vendor dependency!
import infrastructure.email.SendGridClient; // Infrastructure in application!
// No tests catch these violations
// They accumulate until refactoring becomes impossible
```
**Correct (architecture tests enforce boundaries):**
```java
// Using ArchUnit (Java) or similar tools
@AnalyzeClasses(packages = "com.myapp")
class ArchitectureTest {
@ArchTest
static final ArchRule domain_should_not_depend_on_infrastructure =
noClasses()
.that().resideInAPackage("..domain..")
.should().dependOnClassesThat()
.resideInAPackage("..infrastructure..");
@ArchTest
static final ArchRule domain_should_not_use_frameworks =
noClasses()
.that().resideInAPackage("..domain..")
.should().dependOnClassesThat()
.resideInAnyPackage(
"org.springframework..",
"javax.persistence..",
"jakarta.persistence.."
);
@ArchTest
static final ArchRule usecases_should_not_access_controllers =
noClasses()
.that().resideInAPackage("..application..")
.should().dependOnClassesThat()
.resideInAPackage("..interface..");
@ArchTest
static final ArchRule dependencies_point_inward =
layeredArchitecture()
.consideringAllDependencies()
.layer("Domain").definedBy("..domain..")
.layer("Application").definedBy("..application..")
.layer("Infrastructure").definedBy("..infrastructure..")
.layer("Interface").definedBy("..interface..")
.whereLayer("Domain").mayNotAccessAnyLayer()
.whereLayer("Application").mayOnlyAccessLayers("Domain")
.whereLayer("Infrastructure").mayOnlyAccessLayers("Domain", "Application")
.whereLayer("Interface").mayOnlyAccessLayers("Domain", "Application");
}
// TypeScript equivalent using dependency-cruiser
// .dependency-cruiser.js
module.exports = {
forbidden: [
{
name: 'domain-no-infra',
from: { path: '^src/domain' },
to: { path: '^src/infrastructure' }
},
{
name: 'domain-no-frameworks',
from: { path: '^src/domain' },
to: { path: 'node_modules/(express|prisma|typeorm)' }
}
]
};
```
**Run in CI:**
```yaml
# .github/workflows/ci.yml
- name: Check architecture
run: |
./gradlew archTest # Java with ArchUnit
npx depcruise src # TypeScript with dependency-cruiser
```
**Benefits:**
- Violations caught immediately in CI
- New developers can't accidentally break boundaries
- Architecture documentation that stays accurate
Reference: [ArchUnit](https://www.archunit.org/)