43 lines
1.7 KiB
Go
43 lines
1.7 KiB
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
agentv1 "git.ipao.vip/rogee/go-sip/gen/agent/v1"
|
|
"git.ipao.vip/rogee/go-sip/internal/contract"
|
|
"git.ipao.vip/rogee/go-sip/internal/testfixture"
|
|
)
|
|
|
|
func TestExecutionJournalFailureCannotReplayMemoryAsSuccess(t *testing.T) {
|
|
s := activatedServer(time.Date(2026, 9, 18, 1, 0, 0, 0, time.UTC), t)
|
|
blocker := filepath.Join(t.TempDir(), "not-a-directory")
|
|
require.NoError(t, os.WriteFile(blocker, []byte("block"), 0600))
|
|
s.executionPath = filepath.Join(blocker, "journal")
|
|
raw, err := testfixture.Execute()
|
|
require.NoError(t, err)
|
|
envelope, payload, err := contract.DecodeExecute(raw)
|
|
require.NoError(t, err)
|
|
req := &agentv1.ExecuteRequest{Meta: testMeta("execute", "execute-key", 1), Binding: &agentv1.ExecutionBinding{TenantId: envelope.TenantID, TenantKey: envelope.TenantKey, ExecutionId: payload.ExecutionID, TaskId: payload.TaskID, TaskItemId: payload.TaskItemID, TaskRevision: payload.TaskRevision, AgentVersionId: payload.AgentVersionID}, CallExecuteJson: raw}
|
|
response, err := s.Execute(context.Background(), req)
|
|
if err == nil || response != nil {
|
|
t.Fatal("failed write acknowledged")
|
|
}
|
|
response, err = s.Execute(context.Background(), req)
|
|
if err == nil || response != nil {
|
|
t.Fatal("memory replay bypassed failed journal")
|
|
}
|
|
}
|
|
|
|
func TestMissingExecutionJournalWithExistingSessionFailsClosed(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "session.json")
|
|
require.NoError(t, os.WriteFile(path, []byte(`{"generations":{"agent-1":1}}`), 0600))
|
|
s := NewServer(ServerOptions{StatePath: path, Status: &agentv1.AgentStatus{AgentId: "agent-1", CellId: "cell-1", BootId: "boot-1"}})
|
|
if s.executionJournalReady() == nil {
|
|
t.Fatal("missing execution history silently reset")
|
|
}
|
|
}
|