Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

3.3 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { workflowStartProjection } from "./tools-workflow-start-output";

describe("workflow_start structured projection", () => {
  it("carries selected agent/project memory and recipe context to compact clients", () => {
    const projected = workflowStartProjection({
      workflow: { id: "wf-1", intent: "fix memory retrieval", project: "/srv/mso", startedAt: "2026-09-19T00:00:00.000Z", steps: [] },
      bootstrap: {
        orchestration: {
          memoryHits: 3,
          agentMemory: [{ ref: "MEMORY.md#Browser gotcha", kind: "procedural", key: "Browser gotcha", value: "Camoufox is on-demand.", score: 14 }],
          memory: [{ id: "mem-project-1", kind: "failure", title: "Prior regression", summary: "Viewer failed after stale auth.", score: 0.91, lastVerified: "2026-09-18T10:00:00.000Z" }],
          recipe: {
            id: "recipe-1", maturity: "verified", attempts: 4, successRate: 100,
            steps: [{ tool: "browser_status" }, { tool: "exec_run" }],
            instruction: "Prefer the verified bounded route when current evidence is compatible.",
          },
        },
      },
    }) as { context: { memoryHits: number; memory: Array<{ source: string; ref: string; text: string }>; recipe: { id: string; maturity: string; tools: string[] } } };

    expect(projected.context.memoryHits).toBe(3);
    expect(projected.context.memory).toEqual([
      expect.objectContaining({ source: "agent", ref: "MEMORY.md#Browser gotcha", text: "Camoufox is on-demand." }),
      expect.objectContaining({ source: "project", ref: "mem-project-1", text: "Viewer failed after stale auth." }),
    ]);
    expect(projected.context.recipe).toMatchObject({ id: "recipe-1", maturity: "verified", tools: ["browser_status", "exec_run"] });
  });

  it("exposes exact authorized workspace paths without unrelated orchestration data", () => {
    const workspacePath = "/srv/task worktree/" + "deep/".repeat(50);
    const projected = workflowStartProjection({
      workflow: {
        id: "wf-workspace", project: "/srv/mso", startedAt: "2026-10-17T00:00:00.000Z", steps: [],
        orchestration: { workspacePath, isolation: "isolated-worktree", baseCommit: "abc123", baseBranch: "main", reservedResources: ["private-context"] },
      },
    });
    expect(projected?.workspace).toEqual({ path: workspacePath, projectPath: "/srv/mso", isolation: "isolated-worktree", baseCommit: "abc123", baseBranch: "main" });
    expect(JSON.stringify(projected)).not.toContain("private-context");
  });

  it("does not invent a workspace for unresolved host work", () => {
    const projected = workflowStartProjection({ workflow: { id: "wf-host", project: "@host", startedAt: "2026-10-17T00:00:00.000Z", steps: [] } });
    expect(projected).not.toHaveProperty("workspace");
  });

  it("falls back to projected memory plus recipe when orchestration count is absent", () => {
    const projected = workflowStartProjection({
      workflow: { id: "wf-2", startedAt: "2026-09-19T00:00:00.000Z", steps: [] },
      bootstrap: { orchestration: { agentMemory: [{ ref: "USER.md#Locale", value: "Indonesia" }], recipe: { id: "r", maturity: "candidate", attempts: 2, successRate: 100, steps: [] } } },
    }) as { context: { memoryHits: number } };
    expect(projected.context.memoryHits).toBe(2);
  });
});