AgentStack
SKILL verified MIT Self-run

Test Patterns

skill-d-o-hub-rust-self-learning-memory-test-patterns · by d-o-hub

Unified testing patterns for Rust: unit testing quality, episodic memory operations, and async/tokio code. Use when writing tests, reviewing test code, or diagnosing test failures.

No reviews yet
0 installs
17 views
0.0% view→install

Install

$ agentstack add skill-d-o-hub-rust-self-learning-memory-test-patterns

✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

Are you the author of Test Patterns? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Test Patterns for Rust Self-Learning Memory

Unified testing patterns covering unit testing quality, episodic memory domain tests, and async/tokio patterns.

Naming Convention

test___ (e.g., test_withdraw_valid_amount_decreases_balance)

AAA Pattern

#[tokio::test]
async fn test_save_episode() -> anyhow::Result {
    let memory = create_test_memory().await;    // Arrange
    memory.save_episode(&episode).await?;       // Act
    assert_eq!(retrieved.task_description, "Test");  // Assert
    Ok(())
}

Core Principles

  • Single behavior per test, one reason to fail
  • Mock external deps (APIs, DBs, filesystem); don't mock value types
  • Use do-memory-test-utils for setup

Anti-Patterns

| Bad | Fix | |-----|-----| | Testing std library | Test your code | | No assertions | Verify outcomes | | Multiple behaviors | Split tests | | .unwrap() chains | Use Result with ? |

Episodic Memory Testing

State: Created -> InProgress -> Completed/Failed

#[tokio::test]
async fn test_episode_lifecycle() {
    let id = memory.start_episode("Test", ctx, TaskType::CodeGen).await;
    memory.complete_episode(id.clone(), TaskOutcome::Success, None).await?;
    assert_eq!(memory.get_episode(&id).await?.outcome, TaskOutcome::Success);
}

Async/Tokio Patterns

#[tokio::test]                                       // Basic async
#[tokio::test(start_paused = true)]                  // Time control (no real wait)
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]  // Concurrent

Mock Storage

pub struct MockTursoStorage { episodes: Arc>> }
#[async_trait]
impl StorageBackend for MockTursoStorage {
    async fn create_episode(&self, episode: &Episode) -> Result { /* ... */ }
}

Async Pitfalls

| Bad | Good | |-----|------| | std::thread::sleep() | tokio::time::sleep().await | | Blocking runtime | spawn_blocking for sync |

Pre-Commit Checklist

  • [ ] Names: test___, AAA separation, single behavior
  • [ ] Dependencies mocked, #[tokio::test] for async, Result with ?

Success Metrics

Deploy without manual testing | Failures pinpoint exact problems | Tests run in milliseconds

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet — be the first.

Versions

  • v0.1.0 Imported from the upstream source.