2026-11-27 16:19 UTC

SpecGuardian generates Go conformance tests from FizzBee specs

state: expiredheat: mediumuncertainty: mediumrelevance: mediumformal-specifications coding-agents software-verificationmrasu

What is this?

SpecGuardian is a Go testing tool by GitHub user mrasu that connects FizzBee formal specifications to tests of an implementation. In a Show HN post dated November 2, 2026, its author describes generating tests from FizzBee model-checking results and checking whether observed application states are allowed by the spec, including after injected I/O failures. The repository includes a cache-aside example and says the project is under development.

Why it matters

This offers a practical bridge between formal modeling and implementation testing: a spec can help expose bugs that ordinary success-path tests miss, such as an unsafe operation order revealed only when I/O fails. It could make a rigorous conformance check more approachable for Go teams, including teams building AI-generated code, but it still requires a useful spec and project-specific setup. The supplied evidence establishes a working example, not broad adoption or effectiveness across real-world systems.

Current assessment

New: mrasu announced SpecGuardian on Hacker News on November 2, 2026; the linked GitHub repository is the primary evidence supplied. Its documented workflow uses FizzBee to explore allowed states, generates Go tests for one Action invocation at a time, and compares observed implementation state with permitted spec states. Tests can inject an error immediately before supported I/O calls. The included cache-aside example demonstrates detection of an ordering bug that can leave the database and cache in a combination disallowed by the spec. The tool does not automatically connect every project to its spec: users must configure providers, observation and comparison, and application-specific setup and execution code. The repository describes the project as under development and warns APIs or generated code may change. No independent benchmark, adoption evidence, or validation beyond the supplied project materials is provided; the broader implication is potential, not demonstrated impact.

Measured heat

no measured readings yet โ€” the hourly heat pass fills this in

How the heat travelled

09-26 14:00โญ origin echo-reconstructedThe repository README says: โ€œA FizzBee spec describes the state transitions your system allows. However, the spec does not test whether your
mrasu on github (echo) ยท attributed from hn.story.50325878
โ€”
11-01 14:11first on hacker news ยท published ยท +864.2hShow HN: Let formal specs test AI implementations
mrasu
โ€”
11-01 14:11amplified on hacker news ๐Ÿ‘‘hn.story.50325878
mrasu
peak 1 ยท 0 comments ยท 104% of case engagement
11-01 14:25our radar first saw it ยท +864.4hdiscovery anchor: hn.story.50325878โ€”

Evidence (2) โ€” โญ canonical anchor

sourceobjectauthorscorecomments
๐ŸŸง hnShow HN: Let formal specs test AI implementations
Retrieved article excerpt

Open article ยท Retrieved 2026-11-01T14:27:51.726378+00:00

# Spec Guardian

[SpecGuardian](https://github.com/mrasu/spec-guardian/blob/main/docs/img/specguardian-logo.png)

Let formal specs test AI implementations.

A [FizzBee](https://fizzbee.io/) spec describes the state transitions your system allows. However, the spec does not test whether your implementation follows those transitions. SpecGuardian turns FizzBee's results into tests that check whether your implementation reaches an allowed state.

SpecGuardian lets you verify that an AI-generated implementation actually conforms to your specification.

[FizzBee explores allowed states; SpecGuardian generates tests that run normally and with injected I/O failures, then check the resulting states against the specification.](https://github.com/mrasu/spec-guardian/blob/main/docs/img/specguardian-workflow.png)

## From Spec to Test: Cache-Aside

In this cache-aside example, a `WriteAndInvalidate` action stores a new value in the database, then invalidates the corresponding cache entry. The [tutorial spec](https://github.com/mrasu/spec-guardian/blob/main/examples/tutorial_cache_aside_write/docs/spec/CacheAside.fizz) models each operation as atomic and allows a crash before or between them:

```
@conformance
role CacheAside:
  fair action WriteAndInvalidate:
    # Yield to allow a crash before the first I/O.
    atomic:
      pass

    # Write to the database first, then invalidate the cache.
    db.write(self.key, self.write_value)
    cache.delete_cache(self.key)
```

SpecGuardian [generates Go tests](https://github.com/mrasu/spec-guardian/blob/main/examples/tutorial_cache_aside_write/conformance/specguardian/cacheaside_conformance_generated_test.go) from FizzBee's results. They compare the observed state after the action with states allowed by the spec, including states reached when an I/O operation fails.

For example, the generated Go test injects an error into the implementation just before cache invalidation, then checks whether the resulting state is allowed by the spec.

### Catching a Spec Mismatch

Consider an ordering bug in `WriteAndInvalidate`: cache invalidation runs before the database write.

```
func (ca *CacheAside) WriteAndInvalidate(ctx context.Context, input *Input) (*Output, error) {
+  if err := ca.cache.Delete(ctx, input.Key); err != nil {
+    return nil, err
+  }
+
   if err := ca.db.Write(ctx, input.Key, input.Value); err != nil {
     return nil, err
   }

-  if err := ca.cache.Delete(ctx, input.Key); err != nil {
-    return nil, err
-  }
-
   return &Output{Key: input.Key, Value: input.Value}, nil
}
```

Both orders produce the same final state on success. But when the database write fails after cache invalidation, the database still holds `old` value and the cache entry is gone. The spec writes to the database first, so stopping at any point cannot produce this combination.

The test fails with the following output (excerpt):

```
actual state does not match any allowed state:
    I/O events:
      1. valkey.Do
      2. sql.BeginTx [fault injected; call not executed]
```

The mismatch excerpts show the unchanged database value and missing cache entry:

```
Fields.DB.Records[0].Value (-want +got):
  string(
-  "new",
+  "old",
  )
```

```
Fields.Cache.CachedRecords (-want +got):
  map[string]string{
-  "cached": "old",
  }
```

## Getting Started

To try this example locally, start with the included cache-aside write tutorial. You'll need Go and Docker Compose; the FizzBee exploration results and generated tests are included.

Clone the repository and run the example:

```
git clone https://github.com/mrasu/spec-guardian.git
cd spec-guardian/examples/tutorial_cache_aside_write
docker compose up -d
go test -count=1 -tags=specguardian ./conformance/...
```

The test passes, checking normal completion and injected I/O failures. Apply the diff above to `cache_aside.go` and rerun the `go test` command to reproduce the failure. Restore the original order to make the test pass again.

## How It Works

Here's how SpecGuardian works:

1. FizzBee explores the possible states described by the spec.
2. SpecGuardian generates Go tests from the exploration results.
3. Either AI or you write the setup and Action execution code, configure providers in `specguardian.yml`, and write any remaining state observation code.
4. The tests run a function normally and with an error injected immediately before a supported I/O call, then compare the observed state with states allowed by the spec.

`specguardian.yml` configures state observation and comparison. See the [configuration schema](https://github.com/mrasu/spec-guardian/blob/main/docs/specguardian.schema.yaml) for available settings and the [example configuration](https://github.com/mrasu/spec-guardian/blob/main/examples/tutorial_cache_aside_write/specguardian.yml) for an example.

## When to Use

SpecGuardian checks whether an Action ends in a state allowed by the FizzBee spec, including after an injected I/O failure. It complements other tests:

- **Different from unit tests:** It checks the resulting application state against the spec, beyond assertions about individual functions.
- **Different from integration tests:** The expected states come from a FizzBee spec defined independently of the implementation.

## Generate Tests for Your Project

To generate tests for your project, install [FizzBee](https://fizzbee.io/) and run these commands from your Go module directory:

```
fizz --output-dir path/to/output_dir path/to/YourSpec.fizz
go get -tool github.com/mrasu/spec-guardian
go tool spec-guardian init --fizzbee-output-dir path/to/output_dir

# Configure observation and comparison.
$EDITOR specguardian.yml

go generate ./conformance

# Replace <role> with the generated role name and connect the tests to your application.
$EDITOR "conformance/specguardian/<role>_conformance_impl_test.go"

go mod tidy
go test -tags=specguardian ./conformance/...
```

See the [user guide](https://github.com/mrasu/spec-guardian/blob/main/docs/user-guide.md) for the complete setup.

## Examples

- [Cache-aside write tutorial](https://github.com/mrasu/spec-guardian/blob/main/examples/tutorial_cache_aside_write) is the completed project from the [user guide](https://github.com/mrasu/spec-guardian/blob/main/docs/user-guide.md).
- [Cache-aside](https://github.com/mrasu/spec-guardian/blob/main/examples/cache_aside) demonstrates the cache-aside pattern.
- [Idempotent request](https://github.com/mrasu/spec-guardian/blob/main/examples/idempotent_request) demonstrates idempotent requests.
- [Iceberg](https://github.com/mrasu/spec-guardian/blob/main/examples/iceberg) is a real-world example that tests [apache/iceberg-go](https://github.com/apache/iceberg-go).

## Current Scope

SpecGuardian currently generates Go tests for one FizzBee Action invocation at a time. See the [guardian directory](https://github.com/mrasu/spec-guardian/blob/main/guardian) for the available I/O hooks.

SpecGuardian is under development. Its public APIs or generated Go code may change.
mrasu10
๐ŸŸง echo.github โญThe repository README says: โ€œA FizzBee spec describes the state transitions your system allows. However, the spec does not test whether yourmrasuโ€”โ€”

Interpretation history

Decision trace