Repository navigation
fix(session): persist listing deltas so Moonshot prefix cache survives --resume #2070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 24 commits
6cd7a8e
9906d47
4f38f3c
9900083
692c9e3
8a0888b
a3c41fe
6048862
ee39fe3
52f5a6f
ae14a6e
2c484c4
f617f07
2747ba2
373ab79
bc12205
6ccb7d4
9f6fd3b
275e850
1ae5f3a
7dce8c0
dee0c6e
877c882
d4fcbf2
4bec70b
c9b1f35
5f9fd15
9644d07
e4db0f2
a2461f6
3fb14c4
e770e64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| import { afterAll, beforeAll, expect, mock, test } from 'bun:test' | ||
| import { mkdtemp, rm, writeFile } from 'node:fs/promises' | ||
| import { tmpdir } from 'node:os' | ||
| import { join } from 'node:path' | ||
| import type { Message } from '../../types/message.js' | ||
| import { | ||
| acquireSharedMutationLock, | ||
| releaseSharedMutationLock, | ||
| } from '../../test/sharedMutationLock.js' | ||
|
|
||
| type AxiosModule = typeof import('axios') | ||
|
|
||
| let originalAxiosModule: AxiosModule | undefined | ||
| let tempDir: string | undefined | ||
| let postedBodies: Array<{ content?: string }> = [] | ||
|
|
||
| function buildAxiosModuleStub( | ||
| post: (...args: unknown[]) => Promise<unknown>, | ||
| ): AxiosModule { | ||
| const instance = { | ||
| get: async () => ({ status: 200 }), | ||
| post, | ||
| isAxiosError: () => false, | ||
| defaults: {} as Record<string, unknown>, | ||
| interceptors: { | ||
| request: { use: () => 0, eject: () => {} }, | ||
| response: { use: () => 0, eject: () => {} }, | ||
| }, | ||
| } | ||
| return { default: instance } as unknown as AxiosModule | ||
| } | ||
|
|
||
| beforeAll(async () => { | ||
| await acquireSharedMutationLock('submitTranscriptShare.egress') | ||
| originalAxiosModule = await import('axios') | ||
|
|
||
| // MACRO is build-time; stub for the under-test import path. | ||
| ;(globalThis as { MACRO?: { VERSION: string } }).MACRO = { | ||
| VERSION: 'test-version', | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| const realProviders = await import('../../utils/model/providers.js') | ||
| mock.module('../../utils/model/providers.js', () => ({ | ||
| ...realProviders, | ||
| isFirstPartyAnthropicProvider: () => true, | ||
| })) | ||
|
|
||
| const realAuth = await import('../../utils/auth.js') | ||
| mock.module('../../utils/auth.js', () => ({ | ||
| ...realAuth, | ||
| checkAndRefreshOAuthTokenIfNeeded: async () => {}, | ||
| })) | ||
|
|
||
| const realHttp = await import('../../utils/http.js') | ||
| mock.module('../../utils/http.js', () => ({ | ||
| ...realHttp, | ||
| getAuthHeaders: () => ({ | ||
| headers: { Authorization: 'Bearer test' }, | ||
| error: undefined, | ||
| }), | ||
| getUserAgent: () => 'test-agent', | ||
| })) | ||
|
|
||
| tempDir = await mkdtemp(join(tmpdir(), 'openclaude-transcript-share-')) | ||
| const transcriptPath = join(tempDir, 'session.jsonl') | ||
| await writeFile( | ||
| transcriptPath, | ||
| `${JSON.stringify({ | ||
| type: 'user', | ||
| uuid: '00000000-0000-4000-8000-00000000s001', | ||
| parentUuid: null, | ||
| timestamp: '2026-08-07T00:00:00.000Z', | ||
| message: { role: 'user', content: 'share me' }, | ||
| })}\n${JSON.stringify({ | ||
| type: 'attachment', | ||
| uuid: '00000000-0000-4000-8000-00000000s002', | ||
| parentUuid: '00000000-0000-4000-8000-00000000s001', | ||
| timestamp: '2026-08-07T00:00:00.000Z', | ||
| attachment: { | ||
| type: 'skill_listing', | ||
| content: 'Available skills:\n- /leak-me-please', | ||
| skillCount: 1, | ||
| isInitial: true, | ||
| }, | ||
| })}\n`, | ||
| ) | ||
|
|
||
| const realSession = await import('../../utils/sessionStorage.js') | ||
| mock.module('../../utils/sessionStorage.js', () => ({ | ||
| ...realSession, | ||
| getTranscriptPath: () => transcriptPath, | ||
| loadSubagentTranscripts: async () => ({ | ||
| 'agent-leak': [ | ||
| { | ||
| type: 'attachment', | ||
| uuid: '00000000-0000-4000-8000-00000000a101', | ||
| attachment: { | ||
| type: 'agent_listing_delta', | ||
| addedTypes: ['Explore'], | ||
| addedLines: ['- Explore: /leak-agent-listing'], | ||
| removedTypes: [], | ||
| isInitial: true, | ||
| showConcurrencyNote: false, | ||
| }, | ||
| }, | ||
| { | ||
| type: 'user', | ||
| uuid: '00000000-0000-4000-8000-00000000a102', | ||
| message: { role: 'user', content: 'subagent turn' }, | ||
| }, | ||
| ], | ||
| }), | ||
| })) | ||
|
|
||
| mock.module('axios', () => | ||
| buildAxiosModuleStub(async (_url: unknown, body: unknown) => { | ||
| postedBodies.push(body as { content?: string }) | ||
| return { status: 200, data: { transcript_id: 'shared-1' } } | ||
| }), | ||
| ) | ||
| }) | ||
|
|
||
| afterAll(async () => { | ||
| try { | ||
| if (originalAxiosModule) { | ||
| mock.module('axios', () => originalAxiosModule!) | ||
| } | ||
| if (tempDir) { | ||
| await rm(tempDir, { recursive: true, force: true }) | ||
| } | ||
| } finally { | ||
| releaseSharedMutationLock() | ||
| } | ||
| }) | ||
|
|
||
| test('submitTranscriptShare strips listing payloads from the outgoing content body', async () => { | ||
| postedBodies = [] | ||
| process.env.USER_TYPE = 'external' | ||
|
|
||
| const { submitTranscriptShare } = await import('./submitTranscriptShare.js') | ||
|
|
||
| const listing = { | ||
| type: 'attachment', | ||
| uuid: '00000000-0000-4000-8000-00000000m001', | ||
| attachment: { | ||
| type: 'skill_listing', | ||
| content: 'Available skills:\n- /leak-me-please', | ||
| skillCount: 1, | ||
| isInitial: true, | ||
| }, | ||
| } as unknown as Message | ||
| const user = { | ||
| type: 'user', | ||
| uuid: '00000000-0000-4000-8000-00000000m002', | ||
| message: { role: 'user', content: 'plain turn' }, | ||
| } as unknown as Message | ||
|
|
||
| const result = await submitTranscriptShare( | ||
| [listing, user], | ||
| 'bad_feedback_survey', | ||
| 'appearance-test', | ||
| ) | ||
|
|
||
| expect(result.success).toBe(true) | ||
| expect(postedBodies).toHaveLength(1) | ||
| const content = postedBodies[0]?.content ?? '' | ||
| expect(content).toContain('plain turn') | ||
| expect(content).not.toContain('leak-me-please') | ||
| expect(content).not.toContain('leak-agent-listing') | ||
| expect(content).toContain('subagent turn') | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,9 @@ import { isFirstPartyAnthropicProvider } from '../../utils/model/providers.js' | |
| import { normalizeMessagesForAPI } from '../../utils/messages.js' | ||
| import { | ||
| extractAgentIdsFromMessages, | ||
| filterJsonlForExternalEgress, | ||
| filterMessagesForExternalEgress, | ||
| filterSubagentTranscriptsForExternalEgress, | ||
| getTranscriptPath, | ||
| loadSubagentTranscripts, | ||
| MAX_TRANSCRIPT_READ_BYTES, | ||
|
|
@@ -38,19 +41,25 @@ export async function submitTranscriptShare( | |
| try { | ||
| logForDebugging('Collecting transcript for sharing', { level: 'info' }) | ||
|
|
||
| const transcript = normalizeMessagesForAPI(messages) | ||
| const transcript = normalizeMessagesForAPI( | ||
| filterMessagesForExternalEgress(messages), | ||
| ) | ||
|
|
||
| // Collect subagent transcripts | ||
| const agentIds = extractAgentIdsFromMessages(messages) | ||
| const subagentTranscripts = await loadSubagentTranscripts(agentIds) | ||
| const loadedSubagents = await loadSubagentTranscripts(agentIds) | ||
| const subagentTranscripts = | ||
| filterSubagentTranscriptsForExternalEgress(loadedSubagents) | ||
|
|
||
| // Read raw JSONL transcript (with size guard to prevent OOM) | ||
| let rawTranscriptJsonl: string | undefined | ||
| try { | ||
| const transcriptPath = getTranscriptPath() | ||
| const { size } = await stat(transcriptPath) | ||
| if (size <= MAX_TRANSCRIPT_READ_BYTES) { | ||
| rawTranscriptJsonl = await readFile(transcriptPath, 'utf-8') | ||
| rawTranscriptJsonl = filterJsonlForExternalEgress( | ||
| await readFile(transcriptPath, 'utf-8'), | ||
| ) | ||
|
Comment on lines
+44
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Look for tests that exercise submitTranscriptShare and the Feedback submit path end to end.
echo "=== tests referencing submitTranscriptShare ==="
rg -nP --type=ts -C3 '\bsubmitTranscriptShare\b' --glob '*.test.ts' --glob '*.test.tsx'
echo "=== tests referencing the feedback report payload ==="
rg -nP -C3 'rawTranscriptJsonl|subagentTranscripts' --glob '*.test.ts' --glob '*.test.tsx'
echo "=== all call sites of the egress filters ==="
rg -nP --type=ts --type=tsx -C2 '\bfilter(Messages|Jsonl)ForExternalEgress\s*\(' src 2>/dev/null || rg -nP -C2 '\bfilter(Messages|Jsonl)ForExternalEgress\s*\(' srcRepository: Gitlawb/openclaude Length of output: 204 🏁 Script executed: #!/bin/bash
set -u
echo "=== locate submitTranscriptShare files ==="
fd -a 'submitTranscriptShare' . || true
echo "=== list test files near FeedbackSurvey ==="
fd -a 'test\.(ts|tsx)$' . | rg -i 'FeedbackSurvey|feedback|survey|submitTranscriptShare|transcript' || true
echo "=== repository-level references to submitTranscriptShare ==="
rg -n -C3 '\bsubmitTranscript_share\b|\bsubmitTranscriptShare\b|\bsubmitReport\b|\brawTranscriptJsonl\b|\bsubagentTranscripts\b' . --glob '!node_modules' --glob '!dist' --glob '!build' || true
echo "=== repository-level references to external egress filters ==="
rg -n -C2 '\bfilterMessagesForExternalEgress\b|\bfilterJsonlForExternalEgress\b' . --glob '!node_modules' --glob '!dist' --glob '!build' || trueRepository: Gitlawb/openclaude Length of output: 23332 Add a regression test for the FeedbackSurvey transcript share payload.
🤖 Prompt for AI AgentsSource: Path instructions |
||
| } else { | ||
| logForDebugging( | ||
| `Skipping raw transcript read: file too large (${size} bytes)`, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.