2026-08-25 03:28:12 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
perf(skills): batch install verification and live installer progress (#2960)
* perf(skills): batch install verification and keep caches under budget
The tail of an install (agent_done -> verified) issued one remote exec per
check: two for permission normalisation, one per bundled script for the tree
check, three for the scratch wipe. A skill with twenty scripts paid thirty-
odd round trips, each carrying a hidden bootstrap exec and a distributed-
lock resolve, while the console sat on a finished agent with no feedback.
- normalizeSkillPermissions sends chmod and chown as one command.
- verifySkillTree folds the SKILL.md probe and one test per script into a
single command that reports every missing file instead of stopping at the
first. Exit codes 0/1/3 carry the verdict, stderr lines are the final
messages, and the two existing error texts survive verbatim.
- cleanImageScratch merges the workspace reset, the directory restore and
the cache pass into one command whose exit code is still owned by the
strict workspace half. Package caches are no longer wiped wholesale: uv,
npm and pnpm trim their own entries, and the pip/uv/npm/pnpm totals of
both accounts are kept while under 256MB and wiped whole over it, so the
next install resolves a previous download instead of the network.
- The install prompt hands the agent absolute paths for uv, npm, pnpm, pip,
python3 and node from the same one-command probe that used to ask only
whether uv exists, so it neither burns a turn on `which` nor gambles on
the shell PATH.
Tests pin the new command shapes exactly, cover quoting of archive-chosen
file names, assert the tree check stays one command regardless of script
count, exercise the budget guard against a real shell, and keep the
workspace-restore failure semantics intact.
* fix(skills): credit a script's own sys.path bootstrap for shipped modules
The python check resolved every import against the script's directory, its
ancestors up to the skill root and the venv - and nothing else. A module the
skill ships in a sibling subtree (lib/image_video.py, imported by
scripts/generate.py) was invisible to that set, so a skill whose scripts
bootstrap their own library directory was refused for a dependency no
package provides, and the repair round that followed could not fix it
either: it installs packages and is forbidden from editing the tree. One
real install spent seven minutes discovering that, three LLM stream
timeouts included.
The verifier now scans what the tree ships and statically evaluates the
sys.path.insert/append calls each script raises before its imports - the
os.path and pathlib idioms, with variables tracked in source order. A
bootstrap proven to raise the directory that provides the module turns the
finding into a note; anything unprovable stays a refusal, now naming the
shipped file instead of pretending a dependency is missing. The refusal is
unrepairable on purpose: no installer round can fix a shipped module the
import cannot reach.
Tests pin the incident's exact shape, the pathlib idiom, and the guarantee
that makes the evaluator safe: a vendored module still cannot satisfy an
import unless the script's own bootstrap provably reaches it, and modules
pip placed under .venv never count as shipped.
* feat(skills): move the install progress bar while the installer works
The progress card sat at the seeded 35% for the whole agent phase and
only jumped at agent_done. Every tool call the transcript already sees
now advances an asymptotic curve 35 + 44·(1 − e^(−k/12)): monotonic for
any round count, converging below the agent_done anchor at 80, topping
out around 75 even when max_iterations is exhausted.
Each step publishes a one-line command summary (engine hint preferred,
80-rune cap) so the admin can see what the installer is doing. After
the first round ends the activity progress is muted — verification and
repair rounds own the stage anchors (80/82) from there, and a repair
round's tool calls must not drag the bar back under them.
* fix(skills): pin the installer agent's thinking mode off
installerAgentConfig left AgentConfig.Thinking nil, which most providers
read as "defer to the model's own default" — a thinking-capable model
would reason on every ReAct round of an install, burning latency and
completion tokens on what are short shell-command turns. Set an explicit
false so every provider path (Qwen enable_thinking, Ollama think, LKEAP
thinking type) receives a deterministic off instead of a default.
* style(skills): gofmt tenant_skill_verify_python_test.go
CI rejects aligned map keys in this table-driven test; gofmt drops the extra spaces.
* docs(skills): drop the duplicated exit 1 line in the python verifier
The shipped-module case was appended by repeating the whole exit 1 block
instead of extending the existing one.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
2026-09-02 04:23:42 +00:00
|
|
|
"strings"
|
2026-08-25 03:28:12 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
|
|
"github.com/Tencent/WeKnora/internal/event"
|
|
|
|
|
"github.com/Tencent/WeKnora/internal/types"
|
|
|
|
|
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// transcriptStreams records what the installer projects onto the replayable
|
|
|
|
|
// stream, in order, so a test can state the shape the console will read.
|
|
|
|
|
type transcriptStreams struct {
|
|
|
|
|
events []interfaces.StreamEvent
|
|
|
|
|
err error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *transcriptStreams) AppendEvent(
|
|
|
|
|
_ context.Context, _, _ string, evt interfaces.StreamEvent,
|
|
|
|
|
) error {
|
|
|
|
|
s.events = append(s.events, evt)
|
|
|
|
|
return s.err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *transcriptStreams) GetEvents(
|
|
|
|
|
_ context.Context, _, _ string, from int,
|
|
|
|
|
) ([]interfaces.StreamEvent, int, error) {
|
|
|
|
|
return s.events[from:], len(s.events), nil
|
|
|
|
|
}
|
|
|
|
|
|
feat(chat): append messages to a running agent turn (#3123)
* feat(stream): persist live-run markers and per-run steer queues
Mid-run sends need a cross-replica pointer to the generating
assistant and a control-plane list that never hits the SSE stream.
* feat(agent): inject queued user messages at ReAct round boundaries
The engine drains the steer sink after each round, persists accepted
rows, and delays Done until after a loop-end inject so the turn can continue.
* feat(session): expose /steer and hand leftover messages to a follow-up turn
Owner-scoped steer routes queue or inject into the live run, single-flight
AgentQA via the live-run marker, and history replay keeps multiple user rows
inside one turn.
* feat(frontend): queue mid-run messages while an agent turn streams
Stop and Send stay visible together, the overlay follows server delivery,
and history splits the transcript around injected user bubbles.
* fix(frontend): type pending and client_id on SteerQueueItem
vue-tsc failed because the overlay sets those fields while POST /steer is in flight.
* fix(session): harden steer persist, handoff, and new_run
Keep SetLiveRun ahead of SSE and roll back orphan turns, make inject
persist idempotent, append-then-delete on rebind, cap overrun rounds,
and stop aborting a live stream when /steer returns new_run.
* fix(session): satisfy pre-push lint on steer paths
Wrap long lines, check discarded Error/Emit results, and keep
context as the first argument so the fork push hook can pass.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-09 08:43:33 +00:00
|
|
|
func (s *transcriptStreams) AppendSteerEvents(
|
|
|
|
|
_ context.Context, _, _ string, _ []interfaces.StreamEvent,
|
|
|
|
|
) error {
|
|
|
|
|
return s.err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *transcriptStreams) GetSteerEvents(
|
|
|
|
|
_ context.Context, _, _ string, from int,
|
|
|
|
|
) ([]interfaces.StreamEvent, int, error) {
|
|
|
|
|
return nil, from, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *transcriptStreams) UpdateSteerEventData(
|
|
|
|
|
context.Context, string, string, string, map[string]interface{},
|
|
|
|
|
) (bool, error) {
|
|
|
|
|
return false, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *transcriptStreams) DeleteSteerEvent(
|
|
|
|
|
context.Context, string, string, string,
|
|
|
|
|
) (bool, error) {
|
|
|
|
|
return false, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *transcriptStreams) SetLiveRun(context.Context, string, string, string) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *transcriptStreams) ClaimLiveRun(context.Context, string, string, string) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *transcriptStreams) GetLiveRun(context.Context, string) (string, string, error) {
|
|
|
|
|
return "", "", nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *transcriptStreams) ClearLiveRun(context.Context, string, string) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-25 03:28:12 +00:00
|
|
|
func (s *transcriptStreams) types() []types.ResponseType {
|
|
|
|
|
out := make([]types.ResponseType, 0, len(s.events))
|
|
|
|
|
for _, evt := range s.events {
|
|
|
|
|
out = append(out, evt.Type)
|
|
|
|
|
}
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// transcriptMessages is the durable half. Only the two calls the transcript
|
|
|
|
|
// makes are implemented; the rest panic so an accidental new dependency on the
|
|
|
|
|
// repository surfaces as a test failure rather than a silent nil write.
|
|
|
|
|
type transcriptMessages struct {
|
|
|
|
|
interfaces.MessageRepository
|
|
|
|
|
created []*types.Message
|
|
|
|
|
updated []*types.Message
|
|
|
|
|
err error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *transcriptMessages) CreateMessage(
|
|
|
|
|
_ context.Context, msg *types.Message,
|
|
|
|
|
) (*types.Message, error) {
|
|
|
|
|
m.created = append(m.created, msg)
|
|
|
|
|
return msg, m.err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *transcriptMessages) UpdateMessage(_ context.Context, msg *types.Message) error {
|
|
|
|
|
m.updated = append(m.updated, msg)
|
|
|
|
|
return m.err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newTranscriptForTest(t *testing.T) (
|
|
|
|
|
*installTranscript, *event.EventBus, *transcriptStreams, *transcriptMessages,
|
|
|
|
|
) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
bus := event.NewEventBus()
|
|
|
|
|
streams := &transcriptStreams{}
|
|
|
|
|
messages := &transcriptMessages{}
|
perf(skills): batch install verification and live installer progress (#2960)
* perf(skills): batch install verification and keep caches under budget
The tail of an install (agent_done -> verified) issued one remote exec per
check: two for permission normalisation, one per bundled script for the tree
check, three for the scratch wipe. A skill with twenty scripts paid thirty-
odd round trips, each carrying a hidden bootstrap exec and a distributed-
lock resolve, while the console sat on a finished agent with no feedback.
- normalizeSkillPermissions sends chmod and chown as one command.
- verifySkillTree folds the SKILL.md probe and one test per script into a
single command that reports every missing file instead of stopping at the
first. Exit codes 0/1/3 carry the verdict, stderr lines are the final
messages, and the two existing error texts survive verbatim.
- cleanImageScratch merges the workspace reset, the directory restore and
the cache pass into one command whose exit code is still owned by the
strict workspace half. Package caches are no longer wiped wholesale: uv,
npm and pnpm trim their own entries, and the pip/uv/npm/pnpm totals of
both accounts are kept while under 256MB and wiped whole over it, so the
next install resolves a previous download instead of the network.
- The install prompt hands the agent absolute paths for uv, npm, pnpm, pip,
python3 and node from the same one-command probe that used to ask only
whether uv exists, so it neither burns a turn on `which` nor gambles on
the shell PATH.
Tests pin the new command shapes exactly, cover quoting of archive-chosen
file names, assert the tree check stays one command regardless of script
count, exercise the budget guard against a real shell, and keep the
workspace-restore failure semantics intact.
* fix(skills): credit a script's own sys.path bootstrap for shipped modules
The python check resolved every import against the script's directory, its
ancestors up to the skill root and the venv - and nothing else. A module the
skill ships in a sibling subtree (lib/image_video.py, imported by
scripts/generate.py) was invisible to that set, so a skill whose scripts
bootstrap their own library directory was refused for a dependency no
package provides, and the repair round that followed could not fix it
either: it installs packages and is forbidden from editing the tree. One
real install spent seven minutes discovering that, three LLM stream
timeouts included.
The verifier now scans what the tree ships and statically evaluates the
sys.path.insert/append calls each script raises before its imports - the
os.path and pathlib idioms, with variables tracked in source order. A
bootstrap proven to raise the directory that provides the module turns the
finding into a note; anything unprovable stays a refusal, now naming the
shipped file instead of pretending a dependency is missing. The refusal is
unrepairable on purpose: no installer round can fix a shipped module the
import cannot reach.
Tests pin the incident's exact shape, the pathlib idiom, and the guarantee
that makes the evaluator safe: a vendored module still cannot satisfy an
import unless the script's own bootstrap provably reaches it, and modules
pip placed under .venv never count as shipped.
* feat(skills): move the install progress bar while the installer works
The progress card sat at the seeded 35% for the whole agent phase and
only jumped at agent_done. Every tool call the transcript already sees
now advances an asymptotic curve 35 + 44·(1 − e^(−k/12)): monotonic for
any round count, converging below the agent_done anchor at 80, topping
out around 75 even when max_iterations is exhausted.
Each step publishes a one-line command summary (engine hint preferred,
80-rune cap) so the admin can see what the installer is doing. After
the first round ends the activity progress is muted — verification and
repair rounds own the stage anchors (80/82) from there, and a repair
round's tool calls must not drag the bar back under them.
* fix(skills): pin the installer agent's thinking mode off
installerAgentConfig left AgentConfig.Thinking nil, which most providers
read as "defer to the model's own default" — a thinking-capable model
would reason on every ReAct round of an install, burning latency and
completion tokens on what are short shell-command turns. Set an explicit
false so every provider path (Qwen enable_thinking, Ollama think, LKEAP
thinking type) receives a deterministic off instead of a default.
* style(skills): gofmt tenant_skill_verify_python_test.go
CI rejects aligned map keys in this table-driven test; gofmt drops the extra spaces.
* docs(skills): drop the duplicated exit 1 line in the python verifier
The shipped-module case was appended by repeating the whole exit 1 block
instead of extending the existing one.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
2026-09-02 04:23:42 +00:00
|
|
|
tr := newInstallTranscript(context.Background(), bus, streams, messages, "sess-1", "msg-1", nil)
|
2026-08-25 03:28:12 +00:00
|
|
|
tr.Subscribe()
|
|
|
|
|
return tr, bus, streams, messages
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInstallTranscriptProjectsTheAgentsWork(t *testing.T) {
|
|
|
|
|
_, bus, streams, _ := newTranscriptForTest(t)
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
require.NoError(t, bus.Emit(ctx, event.Event{
|
|
|
|
|
ID: "t-1", Type: event.EventAgentThought,
|
|
|
|
|
Data: event.AgentThoughtData{Content: "check for uv", Done: false},
|
|
|
|
|
}))
|
|
|
|
|
require.NoError(t, bus.Emit(ctx, event.Event{
|
|
|
|
|
ID: "c-1", Type: event.EventAgentToolCall,
|
|
|
|
|
Data: event.AgentToolCallData{
|
|
|
|
|
ToolName: "shell_exec", ToolCallID: "call-1",
|
|
|
|
|
Arguments: map[string]any{"command": "uv --version"},
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
require.NoError(t, bus.Emit(ctx, event.Event{
|
|
|
|
|
ID: "r-1", Type: event.EventAgentToolResult,
|
|
|
|
|
Data: event.AgentToolResultData{
|
|
|
|
|
ToolName: "shell_exec", ToolCallID: "call-1", Success: true, Output: "uv 0.4.0",
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
require.Equal(t, []types.ResponseType{
|
|
|
|
|
types.ResponseTypeThinking,
|
|
|
|
|
types.ResponseTypeToolCall,
|
|
|
|
|
types.ResponseTypeToolResult,
|
|
|
|
|
}, streams.types())
|
|
|
|
|
|
|
|
|
|
call := streams.events[1]
|
|
|
|
|
require.Equal(t, "shell_exec", call.Data["tool_name"])
|
|
|
|
|
require.Equal(t, "call-1", call.Data["tool_call_id"])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A failed command is the single most useful thing in an install transcript,
|
2026-09-09 09:46:36 +00:00
|
|
|
// so it must reach the stream as a tool result carrying success=false —
|
|
|
|
|
// response_type=error is reserved for internal failures, not tool outcomes.
|
|
|
|
|
func TestInstallTranscriptReportsAFailedCommandAsAToolResult(t *testing.T) {
|
2026-08-25 03:28:12 +00:00
|
|
|
_, bus, streams, _ := newTranscriptForTest(t)
|
|
|
|
|
|
|
|
|
|
require.NoError(t, bus.Emit(context.Background(), event.Event{
|
|
|
|
|
ID: "r-1", Type: event.EventAgentToolResult,
|
|
|
|
|
Data: event.AgentToolResultData{
|
|
|
|
|
ToolName: "shell_exec", ToolCallID: "call-1",
|
|
|
|
|
Success: false, Error: "exit status 1",
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
|
2026-09-09 09:46:36 +00:00
|
|
|
require.Equal(t, []types.ResponseType{types.ResponseTypeToolResult}, streams.types())
|
2026-08-25 03:28:12 +00:00
|
|
|
require.Equal(t, "exit status 1", streams.events[0].Content)
|
|
|
|
|
require.Equal(t, false, streams.events[0].Data["success"])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInstallTranscriptPersistsTheAnswerAndStepsOnComplete(t *testing.T) {
|
|
|
|
|
tr, bus, streams, messages := newTranscriptForTest(t)
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
require.NoError(t, bus.Emit(ctx, event.Event{
|
|
|
|
|
ID: "a-1", Type: event.EventAgentFinalAnswer,
|
|
|
|
|
Data: event.AgentFinalAnswerData{Content: "installed ", Done: false},
|
|
|
|
|
}))
|
|
|
|
|
require.NoError(t, bus.Emit(ctx, event.Event{
|
|
|
|
|
ID: "a-1", Type: event.EventAgentFinalAnswer,
|
|
|
|
|
Data: event.AgentFinalAnswerData{Content: "pdf-tools", Done: true},
|
|
|
|
|
}))
|
|
|
|
|
require.NoError(t, bus.Emit(ctx, event.Event{
|
|
|
|
|
ID: "done", Type: event.EventAgentComplete,
|
|
|
|
|
Data: event.AgentCompleteData{
|
|
|
|
|
MessageID: "msg-1", TotalDurationMs: 4200, TotalSteps: 3,
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
tr.Finish(ctx, nil)
|
|
|
|
|
|
|
|
|
|
require.Equal(t, types.ResponseTypeComplete, streams.types()[len(streams.types())-1])
|
|
|
|
|
require.Len(t, messages.updated, 1)
|
|
|
|
|
saved := messages.updated[0]
|
|
|
|
|
require.Equal(t, "installed pdf-tools", saved.Content)
|
|
|
|
|
require.True(t, saved.IsCompleted)
|
|
|
|
|
require.EqualValues(t, 4200, saved.AgentDurationMs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The engine routes a round's plain assistant prose through
|
|
|
|
|
// EventAgentFinalAnswer, so every "now I'll check X" preamble arrives as an
|
|
|
|
|
// answer chunk. Only the prose of the round that ends the run is the answer.
|
|
|
|
|
// Without retracting the preambles the persisted record is every round's
|
|
|
|
|
// commentary glued end to end, which is unreadable — and is what the console
|
|
|
|
|
// renders as the install's result.
|
|
|
|
|
func TestInstallTranscriptRetractsPreamblesSupersededByAToolCall(t *testing.T) {
|
|
|
|
|
tr, bus, _, messages := newTranscriptForTest(t)
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
emitAnswer := func(id, content string, done bool) {
|
|
|
|
|
require.NoError(t, bus.Emit(ctx, event.Event{
|
|
|
|
|
ID: id, Type: event.EventAgentFinalAnswer,
|
|
|
|
|
Data: event.AgentFinalAnswerData{Content: content, Done: done},
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emitAnswer("a-1", "The script needs duckduckgo-search, so I'll create the venv:", true)
|
|
|
|
|
require.NoError(t, bus.Emit(ctx, event.Event{
|
|
|
|
|
ID: "c-1", Type: event.EventAgentToolCall,
|
|
|
|
|
Data: event.AgentToolCallData{
|
|
|
|
|
ToolName: "shell_exec", ToolCallID: "call-1",
|
|
|
|
|
Arguments: map[string]any{"command": "uv venv .venv"},
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
emitAnswer("a-2", "Installed successfully. Now verifying:", true)
|
|
|
|
|
require.NoError(t, bus.Emit(ctx, event.Event{
|
|
|
|
|
ID: "c-2", Type: event.EventAgentToolCall,
|
|
|
|
|
Data: event.AgentToolCallData{
|
|
|
|
|
ToolName: "shell_exec", ToolCallID: "call-2",
|
|
|
|
|
Arguments: map[string]any{"command": "python scripts/search.py --help"},
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
emitAnswer("a-3", "Installed duckduckgo-search into the skill venv.", true)
|
|
|
|
|
|
|
|
|
|
require.NoError(t, bus.Emit(ctx, event.Event{
|
|
|
|
|
ID: "done", Type: event.EventAgentComplete,
|
|
|
|
|
Data: event.AgentCompleteData{MessageID: "msg-1", TotalDurationMs: 900},
|
|
|
|
|
}))
|
|
|
|
|
tr.Finish(ctx, nil)
|
|
|
|
|
|
|
|
|
|
require.Len(t, messages.updated, 1)
|
|
|
|
|
require.Equal(t,
|
|
|
|
|
"Installed duckduckgo-search into the skill venv.",
|
|
|
|
|
messages.updated[0].Content,
|
|
|
|
|
"only the final round's prose is the answer; earlier preambles were retracted by their tool calls",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// An install that dies before the engine emits complete is exactly the run
|
|
|
|
|
// someone will come looking for, so Finish must close the record itself.
|
|
|
|
|
func TestInstallTranscriptRecordsAFailedRun(t *testing.T) {
|
|
|
|
|
tr, _, streams, messages := newTranscriptForTest(t)
|
|
|
|
|
|
|
|
|
|
tr.Finish(context.Background(), errors.New("installer agent failed: boom"))
|
|
|
|
|
|
|
|
|
|
require.Equal(t, []types.ResponseType{
|
|
|
|
|
types.ResponseTypeError,
|
|
|
|
|
types.ResponseTypeComplete,
|
|
|
|
|
}, streams.types())
|
|
|
|
|
require.Len(t, messages.updated, 1)
|
|
|
|
|
require.Contains(t, messages.updated[0].Content, "boom")
|
|
|
|
|
require.True(t, messages.updated[0].IsCompleted)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The transcript is a troubleshooting aid. A broken Redis or a failing write
|
|
|
|
|
// must not be able to fail an otherwise good install.
|
|
|
|
|
func TestInstallTranscriptSwallowsItsOwnFailures(t *testing.T) {
|
|
|
|
|
bus := event.NewEventBus()
|
|
|
|
|
streams := &transcriptStreams{err: errors.New("redis down")}
|
|
|
|
|
messages := &transcriptMessages{err: errors.New("db down")}
|
perf(skills): batch install verification and live installer progress (#2960)
* perf(skills): batch install verification and keep caches under budget
The tail of an install (agent_done -> verified) issued one remote exec per
check: two for permission normalisation, one per bundled script for the tree
check, three for the scratch wipe. A skill with twenty scripts paid thirty-
odd round trips, each carrying a hidden bootstrap exec and a distributed-
lock resolve, while the console sat on a finished agent with no feedback.
- normalizeSkillPermissions sends chmod and chown as one command.
- verifySkillTree folds the SKILL.md probe and one test per script into a
single command that reports every missing file instead of stopping at the
first. Exit codes 0/1/3 carry the verdict, stderr lines are the final
messages, and the two existing error texts survive verbatim.
- cleanImageScratch merges the workspace reset, the directory restore and
the cache pass into one command whose exit code is still owned by the
strict workspace half. Package caches are no longer wiped wholesale: uv,
npm and pnpm trim their own entries, and the pip/uv/npm/pnpm totals of
both accounts are kept while under 256MB and wiped whole over it, so the
next install resolves a previous download instead of the network.
- The install prompt hands the agent absolute paths for uv, npm, pnpm, pip,
python3 and node from the same one-command probe that used to ask only
whether uv exists, so it neither burns a turn on `which` nor gambles on
the shell PATH.
Tests pin the new command shapes exactly, cover quoting of archive-chosen
file names, assert the tree check stays one command regardless of script
count, exercise the budget guard against a real shell, and keep the
workspace-restore failure semantics intact.
* fix(skills): credit a script's own sys.path bootstrap for shipped modules
The python check resolved every import against the script's directory, its
ancestors up to the skill root and the venv - and nothing else. A module the
skill ships in a sibling subtree (lib/image_video.py, imported by
scripts/generate.py) was invisible to that set, so a skill whose scripts
bootstrap their own library directory was refused for a dependency no
package provides, and the repair round that followed could not fix it
either: it installs packages and is forbidden from editing the tree. One
real install spent seven minutes discovering that, three LLM stream
timeouts included.
The verifier now scans what the tree ships and statically evaluates the
sys.path.insert/append calls each script raises before its imports - the
os.path and pathlib idioms, with variables tracked in source order. A
bootstrap proven to raise the directory that provides the module turns the
finding into a note; anything unprovable stays a refusal, now naming the
shipped file instead of pretending a dependency is missing. The refusal is
unrepairable on purpose: no installer round can fix a shipped module the
import cannot reach.
Tests pin the incident's exact shape, the pathlib idiom, and the guarantee
that makes the evaluator safe: a vendored module still cannot satisfy an
import unless the script's own bootstrap provably reaches it, and modules
pip placed under .venv never count as shipped.
* feat(skills): move the install progress bar while the installer works
The progress card sat at the seeded 35% for the whole agent phase and
only jumped at agent_done. Every tool call the transcript already sees
now advances an asymptotic curve 35 + 44·(1 − e^(−k/12)): monotonic for
any round count, converging below the agent_done anchor at 80, topping
out around 75 even when max_iterations is exhausted.
Each step publishes a one-line command summary (engine hint preferred,
80-rune cap) so the admin can see what the installer is doing. After
the first round ends the activity progress is muted — verification and
repair rounds own the stage anchors (80/82) from there, and a repair
round's tool calls must not drag the bar back under them.
* fix(skills): pin the installer agent's thinking mode off
installerAgentConfig left AgentConfig.Thinking nil, which most providers
read as "defer to the model's own default" — a thinking-capable model
would reason on every ReAct round of an install, burning latency and
completion tokens on what are short shell-command turns. Set an explicit
false so every provider path (Qwen enable_thinking, Ollama think, LKEAP
thinking type) receives a deterministic off instead of a default.
* style(skills): gofmt tenant_skill_verify_python_test.go
CI rejects aligned map keys in this table-driven test; gofmt drops the extra spaces.
* docs(skills): drop the duplicated exit 1 line in the python verifier
The shipped-module case was appended by repeating the whole exit 1 block
instead of extending the existing one.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
2026-09-02 04:23:42 +00:00
|
|
|
tr := newInstallTranscript(context.Background(), bus, streams, messages, "sess-1", "msg-1", nil)
|
2026-08-25 03:28:12 +00:00
|
|
|
tr.Subscribe()
|
|
|
|
|
|
|
|
|
|
require.NoError(t, bus.Emit(context.Background(), event.Event{
|
|
|
|
|
ID: "t-1", Type: event.EventAgentThought,
|
|
|
|
|
Data: event.AgentThoughtData{Content: "hi", Done: true},
|
|
|
|
|
}))
|
|
|
|
|
require.NotPanics(t, func() { tr.Finish(context.Background(), nil) })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInstallTranscriptCreateSeedsTheAssistantRow(t *testing.T) {
|
|
|
|
|
streams := &transcriptStreams{}
|
|
|
|
|
messages := &transcriptMessages{}
|
|
|
|
|
tr := newInstallTranscript(
|
perf(skills): batch install verification and live installer progress (#2960)
* perf(skills): batch install verification and keep caches under budget
The tail of an install (agent_done -> verified) issued one remote exec per
check: two for permission normalisation, one per bundled script for the tree
check, three for the scratch wipe. A skill with twenty scripts paid thirty-
odd round trips, each carrying a hidden bootstrap exec and a distributed-
lock resolve, while the console sat on a finished agent with no feedback.
- normalizeSkillPermissions sends chmod and chown as one command.
- verifySkillTree folds the SKILL.md probe and one test per script into a
single command that reports every missing file instead of stopping at the
first. Exit codes 0/1/3 carry the verdict, stderr lines are the final
messages, and the two existing error texts survive verbatim.
- cleanImageScratch merges the workspace reset, the directory restore and
the cache pass into one command whose exit code is still owned by the
strict workspace half. Package caches are no longer wiped wholesale: uv,
npm and pnpm trim their own entries, and the pip/uv/npm/pnpm totals of
both accounts are kept while under 256MB and wiped whole over it, so the
next install resolves a previous download instead of the network.
- The install prompt hands the agent absolute paths for uv, npm, pnpm, pip,
python3 and node from the same one-command probe that used to ask only
whether uv exists, so it neither burns a turn on `which` nor gambles on
the shell PATH.
Tests pin the new command shapes exactly, cover quoting of archive-chosen
file names, assert the tree check stays one command regardless of script
count, exercise the budget guard against a real shell, and keep the
workspace-restore failure semantics intact.
* fix(skills): credit a script's own sys.path bootstrap for shipped modules
The python check resolved every import against the script's directory, its
ancestors up to the skill root and the venv - and nothing else. A module the
skill ships in a sibling subtree (lib/image_video.py, imported by
scripts/generate.py) was invisible to that set, so a skill whose scripts
bootstrap their own library directory was refused for a dependency no
package provides, and the repair round that followed could not fix it
either: it installs packages and is forbidden from editing the tree. One
real install spent seven minutes discovering that, three LLM stream
timeouts included.
The verifier now scans what the tree ships and statically evaluates the
sys.path.insert/append calls each script raises before its imports - the
os.path and pathlib idioms, with variables tracked in source order. A
bootstrap proven to raise the directory that provides the module turns the
finding into a note; anything unprovable stays a refusal, now naming the
shipped file instead of pretending a dependency is missing. The refusal is
unrepairable on purpose: no installer round can fix a shipped module the
import cannot reach.
Tests pin the incident's exact shape, the pathlib idiom, and the guarantee
that makes the evaluator safe: a vendored module still cannot satisfy an
import unless the script's own bootstrap provably reaches it, and modules
pip placed under .venv never count as shipped.
* feat(skills): move the install progress bar while the installer works
The progress card sat at the seeded 35% for the whole agent phase and
only jumped at agent_done. Every tool call the transcript already sees
now advances an asymptotic curve 35 + 44·(1 − e^(−k/12)): monotonic for
any round count, converging below the agent_done anchor at 80, topping
out around 75 even when max_iterations is exhausted.
Each step publishes a one-line command summary (engine hint preferred,
80-rune cap) so the admin can see what the installer is doing. After
the first round ends the activity progress is muted — verification and
repair rounds own the stage anchors (80/82) from there, and a repair
round's tool calls must not drag the bar back under them.
* fix(skills): pin the installer agent's thinking mode off
installerAgentConfig left AgentConfig.Thinking nil, which most providers
read as "defer to the model's own default" — a thinking-capable model
would reason on every ReAct round of an install, burning latency and
completion tokens on what are short shell-command turns. Set an explicit
false so every provider path (Qwen enable_thinking, Ollama think, LKEAP
thinking type) receives a deterministic off instead of a default.
* style(skills): gofmt tenant_skill_verify_python_test.go
CI rejects aligned map keys in this table-driven test; gofmt drops the extra spaces.
* docs(skills): drop the duplicated exit 1 line in the python verifier
The shipped-module case was appended by repeating the whole exit 1 block
instead of extending the existing one.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
2026-09-02 04:23:42 +00:00
|
|
|
context.Background(), event.NewEventBus(), streams, messages, "sess-1", "msg-1", nil,
|
2026-08-25 03:28:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
require.NoError(t, tr.Create(context.Background(), "install pdf-tools"))
|
|
|
|
|
require.Len(t, messages.created, 2)
|
|
|
|
|
require.Equal(t, "user", messages.created[0].Role)
|
|
|
|
|
require.Equal(t, "install pdf-tools", messages.created[0].Content)
|
|
|
|
|
require.Equal(t, "assistant", messages.created[1].Role)
|
|
|
|
|
require.Equal(t, "msg-1", messages.created[1].ID)
|
|
|
|
|
require.Equal(t, "sess-1", messages.created[1].SessionID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A console that attaches to a running install reads the event log and nothing
|
|
|
|
|
// else, so the prompt has to be in the log or the run shows up as an agent
|
|
|
|
|
// answering a question nobody can see.
|
|
|
|
|
func TestInstallTranscriptCreateOpensTheLogWithThePrompt(t *testing.T) {
|
|
|
|
|
streams := &transcriptStreams{}
|
|
|
|
|
tr := newInstallTranscript(
|
perf(skills): batch install verification and live installer progress (#2960)
* perf(skills): batch install verification and keep caches under budget
The tail of an install (agent_done -> verified) issued one remote exec per
check: two for permission normalisation, one per bundled script for the tree
check, three for the scratch wipe. A skill with twenty scripts paid thirty-
odd round trips, each carrying a hidden bootstrap exec and a distributed-
lock resolve, while the console sat on a finished agent with no feedback.
- normalizeSkillPermissions sends chmod and chown as one command.
- verifySkillTree folds the SKILL.md probe and one test per script into a
single command that reports every missing file instead of stopping at the
first. Exit codes 0/1/3 carry the verdict, stderr lines are the final
messages, and the two existing error texts survive verbatim.
- cleanImageScratch merges the workspace reset, the directory restore and
the cache pass into one command whose exit code is still owned by the
strict workspace half. Package caches are no longer wiped wholesale: uv,
npm and pnpm trim their own entries, and the pip/uv/npm/pnpm totals of
both accounts are kept while under 256MB and wiped whole over it, so the
next install resolves a previous download instead of the network.
- The install prompt hands the agent absolute paths for uv, npm, pnpm, pip,
python3 and node from the same one-command probe that used to ask only
whether uv exists, so it neither burns a turn on `which` nor gambles on
the shell PATH.
Tests pin the new command shapes exactly, cover quoting of archive-chosen
file names, assert the tree check stays one command regardless of script
count, exercise the budget guard against a real shell, and keep the
workspace-restore failure semantics intact.
* fix(skills): credit a script's own sys.path bootstrap for shipped modules
The python check resolved every import against the script's directory, its
ancestors up to the skill root and the venv - and nothing else. A module the
skill ships in a sibling subtree (lib/image_video.py, imported by
scripts/generate.py) was invisible to that set, so a skill whose scripts
bootstrap their own library directory was refused for a dependency no
package provides, and the repair round that followed could not fix it
either: it installs packages and is forbidden from editing the tree. One
real install spent seven minutes discovering that, three LLM stream
timeouts included.
The verifier now scans what the tree ships and statically evaluates the
sys.path.insert/append calls each script raises before its imports - the
os.path and pathlib idioms, with variables tracked in source order. A
bootstrap proven to raise the directory that provides the module turns the
finding into a note; anything unprovable stays a refusal, now naming the
shipped file instead of pretending a dependency is missing. The refusal is
unrepairable on purpose: no installer round can fix a shipped module the
import cannot reach.
Tests pin the incident's exact shape, the pathlib idiom, and the guarantee
that makes the evaluator safe: a vendored module still cannot satisfy an
import unless the script's own bootstrap provably reaches it, and modules
pip placed under .venv never count as shipped.
* feat(skills): move the install progress bar while the installer works
The progress card sat at the seeded 35% for the whole agent phase and
only jumped at agent_done. Every tool call the transcript already sees
now advances an asymptotic curve 35 + 44·(1 − e^(−k/12)): monotonic for
any round count, converging below the agent_done anchor at 80, topping
out around 75 even when max_iterations is exhausted.
Each step publishes a one-line command summary (engine hint preferred,
80-rune cap) so the admin can see what the installer is doing. After
the first round ends the activity progress is muted — verification and
repair rounds own the stage anchors (80/82) from there, and a repair
round's tool calls must not drag the bar back under them.
* fix(skills): pin the installer agent's thinking mode off
installerAgentConfig left AgentConfig.Thinking nil, which most providers
read as "defer to the model's own default" — a thinking-capable model
would reason on every ReAct round of an install, burning latency and
completion tokens on what are short shell-command turns. Set an explicit
false so every provider path (Qwen enable_thinking, Ollama think, LKEAP
thinking type) receives a deterministic off instead of a default.
* style(skills): gofmt tenant_skill_verify_python_test.go
CI rejects aligned map keys in this table-driven test; gofmt drops the extra spaces.
* docs(skills): drop the duplicated exit 1 line in the python verifier
The shipped-module case was appended by repeating the whole exit 1 block
instead of extending the existing one.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
2026-09-02 04:23:42 +00:00
|
|
|
context.Background(), event.NewEventBus(), streams, &transcriptMessages{}, "sess-1", "msg-1", nil,
|
2026-08-25 03:28:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
require.NoError(t, tr.Create(context.Background(), "install pdf-tools"))
|
|
|
|
|
|
|
|
|
|
require.Equal(t, []types.ResponseType{types.ResponseTypeInstallPrompt}, streams.types())
|
|
|
|
|
require.Equal(t, "install pdf-tools", streams.events[0].Content)
|
|
|
|
|
}
|
2026-08-31 03:42:47 +00:00
|
|
|
|
|
|
|
|
// An install may run a second installer round, because verification happens
|
|
|
|
|
// after the agent stops and a dependency it names is something the agent can
|
|
|
|
|
// still fix. The engine reports "complete" at the end of every turn, so the
|
|
|
|
|
// transcript must not treat the first one as the end of the install — a console
|
|
|
|
|
// that saw it would stop following before the repair round began.
|
|
|
|
|
func TestInstallTranscriptStaysOpenAcrossInstallerRounds(t *testing.T) {
|
|
|
|
|
tr, bus, streams, messages := newTranscriptForTest(t)
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
finishRound := func(steps int, ms int64) {
|
|
|
|
|
require.NoError(t, bus.Emit(ctx, event.Event{
|
|
|
|
|
ID: "done", Type: event.EventAgentComplete,
|
|
|
|
|
Data: event.AgentCompleteData{
|
|
|
|
|
MessageID: "msg-1", TotalSteps: steps, TotalDurationMs: ms,
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
finishRound(3, 1000)
|
|
|
|
|
tr.RecordPrompt("Verification failed. Install defusedxml into the venv.")
|
|
|
|
|
finishRound(2, 500)
|
|
|
|
|
tr.Finish(ctx, nil)
|
|
|
|
|
|
|
|
|
|
kinds := streams.types()
|
|
|
|
|
require.Equal(t, []types.ResponseType{
|
|
|
|
|
types.ResponseTypeInstallPrompt,
|
|
|
|
|
types.ResponseTypeComplete,
|
|
|
|
|
}, kinds, "the repair instruction has to be in the log, and the install ends once")
|
|
|
|
|
require.Contains(t, streams.events[0].Content, "Install defusedxml")
|
|
|
|
|
|
|
|
|
|
terminal := streams.events[len(streams.events)-1]
|
|
|
|
|
require.EqualValues(t, 5, terminal.Data["total_steps"],
|
|
|
|
|
"an install that needed a repair round cost both turns")
|
|
|
|
|
require.EqualValues(t, 1500, terminal.Data["total_duration_ms"])
|
|
|
|
|
require.Len(t, messages.updated, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finish is deferred by the install path and also called on the error path that
|
|
|
|
|
// gives up before that defer is armed. Saying "this install is over" twice would
|
|
|
|
|
// duplicate the verdict in the record people read.
|
|
|
|
|
func TestInstallTranscriptFinishIsIdempotent(t *testing.T) {
|
|
|
|
|
tr, _, streams, messages := newTranscriptForTest(t)
|
|
|
|
|
|
|
|
|
|
tr.Finish(context.Background(), errors.New("python verification failed: boom"))
|
|
|
|
|
tr.Finish(context.Background(), errors.New("python verification failed: boom"))
|
|
|
|
|
|
|
|
|
|
require.Equal(t, []types.ResponseType{
|
|
|
|
|
types.ResponseTypeError,
|
|
|
|
|
types.ResponseTypeComplete,
|
|
|
|
|
}, streams.types())
|
|
|
|
|
require.Len(t, messages.updated, 1)
|
|
|
|
|
}
|
perf(skills): batch install verification and live installer progress (#2960)
* perf(skills): batch install verification and keep caches under budget
The tail of an install (agent_done -> verified) issued one remote exec per
check: two for permission normalisation, one per bundled script for the tree
check, three for the scratch wipe. A skill with twenty scripts paid thirty-
odd round trips, each carrying a hidden bootstrap exec and a distributed-
lock resolve, while the console sat on a finished agent with no feedback.
- normalizeSkillPermissions sends chmod and chown as one command.
- verifySkillTree folds the SKILL.md probe and one test per script into a
single command that reports every missing file instead of stopping at the
first. Exit codes 0/1/3 carry the verdict, stderr lines are the final
messages, and the two existing error texts survive verbatim.
- cleanImageScratch merges the workspace reset, the directory restore and
the cache pass into one command whose exit code is still owned by the
strict workspace half. Package caches are no longer wiped wholesale: uv,
npm and pnpm trim their own entries, and the pip/uv/npm/pnpm totals of
both accounts are kept while under 256MB and wiped whole over it, so the
next install resolves a previous download instead of the network.
- The install prompt hands the agent absolute paths for uv, npm, pnpm, pip,
python3 and node from the same one-command probe that used to ask only
whether uv exists, so it neither burns a turn on `which` nor gambles on
the shell PATH.
Tests pin the new command shapes exactly, cover quoting of archive-chosen
file names, assert the tree check stays one command regardless of script
count, exercise the budget guard against a real shell, and keep the
workspace-restore failure semantics intact.
* fix(skills): credit a script's own sys.path bootstrap for shipped modules
The python check resolved every import against the script's directory, its
ancestors up to the skill root and the venv - and nothing else. A module the
skill ships in a sibling subtree (lib/image_video.py, imported by
scripts/generate.py) was invisible to that set, so a skill whose scripts
bootstrap their own library directory was refused for a dependency no
package provides, and the repair round that followed could not fix it
either: it installs packages and is forbidden from editing the tree. One
real install spent seven minutes discovering that, three LLM stream
timeouts included.
The verifier now scans what the tree ships and statically evaluates the
sys.path.insert/append calls each script raises before its imports - the
os.path and pathlib idioms, with variables tracked in source order. A
bootstrap proven to raise the directory that provides the module turns the
finding into a note; anything unprovable stays a refusal, now naming the
shipped file instead of pretending a dependency is missing. The refusal is
unrepairable on purpose: no installer round can fix a shipped module the
import cannot reach.
Tests pin the incident's exact shape, the pathlib idiom, and the guarantee
that makes the evaluator safe: a vendored module still cannot satisfy an
import unless the script's own bootstrap provably reaches it, and modules
pip placed under .venv never count as shipped.
* feat(skills): move the install progress bar while the installer works
The progress card sat at the seeded 35% for the whole agent phase and
only jumped at agent_done. Every tool call the transcript already sees
now advances an asymptotic curve 35 + 44·(1 − e^(−k/12)): monotonic for
any round count, converging below the agent_done anchor at 80, topping
out around 75 even when max_iterations is exhausted.
Each step publishes a one-line command summary (engine hint preferred,
80-rune cap) so the admin can see what the installer is doing. After
the first round ends the activity progress is muted — verification and
repair rounds own the stage anchors (80/82) from there, and a repair
round's tool calls must not drag the bar back under them.
* fix(skills): pin the installer agent's thinking mode off
installerAgentConfig left AgentConfig.Thinking nil, which most providers
read as "defer to the model's own default" — a thinking-capable model
would reason on every ReAct round of an install, burning latency and
completion tokens on what are short shell-command turns. Set an explicit
false so every provider path (Qwen enable_thinking, Ollama think, LKEAP
thinking type) receives a deterministic off instead of a default.
* style(skills): gofmt tenant_skill_verify_python_test.go
CI rejects aligned map keys in this table-driven test; gofmt drops the extra spaces.
* docs(skills): drop the duplicated exit 1 line in the python verifier
The shipped-module case was appended by repeating the whole exit 1 block
instead of extending the existing one.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
2026-09-02 04:23:42 +00:00
|
|
|
|
|
|
|
|
func TestAsymptoticInstallPercent(t *testing.T) {
|
|
|
|
|
require.Equal(t, 35, asymptoticInstallPercent(0))
|
|
|
|
|
require.Equal(t, 35, asymptoticInstallPercent(-3), "no commands yet means the seeded anchor")
|
|
|
|
|
|
|
|
|
|
// The first command lifts the bar visibly; the exact value pins the curve.
|
|
|
|
|
require.Equal(t, 39, asymptoticInstallPercent(1))
|
|
|
|
|
require.Equal(t, 42, asymptoticInstallPercent(2))
|
|
|
|
|
|
|
|
|
|
// Monotonic for any round count, always below the agent_done anchor at 80,
|
|
|
|
|
// and converged to the ceiling once a run exhausts max_iterations.
|
|
|
|
|
prev := 0
|
|
|
|
|
for k := 1; k <= 200; k++ {
|
|
|
|
|
p := asymptoticInstallPercent(k)
|
|
|
|
|
require.GreaterOrEqual(t, p, prev)
|
|
|
|
|
require.LessOrEqual(t, p, 79)
|
|
|
|
|
prev = p
|
|
|
|
|
}
|
|
|
|
|
require.Equal(t, 79, asymptoticInstallPercent(200))
|
|
|
|
|
// A run that exhausts max_iterations=30 tops out around 75 — the ceiling
|
|
|
|
|
// belongs to the stage anchor, not to any finite command count.
|
|
|
|
|
require.Equal(t, 75, asymptoticInstallPercent(30))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The progress card watches the same bus the transcript does, so every command
|
|
|
|
|
// the installer runs is one step forward — with a one-line summary of what it
|
|
|
|
|
// was — and muting after the first round stops the flow entirely.
|
|
|
|
|
func TestInstallTranscriptPublishesActivityProgressOnToolCalls(t *testing.T) {
|
|
|
|
|
bus := event.NewEventBus()
|
|
|
|
|
streams := &transcriptStreams{}
|
|
|
|
|
messages := &transcriptMessages{}
|
|
|
|
|
type activity struct {
|
|
|
|
|
steps int
|
|
|
|
|
lastCmd string
|
|
|
|
|
}
|
|
|
|
|
var got []activity
|
|
|
|
|
tr := newInstallTranscript(context.Background(), bus, streams, messages, "sess-1", "msg-1",
|
|
|
|
|
func(steps int, lastCmd string) { got = append(got, activity{steps, lastCmd}) })
|
|
|
|
|
tr.Subscribe()
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
emitCall := func(id string, data event.AgentToolCallData) {
|
|
|
|
|
data.ToolCallID = id
|
|
|
|
|
require.NoError(t, bus.Emit(ctx, event.Event{
|
|
|
|
|
ID: id, Type: event.EventAgentToolCall, Data: data,
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
emitCall("c-1", event.AgentToolCallData{
|
|
|
|
|
ToolName: "shell_exec", Arguments: map[string]any{"command": "uv venv .venv"},
|
|
|
|
|
})
|
|
|
|
|
emitCall("c-2", event.AgentToolCallData{
|
|
|
|
|
ToolName: "shell_exec", Hint: `shell_exec: apt-get install -y libgl1`,
|
|
|
|
|
})
|
|
|
|
|
emitCall("c-3", event.AgentToolCallData{
|
|
|
|
|
ToolName: "shell_exec",
|
|
|
|
|
Arguments: map[string]any{"command": "uv pip install --python .venv/bin/python " +
|
|
|
|
|
strings.Repeat("very-long-package-name-", 12)},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
require.Len(t, got, 3)
|
|
|
|
|
require.Equal(t, 1, got[0].steps)
|
|
|
|
|
require.Equal(t, "shell_exec: uv venv .venv", got[0].lastCmd)
|
|
|
|
|
require.Equal(t, `shell_exec: apt-get install -y libgl1`, got[1].lastCmd,
|
|
|
|
|
"the engine's hint is preferred when it has one")
|
|
|
|
|
require.Equal(t, 3, got[2].steps)
|
|
|
|
|
require.Less(t, len([]rune(got[2].lastCmd)), 90, "a long command is truncated to one line")
|
|
|
|
|
|
|
|
|
|
// A repair round must not drag the bar back below the stage anchors, so
|
|
|
|
|
// muting after the first round ends the activity publishes for good.
|
|
|
|
|
tr.muteActivityProgress()
|
|
|
|
|
emitCall("c-4", event.AgentToolCallData{
|
|
|
|
|
ToolName: "shell_exec", Arguments: map[string]any{"command": "uv pip install defusedxml"},
|
|
|
|
|
})
|
|
|
|
|
require.Len(t, got, 3)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A transcript without a publisher (remove path, most tests) counts nothing
|
|
|
|
|
// and calls nothing.
|
|
|
|
|
func TestInstallTranscriptWithoutActivityPublisherStaysSilent(t *testing.T) {
|
|
|
|
|
tr, bus, streams, _ := newTranscriptForTest(t)
|
|
|
|
|
|
|
|
|
|
require.NoError(t, bus.Emit(context.Background(), event.Event{
|
|
|
|
|
ID: "c-1", Type: event.EventAgentToolCall,
|
|
|
|
|
Data: event.AgentToolCallData{
|
|
|
|
|
ToolName: "shell_exec", ToolCallID: "call-1",
|
|
|
|
|
Arguments: map[string]any{"command": "uv venv .venv"},
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
tr.muteActivityProgress()
|
|
|
|
|
|
|
|
|
|
require.NotPanics(t, func() { tr.Finish(context.Background(), nil) })
|
|
|
|
|
require.Equal(t, []types.ResponseType{types.ResponseTypeToolCall, types.ResponseTypeComplete},
|
|
|
|
|
streams.types(), "the transcript itself is unchanged by progress being unwired")
|
|
|
|
|
}
|
2026-09-12 02:06:37 +00:00
|
|
|
|
|
|
|
|
func TestInstallTranscriptProjectsOutputWithoutCompletingTool(t *testing.T) {
|
|
|
|
|
streams := &transcriptStreams{}
|
|
|
|
|
bus := event.NewEventBus()
|
|
|
|
|
tr := newInstallTranscript(context.Background(), bus, streams, nil, "session", "message", nil)
|
|
|
|
|
tr.Subscribe()
|
|
|
|
|
require.NoError(t, bus.Emit(context.Background(), event.Event{
|
|
|
|
|
ID: "chunk", Type: event.EventAgentCommandOutput,
|
|
|
|
|
Data: event.CommandOutputData{ToolCallID: "tool", Output: "Downloading polars", Done: false},
|
|
|
|
|
}))
|
|
|
|
|
require.Len(t, streams.events, 1)
|
|
|
|
|
require.Equal(t, types.ResponseTypeInstallOutput, streams.events[0].Type)
|
|
|
|
|
require.Equal(t, "tool", streams.events[0].Data["tool_call_id"])
|
|
|
|
|
require.Equal(t, "Downloading polars", streams.events[0].Data["output"])
|
|
|
|
|
require.False(t, streams.events[0].Done)
|
|
|
|
|
tr.closed = true
|
|
|
|
|
require.NoError(t, tr.onInstallOutput(context.Background(), event.Event{
|
|
|
|
|
Data: event.CommandOutputData{Output: "late"},
|
|
|
|
|
}))
|
|
|
|
|
require.Len(t, streams.events, 1)
|
|
|
|
|
}
|