feat: persist and dispatch client command input
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package spool
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
@@ -12,6 +13,69 @@ import (
|
||||
"github.com/rvbox/rvbox/internal/domain"
|
||||
)
|
||||
|
||||
func TestExecutionSpecIsDurableAndQuotaCounted_HP_DISPATCH_07(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
directory := filepath.Join(t.TempDir(), "spool")
|
||||
store := openTestStore(t, ctx, directory, DefaultTombstoneLimit)
|
||||
issue := testUUID(t, "019c46f1-1d02-7000-8000-000000000002")
|
||||
spec := []byte("deterministic execution specification")
|
||||
command := testCommand(issue, []byte("spec-hash"))
|
||||
command.ExecutionSpec = spec
|
||||
acceptedAt := time.Date(2026, time.September, 6, 12, 0, 0, 0, time.UTC)
|
||||
accepted, err := store.AcceptCommand(ctx, command, acceptedAt)
|
||||
if err != nil || accepted.Duplicate {
|
||||
t.Fatalf("spec acceptance = %#v, %v", accepted, err)
|
||||
}
|
||||
if !bytes.Equal(accepted.Command.ExecutionSpec, spec) {
|
||||
t.Fatalf("accepted spec = %q, want %q", accepted.Command.ExecutionSpec, spec)
|
||||
}
|
||||
var base, total, specCharge uint64
|
||||
if err := store.db.QueryRowContext(ctx, `SELECT base_charged_bytes, total_charged_bytes FROM commands WHERE issue_uuid = ?`, issue[:]).Scan(&base, &total); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.db.QueryRowContext(ctx, `SELECT charged_bytes FROM command_specs WHERE issue_uuid = ?`, issue[:]).Scan(&specCharge); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if specCharge == 0 || total != base+specCharge {
|
||||
t.Fatalf("spec charge accounting = base=%d total=%d spec=%d", base, total, specCharge)
|
||||
}
|
||||
duplicate, err := store.AcceptCommand(ctx, command, acceptedAt.Add(time.Second))
|
||||
if err != nil || !duplicate.Duplicate || !bytes.Equal(duplicate.Command.ExecutionSpec, spec) {
|
||||
t.Fatalf("spec replay = %#v, %v", duplicate, err)
|
||||
}
|
||||
if err := store.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store = openTestStore(t, ctx, directory, DefaultTombstoneLimit)
|
||||
reopened, err := store.AcceptCommand(ctx, command, acceptedAt.Add(2*time.Second))
|
||||
if err != nil || !reopened.Duplicate || !bytes.Equal(reopened.Command.ExecutionSpec, spec) {
|
||||
t.Fatalf("spec replay after reopen = %#v, %v", reopened, err)
|
||||
}
|
||||
report, err := store.Check(ctx)
|
||||
if err != nil || report.SpecsChecked != 1 {
|
||||
t.Fatalf("spec recovery report = %#v, %v", report, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecutionSpecCorruptionMarksSpoolDirty_BH_DISPATCH_07(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
store := openTestStore(t, ctx, filepath.Join(t.TempDir(), "spool"), DefaultTombstoneLimit)
|
||||
issue := testUUID(t, "019c46f1-1d02-7000-8000-000000000003")
|
||||
command := testCommand(issue, []byte("spec-corrupt"))
|
||||
command.ExecutionSpec = []byte("payload")
|
||||
if _, err := store.AcceptCommand(ctx, command, time.Now().UTC()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := store.db.ExecContext(ctx, `UPDATE command_specs SET payload = ? WHERE issue_uuid = ?`, []byte("tampered"), issue[:]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := store.Check(ctx); !errors.Is(err, ErrStoredPayloadChecksum) {
|
||||
t.Fatalf("corrupt execution spec Check error = %v, want ErrStoredPayloadChecksum", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreDurableIdentityAndSingleInstance_HP_CLIENT_01(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
|
||||
Reference in New Issue
Block a user