dsh-multi-device-config-sync 0.0.0-stage → 1.5.0
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/LICENSE +21 -0
- package/README.md +97 -2
- package/assets/icon-256.png +0 -0
- package/client.js +1334 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +19 -0
- package/index.js +52 -0
- package/lib/backup.js +1087 -0
- package/lib/errors.js +67 -0
- package/lib/gist.js +343 -0
- package/lib/plugins.js +469 -0
- package/lib/routes.js +438 -0
- package/lib/store.js +73 -0
- package/lib/sync-install.js +201 -0
- package/lib/tool.js +191 -0
- package/locale/en.json +24 -0
- package/locale/zh.json +24 -0
- package/package.json +66 -4
- package/test/activation.test.mjs +141 -0
- package/test/client-decisions.test.mjs +55 -0
- package/test/client-registration.test.mjs +98 -0
- package/test/config-preview.test.mjs +454 -0
- package/test/first-run.test.mjs +104 -0
- package/test/harness.mjs +176 -0
- package/test/library.test.mjs +169 -0
- package/test/package.test.mjs +162 -0
- package/test/plugins.test.mjs +543 -0
- package/test/rename-compat.test.mjs +255 -0
- package/test/run.mjs +32 -0
- package/test/sync-install.test.mjs +338 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Regression tests for the desktop panel's decisions, not a replacement for visual review.
|
|
2
|
+
* The standalone Client artifact cannot import a sibling module. Expose its pure
|
|
3
|
+
* decision functions only inside this test's VM; no DOM, fake renderer, live
|
|
4
|
+
* profile, or GitHub access is involved. Do not add a test API to the bundle.
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync } from 'node:fs'
|
|
7
|
+
import vm from 'node:vm'
|
|
8
|
+
import assert from 'node:assert/strict'
|
|
9
|
+
import { createReport, TEST_GIST_ID } from './harness.mjs'
|
|
10
|
+
|
|
11
|
+
const { check, finish } = createReport('client decisions')
|
|
12
|
+
const source = readFileSync(new URL('../client.js', import.meta.url), 'utf8')
|
|
13
|
+
const marker = ' function Panel('
|
|
14
|
+
assert.equal(source.split(marker).length, 2, 'identify the boundary before the real panel')
|
|
15
|
+
const pure = 'sourceId, gistLink, filePlan, validCloudPlan, actionable, compatible, verifiedReport, incomplete, sourceKind'
|
|
16
|
+
const sandbox = { window: { __ModuleLoader__: { load(module) {
|
|
17
|
+
assert.equal(module.id, 'dsh-multi-device-config-sync')
|
|
18
|
+
module.factory(name => { assert.equal(name, 'react'); return Object.freeze({}) })
|
|
19
|
+
} } } }
|
|
20
|
+
vm.runInNewContext(source.replace(marker, ` globalThis.subject = { ${pure} }\n${marker}`), sandbox, { timeout: 500, filename: 'client.js' })
|
|
21
|
+
const f = sandbox.subject
|
|
22
|
+
const id = TEST_GIST_ID
|
|
23
|
+
const canonical = `https://gist.github.com/${id}`
|
|
24
|
+
const fixture = (changes = false) => ({
|
|
25
|
+
profile: 'desktop', files: [{ path: 'cordis.patch.yml', status: changes ? 'overwrite' : 'identical' }],
|
|
26
|
+
counts: { overwrite: Number(changes), add: 0, merge: 0, identical: Number(!changes) }, dropped: [], manifest: null,
|
|
27
|
+
})
|
|
28
|
+
const inventory = { available: true, installed: [], missing: [] }
|
|
29
|
+
const missing = { name: 'example-plugin', spec: '1.0.0', installSpec: 'example-plugin@1.0.0', resolvable: true }
|
|
30
|
+
const unavailable = { available: false, reason: 'no-plugin-manager' }
|
|
31
|
+
const unresolved = { name: 'workspace-plugin', spec: 'workspace:*', installSpec: null, resolvable: false }
|
|
32
|
+
const plan = { ref: { id }, planId: 'reviewed-fixture', preview: fixture(), plugins: inventory }
|
|
33
|
+
|
|
34
|
+
check('both ID and canonical Gist link work without an upload', f.sourceId(id) === id && f.sourceId(`https://gist.github.com/sample/${id}`) === id)
|
|
35
|
+
check('other sites, insecure links and credential-bearing URLs are not backup sources',
|
|
36
|
+
[`http://gist.github.com/${id}`, `https://example.invalid/${id}`, `https://user@gist.github.com/${id}`, `${canonical}?extra=private`, `${canonical}#revision`].every(s => f.sourceId(s) == null))
|
|
37
|
+
check('copy uses the confirmed Gist even if the upstream HTML URL is unrelated', f.gistLink({ id, htmlUrl: 'https://example.invalid/unrelated' }) === canonical)
|
|
38
|
+
check('a receipt without a real ID provides no copy target', f.gistLink({ htmlUrl: canonical }) == null)
|
|
39
|
+
check('the npm client keeps the 1.3 Host protocol and accepts both Git and npm releases',
|
|
40
|
+
['1.3.0', '1.4.0', '1.4.1', '1.5.0'].every(version => f.compatible({ version, cloud: {} })))
|
|
41
|
+
check('a pre-1.3 Host or a status without cloud capabilities remains unsupported',
|
|
42
|
+
!f.compatible({ version: '1.2.99', cloud: {} }) && !f.compatible({ version: '1.4.0' }))
|
|
43
|
+
check('a count that hides a file change is rejected before confirmation', !f.filePlan({ ...fixture(true), counts: fixture().counts }))
|
|
44
|
+
check('a Gist reply must match the explicitly selected source', f.validCloudPlan(plan, 'standard', id) && !f.validCloudPlan(plan, 'standard', 'different-id'))
|
|
45
|
+
check('a config-only preview cannot stand in for a combined preview or vice versa', !f.validCloudPlan(plan, 'config', id) && !f.validCloudPlan({ ...plan, plugins: undefined }, 'standard', id) && f.validCloudPlan({ ...plan, plugins: undefined }, 'config', id))
|
|
46
|
+
check('an unreadable plugin inventory cannot supply a confirmable plan', !f.validCloudPlan({ ...plan, plugins: unavailable }, 'standard', id) && f.validCloudPlan({ ...plan, plugins: unavailable, planId: null }, 'standard', id))
|
|
47
|
+
check('identical configuration with no missing plugins has no write action', !f.actionable({ ...plan, mode: 'standard' }) && !f.actionable({ mode: 'config', preview: fixture() }))
|
|
48
|
+
check('a skipped-only package is not counted as an installation', !f.actionable({ ...plan, mode: 'standard', plugins: { ...inventory, missing: [unresolved] } }))
|
|
49
|
+
check('a real file change or an eligible missing package can be confirmed', f.actionable({ ...plan, mode: 'standard', preview: fixture(true) }) && f.actionable({ ...plan, mode: 'standard', plugins: { ...inventory, missing: [missing] } }))
|
|
50
|
+
check('unavailable inventory does not turn file changes into an implicit config-only write', !f.actionable({ ...plan, mode: 'standard', plugins: unavailable, preview: fixture(true) }))
|
|
51
|
+
check('a pinned Git source is not labelled as an npm registry package', f.sourceKind(missing, k => k) === 'npm' && f.sourceKind({ ...missing, installSpec: 'git+https://github.com/example/plugins.git#rev' }, k => k) === 'Git')
|
|
52
|
+
const result = { ...inventory, results: [{ name: missing.name, outcome: 'installed', pendingBuilds: [] }], outcomeCounts: { installed: 1, 'already-present': 0, failed: 0, skipped: 0 } }
|
|
53
|
+
check('complete results are distinguished from missing data and pending builds', f.verifiedReport(result) && !f.incomplete(result) && f.incomplete({}) && f.incomplete({ ...result, results: [{ ...result.results[0], pendingBuilds: ['build-fixture'] }] }))
|
|
54
|
+
check('no prototype copy or dummy destinations were packaged', !/example\.invalid|示例备份|重新体验/.test(source))
|
|
55
|
+
process.exit(finish())
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** Run the exported browser artifact through registration. No DOM, renderer or profile. */
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { readFileSync } from 'node:fs'
|
|
4
|
+
import vm from 'node:vm'
|
|
5
|
+
import { createReport } from './harness.mjs'
|
|
6
|
+
|
|
7
|
+
const { check, finish } = createReport('client registration')
|
|
8
|
+
const root = new URL('../', import.meta.url)
|
|
9
|
+
const manifest = JSON.parse(readFileSync(new URL('package.json', root), 'utf8'))
|
|
10
|
+
const source = readFileSync(new URL(manifest.exports['./client'], root), 'utf8')
|
|
11
|
+
const id = 'dsh-profile-gist-sync-plus' // Stable Settings section and locale, intentionally not the npm name.
|
|
12
|
+
const modules = []
|
|
13
|
+
const imports = new Set()
|
|
14
|
+
const requests = []
|
|
15
|
+
const browser = {
|
|
16
|
+
__ModuleLoader__: { load: descriptor => modules.push(descriptor) },
|
|
17
|
+
fetch(resource) {
|
|
18
|
+
requests.push(String(resource))
|
|
19
|
+
throw new Error('A client registration must not fetch data')
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
browser.window = browser // window.fetch and globalThis.fetch use the same tripwire.
|
|
23
|
+
vm.runInNewContext(source, browser, { filename: 'client.js', timeout: 500 })
|
|
24
|
+
assert.deepEqual(modules.map(module => module.id), [manifest.name], 'one factory under the published package name')
|
|
25
|
+
const plugin = modules[0].factory(name => {
|
|
26
|
+
imports.add(name)
|
|
27
|
+
assert.equal(name, 'react', 'registration must not load another UI package')
|
|
28
|
+
return Object.freeze({}) // An opaque host module; no React API or fake renderer.
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const dictionaries = new Map()
|
|
32
|
+
const entries = []
|
|
33
|
+
const owners = []
|
|
34
|
+
let language = 'en'
|
|
35
|
+
await plugin.apply({
|
|
36
|
+
effect(register) {
|
|
37
|
+
const dispose = register()
|
|
38
|
+
assert.equal(typeof dispose, 'function', 'the host requires an effect disposer')
|
|
39
|
+
return dispose
|
|
40
|
+
},
|
|
41
|
+
locale: {
|
|
42
|
+
register(namespace, dictionary) {
|
|
43
|
+
dictionaries.set(namespace, dictionary)
|
|
44
|
+
return () => dictionaries.delete(namespace)
|
|
45
|
+
},
|
|
46
|
+
bind: namespace => key => dictionaries.get(namespace)?.[language]?.[key] ?? key,
|
|
47
|
+
},
|
|
48
|
+
slots: {
|
|
49
|
+
// Make each requested owner available, including the old tab and optional icon.
|
|
50
|
+
// Capture the registration, not the output of its component.
|
|
51
|
+
inject(name, activate) {
|
|
52
|
+
owners.push(name)
|
|
53
|
+
try { return activate() } finally { owners.pop() }
|
|
54
|
+
},
|
|
55
|
+
register(options, component) {
|
|
56
|
+
entries.push({ owners: [...owners], options, component })
|
|
57
|
+
return () => {}
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
const inSlot = name => entries.filter(entry => entry.options.name === name)
|
|
62
|
+
const sections = inSlot('settings.section')
|
|
63
|
+
assert.deepEqual(sections.map(({ owners, options }) => [owners, options.id, options.order]),
|
|
64
|
+
[[['settings.section'], id, 16]], 'one top-level Plus page, owned by its section slot and ordered just after Built-in plugins (15)')
|
|
65
|
+
const [section] = sections
|
|
66
|
+
check('the sole section provides a component without mounting it', typeof section.component === 'function')
|
|
67
|
+
check('Plus contributes no tab to Built-in plugins', inSlot('settings.plugins.tab').length === 0)
|
|
68
|
+
const icons = inSlot('settings.section.icon')
|
|
69
|
+
assert.equal(icons.length, 1, 'the available navigation-icon slot gets exactly one contribution')
|
|
70
|
+
const [icon] = icons
|
|
71
|
+
assert.deepEqual(icon.owners, ['settings.section.icon'], 'the icon belongs to the separate decoration slot')
|
|
72
|
+
check('the nav icon decorates the same Plus section, not another page',
|
|
73
|
+
icon.options.id === section.options.id && typeof icon.component === 'function', icon.options.id)
|
|
74
|
+
const label = () => typeof section.options.label === 'function' ? section.options.label() : section.options.label
|
|
75
|
+
for (const [lang, title] of [['zh', '多端配置同步'], ['en', 'Multi-device config sync']]) {
|
|
76
|
+
language = lang // Ask the same live registration for its label again; do not re-apply the plugin.
|
|
77
|
+
const actual = label()
|
|
78
|
+
const { meta } = JSON.parse(readFileSync(new URL(`locale/${lang}.json`, root), 'utf8'))
|
|
79
|
+
check(`the ${lang} sidebar and plugin manager show the same localized name`, actual === title && actual === meta.title, actual)
|
|
80
|
+
}
|
|
81
|
+
check('registration and label lookup make no API request', requests.length === 0, requests.join(', '))
|
|
82
|
+
check('registration requests no non-React modules', [...imports].every(name => name === 'react'), [...imports].join(', '))
|
|
83
|
+
|
|
84
|
+
// Check the dictionaries actually supplied to the host, not text between source-code markers.
|
|
85
|
+
const copy = dictionaries.get(id)
|
|
86
|
+
assert.ok(copy?.zh && copy?.en, 'Plus registers both dictionaries under its own namespace')
|
|
87
|
+
const keys = Object.keys(copy.en)
|
|
88
|
+
assert.deepEqual(Object.keys(copy.zh).sort(), keys.sort(), 'both locales cover the same panel copy')
|
|
89
|
+
const translated = key => [copy.en[key], copy.zh[key]].every(value => typeof value === 'string' && value.trim().length > 0)
|
|
90
|
+
check('every literal panel translation has nonempty copy in both languages',
|
|
91
|
+
[...source.matchAll(/\bt\('([^']+)'\)/g)].every(([, key]) => translated(key)))
|
|
92
|
+
check('runtime error and dependency-note lookups have localized copy',
|
|
93
|
+
['err.', 'note.'].every(prefix => keys.some(key => key.startsWith(prefix) && translated(key))))
|
|
94
|
+
check('both locales explain how to recover GitHub access', translated('tokenLabel') && [copy.zh, copy.en].every(dictionary =>
|
|
95
|
+
['DSH_GITHUB_TOKEN', 'gh auth login'].every(hint => dictionary.tokenHelp?.includes(hint))))
|
|
96
|
+
check('both locales label the main actions, copy receipt and distinct review scopes',
|
|
97
|
+
['backup', 'restore', 'ready', 'copy', 'confirmCombined', 'confirmConfig', 'undoLimit'].every(translated))
|
|
98
|
+
process.exit(finish())
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/** Cloud configuration-only plans: the real route handler, no sockets or package manager. */
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { PassThrough, Readable } from 'node:stream'
|
|
6
|
+
import {
|
|
7
|
+
backupDocument, createReport, makeProfile, stubGithub, tempDir, TEST_GIST_ID as ID, TEST_TOKEN, useProfile,
|
|
8
|
+
} from './harness.mjs'
|
|
9
|
+
|
|
10
|
+
const { check, finish } = createReport('configuration-only plans')
|
|
11
|
+
const home = tempDir('dpg-config-preview-')
|
|
12
|
+
useProfile(join(home, 'profiles', 'test'), home)
|
|
13
|
+
process.env.HOME = process.env.USERPROFILE = home
|
|
14
|
+
process.env.PATH = join(home, 'no-executables')
|
|
15
|
+
for (const key of ['DSH_GITHUB_TOKEN', 'GITHUB_TOKEN', 'GH_TOKEN']) delete process.env[key]
|
|
16
|
+
const realFetch = globalThis.fetch
|
|
17
|
+
globalThis.fetch = async () => { throw new Error('unexpected network access from an isolated test') }
|
|
18
|
+
const { BASE_PATH, registerRoutes } = await import('../lib/routes.js')
|
|
19
|
+
const { WORK_DIR } = await import('../lib/backup.js')
|
|
20
|
+
const { readSettings } = await import('../lib/store.js')
|
|
21
|
+
const source = { id: ID, token: TEST_TOKEN }
|
|
22
|
+
const other = 'another-upload-target'
|
|
23
|
+
const npmrc = 'registry=https://reviewed.invalid/\n'
|
|
24
|
+
const workspace = 'packages: []\n# reviewed policy\n'
|
|
25
|
+
const cloudPlugin = 'reviewed-plugin'
|
|
26
|
+
const credential = 'data/auths/credentials.sqlite'
|
|
27
|
+
|
|
28
|
+
// Compare every file, including hidden history, undo state and the dependency tree.
|
|
29
|
+
function tree(dir) {
|
|
30
|
+
return Object.fromEntries(readdirSync(dir, { withFileTypes: true }).map(entry => {
|
|
31
|
+
const path = join(dir, entry.name)
|
|
32
|
+
return [entry.name, entry.isDirectory() ? tree(path) : readFileSync(path, 'latin1')]
|
|
33
|
+
}))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Exercise the same prefix handler and admission/body/lock paths as the browser,
|
|
37
|
+
// but feed the HTTP stream in process. A PassThrough lets a test hold a write open.
|
|
38
|
+
function request(handler, path, body, headers) {
|
|
39
|
+
const req = body instanceof Readable ? body : Readable.from(body === undefined ? [] : [JSON.stringify(body)])
|
|
40
|
+
Object.assign(req, { url: `${BASE_PATH}/api/${path}`, method: body === undefined ? 'GET' : 'POST', headers: { host: 'localhost', ...headers } })
|
|
41
|
+
return new Promise(resolve => {
|
|
42
|
+
let status
|
|
43
|
+
handler(req, { writeHead(code) { status = code }, end(text) { resolve({ status, payload: JSON.parse(text) }) } })
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
async function expect(response, status, code) {
|
|
47
|
+
const result = await response
|
|
48
|
+
assert.equal(result.status, status, JSON.stringify(result.payload).slice(0, 260))
|
|
49
|
+
if (code) assert.equal(result.payload.code, code)
|
|
50
|
+
return result.payload
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let serial = 0
|
|
54
|
+
async function scenario(label, test) {
|
|
55
|
+
const profile = makeProfile(join(home, 'profiles', `case-${++serial}`))
|
|
56
|
+
useProfile(profile, home)
|
|
57
|
+
const document = backupDocument('sender', [
|
|
58
|
+
{ path: '.npmrc', lines: npmrc.split('\n') },
|
|
59
|
+
{ path: 'pnpm-workspace.yaml', lines: workspace.split('\n') },
|
|
60
|
+
{ path: 'helper.cjs', lines: ['// restored as text only', ''] },
|
|
61
|
+
{ path: credential, lines: ['fixture that the validator must omit'] },
|
|
62
|
+
])
|
|
63
|
+
Object.assign(document.files[0].json, {
|
|
64
|
+
dependencies: { [cloudPlugin]: '1.2.3' }, dsh: { profile: { bundles: [cloudPlugin] } }, scripts: { test: 'reviewed-marker' },
|
|
65
|
+
})
|
|
66
|
+
const repo = stubGithub({ gistId: ID, document })
|
|
67
|
+
let handler
|
|
68
|
+
const calls = []
|
|
69
|
+
const services = {
|
|
70
|
+
webServer: { register(route) { handler = route.handler; return () => { handler = null } } },
|
|
71
|
+
connection: { requestRejection: req => req.headers.denied ? 401 : undefined },
|
|
72
|
+
pluginManager: {
|
|
73
|
+
listPlugins() { calls.push('listPlugins'); return [] },
|
|
74
|
+
listBundles() { calls.push('listBundles'); return [{ name: cloudPlugin, availability: 'profile', installed: true }] },
|
|
75
|
+
installBundle() { calls.push('installBundle'); throw new Error('no installations in this fixture') },
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
|
+
const ctx = { get(name) { if (name === 'pluginManager') calls.push('lookup'); return services[name] } }
|
|
79
|
+
let dispose = registerRoutes(ctx)
|
|
80
|
+
const remount = () => { dispose(); dispose = registerRoutes(ctx) }
|
|
81
|
+
const api = (path, body, headers) => request(handler, path, body, headers)
|
|
82
|
+
const preview = (mode = 'config', from = source) => expect(api(`${mode}/preview`, from), 200)
|
|
83
|
+
const confirm = (planId, mode = 'config') => api(mode === 'config' ? 'config/restore' : 'sync/install', { planId, confirm: true })
|
|
84
|
+
try {
|
|
85
|
+
await test({ profile, document, repo, services, calls, remount, api, preview, confirm })
|
|
86
|
+
check(label, true)
|
|
87
|
+
} catch (error) {
|
|
88
|
+
check(label, false, error.stack)
|
|
89
|
+
} finally {
|
|
90
|
+
dispose()
|
|
91
|
+
repo.restore()
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
await scenario('read-only full-scope preview and confirmation use one exact Gist snapshot and no plugin manager', async ({ profile, document, repo, services, calls, preview, confirm }) => {
|
|
96
|
+
services.pluginManager = undefined // still confirmable, unlike the combined flow
|
|
97
|
+
const before = tree(profile)
|
|
98
|
+
const plan = await preview()
|
|
99
|
+
assert.deepEqual(Object.keys(plan).sort(), ['planId', 'preview', 'ref'])
|
|
100
|
+
assert.ok(typeof plan.planId === 'string' && plan.planId)
|
|
101
|
+
assert.equal(plan.ref.id, ID)
|
|
102
|
+
assert.deepEqual(Object.fromEntries(plan.preview.files.map(f => [f.path, f.status])), {
|
|
103
|
+
'package.json': 'merge', '.npmrc': 'overwrite', 'pnpm-workspace.yaml': 'overwrite', 'helper.cjs': 'add',
|
|
104
|
+
})
|
|
105
|
+
assert.deepEqual(plan.preview.manifest.dependenciesAdded, [cloudPlugin])
|
|
106
|
+
assert.deepEqual(plan.preview.dropped, [{ path: credential, code: 'credential' }])
|
|
107
|
+
assert.deepEqual(tree(profile), before)
|
|
108
|
+
|
|
109
|
+
document.files[0].json.dependencies[cloudPlugin] = '9.9.9'
|
|
110
|
+
document.files.find(f => f.path === '.npmrc').lines = ['changed on GitHub after preview']
|
|
111
|
+
const result = await expect(confirm(plan.planId), 200)
|
|
112
|
+
assert.deepEqual(Object.keys(result).sort(), ['ref', 'report', 'restart', 'warnings'])
|
|
113
|
+
assert.deepEqual(result.ref, plan.ref)
|
|
114
|
+
for (const field of ['files', 'counts', 'manifest', 'dropped', 'droppedEntries']) assert.deepEqual(result.report[field], plan.preview[field], field)
|
|
115
|
+
assert.deepEqual(result.warnings, [])
|
|
116
|
+
assert.equal(result.restart, true)
|
|
117
|
+
assert.equal(readFileSync(join(profile, '.npmrc'), 'utf8'), npmrc)
|
|
118
|
+
assert.equal(readFileSync(join(profile, 'pnpm-workspace.yaml'), 'utf8'), workspace)
|
|
119
|
+
assert.equal(readFileSync(join(profile, 'helper.cjs'), 'utf8'), '// restored as text only\n')
|
|
120
|
+
const manifest = JSON.parse(readFileSync(join(profile, 'package.json'), 'utf8'))
|
|
121
|
+
assert.deepEqual(manifest.dependencies, { 'some-plugin': '1.2.3', [cloudPlugin]: '1.2.3' })
|
|
122
|
+
assert.deepEqual(manifest.scripts, { test: 'reviewed-marker' })
|
|
123
|
+
assert.deepEqual(manifest.dsh.profile.bundles, ['@deepseek-ai/dsh-base', cloudPlugin])
|
|
124
|
+
const after = tree(profile)
|
|
125
|
+
assert.deepEqual(after.node_modules, before.node_modules)
|
|
126
|
+
assert.equal(after.data.auths['credentials.sqlite'], before.data.auths['credentials.sqlite'])
|
|
127
|
+
assert.ok(existsSync(join(result.report.undoDir, 'manifest.json')))
|
|
128
|
+
assert.ok(!JSON.stringify([plan, result, after]).includes(TEST_TOKEN))
|
|
129
|
+
await expect(confirm(plan.planId), 409, 'stale-plan')
|
|
130
|
+
assert.deepEqual(tree(profile), after, 'no second restore, undo point or history record')
|
|
131
|
+
assert.deepEqual(calls, [])
|
|
132
|
+
assert.deepEqual(repo.calls.map(({ method, path, headers }) => [method, path, headers.authorization]), [['GET', `/gists/${ID}`, `Bearer ${TEST_TOKEN}`]])
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
await scenario('each mode refuses the other mode’s ID and shows only its own file policy', async ({ profile, repo, calls, preview, confirm }) => {
|
|
136
|
+
const before = tree(profile)
|
|
137
|
+
const full = await preview()
|
|
138
|
+
const combined = await preview('sync')
|
|
139
|
+
assert.ok(combined.planId && combined.planId !== full.planId)
|
|
140
|
+
for (const path of ['.npmrc', 'pnpm-workspace.yaml', 'helper.cjs']) {
|
|
141
|
+
assert.ok(full.preview.files.some(file => file.path === path))
|
|
142
|
+
assert.ok(combined.preview.dropped.some(file => file.path === path && file.code === 'local-policy'))
|
|
143
|
+
assert.ok(!combined.preview.files.some(file => file.path === path))
|
|
144
|
+
}
|
|
145
|
+
const afterPreview = [...calls]
|
|
146
|
+
await expect(confirm(combined.planId), 409, 'stale-plan')
|
|
147
|
+
await expect(confirm(full.planId, 'sync'), 409, 'stale-plan')
|
|
148
|
+
assert.deepEqual(tree(profile), before)
|
|
149
|
+
await expect(confirm(full.planId), 200) // the wrong endpoint did not spend the right plan
|
|
150
|
+
assert.deepEqual(calls, afterPreview)
|
|
151
|
+
assert.equal(repo.calls.length, 2)
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
await scenario('admission, invalid sources and missing explicit consent cannot write or consume a valid plan', async ({ profile, repo, document, api, preview, confirm, calls }) => {
|
|
155
|
+
const before = tree(profile)
|
|
156
|
+
await expect(api('config/preview', source, { denied: 'yes' }), 401, 'auth')
|
|
157
|
+
await expect(api('config/preview', {}), 400, 'no-cloud')
|
|
158
|
+
await expect(api('config/preview', { ...source, id: 'not a gist!' }), 400, 'invalid')
|
|
159
|
+
assert.equal(repo.calls.length, 0, 'admission and ID checks precede downloading')
|
|
160
|
+
const { planId } = await preview()
|
|
161
|
+
await expect(api('config/restore', { planId, confirm: true }, { denied: 'yes' }), 401, 'auth')
|
|
162
|
+
await expect(api('config/restore', { planId, confirm: true }, { 'sec-fetch-site': 'cross-site' }), 403, 'auth')
|
|
163
|
+
for (const value of [undefined, false, 'true']) await expect(api('config/restore', { planId, confirm: value }), 400, 'invalid')
|
|
164
|
+
await expect(confirm('unknown-plan'), 409, 'stale-plan')
|
|
165
|
+
assert.equal(repo.calls.length, 1)
|
|
166
|
+
assert.deepEqual(tree(profile), before)
|
|
167
|
+
await expect(confirm(planId), 200)
|
|
168
|
+
const after = tree(profile)
|
|
169
|
+
document.files = []
|
|
170
|
+
const invalid = await expect(api('config/preview', source), 400, 'invalid')
|
|
171
|
+
assert.equal(invalid.planId, undefined)
|
|
172
|
+
assert.deepEqual(tree(profile), after)
|
|
173
|
+
assert.deepEqual(calls, [])
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
await scenario('a new same-mode preview supersedes the old ID; expiry is enforced at exactly five minutes', async ({ profile, preview, confirm, repo }) => {
|
|
177
|
+
const before = tree(profile)
|
|
178
|
+
const clock = Date.now
|
|
179
|
+
let time = clock()
|
|
180
|
+
Date.now = () => time
|
|
181
|
+
try {
|
|
182
|
+
const old = await preview()
|
|
183
|
+
const fresh = await preview()
|
|
184
|
+
await expect(confirm(old.planId), 409, 'stale-plan')
|
|
185
|
+
time += 5 * 60_000
|
|
186
|
+
await expect(confirm(fresh.planId), 409, 'stale-plan')
|
|
187
|
+
time -= 1
|
|
188
|
+
await expect(confirm(fresh.planId), 409, 'stale-plan') // failed attempt already consumed
|
|
189
|
+
} finally { Date.now = clock }
|
|
190
|
+
assert.deepEqual(tree(profile), before)
|
|
191
|
+
assert.equal(repo.calls.length, 2)
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
for (const path of ['.npmrc', 'helper.cjs']) {
|
|
195
|
+
await scenario(`a changed policy file or newly present target invalidates the reviewed bytes: ${path}`, async ({ profile, preview, confirm, repo, calls }) => {
|
|
196
|
+
const { planId } = await preview()
|
|
197
|
+
const target = join(profile, path)
|
|
198
|
+
const bytes = existsSync(target) ? readFileSync(target, 'utf8') : null
|
|
199
|
+
writeFileSync(target, bytes === null ? 'appeared since preview' : bytes.replace('registry', 'Registry')) // same length for an existing target
|
|
200
|
+
const edited = tree(profile)
|
|
201
|
+
await expect(confirm(planId), 409, 'stale-plan')
|
|
202
|
+
assert.deepEqual(tree(profile), edited)
|
|
203
|
+
if (bytes !== null) writeFileSync(target, bytes)
|
|
204
|
+
await expect(confirm(planId), 409, 'stale-plan')
|
|
205
|
+
assert.deepEqual(calls, [])
|
|
206
|
+
assert.equal(repo.calls.length, 1)
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
await scenario('both confirmations use the existing write lock and release it on failures and success', async ({ profile, api, preview, confirm, calls }) => {
|
|
211
|
+
const { planId } = await preview()
|
|
212
|
+
const before = tree(profile)
|
|
213
|
+
const heldCombined = new PassThrough()
|
|
214
|
+
const first = api('sync/install', heldCombined)
|
|
215
|
+
await expect(confirm(planId), 409, 'busy')
|
|
216
|
+
heldCombined.end('{}')
|
|
217
|
+
await expect(first, 400, 'invalid')
|
|
218
|
+
const heldConfig = new PassThrough()
|
|
219
|
+
const second = api('config/restore', heldConfig)
|
|
220
|
+
await expect(confirm(planId, 'sync'), 409, 'busy')
|
|
221
|
+
await expect(confirm(planId), 409, 'busy')
|
|
222
|
+
await expect(api('undo', {}), 409, 'busy')
|
|
223
|
+
assert.deepEqual(tree(profile), before)
|
|
224
|
+
heldConfig.end(JSON.stringify({ planId, confirm: true }))
|
|
225
|
+
await expect(second, 200)
|
|
226
|
+
await expect(confirm(planId), 409, 'stale-plan')
|
|
227
|
+
await expect(api('undo', {}), 200)
|
|
228
|
+
assert.deepEqual(calls, [])
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
await scenario('unload invalidates all slots and prevents an already admitted, unread confirmation from writing', async ({ profile, remount, api, document, preview, confirm }) => {
|
|
232
|
+
const before = tree(profile)
|
|
233
|
+
const full = await preview()
|
|
234
|
+
const combined = await preview('sync')
|
|
235
|
+
const local = await expect(api('preview', { reviewed: true, backup: document }), 200)
|
|
236
|
+
const body = new PassThrough()
|
|
237
|
+
const inFlight = api('config/restore', body)
|
|
238
|
+
remount()
|
|
239
|
+
body.end(JSON.stringify({ planId: full.planId, confirm: true }))
|
|
240
|
+
await expect(inFlight, 409, 'stale-plan')
|
|
241
|
+
await expect(confirm(full.planId), 409, 'stale-plan')
|
|
242
|
+
await expect(confirm(combined.planId, 'sync'), 409, 'stale-plan')
|
|
243
|
+
await expect(api('restore', { planId: local.planId, confirm: true }), 409, 'stale-plan')
|
|
244
|
+
assert.deepEqual(tree(profile), before)
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
await scenario('a failed restore cannot update history, run the installer or reuse its ID', async ({ profile, calls, repo, preview, confirm }) => {
|
|
248
|
+
const { planId } = await preview()
|
|
249
|
+
writeFileSync(join(profile, WORK_DIR), 'fixture: cannot make an undo directory here')
|
|
250
|
+
const blocked = tree(profile)
|
|
251
|
+
await expect(confirm(planId), 500, 'other')
|
|
252
|
+
await expect(confirm(planId), 409, 'stale-plan')
|
|
253
|
+
assert.deepEqual(tree(profile), blocked)
|
|
254
|
+
assert.deepEqual(calls, [])
|
|
255
|
+
assert.equal(repo.calls.length, 1)
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
await scenario('failed history persistence returns a warning and a usable undo point, not a false restore failure', async ({ profile, api, preview, confirm, calls }) => {
|
|
259
|
+
mkdirSync(join(profile, WORK_DIR, 'settings.json'), { recursive: true }) // the history rename must fail
|
|
260
|
+
const oldPolicy = readFileSync(join(profile, '.npmrc'), 'utf8')
|
|
261
|
+
const { planId } = await preview()
|
|
262
|
+
const result = await expect(confirm(planId), 200)
|
|
263
|
+
assert.ok(result.warnings.some(w => /configuration restored.*history could not be saved/i.test(w)))
|
|
264
|
+
assert.equal(result.restart, true)
|
|
265
|
+
assert.equal(readFileSync(join(profile, '.npmrc'), 'utf8'), npmrc)
|
|
266
|
+
assert.ok(existsSync(join(result.report.undoDir, 'manifest.json')))
|
|
267
|
+
await expect(confirm(planId), 409, 'stale-plan')
|
|
268
|
+
await expect(api('undo', {}), 200)
|
|
269
|
+
assert.equal(readFileSync(join(profile, '.npmrc'), 'utf8'), oldPolicy)
|
|
270
|
+
assert.deepEqual(calls, [])
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
for (const mode of ['config', 'sync']) {
|
|
274
|
+
for (const bound of [null, other]) {
|
|
275
|
+
await scenario(`${mode} confirmation records the reviewed Gist but keeps the ${bound ? 'different' : 'unset'} upload target`, async ({ api, preview, confirm, calls }) => {
|
|
276
|
+
if (bound) await expect(api('settings', { gistId: bound }), 200)
|
|
277
|
+
const plan = await preview(mode)
|
|
278
|
+
await expect(confirm(plan.planId, mode), 200)
|
|
279
|
+
const { gistId, lastSync, lastUpload } = readSettings()
|
|
280
|
+
assert.equal(gistId, bound)
|
|
281
|
+
assert.equal(lastSync.gistId, ID)
|
|
282
|
+
assert.equal(lastSync.remoteUpdatedAt, plan.ref.updatedAt)
|
|
283
|
+
assert.equal(lastUpload, null)
|
|
284
|
+
assert.ok(!calls.includes('installBundle'))
|
|
285
|
+
})
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
await scenario('the remembered Gist and host token can preview; an identical restore needs no restart', async ({ api, preview, confirm, repo }) => {
|
|
290
|
+
await expect(api('settings', { gistId: ID }), 200)
|
|
291
|
+
await expect(confirm((await preview()).planId), 200)
|
|
292
|
+
process.env.DSH_GITHUB_TOKEN = TEST_TOKEN
|
|
293
|
+
let plan
|
|
294
|
+
try { plan = await preview('config', {}) } finally { delete process.env.DSH_GITHUB_TOKEN }
|
|
295
|
+
assert.equal(plan.preview.counts.identical, plan.preview.files.length)
|
|
296
|
+
assert.equal((await expect(confirm(plan.planId), 200)).restart, false)
|
|
297
|
+
assert.deepEqual(repo.calls.map(call => call.path), [`/gists/${ID}`, `/gists/${ID}`])
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
await scenario('a changed upload target cannot silently turn a reviewed create or update into a different GitHub write', async ({ profile, api, repo }) => {
|
|
301
|
+
await expect(api('settings', { gistId: other }), 200) // another session changed the destination
|
|
302
|
+
const before = tree(profile)
|
|
303
|
+
for (const expectedTarget of [null, ID]) {
|
|
304
|
+
await expect(api('gist/upload', { token: TEST_TOKEN, expectedTarget }), 409, 'stale-plan')
|
|
305
|
+
}
|
|
306
|
+
assert.deepEqual(repo.calls, [])
|
|
307
|
+
assert.deepEqual(tree(profile), before)
|
|
308
|
+
await expect(api('settings', { gistId: '' }), 200)
|
|
309
|
+
await expect(api('gist/upload', { token: TEST_TOKEN, expectedTarget: null }), 200)
|
|
310
|
+
await expect(api('gist/upload', { token: TEST_TOKEN, expectedTarget: ID }), 200)
|
|
311
|
+
assert.deepEqual(repo.calls.map(({ method, path }) => [method, path]), [['POST', '/gists'], ['PATCH', `/gists/${ID}`]])
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
await scenario('upload receipts name their own Gist and the legacy sync keeps its original binding and response', async ({ api }) => {
|
|
315
|
+
const version = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version
|
|
316
|
+
assert.equal((await expect(api('status'), 200)).version, version)
|
|
317
|
+
await expect(api('gist/upload', { token: TEST_TOKEN }), 200)
|
|
318
|
+
await expect(api('settings', { gistId: other }), 200)
|
|
319
|
+
assert.equal(readSettings().lastUpload.gistId, ID)
|
|
320
|
+
assert.equal(readSettings().gistId, other)
|
|
321
|
+
const legacy = await expect(api('sync', source), 200)
|
|
322
|
+
assert.deepEqual(Object.keys(legacy).sort(), ['ref', 'report', 'tokenSource', 'undoDir'])
|
|
323
|
+
assert.equal(readSettings().gistId, ID)
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
const installablePairs = inventory => inventory.missing.filter(row => row.resolvable).map(({ name, installSpec }) => ({ name, installSpec }))
|
|
327
|
+
|
|
328
|
+
await scenario('independent installation validates the reviewed pairs and rejects changed or unavailable inventories without installing', async ({ api, profile, services, calls }) => {
|
|
329
|
+
const pairs = installablePairs(await expect(api('plugins'), 200))
|
|
330
|
+
assert.deepEqual(pairs, [{ name: 'some-plugin', installSpec: 'some-plugin@1.2.3' }])
|
|
331
|
+
const install = expectedPackages => api('plugins/install', { expectedPackages })
|
|
332
|
+
const before = tree(profile)
|
|
333
|
+
for (const invalid of [null, {}, [null], [{ name: 'some-plugin', installSpec: '' }], [...pairs, ...pairs]]) {
|
|
334
|
+
await expect(install(invalid), 400, 'invalid')
|
|
335
|
+
}
|
|
336
|
+
for (const changed of [[], [{ name: 'unreviewed', installSpec: 'unreviewed@1' }], [{ ...pairs[0], installSpec: 'some-plugin@2' }]]) {
|
|
337
|
+
await expect(install(changed), 409, 'stale-plan')
|
|
338
|
+
}
|
|
339
|
+
services.pluginManager = undefined
|
|
340
|
+
await expect(install(pairs), 409, 'stale-plan')
|
|
341
|
+
assert.deepEqual(tree(profile), before)
|
|
342
|
+
assert.ok(!calls.includes('installBundle'))
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
await scenario('matching local packages use actual specs and no build grants; old callers still work', async ({ api, services }) => {
|
|
346
|
+
const pairs = installablePairs(await expect(api('plugins'), 200))
|
|
347
|
+
const installs = []
|
|
348
|
+
services.pluginManager.installBundle = (spec, options) => { installs.push([spec, options]); return { application: 'applied' } }
|
|
349
|
+
for (const body of [{ expectedPackages: pairs, approvedBuilds: ['not-approved'] }, {}]) {
|
|
350
|
+
const report = await expect(api('plugins/install', body), 200)
|
|
351
|
+
assert.equal(report.outcomeCounts.installed, 1)
|
|
352
|
+
}
|
|
353
|
+
assert.deepEqual(installs, [['some-plugin@1.2.3', undefined], ['some-plugin@1.2.3', undefined]])
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
await scenario('a source change or new dependency between comparison and installer recheck cannot expand consent', async ({ api, profile, services, calls }) => {
|
|
357
|
+
const pairs = installablePairs(await expect(api('plugins'), 200))
|
|
358
|
+
let changed = false
|
|
359
|
+
services.pluginManager.listPlugins = () => {
|
|
360
|
+
if (!changed) {
|
|
361
|
+
changed = true // initial inventory already read the original declarations; the installer will see the new ones
|
|
362
|
+
const file = join(profile, 'package.json')
|
|
363
|
+
const manifest = JSON.parse(readFileSync(file, 'utf8'))
|
|
364
|
+
manifest.dependencies = { 'some-plugin': '2.0.0', 'new-gap': '1.0.0' }
|
|
365
|
+
writeFileSync(file, JSON.stringify(manifest))
|
|
366
|
+
}
|
|
367
|
+
return []
|
|
368
|
+
}
|
|
369
|
+
const report = await expect(api('plugins/install', { expectedPackages: pairs }), 200)
|
|
370
|
+
for (const name of ['some-plugin', 'new-gap']) assert.ok(report.results.some(row => row.name === name && row.outcome === 'skipped'))
|
|
371
|
+
assert.ok(!calls.includes('installBundle'))
|
|
372
|
+
await expect(api('plugins/install', { expectedPackages: pairs }), 409, 'stale-plan')
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
await scenario('undo cannot target a replacement snapshot; only the reviewed latest stamp is reverted', async ({ api, profile, preview, confirm }) => {
|
|
376
|
+
const undo = expectedStamp => api('undo', { expectedStamp })
|
|
377
|
+
await expect(undo('a-previous-snapshot'), 409, 'stale-plan')
|
|
378
|
+
await expect(confirm((await preview()).planId), 200)
|
|
379
|
+
const first = (await expect(api('status'), 200)).undo.stamp
|
|
380
|
+
await expect(undo(null), 400, 'invalid')
|
|
381
|
+
assert.equal((await expect(undo(first), 200)).report.stamp, first)
|
|
382
|
+
await expect(confirm((await preview()).planId), 200)
|
|
383
|
+
const latest = (await expect(api('status'), 200)).undo.stamp
|
|
384
|
+
assert.notEqual(first, latest)
|
|
385
|
+
const before = tree(profile)
|
|
386
|
+
await expect(undo(first), 409, 'stale-plan')
|
|
387
|
+
assert.deepEqual(tree(profile), before)
|
|
388
|
+
assert.equal((await expect(undo(latest), 200)).report.stamp, latest)
|
|
389
|
+
await expect(undo(latest), 409, 'stale-plan')
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
await scenario('a reviewed local import applies its validated snapshot once without reading GitHub or changing any Gist binding/history', async ({ api, profile, document, repo, calls }) => {
|
|
393
|
+
const before = tree(profile)
|
|
394
|
+
const plan = await expect(api('preview', { reviewed: true, backup: document }), 200)
|
|
395
|
+
assert.deepEqual(Object.keys(plan).sort(), ['planId', 'preview'])
|
|
396
|
+
assert.equal(typeof plan.planId, 'string')
|
|
397
|
+
assert.deepEqual(plan.preview.dropped, [{ path: credential, code: 'credential' }])
|
|
398
|
+
assert.deepEqual(tree(profile), before)
|
|
399
|
+
const planId = plan.planId
|
|
400
|
+
document.files.find(f => f.path === '.npmrc').lines = ['different file supplied after review']
|
|
401
|
+
await expect(api('restore', { planId }), 400, 'invalid')
|
|
402
|
+
await expect(api('restore', { planId, confirm: true, backup: document }), 400, 'invalid')
|
|
403
|
+
assert.deepEqual(tree(profile), before)
|
|
404
|
+
const saved = await expect(api('restore', { planId, confirm: true }), 200)
|
|
405
|
+
assert.deepEqual(Object.keys(saved), ['report'])
|
|
406
|
+
assert.deepEqual(saved.report.files, plan.preview.files)
|
|
407
|
+
assert.deepEqual(saved.report.dropped, plan.preview.dropped)
|
|
408
|
+
assert.equal(readFileSync(join(profile, '.npmrc'), 'utf8'), npmrc)
|
|
409
|
+
assert.equal(existsSync(join(profile, WORK_DIR, 'settings.json')), false)
|
|
410
|
+
assert.deepEqual(repo.calls, [])
|
|
411
|
+
assert.deepEqual(calls, [])
|
|
412
|
+
await expect(api('restore', { planId, confirm: true }), 409, 'stale-plan')
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
await scenario('local, cloud-config and combined IDs are not interchangeable; the original non-reviewed local API remains usable', async ({ api, profile, document, preview, confirm, repo }) => {
|
|
416
|
+
const before = tree(profile)
|
|
417
|
+
const local = await expect(api('preview', { backup: document, reviewed: true }), 200)
|
|
418
|
+
const full = await preview()
|
|
419
|
+
const combined = await preview('sync')
|
|
420
|
+
for (const id of [full.planId, combined.planId, null]) await expect(api('restore', { planId: id, confirm: true }), 409, 'stale-plan')
|
|
421
|
+
for (const mode of ['config', 'sync']) await expect(confirm(local.planId, mode), 409, 'stale-plan')
|
|
422
|
+
assert.deepEqual(tree(profile), before)
|
|
423
|
+
await expect(api('restore', { planId: local.planId, confirm: true }), 200)
|
|
424
|
+
const legacy = await expect(api('preview', { backup: document }), 200)
|
|
425
|
+
assert.deepEqual(Object.keys(legacy), ['preview'])
|
|
426
|
+
assert.deepEqual(Object.keys(await expect(api('restore', { backup: document, confirm: true }), 200)), ['report'])
|
|
427
|
+
assert.equal(repo.calls.length, 2, 'only the cloud previews contacted the stub')
|
|
428
|
+
})
|
|
429
|
+
|
|
430
|
+
await scenario('local consent expires and detects edits to files the review called identical', async ({ api, profile, document, repo, calls }) => {
|
|
431
|
+
const file = join(profile, 'data/note.json')
|
|
432
|
+
const initial = readFileSync(file, 'utf8')
|
|
433
|
+
document.files.push({ path: 'data/note.json', lines: initial.split('\n') })
|
|
434
|
+
const review = () => expect(api('preview', { backup: document, reviewed: true }), 200)
|
|
435
|
+
const restore = planId => api('restore', { planId, confirm: true })
|
|
436
|
+
const plan = await review()
|
|
437
|
+
assert.equal(plan.preview.files.find(f => f.path === 'data/note.json').status, 'identical')
|
|
438
|
+
writeFileSync(file, initial.replace('world', 'earth'))
|
|
439
|
+
const edited = tree(profile)
|
|
440
|
+
await expect(restore(plan.planId), 409, 'stale-plan')
|
|
441
|
+
const fresh = await review()
|
|
442
|
+
const now = Date.now
|
|
443
|
+
try {
|
|
444
|
+
const later = now() + 5 * 60_000
|
|
445
|
+
Date.now = () => later
|
|
446
|
+
await expect(restore(fresh.planId), 409, 'stale-plan')
|
|
447
|
+
} finally { Date.now = now }
|
|
448
|
+
assert.deepEqual(tree(profile), edited)
|
|
449
|
+
assert.deepEqual(repo.calls, [])
|
|
450
|
+
assert.deepEqual(calls, [])
|
|
451
|
+
})
|
|
452
|
+
|
|
453
|
+
globalThis.fetch = realFetch
|
|
454
|
+
process.exitCode = finish()
|