Files
archie/internal/app/archied/harness_run_test.go
T
sam acec5d392d feat(archied): read-only run-scoped sandbox view over the harness contract (#1662)
* feat(archied): read-only run-scoped sandbox view over the harness contract

Serve RunTarget: the daemon resolves a running task and attempt to its Kit
container and follows its output, refusing a finished or unknown task with a
stated reason. The dashboard adds a Sandbox tab behind the task log's read
authority. Takeover stays out of scope until the sod1 authority is wired.

* fix(archied): scope and close sandbox views correctly

Forward harness activity into container output, bind containers and dashboard views to their attempt, enforce the asserted org, and report unavailable dependencies and interrupted streams accurately.

Refs: archie-core-qi91, archie-core-252tj
2026-10-14 02:57:32 +11:00

66 lines
2.3 KiB
Go

package archied
import (
"context"
"errors"
"io"
"strings"
"testing"
"github.com/containerd/errdefs"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
pb "github.com/samcharles93/archie-core/internal/contracts/harness/v1"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/domain/workflow"
)
type fakeTasks struct {
task *workflow.Task
err error
}
func (f fakeTasks) TaskByID(context.Context, int64) (*workflow.Task, error) { return f.task, f.err }
func TestRunViewOpen(t *testing.T) {
running := &workflow.Task{ID: 7, Status: workflow.StatusRunning, Attempt: 2}
cases := []struct {
name string
tasks fakeTasks
attempt int64
follow error
code codes.Code
reason string
}{
{"running attempt", fakeTasks{task: running}, 2, nil, codes.OK, ""},
{"unknown task", fakeTasks{}, 2, nil, codes.NotFound, "unknown"},
{"finished task", fakeTasks{task: &workflow.Task{ID: 7, Status: workflow.StatusParked, Attempt: 2}}, 2, nil, codes.NotFound, "not running"},
{"earlier attempt", fakeTasks{task: running}, 1, nil, codes.NotFound, "attempt 1 is not running"},
{"container gone", fakeTasks{task: running}, 2, errdefs.ErrNotFound, codes.NotFound, "no running sandbox"},
{"store down", fakeTasks{err: errors.New("dial")}, 2, nil, codes.Unavailable, "unavailable"},
{"other org", fakeTasks{task: &workflow.Task{ID: 7, Org: "other", Status: workflow.StatusRunning, Attempt: 2}}, 2, nil, codes.NotFound, "unknown"},
{"docker down", fakeTasks{task: running}, 2, errors.New("connection refused"), codes.Unavailable, "unavailable"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
v := &runView{tasks: tc.tasks, follow: func(context.Context, int64, int64) (io.ReadCloser, error) {
if tc.follow != nil {
return nil, tc.follow
}
return io.NopCloser(strings.NewReader("")), nil
}}
rc, err := v.open(org.WithOrg(t.Context(), org.DefaultOrgID), &pb.RunTarget{TaskId: 7, Attempt: tc.attempt})
if got := status.Code(err); got != tc.code {
t.Fatalf("code = %v (%v), want %v", got, err, tc.code)
}
if err != nil && !strings.Contains(err.Error(), tc.reason) {
t.Fatalf("reason %q does not state %q", err, tc.reason)
}
if rc != nil {
_ = rc.Close()
}
})
}
}