Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions harness/attempt_public_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,9 @@ func newAttemptTableFixture(t *testing.T, store harness.Storage, conversationFn,
return harness.PreparedExecution{
Capture: publicCapture(),
Open: func(context.Context, harness.OperationAdmission) (harness.Execution, error) {
return harness.Execution{
Model: conversationFn,
CompactModel: compactFn,
NormalizeTool: publicNormalize,
Tool: func(_ context.Context, call model.ToolCall) harness.PreparedTool {
return harness.PreparedTool{Immediate: &harness.ToolOutcome{Result: model.ToolResult{CallID: call.ID, Status: model.ResultError, Content: "no tools"}}}
},
Retry: retry,
}, nil
exec := publicExecution(conversationFn, compactFn)
exec.Retry = retry
return exec, nil
},
}, nil
}})
Expand Down
9 changes: 1 addition & 8 deletions harness/compact_manual_public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,7 @@ func newCompactManualFixture(t *testing.T, store harness.Storage, conversation,
f.defaultPrep = harness.PreparedExecution{
Capture: compactManualCapture(),
Open: func(context.Context, harness.OperationAdmission) (harness.Execution, error) {
return harness.Execution{
Model: conversation.effect,
CompactModel: compact.effect,
NormalizeTool: publicNormalize,
Tool: func(_ context.Context, call model.ToolCall) harness.PreparedTool {
return harness.PreparedTool{Immediate: &harness.ToolOutcome{Result: model.ToolResult{CallID: call.ID, Status: model.ResultError, Content: "no tools"}}}
},
}, nil
return publicExecution(conversation.effect, compact.effect), nil
},
}
ctx, cancel := context.WithCancel(context.Background())
Expand Down
32 changes: 22 additions & 10 deletions harness/compact_manual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,21 +396,13 @@ func TestCompactAdmissionCodecRules(t *testing.T) {
admission := wireObject(t, raw)["admission"]
mutatedAdmission := setKey(admission, "admitted_entry", json.RawMessage(`{"session_id":"`+testSessionID+`","entry_id":"`+hexID(1)+`"}`))
mutated := setKey(raw, "admission", mutatedAdmission)
if _, err := decodeOperationRegister(Register{Key: RegisterKey{SessionID: testSessionID, Kind: RegisterOperation, OperationID: testOpID}, Payload: mutated}); err == nil {
t.Fatalf("compact payload with an admitted entry decoded")
} else if !strings.Contains(err.Error(), "admitted_entry") {
t.Fatalf("error %v, want the admitted_entry member named", err)
}

// A message payload without the member rejects.
messageRaw, err := encodeOperationRegister(validOperationRecord())
if err != nil {
t.Fatalf("encode message register: %v", err)
}
messageless := setKey(messageRaw, "admission", deleteKey(t, wireObject(t, messageRaw)["admission"], "admitted_entry"))
if _, err := decodeOperationRegister(Register{Key: RegisterKey{SessionID: testSessionID, Kind: RegisterOperation, OperationID: testOpID}, Payload: messageless}); err == nil {
t.Fatalf("message payload without its admitted entry decoded")
}

// An unknown kind rejects on both directions.
unknown := compactOperationRecord(testOpID)
Expand All @@ -419,8 +411,28 @@ func TestCompactAdmissionCodecRules(t *testing.T) {
t.Fatalf("unknown request kind encoded")
}
unknownWire := setKey(raw, "admission", setKey(admission, "request_kind", json.RawMessage(`"bogus"`)))
if _, err := decodeOperationRegister(Register{Key: RegisterKey{SessionID: testSessionID, Kind: RegisterOperation, OperationID: testOpID}, Payload: unknownWire}); err == nil {
t.Fatalf("unknown request kind decoded")

// The raw payloads above bypass the production encoder: each names one
// invalid persisted state the decoder must refuse.
rejections := []struct {
name string
payload json.RawMessage
wantText string
}{
{"compact payload carrying the admitted entry", mutated, "admitted_entry"},
{"message payload without the admitted entry", messageless, ""},
{"unknown request kind", unknownWire, ""},
}
for _, tc := range rejections {
t.Run(tc.name, func(t *testing.T) {
_, err := decodeOperationRegister(Register{Key: RegisterKey{SessionID: testSessionID, Kind: RegisterOperation, OperationID: testOpID}, Payload: tc.payload})
if err == nil {
t.Fatalf("%s decoded", tc.name)
}
if tc.wantText != "" && !strings.Contains(err.Error(), tc.wantText) {
t.Fatalf("error %v, want the %s member named", err, tc.wantText)
}
})
}
}

Expand Down
42 changes: 19 additions & 23 deletions harness/effect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ func executeDirect(h *Harness, c *coordinator, execCtx context.Context, operatio
return h.finishExecution(c, run, operationID, res, err, closeExecution)
}

// newEffectHarness admits one running Operation ("op-1") with the given
// prepared physical model request function and returns the pieces the effect
// fixtures need.
func newEffectHarness(t *testing.T, modelFn func(context.Context, model.Request) (model.Stream, error)) (*Harness, *graphStorage, *coordinator, string) {
// newAdmittedHarness admits one running Operation ("op-1") over a fresh empty
// store under the given Harness context and prepared execution: the shared
// admission construction of the effect and opener fixtures.
func newAdmittedHarness(t *testing.T, hctx context.Context, prepared PreparedExecution) (*Harness, *graphStorage, *coordinator, string) {
t.Helper()
store := emptyStore(t)
prepared := modelPrepared(modelFn)
h := newTestHarness(t, store, func(context.Context, PreparationRequest) (PreparedExecution, error) {
h, err := New(hctx, Dependencies{Storage: store, Prepare: func(context.Context, PreparationRequest) (PreparedExecution, error) {
return prepared, nil
})
}})
if err != nil {
t.Fatalf("New: %v", err)
}
session, err := h.CreateSession(context.Background(), CreateSessionRequest{Workspace: "/tmp/works", AgentType: "coder"})
if err != nil {
t.Fatalf("CreateSession: %v", err)
Expand All @@ -46,6 +48,14 @@ func newEffectHarness(t *testing.T, modelFn func(context.Context, model.Request)
return h, store, c, session.Identity.SessionID
}

// newEffectHarness admits one running Operation ("op-1") with the given
// prepared physical model request function and returns the pieces the effect
// fixtures need.
func newEffectHarness(t *testing.T, modelFn func(context.Context, model.Request) (model.Stream, error)) (*Harness, *graphStorage, *coordinator, string) {
t.Helper()
return newAdmittedHarness(t, context.Background(), modelPrepared(modelFn))
}

// invokeModelEffect drives one model effect with a validated request; a nil
// assemble callback runs the real Agent assembly.
func invokeModelEffect(t *testing.T, me agent.ModelEffect, assemble agent.AssemblyCallback) (agent.ModelSettlement, error) {
Expand Down Expand Up @@ -1004,24 +1014,10 @@ func (s *toolSpy) dispatched() []string {
// pieces the execution fixtures need.
func newOpenerHarness(t *testing.T, open func(context.Context, OperationAdmission) (Execution, error)) (*Harness, *graphStorage, *coordinator, string, PreparedExecution, context.CancelFunc) {
t.Helper()
store := emptyStore(t)
prepared := PreparedExecution{Capture: testCapture(), Open: open}
hctx, cancel := context.WithCancel(context.Background())
h, err := New(hctx, Dependencies{Storage: store, Prepare: func(context.Context, PreparationRequest) (PreparedExecution, error) {
return prepared, nil
}})
if err != nil {
t.Fatalf("New: %v", err)
}
session, err := h.CreateSession(context.Background(), CreateSessionRequest{Workspace: "/tmp/works", AgentType: "coder"})
if err != nil {
t.Fatalf("CreateSession: %v", err)
}
if _, disposition := mustAdmitWithoutExecution(t, h, session.Identity.SessionID, testOpID, admissionContent("hello")); disposition != DispositionAdmitted {
t.Fatalf("disposition %q, want admitted", disposition)
}
c := leaseCoordinator(t, h, session.Identity.SessionID)
return h, store, c, session.Identity.SessionID, prepared, cancel
h, store, c, sessionID := newAdmittedHarness(t, hctx, prepared)
return h, store, c, sessionID, prepared, cancel
}

// newExecutionHarness admits one running Operation ("op-1") under a cancelable
Expand Down
Loading