fix: update test expectations for observation salvage (intentional #1908 behavior change)

- Update test: parseSummary with <observation> tags now returns salvaged
  summary object instead of null, matching the intentional #1908 behavior
- Fix docstring: salvageSummaryFromObservationTags extracts from all
  observations, not just the first
- Add explanatory comment in test linking #1360#1908 behavior change

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alex Newman
2026-04-18 14:42:15 -07:00
parent 88bfadf517
commit cbeddef2d7
2 changed files with 15 additions and 3 deletions

View File

@@ -206,7 +206,8 @@ export function parseSummary(text: string, sessionId?: number): ParsedSummary |
/**
* Salvage a ParsedSummary from <observation> tags when the LLM failed to
* emit <summary> tags. Extracts title → request, narrative → learned,
* and facts → investigated/completed fields from the first observation.
* and facts → investigated/completed fields from all observations,
* joining multiple values with semicolons or double newlines.
* Returns null only if the observation content is completely empty. (#1908)
*/
function salvageSummaryFromObservationTags(text: string, sessionId?: number): ParsedSummary | null {

View File

@@ -8,8 +8,19 @@ import { describe, it, expect } from 'bun:test';
import { parseSummary } from '../../src/sdk/parser.js';
describe('parseSummary', () => {
it('returns null when no <summary> tag present', () => {
expect(parseSummary('<observation><title>foo</title></observation>')).toBeNull();
// Intentional behavior change from #1908: parseSummary now salvages data from
// <observation> tags when no <summary> tags are present, rather than discarding
// the output. Previously this returned null (see #1360), but #1908 determined
// that discarding observation-tagged output loses valuable session data.
it('salvages summary from <observation> tags when no <summary> tag present (#1908)', () => {
const result = parseSummary('<observation><title>foo</title></observation>');
expect(result).not.toBeNull();
expect(result?.request).toBe('foo');
expect(result?.investigated).toBeNull();
expect(result?.learned).toBeNull();
expect(result?.completed).toBeNull();
expect(result?.next_steps).toBeNull();
expect(result?.notes).toBeNull();
});
it('returns null when <summary> has no sub-tags (false positive — fix for #1360)', () => {