@indigoai-us/hq-cloud 5.32.0 → 5.33.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/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +10 -18
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +27 -3
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/share.test.js +26 -6
- package/dist/cli/share.test.js.map +1 -1
- package/dist/cli/sync.js +1 -1
- package/dist/cli/sync.js.map +1 -1
- package/dist/lib/conflict-file.d.ts +7 -6
- package/dist/lib/conflict-file.d.ts.map +1 -1
- package/dist/lib/conflict-file.js +7 -27
- package/dist/lib/conflict-file.js.map +1 -1
- package/dist/lib/conflict.test.d.ts +4 -3
- package/dist/lib/conflict.test.d.ts.map +1 -1
- package/dist/lib/conflict.test.js +5 -33
- package/dist/lib/conflict.test.js.map +1 -1
- package/dist/lib/machine-id.d.ts +108 -0
- package/dist/lib/machine-id.d.ts.map +1 -0
- package/dist/lib/machine-id.js +170 -0
- package/dist/lib/machine-id.js.map +1 -0
- package/dist/lib/machine-id.test.d.ts +8 -0
- package/dist/lib/machine-id.test.d.ts.map +1 -0
- package/dist/lib/machine-id.test.js +195 -0
- package/dist/lib/machine-id.test.js.map +1 -0
- package/package.json +1 -1
- package/src/bin/sync-runner.ts +10 -16
- package/src/cli/share.test.ts +26 -6
- package/src/cli/share.ts +27 -3
- package/src/cli/sync.ts +1 -1
- package/src/lib/conflict-file.ts +7 -27
- package/src/lib/conflict.test.ts +4 -40
- package/src/lib/machine-id.test.ts +221 -0
- package/src/lib/machine-id.ts +175 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conflict.test.js","sourceRoot":"","sources":["../../src/lib/conflict.test.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"conflict.test.js","sourceRoot":"","sources":["../../src/lib/con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**
|
|
2
|
+
* Machine-ID provisioning — owns the per-host identity used to attribute
|
|
3
|
+
* conflict mirrors, telemetry rows, and `.hq-conflicts/index.json` entries.
|
|
4
|
+
*
|
|
5
|
+
* Historically the menubar app (`indigoai-us/hq-sync`) was the sole writer
|
|
6
|
+
* of `machineId` via `~/.hq/menubar.json`, and every other sync caller
|
|
7
|
+
* best-effort read from there. That arrangement is backwards: hq-cloud is
|
|
8
|
+
* the engine that runs on every sync host (macOS-with-menubar, macOS CLI,
|
|
9
|
+
* Linux HQ Pro Outposts, future Windows), while the menubar is an optional
|
|
10
|
+
* macOS-only UI. Linux outposts therefore had no menubar.json, so
|
|
11
|
+
* `readShortMachineId()` returned the literal string `"unknown"` and
|
|
12
|
+
* every conflict file on those hosts was tagged `-unknown` (which then
|
|
13
|
+
* also slipped past `EPHEMERAL_PATH_PATTERN` in `src/cli/share.ts` — see
|
|
14
|
+
* Fix 2 — and rode S3 round-trips as a regular file).
|
|
15
|
+
*
|
|
16
|
+
* This module flips ownership: hq-cloud provisions a UUID on first call
|
|
17
|
+
* and persists it to `<hqRoot>/.hq/machine-id` (one line, plain text).
|
|
18
|
+
* Every subsequent call hits the persisted file. Existing macOS installs
|
|
19
|
+
* with menubar-written IDs are migrated forward on first call: tier 3
|
|
20
|
+
* picks up the menubar.json value, writes it to `<hqRoot>/.hq/machine-id`,
|
|
21
|
+
* and returns it — so the id is stable across the migration window.
|
|
22
|
+
*
|
|
23
|
+
* Resolution order (first hit wins, every miss falls through):
|
|
24
|
+
* 1. `process.env.HQ_MACHINE_ID` — explicit override for CI / tests.
|
|
25
|
+
* 2. `<hqRoot>/.hq/machine-id` — source-of-truth on the host.
|
|
26
|
+
* 3. `~/.hq/menubar.json` `machineId` field — back-compat for existing
|
|
27
|
+
* macOS installs; migrated forward to tier 2 on first read.
|
|
28
|
+
* 4. Autogen — write a fresh UUID to `<hqRoot>/.hq/machine-id` and return.
|
|
29
|
+
*
|
|
30
|
+
* Concurrent autogen race is benign: two writers each pick a fresh UUID,
|
|
31
|
+
* last-writer-wins on disk, both processes re-read the now-stable file on
|
|
32
|
+
* their next call. The window is narrow (single sync run startup) and the
|
|
33
|
+
* downside (one extra conflict-file rename across a single race window) is
|
|
34
|
+
* trivial compared to the litter-ratchet bug it replaces.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Path to `~/.hq/menubar.json`. Evaluated lazily at call time (not module
|
|
38
|
+
* load) so tests overriding `HOME` post-import see the right file. Going
|
|
39
|
+
* through `os.homedir()` rather than `process.env.HOME` keeps the Windows
|
|
40
|
+
* USERPROFILE fallback intact.
|
|
41
|
+
*/
|
|
42
|
+
declare function menubarJsonPath(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Path to `<hqRoot>/.hq/machine-id` — the source-of-truth file.
|
|
45
|
+
*/
|
|
46
|
+
declare function hqRootMachineIdPath(hqRoot: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Read the persisted id from `<hqRoot>/.hq/machine-id`, or undefined if
|
|
49
|
+
* absent/unreadable/empty. Trims trailing whitespace so manual edits with
|
|
50
|
+
* a final newline don't break attribution.
|
|
51
|
+
*/
|
|
52
|
+
declare function readHqRootMachineId(hqRoot: string): string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Read the menubar-written id from `~/.hq/menubar.json`, or undefined if
|
|
55
|
+
* the file is missing / unreadable / doesn't contain a string `machineId`.
|
|
56
|
+
*/
|
|
57
|
+
declare function readMenubarMachineId(): string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Persist `id` to `<hqRoot>/.hq/machine-id`. Best-effort — failures are
|
|
60
|
+
* silent so a read-only hqRoot (e.g. a CI mount) still gets a working id
|
|
61
|
+
* for the current process, even if it can't be persisted for the next run.
|
|
62
|
+
*/
|
|
63
|
+
declare function persistMachineId(hqRoot: string, id: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Resolve or provision the machine id for this host, persisting it to
|
|
66
|
+
* `<hqRoot>/.hq/machine-id` so the result is stable across sync runs.
|
|
67
|
+
*
|
|
68
|
+
* Returns the full id (UUID-shaped on first generation, free-form when
|
|
69
|
+
* migrated from a menubar.json that wrote something non-UUID). Use
|
|
70
|
+
* {@link readShortMachineId} for the 6-char prefix used in conflict
|
|
71
|
+
* filenames.
|
|
72
|
+
*/
|
|
73
|
+
export declare function getOrCreateMachineId(hqRoot: string): string;
|
|
74
|
+
/**
|
|
75
|
+
* Short form (six hex chars) for use in conflict filenames. The short
|
|
76
|
+
* token is what gets stamped into `<orig>.conflict-<ts>-<short>.<ext>` —
|
|
77
|
+
* see `buildConflictPath` in `./conflict-file.ts`.
|
|
78
|
+
*
|
|
79
|
+
* **Always returns `[a-f0-9]{6}`** so the resulting filename matches the
|
|
80
|
+
* `EPHEMERAL_PATH_PATTERN` in `src/cli/share.ts`. Tier 1 (`HQ_MACHINE_ID`)
|
|
81
|
+
* and tier 3 (legacy menubar values) can return arbitrary non-hex strings
|
|
82
|
+
* — e.g. an env override of `"ci-runner-42"` or a menubar-written
|
|
83
|
+
* `"menubar-legacy-id"`. Slicing those raw would produce `ci-run` or
|
|
84
|
+
* `menuba`, which the ephemeral filter would refuse and the push walker
|
|
85
|
+
* would round-trip to S3 — the exact litter-ratchet bug this module
|
|
86
|
+
* exists to close.
|
|
87
|
+
*
|
|
88
|
+
* Normalization: if the first 6 chars of the resolved id are all hex
|
|
89
|
+
* (the typical UUID / hex-id case), use them as-is so the short token
|
|
90
|
+
* remains an intuitive prefix of the full id. Otherwise derive a
|
|
91
|
+
* deterministic SHA-1 hash of the full id and take the first 6 chars —
|
|
92
|
+
* stable across calls, attributable to the same machine, always hex.
|
|
93
|
+
*/
|
|
94
|
+
export declare function readShortMachineId(hqRoot: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* Test-only exports. Mirrors the `_testing` namespace pattern used by
|
|
97
|
+
* `src/cli/share.ts` so regression-critical helpers can be pinned by
|
|
98
|
+
* direct unit tests without round-tripping through the public API.
|
|
99
|
+
*/
|
|
100
|
+
export declare const _testing: {
|
|
101
|
+
menubarJsonPath: typeof menubarJsonPath;
|
|
102
|
+
hqRootMachineIdPath: typeof hqRootMachineIdPath;
|
|
103
|
+
readHqRootMachineId: typeof readHqRootMachineId;
|
|
104
|
+
readMenubarMachineId: typeof readMenubarMachineId;
|
|
105
|
+
persistMachineId: typeof persistMachineId;
|
|
106
|
+
};
|
|
107
|
+
export {};
|
|
108
|
+
//# sourceMappingURL=machine-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine-id.d.ts","sourceRoot":"","sources":["../../src/lib/machine-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAOH;;;;;GAKG;AACH,iBAAS,eAAe,IAAI,MAAM,CAEjC;AAED;;GAEG;AACH,iBAAS,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;GAIG;AACH,iBAAS,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAO/D;AAED;;;GAGG;AACH,iBAAS,oBAAoB,IAAI,MAAM,GAAG,SAAS,CAWlD;AAED;;;;GAIG;AACH,iBAAS,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAQ1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAqB3D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKzD;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAC"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Machine-ID provisioning — owns the per-host identity used to attribute
|
|
3
|
+
* conflict mirrors, telemetry rows, and `.hq-conflicts/index.json` entries.
|
|
4
|
+
*
|
|
5
|
+
* Historically the menubar app (`indigoai-us/hq-sync`) was the sole writer
|
|
6
|
+
* of `machineId` via `~/.hq/menubar.json`, and every other sync caller
|
|
7
|
+
* best-effort read from there. That arrangement is backwards: hq-cloud is
|
|
8
|
+
* the engine that runs on every sync host (macOS-with-menubar, macOS CLI,
|
|
9
|
+
* Linux HQ Pro Outposts, future Windows), while the menubar is an optional
|
|
10
|
+
* macOS-only UI. Linux outposts therefore had no menubar.json, so
|
|
11
|
+
* `readShortMachineId()` returned the literal string `"unknown"` and
|
|
12
|
+
* every conflict file on those hosts was tagged `-unknown` (which then
|
|
13
|
+
* also slipped past `EPHEMERAL_PATH_PATTERN` in `src/cli/share.ts` — see
|
|
14
|
+
* Fix 2 — and rode S3 round-trips as a regular file).
|
|
15
|
+
*
|
|
16
|
+
* This module flips ownership: hq-cloud provisions a UUID on first call
|
|
17
|
+
* and persists it to `<hqRoot>/.hq/machine-id` (one line, plain text).
|
|
18
|
+
* Every subsequent call hits the persisted file. Existing macOS installs
|
|
19
|
+
* with menubar-written IDs are migrated forward on first call: tier 3
|
|
20
|
+
* picks up the menubar.json value, writes it to `<hqRoot>/.hq/machine-id`,
|
|
21
|
+
* and returns it — so the id is stable across the migration window.
|
|
22
|
+
*
|
|
23
|
+
* Resolution order (first hit wins, every miss falls through):
|
|
24
|
+
* 1. `process.env.HQ_MACHINE_ID` — explicit override for CI / tests.
|
|
25
|
+
* 2. `<hqRoot>/.hq/machine-id` — source-of-truth on the host.
|
|
26
|
+
* 3. `~/.hq/menubar.json` `machineId` field — back-compat for existing
|
|
27
|
+
* macOS installs; migrated forward to tier 2 on first read.
|
|
28
|
+
* 4. Autogen — write a fresh UUID to `<hqRoot>/.hq/machine-id` and return.
|
|
29
|
+
*
|
|
30
|
+
* Concurrent autogen race is benign: two writers each pick a fresh UUID,
|
|
31
|
+
* last-writer-wins on disk, both processes re-read the now-stable file on
|
|
32
|
+
* their next call. The window is narrow (single sync run startup) and the
|
|
33
|
+
* downside (one extra conflict-file rename across a single race window) is
|
|
34
|
+
* trivial compared to the litter-ratchet bug it replaces.
|
|
35
|
+
*/
|
|
36
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
37
|
+
import * as fs from "node:fs";
|
|
38
|
+
import * as os from "node:os";
|
|
39
|
+
import * as path from "node:path";
|
|
40
|
+
/**
|
|
41
|
+
* Path to `~/.hq/menubar.json`. Evaluated lazily at call time (not module
|
|
42
|
+
* load) so tests overriding `HOME` post-import see the right file. Going
|
|
43
|
+
* through `os.homedir()` rather than `process.env.HOME` keeps the Windows
|
|
44
|
+
* USERPROFILE fallback intact.
|
|
45
|
+
*/
|
|
46
|
+
function menubarJsonPath() {
|
|
47
|
+
return path.join(os.homedir(), ".hq", "menubar.json");
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Path to `<hqRoot>/.hq/machine-id` — the source-of-truth file.
|
|
51
|
+
*/
|
|
52
|
+
function hqRootMachineIdPath(hqRoot) {
|
|
53
|
+
return path.join(hqRoot, ".hq", "machine-id");
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Read the persisted id from `<hqRoot>/.hq/machine-id`, or undefined if
|
|
57
|
+
* absent/unreadable/empty. Trims trailing whitespace so manual edits with
|
|
58
|
+
* a final newline don't break attribution.
|
|
59
|
+
*/
|
|
60
|
+
function readHqRootMachineId(hqRoot) {
|
|
61
|
+
try {
|
|
62
|
+
const raw = fs.readFileSync(hqRootMachineIdPath(hqRoot), "utf-8").trim();
|
|
63
|
+
return raw.length > 0 ? raw : undefined;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Read the menubar-written id from `~/.hq/menubar.json`, or undefined if
|
|
71
|
+
* the file is missing / unreadable / doesn't contain a string `machineId`.
|
|
72
|
+
*/
|
|
73
|
+
function readMenubarMachineId() {
|
|
74
|
+
try {
|
|
75
|
+
const raw = fs.readFileSync(menubarJsonPath(), "utf-8");
|
|
76
|
+
const parsed = JSON.parse(raw);
|
|
77
|
+
if (typeof parsed.machineId === "string" && parsed.machineId.length > 0) {
|
|
78
|
+
return parsed.machineId;
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Persist `id` to `<hqRoot>/.hq/machine-id`. Best-effort — failures are
|
|
88
|
+
* silent so a read-only hqRoot (e.g. a CI mount) still gets a working id
|
|
89
|
+
* for the current process, even if it can't be persisted for the next run.
|
|
90
|
+
*/
|
|
91
|
+
function persistMachineId(hqRoot, id) {
|
|
92
|
+
try {
|
|
93
|
+
fs.mkdirSync(path.join(hqRoot, ".hq"), { recursive: true });
|
|
94
|
+
fs.writeFileSync(hqRootMachineIdPath(hqRoot), `${id}\n`);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Read-only filesystem or permission issue — caller gets the id back
|
|
98
|
+
// anyway. Next sync run will retry the persist.
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Resolve or provision the machine id for this host, persisting it to
|
|
103
|
+
* `<hqRoot>/.hq/machine-id` so the result is stable across sync runs.
|
|
104
|
+
*
|
|
105
|
+
* Returns the full id (UUID-shaped on first generation, free-form when
|
|
106
|
+
* migrated from a menubar.json that wrote something non-UUID). Use
|
|
107
|
+
* {@link readShortMachineId} for the 6-char prefix used in conflict
|
|
108
|
+
* filenames.
|
|
109
|
+
*/
|
|
110
|
+
export function getOrCreateMachineId(hqRoot) {
|
|
111
|
+
// Tier 1: env override.
|
|
112
|
+
const fromEnv = process.env.HQ_MACHINE_ID;
|
|
113
|
+
if (fromEnv && fromEnv.length > 0)
|
|
114
|
+
return fromEnv;
|
|
115
|
+
// Tier 2: persisted source-of-truth.
|
|
116
|
+
const persisted = readHqRootMachineId(hqRoot);
|
|
117
|
+
if (persisted)
|
|
118
|
+
return persisted;
|
|
119
|
+
// Tier 3: back-compat read of menubar.json. Migrate forward on first hit
|
|
120
|
+
// so subsequent calls take tier 2 and the menubar dependency drops out.
|
|
121
|
+
const fromMenubar = readMenubarMachineId();
|
|
122
|
+
if (fromMenubar) {
|
|
123
|
+
persistMachineId(hqRoot, fromMenubar);
|
|
124
|
+
return fromMenubar;
|
|
125
|
+
}
|
|
126
|
+
// Tier 4: autogen + persist.
|
|
127
|
+
const fresh = randomUUID();
|
|
128
|
+
persistMachineId(hqRoot, fresh);
|
|
129
|
+
return fresh;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Short form (six hex chars) for use in conflict filenames. The short
|
|
133
|
+
* token is what gets stamped into `<orig>.conflict-<ts>-<short>.<ext>` —
|
|
134
|
+
* see `buildConflictPath` in `./conflict-file.ts`.
|
|
135
|
+
*
|
|
136
|
+
* **Always returns `[a-f0-9]{6}`** so the resulting filename matches the
|
|
137
|
+
* `EPHEMERAL_PATH_PATTERN` in `src/cli/share.ts`. Tier 1 (`HQ_MACHINE_ID`)
|
|
138
|
+
* and tier 3 (legacy menubar values) can return arbitrary non-hex strings
|
|
139
|
+
* — e.g. an env override of `"ci-runner-42"` or a menubar-written
|
|
140
|
+
* `"menubar-legacy-id"`. Slicing those raw would produce `ci-run` or
|
|
141
|
+
* `menuba`, which the ephemeral filter would refuse and the push walker
|
|
142
|
+
* would round-trip to S3 — the exact litter-ratchet bug this module
|
|
143
|
+
* exists to close.
|
|
144
|
+
*
|
|
145
|
+
* Normalization: if the first 6 chars of the resolved id are all hex
|
|
146
|
+
* (the typical UUID / hex-id case), use them as-is so the short token
|
|
147
|
+
* remains an intuitive prefix of the full id. Otherwise derive a
|
|
148
|
+
* deterministic SHA-1 hash of the full id and take the first 6 chars —
|
|
149
|
+
* stable across calls, attributable to the same machine, always hex.
|
|
150
|
+
*/
|
|
151
|
+
export function readShortMachineId(hqRoot) {
|
|
152
|
+
const full = getOrCreateMachineId(hqRoot);
|
|
153
|
+
const head = full.slice(0, 6);
|
|
154
|
+
if (/^[a-f0-9]{6}$/.test(head))
|
|
155
|
+
return head;
|
|
156
|
+
return createHash("sha1").update(full).digest("hex").slice(0, 6);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Test-only exports. Mirrors the `_testing` namespace pattern used by
|
|
160
|
+
* `src/cli/share.ts` so regression-critical helpers can be pinned by
|
|
161
|
+
* direct unit tests without round-tripping through the public API.
|
|
162
|
+
*/
|
|
163
|
+
export const _testing = {
|
|
164
|
+
menubarJsonPath,
|
|
165
|
+
hqRootMachineIdPath,
|
|
166
|
+
readHqRootMachineId,
|
|
167
|
+
readMenubarMachineId,
|
|
168
|
+
persistMachineId,
|
|
169
|
+
};
|
|
170
|
+
//# sourceMappingURL=machine-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine-id.js","sourceRoot":"","sources":["../../src/lib/machine-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC;;;;;GAKG;AACH,SAAS,eAAe;IACtB,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB,CAAC,MAAc;IACzC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;AAChD,CAAC;AAED;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,MAAc;IACzC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,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AO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC;IAElD,qCAAqC;IACrC,MAAM,SAAS,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC9C,IAAI,SAAS;QAAE,OAAO,SAAS,CAAC;IAEhC,yEAAyE;IACzE,wEAAwE;IACxE,MAAM,WAAW,GAAG,oBAAoB,EAAE,CAAC;IAC3C,IAAI,WAAW,EAAE,CAAC;QAChB,gBAAgB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QACtC,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,6BAA6B;IAC7B,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC;IAC3B,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAChC,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,MAAM,IAAI,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9B,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5C,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACnE,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,eAAe;IACf,mBAAmB;IACnB,mBAAmB;IACnB,oBAAoB;IACpB,gBAAgB;CACjB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Machine-ID resolver tests. Pins the four-tier fallback contract so a
|
|
3
|
+
* regression in tier ordering, the migration-forward behavior, or the
|
|
4
|
+
* "unknown sentinel is no longer reachable" invariant is caught at build
|
|
5
|
+
* time rather than re-litigating it on a user's Lightsail outpost.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=machine-id.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine-id.test.d.ts","sourceRoot":"","sources":["../../src/lib/machine-id.test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Machine-ID resolver tests. Pins the four-tier fallback contract so a
|
|
3
|
+
* regression in tier ordering, the migration-forward behavior, or the
|
|
4
|
+
* "unknown sentinel is no longer reachable" invariant is caught at build
|
|
5
|
+
* time rather than re-litigating it on a user's Lightsail outpost.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
8
|
+
import * as fs from "fs";
|
|
9
|
+
import * as os from "os";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import { getOrCreateMachineId, readShortMachineId } from "./machine-id.js";
|
|
12
|
+
function freshTmp(prefix) {
|
|
13
|
+
return fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
14
|
+
}
|
|
15
|
+
describe("getOrCreateMachineId (four-tier resolver)", () => {
|
|
16
|
+
let originalHome;
|
|
17
|
+
let originalEnvId;
|
|
18
|
+
let tmpHome;
|
|
19
|
+
let tmpHqRoot;
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
originalHome = process.env.HOME;
|
|
22
|
+
originalEnvId = process.env.HQ_MACHINE_ID;
|
|
23
|
+
delete process.env.HQ_MACHINE_ID;
|
|
24
|
+
tmpHome = freshTmp("hq-machineid-home-");
|
|
25
|
+
tmpHqRoot = freshTmp("hq-machineid-root-");
|
|
26
|
+
process.env.HOME = tmpHome;
|
|
27
|
+
});
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
if (originalHome)
|
|
30
|
+
process.env.HOME = originalHome;
|
|
31
|
+
else
|
|
32
|
+
delete process.env.HOME;
|
|
33
|
+
if (originalEnvId !== undefined)
|
|
34
|
+
process.env.HQ_MACHINE_ID = originalEnvId;
|
|
35
|
+
else
|
|
36
|
+
delete process.env.HQ_MACHINE_ID;
|
|
37
|
+
fs.rmSync(tmpHome, { recursive: true, force: true });
|
|
38
|
+
fs.rmSync(tmpHqRoot, { recursive: true, force: true });
|
|
39
|
+
});
|
|
40
|
+
// ── tier 1: HQ_MACHINE_ID env override ────────────────────────────────
|
|
41
|
+
it("tier 1: returns HQ_MACHINE_ID env when set, ignoring lower tiers", () => {
|
|
42
|
+
process.env.HQ_MACHINE_ID = "env-override-id";
|
|
43
|
+
// Even if a persisted file exists, env wins.
|
|
44
|
+
fs.mkdirSync(path.join(tmpHqRoot, ".hq"), { recursive: true });
|
|
45
|
+
fs.writeFileSync(path.join(tmpHqRoot, ".hq", "machine-id"), "persisted\n");
|
|
46
|
+
expect(getOrCreateMachineId(tmpHqRoot)).toBe("env-override-id");
|
|
47
|
+
// Env-only resolution must not clobber the on-disk source-of-truth.
|
|
48
|
+
expect(fs.readFileSync(path.join(tmpHqRoot, ".hq", "machine-id"), "utf-8").trim()).toBe("persisted");
|
|
49
|
+
});
|
|
50
|
+
// ── tier 2: <hqRoot>/.hq/machine-id ───────────────────────────────────
|
|
51
|
+
it("tier 2: returns the trimmed contents of <hqRoot>/.hq/machine-id", () => {
|
|
52
|
+
fs.mkdirSync(path.join(tmpHqRoot, ".hq"), { recursive: true });
|
|
53
|
+
fs.writeFileSync(path.join(tmpHqRoot, ".hq", "machine-id"), " abc-123-persisted \n\n");
|
|
54
|
+
expect(getOrCreateMachineId(tmpHqRoot)).toBe("abc-123-persisted");
|
|
55
|
+
});
|
|
56
|
+
it("tier 2: empty machine-id file falls through to autogen", () => {
|
|
57
|
+
fs.mkdirSync(path.join(tmpHqRoot, ".hq"), { recursive: true });
|
|
58
|
+
fs.writeFileSync(path.join(tmpHqRoot, ".hq", "machine-id"), "");
|
|
59
|
+
const id = getOrCreateMachineId(tmpHqRoot);
|
|
60
|
+
// UUID v4 shape.
|
|
61
|
+
expect(id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
|
|
62
|
+
// Persisted on disk for next call.
|
|
63
|
+
expect(fs.readFileSync(path.join(tmpHqRoot, ".hq", "machine-id"), "utf-8").trim()).toBe(id);
|
|
64
|
+
});
|
|
65
|
+
// ── tier 3: ~/.hq/menubar.json (legacy, migrated forward) ─────────────
|
|
66
|
+
it("tier 3: reads menubar.json AND migrates the value into <hqRoot>/.hq/machine-id", () => {
|
|
67
|
+
fs.mkdirSync(path.join(tmpHome, ".hq"), { recursive: true });
|
|
68
|
+
fs.writeFileSync(path.join(tmpHome, ".hq", "menubar.json"), JSON.stringify({ machineId: "menubar-legacy-id" }));
|
|
69
|
+
expect(getOrCreateMachineId(tmpHqRoot)).toBe("menubar-legacy-id");
|
|
70
|
+
// Migrated forward — subsequent calls now hit tier 2.
|
|
71
|
+
expect(fs.readFileSync(path.join(tmpHqRoot, ".hq", "machine-id"), "utf-8").trim()).toBe("menubar-legacy-id");
|
|
72
|
+
});
|
|
73
|
+
it("tier 3: malformed menubar.json falls through to autogen", () => {
|
|
74
|
+
fs.mkdirSync(path.join(tmpHome, ".hq"), { recursive: true });
|
|
75
|
+
fs.writeFileSync(path.join(tmpHome, ".hq", "menubar.json"), "{not-json");
|
|
76
|
+
const id = getOrCreateMachineId(tmpHqRoot);
|
|
77
|
+
expect(id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
|
|
78
|
+
});
|
|
79
|
+
it("tier 3: menubar.json without a machineId field falls through to autogen", () => {
|
|
80
|
+
fs.mkdirSync(path.join(tmpHome, ".hq"), { recursive: true });
|
|
81
|
+
fs.writeFileSync(path.join(tmpHome, ".hq", "menubar.json"), JSON.stringify({ telemetryEnabled: true }));
|
|
82
|
+
const id = getOrCreateMachineId(tmpHqRoot);
|
|
83
|
+
expect(id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
|
|
84
|
+
});
|
|
85
|
+
// ── tier 4: autogen + persist ─────────────────────────────────────────
|
|
86
|
+
it("tier 4: generates a UUID and persists it for the next call", () => {
|
|
87
|
+
const id = getOrCreateMachineId(tmpHqRoot);
|
|
88
|
+
expect(id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
|
|
89
|
+
expect(fs.readFileSync(path.join(tmpHqRoot, ".hq", "machine-id"), "utf-8").trim()).toBe(id);
|
|
90
|
+
// Stable across calls.
|
|
91
|
+
expect(getOrCreateMachineId(tmpHqRoot)).toBe(id);
|
|
92
|
+
});
|
|
93
|
+
it("tier 4: stays in-process even if hqRoot is read-only (best-effort persist)", () => {
|
|
94
|
+
// Pre-create .hq as a regular dir, then strip write perms.
|
|
95
|
+
fs.mkdirSync(path.join(tmpHqRoot, ".hq"), { recursive: true });
|
|
96
|
+
fs.chmodSync(path.join(tmpHqRoot, ".hq"), 0o500); // r-x only
|
|
97
|
+
try {
|
|
98
|
+
const id = getOrCreateMachineId(tmpHqRoot);
|
|
99
|
+
expect(id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
fs.chmodSync(path.join(tmpHqRoot, ".hq"), 0o700);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
// ── invariant: "unknown" sentinel is unreachable ──────────────────────
|
|
106
|
+
it("never returns the legacy 'unknown' sentinel — every host gets a real id", () => {
|
|
107
|
+
// No env, no persisted file, no menubar.json — pure tier-4 path.
|
|
108
|
+
const id = getOrCreateMachineId(tmpHqRoot);
|
|
109
|
+
expect(id).not.toBe("unknown");
|
|
110
|
+
expect(id.length).toBeGreaterThan(6);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe("readShortMachineId", () => {
|
|
114
|
+
let originalHome;
|
|
115
|
+
let originalEnvId;
|
|
116
|
+
let tmpHome;
|
|
117
|
+
let tmpHqRoot;
|
|
118
|
+
beforeEach(() => {
|
|
119
|
+
originalHome = process.env.HOME;
|
|
120
|
+
originalEnvId = process.env.HQ_MACHINE_ID;
|
|
121
|
+
delete process.env.HQ_MACHINE_ID;
|
|
122
|
+
tmpHome = freshTmp("hq-machineid-short-home-");
|
|
123
|
+
tmpHqRoot = freshTmp("hq-machineid-short-root-");
|
|
124
|
+
process.env.HOME = tmpHome;
|
|
125
|
+
});
|
|
126
|
+
afterEach(() => {
|
|
127
|
+
if (originalHome)
|
|
128
|
+
process.env.HOME = originalHome;
|
|
129
|
+
else
|
|
130
|
+
delete process.env.HOME;
|
|
131
|
+
if (originalEnvId !== undefined)
|
|
132
|
+
process.env.HQ_MACHINE_ID = originalEnvId;
|
|
133
|
+
else
|
|
134
|
+
delete process.env.HQ_MACHINE_ID;
|
|
135
|
+
fs.rmSync(tmpHome, { recursive: true, force: true });
|
|
136
|
+
fs.rmSync(tmpHqRoot, { recursive: true, force: true });
|
|
137
|
+
});
|
|
138
|
+
it("returns the first 6 chars when the resolved id has a hex prefix", () => {
|
|
139
|
+
process.env.HQ_MACHINE_ID = "deadbeefcafe1234567890";
|
|
140
|
+
expect(readShortMachineId(tmpHqRoot)).toBe("deadbe");
|
|
141
|
+
});
|
|
142
|
+
it("returns the first 6 chars of an autogenerated UUID", () => {
|
|
143
|
+
const short = readShortMachineId(tmpHqRoot);
|
|
144
|
+
expect(short).toHaveLength(6);
|
|
145
|
+
expect(short).toMatch(/^[0-9a-f]{6}$/);
|
|
146
|
+
expect(short).not.toBe("unknow"); // legacy "unknown" prefix — must not reappear
|
|
147
|
+
});
|
|
148
|
+
it("reads the same hex prefix from <hqRoot>/.hq/machine-id when persisted", () => {
|
|
149
|
+
fs.mkdirSync(path.join(tmpHqRoot, ".hq"), { recursive: true });
|
|
150
|
+
fs.writeFileSync(path.join(tmpHqRoot, ".hq", "machine-id"), "abcdef-rest-can-be-anything");
|
|
151
|
+
expect(readShortMachineId(tmpHqRoot)).toBe("abcdef");
|
|
152
|
+
});
|
|
153
|
+
// ── normalization invariant: short token is ALWAYS [a-f0-9]{6} ────────
|
|
154
|
+
//
|
|
155
|
+
// Regression coverage for the Codex-flagged P2 — without this, a
|
|
156
|
+
// non-hex `HQ_MACHINE_ID` or legacy menubar value (e.g. "ci-runner-42",
|
|
157
|
+
// "menubar-legacy-id") would slice to a non-hex 6-char prefix, the
|
|
158
|
+
// conflict filename would carry that non-hex token, and the
|
|
159
|
+
// `EPHEMERAL_PATH_PATTERN` in `src/cli/share.ts` (which only accepts
|
|
160
|
+
// `[a-f0-9]+` or the literal `unknown`) would refuse it, restoring the
|
|
161
|
+
// exact litter-ratchet loop this module exists to close.
|
|
162
|
+
it.each([
|
|
163
|
+
// Tier-1 env override with non-hex characters.
|
|
164
|
+
["ci-runner-42"],
|
|
165
|
+
["env-override-id"],
|
|
166
|
+
// Tier-3 legacy menubar value with non-hex characters.
|
|
167
|
+
["menubar-legacy-id"],
|
|
168
|
+
// Mixed-case that contains non-hex letters in the first 6 chars.
|
|
169
|
+
["Gabc12-rest"],
|
|
170
|
+
// First 6 chars are hex but contain uppercase (regex is case-sensitive).
|
|
171
|
+
["ABCDEF-rest"],
|
|
172
|
+
])("normalizes non-hex source ids to a hex token: %s", (sourceId) => {
|
|
173
|
+
process.env.HQ_MACHINE_ID = sourceId;
|
|
174
|
+
const short = readShortMachineId(tmpHqRoot);
|
|
175
|
+
expect(short).toMatch(/^[a-f0-9]{6}$/);
|
|
176
|
+
expect(short).toHaveLength(6);
|
|
177
|
+
});
|
|
178
|
+
it("normalization is deterministic — same source id always yields same short token", () => {
|
|
179
|
+
process.env.HQ_MACHINE_ID = "menubar-legacy-id";
|
|
180
|
+
const a = readShortMachineId(tmpHqRoot);
|
|
181
|
+
const b = readShortMachineId(tmpHqRoot);
|
|
182
|
+
expect(a).toBe(b);
|
|
183
|
+
expect(a).toMatch(/^[a-f0-9]{6}$/);
|
|
184
|
+
});
|
|
185
|
+
it("normalization distinguishes different source ids", () => {
|
|
186
|
+
process.env.HQ_MACHINE_ID = "menubar-legacy-id";
|
|
187
|
+
const a = readShortMachineId(tmpHqRoot);
|
|
188
|
+
process.env.HQ_MACHINE_ID = "ci-runner-42";
|
|
189
|
+
const b = readShortMachineId(tmpHqRoot);
|
|
190
|
+
expect(a).not.toBe(b);
|
|
191
|
+
expect(a).toMatch(/^[a-f0-9]{6}$/);
|
|
192
|
+
expect(b).toMatch(/^[a-f0-9]{6}$/);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
//# sourceMappingURL=machine-id.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine-id.test.js","sourceRoot":"","sources":["../../src/lib/machine-id.test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE3E,SAAS,QAAQ,CAAC,MAAc;IAC9B,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,QAAQ,CAAC,2CAA2C,EAAE,GAAG,EAAE;IACzD,IAAI,YAAgC,CAAC;IACrC,IAAI,aAAiC,CAAC;IACtC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AM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,OAAO,CAAC,GAAG,CAAC,aAAa,GAAG,mBAAmB,CAAC;QAChD,MAAM,CAAC,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,aAAa,GAAG,cAAc,CAAC;QAC3C,MAAM,CAAC,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACxC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QACnC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/bin/sync-runner.ts
CHANGED
|
@@ -89,6 +89,7 @@ import type { ConflictStrategy } from "../cli/conflict.js";
|
|
|
89
89
|
import type { UploadAuthor } from "../s3.js";
|
|
90
90
|
import { collectAndSendTelemetry } from "../telemetry.js";
|
|
91
91
|
import { describeError } from "../lib/describe-error.js";
|
|
92
|
+
import { getOrCreateMachineId } from "../lib/machine-id.js";
|
|
92
93
|
import {
|
|
93
94
|
TreeWatcher,
|
|
94
95
|
WatchPushDriver,
|
|
@@ -593,24 +594,17 @@ function parseArgs(argv: string[]): ParsedArgs | { error: string } {
|
|
|
593
594
|
async function defaultCollectTelemetry(
|
|
594
595
|
client: VaultClientSurface,
|
|
595
596
|
clientIsStub: boolean,
|
|
597
|
+
hqRoot: string,
|
|
596
598
|
): Promise<void> {
|
|
597
599
|
if (clientIsStub) return;
|
|
598
600
|
try {
|
|
599
|
-
// machineId:
|
|
600
|
-
//
|
|
601
|
-
//
|
|
602
|
-
//
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
const raw = await fs.promises.readFile(menubarPath, "utf-8");
|
|
607
|
-
const parsed = JSON.parse(raw) as { machineId?: unknown };
|
|
608
|
-
if (typeof parsed.machineId === "string" && parsed.machineId.length > 0) {
|
|
609
|
-
machineId = parsed.machineId;
|
|
610
|
-
}
|
|
611
|
-
} catch {
|
|
612
|
-
// No menubar.json — proceed with "unknown".
|
|
613
|
-
}
|
|
601
|
+
// machineId: hq-cloud owns provisioning via `<hqRoot>/.hq/machine-id`
|
|
602
|
+
// (see `src/lib/machine-id.ts`). The resolver migrates forward from
|
|
603
|
+
// any legacy `~/.hq/menubar.json` value on first call, then becomes
|
|
604
|
+
// self-sufficient. On a clean Linux outpost (no menubar app), a fresh
|
|
605
|
+
// UUID is generated + persisted, so this row is attributable rather
|
|
606
|
+
// than collapsing onto the legacy `"unknown"` sentinel.
|
|
607
|
+
const machineId = getOrCreateMachineId(hqRoot);
|
|
614
608
|
|
|
615
609
|
// installerVersion: callers (the Tauri menubar) set this when spawning
|
|
616
610
|
// the runner so the historical `installerVersion` dimension on
|
|
@@ -1245,7 +1239,7 @@ export async function runRunner(
|
|
|
1245
1239
|
// which naturally bounds the outer wait.
|
|
1246
1240
|
const telemetryFn =
|
|
1247
1241
|
deps.collectTelemetry ??
|
|
1248
|
-
(() => defaultCollectTelemetry(client, deps.createVaultClient !== undefined));
|
|
1242
|
+
(() => defaultCollectTelemetry(client, deps.createVaultClient !== undefined, parsed.hqRoot));
|
|
1249
1243
|
await telemetryFn().catch(() => undefined);
|
|
1250
1244
|
|
|
1251
1245
|
emit({
|