@indigoai-us/hq-cloud 6.16.19 → 6.16.21
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/dist/bin/sync-runner-installation-id.d.ts +66 -0
- package/dist/bin/sync-runner-installation-id.d.ts.map +1 -0
- package/dist/bin/sync-runner-installation-id.js +138 -0
- package/dist/bin/sync-runner-installation-id.js.map +1 -0
- package/dist/bin/sync-runner-manifest.d.ts +120 -0
- package/dist/bin/sync-runner-manifest.d.ts.map +1 -0
- package/dist/bin/sync-runner-manifest.js +348 -0
- package/dist/bin/sync-runner-manifest.js.map +1 -0
- package/dist/bin/sync-runner-manifest.test.d.ts +12 -0
- package/dist/bin/sync-runner-manifest.test.d.ts.map +1 -0
- package/dist/bin/sync-runner-manifest.test.js +510 -0
- package/dist/bin/sync-runner-manifest.test.js.map +1 -0
- package/dist/bin/sync-runner.d.ts +56 -21
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +86 -61
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/bin/sync-runner.test.js +217 -0
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/share-presign-transport.test.d.ts +22 -0
- package/dist/cli/share-presign-transport.test.d.ts.map +1 -0
- package/dist/cli/share-presign-transport.test.js +237 -0
- package/dist/cli/share-presign-transport.test.js.map +1 -0
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +17 -3
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +9 -0
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/sync.test.js +123 -0
- package/dist/cli/sync.test.js.map +1 -1
- package/dist/company-slug.d.ts +31 -0
- package/dist/company-slug.d.ts.map +1 -0
- package/dist/company-slug.js +52 -0
- package/dist/company-slug.js.map +1 -0
- package/dist/company-slug.test.d.ts +7 -0
- package/dist/company-slug.test.d.ts.map +1 -0
- package/dist/company-slug.test.js +43 -0
- package/dist/company-slug.test.js.map +1 -0
- package/dist/company-vault-transport.d.ts +69 -0
- package/dist/company-vault-transport.d.ts.map +1 -0
- package/dist/company-vault-transport.js +89 -0
- package/dist/company-vault-transport.js.map +1 -0
- package/dist/company-vault-transport.test.d.ts +12 -0
- package/dist/company-vault-transport.test.d.ts.map +1 -0
- package/dist/company-vault-transport.test.js +97 -0
- package/dist/company-vault-transport.test.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/journal-ledger-index.test.d.ts +15 -0
- package/dist/journal-ledger-index.test.d.ts.map +1 -0
- package/dist/journal-ledger-index.test.js +247 -0
- package/dist/journal-ledger-index.test.js.map +1 -0
- package/dist/journal.d.ts +110 -0
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +253 -5
- package/dist/journal.js.map +1 -1
- package/dist/manifest/US-002.acceptance.test.d.ts +11 -0
- package/dist/manifest/US-002.acceptance.test.d.ts.map +1 -0
- package/dist/manifest/US-002.acceptance.test.js +160 -0
- package/dist/manifest/US-002.acceptance.test.js.map +1 -0
- package/dist/manifest/US-004.acceptance.test.d.ts +12 -0
- package/dist/manifest/US-004.acceptance.test.d.ts.map +1 -0
- package/dist/manifest/US-004.acceptance.test.js +173 -0
- package/dist/manifest/US-004.acceptance.test.js.map +1 -0
- package/dist/manifest/build-manifest.bench.test.d.ts +22 -0
- package/dist/manifest/build-manifest.bench.test.d.ts.map +1 -0
- package/dist/manifest/build-manifest.bench.test.js +544 -0
- package/dist/manifest/build-manifest.bench.test.js.map +1 -0
- package/dist/manifest/build-manifest.d.ts +319 -0
- package/dist/manifest/build-manifest.d.ts.map +1 -0
- package/dist/manifest/build-manifest.js +1043 -0
- package/dist/manifest/build-manifest.js.map +1 -0
- package/dist/manifest/build-manifest.test.d.ts +10 -0
- package/dist/manifest/build-manifest.test.d.ts.map +1 -0
- package/dist/manifest/build-manifest.test.js +1060 -0
- package/dist/manifest/build-manifest.test.js.map +1 -0
- package/dist/manifest/contract.d.ts +290 -0
- package/dist/manifest/contract.d.ts.map +1 -0
- package/dist/manifest/contract.js +476 -0
- package/dist/manifest/contract.js.map +1 -0
- package/dist/manifest/contract.test.d.ts +17 -0
- package/dist/manifest/contract.test.d.ts.map +1 -0
- package/dist/manifest/contract.test.js +283 -0
- package/dist/manifest/contract.test.js.map +1 -0
- package/dist/manifest/import-graph.test.d.ts +25 -0
- package/dist/manifest/import-graph.test.d.ts.map +1 -0
- package/dist/manifest/import-graph.test.js +120 -0
- package/dist/manifest/import-graph.test.js.map +1 -0
- package/dist/manifest/ledger-shard-isolation.test.d.ts +18 -0
- package/dist/manifest/ledger-shard-isolation.test.d.ts.map +1 -0
- package/dist/manifest/ledger-shard-isolation.test.js +153 -0
- package/dist/manifest/ledger-shard-isolation.test.js.map +1 -0
- package/dist/manifest/snapshot-store.d.ts +143 -0
- package/dist/manifest/snapshot-store.d.ts.map +1 -0
- package/dist/manifest/snapshot-store.js +291 -0
- package/dist/manifest/snapshot-store.js.map +1 -0
- package/dist/manifest/snapshot-store.test.d.ts +11 -0
- package/dist/manifest/snapshot-store.test.d.ts.map +1 -0
- package/dist/manifest/snapshot-store.test.js +133 -0
- package/dist/manifest/snapshot-store.test.js.map +1 -0
- package/dist/manifest/upload-manifest.d.ts +301 -0
- package/dist/manifest/upload-manifest.d.ts.map +1 -0
- package/dist/manifest/upload-manifest.js +921 -0
- package/dist/manifest/upload-manifest.js.map +1 -0
- package/dist/manifest/upload-manifest.test.d.ts +10 -0
- package/dist/manifest/upload-manifest.test.d.ts.map +1 -0
- package/dist/manifest/upload-manifest.test.js +1052 -0
- package/dist/manifest/upload-manifest.test.js.map +1 -0
- package/dist/manifest-reconcile.d.ts.map +1 -1
- package/dist/manifest-reconcile.js +1 -26
- package/dist/manifest-reconcile.js.map +1 -1
- package/dist/posix-key.d.ts +36 -0
- package/dist/posix-key.d.ts.map +1 -0
- package/dist/posix-key.js +38 -0
- package/dist/posix-key.js.map +1 -0
- package/dist/s3.d.ts +2 -18
- package/dist/s3.d.ts.map +1 -1
- package/dist/s3.js +6 -20
- package/dist/s3.js.map +1 -1
- package/dist/sync/journal-ledger-stream.d.ts +56 -0
- package/dist/sync/journal-ledger-stream.d.ts.map +1 -0
- package/dist/sync/journal-ledger-stream.js +191 -0
- package/dist/sync/journal-ledger-stream.js.map +1 -0
- package/dist/sync/journal-ledger-stream.test.d.ts +12 -0
- package/dist/sync/journal-ledger-stream.test.d.ts.map +1 -0
- package/dist/sync/journal-ledger-stream.test.js +134 -0
- package/dist/sync/journal-ledger-stream.test.js.map +1 -0
- package/dist/types.d.ts +18 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Desktop-daemon hook for the sync-reconciliation audit (US-004).
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS LIVES IN THE RUNNER
|
|
5
|
+
* ----------------------------
|
|
6
|
+
* The HQ Sync desktop app does not run a sync pass itself — it spawns
|
|
7
|
+
* `hq-sync-runner` and consumes its ndjson. So "after a successful sync pass
|
|
8
|
+
* the desktop daemon uploads a manifest" IS a runner concern: the runner is
|
|
9
|
+
* the only process that knows which scopes were synced, which of them finished
|
|
10
|
+
* CLEANLY, where the HQ root and the state dir are, and how to mint a JWT.
|
|
11
|
+
*
|
|
12
|
+
* WHAT THIS OWNS (and nothing more)
|
|
13
|
+
* ---------------------------------
|
|
14
|
+
* - picking the scopes that earned an upload (clean pass only);
|
|
15
|
+
* - resolving the installation/machine identity;
|
|
16
|
+
* - the authed transport (base URL + bearer);
|
|
17
|
+
* - turning each pass result into one additive ndjson event.
|
|
18
|
+
*
|
|
19
|
+
* Everything that makes an upload SAFE — the kill switch, the 24h per-scope
|
|
20
|
+
* throttle, sequencing, chunking, the delta base, the 404 soft skip and the
|
|
21
|
+
* upload wall clock — belongs to `runManifestUploadPass` and is deliberately
|
|
22
|
+
* NOT re-derived here.
|
|
23
|
+
*
|
|
24
|
+
* FAILURE POSTURE
|
|
25
|
+
* ---------------
|
|
26
|
+
* This is a tail step: it runs AFTER `all-complete` has been emitted, and it
|
|
27
|
+
* can never change the runner's exit code or any pre-existing event. An audit
|
|
28
|
+
* that can break sync is strictly worse than no audit, so every call site is
|
|
29
|
+
* wrapped and every outcome — including a throwing or hanging transport — ends
|
|
30
|
+
* as a diagnostic plus (where a pass ran) one `manifest-upload` event.
|
|
31
|
+
*/
|
|
32
|
+
import { getOrCreateMachineId } from "../lib/machine-id.js";
|
|
33
|
+
import { readDesktopInstallationId } from "./sync-runner-installation-id.js";
|
|
34
|
+
import { isManifestUploadDisabled, runManifestUploadPass, } from "../manifest/upload-manifest.js";
|
|
35
|
+
/**
|
|
36
|
+
* Wall-clock bound on the tree WALK for one scope.
|
|
37
|
+
*
|
|
38
|
+
* Separate from the seam's upload budget (a slow disk and a black-holed socket
|
|
39
|
+
* fail for unrelated reasons).
|
|
40
|
+
*
|
|
41
|
+
* Was 30s, which measured as far too tight: on a real 690k-file personal vault
|
|
42
|
+
* the walk expired after ~179k files, and (before the truncation guard landed)
|
|
43
|
+
* uploaded the resulting empty manifest as a complete one. The stat walk
|
|
44
|
+
* benches at well under 2s per 70k files, so ~690k files wants ~20s of pure
|
|
45
|
+
* stat — but a cold page cache, a spinning disk or a busy laptop can multiply
|
|
46
|
+
* that several times over, and the cost of over-budgeting is nil (the walk
|
|
47
|
+
* yields to the event loop throughout and stops the moment it finishes) while
|
|
48
|
+
* the cost of under-budgeting is a scope that can NEVER complete a pass.
|
|
49
|
+
* 90s gives roughly 4x headroom over the measured target.
|
|
50
|
+
*/
|
|
51
|
+
export const RUNNER_MANIFEST_WALK_WALL_MS = 90_000;
|
|
52
|
+
/**
|
|
53
|
+
* Bound on the ENTIRE post-sync manifest phase, across every scope.
|
|
54
|
+
*
|
|
55
|
+
* The per-scope budgets already bound each pass, but a wide fanout multiplies
|
|
56
|
+
* them. This is the promise the runner makes to its supervisor: the tail step
|
|
57
|
+
* is over within a bounded time no matter how many companies are in the plan.
|
|
58
|
+
*/
|
|
59
|
+
export const RUNNER_MANIFEST_PHASE_WALL_MS = 240_000;
|
|
60
|
+
/** Per-request timeout for one chunk POST. */
|
|
61
|
+
const MANIFEST_REQUEST_TIMEOUT_MS = 20_000;
|
|
62
|
+
/**
|
|
63
|
+
* Which scope does this fanout target describe?
|
|
64
|
+
*
|
|
65
|
+
* The personal leg is `kind: "personal"`; every other target is its company.
|
|
66
|
+
* A target with no uid cannot be attributed to a company and is skipped rather
|
|
67
|
+
* than uploaded under a guessed identity.
|
|
68
|
+
*/
|
|
69
|
+
function scopeForTarget(target) {
|
|
70
|
+
// `personalMode` ONLY. The slug is emphatically not a discriminator: a cloud
|
|
71
|
+
// company may be literally NAMED "personal" — its own directory under
|
|
72
|
+
// companies, its own uid, its own bucket — and keying on the string would
|
|
73
|
+
// build a PERSONAL manifest for it (the personal snapshot scope key, the
|
|
74
|
+
// personal journal shard, the personal walk roots) and upload that tenant's
|
|
75
|
+
// file list under the operator's personal vault. That is a tenant-boundary
|
|
76
|
+
// bug, not a labelling one. `resolveScope()` in the builder already refuses
|
|
77
|
+
// to conflate the two; this call site must not hand it the wrong scope in
|
|
78
|
+
// the first place.
|
|
79
|
+
if (target.personalMode === true) {
|
|
80
|
+
return { kind: "personal" };
|
|
81
|
+
}
|
|
82
|
+
if (!target.uid)
|
|
83
|
+
return null;
|
|
84
|
+
return { kind: "company", companyUid: target.uid, slug: target.slug };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The authed POST the seam asks for.
|
|
88
|
+
*
|
|
89
|
+
* Resolves for ANY HTTP answer (the pass reasons about 404/409/413 itself) and
|
|
90
|
+
* rejects only for genuine transport failures.
|
|
91
|
+
*/
|
|
92
|
+
function createTransport(options) {
|
|
93
|
+
const base = options.apiBaseUrl.replace(/\/+$/, "");
|
|
94
|
+
const url = `${base}/v1/sync-manifest/upload`;
|
|
95
|
+
const doFetch = options.fetchImpl ?? fetch;
|
|
96
|
+
return async (chunk) => {
|
|
97
|
+
const token = await options.getAccessToken();
|
|
98
|
+
const controller = new AbortController();
|
|
99
|
+
const timer = setTimeout(() => controller.abort(), MANIFEST_REQUEST_TIMEOUT_MS);
|
|
100
|
+
try {
|
|
101
|
+
const res = await doFetch(url, {
|
|
102
|
+
method: "POST",
|
|
103
|
+
headers: {
|
|
104
|
+
Authorization: `Bearer ${token}`,
|
|
105
|
+
"content-type": "application/json",
|
|
106
|
+
...(options.clientInfo
|
|
107
|
+
? {
|
|
108
|
+
"x-hq-client-name": options.clientInfo.name,
|
|
109
|
+
"x-hq-client-version": options.clientInfo.version,
|
|
110
|
+
}
|
|
111
|
+
: {}),
|
|
112
|
+
},
|
|
113
|
+
body: JSON.stringify(chunk),
|
|
114
|
+
signal: controller.signal,
|
|
115
|
+
});
|
|
116
|
+
// A body is optional: the pass only needs it for `snapshotId` /
|
|
117
|
+
// `materialised` / `resend_full`, and a non-JSON error page is not a
|
|
118
|
+
// transport failure.
|
|
119
|
+
let body;
|
|
120
|
+
try {
|
|
121
|
+
body = await res.json();
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
body = undefined;
|
|
125
|
+
}
|
|
126
|
+
return { status: res.status, body };
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
clearTimeout(timer);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** Sentinel for "the phase budget ran out before this pass settled". */
|
|
134
|
+
const PHASE_TIMED_OUT = Symbol("manifest-upload-phase-timeout");
|
|
135
|
+
/**
|
|
136
|
+
* Resolve with `pass`, or with {@link PHASE_TIMED_OUT} at `deadlineMs`.
|
|
137
|
+
*
|
|
138
|
+
* An abandoned pass is left to settle on its own (its abort signal has already
|
|
139
|
+
* been raised); nothing downstream reads it, and its own `finally` still
|
|
140
|
+
* releases the per-scope lock.
|
|
141
|
+
*/
|
|
142
|
+
async function withPhaseDeadline(pass, deadlineMs) {
|
|
143
|
+
let timer;
|
|
144
|
+
try {
|
|
145
|
+
return await Promise.race([
|
|
146
|
+
pass,
|
|
147
|
+
new Promise((resolve) => {
|
|
148
|
+
timer = setTimeout(() => resolve(PHASE_TIMED_OUT), Math.max(0, deadlineMs - Date.now()));
|
|
149
|
+
timer.unref?.();
|
|
150
|
+
}),
|
|
151
|
+
]);
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
if (timer !== undefined)
|
|
155
|
+
clearTimeout(timer);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Run one manifest upload pass per cleanly-synced scope.
|
|
160
|
+
*
|
|
161
|
+
* Never throws, never rejects: the caller is a tail step whose only contract
|
|
162
|
+
* is that the runner's exit code and event stream are unchanged by it.
|
|
163
|
+
*/
|
|
164
|
+
export async function runPostSyncManifestUploads(options) {
|
|
165
|
+
const env = options.env ?? process.env;
|
|
166
|
+
// Checked HERE, before anything is built or resolved, so the kill switch
|
|
167
|
+
// costs exactly nothing: no identity resolution, no transport, no walk, no
|
|
168
|
+
// event. (The seam checks it too — this is the "don't even build it" half.)
|
|
169
|
+
if (isManifestUploadDisabled(env))
|
|
170
|
+
return [];
|
|
171
|
+
const emitted = [];
|
|
172
|
+
const runPass = options.runPass ?? runManifestUploadPass;
|
|
173
|
+
const report = options.reportDiagnostic ?? (() => undefined);
|
|
174
|
+
// Only a scope whose leg finished cleanly earns an upload. A partial pass
|
|
175
|
+
// would describe a tree the client has not finished materialising, and the
|
|
176
|
+
// server would read that as "missing on client" — the exact false positive
|
|
177
|
+
// this audit exists to avoid. When in doubt, skip.
|
|
178
|
+
const eligible = options.targets.filter((target) => options.completedCompanySlugs.has(target.slug));
|
|
179
|
+
if (eligible.length === 0)
|
|
180
|
+
return [];
|
|
181
|
+
let machineId;
|
|
182
|
+
try {
|
|
183
|
+
machineId = (options.resolveMachineId ?? getOrCreateMachineId)(options.hqRoot);
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
report({
|
|
187
|
+
event: "runner.manifest_upload.identity_failed",
|
|
188
|
+
message: "manifest identity resolution failed; skipping manifest uploads",
|
|
189
|
+
err,
|
|
190
|
+
context: { hqRoot: options.hqRoot },
|
|
191
|
+
});
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
// The installation id is NOT the machine id. The server fences the upload on
|
|
195
|
+
// client-health enrolment, and on a desktop host the enrolled id is the one
|
|
196
|
+
// the menubar app's heartbeat pinned in `~/.hq/client-health.json` — see
|
|
197
|
+
// `sync-runner-installation-id.ts`. Uploading under the machine id would 403
|
|
198
|
+
// (INSTALLATION_NOT_ENROLLED) on every host whose `<hqRoot>/.hq/machine-id`
|
|
199
|
+
// was provisioned independently of the menubar identity.
|
|
200
|
+
let installationId;
|
|
201
|
+
try {
|
|
202
|
+
installationId = (options.resolveInstallationId ?? readDesktopInstallationId)({ stateDir: options.stateDir });
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
// The reader is written not to throw; treat any surprise as "unknown".
|
|
206
|
+
report({
|
|
207
|
+
event: "runner.manifest_upload.identity_failed",
|
|
208
|
+
message: "enrolled installation lookup failed; skipping manifest uploads",
|
|
209
|
+
err,
|
|
210
|
+
context: { stateDir: options.stateDir },
|
|
211
|
+
});
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
if (installationId === undefined) {
|
|
215
|
+
// No heartbeat has ever enrolled this host, so every chunk we could send
|
|
216
|
+
// is guaranteed a 403. Skipping is the honest outcome: it costs nothing,
|
|
217
|
+
// leaves no misleading `failed` event, and self-heals as soon as the
|
|
218
|
+
// desktop app's heartbeat lands. Minting an id here is NOT an option — it
|
|
219
|
+
// would be unenrolled anyway and could orphan the heartbeat's own rows.
|
|
220
|
+
report({
|
|
221
|
+
event: "runner.manifest_upload.not_enrolled",
|
|
222
|
+
message: "no enrolled client-health installation for this host; skipping manifest uploads",
|
|
223
|
+
context: { stateDir: options.stateDir },
|
|
224
|
+
});
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
const transport = createTransport({
|
|
228
|
+
apiBaseUrl: options.apiBaseUrl,
|
|
229
|
+
getAccessToken: options.getAccessToken,
|
|
230
|
+
...(options.clientInfo ? { clientInfo: options.clientInfo } : {}),
|
|
231
|
+
...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
|
|
232
|
+
});
|
|
233
|
+
const phaseDeadlineMs = Date.now() + RUNNER_MANIFEST_PHASE_WALL_MS;
|
|
234
|
+
// One controller for the whole phase: when the phase budget is spent, the
|
|
235
|
+
// in-flight pass is asked to stop and the remaining scopes are not started.
|
|
236
|
+
const phaseAbort = new AbortController();
|
|
237
|
+
const phaseTimer = setTimeout(() => phaseAbort.abort(), RUNNER_MANIFEST_PHASE_WALL_MS);
|
|
238
|
+
// A tail step must never keep a finished process alive.
|
|
239
|
+
phaseTimer.unref?.();
|
|
240
|
+
try {
|
|
241
|
+
for (let index = 0; index < eligible.length; index += 1) {
|
|
242
|
+
const target = eligible[index];
|
|
243
|
+
if (Date.now() >= phaseDeadlineMs || phaseAbort.signal.aborted) {
|
|
244
|
+
report({
|
|
245
|
+
event: "runner.manifest_upload.phase_budget_exhausted",
|
|
246
|
+
message: "manifest upload phase budget spent; remaining scopes skipped",
|
|
247
|
+
// Counted from the LOOP INDEX, not from `emitted.length`. A target
|
|
248
|
+
// that was skipped (no uid, so no scope) emits nothing, and a pass
|
|
249
|
+
// that timed out breaks before emitting — so
|
|
250
|
+
// `eligible.length - emitted.length` silently counted those as
|
|
251
|
+
// still-pending and over-reported the remainder.
|
|
252
|
+
context: { remaining: eligible.length - index },
|
|
253
|
+
});
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
const scope = scopeForTarget(target);
|
|
257
|
+
if (scope === null)
|
|
258
|
+
continue;
|
|
259
|
+
try {
|
|
260
|
+
// The seam bounds its own walk and upload, but this call site must not
|
|
261
|
+
// TRUST that: an injected/updated pass that never settles would
|
|
262
|
+
// otherwise wedge the runner's tail forever. Race every pass against
|
|
263
|
+
// the remaining phase budget so the loop terminates by construction.
|
|
264
|
+
const result = await withPhaseDeadline(runPass({
|
|
265
|
+
scope,
|
|
266
|
+
hqRoot: options.hqRoot,
|
|
267
|
+
stateDir: options.stateDir,
|
|
268
|
+
// Two DIFFERENT identities, deliberately. `installationId` is the
|
|
269
|
+
// client-health-enrolled identity (the join key the server checks);
|
|
270
|
+
// `machineId` stays hq-cloud's own per-host id
|
|
271
|
+
// (`<hqRoot>/.hq/machine-id`, see src/lib/machine-id.ts) which
|
|
272
|
+
// attributes conflict mirrors. They coincide on some hosts and
|
|
273
|
+
// diverge on others; they are not interchangeable.
|
|
274
|
+
installationId,
|
|
275
|
+
machineId,
|
|
276
|
+
// Always `desktop`: this binary is what the HQ Sync app spawns.
|
|
277
|
+
// The CLI's `hq sync manifest` owns the `cli` source.
|
|
278
|
+
source: "desktop",
|
|
279
|
+
transport,
|
|
280
|
+
// Throttle ON, no force-full: the daemon path is exactly the one
|
|
281
|
+
// the 24h spacing exists for.
|
|
282
|
+
...(options.now !== undefined ? { now: options.now } : {}),
|
|
283
|
+
env,
|
|
284
|
+
maxWallMs: RUNNER_MANIFEST_WALK_WALL_MS,
|
|
285
|
+
// Explicit, not inherited. This is the post-sync TAIL STEP on a
|
|
286
|
+
// laptop: it may stat the tree, it may not read it. Content hashing
|
|
287
|
+
// costs an unbounded amount of IO (measured at ~9m40s / 2.9 GB RSS
|
|
288
|
+
// on a real vault with a cold journal) and belongs behind an
|
|
289
|
+
// explicit `hq sync manifest --full-hash`, never here.
|
|
290
|
+
hashPolicy: "never",
|
|
291
|
+
abortSignal: phaseAbort.signal,
|
|
292
|
+
logger: {
|
|
293
|
+
warn: (message, meta) => report({
|
|
294
|
+
event: "runner.manifest_upload.warn",
|
|
295
|
+
message,
|
|
296
|
+
context: meta,
|
|
297
|
+
}),
|
|
298
|
+
error: (message, meta) => report({
|
|
299
|
+
event: "runner.manifest_upload.error",
|
|
300
|
+
message,
|
|
301
|
+
context: meta,
|
|
302
|
+
}),
|
|
303
|
+
},
|
|
304
|
+
}), phaseDeadlineMs);
|
|
305
|
+
if (result === PHASE_TIMED_OUT) {
|
|
306
|
+
phaseAbort.abort();
|
|
307
|
+
report({
|
|
308
|
+
event: "runner.manifest_upload.phase_timeout",
|
|
309
|
+
message: "manifest upload pass exceeded the phase budget; abandoned",
|
|
310
|
+
context: { company: target.slug },
|
|
311
|
+
});
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
const payload = {
|
|
315
|
+
company: target.slug,
|
|
316
|
+
scope: scope.kind === "company" ? "company" : "personal",
|
|
317
|
+
status: result.status,
|
|
318
|
+
...(result.mode ? { mode: result.mode } : {}),
|
|
319
|
+
...(result.chunkCount !== undefined
|
|
320
|
+
? { chunkCount: result.chunkCount }
|
|
321
|
+
: {}),
|
|
322
|
+
...(result.uploadedChunks !== undefined
|
|
323
|
+
? { uploadedChunks: result.uploadedChunks }
|
|
324
|
+
: {}),
|
|
325
|
+
...(result.error ? { errorKind: result.error.kind } : {}),
|
|
326
|
+
};
|
|
327
|
+
emitted.push(payload);
|
|
328
|
+
options.emitEvent(payload);
|
|
329
|
+
}
|
|
330
|
+
catch (err) {
|
|
331
|
+
// `runManifestUploadPass` only throws for a programmer error (a
|
|
332
|
+
// malformed scope). Report it and keep going — one bad scope must not
|
|
333
|
+
// cost the others their audit, and none of it may reach the caller.
|
|
334
|
+
report({
|
|
335
|
+
event: "runner.manifest_upload.threw",
|
|
336
|
+
message: "manifest upload pass threw",
|
|
337
|
+
err,
|
|
338
|
+
context: { company: target.slug },
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
finally {
|
|
344
|
+
clearTimeout(phaseTimer);
|
|
345
|
+
}
|
|
346
|
+
return emitted;
|
|
347
|
+
}
|
|
348
|
+
//# sourceMappingURL=sync-runner-manifest.js.map
|
|
@@ -0,0 +1 @@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gEAAgE;gBAChE,sEAAsE;gBACtE,oEAAoE;gBACpE,MAAM,CAAC;oBACL,KAAK,EAAE,8BAA8B;oBACrC,OAAO,EAAE,4BAA4B;oBACrC,GAAG;oBACH,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE;iBAClC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,UAAU,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the runner's post-sync manifest upload tail step (US-004).
|
|
3
|
+
*
|
|
4
|
+
* These drive `runPostSyncManifestUploads` directly — the runner's own
|
|
5
|
+
* integration with it (only after a clean pass, never affecting the exit code)
|
|
6
|
+
* is asserted in `sync-runner.test.ts`. The throttle test deliberately uses the
|
|
7
|
+
* REAL `runManifestUploadPass` against a temp HQ root, because "two passes in
|
|
8
|
+
* one day upload once" is a property of the wiring plus the seam, not of a
|
|
9
|
+
* stub.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=sync-runner-manifest.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-runner-manifest.test.d.ts","sourceRoot":"","sources":["../../src/bin/sync-runner-manifest.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|