@indigoai-us/hq-cloud 6.16.72-alpha.0 → 6.16.72
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-watch-loop.d.ts +5 -35
- package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
- package/dist/bin/sync-runner-watch-loop.js +32 -156
- package/dist/bin/sync-runner-watch-loop.js.map +1 -1
- package/dist/bin/sync-runner.test.js +12 -96
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/rescue-breaker.test.js +94 -1
- package/dist/cli/rescue-breaker.test.js.map +1 -1
- package/dist/cli/rescue-classify-ordering.test.js +1 -1
- package/dist/cli/rescue-clone-network-retry.test.d.ts +2 -0
- package/dist/cli/rescue-clone-network-retry.test.d.ts.map +1 -0
- package/dist/cli/rescue-clone-network-retry.test.js +415 -0
- package/dist/cli/rescue-clone-network-retry.test.js.map +1 -0
- package/dist/cli/rescue-core.d.ts +12 -5
- package/dist/cli/rescue-core.d.ts.map +1 -1
- package/dist/cli/rescue-core.js +685 -93
- package/dist/cli/rescue-core.js.map +1 -1
- package/dist/cli/rescue-drift-reconcile.test.js +1 -1
- package/dist/cli/rescue-drop-dir-symlink.test.js +1 -1
- package/dist/cli/rescue-exec-bit-preserve.test.js +1 -1
- package/dist/cli/rescue-hq-root-guard.test.js +1 -1
- package/dist/cli/rescue-journal-reconcile.test.js +1 -1
- package/dist/cli/rescue-keep-local-ignore.test.js +2 -2
- package/dist/cli/rescue-move.test.d.ts +2 -0
- package/dist/cli/rescue-move.test.d.ts.map +1 -0
- package/dist/cli/rescue-move.test.js +162 -0
- package/dist/cli/rescue-move.test.js.map +1 -0
- package/dist/cli/rescue-mtime-preserve.test.js +1 -1
- package/dist/cli/rescue-preserve-copy-symlink.test.d.ts +2 -0
- package/dist/cli/rescue-preserve-copy-symlink.test.d.ts.map +1 -0
- package/dist/cli/rescue-preserve-copy-symlink.test.js +338 -0
- package/dist/cli/rescue-preserve-copy-symlink.test.js.map +1 -0
- package/dist/cli/rescue-rsync-preflight.test.js +108 -12
- package/dist/cli/rescue-rsync-preflight.test.js.map +1 -1
- package/dist/cli/rescue-rsync-status.test.d.ts +2 -0
- package/dist/cli/rescue-rsync-status.test.d.ts.map +1 -0
- package/dist/cli/rescue-rsync-status.test.js +199 -0
- package/dist/cli/rescue-rsync-status.test.js.map +1 -0
- package/dist/cli/rescue-settings-reconcile.test.js +2 -2
- package/dist/cli/rescue-snapshot-copy.test.js +1 -1
- package/dist/cli/rescue-snapshot-recovery.test.js +1 -1
- package/dist/cli/rescue-source-switch-floor.test.js +1 -1
- package/package.json +1 -1
|
@@ -112,7 +112,7 @@ describe.skipIf(!gitAvailable)("rescue drift convergence guard", () => {
|
|
|
112
112
|
shimDir = path.join(workDir, "shim");
|
|
113
113
|
fs.mkdirSync(shimDir, { recursive: true });
|
|
114
114
|
const shim = `#!/usr/bin/env bash
|
|
115
|
-
if [ "$1" = "clone" ]; then
|
|
115
|
+
if [ "$1" = "clone" ] || [ "$1" = "ls-remote" ]; then
|
|
116
116
|
args=()
|
|
117
117
|
for a in "$@"; do
|
|
118
118
|
case "$a" in
|
|
@@ -134,7 +134,7 @@ describe.skipIf(!toolsAvailable)("rescue drops directory-target symlinks", () =>
|
|
|
134
134
|
shimDir = path.join(workDir, "shim");
|
|
135
135
|
fs.mkdirSync(shimDir, { recursive: true });
|
|
136
136
|
const shim = `#!/usr/bin/env bash
|
|
137
|
-
if [ "$1" = "clone" ]; then
|
|
137
|
+
if [ "$1" = "clone" ] || [ "$1" = "ls-remote" ]; then
|
|
138
138
|
args=()
|
|
139
139
|
for a in "$@"; do
|
|
140
140
|
case "$a" in
|
|
@@ -126,7 +126,7 @@ describe.skipIf(!toolsAvailable)("rescue restores +x on shipped shebang scripts"
|
|
|
126
126
|
shimDir = path.join(workDir, "shim");
|
|
127
127
|
fs.mkdirSync(shimDir, { recursive: true });
|
|
128
128
|
const shim = `#!/usr/bin/env bash
|
|
129
|
-
if [ "$1" = "clone" ]; then
|
|
129
|
+
if [ "$1" = "clone" ] || [ "$1" = "ls-remote" ]; then
|
|
130
130
|
args=()
|
|
131
131
|
for a in "$@"; do
|
|
132
132
|
case "$a" in
|
|
@@ -95,7 +95,7 @@ describe.skipIf(!gitAvailable)("rescue HQ-root sanity gate", () => {
|
|
|
95
95
|
shimDir = path.join(workDir, "shim");
|
|
96
96
|
fs.mkdirSync(shimDir, { recursive: true });
|
|
97
97
|
const shim = `#!/usr/bin/env bash
|
|
98
|
-
if [ "$1" = "clone" ]; then
|
|
98
|
+
if [ "$1" = "clone" ] || [ "$1" = "ls-remote" ]; then
|
|
99
99
|
args=()
|
|
100
100
|
for a in "$@"; do
|
|
101
101
|
case "$a" in
|
|
@@ -126,7 +126,7 @@ describe.skipIf(!gitAvailable)("rescue leaves the sync journal untouched + stamp
|
|
|
126
126
|
const shimDir = path.join(workDir, "shim");
|
|
127
127
|
fs.mkdirSync(shimDir, { recursive: true });
|
|
128
128
|
fs.writeFileSync(path.join(shimDir, "git"), `#!/usr/bin/env bash
|
|
129
|
-
if [ "$1" = "clone" ]; then
|
|
129
|
+
if [ "$1" = "clone" ] || [ "$1" = "ls-remote" ]; then
|
|
130
130
|
args=(); for a in "$@"; do case "$a" in https://github.com/*) a=${JSON.stringify(upstream)} ;; esac; args+=("$a"); done
|
|
131
131
|
exec ${JSON.stringify(realGit)} "\${args[@]}"
|
|
132
132
|
fi
|
|
@@ -147,7 +147,7 @@ describe.skipIf(!toolsAvailable)("rescue keeps locally-edited root ignore files"
|
|
|
147
147
|
shimDir = path.join(workDir, "shim");
|
|
148
148
|
fs.mkdirSync(shimDir, { recursive: true });
|
|
149
149
|
const shim = `#!/usr/bin/env bash
|
|
150
|
-
if [ "$1" = "clone" ]; then
|
|
150
|
+
if [ "$1" = "clone" ] || [ "$1" = "ls-remote" ]; then
|
|
151
151
|
args=()
|
|
152
152
|
for a in "$@"; do
|
|
153
153
|
case "$a" in
|
|
@@ -269,7 +269,7 @@ describe.skipIf(!toolsAvailable)("rescue keep-local requires a floor-proven edit
|
|
|
269
269
|
const shimDir = path.join(workDir, "shim");
|
|
270
270
|
fs.mkdirSync(shimDir, { recursive: true });
|
|
271
271
|
fs.writeFileSync(path.join(shimDir, "git"), `#!/usr/bin/env bash
|
|
272
|
-
if [ "$1" = "clone" ]; then
|
|
272
|
+
if [ "$1" = "clone" ] || [ "$1" = "ls-remote" ]; then
|
|
273
273
|
args=()
|
|
274
274
|
for a in "$@"; do
|
|
275
275
|
case "$a" in
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rescue-move.test.d.ts","sourceRoot":"","sources":["../../src/cli/rescue-move.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { execFileSync } from "child_process";
|
|
3
|
+
import * as fs from "fs";
|
|
4
|
+
import * as os from "os";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
import { runRescue } from "./rescue-core.js";
|
|
7
|
+
vi.mock("fs", async (importOriginal) => {
|
|
8
|
+
const actual = await importOriginal();
|
|
9
|
+
return { ...actual };
|
|
10
|
+
});
|
|
11
|
+
function has(bin, ...args) {
|
|
12
|
+
try {
|
|
13
|
+
execFileSync(bin, args, { stdio: "ignore" });
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const toolsAvailable = has("git", "--version") && has("rsync", "--version");
|
|
21
|
+
function errnoError(code, syscall, message) {
|
|
22
|
+
const error = new Error(message);
|
|
23
|
+
error.code = code;
|
|
24
|
+
error.syscall = syscall;
|
|
25
|
+
return error;
|
|
26
|
+
}
|
|
27
|
+
function captureRescue(argv, env) {
|
|
28
|
+
let stdout = "";
|
|
29
|
+
let stderr = "";
|
|
30
|
+
const originalOut = process.stdout.write.bind(process.stdout);
|
|
31
|
+
const originalErr = process.stderr.write.bind(process.stderr);
|
|
32
|
+
process.stdout.write = ((chunk) => {
|
|
33
|
+
stdout += String(chunk);
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
process.stderr.write = ((chunk) => {
|
|
37
|
+
stderr += String(chunk);
|
|
38
|
+
return true;
|
|
39
|
+
});
|
|
40
|
+
let status;
|
|
41
|
+
let threw;
|
|
42
|
+
try {
|
|
43
|
+
status = runRescue(argv, { env }).status;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
threw = error;
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
process.stdout.write = originalOut;
|
|
50
|
+
process.stderr.write = originalErr;
|
|
51
|
+
}
|
|
52
|
+
return { status, stdout, stderr, threw };
|
|
53
|
+
}
|
|
54
|
+
describe.skipIf(!toolsAvailable)("rescue move destinations", () => {
|
|
55
|
+
let workDir;
|
|
56
|
+
let hqRoot;
|
|
57
|
+
let upstream;
|
|
58
|
+
let env;
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
workDir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-rescue-move-"));
|
|
61
|
+
hqRoot = path.join(workDir, "hq");
|
|
62
|
+
upstream = path.join(workDir, "upstream");
|
|
63
|
+
fs.mkdirSync(path.join(hqRoot, "companies"), { recursive: true });
|
|
64
|
+
fs.mkdirSync(path.join(hqRoot, "core", "scripts"), { recursive: true });
|
|
65
|
+
fs.mkdirSync(path.join(hqRoot, "personal", "scripts"), { recursive: true });
|
|
66
|
+
fs.writeFileSync(path.join(hqRoot, "core", "scripts", "x.sh"), "local edit\n");
|
|
67
|
+
fs.mkdirSync(path.join(upstream, "core", "scripts"), { recursive: true });
|
|
68
|
+
fs.writeFileSync(path.join(upstream, "core", "scripts", "x.sh"), "release\n");
|
|
69
|
+
execFileSync("git", ["init", "-b", "main", upstream], { stdio: "ignore" });
|
|
70
|
+
execFileSync("git", ["-C", upstream, "add", "."], { stdio: "ignore" });
|
|
71
|
+
execFileSync("git", [
|
|
72
|
+
"-C",
|
|
73
|
+
upstream,
|
|
74
|
+
"-c",
|
|
75
|
+
"user.name=test",
|
|
76
|
+
"-c",
|
|
77
|
+
"user.email=test@example.com",
|
|
78
|
+
"commit",
|
|
79
|
+
"-m",
|
|
80
|
+
"fixture",
|
|
81
|
+
], { stdio: "ignore" });
|
|
82
|
+
const realGit = execFileSync("bash", ["-lc", "command -v git"]).toString().trim();
|
|
83
|
+
const shimDir = path.join(workDir, "bin");
|
|
84
|
+
fs.mkdirSync(shimDir, { recursive: true });
|
|
85
|
+
fs.writeFileSync(path.join(shimDir, "git"), `#!/usr/bin/env bash
|
|
86
|
+
if [ "$1" = "clone" ] || [ "$1" = "ls-remote" ]; then
|
|
87
|
+
args=()
|
|
88
|
+
for arg in "$@"; do
|
|
89
|
+
case "$arg" in
|
|
90
|
+
https://github.com/test/repo.git) arg=${JSON.stringify(upstream)} ;;
|
|
91
|
+
esac
|
|
92
|
+
args+=("$arg")
|
|
93
|
+
done
|
|
94
|
+
exec ${JSON.stringify(realGit)} "\${args[@]}"
|
|
95
|
+
fi
|
|
96
|
+
exec ${JSON.stringify(realGit)} "$@"
|
|
97
|
+
`, { mode: 0o755 });
|
|
98
|
+
env = { ...process.env, PATH: `${shimDir}:${process.env.PATH ?? ""}` };
|
|
99
|
+
});
|
|
100
|
+
afterEach(() => {
|
|
101
|
+
vi.restoreAllMocks();
|
|
102
|
+
fs.rmSync(workDir, { recursive: true, force: true });
|
|
103
|
+
});
|
|
104
|
+
function args() {
|
|
105
|
+
return [
|
|
106
|
+
"--hq-root",
|
|
107
|
+
hqRoot,
|
|
108
|
+
"--source",
|
|
109
|
+
"test/repo",
|
|
110
|
+
"--ref",
|
|
111
|
+
"main",
|
|
112
|
+
"--paths",
|
|
113
|
+
"core",
|
|
114
|
+
"--no-history-check",
|
|
115
|
+
"--no-backup",
|
|
116
|
+
"--yes",
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
it("copies beside an existing non-empty directory and leaves that directory untouched", () => {
|
|
120
|
+
const destination = path.join(hqRoot, "personal", "scripts", "x.sh");
|
|
121
|
+
fs.mkdirSync(destination, { recursive: true });
|
|
122
|
+
fs.writeFileSync(path.join(destination, "keep.txt"), "directory data\n");
|
|
123
|
+
const result = captureRescue(args(), env);
|
|
124
|
+
expect(result.threw, `${result.stdout}\n${result.stderr}`).toBeUndefined();
|
|
125
|
+
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
|
|
126
|
+
expect(fs.readFileSync(path.join(destination, "keep.txt"), "utf8")).toBe("directory data\n");
|
|
127
|
+
const siblings = fs
|
|
128
|
+
.readdirSync(path.dirname(destination))
|
|
129
|
+
.filter((name) => name.startsWith("x.sh.hq-rescue-"));
|
|
130
|
+
expect(siblings).toHaveLength(1);
|
|
131
|
+
expect(fs.readFileSync(path.join(path.dirname(destination), siblings[0]), "utf8")).toBe("local edit\n");
|
|
132
|
+
expect(result.stderr).not.toContain("ENOTEMPTY");
|
|
133
|
+
expect(result.stderr).not.toContain("rescue-move-failed");
|
|
134
|
+
});
|
|
135
|
+
it("falls back to a sibling when the first rename reports ENOTEMPTY", () => {
|
|
136
|
+
const source = path.join(hqRoot, "core", "scripts", "x.sh");
|
|
137
|
+
const destination = path.join(hqRoot, "personal", "scripts", "x.sh");
|
|
138
|
+
const realRenameSync = fs.renameSync;
|
|
139
|
+
let injected = false;
|
|
140
|
+
vi.spyOn(fs, "renameSync").mockImplementation(((from, to) => {
|
|
141
|
+
if (!injected &&
|
|
142
|
+
path.resolve(String(from)) === source &&
|
|
143
|
+
path.resolve(String(to)) === destination) {
|
|
144
|
+
injected = true;
|
|
145
|
+
throw errnoError("ENOTEMPTY", "rename", "directory not empty");
|
|
146
|
+
}
|
|
147
|
+
return realRenameSync(from, to);
|
|
148
|
+
}));
|
|
149
|
+
const result = captureRescue(args(), env);
|
|
150
|
+
expect(result.threw, `${result.stdout}\n${result.stderr}`).toBeUndefined();
|
|
151
|
+
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
|
|
152
|
+
expect(injected).toBe(true);
|
|
153
|
+
expect(fs.readFileSync(source, "utf8")).toBe("release\n");
|
|
154
|
+
const sibling = fs
|
|
155
|
+
.readdirSync(path.dirname(destination))
|
|
156
|
+
.find((name) => name.startsWith("x.sh.hq-rescue-"));
|
|
157
|
+
expect(sibling).toBeDefined();
|
|
158
|
+
expect(fs.readFileSync(path.join(path.dirname(destination), sibling), "utf8")).toBe("local edit\n");
|
|
159
|
+
expect(result.stderr).not.toContain("ENOTEMPTY");
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
//# sourceMappingURL=rescue-move.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rescue-move.test.js","sourceRoot":"","sources":["../../src/cli/rescue-move.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE;IACrC,MAAM,MAAM,GAAG,MAAM,cAAc,EAAuB,CAAC;IAC3D,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,SAAS,GAAG,CAAC,GAAW,EAAE,GAAG,IAAc;IACzC,IAAI,CAAC;QACH,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC7C,OAAO,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AAU,CAAC,iBAAiB,CAAC,CAAC,CAAC;QACtD,MAAM,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;QAC9B,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,OAAQ,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAClF,cAAc,CACf,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -126,7 +126,7 @@ describe.skipIf(!toolsAvailable)("rescue preserves mtimes (no clone-time flatten
|
|
|
126
126
|
shimDir = path.join(workDir, "shim");
|
|
127
127
|
fs.mkdirSync(shimDir, { recursive: true });
|
|
128
128
|
const shim = `#!/usr/bin/env bash
|
|
129
|
-
if [ "$1" = "clone" ]; then
|
|
129
|
+
if [ "$1" = "clone" ] || [ "$1" = "ls-remote" ]; then
|
|
130
130
|
args=()
|
|
131
131
|
for a in "$@"; do
|
|
132
132
|
case "$a" in
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rescue-preserve-copy-symlink.test.d.ts","sourceRoot":"","sources":["../../src/cli/rescue-preserve-copy-symlink.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression coverage for preserve-subpath copying on Windows accounts that
|
|
3
|
+
* cannot create symbolic links. The fault is injected at fs.symlinkSync or
|
|
4
|
+
* fs.mkdirSync because Linux CI can create links without Windows privilege.
|
|
5
|
+
*/
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { execFileSync } from "child_process";
|
|
8
|
+
import * as fs from "fs";
|
|
9
|
+
import * as os from "os";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import { SNAPSHOT_FILE } from "../backup-prune.js";
|
|
12
|
+
vi.mock("fs", async (importOriginal) => {
|
|
13
|
+
const actual = await importOriginal();
|
|
14
|
+
return { ...actual };
|
|
15
|
+
});
|
|
16
|
+
import { runRescue } from "./rescue-core.js";
|
|
17
|
+
function errnoError(code, syscall, message) {
|
|
18
|
+
const error = new Error(message);
|
|
19
|
+
error.code = code;
|
|
20
|
+
error.errno = code === "EPERM" ? -4048 : undefined;
|
|
21
|
+
error.syscall = syscall;
|
|
22
|
+
return error;
|
|
23
|
+
}
|
|
24
|
+
function has(bin, ...args) {
|
|
25
|
+
try {
|
|
26
|
+
execFileSync(bin, args, { stdio: "ignore" });
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const toolsAvailable = has("git", "--version") && has("rsync", "--version");
|
|
34
|
+
function withPlatform(platform, run) {
|
|
35
|
+
const descriptor = Object.getOwnPropertyDescriptor(process, "platform");
|
|
36
|
+
if (!descriptor)
|
|
37
|
+
throw new Error("process.platform descriptor is unavailable");
|
|
38
|
+
Object.defineProperty(process, "platform", { value: platform, configurable: true });
|
|
39
|
+
try {
|
|
40
|
+
return run();
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
Object.defineProperty(process, "platform", descriptor);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function captureRescue(argv, env) {
|
|
47
|
+
let stdout = "";
|
|
48
|
+
let stderr = "";
|
|
49
|
+
const originalOut = process.stdout.write.bind(process.stdout);
|
|
50
|
+
const originalErr = process.stderr.write.bind(process.stderr);
|
|
51
|
+
process.stdout.write = ((chunk) => {
|
|
52
|
+
stdout += String(chunk);
|
|
53
|
+
return true;
|
|
54
|
+
});
|
|
55
|
+
process.stderr.write = ((chunk) => {
|
|
56
|
+
stderr += String(chunk);
|
|
57
|
+
return true;
|
|
58
|
+
});
|
|
59
|
+
let status;
|
|
60
|
+
let threw;
|
|
61
|
+
try {
|
|
62
|
+
status = runRescue(argv, { env }).status;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
threw = error;
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
process.stdout.write = originalOut;
|
|
69
|
+
process.stderr.write = originalErr;
|
|
70
|
+
}
|
|
71
|
+
return { status, stdout, stderr, threw };
|
|
72
|
+
}
|
|
73
|
+
describe.skipIf(!toolsAvailable)("rescue preserves links without Windows symlink privilege", () => {
|
|
74
|
+
let workDir;
|
|
75
|
+
let hqRoot;
|
|
76
|
+
let backupRoot;
|
|
77
|
+
let upstream;
|
|
78
|
+
let env;
|
|
79
|
+
beforeEach(() => {
|
|
80
|
+
workDir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-rescue-preserve-link-"));
|
|
81
|
+
hqRoot = path.join(workDir, "hq");
|
|
82
|
+
backupRoot = path.join(workDir, "backups");
|
|
83
|
+
upstream = path.join(workDir, "upstream");
|
|
84
|
+
fs.mkdirSync(path.join(hqRoot, "core"), { recursive: true });
|
|
85
|
+
fs.mkdirSync(path.join(hqRoot, "personal"), { recursive: true });
|
|
86
|
+
fs.mkdirSync(path.join(hqRoot, "companies"), { recursive: true });
|
|
87
|
+
fs.writeFileSync(path.join(hqRoot, "core", "release.txt"), "local release\n");
|
|
88
|
+
fs.mkdirSync(backupRoot, { recursive: true });
|
|
89
|
+
fs.mkdirSync(path.join(upstream, "core"), { recursive: true });
|
|
90
|
+
fs.writeFileSync(path.join(upstream, "core", "release.txt"), "released\n");
|
|
91
|
+
fs.mkdirSync(path.join(upstream, "core", "preserved-file"), { recursive: true });
|
|
92
|
+
fs.writeFileSync(path.join(upstream, "core", "preserved-file", "overlay.txt"), "overlay directory data\n");
|
|
93
|
+
execFileSync("git", ["init", "-b", "main", upstream], { stdio: "ignore" });
|
|
94
|
+
execFileSync("git", ["-C", upstream, "add", "."], { stdio: "ignore" });
|
|
95
|
+
execFileSync("git", [
|
|
96
|
+
"-C",
|
|
97
|
+
upstream,
|
|
98
|
+
"-c",
|
|
99
|
+
"user.name=test",
|
|
100
|
+
"-c",
|
|
101
|
+
"user.email=test@example.com",
|
|
102
|
+
"commit",
|
|
103
|
+
"-m",
|
|
104
|
+
"fixture",
|
|
105
|
+
], { stdio: "ignore" });
|
|
106
|
+
const realGit = execFileSync("bash", ["-lc", "command -v git"]).toString().trim();
|
|
107
|
+
const shimDir = path.join(workDir, "bin");
|
|
108
|
+
fs.mkdirSync(shimDir, { recursive: true });
|
|
109
|
+
fs.writeFileSync(path.join(shimDir, "git"), `#!/usr/bin/env bash
|
|
110
|
+
if [ "$1" = "clone" ] || [ "$1" = "ls-remote" ]; then
|
|
111
|
+
args=()
|
|
112
|
+
for arg in "$@"; do
|
|
113
|
+
case "$arg" in
|
|
114
|
+
https://github.com/test/repo.git) arg=${JSON.stringify(upstream)} ;;
|
|
115
|
+
esac
|
|
116
|
+
args+=("$arg")
|
|
117
|
+
done
|
|
118
|
+
exec ${JSON.stringify(realGit)} "\${args[@]}"
|
|
119
|
+
fi
|
|
120
|
+
exec ${JSON.stringify(realGit)} "$@"
|
|
121
|
+
`, { mode: 0o755 });
|
|
122
|
+
env = { ...process.env, PATH: `${shimDir}:${process.env.PATH ?? ""}` };
|
|
123
|
+
});
|
|
124
|
+
afterEach(() => {
|
|
125
|
+
vi.restoreAllMocks();
|
|
126
|
+
fs.rmSync(workDir, { recursive: true, force: true });
|
|
127
|
+
});
|
|
128
|
+
function updateArgs(preserve, includeBackup = false) {
|
|
129
|
+
return [
|
|
130
|
+
"--hq-root",
|
|
131
|
+
hqRoot,
|
|
132
|
+
"--source",
|
|
133
|
+
"test/repo",
|
|
134
|
+
"--ref",
|
|
135
|
+
"main",
|
|
136
|
+
"--paths",
|
|
137
|
+
"core",
|
|
138
|
+
"--no-history-check",
|
|
139
|
+
...(includeBackup ? ["--backup-dir", backupRoot] : ["--no-backup"]),
|
|
140
|
+
"--yes",
|
|
141
|
+
...preserve.flatMap((rel) => ["--preserve-subpath", rel]),
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
function denyOrdinaryWindowsSymlinks() {
|
|
145
|
+
const realSymlinkSync = fs.symlinkSync;
|
|
146
|
+
return vi.spyOn(fs, "symlinkSync").mockImplementation(((target, destination, type) => {
|
|
147
|
+
if (process.platform === "win32" && type !== "junction") {
|
|
148
|
+
throw errnoError("EPERM", "symlink", "operation not permitted, symlink");
|
|
149
|
+
}
|
|
150
|
+
return realSymlinkSync(target, destination, type);
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
function recoveryManifest() {
|
|
154
|
+
const snapshots = fs
|
|
155
|
+
.readdirSync(backupRoot)
|
|
156
|
+
.filter((name) => name.startsWith("pre-update-"));
|
|
157
|
+
expect(snapshots).toHaveLength(1);
|
|
158
|
+
return JSON.parse(fs.readFileSync(path.join(backupRoot, snapshots[0], SNAPSHOT_FILE), "utf8"));
|
|
159
|
+
}
|
|
160
|
+
it("preserves a directory link as a junction when Windows rejects symlink creation", () => {
|
|
161
|
+
const target = path.join(hqRoot, "personal", "linked-directory");
|
|
162
|
+
fs.mkdirSync(target, { recursive: true });
|
|
163
|
+
fs.writeFileSync(path.join(target, "sentinel.txt"), "directory data\n");
|
|
164
|
+
const link = path.join(hqRoot, "core", "preserved-directory");
|
|
165
|
+
fs.symlinkSync("../personal/linked-directory", link);
|
|
166
|
+
const symlinkSpy = denyOrdinaryWindowsSymlinks();
|
|
167
|
+
const result = withPlatform("win32", () => captureRescue(updateArgs(["core/preserved-directory"]), env));
|
|
168
|
+
expect(result.threw, `${result.stdout}\n${result.stderr}`).toBeUndefined();
|
|
169
|
+
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
|
|
170
|
+
expect(fs.lstatSync(link).isSymbolicLink()).toBe(true);
|
|
171
|
+
expect(fs.readlinkSync(link)).toBe(target);
|
|
172
|
+
expect(fs.readFileSync(path.join(link, "sentinel.txt"), "utf8")).toBe("directory data\n");
|
|
173
|
+
expect(symlinkSpy.mock.calls.some(([, , type]) => type === "junction")).toBe(true);
|
|
174
|
+
expect(result.stderr).not.toContain("HQ_RESCUE_FAILURE_KIND=preserve-restore-failed");
|
|
175
|
+
});
|
|
176
|
+
it("preserves a file link as copied data when Windows rejects symlink creation", () => {
|
|
177
|
+
const target = path.join(hqRoot, "core", "linked-target.txt");
|
|
178
|
+
fs.writeFileSync(target, "local linked data\n");
|
|
179
|
+
const link = path.join(hqRoot, "core", "preserved-file");
|
|
180
|
+
fs.symlinkSync("linked-target.txt", link);
|
|
181
|
+
denyOrdinaryWindowsSymlinks();
|
|
182
|
+
const result = withPlatform("win32", () => captureRescue(updateArgs(["core/preserved-file"]), env));
|
|
183
|
+
expect(result.threw, `${result.stdout}\n${result.stderr}`).toBeUndefined();
|
|
184
|
+
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
|
|
185
|
+
expect(fs.lstatSync(link).isFile()).toBe(true);
|
|
186
|
+
expect(fs.readFileSync(link, "utf8")).toBe("local linked data\n");
|
|
187
|
+
});
|
|
188
|
+
it("restores a preserved file over a non-empty directory from the overlay", () => {
|
|
189
|
+
const preserved = path.join(hqRoot, "core", "preserved-file");
|
|
190
|
+
fs.writeFileSync(preserved, "local preserved file\n");
|
|
191
|
+
const result = withPlatform("linux", () => captureRescue(updateArgs(["core/preserved-file"]), env));
|
|
192
|
+
expect(result.threw, `${result.stdout}\n${result.stderr}`).toBeUndefined();
|
|
193
|
+
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
|
|
194
|
+
expect(fs.lstatSync(preserved).isFile()).toBe(true);
|
|
195
|
+
expect(fs.readFileSync(preserved, "utf8")).toBe("local preserved file\n");
|
|
196
|
+
expect(fs.readdirSync(path.dirname(preserved)).filter((name) => name.includes(".hq-restore-"))).toEqual([]);
|
|
197
|
+
expect(result.stderr).not.toContain("HQ_RESCUE_FAILURE_KIND=preserve-restore-failed");
|
|
198
|
+
});
|
|
199
|
+
it("keeps a file carve-out in place when staged copyFile fails", () => {
|
|
200
|
+
const failed = path.join(hqRoot, "core", "failed");
|
|
201
|
+
fs.writeFileSync(failed, "failed local data\n");
|
|
202
|
+
const realCopyFileSync = fs.copyFileSync;
|
|
203
|
+
vi.spyOn(fs, "copyFileSync").mockImplementation(((from, to, mode) => {
|
|
204
|
+
if (path.resolve(String(to)).includes(".hq-restore-")) {
|
|
205
|
+
throw errnoError("EPERM", "copyfile", "operation not permitted, copyfile");
|
|
206
|
+
}
|
|
207
|
+
return realCopyFileSync(from, to, mode);
|
|
208
|
+
}));
|
|
209
|
+
const result = withPlatform("win32", () => captureRescue(updateArgs(["core/failed"], true), env));
|
|
210
|
+
expect(result.threw, `${result.stdout}\n${result.stderr}`).toBeUndefined();
|
|
211
|
+
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(1);
|
|
212
|
+
expect(fs.readFileSync(failed, "utf8")).toBe("failed local data\n");
|
|
213
|
+
expect(result.stderr).toContain("core/failed");
|
|
214
|
+
expect(result.stderr).toContain(path.join("preserve-unrestored", "core", "failed"));
|
|
215
|
+
expect(result.stderr.trimEnd()).toMatch(/HQ_RESCUE_FAILURE_KIND=preserve-restore-failed$/);
|
|
216
|
+
expect(result.stderr).not.toContain("Developer Mode in Windows Settings");
|
|
217
|
+
expect(recoveryManifest().status).toBe("recovery-required");
|
|
218
|
+
});
|
|
219
|
+
it("reports a post-overlay preserve restore failure after restoring every other preserved path", () => {
|
|
220
|
+
const failed = path.join(hqRoot, "core", "failed");
|
|
221
|
+
const restored = path.join(hqRoot, "core", "restored");
|
|
222
|
+
fs.mkdirSync(path.join(failed, "child"), { recursive: true });
|
|
223
|
+
fs.mkdirSync(restored, { recursive: true });
|
|
224
|
+
fs.writeFileSync(path.join(failed, "child", "keep.txt"), "failed local data\n");
|
|
225
|
+
fs.writeFileSync(path.join(restored, "keep.txt"), "restored local data\n");
|
|
226
|
+
const realMkdirSync = fs.mkdirSync;
|
|
227
|
+
vi.spyOn(fs, "mkdirSync").mockImplementation(((target, options) => {
|
|
228
|
+
if (path.resolve(String(target)).includes(".hq-restore-") &&
|
|
229
|
+
path.resolve(String(target)).endsWith("/child")) {
|
|
230
|
+
throw errnoError("EPERM", "mkdir", "operation not permitted, mkdir");
|
|
231
|
+
}
|
|
232
|
+
return realMkdirSync(target, options);
|
|
233
|
+
}));
|
|
234
|
+
const result = withPlatform("win32", () => captureRescue(updateArgs(["core/failed", "core/restored"], true), env));
|
|
235
|
+
expect(result.threw, `${result.stdout}\n${result.stderr}`).toBeUndefined();
|
|
236
|
+
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(1);
|
|
237
|
+
expect(result.stdout).toContain("restored core/restored");
|
|
238
|
+
expect(result.stdout).not.toContain("==> Done.");
|
|
239
|
+
expect(result.stderr).toContain("core/failed");
|
|
240
|
+
expect(result.stderr.trimEnd()).toMatch(/HQ_RESCUE_FAILURE_KIND=preserve-restore-failed$/);
|
|
241
|
+
expect(result.stderr).not.toContain("Developer Mode in Windows Settings");
|
|
242
|
+
expect(result.stderr).toContain("updated HQ release files are already in place");
|
|
243
|
+
expect(result.stderr).toContain("--restore-snapshot");
|
|
244
|
+
expect(fs.readFileSync(path.join(failed, "child", "keep.txt"), "utf8")).toBe("failed local data\n");
|
|
245
|
+
expect(result.stderr).toContain(path.join("preserve-unrestored", "core", "failed"));
|
|
246
|
+
expect(fs.readFileSync(path.join(hqRoot, "core", "release.txt"), "utf8")).toBe("released\n");
|
|
247
|
+
expect(fs.readFileSync(path.join(restored, "keep.txt"), "utf8")).toBe("restored local data\n");
|
|
248
|
+
expect(recoveryManifest().status).toBe("recovery-required");
|
|
249
|
+
});
|
|
250
|
+
it("names an incomplete snapshot instead of a restore command that will refuse", () => {
|
|
251
|
+
const skipped = path.join(hqRoot, "core", "release.txt");
|
|
252
|
+
fs.writeFileSync(path.join(hqRoot, "core", "still-readable.txt"), "captured alongside the skipped file\n");
|
|
253
|
+
const failed = path.join(hqRoot, "core", "failed");
|
|
254
|
+
fs.mkdirSync(path.join(failed, "child"), { recursive: true });
|
|
255
|
+
fs.writeFileSync(path.join(failed, "child", "keep.txt"), "failed local data\n");
|
|
256
|
+
const realOpenSync = fs.openSync;
|
|
257
|
+
vi.spyOn(fs, "openSync").mockImplementation(((file, flags, mode) => {
|
|
258
|
+
if (path.resolve(String(file)) === skipped && flags === "r") {
|
|
259
|
+
throw errnoError("EDEADLK", "read", "Unknown system error -11, read");
|
|
260
|
+
}
|
|
261
|
+
return realOpenSync(file, flags, mode);
|
|
262
|
+
}));
|
|
263
|
+
const realMkdirSync = fs.mkdirSync;
|
|
264
|
+
vi.spyOn(fs, "mkdirSync").mockImplementation(((target, options) => {
|
|
265
|
+
if (path.resolve(String(target)).includes(".hq-restore-") &&
|
|
266
|
+
path.resolve(String(target)).endsWith("/child")) {
|
|
267
|
+
throw errnoError("EPERM", "mkdir", "operation not permitted, mkdir");
|
|
268
|
+
}
|
|
269
|
+
return realMkdirSync(target, options);
|
|
270
|
+
}));
|
|
271
|
+
const result = withPlatform("win32", () => captureRescue(updateArgs(["core/failed"], true), env));
|
|
272
|
+
expect(result.threw, `${result.stdout}\n${result.stderr}`).toBeUndefined();
|
|
273
|
+
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(1);
|
|
274
|
+
expect(result.stderr).toContain("core/failed");
|
|
275
|
+
expect(result.stderr).toContain("This snapshot is incomplete");
|
|
276
|
+
expect(result.stderr).toContain("core/release.txt");
|
|
277
|
+
expect(result.stderr).toContain(backupRoot);
|
|
278
|
+
expect(result.stderr).toContain("copying the files you need");
|
|
279
|
+
expect(result.stderr).toContain("will not restore it with --restore-snapshot");
|
|
280
|
+
expect(result.stderr).not.toContain("Restore it with:");
|
|
281
|
+
expect(result.stderr).not.toContain("Developer Mode in Windows Settings");
|
|
282
|
+
expect(result.stderr.trimEnd()).toMatch(/HQ_RESCUE_FAILURE_KIND=preserve-restore-failed$/);
|
|
283
|
+
});
|
|
284
|
+
it("gives manual recovery guidance when the snapshot manifest is unreadable", () => {
|
|
285
|
+
const failed = path.join(hqRoot, "core", "failed");
|
|
286
|
+
fs.mkdirSync(failed, { recursive: true });
|
|
287
|
+
fs.writeFileSync(path.join(failed, "keep.txt"), "failed local data\n");
|
|
288
|
+
const realMkdirSync = fs.mkdirSync;
|
|
289
|
+
vi.spyOn(fs, "mkdirSync").mockImplementation(((target, options) => {
|
|
290
|
+
const candidate = path.resolve(String(target));
|
|
291
|
+
if (candidate.includes(".hq-restore-")) {
|
|
292
|
+
const snapshot = fs
|
|
293
|
+
.readdirSync(backupRoot)
|
|
294
|
+
.find((name) => name.startsWith("pre-update-"));
|
|
295
|
+
expect(snapshot).toBeDefined();
|
|
296
|
+
fs.writeFileSync(path.join(backupRoot, snapshot, SNAPSHOT_FILE), "{ not valid json\n");
|
|
297
|
+
throw errnoError("EPERM", "mkdir", "operation not permitted, mkdir");
|
|
298
|
+
}
|
|
299
|
+
return realMkdirSync(target, options);
|
|
300
|
+
}));
|
|
301
|
+
const result = withPlatform("win32", () => captureRescue(updateArgs(["core/failed"], true), env));
|
|
302
|
+
expect(result.threw, `${result.stdout}\n${result.stderr}`).toBeUndefined();
|
|
303
|
+
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(1);
|
|
304
|
+
expect(result.stderr).toContain("Snapshot manifest is unreadable");
|
|
305
|
+
expect(result.stderr).toContain(backupRoot);
|
|
306
|
+
expect(result.stderr).toContain("Recover by copying the files you need");
|
|
307
|
+
expect(result.stderr).not.toContain("--restore-snapshot");
|
|
308
|
+
expect(result.stderr.trimEnd()).toMatch(/HQ_RESCUE_FAILURE_KIND=preserve-restore-failed$/);
|
|
309
|
+
});
|
|
310
|
+
it("suggests Developer Mode when Windows blocks creating a preserved link", () => {
|
|
311
|
+
const target = path.join(hqRoot, "personal", "linked-directory");
|
|
312
|
+
fs.mkdirSync(target, { recursive: true });
|
|
313
|
+
fs.writeFileSync(path.join(target, "sentinel.txt"), "directory data\n");
|
|
314
|
+
const link = path.join(hqRoot, "core", "preserved-directory");
|
|
315
|
+
fs.symlinkSync("../personal/linked-directory", link);
|
|
316
|
+
vi.spyOn(fs, "symlinkSync").mockImplementation(() => {
|
|
317
|
+
throw errnoError("EPERM", "symlink", "operation not permitted, symlink");
|
|
318
|
+
});
|
|
319
|
+
const result = withPlatform("win32", () => captureRescue(updateArgs(["core/preserved-directory"], false), env));
|
|
320
|
+
expect(result.status).toBeUndefined();
|
|
321
|
+
expect(result.threw).toMatchObject({ code: "EPERM", syscall: "symlink" });
|
|
322
|
+
expect(result.stderr).toContain("Cannot preserve core/preserved-directory");
|
|
323
|
+
expect(result.stderr).toContain("Developer Mode in Windows Settings");
|
|
324
|
+
expect(result.stderr).toContain("No HQ files were changed.");
|
|
325
|
+
});
|
|
326
|
+
it("keeps a symlink on POSIX where symlink creation succeeds", () => {
|
|
327
|
+
const target = path.join(hqRoot, "core", "linked-target.txt");
|
|
328
|
+
fs.writeFileSync(target, "local linked data\n");
|
|
329
|
+
const link = path.join(hqRoot, "core", "preserved-posix-file");
|
|
330
|
+
fs.symlinkSync("linked-target.txt", link);
|
|
331
|
+
const result = withPlatform("linux", () => captureRescue(updateArgs(["core/preserved-posix-file"]), env));
|
|
332
|
+
expect(result.threw, `${result.stdout}\n${result.stderr}`).toBeUndefined();
|
|
333
|
+
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
|
|
334
|
+
expect(fs.lstatSync(link).isSymbolicLink()).toBe(true);
|
|
335
|
+
expect(fs.readlinkSync(link)).toBe("linked-target.txt");
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
//# sourceMappingURL=rescue-preserve-copy-symlink.test.js.map
|