mirror of
https://github.com/Gitlawb/openclaude.git
synced 2026-08-24 10:14:19 -05:00
fix(typecheck): type session storage test fixtures (#1526)
* fix(typecheck): type session storage test fixtures * fix(typecheck): align snip boundary fixture ids
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { afterEach, expect, test } from 'bun:test'
|
||||
import type { ToolResultBlockParam } from '@anthropic-ai/sdk/resources/index.mjs'
|
||||
import { type UUID } from 'node:crypto'
|
||||
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
@@ -27,7 +28,7 @@ function id(n: number): UUID {
|
||||
return `00000000-0000-4000-8000-${String(n).padStart(12, '0')}` as UUID
|
||||
}
|
||||
|
||||
function base(uuid: string, parentUuid: string | null) {
|
||||
function base(uuid: UUID, parentUuid: UUID | null) {
|
||||
return {
|
||||
uuid,
|
||||
parentUuid,
|
||||
@@ -40,7 +41,11 @@ function base(uuid: string, parentUuid: string | null) {
|
||||
}
|
||||
}
|
||||
|
||||
function user(uuid: string, parentUuid: string | null, content: string) {
|
||||
function user(
|
||||
uuid: UUID,
|
||||
parentUuid: UUID | null,
|
||||
content: string | ToolResultBlockParam[],
|
||||
) {
|
||||
return {
|
||||
...base(uuid, parentUuid),
|
||||
type: 'user',
|
||||
@@ -52,7 +57,7 @@ function user(uuid: string, parentUuid: string | null, content: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function assistant(uuid: string, parentUuid: string | null, text: string) {
|
||||
function assistant(uuid: UUID, parentUuid: UUID | null, text: string) {
|
||||
return {
|
||||
...base(uuid, parentUuid),
|
||||
type: 'assistant',
|
||||
@@ -74,12 +79,12 @@ function assistant(uuid: string, parentUuid: string | null, text: string) {
|
||||
}
|
||||
|
||||
function compactBoundary(
|
||||
uuid: string,
|
||||
parentUuid: string | null,
|
||||
uuid: UUID,
|
||||
parentUuid: UUID | null,
|
||||
preservedSegment: {
|
||||
headUuid: string
|
||||
anchorUuid: string
|
||||
tailUuid: string
|
||||
headUuid: UUID
|
||||
anchorUuid: UUID
|
||||
tailUuid: UUID
|
||||
},
|
||||
) {
|
||||
return {
|
||||
@@ -98,9 +103,9 @@ function compactBoundary(
|
||||
}
|
||||
|
||||
function snipBoundary(
|
||||
uuid: string,
|
||||
parentUuid: string | null,
|
||||
removedUuids: string[],
|
||||
uuid: UUID,
|
||||
parentUuid: UUID | null,
|
||||
removedUuids: UUID[],
|
||||
) {
|
||||
return {
|
||||
...base(uuid, parentUuid),
|
||||
@@ -121,6 +126,23 @@ async function writeJsonl(entries: unknown[]): Promise<string> {
|
||||
return filePath
|
||||
}
|
||||
|
||||
function getToolResultContent(content: unknown): string | undefined {
|
||||
if (!Array.isArray(content)) return undefined
|
||||
|
||||
const [block] = content
|
||||
if (
|
||||
typeof block !== 'object' ||
|
||||
block === null ||
|
||||
!('type' in block) ||
|
||||
block.type !== 'tool_result' ||
|
||||
!('content' in block)
|
||||
) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return typeof block.content === 'string' ? block.content : undefined
|
||||
}
|
||||
|
||||
function readGoalStateEntries(text: string): Array<{ goal: GoalState | null }> {
|
||||
return text
|
||||
.split('\n')
|
||||
@@ -300,18 +322,14 @@ test('loadTranscriptFile fails closed when preserved-segment anchor is missing',
|
||||
})
|
||||
|
||||
test('stripPersistedToolUseResultsFromJSONLBuffer drops raw toolUseResult while preserving persisted preview content', () => {
|
||||
const persisted = user(id(31), null, 'placeholder')
|
||||
persisted.message = {
|
||||
role: 'user',
|
||||
content: [
|
||||
{
|
||||
type: 'tool_result',
|
||||
tool_use_id: 'tool-31',
|
||||
is_error: false,
|
||||
content: '<persisted-output>\nPreview text\n</persisted-output>',
|
||||
},
|
||||
],
|
||||
}
|
||||
const persisted = user(id(31), null, [
|
||||
{
|
||||
type: 'tool_result',
|
||||
tool_use_id: 'tool-31',
|
||||
is_error: false,
|
||||
content: '<persisted-output>\nPreview text\n</persisted-output>',
|
||||
},
|
||||
])
|
||||
;(persisted as typeof persisted & { toolUseResult?: unknown }).toolUseResult = {
|
||||
stdout: 'x'.repeat(200_000),
|
||||
stderr: '',
|
||||
@@ -324,24 +342,18 @@ test('stripPersistedToolUseResultsFromJSONLBuffer drops raw toolUseResult while
|
||||
>
|
||||
|
||||
expect(parsed?.toolUseResult).toBeUndefined()
|
||||
expect(
|
||||
(parsed?.message.content as Array<{ content: string }>)[0]?.content,
|
||||
).toContain('Preview text')
|
||||
expect(getToolResultContent(parsed?.message.content)).toContain('Preview text')
|
||||
})
|
||||
|
||||
test('loadTranscriptFile omits raw toolUseResult for persisted-output transcript entries', async () => {
|
||||
const persisted = user(id(41), null, 'placeholder')
|
||||
persisted.message = {
|
||||
role: 'user',
|
||||
content: [
|
||||
{
|
||||
type: 'tool_result',
|
||||
tool_use_id: 'tool-41',
|
||||
is_error: false,
|
||||
content: '<persisted-output>\nPreview text\n</persisted-output>',
|
||||
},
|
||||
],
|
||||
}
|
||||
const persisted = user(id(41), null, [
|
||||
{
|
||||
type: 'tool_result',
|
||||
tool_use_id: 'tool-41',
|
||||
is_error: false,
|
||||
content: '<persisted-output>\nPreview text\n</persisted-output>',
|
||||
},
|
||||
])
|
||||
;(persisted as typeof persisted & { toolUseResult?: unknown }).toolUseResult = {
|
||||
stdout: 'y'.repeat(200_000),
|
||||
stderr: '',
|
||||
@@ -355,9 +367,7 @@ test('loadTranscriptFile omits raw toolUseResult for persisted-output transcript
|
||||
|
||||
expect(loaded).toBeDefined()
|
||||
expect(loaded?.toolUseResult).toBeUndefined()
|
||||
expect(
|
||||
(loaded?.message.content as Array<{ content: string }>)[0]?.content,
|
||||
).toContain('Preview text')
|
||||
expect(getToolResultContent(loaded?.message.content)).toContain('Preview text')
|
||||
})
|
||||
|
||||
test('loadTranscriptFile restores last goal-state metadata entry', async () => {
|
||||
|
||||
Reference in New Issue
Block a user