Approve/commit now write FAV staging in the domain transaction, recover-apply materializes scratch collections, and unpublished or GET paths cannot mutate the registry. Co-authored-by: Cursor <cursoragent@cursor.com>
61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"chat-agent-system/internal/artifactvault"
|
|
"chat-agent-system/internal/config"
|
|
)
|
|
|
|
type writeFailRegistry struct {
|
|
*artifactvault.MemoryRegistry
|
|
requests int
|
|
}
|
|
|
|
func (w *writeFailRegistry) Request(ctx context.Context, facts artifactvault.Facts, req artifactvault.PublishRequest) (*artifactvault.Artifact, *artifactvault.Staging, error) {
|
|
w.requests++
|
|
return nil, nil, fmt.Errorf("GET must not write")
|
|
}
|
|
|
|
func TestTryVaultDegradedDoesNotRequest(t *testing.T) {
|
|
ctx := context.Background()
|
|
mem := artifactvault.NewMemoryRegistry()
|
|
spy := &writeFailRegistry{MemoryRegistry: mem}
|
|
dir := t.TempDir()
|
|
store, err := artifactvault.NewFilesystemStore(dir, "vault-id-test", []byte("0123456789abcdef0123456789abcdef"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pub := &artifactvault.Publisher{Reg: mem, Store: store}
|
|
facts := artifactvault.Facts{
|
|
ArtifactType: artifactvault.TypeAgentCommit, CandidateStatus: "committed", OutputSnapshotID: 7,
|
|
ChangeKind: "agent_commit", ChangeToSnapshotID: 7, Classification: artifactvault.ClassificationOK,
|
|
Payload: []byte("# ledger\n"),
|
|
}
|
|
req := artifactvault.PublishRequest{
|
|
ArtifactType: artifactvault.TypeAgentCommit, Environment: "dev", ProjectExternalKey: "3",
|
|
LogicalResourceID: "doc_nowrite", SourceEventKind: "agent_commit", SourceEventID: "ev-nowrite",
|
|
Payload: []byte("# ledger\n"), TerminalState: "committed",
|
|
}
|
|
if _, _, err := mem.Request(ctx, facts, req); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := pub.Drain(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s := &Server{
|
|
cfg: &config.Config{Env: "dev", FAVDegradedRead: true, DataDir: t.TempDir()},
|
|
vaultReg: spy,
|
|
vaultPub: &artifactvault.Publisher{Reg: spy, Store: store},
|
|
}
|
|
b, _, err := s.tryVaultDegraded(ctx, "dev", "doc_nowrite", "3")
|
|
if err != nil || string(b) != "# ledger\n" {
|
|
t.Fatalf("degraded: %v %q", err, b)
|
|
}
|
|
if spy.requests != 0 {
|
|
t.Fatalf("GET path issued %d Request writes", spy.requests)
|
|
}
|
|
}
|