dsh-plugin-update-doctor 0.5.0 → 0.5.3
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/README.md +91 -12
- package/client.js +328 -32
- package/docs/DETAIL.md +65 -22
- package/docs/PUBLICATION.md +29 -3
- package/docs/RELEASE_NOTES_0_5_1.md +80 -0
- package/docs/RELEASE_REVIEW_0_5_1.md +54 -0
- package/docs/SELF_UPDATE.md +5 -1
- package/docs/UNION_GENERATION_0_5_2.md +32 -0
- package/docs/V0_3_DESIGN.md +2 -0
- package/docs/VERIFICATION.md +81 -4
- package/docs/WINDOWS_REQUIREMENTS.md +48 -0
- package/docs/WINDOWS_SUPPORT.md +78 -0
- package/docs/WSL_STRUCTURAL_0_5_3.md +30 -0
- package/index.js +15 -2
- package/lib/dependency-policy.js +89 -0
- package/lib/history.js +2 -2
- package/lib/http.js +5 -1
- package/lib/identity.js +22 -3
- package/lib/online.js +44 -18
- package/lib/self-update-policy.js +60 -26
- package/lib/self-update-store.js +21 -9
- package/lib/self-update.js +80 -29
- package/lib/service.js +437 -58
- package/lib/source.js +29 -0
- package/lib/staging.js +128 -30
- package/lib/union-generation.js +376 -0
- package/lib/union-service.js +83 -0
- package/lib/union-staging.js +325 -0
- package/lib/wsl-outcome.js +15 -0
- package/lib/wsl-policy.js +71 -5
- package/lib/wsl-proof.js +85 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +10 -50
package/lib/self-update-store.js
CHANGED
|
@@ -2,8 +2,9 @@ import { open, mkdir, lstat, realpath, opendir, link, unlink, rmdir } from 'node
|
|
|
2
2
|
import { resolve, join, dirname, basename, parse, sep } from 'node:path';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
import { boundedFile } from './file-read.js';
|
|
5
|
-
import { PUBLIC_REGISTRY, registryOrigin } from './source.js';
|
|
5
|
+
import { PUBLIC_REGISTRY, PUBLIC_MIRROR, approvedPublicRegistry, registryOrigin } from './source.js';
|
|
6
6
|
import { parseSelfGithubSource, SELF_UPDATE_GITHUB_REPOSITORY } from './self-update-github.js';
|
|
7
|
+
import { verifySelfRegistryPlan } from './self-update-policy.js';
|
|
7
8
|
|
|
8
9
|
const SELF = 'dsh-plugin-update-doctor';
|
|
9
10
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
@@ -12,7 +13,7 @@ const SHA = /^[a-f0-9]{64}$/;
|
|
|
12
13
|
const APPLICATION = new Set(['applied', 'failed', 'cancelled', 'restart-required', 'overridden']);
|
|
13
14
|
const STAGES = new Set(['install', 'enable', 'remove']);
|
|
14
15
|
const RESTART = new Set(['no-hmr', 'package-moved', 'host-module', 'unmanaged-plugin', 'module-comparison']);
|
|
15
|
-
const ATTEMPT_KEYS = new Set(['schemaVersion', 'id', 'name', 'from', 'to', 'registry', 'sourceKind', 'repository', 'fromCommit', 'toCommit', 'pid', 'startedAt', 'taskPolicy', 'confirmCancel', 'previousSha256', 'nextSha256', 'previousFiles', 'nextFiles']);
|
|
16
|
+
const ATTEMPT_KEYS = new Set(['schemaVersion', 'id', 'name', 'from', 'to', 'registry', 'sourceKind', 'sourceMode', 'publicMirror', 'confirmPublicMirror', 'hostRegistryPlan', 'repository', 'fromCommit', 'toCommit', 'pid', 'startedAt', 'taskPolicy', 'confirmCancel', 'previousSha256', 'nextSha256', 'previousFiles', 'nextFiles']);
|
|
16
17
|
const RESULT_KEYS = new Set(['schemaVersion', 'id', 'finishedAt', 'official', 'outcome', 'error', 'truncated']);
|
|
17
18
|
const HANDOFF_KEYS = new Set(['schemaVersion', 'id', 'handedOffAt']);
|
|
18
19
|
const object = value => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -34,28 +35,39 @@ export class SelfUpdateStore {
|
|
|
34
35
|
if (!object(value)) fail('self-update-attempt-invalid');
|
|
35
36
|
if (reading) {
|
|
36
37
|
exactKeys(value, ATTEMPT_KEYS);
|
|
37
|
-
if (value.schemaVersion
|
|
38
|
+
if (![1,2].includes(value.schemaVersion) || value.name !== SELF || ['id', 'from', 'to', 'pid', 'startedAt', 'taskPolicy', 'confirmCancel'].some(key => !Object.hasOwn(value, key))) fail('self-update-record-format');
|
|
38
39
|
if (!Number.isSafeInteger(value.pid) || value.pid < 1 || typeof value.confirmCancel !== 'boolean' || !['wait-for-idle', 'cancel-active'].includes(value.taskPolicy)) fail('self-update-record-format');
|
|
39
40
|
timestamp(value.startedAt);
|
|
40
41
|
}
|
|
41
42
|
const id = identifier(value.id ?? randomUUID());
|
|
42
43
|
if (!VERSION.test(value.from ?? '') || !VERSION.test(value.to ?? '') || value.from === value.to) fail('self-update-attempt-target');
|
|
43
|
-
const git = value.sourceKind === 'git';
|
|
44
|
+
const git = value.sourceKind === 'git', publicMirror = registryOrigin(value.registry) === PUBLIC_MIRROR;
|
|
44
45
|
let source;
|
|
45
46
|
if (git) {
|
|
46
|
-
if (value.registry !== undefined || value.repository !== SELF_UPDATE_GITHUB_REPOSITORY || value.fromCommit === value.toCommit) fail('self-update-attempt-target');
|
|
47
|
+
if (value.registry !== undefined || ['sourceMode','publicMirror','confirmPublicMirror','hostRegistryPlan'].some(key=>value[key]!==undefined) || value.repository !== SELF_UPDATE_GITHUB_REPOSITORY || value.fromCommit === value.toCommit) fail('self-update-attempt-target');
|
|
47
48
|
const previous = parseSelfGithubSource('github:' + value.repository + '#' + value.fromCommit), next = parseSelfGithubSource('github:' + value.repository + '#' + value.toCommit);
|
|
48
49
|
source = { sourceKind: 'git', repository: SELF_UPDATE_GITHUB_REPOSITORY, fromCommit: previous.commit, toCommit: next.commit };
|
|
49
50
|
} else {
|
|
50
|
-
if (value.sourceKind !== undefined && value.sourceKind !== 'registry' ||
|
|
51
|
+
if (value.sourceKind !== undefined && value.sourceKind !== 'registry' || !approvedPublicRegistry(value.registry)
|
|
51
52
|
|| ['repository', 'fromCommit', 'toCommit'].some(key => value[key] !== undefined)) fail('self-update-attempt-target');
|
|
52
|
-
|
|
53
|
+
if (publicMirror) {
|
|
54
|
+
if (value.sourceMode !== 'public-mirror' || value.publicMirror !== true || value.confirmPublicMirror !== true
|
|
55
|
+
|| reading && value.schemaVersion !== 2) fail('self-update-attempt-target');
|
|
56
|
+
exactKeys(value.hostRegistryPlan,new Set(['queryRegistry','registry','resolved','fallbackRegistries']));
|
|
57
|
+
const plan=verifySelfRegistryPlan(value.hostRegistryPlan,PUBLIC_MIRROR);
|
|
58
|
+
if(value.hostRegistryPlan.queryRegistry!==PUBLIC_MIRROR)fail('self-update-attempt-target');
|
|
59
|
+
source = { registry: PUBLIC_MIRROR, sourceMode:'public-mirror', publicMirror:true, confirmPublicMirror:true, hostRegistryPlan:plan };
|
|
60
|
+
} else {
|
|
61
|
+
if (['sourceMode','publicMirror','confirmPublicMirror','hostRegistryPlan'].some(key=>value[key]!==undefined) || reading && value.schemaVersion !== 1) fail('self-update-attempt-target');
|
|
62
|
+
source = { registry: PUBLIC_REGISTRY };
|
|
63
|
+
}
|
|
53
64
|
}
|
|
54
65
|
const pid = value.pid ?? this.pid;
|
|
55
66
|
if (!Number.isSafeInteger(pid) || pid < 1 || !reading && pid !== this.pid) fail('self-update-attempt-pid');
|
|
56
67
|
const taskPolicy = value.taskPolicy ?? 'wait-for-idle', confirmCancel = value.confirmCancel ?? false;
|
|
57
68
|
if (!['wait-for-idle', 'cancel-active'].includes(taskPolicy) || typeof confirmCancel !== 'boolean' || taskPolicy === 'cancel-active' && !confirmCancel || taskPolicy === 'wait-for-idle' && confirmCancel) fail('self-update-task-policy');
|
|
58
|
-
|
|
69
|
+
if (git && reading && value.schemaVersion !== 1) fail('self-update-attempt-target');
|
|
70
|
+
const result = { schemaVersion: publicMirror ? 2 : 1, id, name: SELF, from: value.from, to: value.to, ...source, pid, startedAt: timestamp(value.startedAt ?? this.time()), taskPolicy, confirmCancel };
|
|
59
71
|
for (const key of ['previousSha256', 'nextSha256']) if (value[key] !== undefined) { if (!SHA.test(value[key])) fail('self-update-digest-invalid'); result[key] = value[key]; }
|
|
60
72
|
for (const key of ['previousFiles', 'nextFiles']) if (value[key] !== undefined) {
|
|
61
73
|
if (!object(value[key]) || Object.keys(value[key]).length === 0 || Object.keys(value[key]).length > 128) fail('self-update-files-invalid');
|
|
@@ -107,7 +119,7 @@ export class SelfUpdateStore {
|
|
|
107
119
|
if (typeof source.timedOut === 'boolean') result.packageResult.timedOut = source.timedOut;
|
|
108
120
|
if (typeof source.kind === 'string') result.packageResult.kind = this.text(source.kind, 64);
|
|
109
121
|
}
|
|
110
|
-
if (Array.isArray(value.registries)) result.registries = value.registries.slice(0, 8).map(registry => registry === null ? null :
|
|
122
|
+
if (Array.isArray(value.registries)) result.registries = value.registries.slice(0, 8).map(registry => registry === null ? null : approvedPublicRegistry(registry) ? registryOrigin(registry) : '<unsupported-registry>');
|
|
111
123
|
if (['registry', 'spec-host'].includes(value.failedAt)) result.failedAt = value.failedAt;
|
|
112
124
|
return result;
|
|
113
125
|
}
|
package/lib/self-update.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { PUBLIC_MIRROR, approvedPublicRegistry, registryOrigin, readRegistryVersions } from './source.js';
|
|
3
|
+
import { versionDiscovery } from './online.js';
|
|
4
|
+
import { verifySelfRegistryPlan } from './self-update-policy.js';
|
|
3
5
|
import { SelfUpdateStore } from './self-update-store.js';
|
|
4
6
|
import { parseSelfGithubSource } from './self-update-github.js';
|
|
5
7
|
|
|
@@ -40,47 +42,87 @@ export class SelfUpdateCoordinator {
|
|
|
40
42
|
}
|
|
41
43
|
if (typeof this.manager.updateBundle !== 'function' || !this.taskGate || !this.preflight) throw failure('self-update-handoff-unavailable', 'Independent Host update support is unavailable.');
|
|
42
44
|
}
|
|
43
|
-
async
|
|
44
|
-
const { bundle, rows } = await this.current(); this.assertBundle(bundle, rows);
|
|
45
|
+
async discoverVersions(bundle, signal) {
|
|
45
46
|
if (bundle.update === 'git') {
|
|
46
47
|
let offered;
|
|
47
48
|
try { offered = await this.githubPreflight.discover({ bundle, signal }); }
|
|
48
49
|
catch (error) { if (error.code !== 'self-github-no-newer-version') throw error; return { status: 'listed', sourceKind: 'git', repository: parseSelfGithubSource(bundle.source).repository, versions: [] }; }
|
|
49
50
|
return { status: 'listed', sourceKind: 'git', repository: offered.repository, versions: offered.version ? [{ ...offered, bundle: true }] : [] };
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
return readRegistryVersions(this.manager, SELF_UPDATE_PACKAGE, signal);
|
|
53
|
+
}
|
|
54
|
+
async versions(signal) {
|
|
55
|
+
const { bundle, rows } = await this.current(); this.assertBundle(bundle, rows);
|
|
56
|
+
const answer = await this.discoverVersions(bundle, signal);
|
|
57
|
+
if (bundle.update !== 'git' && (answer.status !== 'listed' || !approvedPublicRegistry(answer.registry) || answer.queryReasons?.length)) throw failure('self-update-public-origin-required', 'Self-update version discovery requires verified official npm or the fixed public mirror; other sources are not migrated.');
|
|
58
|
+
if (versionDiscovery(answer).versionStatus === 'unknown') throw failure('version-metadata-incomplete', 'The version metadata is incomplete; prepare no update from it.');
|
|
53
59
|
return answer;
|
|
54
60
|
}
|
|
55
61
|
async checkOffer(bundle, offer, query, signal) {
|
|
56
62
|
const common = { bundle, currentDirectory: await this.resolvePackage(SELF_UPDATE_PACKAGE), targetVersion: offer.version, resolvedYamlVersion: await this.resolveYamlVersion(), signal };
|
|
57
63
|
if (bundle.update === 'git') return this.githubPreflight.check({ ...common, targetCommit: offer.commit });
|
|
58
|
-
|
|
64
|
+
const checked = await this.preflight.check({ ...common, registries: await this.manager.registries(), queryRegistry: query.registry });
|
|
65
|
+
const selectedRegistry = registryOrigin(query.registry);
|
|
66
|
+
if (selectedRegistry === PUBLIC_MIRROR && (checked.registry !== selectedRegistry || checked.sourceMode !== 'public-mirror' || checked.publicMirror !== true || !checked.hostRegistryPlan)) throw failure('self-public-mirror-preflight-unverified', 'Mirror canonical archive verification and its bound public registry plan were not provided.');
|
|
67
|
+
await this.checkRegistryPlan(selectedRegistry, signal, checked.hostRegistryPlan);
|
|
68
|
+
return { ...checked, registry: selectedRegistry };
|
|
69
|
+
}
|
|
70
|
+
async checkRegistryPlan(registry, signal, expectedPlan) {
|
|
71
|
+
const actual = verifySelfRegistryPlan(await this.manager.registries(), registry);
|
|
72
|
+
if (expectedPlan && JSON.stringify(actual) !== JSON.stringify(expectedPlan)) throw failure('self-registry-plan-changed', 'The confirmed public registry/fallback plan changed.');
|
|
73
|
+
signal?.throwIfAborted();
|
|
74
|
+
return actual;
|
|
75
|
+
}
|
|
76
|
+
offeredVersion(query) {
|
|
77
|
+
const discovery = versionDiscovery(query);
|
|
78
|
+
if (discovery.versionStatus !== 'available') throw failure('version-not-admitted', 'A complete compatible newer version offer is required.');
|
|
79
|
+
return query.versions.find(item => item.version === discovery.latestVersion);
|
|
59
80
|
}
|
|
60
81
|
assertPrepared(actual, prepared) {
|
|
61
82
|
if (actual.previous.sha256 !== prepared.previous.sha256 || actual.next.sha256 !== prepared.next.sha256
|
|
62
83
|
|| actual.sourceKind !== prepared.sourceKind || actual.fromCommit !== prepared.fromCommit || actual.toCommit !== prepared.toCommit
|
|
84
|
+
|| actual.registry !== prepared.registry || actual.sourceMode !== prepared.sourceMode || actual.publicMirror !== prepared.publicMirror
|
|
85
|
+
|| JSON.stringify(actual.hostRegistryPlan) !== JSON.stringify(prepared.hostRegistryPlan)
|
|
63
86
|
|| actual.nextSpec !== prepared.nextSpec) throw failure('self-update-archive-changed', 'Prepared source identities or package bytes changed; prepare a new confirmation.');
|
|
64
87
|
}
|
|
65
88
|
async scan(signal) {
|
|
89
|
+
let discovery = { versionStatus:'not-checked', latestVersion:null, latestPublishedVersion:null }, registry = null;
|
|
66
90
|
try {
|
|
67
91
|
const { bundle, rows } = await this.current(); this.assertBundle(bundle, rows);
|
|
68
|
-
const query = await this.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
92
|
+
const query = await this.discoverVersions(bundle, signal);
|
|
93
|
+
discovery = versionDiscovery(query); registry = query?.registry ?? null;
|
|
94
|
+
const reasons = [...query?.queryReasons ?? []];
|
|
95
|
+
if (discovery.versionStatus === 'error') reasons.push('version-query-failed');
|
|
96
|
+
if (discovery.versionStatus === 'unknown') reasons.push('version-metadata-incomplete');
|
|
97
|
+
if (bundle.update !== 'git') {
|
|
98
|
+
if (!approvedPublicRegistry(registry)) reasons.push(registry ? 'self-update-public-origin-required' : 'self-query-origin-unverified');
|
|
99
|
+
else {
|
|
100
|
+
try { verifySelfRegistryPlan(await this.manager.registries(), registry); }
|
|
101
|
+
catch (error) { if (signal?.aborted) throw error; reasons.push(error.code ?? 'self-query-origin-unverified'); }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
try { await this.assertAvailable(); } catch (error) { reasons.push(error.code ?? 'busy'); }
|
|
105
|
+
const offered = query?.versions?.find(item => item.version === discovery.latestVersion);
|
|
106
|
+
if (!reasons.length && offered) {
|
|
107
|
+
try { await this.checkOffer(bundle, offered, query, signal); }
|
|
108
|
+
catch (error) { if (signal?.aborted) throw error; reasons.push(error.code ?? 'self-update-check-failed'); }
|
|
109
|
+
}
|
|
110
|
+
const canUpdate = !reasons.length && discovery.versionStatus === 'available';
|
|
111
|
+
const updateStatus = canUpdate ? 'available' : reasons.length ? 'blocked' : 'no-update';
|
|
112
|
+
return { name:SELF_UPDATE_PACKAGE, version:bundle.version, ...discovery, versionChecked:discovery.versionStatus !== 'error',
|
|
113
|
+
...(bundle.update === 'git' ? { sourceKind:'git', repository:query.repository, branch:'main', sourceLabel:'GitHub main HEAD (not a release)', latestCommit:offered?.commit ?? null, currentCommit:parseSelfGithubSource(bundle.source).commit } : { sourceKind:'registry', registry,
|
|
114
|
+
...(registry === PUBLIC_MIRROR ? { sourceMode:'public-mirror', publicMirror:true, mirrorRiskRequiresAcknowledgement:true, infoWarnings:['public-mirror-may-lag'] } : {}) }),
|
|
115
|
+
canUpdate, updateStatus, status:updateStatus === 'blocked' ? 'blocked' : discovery.versionStatus, mode:'host-self-update', reasons:[...new Set(reasons)] };
|
|
75
116
|
} catch (error) {
|
|
76
|
-
|
|
117
|
+
if (signal?.aborted) throw error;
|
|
118
|
+
return { name:SELF_UPDATE_PACKAGE, ...discovery, registry, canUpdate:false, updateStatus:'blocked', status:'blocked', versionChecked:false, mode:'host-self-update', reasons:[error.code ?? 'self-update-check-failed'] };
|
|
77
119
|
}
|
|
78
120
|
}
|
|
79
121
|
async validateTarget(version, signal, targetCommit) {
|
|
80
122
|
await this.assertAvailable();
|
|
81
123
|
const { bundle, rows } = await this.current(); this.assertBundle(bundle, rows);
|
|
82
124
|
const versions = await this.versions(signal);
|
|
83
|
-
const offered =
|
|
125
|
+
const offered = this.offeredVersion(versions);
|
|
84
126
|
if (offered?.version !== version || bundle.update === 'git' && targetCommit !== undefined && offered.commit !== targetCommit
|
|
85
127
|
|| bundle.update !== 'git' && targetCommit !== undefined) throw failure('version-not-admitted', 'Choose the exact offered version and commit from the latest check.');
|
|
86
128
|
const checked = await this.checkOffer(bundle, offered, versions, signal);
|
|
@@ -89,25 +131,28 @@ export class SelfUpdateCoordinator {
|
|
|
89
131
|
async prepare(version, signal, { issueTicket = true, targetCommit } = {}) {
|
|
90
132
|
if (!stable(version)) throw failure('invalid-version', 'An exact stable version is required.');
|
|
91
133
|
const { bundle, checked, fingerprint } = await this.validateTarget(version, signal, targetCommit);
|
|
92
|
-
const git = bundle.update === 'git';
|
|
93
|
-
const
|
|
134
|
+
const git = bundle.update === 'git', publicMirror = !git && checked.registry === PUBLIC_MIRROR;
|
|
135
|
+
const mirrorFields = publicMirror ? { registry: checked.registry, sourceMode:'public-mirror', publicMirror:true, mirrorRiskRequiresAcknowledgement:true, hostRegistryPlan:checked.hostRegistryPlan } : {};
|
|
136
|
+
const plan = { id: randomUUID(), operation: 'host-self-update', profile: this.profile.name, ...mirrorFields,
|
|
94
137
|
items: [{ name: SELF_UPDATE_PACKAGE, from: bundle.version, to: version, version, mode: 'host-self-update', highImpact: true,
|
|
95
|
-
...(git ? { sourceKind: 'git', repository: checked.repository, fromCommit: checked.fromCommit, toCommit: checked.toCommit } : { sourceKind: 'registry' }) }],
|
|
138
|
+
...(git ? { sourceKind: 'git', repository: checked.repository, fromCommit: checked.fromCommit, toCommit: checked.toCommit } : { sourceKind: 'registry', registry: checked.registry, ...mirrorFields }) }],
|
|
96
139
|
expiresAt: new Date(this.now() + 120000).toISOString(), taskPolicy: 'wait-for-idle', taskPolicies: ['wait-for-idle', 'cancel-active'],
|
|
97
140
|
warnings: ['This is a separate self-update, not a normal batch. The independent official Host manager performs installation and its own rollback.',
|
|
98
141
|
'Current Agent tasks are coordinated before handoff. The old gate is released when the updater unloads; new tasks are not frozen throughout Host replacement.',
|
|
99
142
|
git ? 'GitHub main HEAD is discovery, not a signed release. The confirmed full commit pins the target. The Host fetches it again; preflight is not an atomic byte replacement.' : 'Downloaded old/new archives are preflight evidence only. The Host downloads registry packages again; it has no exact-archive replacement or atomic compare-and-swap API.',
|
|
100
143
|
...(git ? ['GitHub package dependencies use the existing Host registry configuration. No registry migration or build-script approval is granted; Host restoration uses the old saved commit and is verified separately.'] : []),
|
|
144
|
+
...(publicMirror ? ['The fixed public mirror may lag. Its prepared updater bytes must match canonical official npm archives, but the Host downloads again and may use existing known-public fallback/dependency sources. This is not a public-only atomic archive replacement or a guarantee of successful installation/recovery. Confirm this mirror risk separately; no source configuration is changed.'] : []),
|
|
101
145
|
'The panel may disappear and reload. Missing final evidence remains unknown and is never automatically retried. If both installation and Host recovery fail, use the official manager.'] };
|
|
102
146
|
if (!issueTicket) return this.redact(plan);
|
|
103
147
|
const ticket = randomUUID(); this.tickets.clear(); this.tickets.set(ticket, { plan, checked, fingerprint });
|
|
104
148
|
return this.redact({ ...plan, ticket });
|
|
105
149
|
}
|
|
106
150
|
hasTicket(ticket) { return this.tickets.has(ticket); }
|
|
107
|
-
async commit(ticket, { taskPolicy = 'wait-for-idle', confirmCancel = false } = {}) {
|
|
151
|
+
async commit(ticket, { taskPolicy = 'wait-for-idle', confirmCancel = false, confirmPublicMirror = false } = {}) {
|
|
108
152
|
const prepared = this.tickets.get(ticket); this.tickets.delete(ticket);
|
|
109
153
|
if (!prepared || this.now() >= Date.parse(prepared.plan.expiresAt)) throw failure('stale-confirmation', 'Self-update confirmation expired; prepare again.');
|
|
110
154
|
if (!['wait-for-idle', 'cancel-active'].includes(taskPolicy) || taskPolicy === 'cancel-active' && confirmCancel !== true) throw failure('task-confirmation-required', 'Stopping tasks requires separate explicit consent.');
|
|
155
|
+
if (prepared.checked.sourceMode === 'public-mirror' && confirmPublicMirror !== true) throw failure('self-public-mirror-confirmation-required', 'The fixed public mirror risk requires separate explicit consent.');
|
|
111
156
|
await this.assertAvailable();
|
|
112
157
|
const { bundle, rows } = await this.current(); this.assertBundle(bundle, rows);
|
|
113
158
|
if (this.fingerprint(bundle) !== prepared.fingerprint) throw failure('state-changed', 'The updater changed since confirmation preparation.');
|
|
@@ -118,22 +163,23 @@ export class SelfUpdateCoordinator {
|
|
|
118
163
|
try {
|
|
119
164
|
const source = prepared.checked.sourceKind === 'git'
|
|
120
165
|
? { sourceKind: 'git', repository: prepared.checked.repository, fromCommit: prepared.checked.fromCommit, toCommit: prepared.checked.toCommit }
|
|
121
|
-
: { registry:
|
|
166
|
+
: { registry: prepared.checked.registry, ...(prepared.checked.sourceMode === 'public-mirror' ? { sourceMode:'public-mirror', publicMirror:true, confirmPublicMirror:true, hostRegistryPlan:prepared.checked.hostRegistryPlan } : {}) };
|
|
122
167
|
await this.store.start({ id, name: SELF_UPDATE_PACKAGE, from: bundle.version, to: prepared.plan.items[0].to, ...source, startedAt: new Date(this.now()).toISOString(), taskPolicy, confirmCancel: taskPolicy === 'cancel-active', previousSha256: prepared.checked.previous.sha256, nextSha256: prepared.checked.next.sha256,
|
|
123
168
|
...(prepared.checked.previous.files ? { previousFiles: prepared.checked.previous.files } : {}), ...(prepared.checked.next.files ? { nextFiles: prepared.checked.next.files } : {}) });
|
|
124
169
|
} catch (error) { this.job = null; throw error; }
|
|
125
|
-
job.work = this.run(job, { taskPolicy, confirmCancel }).finally(() => { if (this.job === job) this.job = null; });
|
|
170
|
+
job.work = this.run(job, { taskPolicy, confirmCancel, confirmPublicMirror }).finally(() => { if (this.job === job) this.job = null; });
|
|
126
171
|
job.work.catch(() => {});
|
|
127
172
|
return { operationId: id, operation: 'host-self-update', phase: 'waiting' };
|
|
128
173
|
}
|
|
129
174
|
async run(job, policy) {
|
|
130
175
|
try {
|
|
131
176
|
// Recheck source, bytes and state before task cancellation and before any mutation.
|
|
177
|
+
if (job.prepared.checked.sourceMode === 'public-mirror' && policy.confirmPublicMirror !== true) throw failure('self-public-mirror-confirmation-required', 'The confirmed mirror risk consent is missing.');
|
|
132
178
|
const target = job.prepared.plan.items[0].to;
|
|
133
179
|
const { bundle, rows } = await this.current(); this.assertBundle(bundle, rows);
|
|
134
180
|
if (this.fingerprint(bundle) !== job.prepared.fingerprint || this.unavailable()) throw failure('state-changed', 'Updater state changed before handoff.');
|
|
135
181
|
const query = await this.versions(job.controller.signal);
|
|
136
|
-
const offeredBeforeTasks =
|
|
182
|
+
const offeredBeforeTasks = this.offeredVersion(query);
|
|
137
183
|
if (offeredBeforeTasks?.version !== target || offeredBeforeTasks?.commit !== job.prepared.checked.toCommit) throw failure('version-not-admitted', 'Self-update offer changed before task handling.');
|
|
138
184
|
const checked = await this.checkOffer(bundle, offeredBeforeTasks, query, job.controller.signal);
|
|
139
185
|
this.assertPrepared(checked, job.prepared.checked);
|
|
@@ -143,7 +189,7 @@ export class SelfUpdateCoordinator {
|
|
|
143
189
|
const current = await this.current(); this.assertBundle(current.bundle, current.rows);
|
|
144
190
|
if (this.fingerprint(current.bundle) !== job.prepared.fingerprint || this.unavailable() || this.closed) throw failure('state-changed', 'Updater changed while waiting.');
|
|
145
191
|
const refreshedQuery = await this.versions(gateSignal);
|
|
146
|
-
const refreshedOffered =
|
|
192
|
+
const refreshedOffered = this.offeredVersion(refreshedQuery);
|
|
147
193
|
if (refreshedOffered?.version !== target || refreshedOffered?.commit !== job.prepared.checked.toCommit) throw failure('version-not-admitted', 'Self-update offer changed while waiting.');
|
|
148
194
|
const refreshed = await this.checkOffer(current.bundle, refreshedOffered, refreshedQuery, gateSignal);
|
|
149
195
|
this.assertPrepared(refreshed, job.prepared.checked);
|
|
@@ -153,10 +199,13 @@ export class SelfUpdateCoordinator {
|
|
|
153
199
|
await this.store.markHandedOff(job.id);
|
|
154
200
|
gateSignal.throwIfAborted();
|
|
155
201
|
if (this.closed || this.unavailable()) throw failure('state-changed', 'Updater unloaded during handoff.');
|
|
202
|
+
if (refreshed.sourceKind !== 'git') await this.checkRegistryPlan(refreshedQuery.registry, gateSignal, job.prepared.checked.hostRegistryPlan);
|
|
203
|
+
gateSignal.throwIfAborted();
|
|
204
|
+
if (this.closed || this.unavailable()) throw failure('state-changed', 'Updater changed during the final source check.');
|
|
156
205
|
job.phase = 'handed-off'; job.dispatched = true;
|
|
157
206
|
// Capture the public manager method once. Its own ownerContext performs the package flow.
|
|
158
207
|
const manager = this.manager;
|
|
159
|
-
const options = refreshed.sourceKind === 'git' ? { spec: refreshed.nextSpec, requestId: job.id } : { registry:
|
|
208
|
+
const options = refreshed.sourceKind === 'git' ? { spec: refreshed.nextSpec, requestId: job.id } : { registry: job.prepared.checked.registry, requestId: job.id };
|
|
160
209
|
const result = await manager.updateBundle(SELF_UPDATE_PACKAGE, target, options);
|
|
161
210
|
// The sole post-unload work is bounded sanitized evidence persistence.
|
|
162
211
|
await this.store.finish(job.id, result);
|
|
@@ -175,12 +224,13 @@ export class SelfUpdateCoordinator {
|
|
|
175
224
|
const entry = id ? await this.store.read(id) : await this.store.latest();
|
|
176
225
|
if (!entry?.attempt) return entry;
|
|
177
226
|
const current = await this.current();
|
|
178
|
-
const git = entry.attempt.sourceKind === 'git';
|
|
227
|
+
const git = entry.attempt.sourceKind === 'git', publicMirror = entry.attempt.sourceMode === 'public-mirror';
|
|
179
228
|
const verify = async (version, files, expectedCommit) => {
|
|
180
|
-
let packageStatus = 'unknown', sourceStatus = git ? 'unknown' : undefined;
|
|
229
|
+
let packageStatus = 'unknown', sourceStatus = git || publicMirror ? 'unknown' : undefined;
|
|
181
230
|
if (git) {
|
|
182
231
|
try { sourceStatus = current.bundle?.update === 'git' && parseSelfGithubSource(current.bundle.source).commit === expectedCommit ? 'verified' : 'failed'; } catch { sourceStatus = 'failed'; }
|
|
183
|
-
}
|
|
232
|
+
} else if(publicMirror) sourceStatus=current.bundle?.installed===true && current.bundle.update==='registry'
|
|
233
|
+
&& current.bundle.version===version && current.bundle.source===`${SELF_UPDATE_PACKAGE}@${version}`?'verified':'failed';
|
|
184
234
|
const verifier = git ? this.githubPreflight : this.preflight;
|
|
185
235
|
if (current.bundle?.version === version && files && typeof verifier?.verifyInstalled === 'function') {
|
|
186
236
|
try {
|
|
@@ -192,11 +242,12 @@ export class SelfUpdateCoordinator {
|
|
|
192
242
|
const expectedRows = current.rows.length === 1 && current.rows[0].moduleName === SELF_UPDATE_PACKAGE && (current.rows[0].patchId === 'plugin-update-doctor' || current.rows[0].entryId === 'include:plugin-update-doctor');
|
|
193
243
|
const hostStatus = current.bundle?.version === version && expectedRows && current.rows.every(row => row.enabled && row.fiberPhase === 'active') ? 'active' : 'unknown';
|
|
194
244
|
return { package: { status: packageStatus, version: current.bundle?.version ?? null, expectedVersion: version }, host: { status: hostStatus, activeRows: current.rows.filter(row => row.enabled && row.fiberPhase === 'active').length, totalRows: current.rows.length },
|
|
195
|
-
...(git ? { source: { status: sourceStatus, repository: entry.attempt.repository, expectedCommit } } :
|
|
245
|
+
...(git ? { source: { status: sourceStatus, repository: entry.attempt.repository, expectedCommit } } : publicMirror ?
|
|
246
|
+
{ source:{status:sourceStatus,expectedKind:'registry',kind:current.bundle?.update??'unknown',confirmedRegistry:entry.attempt.registry,sourceMode:'public-mirror',publicMirror:true,transportVerified:false} } : {}) };
|
|
196
247
|
};
|
|
197
248
|
const verification = await verify(entry.attempt.to, entry.attempt.nextFiles, entry.attempt.toCommit);
|
|
198
249
|
const restoreVerification = entry.result?.restore ? await verify(entry.attempt.from, entry.attempt.previousFiles, entry.attempt.fromCommit) : undefined;
|
|
199
|
-
const verifiedApplied = entry.result?.result?.application === 'applied' && verification.package.status === 'verified' && verification.host.status === 'active' && (!git || verification.source.status === 'verified');
|
|
250
|
+
const verifiedApplied = entry.result?.result?.application === 'applied' && verification.package.status === 'verified' && verification.host.status === 'active' && (!(git || publicMirror) || verification.source.status === 'verified');
|
|
200
251
|
return { ...entry, verification, restoreVerification, verifiedApplied };
|
|
201
252
|
}
|
|
202
253
|
async dispose() {
|