Search the web for best practices around iterative test harness patterns for LLM/chatbot evaluation in TypeScript codebases. Also search GitHub for similar LangGraph test harness files using streamQuery, resetGraph, and streamEvents patterns to see how other projects structure multi-run test loops. Look for patterns around:
How to structure large inline question arrays in chatbot test harnesses (should they be in separate files?)
Best patterns for organizing test/eval question fixtures
How other LangGraph projects structure their iterative evaluation harnesses
Common approaches for splitting large monolithic test scripts into modular components
Return a summary of findings with concrete patterns and examples.
Assistant
Let me dig deeper into the most promising results and search GitHub for specific patterns.
Assistant
Now let me search GitHub for real TypeScript LangGraph test harness patterns with those specific APIs:
Assistant
Let me search more specifically for LangGraph evaluation/test harness patterns and the specific APIs:
Assistant
Let me search more specifically for LangGraph TypeScript test patterns and look at the existing codebase:
Assistant
Let me look at the existing BBallGenius test harness and search for more specific patterns:
Assistant
Let me search for a few more specific patterns and look at the existing eval directory structure:
Assistant
Now I have comprehensive research findings. Here is my summary:
Summary of Findings: Iterative Test Harness Patterns for LLM/Chatbot Evaluation in TypeScript
1. How to Structure Large Inline Question Arrays
Key Insight: Separate them into their own files, organized by purpose and tier.
The BBallGenius codebase demonstrates this well with three distinct question fixture files:
Industry practice (LangSmith, Langfuse): Use external JSONL/JSON datasets created via LangSmith Client.create_dataset() + Client.create_examples(), then referenced by name in evaluation runs. This decouples test data from runner code entirely.
2. Best Patterns for Organizing Test/Eval Question Fixtures
Layer 1: Interface (types file)
Define the Question or EvalQuery interface with the right abstraction level
Key takeaway: The three-way comparison pattern (agent vs DB vs external-ground-truth) is powerful. It distinguishes agent_bug (agent wrong when DB is correct) from data_quality (DB wrong vs external truth) from stale_test_expected (test expectations are outdated vs external truth).
3. How Other LangGraph Projects Structure Iterative Evaluation Harnesses
4. Common Approaches for Splitting Large Monolithic Test Scripts
The BBallGenius codebase demonstrates a multi-layer modular decomposition:
code
scripts/
chatbot-smoke.ts # Scenario A: CLI smoke test (invoke-based, keyword matching)
chatbot-eval-multi-model.ts # Scenario B: Multi-model iteration loop (invoke-based)
iterate_loop.ts # Scenario C: Detailed streaming trace (stream-based)
src/tabs/chatbot/eval/
nba-100-queries.ts # Module 1: Large question array (100 items)
question-matrix.ts # Module 2: Behavioral matrix (30 items, 4 tiers)
matrixHarness.ts # Module 3: Matrix-driven eval runner with BBR truth
bbrTruth.ts / bbr-truth.json # Module 4: External truth source resolver
dbTruth.ts # Module 5: DB truth reader
ground-truth.json # Module 6: Legacy truth (deprecated)
__fixtures__/ # Static test fixtures (HTML files)
__tests__/ # Unit tests for parser modules
The modular decomposition layers:
Layer
Responsibility
Example
Question data
Pure arrays of objects
nba-100-queries.ts, question-matrix.ts
Truth resolvers
Fetch/generate expected values
bbrTruth.ts, dbTruth.ts
Evaluator logic
Score answers against expectations
Inline evaluateAnswer(), checkAnswer()
Runner harness
Orchestrate question loop, streaming, timeout
matrixHarness.ts, iterate_loop.ts
Report generation
Aggregate results, produce summary
Inline at end of each harness
Config
Environment variable-driven parameters
RUNS_PER_QUESTION, RUN_TIMEOUT_MS, LOG_DIR
Key decomposition recommendations:
Never put 100+ questions inline in a test script — extract to a separate file
Separate question data (pure data) from runner logic (orchestration with resetGraph/streamQuery/invoke)
Separate evaluator logic (how to score an answer) from harness logic (how to run the agent)
Use a typed interface that all question arrays conform to
For truth anchors, use a resolver pattern (e.g., resolveBbrValue(id) abstracts the underlying JSON)
Use environment variables for config (timeouts, concurrency, model selection) rather than hardcoding
Concrete Code Examples
Best practice: Shared event loop pattern (from matrixHarness.ts):
typescript
async function runAgent(question, prompt, threadId) {
const deadline = Date.now() + RUN_TIMEOUT_MS;
resetGraph(); // 1. Reset state per run
const gen = streamQuery([ // 2. Start streaming
new SystemMessage(prompt),
new HumanMessage(question)
], threadId);
const it = gen[Symbol.asyncIterator]();
while (Date.now() < deadline) {
const remaining = Math.max(1, deadline - Date.now());
const next = await Promise.race([ // 3. Timeout per event
it.next(),
new Promise((_, rej) =>
setTimeout(() => rej(new Error('TIMEOUT')), remaining)
),
]);
if (next.done) break;
const ev = next.value;
// 4. Handle token / tool_start / tool_end / done / error
if (ev.type === 'token') { /* accumulate */ }
else if (ev.type === 'done') { /* extract answer */ }
}
}
Best practice: Three-way verdict classification (from matrixHarness.ts):
typescript
// Verdict classification: agent vs DB vs external truth
function finalizeFactual(result, question) {
for (const c of result.comparisons) {
if (c.bbrVerified && c.dbSupported) {
c.dbMatchesBbr = valuesMatch(c.db, c.bbr);
if (!c.dbMatchesBbr) anyVerifiedMismatch = true;
}
}
if (anyVerifiedMismatch)
return { verdict: 'data_quality', passed: false }; // DB wrong, not agent
if (agent matches BBR)
return { verdict: 'pass', passed: true }; // Agent correct
else
return { verdict: 'agent_bug', passed: false }; // Agent wrong
}
Best practice: Multi-model iteration (from chatbot-eval-multi-model.ts):
typescript
const MODELS = ['model-a', 'model-b', 'model-c'];
async function runIteration(iteration, questions, systemPrompt) {
for (const model of MODELS) {
setModel(model);
resetGraph();
for (const q of questions) {
const result = await runTestForModel(model, q, systemPrompt, iteration);
// classify: PASS, WRONG_ANSWER, SQL_ERROR, LOOP, TIMEOUT, etc.
}
// Detect failure patterns across all models
const fixes = analyzeFailures(iterationResults);
// loopFailures → bump recursion limit
// sqlErrors → improve prompt with schema hints
// wrongAnswers → refine system prompt
}
}
Limitations / Gaps
No real open-source TypeScript LangGraph evaluation harnesses found on GitHub using streamEvents with LangGraph specifically — the streamEvents API is more commonly used with Vercel AI SDK adapters and LangChain runnables, not LangGraph's own streamEvents v2 (which is newer).
Most LangGraph eval tooling is Python-first — LangSmith's aevaluate(), Langfuse's dataset.run_experiment(), Composo's composo_client.evaluate(), and Promptfoo's YAML providers are Python-centric. TypeScript LangGraph projects tend to build their own harnesses from scratch.
The resetGraph pattern doesn't appear in public GitHub repositories at scale — it's an internal pattern in the BBallGenius codebase that resets the cached singleton graph instance.
No standardized "fixture format" for LangGraph test questions across the industry — each project defines its own interface.