mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-23 14:33:36 +08:00
fix(context): normalize attachments in status analysis (#1022)
This commit is contained in:
parent
2d58d11fb1
commit
0bbfc62907
59
src/utils/analyzeContext.test.ts
Normal file
59
src/utils/analyzeContext.test.ts
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import { afterAll, beforeAll, describe, expect, test } from 'bun:test'
|
||||||
|
import { mkdtemp, rm } from 'node:fs/promises'
|
||||||
|
import { tmpdir } from 'node:os'
|
||||||
|
import { join } from 'node:path'
|
||||||
|
|
||||||
|
let configDir: string
|
||||||
|
const originalConfigDir = process.env.CLAUDE_CONFIG_DIR
|
||||||
|
const originalSimpleMode = process.env.CLAUDE_CODE_SIMPLE
|
||||||
|
|
||||||
|
describe('analyzeContextUsage', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
configDir = await mkdtemp(join(tmpdir(), 'cc-haha-analyze-context-'))
|
||||||
|
process.env.CLAUDE_CONFIG_DIR = configDir
|
||||||
|
process.env.CLAUDE_CODE_SIMPLE = '1'
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
if (originalConfigDir === undefined) {
|
||||||
|
delete process.env.CLAUDE_CONFIG_DIR
|
||||||
|
} else {
|
||||||
|
process.env.CLAUDE_CONFIG_DIR = originalConfigDir
|
||||||
|
}
|
||||||
|
if (originalSimpleMode === undefined) {
|
||||||
|
delete process.env.CLAUDE_CODE_SIMPLE
|
||||||
|
} else {
|
||||||
|
process.env.CLAUDE_CODE_SIMPLE = originalSimpleMode
|
||||||
|
}
|
||||||
|
await rm(configDir, { recursive: true, force: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('analyzes attachment messages for the context status view', async () => {
|
||||||
|
const { analyzeContextUsage } = await import('./analyzeContext.js')
|
||||||
|
|
||||||
|
const result = await analyzeContextUsage(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'attachment',
|
||||||
|
attachment: { type: 'directory', path: configDir },
|
||||||
|
uuid: 'issue-1022',
|
||||||
|
timestamp: '2026-07-17T00:00:00.000Z',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'claude-sonnet-4-20250514',
|
||||||
|
async () => ({ mode: 'default' }),
|
||||||
|
[],
|
||||||
|
{ activeAgents: [], allAgents: [] },
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
{ estimateOnly: true },
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(result.messageBreakdown?.attachmentTokens).toBeGreaterThan(0)
|
||||||
|
expect(result.messageBreakdown?.attachmentsByType).toEqual([
|
||||||
|
{ name: 'directory', tokens: expect.any(Number) },
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -60,7 +60,10 @@ import { logForDebugging } from './debug.js'
|
|||||||
import { isEnvTruthy } from './envUtils.js'
|
import { isEnvTruthy } from './envUtils.js'
|
||||||
import { errorMessage, toError } from './errors.js'
|
import { errorMessage, toError } from './errors.js'
|
||||||
import { logError } from './log.js'
|
import { logError } from './log.js'
|
||||||
import { normalizeMessagesForAPI } from './messages.js'
|
import {
|
||||||
|
normalizeAttachmentForAPI,
|
||||||
|
normalizeMessagesForAPI,
|
||||||
|
} from './messages.js'
|
||||||
import { getRuntimeMainLoopModel } from './model/model.js'
|
import { getRuntimeMainLoopModel } from './model/model.js'
|
||||||
import { isFirstPartyAnthropicBaseUrl } from './model/providers.js'
|
import { isFirstPartyAnthropicBaseUrl } from './model/providers.js'
|
||||||
import type { SettingSource } from './settings/constants.js'
|
import type { SettingSource } from './settings/constants.js'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user