Repository navigation
fix(cli): lore logs -f streams new lines (bypass bridge for legacy's never-resolving promise) - #1579
Merged
Merged
Conversation
…never-resolving promise)
Bug: `lore logs -f` printed nothing. The typed wrapper delegated
to the legacy `commandLogs` via the shared `runLegacyAndCollect`
bridge, which `await`s the legacy function. The legacy deliberately
returns `new Promise(() => {})` after installing the watchFile
poller + SIGINT/SIGTERM cleanup — i.e. it NEVER resolves. So the
bridge hung forever on -f, and the user saw an empty terminal.
Fix: split the handler into two execution paths.
Non-follow: bridge wrapper, as before (synchronous initial read,
returns cleanly).
Follow (-f / --follow): invoke the legacy WITHOUT await. The
legacy's initial read is fully synchronous (readFileSync + split +
console.log of tail) BEFORE any control-flow suspension; the
watchFile poller + signal handlers keep the Node process alive on
the event loop; the default SIGINT handler exits the process on
Ctrl-C.
This is the only typed command that does not funnel through
`buildOutputCommand` for one of its code paths — the streaming
follow-mode is request/streamship-shaped, not
request/response-shaped. Documented in the file header.
Test updates:
- The old `-f` test was written for the bridge-based wrapper. It
mocked commandLogs but didn't pin that the wrapper actually returns
(vs. hangs). Rewrote to:
1. Forward the same values to the legacy (mock verified)
2. `Promise.race` against a 2s timeout — fails if the wrapper
hangs (the user-facing bug)
3. Cleanly tear down SIGINT/SIGTERM listeners installed by the
legacy so the test process can exit
4. Mock cleanup via `vi.doUnmock` + `vi.resetModules`
All gates green: 215 CLI tests pass across 22 files, TypeScript
clean, lint clean (zero errors), format clean, bundle succeeds.
Contributor
Codecov Results 📊✅ Patch coverage is 88.89%. Project has 6917 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 76.38% 76.39% +0.01%
==========================================
Files 198 198 —
Lines 29296 29300 +4
Branches 21173 21175 +2
==========================================
+ Hits 22378 22383 +5
- Misses 6918 6917 -1
- Partials 2177 2178 +1Generated by Codecov Action |
…eview) Independent adversarial review on PR #1579 found two load-bearing gaps in the regression test for the `-f`/follow fix: CRITICAL #1: The mock commandLogs returned synchronously (so the Promise.race timeout never fired against the actual user-facing regression — a revert to `await` would pass the test). Changed the mock to return `new Promise<void>(() => {})` so the test faithfully simulates the real legacy's never-resolving watchFile promise. The wrapper's `void` discard (not `await`) is now genuinely load-bearing. CRITICAL #2: The test only asserted `logsImpl` was called once (`toHaveBeenCalledTimes(1)`), not what was forwarded. A regression that drops `values.f = flags.follow` would silently pass. Added explicit assertion: expect(callArgs[1]).toMatchObject({ follow: true, f: true, lines: 50, n: 50, }) Confirmed load-bearing by mutation: removing `values.f = flags.follow` from the handler makes the test fail with 'expected ... to match object { follow: true, f: true, ... }'. MEDIUM #3 (production code): The follow path returned `{ kind: "value", data: "" }` which the typed output pipeline emits as `"\n` in human mode or `{ "output": "" }\n` in JSON mode (after the legacy's raw stdout). Changed to `{ kind: "empty" }` — `empty` is the canonical 'no envelope to render' shape that writes nothing. LOW #4 (production code): Added a defensive `.catch()` on the fire-and-forget `void commandLogs([])` so a future legacy path that throws (instead of `process.exit(1)`) doesn't go to an unhandled rejection. Cleanup #6 (test code): Removed the redundant `Promise.resolve(runCli())` wrapping (cleanup #6 from review). The runtime Promise.race handles Promise and value inputs the same way. Lint: oxlint-disable-next-line used on the no-misused-promises violation (matches the established pattern in `background-limiter.test.ts:376`). All gates green: 215 CLI tests pass across 22 files, TypeScript clean, lint clean (zero errors), format clean, bundle succeeds.
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the user-reported bug:
lore logs -fprinted nothing because the typed wrapper hung trying to await the legacy's non-resolving promise.What's in this PR
Bug
The typed
commands/logs.tsrouted both non-follow and follow invocations through the sharedrunLegacyAndCollectbridge. The bridge'sawait call()blocks until the legacy function returns. The legacy'scommandLogs(inpackages/gateway/src/cli/logs.ts) deliberately returnsnew Promise(() => {})after installing the watchFile poller + SIGINT/SIGTERM cleanup — it NEVER resolves. Result:lore logs -fblocked forever, and the user saw an empty terminal.Fix
Split the handler into two execution paths based on whether
followis set.logs,logs -n 10, etc.): unchanged. Bridge wrapper. Initial read is synchronous, returns cleanly.logs -f): invoke the legacy WITHOUTawait. The legacy's initial read is fully synchronous (readFileSync+split\('\n')+console.logof the tail) BEFORE any control-flow suspension (lines 62-68 of the legacy handler). The watchFile poller + signal handlers keep Node alive on the event loop; the default SIGINT handler exits on Ctrl-C.The typed output envelope for the follow path is empty (
data: ''), since the streaming stdout IS the output — there's nothing to capture in a request/response envelope. This is documented in the file header as the one typed command with a non-standard output shape.Test updates
The old
-ftest was designed for the bridge-based wrapper. It mockedcommandLogsbut didn't pin that the wrapper actually returns vs. hangs. Rewrote to:values.follow=true+values.f=trueto the legacy (mock verified — covers alias wiring).Promise.raceagainst a 2-second timeout — fails loudly if the wrapper hangs (which is the user-facing bug).vi.doUnmock+vi.resetModulescleanup.Verification
-ftest was rewritten in place; no count change).Notes
buildOutputCommandfor one of its code paths. The follow-mode's streaming-until-Ctrl-C shape is incompatible with the request/response envelope.-fhelp text already advertised the behavior correctly ("Tail the log and print new lines as they arrive (Ctrl-C to stop)"). The fix makes the runtime match the docs.commandLogs's initial tail as a separate exported function so the typed wrapper doesn't need to defer to the legacy at all for the follow path. Trivial refactor, deferred.