Skip to content

Commit f79769f

Browse files
GiniGini
authored andcommitted
Validate imported attachment bytes
1 parent 5b2e06c commit f79769f

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎scripts/postgres-import-e2e.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ const main = async () => {
3636
const projectFile = projectWithFile.files[0]!
3737
const before = await source.readProjectFile(project.id, projectFile.path)
3838
await source.updateProjectFile(project.id, projectFile.path, 'Imported project context v2.', before.contentHash)
39-
const task = await source.createTask('Import durable bytes', 'demo', 'document', project.id, undefined, [], [], [], ownerUserId)
39+
const attachment = { name: 'private.txt', path: 'inputs/01-private.txt', size: Buffer.byteLength('private input'), mimeType: 'text/plain' }
40+
const task = await source.createTask('Import durable bytes', 'demo', 'document', project.id, undefined, [], [attachment], [], ownerUserId)
4041
await source.writeWorkspaceFile(task.id, 'README.md', '# Imported workspace\n')
4142
await source.writeWorkspaceBytes(task.id, 'data.bin', Buffer.from([0, 1, 2, 255]))
4243
const version = await source.createWorkspaceVersion(task.id, 'Import snapshot')
4344
assert.ok(version)
44-
await source.writeWorkspaceFile(task.id, 'inputs/private.txt', 'private input')
45+
await source.writeWorkspaceFile(task.id, attachment.path, 'private input')
4546
await source.beginTurn(task.id, 'Import native trace', 'demo')
4647
await source.ingestNativeEvent(task.id, {
4748
source: 'claude_agent_sdk', sourceEventId: 'sdk-import-0', sourceSequence: 0, nativeType: 'tool_use',
@@ -60,7 +61,7 @@ const main = async () => {
6061
assert.equal(await imported.readWorkspaceFile(task.id, 'README.md'), '# Imported workspace\n')
6162
assert.deepEqual([...await imported.readWorkspaceBytes(task.id, 'data.bin')], [0, 1, 2, 255])
6263
assert.equal((await imported.listWorkspaceVersions(task.id)).length, 1)
63-
assert.equal(await imported.readWorkspaceFile(task.id, 'inputs/private.txt'), 'private input')
64+
assert.equal(await imported.readWorkspaceFile(task.id, attachment.path), 'private input')
6465
assert.equal((await imported.readProjectFile(project.id, projectFile.path, ownerUserId)).content, 'Imported project context v2.')
6566
assert.equal(imported.listProjectFileVersions(project.id, projectFile.path, ownerUserId).length, 1)
6667
assert.equal((await imported.listNativeEvents(task.id)).length, 1)

‎scripts/postgres-import.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ const run = async () => {
5555
counts.events += store.listEvents(task.id).length
5656
counts.nativeEvents += (await store.listNativeEvents(task.id)).length
5757
counts.versions += (await store.listWorkspaceVersions(task.id)).length
58+
const workspaceFiles = new Map((await store.listWorkspaceFiles(task.id)).map((file) => [file.path, file]))
59+
for (const attachment of task.attachments) {
60+
const file = workspaceFiles.get(attachment.path)
61+
if (!file) throw new Error(`Task ${task.id} attachment ${attachment.path} is missing from the legacy workspace`)
62+
if (file.size !== attachment.size) throw new Error(`Task ${task.id} attachment ${attachment.path} size metadata does not match workspace bytes`)
63+
}
5864
}
5965
if (options.dryRun) {
6066
console.log(JSON.stringify({ dryRun: true, dataRoot: options.dataRoot, owners: [...owners], counts }, null, 2))

0 commit comments

Comments
 (0)