Skip to content
Draft
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
71 changes: 27 additions & 44 deletions source/agent-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe('parseStringResult()', () => {
assert({
given: 'JSON string starting with {',
should: 'parse as JSON object',
actual: JSON.stringify(result),
expected: '{"passed":true,"output":"test"}'
actual: result,
expected: { passed: true, output: 'test' }
});

assert({
Expand All @@ -47,8 +47,8 @@ describe('parseStringResult()', () => {
assert({
given: 'JSON string starting with [',
should: 'parse as JSON array',
actual: result.length,
expected: 2
actual: result,
expected: [{ id: 1 }, { id: 2 }]
});
});

Expand All @@ -61,8 +61,8 @@ describe('parseStringResult()', () => {
assert({
given: 'markdown-wrapped JSON',
should: 'extract and parse JSON',
actual: JSON.stringify(result),
expected: '{"passed":true,"output":"test"}'
actual: result,
expected: { passed: true, output: 'test' }
});

assert({
Expand All @@ -82,8 +82,8 @@ describe('parseStringResult()', () => {
assert({
given: 'markdown without json tag',
should: 'extract and parse JSON',
actual: result.passed,
expected: true
actual: result,
expected: { passed: true }
});
});

Expand All @@ -96,8 +96,8 @@ describe('parseStringResult()', () => {
assert({
given: 'malformed JSON with markdown fallback',
should: 'extract from markdown block',
actual: result.passed,
expected: true
actual: result,
expected: { passed: true }
});

assert({
Expand Down Expand Up @@ -156,13 +156,6 @@ describe('parseStringResult()', () => {

const result = parseStringResult(input, logger);

assert({
given: 'JSON with surrounding whitespace',
should: 'parse successfully',
actual: result.passed,
expected: true
});

assert({
given: 'JSON with surrounding whitespace',
should: 'return parsed object matching trimmed input',
Expand Down Expand Up @@ -261,30 +254,15 @@ describe('parseOpenCodeNDJSON()', () => {

assert({
given: 'NDJSON with no text events',
should: 'have ParseError name in cause',
actual: error?.cause?.name,
expected: 'ParseError'
});

assert({
given: 'NDJSON with no text events',
should: 'have NO_TEXT_EVENTS code in cause',
actual: error?.cause?.code,
expected: 'NO_TEXT_EVENTS'
});

assert({
given: 'NDJSON with no text events',
should: 'include ndjsonLength in cause',
actual: typeof error?.cause?.ndjsonLength === 'number',
expected: true
});

assert({
given: 'NDJSON with no text events',
should: 'include linesProcessed in cause',
actual: error?.cause?.linesProcessed,
expected: 2
should: 'throw Error with full ParseError cause',
actual: error?.cause,
expected: {
name: 'ParseError',
code: 'NO_TEXT_EVENTS',
message: 'No text events found in OpenCode output',
ndjsonLength: ndjson.length,
linesProcessed: 2
}
});
});

Expand Down Expand Up @@ -369,9 +347,14 @@ describe('unwrapAgentResult()', () => {

assert({
given: 'plain text that is not valid JSON',
should: 'throw Error with ParseError cause',
actual: error?.cause?.name,
expected: 'ParseError'
should: 'throw Error with full ParseError cause',
actual: error?.cause,
expected: {
name: 'ParseError',
code: 'PARSE_FAILURE',
message: 'Agent output is not valid JSON: plain text response',
outputPreview: 'plain text response'
}
});
});

Expand Down
Loading