@@ -132,13 +132,60 @@ function runCanonicalizeAppBundle(appBundle: string) {
|
132 | 132 | }; |
133 | 133 | } |
134 | 134 | |
| 135 | +function runRestartArgParser(...args: string[]) { |
| 136 | +const root = mkdtempSync(join(tmpdir(), "openclaw-restart-mac-test-")); |
| 137 | +tempRoots.push(root); |
| 138 | + |
| 139 | +const script = readFileSync(restartScriptPath, "utf8"); |
| 140 | +const parserBlock = script.slice( |
| 141 | +script.indexOf('for arg in "$@"; do'), |
| 142 | +script.indexOf('if [[ "$NO_SIGN" -eq 1 && "$SIGN" -eq 1 ]]'), |
| 143 | +); |
| 144 | +const harnessPath = join(root, "arg-parser-harness.sh"); |
| 145 | +writeFileSync( |
| 146 | +harnessPath, |
| 147 | +[ |
| 148 | +"#!/usr/bin/env bash", |
| 149 | +"set -euo pipefail", |
| 150 | +"WAIT_FOR_LOCK=0", |
| 151 | +"NO_SIGN=0", |
| 152 | +"SIGN=0", |
| 153 | +"AUTO_DETECT_SIGNING=1", |
| 154 | +"ATTACH_ONLY=1", |
| 155 | +'log() { printf "%s\\n" "$*"; }', |
| 156 | +'fail() { printf "ERROR: %s\\n" "$*" >&2; exit 1; }', |
| 157 | +parserBlock, |
| 158 | +'printf "wait=%s no_sign=%s sign=%s attach_only=%s\\n" "$WAIT_FOR_LOCK" "$NO_SIGN" "$SIGN" "$ATTACH_ONLY"', |
| 159 | +].join("\n"), |
| 160 | +); |
| 161 | +chmodSync(harnessPath, 0o755); |
| 162 | + |
| 163 | +return spawnSync("bash", [harnessPath, ...args], { encoding: "utf8" }); |
| 164 | +} |
| 165 | + |
135 | 166 | afterEach(() => { |
136 | 167 | for (const root of tempRoots.splice(0)) { |
137 | 168 | rmSync(root, { force: true, recursive: true }); |
138 | 169 | } |
139 | 170 | }); |
140 | 171 | |
141 | 172 | describe("scripts/restart-mac.sh", () => { |
| 173 | +it("rejects unknown restart options before side effects", () => { |
| 174 | +const result = runRestartArgParser("--wat"); |
| 175 | + |
| 176 | +expect(result.status).toBe(1); |
| 177 | +expect(result.stdout).toBe(""); |
| 178 | +expect(result.stderr.trim()).toBe("ERROR: Unknown restart option: --wat"); |
| 179 | +}); |
| 180 | + |
| 181 | +it("parses restart mode flags before side effects", () => { |
| 182 | +const result = runRestartArgParser("--wait", "--no-sign", "--no-attach-only"); |
| 183 | + |
| 184 | +expect(result.status).toBe(0); |
| 185 | +expect(result.stdout.trim()).toBe("wait=1 no_sign=1 sign=0 attach_only=0"); |
| 186 | +expect(result.stderr).toBe(""); |
| 187 | +}); |
| 188 | + |
142 | 189 | it("fails the gateway verification when lsof finds no listener", () => { |
143 | 190 | const result = runGatewayPortCheck("#!/usr/bin/env bash\nexit 1\n"); |
144 | 191 | |
|