movehat 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/compile.d.ts.map +1 -1
- package/dist/commands/compile.js +19 -10
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/test.js +12 -19
- package/dist/commands/test.js.map +1 -1
- package/dist/core/Publisher.d.ts.map +1 -1
- package/dist/core/Publisher.js +20 -14
- package/dist/core/Publisher.js.map +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +8 -5
- package/dist/core/config.js.map +1 -1
- package/dist/core/deployments.d.ts.map +1 -1
- package/dist/core/deployments.js +4 -2
- package/dist/core/deployments.js.map +1 -1
- package/dist/fork/manager.js +10 -10
- package/dist/fork/manager.js.map +1 -1
- package/dist/fork/server.d.ts.map +1 -1
- package/dist/fork/server.js +21 -15
- package/dist/fork/server.js.map +1 -1
- package/dist/fork/test.d.ts.map +1 -1
- package/dist/fork/test.js +3 -2
- package/dist/fork/test.js.map +1 -1
- package/dist/harness/codeObject.js +11 -8
- package/dist/harness/codeObject.js.map +1 -1
- package/dist/harness/script.d.ts.map +1 -1
- package/dist/harness/script.js +9 -6
- package/dist/harness/script.js.map +1 -1
- package/dist/helpers/setupLocalTesting.js +3 -3
- package/dist/helpers/setupLocalTesting.js.map +1 -1
- package/dist/node/LocalNodeManager.d.ts.map +1 -1
- package/dist/node/LocalNodeManager.js +60 -22
- package/dist/node/LocalNodeManager.js.map +1 -1
- package/dist/node/__tests__/LocalNodeManager.test.js +110 -11
- package/dist/node/__tests__/LocalNodeManager.test.js.map +1 -1
- package/dist/ui/__tests__/logger.test.d.ts +2 -0
- package/dist/ui/__tests__/logger.test.d.ts.map +1 -0
- package/dist/ui/__tests__/logger.test.js +75 -0
- package/dist/ui/__tests__/logger.test.js.map +1 -0
- package/dist/ui/formatters.d.ts +0 -16
- package/dist/ui/formatters.d.ts.map +1 -1
- package/dist/ui/formatters.js +1 -1
- package/dist/ui/formatters.js.map +1 -1
- package/dist/ui/logger.d.ts +41 -0
- package/dist/ui/logger.d.ts.map +1 -1
- package/dist/ui/logger.js +49 -0
- package/dist/ui/logger.js.map +1 -1
- package/dist/ui/spinner.d.ts +25 -0
- package/dist/ui/spinner.d.ts.map +1 -1
- package/dist/ui/spinner.js +44 -0
- package/dist/ui/spinner.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +4 -0
- package/src/commands/compile.ts +24 -15
- package/src/commands/test.ts +12 -19
- package/src/core/Publisher.ts +49 -34
- package/src/core/config.ts +9 -6
- package/src/core/deployments.ts +5 -4
- package/src/fork/manager.ts +10 -10
- package/src/fork/server.ts +21 -15
- package/src/fork/test.ts +3 -2
- package/src/harness/codeObject.ts +8 -5
- package/src/harness/script.ts +7 -4
- package/src/helpers/setupLocalTesting.ts +3 -3
- package/src/node/LocalNodeManager.ts +63 -24
- package/src/node/__tests__/LocalNodeManager.test.ts +140 -14
- package/src/ui/__tests__/logger.test.ts +89 -0
- package/src/ui/formatters.ts +1 -1
- package/src/ui/logger.ts +62 -0
- package/src/ui/spinner.ts +47 -0
package/src/fork/test.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { join } from 'path';
|
|
|
2
2
|
import { existsSync } from 'fs';
|
|
3
3
|
import { runCli } from '../utils/runCli.js';
|
|
4
4
|
import type { ChildProcessAdapter } from '../utils/childProcessAdapter.js';
|
|
5
|
+
import { logger } from '../ui/index.js';
|
|
5
6
|
|
|
6
7
|
export interface SnapshotOptions {
|
|
7
8
|
path?: string;
|
|
@@ -40,7 +41,7 @@ export async function snapshot(options: SnapshotOptions = {}): Promise<string> {
|
|
|
40
41
|
const name = options.name || `snapshot-${Date.now()}`;
|
|
41
42
|
const snapshotPath = options.path || join(process.cwd(), '.movehat', 'snapshots', name);
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
logger.info(`Creating snapshot: ${name}...`);
|
|
44
45
|
|
|
45
46
|
try {
|
|
46
47
|
// Initialize fork/snapshot using aptos CLI.
|
|
@@ -68,7 +69,7 @@ export async function snapshot(options: SnapshotOptions = {}): Promise<string> {
|
|
|
68
69
|
throw new Error('Snapshot directory was not created');
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
|
|
72
|
+
logger.success(`Snapshot created at ${snapshotPath}`, 2);
|
|
72
73
|
return snapshotPath;
|
|
73
74
|
} catch (error) {
|
|
74
75
|
const msg = error instanceof Error ? error.message : String(error);
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from "../errors.js";
|
|
21
21
|
import { runCli } from "../utils/runCli.js";
|
|
22
22
|
import { parseTxHash } from "../utils/parseCliOutput.js";
|
|
23
|
-
import { logger } from "../ui/index.js";
|
|
23
|
+
import { logger, isVerbose } from "../ui/index.js";
|
|
24
24
|
import {
|
|
25
25
|
writeTempKeyFile,
|
|
26
26
|
removeKeyFile,
|
|
@@ -206,7 +206,7 @@ async function executeMovementMoveObject(
|
|
|
206
206
|
},
|
|
207
207
|
{ adapter: opts.adapter }
|
|
208
208
|
);
|
|
209
|
-
if (buildResult.stdout)
|
|
209
|
+
if (isVerbose() && buildResult.stdout) logger.info(buildResult.stdout.trim(), 2);
|
|
210
210
|
|
|
211
211
|
// Format the private key into AIP-80 shape so the Movement CLI
|
|
212
212
|
// doesn't emit its raw-hex deprecation warning. `formatPrivateKey`
|
|
@@ -265,8 +265,11 @@ async function executeMovementMoveObject(
|
|
|
265
265
|
{ adapter: opts.adapter }
|
|
266
266
|
);
|
|
267
267
|
deployOut = result.stdout;
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
// Both streams gated behind isVerbose(); see §9 — stream channel
|
|
269
|
+
// is not by itself a failure signal. Real failures throw via
|
|
270
|
+
// CliExecutionError and are surfaced from the catch below.
|
|
271
|
+
if (isVerbose() && result.stdout) logger.info(result.stdout.trim(), 2);
|
|
272
|
+
if (isVerbose() && result.stderr) logger.info(result.stderr.trim(), 2);
|
|
270
273
|
} finally {
|
|
271
274
|
// Unlink via the observable helper — emit a warning if the file
|
|
272
275
|
// could not be removed AND still exists on disk (private key
|
|
@@ -336,7 +339,7 @@ async function executeMovementMoveObject(
|
|
|
336
339
|
throw error;
|
|
337
340
|
}
|
|
338
341
|
if (error instanceof CliExecutionError) {
|
|
339
|
-
if (error.stdoutPreview)
|
|
342
|
+
if (error.stdoutPreview) logger.info(error.stdoutPreview, 2);
|
|
340
343
|
logger.error(
|
|
341
344
|
`Failed to ${subcommand === "deploy-object" ? "deploy" : "upgrade"} module: ${error.message}\n${error.stderr}`
|
|
342
345
|
);
|
package/src/harness/script.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { validatePathSafety } from "../core/shell.js";
|
|
|
10
10
|
import { CliExecutionError } from "../errors.js";
|
|
11
11
|
import { runCli } from "../utils/runCli.js";
|
|
12
12
|
import { parseTxHash } from "../utils/parseCliOutput.js";
|
|
13
|
-
import { logger } from "../ui/index.js";
|
|
13
|
+
import { logger, isVerbose } from "../ui/index.js";
|
|
14
14
|
import {
|
|
15
15
|
writeTempKeyFile,
|
|
16
16
|
removeKeyFile,
|
|
@@ -132,8 +132,11 @@ export async function runMoveScript(
|
|
|
132
132
|
{ adapter: options.adapter }
|
|
133
133
|
);
|
|
134
134
|
scriptOut = result.stdout;
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
// Both streams gated behind isVerbose(); Movement CLI uses
|
|
136
|
+
// stderr for progress messages too. Real failures throw via
|
|
137
|
+
// CliExecutionError and are surfaced from the catch below.
|
|
138
|
+
if (isVerbose() && result.stdout) logger.info(result.stdout.trim(), 2);
|
|
139
|
+
if (isVerbose() && result.stderr) logger.info(result.stderr.trim(), 2);
|
|
137
140
|
} finally {
|
|
138
141
|
// Observable cleanup — emit a warning if the unlink failed and
|
|
139
142
|
// the file is still on disk (private key would persist silently
|
|
@@ -167,7 +170,7 @@ export async function runMoveScript(
|
|
|
167
170
|
return out;
|
|
168
171
|
} catch (error) {
|
|
169
172
|
if (error instanceof CliExecutionError) {
|
|
170
|
-
if (error.stdoutPreview)
|
|
173
|
+
if (error.stdoutPreview) logger.info(error.stdoutPreview, 2);
|
|
171
174
|
logger.error(`Failed to run Move script: ${error.message}\n${error.stderr}`);
|
|
172
175
|
} else {
|
|
173
176
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
@@ -95,9 +95,9 @@ export async function setupLocalTesting(
|
|
|
95
95
|
const accountLabels = options.accountLabels || ["deployer", "alice", "bob"];
|
|
96
96
|
|
|
97
97
|
logger.newline();
|
|
98
|
-
logger.
|
|
99
|
-
logger.
|
|
100
|
-
logger.
|
|
98
|
+
logger.phase("Setting up local testing environment");
|
|
99
|
+
logger.kv("Mode", mode, 2);
|
|
100
|
+
logger.kv("Accounts", accountLabels.join(", "), 2);
|
|
101
101
|
logger.newline();
|
|
102
102
|
|
|
103
103
|
if (mode === 'local-node') {
|
|
@@ -6,7 +6,16 @@ import {
|
|
|
6
6
|
type ChildProcessAdapter,
|
|
7
7
|
type SpawnedProcess,
|
|
8
8
|
} from "../utils/childProcessAdapter.js";
|
|
9
|
-
import { logger } from "../ui/index.js";
|
|
9
|
+
import { logger, isVerbose, colors, symbols } from "../ui/index.js";
|
|
10
|
+
import { withTimedSpinner, withSpinner } from "../ui/spinner.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Substrings that always surface from the movement subprocess regardless
|
|
14
|
+
* of verbosity. These are signals the user must see to debug a stuck
|
|
15
|
+
* startup (panic, fatal, address-in-use). Tested in
|
|
16
|
+
* __tests__/LocalNodeManager.test.ts to guard against silent regressions.
|
|
17
|
+
*/
|
|
18
|
+
const CRITICAL_NODE_OUTPUT = /panic|fatal|address already in use|EADDRINUSE/i;
|
|
10
19
|
|
|
11
20
|
export interface LocalNodeOptions {
|
|
12
21
|
testDir?: string; // Directory for node data (default: .movehat/local-node)
|
|
@@ -86,7 +95,7 @@ export class LocalNodeManager {
|
|
|
86
95
|
*/
|
|
87
96
|
async start(): Promise<LocalNodeInfo> {
|
|
88
97
|
if (this.spawned) {
|
|
89
|
-
|
|
98
|
+
logger.info("Local node already running");
|
|
90
99
|
return this.getNodeInfo();
|
|
91
100
|
}
|
|
92
101
|
|
|
@@ -98,11 +107,11 @@ export class LocalNodeManager {
|
|
|
98
107
|
|
|
99
108
|
try {
|
|
100
109
|
logger.newline();
|
|
101
|
-
logger.step("Starting local Movement node
|
|
102
|
-
logger.
|
|
103
|
-
logger.
|
|
104
|
-
logger.
|
|
105
|
-
logger.
|
|
110
|
+
logger.step("Starting local Movement node");
|
|
111
|
+
logger.kv("Test directory", this.options.testDir, 2);
|
|
112
|
+
logger.kv("RPC port", String(this.options.apiPort), 2);
|
|
113
|
+
logger.kv("Faucet port", String(this.options.faucetPort), 2);
|
|
114
|
+
logger.kv("Ready port", String(this.options.readyPort), 2);
|
|
106
115
|
logger.newline();
|
|
107
116
|
|
|
108
117
|
// Clean state if force restart
|
|
@@ -133,19 +142,43 @@ export class LocalNodeManager {
|
|
|
133
142
|
stdio: this.options.silent ? "ignore" : "pipe",
|
|
134
143
|
});
|
|
135
144
|
|
|
136
|
-
//
|
|
145
|
+
// Subprocess output handling (see §9 Console UX in CLAUDE.md):
|
|
146
|
+
// - stdout chatter is hidden by default; gated by isVerbose()
|
|
147
|
+
// - lines matching CRITICAL_NODE_OUTPUT always surface as warnings
|
|
148
|
+
// so the user is never silenced through a real failure
|
|
149
|
+
// - stderr is always surfaced (real signal), modulo benign WARN
|
|
150
|
+
// lines that the movement binary emits during normal startup
|
|
137
151
|
if (!this.options.silent && this.spawned.stdout && this.spawned.stderr) {
|
|
138
152
|
this.spawned.stdout.on("data", (data: Buffer) => {
|
|
139
153
|
const output = data.toString().trim();
|
|
140
|
-
if (output)
|
|
141
|
-
|
|
154
|
+
if (!output) return;
|
|
155
|
+
if (CRITICAL_NODE_OUTPUT.test(output)) {
|
|
156
|
+
logger.warning(output);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (isVerbose()) {
|
|
160
|
+
for (const line of output.split("\n")) {
|
|
161
|
+
if (line) console.log(` ${colors.muted(symbols.pointer + " " + line)}`);
|
|
162
|
+
}
|
|
142
163
|
}
|
|
143
164
|
});
|
|
144
165
|
|
|
145
166
|
this.spawned.stderr.on("data", (data: Buffer) => {
|
|
146
167
|
const output = data.toString().trim();
|
|
147
|
-
if (
|
|
148
|
-
|
|
168
|
+
if (!output) return;
|
|
169
|
+
// Movement CLI uses stderr for both progress messages
|
|
170
|
+
// ("Applying post startup steps...", "Compiling...") and
|
|
171
|
+
// real errors. Stream channel alone isn't a reliable
|
|
172
|
+
// signal — gate routine lines behind verbosity, escalate
|
|
173
|
+
// anything matching CRITICAL_NODE_OUTPUT regardless.
|
|
174
|
+
if (CRITICAL_NODE_OUTPUT.test(output)) {
|
|
175
|
+
logger.error(output);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (isVerbose()) {
|
|
179
|
+
for (const line of output.split("\n")) {
|
|
180
|
+
if (line) console.error(` ${colors.muted(symbols.pointer + " " + line)}`);
|
|
181
|
+
}
|
|
149
182
|
}
|
|
150
183
|
});
|
|
151
184
|
}
|
|
@@ -161,11 +194,13 @@ export class LocalNodeManager {
|
|
|
161
194
|
this.spawned = null;
|
|
162
195
|
});
|
|
163
196
|
|
|
164
|
-
// Wait for node to be ready
|
|
165
|
-
|
|
166
|
-
|
|
197
|
+
// Wait for node to be ready — wrapped in withTimedSpinner so the
|
|
198
|
+
// user sees live elapsed-time feedback while subprocess chatter is
|
|
199
|
+
// hidden in non-verbose mode.
|
|
200
|
+
await withTimedSpinner("Waiting for node to be ready", () =>
|
|
201
|
+
this.waitForReady(60000)
|
|
202
|
+
);
|
|
167
203
|
|
|
168
|
-
logger.success("Local Movement node is ready!");
|
|
169
204
|
logger.newline();
|
|
170
205
|
|
|
171
206
|
this.starting = false;
|
|
@@ -303,7 +338,9 @@ export class LocalNodeManager {
|
|
|
303
338
|
}
|
|
304
339
|
|
|
305
340
|
const result = await response.json();
|
|
306
|
-
|
|
341
|
+
if (isVerbose()) {
|
|
342
|
+
logger.success(`Funded ${address} with ${amount} octas`, 2);
|
|
343
|
+
}
|
|
307
344
|
|
|
308
345
|
return result;
|
|
309
346
|
} catch (error) {
|
|
@@ -317,13 +354,15 @@ export class LocalNodeManager {
|
|
|
317
354
|
*/
|
|
318
355
|
async fundAccounts(accounts: (Account | string)[], amount: number = 100_000_000): Promise<void> {
|
|
319
356
|
logger.newline();
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
357
|
+
await withSpinner(
|
|
358
|
+
`Funding ${accounts.length} accounts from local faucet`,
|
|
359
|
+
async () => {
|
|
360
|
+
for (const account of accounts) {
|
|
361
|
+
await this.fundAccount(account, amount);
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
`Funded ${accounts.length} accounts (${(amount / 1e8).toFixed(0)} APT each)`,
|
|
365
|
+
);
|
|
327
366
|
logger.newline();
|
|
328
367
|
}
|
|
329
368
|
|
|
@@ -181,7 +181,7 @@ describe("LocalNodeManager — start / stop / lifecycle", () => {
|
|
|
181
181
|
expect(proc.stderr!.listenerCount("data")).toBe(0);
|
|
182
182
|
});
|
|
183
183
|
|
|
184
|
-
it("start in non-silent mode wires stdout/stderr listeners that
|
|
184
|
+
it("start in non-silent mode wires stdout/stderr listeners that respect §9 filtering", async () => {
|
|
185
185
|
const { adapter, spawned } = buildFakeAdapter();
|
|
186
186
|
stubFetchAlwaysOk();
|
|
187
187
|
const mgr = new LocalNodeManager({ adapter, testDir: tmpDir, silent: false });
|
|
@@ -191,19 +191,9 @@ describe("LocalNodeManager — start / stop / lifecycle", () => {
|
|
|
191
191
|
const proc = spawned[0]!;
|
|
192
192
|
expect(proc.stdout!.listenerCount("data")).toBeGreaterThan(0);
|
|
193
193
|
expect(proc.stderr!.listenerCount("data")).toBeGreaterThan(0);
|
|
194
|
-
|
|
195
|
-
//
|
|
196
|
-
|
|
197
|
-
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("local node ready"));
|
|
198
|
-
|
|
199
|
-
// stderr non-WARN line goes through console.error.
|
|
200
|
-
proc.stderr!.emit("data", Buffer.from("real error\n"));
|
|
201
|
-
expect(errSpy).toHaveBeenCalledWith(expect.stringContaining("real error"));
|
|
202
|
-
|
|
203
|
-
// stderr WARN line should be filtered (no error log).
|
|
204
|
-
errSpy.mockClear();
|
|
205
|
-
proc.stderr!.emit("data", Buffer.from("WARN something\n"));
|
|
206
|
-
expect(errSpy).not.toHaveBeenCalledWith(expect.stringContaining("WARN"));
|
|
194
|
+
// Detailed filter behavior — what passes through vs what's gated
|
|
195
|
+
// behind isVerbose() — lives in the "§9 console UX" describe block
|
|
196
|
+
// below. This test only locks the listener-wiring contract.
|
|
207
197
|
});
|
|
208
198
|
|
|
209
199
|
it("force-restart cleans the test directory before spawn", async () => {
|
|
@@ -451,3 +441,139 @@ describe("LocalNodeManager — fundAccount", () => {
|
|
|
451
441
|
expect(fetchFn.mock.calls.length).toBeGreaterThanOrEqual(4);
|
|
452
442
|
});
|
|
453
443
|
});
|
|
444
|
+
|
|
445
|
+
describe("LocalNodeManager — subprocess output filtering (§9 console UX)", () => {
|
|
446
|
+
let tmpDir: string;
|
|
447
|
+
let logSpy: ReturnType<typeof vi.spyOn>;
|
|
448
|
+
let errSpy: ReturnType<typeof vi.spyOn>;
|
|
449
|
+
let warnSpy: ReturnType<typeof vi.spyOn>;
|
|
450
|
+
|
|
451
|
+
beforeEach(() => {
|
|
452
|
+
tmpDir = mkdtempSync(join(tmpdir(), "movehat-localnode-filter-"));
|
|
453
|
+
logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined);
|
|
454
|
+
errSpy = vi.spyOn(console, "error").mockImplementation(() => undefined);
|
|
455
|
+
warnSpy = vi.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
456
|
+
// Ensure quiet mode is the default for each test; the verbose tests
|
|
457
|
+
// set MOVEHAT_VERBOSE explicitly inside their own scope.
|
|
458
|
+
delete process.env.MOVEHAT_VERBOSE;
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
afterEach(() => {
|
|
462
|
+
vi.restoreAllMocks();
|
|
463
|
+
vi.unstubAllGlobals();
|
|
464
|
+
delete process.env.MOVEHAT_VERBOSE;
|
|
465
|
+
if (existsSync(tmpDir)) {
|
|
466
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it("hides routine stdout chatter from the movement node in quiet mode", async () => {
|
|
471
|
+
const { adapter, spawned } = buildFakeAdapter();
|
|
472
|
+
stubFetchAlwaysOk();
|
|
473
|
+
const mgr = new LocalNodeManager({ adapter, testDir: tmpDir });
|
|
474
|
+
await mgr.start();
|
|
475
|
+
|
|
476
|
+
const proc = spawned[0]!;
|
|
477
|
+
logSpy.mockClear();
|
|
478
|
+
|
|
479
|
+
// Push routine chatter — exactly the noise we used to spam to stdout.
|
|
480
|
+
proc.stdout!.emit("data", Buffer.from("Loading aptos framework module"));
|
|
481
|
+
proc.stdout!.emit("data", Buffer.from("Compiling Move bytecode"));
|
|
482
|
+
proc.stdout!.emit("data", Buffer.from("aptos_account: account created"));
|
|
483
|
+
|
|
484
|
+
// None of these should have reached stdout (no `[Node]` prefix, no
|
|
485
|
+
// muted gray `›` prefix). The only console.log calls that may arise
|
|
486
|
+
// are from the spinner mock falling back to plain text — but since
|
|
487
|
+
// ora auto-disables in non-TTY (vitest is non-TTY), even those are
|
|
488
|
+
// suppressed.
|
|
489
|
+
const stdoutCalls = logSpy.mock.calls.flat().join(" ");
|
|
490
|
+
expect(stdoutCalls).not.toContain("Loading aptos framework module");
|
|
491
|
+
expect(stdoutCalls).not.toContain("Compiling Move bytecode");
|
|
492
|
+
expect(stdoutCalls).not.toContain("aptos_account: account created");
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it("always surfaces panic / fatal lines as warnings, even in quiet mode", async () => {
|
|
496
|
+
const { adapter, spawned } = buildFakeAdapter();
|
|
497
|
+
stubFetchAlwaysOk();
|
|
498
|
+
const mgr = new LocalNodeManager({ adapter, testDir: tmpDir });
|
|
499
|
+
await mgr.start();
|
|
500
|
+
|
|
501
|
+
const proc = spawned[0]!;
|
|
502
|
+
warnSpy.mockClear();
|
|
503
|
+
|
|
504
|
+
proc.stdout!.emit("data", Buffer.from("thread 'main' panicked at 'state corrupted'"));
|
|
505
|
+
|
|
506
|
+
const warnCalls = warnSpy.mock.calls.flat().join(" ");
|
|
507
|
+
expect(warnCalls).toContain("panicked");
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
it("surfaces 'address already in use' (port conflict) regardless of verbosity", async () => {
|
|
511
|
+
const { adapter, spawned } = buildFakeAdapter();
|
|
512
|
+
stubFetchAlwaysOk();
|
|
513
|
+
const mgr = new LocalNodeManager({ adapter, testDir: tmpDir });
|
|
514
|
+
await mgr.start();
|
|
515
|
+
|
|
516
|
+
const proc = spawned[0]!;
|
|
517
|
+
warnSpy.mockClear();
|
|
518
|
+
|
|
519
|
+
proc.stdout!.emit(
|
|
520
|
+
"data",
|
|
521
|
+
Buffer.from("error: address already in use: 127.0.0.1:8080"),
|
|
522
|
+
);
|
|
523
|
+
|
|
524
|
+
const warnCalls = warnSpy.mock.calls.flat().join(" ");
|
|
525
|
+
expect(warnCalls).toContain("address already in use");
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
it("surfaces stdout chatter with gray prefix in verbose mode", async () => {
|
|
529
|
+
process.env.MOVEHAT_VERBOSE = "1";
|
|
530
|
+
const { adapter, spawned } = buildFakeAdapter();
|
|
531
|
+
stubFetchAlwaysOk();
|
|
532
|
+
const mgr = new LocalNodeManager({ adapter, testDir: tmpDir });
|
|
533
|
+
await mgr.start();
|
|
534
|
+
|
|
535
|
+
const proc = spawned[0]!;
|
|
536
|
+
logSpy.mockClear();
|
|
537
|
+
|
|
538
|
+
proc.stdout!.emit("data", Buffer.from("Loading aptos framework module"));
|
|
539
|
+
|
|
540
|
+
const stdoutCalls = logSpy.mock.calls.flat().join(" ");
|
|
541
|
+
expect(stdoutCalls).toContain("Loading aptos framework module");
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("always surfaces critical stderr (panic/EADDRINUSE) via logger.error", async () => {
|
|
545
|
+
const { adapter, spawned } = buildFakeAdapter();
|
|
546
|
+
stubFetchAlwaysOk();
|
|
547
|
+
const mgr = new LocalNodeManager({ adapter, testDir: tmpDir });
|
|
548
|
+
await mgr.start();
|
|
549
|
+
|
|
550
|
+
const proc = spawned[0]!;
|
|
551
|
+
errSpy.mockClear();
|
|
552
|
+
|
|
553
|
+
proc.stderr!.emit("data", Buffer.from("thread panicked: failed to bind socket"));
|
|
554
|
+
|
|
555
|
+
const stderrCalls = errSpy.mock.calls.flat().join(" ");
|
|
556
|
+
expect(stderrCalls).toContain("panicked");
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
it("hides routine progress stderr in quiet mode (Movement CLI emits progress to stderr too)", async () => {
|
|
560
|
+
const { adapter, spawned } = buildFakeAdapter();
|
|
561
|
+
stubFetchAlwaysOk();
|
|
562
|
+
const mgr = new LocalNodeManager({ adapter, testDir: tmpDir });
|
|
563
|
+
await mgr.start();
|
|
564
|
+
|
|
565
|
+
const proc = spawned[0]!;
|
|
566
|
+
errSpy.mockClear();
|
|
567
|
+
|
|
568
|
+
// The movement subprocess emits progress messages to stderr that
|
|
569
|
+
// are NOT errors: "Applying post startup steps...", "Compiling,
|
|
570
|
+
// may take a little while...". Hiding stream channel from the
|
|
571
|
+
// user keeps the console clean.
|
|
572
|
+
proc.stderr!.emit("data", Buffer.from("Applying post startup steps..."));
|
|
573
|
+
proc.stderr!.emit("data", Buffer.from("[WARN] deprecated config field"));
|
|
574
|
+
|
|
575
|
+
const stderrCalls = errSpy.mock.calls.flat().join(" ");
|
|
576
|
+
expect(stderrCalls).not.toContain("Applying post startup steps");
|
|
577
|
+
expect(stderrCalls).not.toContain("deprecated config field");
|
|
578
|
+
});
|
|
579
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { configureLogger, isVerbose, divider, phase } from "../logger.js";
|
|
4
|
+
|
|
5
|
+
describe("logger — verbosity", () => {
|
|
6
|
+
let originalEnv: string | undefined;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
originalEnv = process.env.MOVEHAT_VERBOSE;
|
|
10
|
+
// Start each test from a clean slate so prior runs cannot leak.
|
|
11
|
+
delete process.env.MOVEHAT_VERBOSE;
|
|
12
|
+
configureLogger({ verbosity: "normal" });
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
if (originalEnv === undefined) {
|
|
17
|
+
delete process.env.MOVEHAT_VERBOSE;
|
|
18
|
+
} else {
|
|
19
|
+
process.env.MOVEHAT_VERBOSE = originalEnv;
|
|
20
|
+
}
|
|
21
|
+
configureLogger({ verbosity: "normal" });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("defaults to non-verbose when MOVEHAT_VERBOSE is unset and config is normal", () => {
|
|
25
|
+
expect(isVerbose()).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("returns true when MOVEHAT_VERBOSE=1 (env-driven path)", () => {
|
|
29
|
+
process.env.MOVEHAT_VERBOSE = "1";
|
|
30
|
+
expect(isVerbose()).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("returns true when configureLogger({ verbosity: 'verbose' }) is set in-process", () => {
|
|
34
|
+
configureLogger({ verbosity: "verbose" });
|
|
35
|
+
expect(isVerbose()).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("env var wins even when in-process config is normal (allows shell-script callers)", () => {
|
|
39
|
+
configureLogger({ verbosity: "normal" });
|
|
40
|
+
process.env.MOVEHAT_VERBOSE = "1";
|
|
41
|
+
expect(isVerbose()).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("non-'1' MOVEHAT_VERBOSE values do not enable verbose mode", () => {
|
|
45
|
+
process.env.MOVEHAT_VERBOSE = "true";
|
|
46
|
+
expect(isVerbose()).toBe(false);
|
|
47
|
+
process.env.MOVEHAT_VERBOSE = "0";
|
|
48
|
+
expect(isVerbose()).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("logger.phase / logger.divider", () => {
|
|
53
|
+
let logSpy: ReturnType<typeof vi.spyOn>;
|
|
54
|
+
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined);
|
|
57
|
+
configureLogger({ silent: false });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
vi.restoreAllMocks();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("phase prints three lines: top rule, indented title, bottom rule", () => {
|
|
65
|
+
phase("Local Movement node");
|
|
66
|
+
expect(logSpy).toHaveBeenCalledTimes(3);
|
|
67
|
+
|
|
68
|
+
const calls = logSpy.mock.calls.map((c: unknown[]) => String(c[0]));
|
|
69
|
+
// The title line carries the supplied text after the two-space indent.
|
|
70
|
+
expect(calls[1]).toContain("Local Movement node");
|
|
71
|
+
// Top and bottom rules should be identical (same width, same color).
|
|
72
|
+
expect(calls[0]).toBe(calls[2]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("divider prints a single muted rule line", () => {
|
|
76
|
+
divider();
|
|
77
|
+
expect(logSpy).toHaveBeenCalledTimes(1);
|
|
78
|
+
const line = String(logSpy.mock.calls[0]?.[0] ?? "");
|
|
79
|
+
// The rule character is `━` (BOX DRAWINGS HEAVY HORIZONTAL).
|
|
80
|
+
expect(line).toMatch(/━+/);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("phase and divider are silenced when configureLogger({ silent: true })", () => {
|
|
84
|
+
configureLogger({ silent: true });
|
|
85
|
+
phase("hidden phase");
|
|
86
|
+
divider();
|
|
87
|
+
expect(logSpy).not.toHaveBeenCalled();
|
|
88
|
+
});
|
|
89
|
+
});
|
package/src/ui/formatters.ts
CHANGED
|
@@ -176,7 +176,7 @@ export const indent = (text: string, spaces: number): string => {
|
|
|
176
176
|
* console.log(divider(40, '='));
|
|
177
177
|
* // ========================================
|
|
178
178
|
*/
|
|
179
|
-
|
|
179
|
+
const divider = (
|
|
180
180
|
width: number = 60,
|
|
181
181
|
char: string = symbols.line
|
|
182
182
|
): string => {
|
package/src/ui/logger.ts
CHANGED
|
@@ -6,6 +6,14 @@ import { coloredSymbol, symbols } from './symbols.js';
|
|
|
6
6
|
*/
|
|
7
7
|
export type LogLevel = 'info' | 'success' | 'error' | 'warning' | 'debug';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Verbosity level for subprocess output and gray-prefixed chatter.
|
|
11
|
+
* - `quiet` — reserved; currently behaves like `normal`
|
|
12
|
+
* - `normal` — default; system logs only, subprocess chatter hidden
|
|
13
|
+
* - `verbose` — surface subprocess stdout with a muted gray `›` prefix
|
|
14
|
+
*/
|
|
15
|
+
export type Verbosity = 'quiet' | 'normal' | 'verbose';
|
|
16
|
+
|
|
9
17
|
/**
|
|
10
18
|
* Logger configuration options
|
|
11
19
|
*/
|
|
@@ -16,6 +24,8 @@ export interface LoggerConfig {
|
|
|
16
24
|
level?: LogLevel;
|
|
17
25
|
/** Include timestamps in log messages */
|
|
18
26
|
timestamp?: boolean;
|
|
27
|
+
/** Verbosity level for subprocess output */
|
|
28
|
+
verbosity?: Verbosity;
|
|
19
29
|
}
|
|
20
30
|
|
|
21
31
|
/**
|
|
@@ -25,8 +35,18 @@ let config: LoggerConfig = {
|
|
|
25
35
|
silent: false,
|
|
26
36
|
level: 'info',
|
|
27
37
|
timestamp: false,
|
|
38
|
+
verbosity: process.env.MOVEHAT_VERBOSE === '1' ? 'verbose' : 'normal',
|
|
28
39
|
};
|
|
29
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Whether subprocess chatter should reach the user's terminal.
|
|
43
|
+
* Honors both the in-process config (set by the `-v` CLI flag's
|
|
44
|
+
* preAction hook) and the `MOVEHAT_VERBOSE=1` env var (which lets
|
|
45
|
+
* callers opt in before the CLI parses args, e.g. in shell scripts).
|
|
46
|
+
*/
|
|
47
|
+
export const isVerbose = (): boolean =>
|
|
48
|
+
config.verbosity === 'verbose' || process.env.MOVEHAT_VERBOSE === '1';
|
|
49
|
+
|
|
30
50
|
/**
|
|
31
51
|
* Configure logger globally
|
|
32
52
|
*
|
|
@@ -186,6 +206,45 @@ export const section = (title: string): void => {
|
|
|
186
206
|
console.log(`\n${colors.brandBright(title)}`);
|
|
187
207
|
};
|
|
188
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Width of the `━` rule used by `phase` and `divider`. Matched to a
|
|
211
|
+
* comfortable terminal width that fits in a side-by-side dev layout.
|
|
212
|
+
*/
|
|
213
|
+
const PHASE_RULE_WIDTH = 52;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Single muted horizontal rule. Use to close out a phase or to
|
|
217
|
+
* visually separate output sections.
|
|
218
|
+
*/
|
|
219
|
+
export const divider = (): void => {
|
|
220
|
+
if (config.silent) return;
|
|
221
|
+
console.log(colors.muted('━'.repeat(PHASE_RULE_WIDTH)));
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Phase header — renders a muted top rule, a bold brand-colored title
|
|
226
|
+
* indented two spaces, and a muted bottom rule. Use at top-level phase
|
|
227
|
+
* boundaries (local node start, deploy flow, test orchestrator
|
|
228
|
+
* sections) so the user can visually anchor where one phase ends and
|
|
229
|
+
* the next begins.
|
|
230
|
+
*
|
|
231
|
+
* @param title - Phase title (e.g. "Local Movement node")
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* logger.phase('Local Movement node');
|
|
235
|
+
* // Renders:
|
|
236
|
+
* // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
237
|
+
* // Local Movement node
|
|
238
|
+
* // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
239
|
+
*/
|
|
240
|
+
export const phase = (title: string): void => {
|
|
241
|
+
if (config.silent) return;
|
|
242
|
+
const rule = colors.muted('━'.repeat(PHASE_RULE_WIDTH));
|
|
243
|
+
console.log(rule);
|
|
244
|
+
console.log(` ${colors.brandBright(title)}`);
|
|
245
|
+
console.log(rule);
|
|
246
|
+
};
|
|
247
|
+
|
|
189
248
|
/**
|
|
190
249
|
* Key-value pair
|
|
191
250
|
* Use for displaying structured data
|
|
@@ -235,6 +294,7 @@ export const item = (text: string, indent: number = 0): void => {
|
|
|
235
294
|
*/
|
|
236
295
|
export const logger = {
|
|
237
296
|
configure: configureLogger,
|
|
297
|
+
isVerbose,
|
|
238
298
|
info,
|
|
239
299
|
success,
|
|
240
300
|
error,
|
|
@@ -243,6 +303,8 @@ export const logger = {
|
|
|
243
303
|
plain,
|
|
244
304
|
newline,
|
|
245
305
|
section,
|
|
306
|
+
phase,
|
|
307
|
+
divider,
|
|
246
308
|
kv,
|
|
247
309
|
item,
|
|
248
310
|
};
|