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
96 changes: 49 additions & 47 deletions app/cli/internal/trace/README.md

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion app/cli/internal/trace/e2e/checks_more.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,14 @@ func checkGenericSessionStored(s *Session) error {
// checkNoSessionStartHook makes sure that the session-start hook did not
// fire, so that the scenario tests a missed session start.
func checkNoSessionStartHook(s *Session) error {
if _, err := hookMessage(s, "SessionStart"); err == nil {
_, err := hookMessage(s, "SessionStart")
switch {
case err == nil:
return errors.New("the session-start hook fired, so the scenario does not test a missed start")
case errors.Is(err, errNotCovered):
// A harness that reports no hook messages cannot show that the hook
// did not fire.
return err
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions app/cli/internal/trace/e2e/claude.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c *Claude) Version(ctx context.Context) (string, error) {
func (c *Claude) Run(ctx context.Context, req RunRequest) (*RunOutput, error) {
args := []string{
"-p", req.Prompt,
"--model", req.Model,
flagModel, req.Model,
"--output-format", "stream-json",
"--verbose",
"--include-hook-events",
Expand Down Expand Up @@ -181,7 +181,7 @@ func (c *Claude) HookConfig() HookConfig {
}
}
`,
UserMarker: "e2e-user-hook",
UserMarker: userHookMarker,
}
}

Expand Down
4 changes: 4 additions & 0 deletions app/cli/internal/trace/e2e/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ harnesses:
version: "2.0.22"
models:
- openrouter/anthropic/claude-haiku-5.5
Pi:
version: "1.3.0"
models:
- openrouter/anthropic/claude-haiku-5.5

# Runs and pass threshold of a cell whose feature depends on the model
# following an instruction (R-006, D-004). A cell of any other feature runs
Expand Down
1 change: 1 addition & 0 deletions app/cli/internal/trace/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func TestTraceMatrix(t *testing.T) {
var harnesses = map[string]Harness{
HarnessClaudeCode: &Claude{},
"OpenCode 2": &OpenCode{Major: "2"},
"Pi": &Pi{},
}

// configuredHarnesses returns the adapters of the harnesses that the suite
Expand Down
7 changes: 7 additions & 0 deletions app/cli/internal/trace/e2e/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import "context"
// HarnessClaudeCode is the column name of Claude Code in the feature table.
const HarnessClaudeCode = "Claude Code"

const (
// flagModel is the model flag that all the harnesses share.
flagModel = "--model"
// userHookMarker is in the hook of the user that a scenario seeds.
userHookMarker = "e2e-user-hook"
)

// RunRequest is one headless session of a harness.
type RunRequest struct {
// Dir is the repository the session runs in.
Expand Down
4 changes: 2 additions & 2 deletions app/cli/internal/trace/e2e/opencode.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (o *OpenCode) Version(ctx context.Context) (string, error) {
// as synthetic messages, which the run output does not show. Run exports the
// session after the run and reads them from the export.
func (o *OpenCode) Run(ctx context.Context, req RunRequest) (*RunOutput, error) {
args := []string{"run", "--standalone", "--format", "json", "--auto", "--model", req.Model}
args := []string{"run", "--standalone", "--format", "json", "--auto", flagModel, req.Model}

// A pasted image goes in as an attached file, from outside the
// repository, so that the agent cannot commit it.
Expand Down Expand Up @@ -274,7 +274,7 @@ export default {
async setup() {},
}
`,
UserMarker: "e2e-user-hook",
UserMarker: userHookMarker,
}
}

Expand Down
157 changes: 157 additions & 0 deletions app/cli/internal/trace/e2e/pi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
//
// Copyright 2026 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package e2e

import (
"bytes"
"context"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"slices"
"strings"
)

// piExtensionPath is the extension file where `trace init` installs the Pi
// hooks (spec issue-3520, D-002).
const piExtensionPath = ".pi/extensions/chainloop-trace.ts"

var piVersionRe = regexp.MustCompile(`\d+\.\d+\.\d+`)

// Pi is the harness adapter of the Pi coding agent.
type Pi struct {
// Bin is the pi executable. Empty means "pi" from PATH.
Bin string
}

func (p *Pi) bin() string {
if p.Bin != "" {
return p.Bin
}
return "pi"
}

// Column implements Harness.
func (p *Pi) Column() string { return "Pi" }

// TraceFlag implements Harness.
func (p *Pi) TraceFlag() string { return "--pi" }

// Version implements Harness. `pi --version` prints "0.79.6".
func (p *Pi) Version(ctx context.Context) (string, error) {
out, err := exec.CommandContext(ctx, p.bin(), "--version").Output() //nolint:gosec // the harness binary under test // nosemgrep
if err != nil {
return "", fmt.Errorf("pi --version: %w", err)
}
v := piVersionRe.FindString(string(out))
if v == "" {
return "", fmt.Errorf("pi --version: no version in %q", strings.TrimSpace(string(out)))
}
return v, nil
}

// Run implements Harness. It runs `pi -p` with the JSON output.
//
// The configuration folder of Pi and its session folder are next to the
// workspace, so the extensions, the skills and the settings of the user who
// runs the suite do not load, and the sessions of the suite do not mix with
// the sessions of the user. --approve trusts the project files of the
// workspace, which hold the Chainloop extension.
//
// The Chainloop extension gives its instruction and reminder to the model as
// hidden context, which the run output does not show. Until the suite reads
// them from the session file, the hook messages are not reported.
func (p *Pi) Run(ctx context.Context, req RunRequest) (*RunOutput, error) {
base := filepath.Dir(req.Dir)
args := []string{
"-p", "--mode", "json", "--approve",
flagModel, req.Model,
"--session-dir", filepath.Join(base, "pi-sessions"),
}

// A pasted image goes in as an attached file, from outside the
// repository, so that the agent cannot commit it.
if len(req.Images) > 0 {
dir, err := os.MkdirTemp("", "chainloop-trace-e2e-")
if err != nil {
return nil, err
}
defer os.RemoveAll(dir)
for i, img := range req.Images {
path := filepath.Join(dir, fmt.Sprintf("pasted-%d.png", i+1))
if err := os.WriteFile(path, img, 0o600); err != nil {
return nil, err
}
args = append(args, "@"+path)
}
}
args = append(args, req.Prompt)

name := p.bin()
if len(req.Wrapper) > 0 {
name = req.Wrapper[0]
args = append(append(append([]string{}, req.Wrapper[1:]...), p.bin()), args...)
}

cmd := exec.CommandContext(ctx, name, args...) //nolint:gosec // the harness binary under test, with the prompt of a scenario // nosemgrep
cmd.Dir = req.Dir
cmd.Env = append(slices.Clone(req.Env),
"PI_CODING_AGENT_DIR="+filepath.Join(base, "pi-agent"),
"PI_SKIP_VERSION_CHECK=1",
"PI_TELEMETRY=0",
)
var stderr bytes.Buffer
cmd.Stderr = &stderr

raw, err := cmd.Output()
if err != nil {
return &RunOutput{Raw: raw}, fmt.Errorf("pi -p: %w: %s", err, strings.TrimSpace(stderr.String()))
}

return &RunOutput{Raw: raw}, nil
}

// HookConfig implements Harness. The Chainloop extension is a file of its
// own, so the extension of the user is in another file.
func (p *Pi) HookConfig() HookConfig {
return HookConfig{
Path: piExtensionPath,
ChainloopMarker: "chainloop",
UserPath: ".pi/extensions/e2e-user.ts",
UserConfig: `// e2e-user-hook
export default function () {}
`,
UserMarker: userHookMarker,
}
}

// errPiSessionStart is the error of DisableSessionStart until the suite
// knows the shape of the Chainloop extension.
var errPiSessionStart = errors.New("pi: the suite cannot remove the session-start hook of the Chainloop extension yet")

// DisableSessionStart implements Harness. The Chainloop extension of Pi does
// not exist yet, so there is no handler to change.
func (p *Pi) DisableSessionStart(string) error {
return errPiSessionStart
}

// SkillPath implements Harness. Pi finds project skills in .agents/skills.
func (p *Pi) SkillPath(name string) string {
return ".agents/skills/" + name + "/SKILL.md"
}
Loading