Files
DeepSeek-Reasonix/internal/assembly/boot/coalesce_wiring_test.go
T
YHH 23f0a011c4 fix(config): workspace configuration only narrows the user's settings (#11208)
A workspace's reasonix.toml and .reasonix/settings.json are read as
untrusted input.

- [sandbox]: bash may only move to enforce and network only to false;
  forbid_read and denied_domains add to the user's; allow_write entries
  and workspace_root apply only when they resolve inside the workspace.
  ${VAR} in sandbox and proxy paths expands from the process environment
  only.
- [permissions] mode, allow and allow_dynamic_bash, [network] proxy
  settings and [desktop] default_tool_approval_mode are read from the
  user config only; deny and ask add to the user's. An "always allow"
  given in a workspace is stored under the Reasonix home
  (project-grants.json) rather than in the checkout.
- Programs a workspace declares (hooks, language servers, providers,
  tools.search.rg_path, tools.shell.path, [browser], tools.system_one
  endpoints and the local Laya runtime) run only once approved for that
  folder. An approval records the declaration and a digest of the files
  it names, is kept under the Reasonix home, and is checked again before
  each start; a change refuses the start with ErrProjectProgramChanged.
  `reasonix trust` lists and approves them, and saving hooks from the
  hooks page approves the block written. Model settings that named only
  a held-back provider fall back to the user's choice.
- Single program paths may not point into the workspace, a temporary
  directory, an allow_write root or a toolchain cache.
- Sandbox write roots and host write directories keep the identity they
  had when first granted; a root whose identity changed is dropped with
  sandbox.write_root_redirected or sandbox.write_root_changed. The
  host-writable directory list lives in internal/base/hostwrite.
- Every ignored value is reported as a load warning with a typed reason
  (Config.IgnoredProjectSettings); held-back programs raise the
  project_programs_awaiting_approval notice.
2026-09-28 18:21:34 -07:00

95 lines
2.3 KiB
Go

package boot
import (
"context"
"fmt"
"strings"
"sync"
"testing"
"reasonix/internal/contract/event"
"reasonix/internal/contract/provider"
)
type coalesceWiringProvider struct{ deltas int }
func (p *coalesceWiringProvider) Name() string { return "boot-coalesce-test" }
func (p *coalesceWiringProvider) Stream(context.Context, provider.Request) (<-chan provider.Chunk, error) {
ch := make(chan provider.Chunk, p.deltas+1)
for i := range p.deltas {
ch <- provider.Chunk{Type: provider.ChunkText, Text: fmt.Sprintf("w%d ", i)}
}
ch <- provider.Chunk{Type: provider.ChunkDone}
close(ch)
return ch, nil
}
type coalesceRecordSink struct {
mu sync.Mutex
texts []string
events int
}
func (s *coalesceRecordSink) Emit(e event.Event) {
s.mu.Lock()
defer s.mu.Unlock()
if e.Kind == event.Text {
s.events++
s.texts = append(s.texts, e.Text)
}
}
// TestBuildCoalescesAgentStreamDeltas pins the wiring, not the coalescer: the
// executor emits into the shared boot sink directly, so coalescing must wrap
// that sink — wrapping only the controller's reference leaves the per-chunk
// stream untouched (the regression this test exists for).
func TestBuildCoalescesAgentStreamDeltas(t *testing.T) {
isolateConfigHome(t)
dir := robustTempDir(t)
t.Chdir(dir)
const deltas = 40
provider.Register("boot-coalesce-test", func(provider.Config) (provider.Provider, error) {
return &coalesceWiringProvider{deltas: deltas}, nil
})
writeFile(t, dir, "reasonix.toml", `
default_model = "test-model"
[agent]
system_prompt = "BASE"
[[providers]]
name = "test-model"
kind = "boot-coalesce-test"
model = "x"
`)
approveWorkspace(t, dir)
sink := &coalesceRecordSink{}
ctrl, err := Build(context.Background(), Options{Sink: sink})
if err != nil {
t.Fatalf("Build: %v", err)
}
defer ctrl.Close()
if err := ctrl.Run(context.Background(), "stream"); err != nil {
t.Fatalf("Run: %v", err)
}
sink.mu.Lock()
events := sink.events
joined := strings.Join(sink.texts, "")
sink.mu.Unlock()
var want strings.Builder
for i := range deltas {
fmt.Fprintf(&want, "w%d ", i)
}
if joined != want.String() {
t.Fatalf("concatenated deltas = %q, want %q", joined, want.String())
}
if events >= deltas/2 {
t.Fatalf("frontend sink saw %d text events for %d provider chunks — agent stream is not coalesced", events, deltas)
}
}