testable-documentation

Type: fact
Tags: amigosdocumentationtestingexamplesdeveloper-experience
Created: Thu Oct 30 2025 00:00:00 GMT+0000 (Coordinated Universal Time)

Testable Documentation - Living Code Examples

Every code snippet in Amigos is executable, testable, and trackable. Documentation that can’t run is already outdated.

Core Philosophy

ā€œIf it’s not runnable, it’s not documentation - it’s wishful thinking.ā€

The Go Example Pattern, Everywhere

Go pioneered testable documentation with func Example:

func ExampleReverse() {
    fmt.Println(Reverse("hello"))
    // Output: olleh
}

Amigos takes this concept and makes it universal:

How It Works in Amigos

Traditional Documentation (Dead)

# How to create a blog
Here's how you might create a blog:
```go
blog := NewBlog("My Blog")  // This might work?
blog.AddPost(post)          // Hopefully still valid

### Amigos Documentation (Living)
```markdown
# How to create a blog
import "hub.amigos.dev/blog@v1.2.3"

Example_CreateBlog() {
    blog := blog.New("My Blog")
    post := blog.NewPost("Hello", "World")
    blog.Publish(post)
    
    fmt.Println(blog.PostCount())
    fmt.Println(post.URL())
    // Output:
    // 1
    // /posts/hello
}

Key Features

1. Executable Snippets

Every code block can be executed directly:

amigos run docs/example.md#Example_CreateBlog

2. Version Pinning

Examples pin to specific versions:

import "hub.amigos.dev/auth@v2.1.0"

3. Output Verification

Expected outputs are part of the documentation:

// Output:
// user: alice
// role: admin

4. Import Tracking

Know which examples use your service:

amigos examples hub.amigos.dev/auth
> Found 47 examples across 23 services

5. Breakage Detection

When you update a service, see which examples break:

amigos test-downstream hub.amigos.dev/auth@v3.0.0
> Testing 47 examples...
> āŒ 3 examples need updating
> āœ… 44 examples still work

Implementation Details

Example Metadata

---
example: CreateBlog
imports: 
  - hub.amigos.dev/blog@v1.2.3
  - hub.amigos.dev/auth@v2.1.0
tested: 2024-03-15T10:30:00Z
status: passing
---

Continuous Testing

The Example Contract

When you write an example:

  1. It must compile
  2. It must run
  3. It must produce expected output
  4. It must use real imports
  5. It must represent actual usage

Benefits

For Documentation Writers

For Service Authors

For Learners

Advanced Features

1. Stateful Examples

Example_UserSession() stateful {
    // Setup: create test user
    user := auth.Register("alice", "password")
    
    // Example: login flow
    session := auth.Login("alice", "password")
    profile := session.GetProfile()
    
    fmt.Println(profile.Username)
    // Output: alice
    
    // Cleanup: automatic
}

2. Example Inheritance

Example_AdminPanel() extends Example_UserSession {
    // Continues from previous state
    session.GrantAdmin()
    
    fmt.Println(session.IsAdmin())
    // Output: true
}

3. Interactive Examples

Example_Calculator() interactive {
    calc := calculator.New()
    
    // User can modify these values
    result := calc.Add(5, 3)
    
    fmt.Println(result)
    // Output: 8
}

4. Performance Examples

Example_BulkInsert() benchmark {
    db := database.New()
    
    start := time.Now()
    for i := 0; i < 1000; i++ {
        db.Insert(Record{ID: i})
    }
    
    fmt.Printf("Inserted 1000 records in %v", time.Since(start))
    // Output: Inserted 1000 records in 50ms ± 10ms
}

The Network Effect

Discovery Through Examples

Example-Driven Development

  1. Write the example first
  2. Make it pass
  3. Ship the feature
  4. Examples become the spec

Integration with Amigos

In the Import Economy

In the Editor

// Type "blog.New" and see:
// šŸ“– 15 examples available
// ⭐ Most popular: Example_SimpleBlog
// šŸ”„ Last updated: 2 hours ago
// ā–¶ļø Run example inline

In the Service Page

Each service shows:

Philosophy Extensions

ā€œShow, Don’t Tellā€

Instead of explaining what your service does, show it in action.

ā€œTest by Teachingā€

The best test suite is one that teaches others how to use your code.

ā€œDocumentation as Codeā€

Treat examples with the same rigor as production code.

Implementation Checklist

The Ultimate Goal

Every piece of code shared in the Amigos ecosystem is runnable, testable, and useful.

No more dead documentation. No more ā€œthis should work.ā€ No more version mismatches.

Just living, breathing examples that evolve with the platform.

Questions

The future of documentation isn’t static text - it’s living code that teaches, tests, and evolves.

See also

← Back to Knowledge Base