Skip to content

Commit a8985b5

Browse files
phodalQoder-AI
andcommitted
test(cli): assert help-flag normalization through dispatch equality
The pre-help-flag variants of every terminal path each spawned a guarded subprocess, even though resolveDispatch normalizes them to the exact dispatch the canonical `--help` run already executed with zero side effects. Those runs re-verified canonical's own arguments and dominated the runtime of this file. Compare the normalized dispatch arguments against the canonical dispatch instead, and keep the canonical guarded subprocess as the behavioral evidence. Identical script plus identical arguments yields identical execution, so the zero-side-effect contract stays covered. Validated with node --test test/better-harness-cli.test.mjs. Co-authored-by: QoderAI (Qwen 3.8 Max) <qoder_ai@qoder.com>
1 parent 515170a commit a8985b5

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

test/better-harness-cli.test.mjs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -495,23 +495,21 @@ test("better-harness CLI short-circuits help for every registered terminal path"
495495
assert.equal(canonical.stderr, "", canonicalArgs.join(" "));
496496
assert.notEqual(canonical.stdout, "", canonicalArgs.join(" "));
497497

498+
// The canonical `--help` run above already proved this dispatch executes
499+
// to help with zero side effects under the guard. For the pre-help-flag
500+
// variants we only need to prove resolveDispatch normalizes them to that
501+
// same dispatch (identical script, `invalid-before-help` stripped, trailing
502+
// `--help`); an identical dispatch yields byte-identical execution, so a
503+
// per-variant guarded subprocess would only re-run canonical's own args.
498504
for (const helpFlag of ["--help", "-h"]) {
499505
const args = [...pathSegments, "invalid-before-help", helpFlag];
500506
const dispatch = resolveDispatch(args);
501507

502508
assert.equal(dispatch.kind, "dispatch", args.join(" "));
503509
assert.equal(dispatch.script, canonicalDispatch.script, args.join(" "));
510+
assert.deepEqual(dispatch.args, canonicalDispatch.args, args.join(" "));
504511
assert.equal(dispatch.args.includes("invalid-before-help"), false, args.join(" "));
505512
assert.equal(dispatch.args.at(-1), "--help", args.join(" "));
506-
507-
const result = await runGuardedBetterHarness(args, {
508-
cwd: isolatedRoot,
509-
expectedOwner: dispatch.script,
510-
expectedOwnerArgs: dispatch.args,
511-
});
512-
assert.equal(result.status, 0, `${args.join(" ")}\n${result.stderr}`);
513-
assert.equal(result.stderr, "", args.join(" "));
514-
assert.equal(result.stdout, canonical.stdout, args.join(" "));
515513
}
516514
}
517515
} finally {

0 commit comments

Comments
 (0)