lakehouse/bot/test.ts
profit f44b6b3e6b Control-plane pivot: Phase 38-44 plan + bot scaffold
Direction shift 2026-04-22: docs/CONTROL_PLANE_PRD.md becomes the
long-horizon architecture target. Existing Lakehouse (docs/PRD.md,
Phases 0-37) is preserved as the reference implementation and first
consumer. New 6-layer architecture:

  L1 Universal API /v1/chat /v1/usage /v1/sessions /v1/tools /v1/context
  L2 Routing & Policy Engine (rules, fallback chains, cost gating)
  L3 Provider Adapter Layer (Ollama + OpenRouter + Gemini + Claude)
  L4 Knowledge + Memory + Playbooks (already built)
  L5 Execution Loop (scenarios + bot/cycle.ts instances)
  L6 Observability + token accounting

Phases 38-44 sequenced with detailed per-phase specs in the PRD.
Current scope: staffing domain (synthetic workers_500k, contracts,
emails, SMS, playbooks). DevOps (Terraform/Ansible) is long-horizon
target — architecture-compatible but not current.

Files added:
- docs/CONTROL_PLANE_PRD.md — 6-layer architecture, Phase 38-44
  sequencing with staffing-first Truth Layer + Validation pipeline
- bot/ — manual-only PR bot scaffold. First consumer test-bed for
  /v1/chat (Phase 38). Mem0-aligned ADD/UPDATE/NOOP apply semantics;
  KB feedback loop reads prior cycles on same gap and injects into
  cloud prompt so bot cycles compound like scenario.ts runs do.
- tests/multi-agent/run_stress.ts — the 6-task diverse stress test
  referenced in the previous commit but missing from its staging

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 02:43:31 -05:00

47 lines
1.6 KiB
TypeScript

// Run the test gate: `cargo test --workspace` + `bun test`.
// Returns { green, output } — output is last ~4KB of combined stdout/stderr.
import { spawn } from "node:child_process";
const REPO_ROOT = "/home/profit/lakehouse";
const TEST_TIMEOUT_MS = 15 * 60 * 1000; // 15 min cargo + 2 min bun, generous
export async function runTests(): Promise<{ green: boolean; output: string }> {
const cargoOut = await runCmd("cargo", ["test", "--workspace", "--quiet", "--", "--test-threads=1"], REPO_ROOT, TEST_TIMEOUT_MS);
if (cargoOut.code !== 0) {
return { green: false, output: tail(`cargo test (${cargoOut.code}):\n${cargoOut.combined}`) };
}
const bunOut = await runCmd("bun", ["test", "tests/multi-agent"], REPO_ROOT, 120000);
const bunGreen = bunOut.code === 0;
const combined = [
`cargo test: OK`,
`bun test (${bunOut.code}):`,
bunOut.combined,
].join("\n");
return { green: bunGreen, output: tail(combined) };
}
function tail(s: string, n = 4096): string {
return s.length > n ? "…" + s.slice(-n) : s;
}
function runCmd(
cmd: string,
args: string[],
cwd: string,
timeoutMs: number,
): Promise<{ code: number; combined: string }> {
return new Promise(resolveP => {
const child = spawn(cmd, args, { cwd, env: { ...process.env } });
let combined = "";
child.stdout.on("data", d => { combined += d.toString(); });
child.stderr.on("data", d => { combined += d.toString(); });
const timer = setTimeout(() => child.kill("SIGKILL"), timeoutMs);
child.on("close", code => {
clearTimeout(timer);
resolveP({ code: code ?? -1, combined });
});
});
}