dsh-compact-pi 0.2.3-b3 → 0.2.3-b5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +7 -5
- package/bin/dcp-session.ts +25 -18
- package/dist/codec.mjs +45 -9
- package/dist/dcp-session.mjs +1069 -605
- package/dist/index.js +9 -3
- package/docs/compatibility.md +1 -1
- package/docs/help.md +14 -4
- package/docs/publishing.md +4 -4
- package/docs/testing.md +17 -0
- package/package.json +2 -2
- package/scripts/test-correction-scope.ts +187 -0
- package/skills/dcp-migrate-to-dsh/SKILL.md +15 -8
- package/skills/dcp-migrate-to-dsh/references/commands.md +33 -0
- package/src/codec.ts +40 -6
- package/src/dsh/convert.ts +11 -5
- package/src/dsh/import.ts +53 -24
- package/src/dsh/migration-cli.ts +137 -0
- package/src/dsh/migration-web.ts +44 -0
- package/src/dsh/migration.ts +216 -0
- package/src/dsh/sync.ts +9 -1
- package/test/convert.test.ts +37 -0
- package/test/migration.test.ts +72 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { promises as fs } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { test } from 'node:test'
|
|
6
|
+
import { applyMigration, findPiSources, planMigration, type MigrationOptions } from '../src/dsh/migration.ts'
|
|
7
|
+
import { readDshFile } from '../src/dsh/store.ts'
|
|
8
|
+
|
|
9
|
+
test('plan and apply require explicit paths and preserve conflicts and source changes', async () => {
|
|
10
|
+
const temp = await fs.mkdtemp(path.join(tmpdir(), 'dcp-migration-test-'))
|
|
11
|
+
try {
|
|
12
|
+
const project = path.join(temp, 'Project 中文')
|
|
13
|
+
const piHome = path.join(temp, 'pi')
|
|
14
|
+
const source = path.join(piHome, 'sessions', 'project', 'session.jsonl')
|
|
15
|
+
const dshHome = path.join(temp, 'dsh')
|
|
16
|
+
for (const dir of [project, path.dirname(source), dshHome]) await fs.mkdir(dir, { recursive: true })
|
|
17
|
+
const timestamp = new Date().toISOString()
|
|
18
|
+
const header = { type: 'session', version: 3, id: 'source-id', cwd: project, timestamp }
|
|
19
|
+
const user = {
|
|
20
|
+
type: 'message', id: 'u', parentId: null, timestamp,
|
|
21
|
+
message: { role: 'user', content: 'Migration fixture' },
|
|
22
|
+
}
|
|
23
|
+
const rows = [header, user].map(JSON.stringify).join('\n') + '\n'
|
|
24
|
+
await fs.writeFile(source, rows)
|
|
25
|
+
const listed = await findPiSources({ piHome, id: header.id })
|
|
26
|
+
assert.deepEqual(listed.map(entry => entry.path), [source])
|
|
27
|
+
const sessionRoot = path.join(dshHome, 'sessions')
|
|
28
|
+
const options: MigrationOptions = {
|
|
29
|
+
source, workspace: project, dshHome, sessionRoot,
|
|
30
|
+
target: process.platform === 'win32' ? 'windows-desktop'
|
|
31
|
+
: process.platform === 'linux' ? 'linux-desktop' : 'web',
|
|
32
|
+
profile: 'desktop', dshVersion: '0.2.3-alpha.2', encoding: 'plain',
|
|
33
|
+
}
|
|
34
|
+
await assert.rejects(planMigration({ ...options, profile: undefined }), /profile/)
|
|
35
|
+
const first = await planMigration(options)
|
|
36
|
+
await assert.rejects(fs.stat(sessionRoot), { code: 'ENOENT' })
|
|
37
|
+
await assert.rejects(applyMigration(first, 'wrong'), /confirmation code/)
|
|
38
|
+
await fs.appendFile(source, '\n')
|
|
39
|
+
await assert.rejects(applyMigration(first, first.confirmation), /changed/)
|
|
40
|
+
await assert.rejects(fs.stat(sessionRoot), { code: 'ENOENT' })
|
|
41
|
+
const approved = await planMigration(options)
|
|
42
|
+
const receipt = await applyMigration(approved, approved.confirmation)
|
|
43
|
+
assert.equal(receipt.status, 'written')
|
|
44
|
+
const original = await fs.readFile(receipt.output)
|
|
45
|
+
await assert.rejects(planMigration(options), /already exists/)
|
|
46
|
+
await assert.rejects(planMigration({ ...options, encoding: 'zstd' }), /different encoding/)
|
|
47
|
+
const duplicate = await planMigration({ ...options, onConflict: 'copy' })
|
|
48
|
+
assert.notEqual(duplicate.sessionId, first.sessionId)
|
|
49
|
+
const second = await applyMigration(duplicate, duplicate.confirmation)
|
|
50
|
+
assert.deepEqual(await fs.readFile(receipt.output), original)
|
|
51
|
+
assert.equal((await readDshFile(second.output))?.header.id, duplicate.sessionId)
|
|
52
|
+
|
|
53
|
+
const hybrid = path.join(temp, 'mixed.jsonl')
|
|
54
|
+
const hybridRows = [
|
|
55
|
+
{ ...header, version: 4, timestamp: undefined, createdAt: Date.parse(timestamp) },
|
|
56
|
+
{ type: 'turn/start', seq: 0, data: { turn: 1 } },
|
|
57
|
+
{ type: 'model_change', id: 'model', timestamp, modelId: 'fixture-model', provider: 'fixture' },
|
|
58
|
+
{ ...user, parentId: 'model' },
|
|
59
|
+
].map(JSON.stringify).join('\n') + '\n'
|
|
60
|
+
await fs.writeFile(hybrid, hybridRows)
|
|
61
|
+
const portable = { source: hybrid, target: 'portable', exportDir: temp } as const
|
|
62
|
+
await assert.rejects(planMigration(portable), /explicitly approve/)
|
|
63
|
+
const recover = await planMigration({ ...portable, recoverPiEntries: true })
|
|
64
|
+
assert.equal(recover.mirrorRows, 1)
|
|
65
|
+
const exported = await applyMigration(recover, recover.confirmation)
|
|
66
|
+
assert.equal(exported.status, 'exported')
|
|
67
|
+
assert.equal(exported.attachmentHome, path.dirname(exported.output))
|
|
68
|
+
assert.equal(await fs.readFile(hybrid, 'utf8'), hybridRows)
|
|
69
|
+
} finally {
|
|
70
|
+
await fs.rm(temp, { recursive: true, force: true, maxRetries: 5 })
|
|
71
|
+
}
|
|
72
|
+
})
|